Moving 2.0 development version to main trunk.
[fa-stable.git] / purchasing / supplier_invoice_grns.php
index 04aaaea7526dfce88f108eb2ed6cb05410dadd2e..541a4c4da42b439417055114918a2d7c5af9993e 100644 (file)
@@ -2,10 +2,9 @@
 
 $page_security = 5;
 $path_to_root="..";
-include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
 
+include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
 include_once($path_to_root . "/includes/session.inc");
-
 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
 
@@ -14,7 +13,6 @@ if ($use_date_picker)
        $js .= get_js_date_picker();
 page(_("Select Received Items to Add"), false, false, "", $js);
 
-
 if (!isset($_SESSION['supp_trans']))
 {
        display_note("To enter supplier transactions the supplier must first be selected from the supplier selection screen, then the link to enter a supplier credit note must be clicked on.", 1, 0);;
@@ -33,42 +31,43 @@ function check_data()
 {
        global $check_price_charged_vs_order_price,
                $check_qty_charged_vs_del_qty;
-       if (!is_numeric($_POST['this_quantity_inv'])) 
-       {
-               display_error( _("The quantity to invoice must be numeric."));
-               return false;
-       }
-
-       if ($_POST['this_quantity_inv'] <= 0) 
+       if (!check_num('this_quantity_inv', 0) || input_num('this_quantity_inv')==0)
        {
-               display_error( _("The quantity to invoice must be greater than zero."));
+               display_error( _("The quantity to invoice must be numeric and greater than zero."));
+               set_focus('this_quantity_inv');
                return false;
        }
 
-       if (!is_numeric($_POST['ChgPrice']))
+       if (!check_num('ChgPrice'))
        {
                display_error( _("The price is not numeric."));
+               set_focus('ChgPrice');
                return false;
        }
 
-       if ($check_price_charged_vs_order_price == True) 
+       if ($check_price_charged_vs_order_price == True)
        {
-               if ($_POST['ChgPrice']/$_POST['order_price'] > 
-                       (1 + (sys_prefs::over_charge_allowance() / 100)))
-               {
+               if ($_POST['order_price']!=input_num('ChgPrice')) {
+                    if ($_POST['order_price']==0 ||
+                       input_num('ChgPrice')/$_POST['order_price'] >
+                           (1 + (sys_prefs::over_charge_allowance() / 100)))
+                   {
                        display_error(_("The price being invoiced is more than the purchase order price by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.") .
                        _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
+                       set_focus('ChgPrice');
                        return false;
+                   }
                }
        }
 
-       if ($check_qty_charged_vs_del_qty == True) 
+       if ($check_qty_charged_vs_del_qty == True)
        {
-               if ($_POST['this_quantity_inv'] / ($_POST['qty_recd'] - $_POST['prev_quantity_inv']) > 
+               if (input_num('this_quantity_inv') / ($_POST['qty_recd'] - $_POST['prev_quantity_inv']) >
                        (1+ (sys_prefs::over_charge_allowance() / 100)))
                {
                        display_error( _("The quantity being invoiced is more than the outstanding quantity by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.")
                        . _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
+                       set_focus('this_quantity_inv');
                        return false;
                }
        }
@@ -83,40 +82,38 @@ if (isset($_POST['AddGRNToTrans']))
 
        if (check_data())
        {
-       if ($_POST['this_quantity_inv'] >= ($_POST['qty_recd'] - $_POST['prev_quantity_inv']))
+       if (input_num('this_quantity_inv') >= ($_POST['qty_recd'] - $_POST['prev_quantity_inv']))
        {
-               $complete = True;
-       } 
-       else 
+               $complete = true;
+       }
+       else
        {
-               $complete = False;
+               $complete = false;
        }
 
-               //$_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'], $_POST['po_detail_item'],
-               //      $_POST['item_code'], $_POST['item_description'], $_POST['qty_recd'],
-               //      $_POST['prev_quantity_inv'], $_POST['this_quantity_inv'],
-               //      $_POST['order_price'], $_POST['ChgPrice'], $complete,
-               //      $_POST['std_cost_unit'], $_POST['gl_code']);
                $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'], $_POST['po_detail_item'],
                        $_POST['item_code'], $_POST['item_description'], $_POST['qty_recd'],
-                       $_POST['prev_quantity_inv'], $_POST['this_quantity_inv'],
-                       $_POST['order_price'], $_POST['ChgPrice'], $complete,
+                       $_POST['prev_quantity_inv'], input_num('this_quantity_inv'),
+                       $_POST['order_price'], input_num('ChgPrice'), $complete,
                        $_POST['std_cost_unit'], "");
        }
 }
 
 //-----------------------------------------------------------------------------------------
-
-if (isset($_GET['Delete']))
+$id = find_submit('Delete');
+if ($id != -1)
 {
-       $_SESSION['supp_trans']->remove_grn_from_trans($_GET['Delete']);
+       $_SESSION['supp_trans']->remove_grn_from_trans($id);
+       $Ajax->activate('grn_items');
+       $Ajax->activate('grn_table');
 }
 
 //-----------------------------------------------------------------------------------------
-
+start_form(false,true);
 display_grn_items($_SESSION['supp_trans'], 1);
-
+end_form();
 echo "<br>";
+
 hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Supplier Invoice Entry"));
 echo "<hr>";
 
@@ -139,7 +136,7 @@ function display_grn_items_for_selection()
     start_form(false, true);
 
     display_heading2(_("Items Received Yet to be Invoiced"));
-
+       div_start('grn_table');
     start_table("$table_style colspan=7 width=95%");
     $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
        _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
@@ -149,35 +146,36 @@ function display_grn_items_for_selection()
 
     while ($myrow = db_fetch($result))
     {
-
-       $grn_already_on_invoice = False;
+               $grn_already_on_invoice = false;
 
        foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
        {
-               if ($entered_grn->id == $myrow["id"]) 
+               if ($entered_grn->id == $myrow["id"])
                {
-                       $grn_already_on_invoice = True;
+                       $grn_already_on_invoice = true;
                }
        }
-       if ($grn_already_on_invoice == False)
+       if ($grn_already_on_invoice == false)
        {
 
                        alt_table_row_color($k);
 
                label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
                //text_cells(null, 'grn_item_id', $myrow["id"]);
-               submit_cells('grn_item_id', $myrow["id"]);
+               submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
                label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
             label_cell($myrow["item_code"]);
             label_cell($myrow["description"]);
             label_cell(sql2date($myrow["delivery_date"]));
-            qty_cell($myrow["qty_recd"]);
-            qty_cell($myrow["quantity_inv"]);
-            qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"]);
+            $dec = get_qty_dec($myrow["item_code"]);
+            qty_cell($myrow["qty_recd"], false, $dec);
+            qty_cell($myrow["quantity_inv"], false, $dec);
+            qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
             amount_cell($myrow["unit_price"]);
-            amount_cell($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]));
+            amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
+                          user_price_dec()));
                        end_row();
-                       
+
                $i++;
                if ($i > 15)
                {
@@ -188,40 +186,54 @@ function display_grn_items_for_selection()
     }
 
     end_table();
+       div_end();
 }
 
 //-----------------------------------------------------------------------------------------
