From: Joe Hunt Date: Sat, 18 Oct 2008 21:27:41 +0000 (+0000) Subject: Bug [0000075] Cost Update problems still (voiding supplier invoice). Can't remove... X-Git-Tag: 2.3-final~1410 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=999571881ec99a9b927fcf35d3fecbf45b3b68e7;p=fa-stable.git 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. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 81be36aa..9c0433c9 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 3b5443f6..1e080be7 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -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, diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 59366cce..a99dd5d0 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -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"]); } } } diff --git a/purchasing/supplier_invoice_grns.php b/purchasing/supplier_invoice_grns.php index c334a699..11c8a636 100644 --- a/purchasing/supplier_invoice_grns.php +++ b/purchasing/supplier_invoice_grns.php @@ -120,29 +120,32 @@ hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to echo "
"; //----------------------------------------------------------------------------------------- +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) {