Multiply order items with same stock_id (with warning), code cleanups.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 6 Feb 2010 21:54:07 +0000 (21:54 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Sat, 6 Feb 2010 21:54:07 +0000 (21:54 +0000)
purchasing/includes/db/po_db.inc
purchasing/includes/po_class.inc
purchasing/includes/supp_trans_class.inc
purchasing/includes/ui/po_ui.inc
purchasing/po_entry_items.php

index e89d96033a93714bdffa468d0953b8ed684c3beb..308e937ab632d8e6af59e2d50e4a8298951c2c1a 100644 (file)
@@ -46,16 +46,13 @@ function add_po(&$po_obj)
      /*Insert the purchase order detail records */
      foreach ($po_obj->line_items as $po_line)
      {
-       if ($po_line->Deleted == false)
-       {
-               $sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date,    unit_price,     quantity_ordered) VALUES (";
-               $sql .= $po_obj->order_no . ", " . db_escape($po_line->stock_id). "," .
-                       db_escape($po_line->item_description). ",'" .
-                       date2sql($po_line->req_del_date) . "'," .
-                       db_escape($po_line->price) . ", " .
-                       db_escape($po_line->quantity). ")";
-                       db_query($sql, "One of the purchase order detail records could not be inserted");
-       }
+               $sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date,    unit_price,     quantity_ordered) VALUES (";
+               $sql .= $po_obj->order_no . ", " . db_escape($po_line->stock_id). "," .
+               db_escape($po_line->item_description). ",'" .
+               date2sql($po_line->req_del_date) . "'," .
+               db_escape($po_line->price) . ", " .
+               db_escape($po_line->quantity). ")";
+               db_query($sql, "One of the purchase order detail records could not be inserted");
      }
 
        $Refs->save(ST_PURCHORDER, $po_obj->order_no, $po_obj->reference);
@@ -83,43 +80,29 @@ function update_po(&$po_obj)
     $sql .= " WHERE order_no = " . $po_obj->order_no;
        db_query($sql, "The purchase order could not be updated");
 
+       $sql = "DELETE FROM ".TB_PREF."purch_order_details WHERE order_no="
+               .db_escape($po_obj->order_no);
+       db_query($sql, "could not delete old purch order details");
+
     /*Now Update the purchase order detail records */
     foreach ($po_obj->line_items as $po_line)
     {
-
-               if ($po_line->Deleted==True)
-               {
-                       // Sherifoz 21.06.03 Handle deleting existing lines
-                       if ($po_line->po_detail_rec!='')
-                       {
-                               $sql = "DELETE FROM ".TB_PREF."purch_order_details WHERE po_detail_item=".db_escape($po_line->po_detail_rec);
-                               db_query($sql, "could not query purch order details");
-                       }
-               }
-               else if ($po_line->po_detail_rec == '')
-               {
-                       // Sherifoz 21.06.03 Handle adding new lines vs. updating. if no key(po_detail_rec) then it's a new line
-                       $sql = "INSERT INTO ".TB_PREF."purch_order_details (order_no, item_code, description, delivery_date, unit_price,        quantity_ordered) VALUES (";
-                       $sql .= $po_obj->order_no . "," .
-                               db_escape($po_line->stock_id). "," .
-                               db_escape($po_line->item_description). ",'" .
-                               date2sql($po_line->req_del_date) . "'," .
-                               db_escape($po_line->price) . ", ".db_escape($po_line->quantity) . ")";
-               }
-               else
-               {
-                       $sql = "UPDATE ".TB_PREF."purch_order_details SET item_code=".db_escape($po_line->stock_id).",
-                               description =" . db_escape($po_line->item_description). ",
-                               delivery_date ='" . date2sql($po_line->req_del_date) . "',
-                               unit_price=".db_escape($po_line->price).",
-                               quantity_ordered=".db_escape($po_line->quantity) . "
-                               WHERE po_detail_item=".db_escape($po_line->po_detail_rec);
-               }
+       $sql = "INSERT INTO ".TB_PREF."purch_order_details (po_detail_item, order_no, item_code, 
+               description, delivery_date, unit_price, quantity_ordered) VALUES ("
+                       .db_escape($po_line->po_detail_rec ? $po_line->po_detail_rec : 0). ","
+                       .$po_obj->order_no . ","
+                       .db_escape($po_line->stock_id). ","
+                       .db_escape($po_line->item_description). ",'"
+                       .date2sql($po_line->req_del_date) . "',"
+                       .db_escape($po_line->price) . ", "
+                       .db_escape($po_line->quantity) . ")";
+               
                db_query($sql, "One of the purchase order detail records could not be updated");
     }
 
-       //add_comments(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
+       // add_comments(ST_PURCHORDER, $po_obj->order_no, $po_obj->orig_order_date, $po_obj->Comments);
 
+       add_audit_trail($po_obj->trans_type, $po_obj->order_no, $po_obj->document_date, _("Updated."));
        commit_transaction();
 
        return $po_obj->order_no;
@@ -183,10 +166,8 @@ function read_po_items($order_no, &$order, $open_items_only=false)
 
     if (db_num_rows($result) > 0)
     {
-
                while ($myrow = db_fetch($result))
         {
-
                $data = get_purchase_data($order->supplier_id, $myrow['item_code']);
                if ($data !== false)
                {
index b3b9c2b2b35e5059b9d053bc2d3c3cfde0b7a257..6ee90e1183ba0c04a06f254825f255f3b76af2c2 100644 (file)
@@ -43,9 +43,9 @@ class purch_order
                {
                        $this->line_items[$line_no] = new line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom, $req_del_date, $qty_inv, $qty_recd);
                        $this->lines_on_order++;
-                       Return 1;
+                       return 1;
                }
-               Return 0;
+               return 0;
        }
 
        function update_order_item($line_no, $qty, $price, $req_del_date)
@@ -58,22 +58,12 @@ class purch_order
 
        function remove_from_order($line_no)
        {
-                $this->line_items[$line_no]->Deleted = true;
+               array_splice($this->line_items, $line_no, 1);
        }
        
        function order_has_items() 
        {
-               if (count($this->line_items) > 0)
-               {
-                       foreach ($this->line_items as $ordered_items) 
-                       {
-                               if ($ordered_items->Deleted == false)
-                               {
-                                       return true;
-                               }
-                       }
-               }
-               return false;           
+               return count($this->line_items) != 0;
        }
        
        function clear_items() 
@@ -120,19 +110,18 @@ class purch_order
 class line_details 
 {
 
-       Var $line_no;
-       Var $po_detail_rec;
-       Var $stock_id;
-       Var $item_description;
-       Var $quantity;
-       Var $price;
-       Var $units;
-       Var $req_del_date;
-       Var $qty_inv;
-       Var $qty_received;
-       Var $standard_cost;
-       Var $receive_qty;
-       Var $Deleted;   
+       var $line_no;
+       var $po_detail_rec;
+       var $stock_id;
+       var $item_description;
+       var $quantity;
+       var $price;
+       var $units;
+       var $req_del_date;
+       var $qty_inv;
+       var $qty_received;
+       var $standard_cost;
+       var $receive_qty;
        
        function line_details($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date, $qty_inv, $qty_recd)
        {
@@ -149,7 +138,6 @@ class line_details
                $this->qty_inv = $qty_inv;
                $this->receive_qty = 0; /*initialise these last two only */
                $this->standard_cost =0;
-               $this->Deleted = false;
        }
 }
 
index 98bd4fcdc88f10868b74141fd6b216791cca9952..d5f7508410f8222b35f6186ed76207ed1f7a623b 100644 (file)
@@ -17,7 +17,7 @@ include_once($path_to_root . "/taxes/tax_calc.inc");
 class supp_trans 
 {
 
-       var $grn_items; /*array of objects of class GRNDetails using the GRN No as the pointer */
+       var $grn_items; /*array of objects of class grn_item using the id as the pointer */
        var $gl_codes; /*array of objects of class gl_codes using a counter as the pointer */
        var $supplier_id;
        var $supplier_name;
@@ -65,11 +65,11 @@ class supp_trans
                return 1;
        }
 
-       function remove_grn_from_trans(&$grn_item_id)
+       function remove_grn_from_trans($grn_item_id)
        {
            unset($this->grn_items[$grn_item_id]);
        }
-       function remove_gl_codes_from_trans(&$gl_code_counter)
+       function remove_gl_codes_from_trans($gl_code_counter)
        {
             unset($this->gl_codes[$gl_code_counter]);
        }
@@ -87,7 +87,7 @@ class supp_trans
                $this->ov_amount = $this->ov_discount = $this->supplier_id = 0;
                
                $this->grn_items = array();
-               $this->gl_codes = array();              
+               $this->gl_codes = array();
        }
        
     function get_taxes($tax_group_id=null, $shipping_cost=0, $gl_codes=true)
index 830f483f3998e7e04a9ec150f4508d1f618cb8a9..ae8f4ba297ff2b32d900383ea62707163bc0b42b 100644 (file)
@@ -177,37 +177,33 @@ function display_po_items(&$order, $editable=true)
        $k = 0;
        foreach ($order->line_items as $line_no => $po_line)
        {
-
-               if ($po_line->Deleted == false)
+       $line_total =   round($po_line->quantity * $po_line->price,  user_price_dec());
+       if (!$editable || ($id != $line_no))
                {
-               $line_total =   round($po_line->quantity * $po_line->price,  user_price_dec());
-               if (!$editable || ($id != $line_no))
+               alt_table_row_color($k);
+               label_cell($po_line->stock_id);
+               label_cell($po_line->item_description);
+            qty_cell($po_line->quantity, false, get_qty_dec($po_line->stock_id));
+            qty_cell($po_line->qty_received, false, get_qty_dec($po_line->stock_id));
+               label_cell($po_line->units);
+            label_cell($po_line->req_del_date);
+               amount_decimal_cell($po_line->price);
+            amount_cell($line_total);
+
+                       if ($editable)
                        {
-                       alt_table_row_color($k);
-                       label_cell($po_line->stock_id);
-                       label_cell($po_line->item_description);
-                qty_cell($po_line->quantity, false, get_qty_dec($po_line->stock_id));
-                qty_cell($po_line->qty_received, false, get_qty_dec($po_line->stock_id));
-                       label_cell($po_line->units);
-                label_cell($po_line->req_del_date);
-                       amount_decimal_cell($po_line->price);
-                amount_cell($line_total);
-
-                if ($editable)
-                {
                                        edit_button_cell("Edit$line_no", _("Edit"),
                                          _('Edit document line'));
                                        delete_button_cell("Delete$line_no", _("Delete"),
-                                         _('Remove line from document'));
-                }
-                       end_row();
-                       }
-                       else
-                       {
-                               po_item_controls($order, $po_line->stock_id);
+                                               _('Remove line from document'));
                        }
-               $total += $line_total;
+               end_row();
+               }
+               else
+               {
+                       po_item_controls($order, $po_line->stock_id);
                }
+               $total += $line_total;
     }
 
        if ($id==-1 && $editable)
index d25cba3ca8a6eae92c6fddfbe295dc9d4a69637b..5a7958d28d9295ba6941b311c6f481dcc2bc4388 100644 (file)
@@ -218,14 +218,11 @@ function handle_add_new_item()
                {
                    foreach ($_SESSION['PO']->line_items as $order_item) 
                    {
-
                        /* do a loop round the items on the order to see that the item
                        is not already on this order */
-                           if (($order_item->stock_id == $_POST['stock_id']) && 
-                               ($order_item->Deleted == false)) 
+                           if (($order_item->stock_id == $_POST['stock_id'])) 
                            {
-                                       $allow_update = false;
-                                       display_error(_("The selected item is already on this order."));
+                                       display_warning(_("The selected item is already on this order."));
                            }
                    } /* end of the foreach loop to look for pre-existing items of the same code */
                }