From a5b6e00b46702e6a74bf57b5fea7c0476901d4be Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Fri, 31 Dec 2010 11:43:21 +0000 Subject: [PATCH] Fixed bug in earlier invoice_db (GRN Provision should have only one row) Only GRN Clearring on stock items. --- CHANGELOG.txt | 13 +++++++++ purchasing/includes/db/grn_db.inc | 22 +++++++--------- purchasing/includes/db/invoice_db.inc | 38 ++++++++++++++++++--------- 3 files changed, 48 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 6b8e1ca..a691fa5 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,19 @@ Legend: ! -> Note $ -> Affected files +31-Dec-2010 Joe Hunt +# Fixed bug in earlier invoice_db (GRN Provision should have only one row) + Only GRN Clearring on stock items. +$ /purchasing/includes/db/grn_db.inc + /purchasing/includes/db/invoice_db.inc +! Changed so supplier credit note items shows the invoice price/not grn price +$ /purchasing/includes/db/grn_db.inc + /invoice_ui.inc ++ Added link for viewing GL Delivery if clearing account +$ /purchasing/po_receive_items.php +# Bug. $n undefined in /admin/gl_setup.php +$ /admin/gl_setup.php + 30-Dec-2010 Janusz Dobrowolski + Added option for using GRN Clearing Account for yet non invoiced GRNs. $ /purchasing/includes/po_class.inc diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 7b66d03..691ae73 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -92,7 +92,6 @@ function add_grn(&$po) $clearing_act = get_company_pref('grn_clearing_act'); if ($clearing_act) { // otherwise GRN clearing account is not used $total = 0; - $supplier_accounts = get_supplier_accounts($po->supplier_id); } foreach ($po->line_items as $line_no => $order_line) { @@ -100,19 +99,17 @@ function add_grn(&$po) { $stock_gl_code = get_stock_gl_code($order_line->stock_id); - if($clearing_act) { - $inv_act = (is_inventory_item($order_line->stock_id) ? $stock_gl_code["inventory_account"] : - ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"])); - - $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $inv_act, - $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], - $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id); - } /*Update sales_order_details for the new quantity received and the standard cost used for postings to GL and recorded in the stock movements for FIFO/LIFO stocks valuations*/ - //------------------- update average material cost ------------------------------------------ Joe Hunt Mar-03-2008 + //------------------- update average material cost and clearing account ----- Joe Hunt Mar-03-2008 if (is_inventory_item($order_line->stock_id)) + { + if ($clearing_act) + $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $stock_gl_code["inventory_account"], + $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], + $order_line->receive_qty * $order_line->taxfree_charge_price($po), $po->supplier_id); update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price, $order_line->receive_qty, $date_); + } //---------------------------------------------------------------------------------------------------------------- if ($order_line->qty_received == 0) { @@ -139,9 +136,9 @@ function add_grn(&$po) } /*quantity received is != 0 */ } /*end of order_line loop */ - if ($clearing_act) { + if ($clearing_act && $total != 0.0) { $total += add_gl_trans_supplier(ST_SUPPRECEIVE, $grn, $date_, $clearing_act, - 0, 0, -$total, $po->supplier_id); + 0, 0, -$total, null); } $Refs->save(ST_SUPPRECEIVE, $grn, $po->reference); @@ -247,6 +244,7 @@ function get_grn_items($grn_batch_id=0, $supplier_id="", $outstanding_only=false { $sql = "SELECT ".TB_PREF."grn_batch.*, ".TB_PREF."grn_items.*, " .TB_PREF."purch_order_details.unit_price," + .TB_PREF."purch_order_details.act_price," .TB_PREF."purch_order_details.quantity_ordered," .TB_PREF."purch_order_details.std_cost_unit, units FROM ".TB_PREF."grn_batch, ".TB_PREF."grn_items, " diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 8b7afee..a8b6e0d 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -203,16 +203,19 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b $line_tax = $entered_grn->full_charge_price($supp_trans->tax_group_id) - $line_taxfree; $stock_gl_code = get_stock_gl_code($entered_grn->item_code); - $iv_act = $clearing_act ? $clearing_act : (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : + if ($trans_type == ST_SUPPCREDIT) + { + $iv_act = (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"])); - - $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, - $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], - $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id); - - // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt - if ($trans_type == ST_SUPPINVOICE) + $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, + $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], + $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id); + } + else { + // -------------- if price changed since po received. 16 Aug 2008 Joe Hunt + $iv_act = is_inventory_item($entered_grn->item_code) ? ($clearing_act ? $clearing_act : $stock_gl_code["inventory_account"]) : + ($supplier_accounts["purchase_account"] ? $supplier_accounts["purchase_account"] : $stock_gl_code["cogs_account"]); $old = update_supp_received_items_for_invoice($entered_grn->id, $entered_grn->po_detail_item, $entered_grn->this_quantity_inv, $entered_grn->chg_price); // Since the standard cost is always calculated on basis of the po unit_price, @@ -230,8 +233,17 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b //{ //$diff = $entered_grn->chg_price - $old_price; $old_date = sql2date($old[1]); - if (is_inventory_item($entered_grn->item_code)) + if (!is_inventory_item($entered_grn->item_code)) + $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, + $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], + $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id); + else { + $currency = get_supplier_currency($supp_trans->supplier_id); + $ex_rate = get_exchange_rate_from_home_currency($currency, $old_date); + $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, + $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], + $entered_grn->this_quantity_inv * $old_price, $supp_trans->supplier_id, "", $ex_rate); $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price, $entered_grn->chg_price); @@ -245,14 +257,14 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b if (($diff * $entered_grn->this_quantity_inv) != 0 ) { $diff_amt = $diff * $entered_grn->this_quantity_inv; - add_gl_trans($trans_type, $invoice_id, $date_, $iv_act, + $total += add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["inventory_account"], $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], 'GRN Provision', $diff_amt, null, null, null, "The general ledger transaction could not be added for the GRN of the inventory item"); - add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"], - 0, 0, 'GRN Provision', -$diff_amt, null, null, null, - "The general ledger transaction could not be added for the GRN of the inventory item"); + //add_gl_trans($trans_type, $invoice_id, $date_, $stock_gl_code["cogs_account"], + // 0, 0, 'GRN Provision', -$diff_amt, null, null, null, + // "The general ledger transaction could not be added for the GRN of the inventory item"); } } // added 2008-12-08 Joe Hunt. Update the purchase data table -- 2.30.2