+if (find_submit('grn_item_id') || get_post('AddGRNToTrans'))
+{
+       $Ajax->activate('grn_selector');
+}
+if (get_post('AddGRNToTrans')) 
+{
+       $Ajax->activate('grn_table');
+       $Ajax->activate('grn_items');
+}
 
 display_grn_items_for_selection();
 
 //-----------------------------------------------------------------------------------------
 
-if (isset($_POST['grn_item_id']) && $_POST['grn_item_id'] != "")
+div_start('grn_selector');
+
+$id = find_submit('grn_item_id');
+if ($id != -1)
 {
 
-       $myrow = get_grn_item_detail($_POST['grn_item_id']);
+       $myrow = get_grn_item_detail($id);
 
        echo "<br>";
        display_heading2(_("Delivery Item Selected For Adding To A Supplier Invoice"));
        start_table("$table_style width=80%");
        $th = array(_("Sequence #"), _("Item"), _("Description"), _("Quantity Outstanding"),
                _("Quantity to Invoice"), _("Order Price"), _("Actual Price"));
-       table_header($th);      
+       table_header($th);
 
        start_row();
-       label_cell($_POST['grn_item_id']);
+       label_cell($id);
        label_cell($myrow['item_code']);
        label_cell($myrow['description']);
-       qty_cell($myrow['QtyOstdg']);
-       text_cells(null, 'this_quantity_inv', $myrow['QtyOstdg'], 13, 15);
+       $dec = get_qty_dec($myrow['item_code']);
+       qty_cell($myrow['QtyOstdg'], false, $dec);
+       qty_cells(null, 'this_quantity_inv', number_format2($myrow['QtyOstdg'], $dec), null, null, $dec);
        amount_cell($myrow['unit_price']);
-       text_cells(null, 'ChgPrice', $myrow['unit_price'], 13, 15);
+       small_amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
        end_row();
        end_table(1);;
 
-       submit_center('AddGRNToTrans', _("Add to Invoice"));
+       submit_center('AddGRNToTrans', _("Add to Invoice"), true, '', true);
 
-       hidden('GRNNumber', $_POST['grn_item_id']);
+       hidden('GRNNumber', $id);
        hidden('item_code', $myrow['item_code']);
        hidden('item_description', $myrow['description']);;
        hidden('qty_recd', $myrow['qty_recd']);
@@ -231,9 +243,12 @@ if (isset($_POST['grn_item_id']) && $_POST['grn_item_id'] != "")
 
        hidden('po_detail_item', $myrow['po_detail_item']);
 }
+div_end();
 
 //----------------------------------------------------------------------------------------
 
 end_form();
-end_page();
+echo '<br>';
+end_page(false, true);
+
 ?>