[0000609] Invalid costing results when changing PO rate and [0000635] Over received...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 15 Mar 2011 13:20:46 +0000 (14:20 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Tue, 15 Mar 2011 13:20:46 +0000 (14:20 +0100)
purchasing/includes/db/grn_db.inc
purchasing/includes/db/po_db.inc
purchasing/includes/ui/po_ui.inc

index f418ff3eeb4dc68c38ca16d60f98d2caa5dedf07..f76f6c75fcdb8ffb6374476bccc1c9e62f281c81 100644 (file)
@@ -121,11 +121,12 @@ function add_grn(&$po)
                        add_or_update_purchase_data($po->supplier_id, $order_line->stock_id, $order_line->price, 
                                $order_line->item_description); 
 
-                       /*Need to insert a grn item */
-
+                       /*Need to insert a grn item */ // also need to check for over-receive.(within allowance)
+                       if ($order_line->receive_qty + $order_line->qty_received > $order_line->quantity)
+                               $order_line->quantity = $order_line->receive_qty + $order_line->qty_received;
                        $grn_item = add_grn_detail_item($grn, $order_line->po_detail_rec,
                                $order_line->stock_id, $order_line->item_description,
-                               $order_line->standard_cost,     $order_line->receive_qty, $order_line->price);
+                               $order_line->standard_cost,     $order_line->receive_qty, $order_line->price, $order_line->quantity);
 
                        $po->line_items[$line_no]->grn_item_id = $grn_item;
                        /* Update location stock records - NB  a po cannot be entered for a service/kit parts done automatically */
@@ -169,11 +170,12 @@ function add_grn_batch($po_number, $supplier_id, $reference, $location, $date_)
 //-------------------------------------------------------------------------------------------------------------
 
 function add_grn_detail_item($grn_batch_id, $po_detail_item, $item_code, $description, $standard_unit_cost,
-       $quantity_received, $price)
+       $quantity_received, $price, $quantity)
 {
        $sql = "UPDATE ".TB_PREF."purch_order_details
         SET quantity_received = quantity_received + ".db_escape($quantity_received).",
         std_cost_unit=".db_escape($standard_unit_cost).",
+        quantity_ordered=".db_escape($quantity).",
         act_price=".db_escape($price)."
         WHERE po_detail_item = ".db_escape($po_detail_item);
 
index ebd2c7241e177f0dfe0f576bb7728a60e31520e6..adab9ad31f67b534283a7bb6f18303fe8c1262d0 100644 (file)
@@ -98,14 +98,15 @@ function update_po(&$po_obj)
     foreach ($po_obj->line_items as $po_line)
     {
        $sql = "INSERT INTO ".TB_PREF."purch_order_details (po_detail_item, order_no, item_code, 
-               description, delivery_date, unit_price, quantity_ordered) VALUES ("
+               description, delivery_date, unit_price, quantity_ordered, quantity_received) 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_escape($po_line->quantity) . ", "
+                       .db_escape($po_line->qty_received) . ")";
                
                db_query($sql, "One of the purchase order detail records could not be updated");
     }
index c7f8d2a926ed79a8fce27c8ca2fb13931c7f78cf..d0aa40acb3edab8a2321bafad10ab610ce6df20f 100644 (file)
@@ -423,8 +423,11 @@ function po_item_controls(&$order, &$rowcounter, $line_no=-1)
        label_cell($_POST['units'], '', 'units');
        if ($order->trans_type == ST_PURCHORDER)
                date_cells(null, 'req_del_date', '', null, 0, 0, 0);
-       if ($qty_rcvd > 0)      
+       if ($qty_rcvd > 0)
+       {
                amount_decimal_cell($_POST['price']);
+               hidden('price', $_POST['price']);
+       }       
        else    
                amount_cells(null, 'price', null, null, null, $dec2);