Bug [0000075] Cost Update problems still (voiding supplier invoice). Can't remove...
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 18 Oct 2008 21:27:41 +0000 (21:27 +0000)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Sat, 18 Oct 2008 21:27:41 +0000 (21:27 +0000)
CHANGELOG.txt
purchasing/includes/db/grn_db.inc
purchasing/includes/db/invoice_db.inc
purchasing/supplier_invoice_grns.php

index 81be36aae0e931feeab665ecb67224f01edf1f01..9c0433c9fb587ad145e47aee20147037b035e907 100644 (file)
@@ -19,6 +19,13 @@ Legend:
 ! -> Note
 $ -> Affected files
 
+18-Oct-2008 Joe Hunt
+# Bug [0000075] Cost Update problems still (voiding supplier invoice). Can't remove GRNs from
+  Yet to be invoiced (supplier invoice). Can now be done with admin access.
+$ /purchasing/supplier_invoice_grns.php
+  /purchasing/includes/db/grn_db.inc
+  /purchasing/includes/db/invoice_db.inc
+  
 15-Oct-2008 Joe Hunt
 # Bug [0000074] Marked items are overdue. For Filled (fully delivered) Sales Order
 $ /sales/inquiry/sales_orders_view.php
index 3b5443f6db0882c0a01ae5f054c7be7273031dc9..1e080be792fc4bc2d654677e702981c985e9158a 100644 (file)
@@ -136,6 +136,13 @@ function get_grn_batch_from_item($item)
        return $row[0];
 }
 
+function get_grn_batch($grn)
+{
+       $sql = "SELECT * FROM ".TB_PREF."grn_batch WHERE id=$grn";
+       $result = db_query($sql, "Could not retreive GRN batch id");
+       return db_fetch($result);
+}
+
 function set_grn_item_credited(&$entered_grn, $supplier, $transno, $date)
 {
        $mcost = update_average_material_cost($supplier, $entered_grn->item_code,
index 59366cceb172c64cf839cbe0ee25091adb961f7a..a99dd5d0f16f0ed7c89ba1f55c28b3d910ef88b2 100644 (file)
@@ -361,8 +361,19 @@ function void_supp_invoice($type, $type_no)
         {
                if (strlen($details_row["grn_item_id"]) > 0) // it can be empty for GL items
                {
-                               update_supp_received_items_for_invoice($details_row["grn_item_id"],
-                                       $details_row["po_detail_item_id"], -$details_row["quantity"]);
+                       // Changed 2008-10-17 by Joe Hunt to get the avg. material cost updated
+                               /*update_supp_received_items_for_invoice($details_row["grn_item_id"],
+                                       $details_row["po_detail_item_id"], -$details_row["quantity"]); 
+                                       No, this will catch the GRN for invoicing again. Better leave as is. */
+                               $supp = get_supp_trans($type_no, $type);
+                               $old_mat_cost = get_standard_cost($details_row["stock_id"]);
+                               update_average_material_cost($supp["supplier_id"], $details_row["stock_id"],
+                                       $details_row["FullUnitPrice"], -$details_row["quantity"], Today());
+                               $batch = get_grn_batch_from_item($details_row["grn_item_id"]);  
+                               $grn = get_grn_batch($batch);
+       
+               add_stock_move(25, $details_row["stock_id"], $batch, $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+                       -$details_row["quantity"], $old_mat_cost, $supp["supplier_id"], 1, $details_row["FullUnitPrice"]);
                }
         }
        }
index c334a699c31bbf6b517dd90072acf5e8945e6469..11c8a6363f8bf831ca8fbabcd6a6c0414ff05a15 100644 (file)
@@ -120,29 +120,32 @@ hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to
 echo "<hr>";
 
 //-----------------------------------------------------------------------------------------
+start_form(false, true); // 2008-10-18 Joe Hunt. Moved form outside function
 
 function display_grn_items_for_selection()
 {
        global $table_style;
 
+       div_start('grn_table'); // 2008-10-18 Joe Hunt Moved up a bit to compute num-rows = 0
        $result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, true);
 
     if (db_num_rows($result) == 0)
     {
        display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
-       end_page();
-       exit;
+               div_end(); // Changed 2008-10-18 Joe Hunt
+       return;
     }
-
+    
     /*Set up a table to show the outstanding GRN items for selection */
-    start_form(false, true);
 
     display_heading2(_("Items Received Yet to be Invoiced"));
-       div_start('grn_table');
+       //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"),
        _("Uninvoiced Quantity"), _("Order Price"), _("Total"));
+    if ($_SESSION["wa_current_user"]->access == 2)     // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+       $th[] = "";     
     table_header($th);
     $i = $k = 0;
 
@@ -176,6 +179,8 @@ function display_grn_items_for_selection()
             amount_cell($myrow["unit_price"]);
             amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
                           user_price_dec()));
+               if ($_SESSION["wa_current_user"]->access == 2)  // Added 2008-10-18 by Joe Hunt. Only admins can remove GRNs
+                       submit_cells('void_item_id'.$myrow["id"], _("Remove"), '', '', true);
                        end_row();
 
                $i++;
@@ -192,23 +197,53 @@ function display_grn_items_for_selection()
 }
 
 //-----------------------------------------------------------------------------------------
-if (find_submit('grn_item_id') || get_post('AddGRNToTrans'))
+$id = find_submit('grn_item_id');
+$id2 = find_submit('void_item_id');
+if ($id != -1 || id2 != -1 || get_post('AddGRNToTrans'))
 {
        $Ajax->activate('grn_selector');
 }
-if (get_post('AddGRNToTrans'))
+if (get_post('AddGRNToTrans') || $id2 != -1)
 {
        $Ajax->activate('grn_table');
        $Ajax->activate('grn_items');
 }
 
+if ($_SESSION["wa_current_user"]->access == 2)
+{
+       if ($id2 != -1) // Added section 2008-10-18 Joe Hunt for voiding delivery lines
+       {
+               begin_transaction();
+               
+               $myrow = get_grn_item_detail($id2);
+
+               $grn = get_grn_batch($myrow['grn_batch_id']);
+
+           $sql = "UPDATE ".TB_PREF."purch_order_details
+                       SET quantity_received = qty_invoiced, quantity_ordered = qty_invoiced WHERE po_detail_item = ".$myrow["po_detail_item"];
+           db_query($sql, "The quantity invoiced of the purchase order line could not be updated");
+
+           $sql = "UPDATE ".TB_PREF."grn_items
+               SET qty_recd = quantity_inv WHERE id = ".$myrow["id"];
+               db_query($sql, "The quantity invoiced off the items received record could not be updated");
+       
+               update_average_material_cost($grn["supplier_id"], $myrow["item_code"],
+                       $myrow["unit_price"], -$myrow["QtyOstdg"], Today());
+
+               add_stock_move(25, $myrow["item_code"], $myrow['grn_batch_id'], $grn['loc_code'], sql2date($grn["delivery_date"]), "",
+                       -$myrow["QtyOstdg"], $myrow['std_cost_unit'], $grn["supplier_id"], 1, $myrow['unit_price']);
+                       
+               commit_transaction();
+       }               
+}
+
 display_grn_items_for_selection();
 
 //-----------------------------------------------------------------------------------------
 
 div_start('grn_selector');
 
-$id = find_submit('grn_item_id');
+//$id = find_submit('grn_item_id');
 if ($id != -1)
 {