From a9e2c0e710a5431ce3c31ef89d4c94bf69538238 Mon Sep 17 00:00:00 2001 From: Janusz Dobrowolski Date: Tue, 13 Oct 2015 20:41:39 +0200 Subject: [PATCH] Fixed net value calculations for GRN leading to unbalanced clearing account. --- purchasing/includes/db/grn_db.inc | 4 ++-- purchasing/includes/po_class.inc | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 4d85cc9f..f973af91 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -119,7 +119,7 @@ function add_grn(&$po) 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, '', 0, $order_line->stock_id); + $order_line->taxfree_charge_value($po), $po->supplier_id, '', 0, $order_line->stock_id); update_average_material_cost($po->supplier_id, $order_line->stock_id, $order_line->price, $order_line->receive_qty, $date_); } @@ -145,7 +145,7 @@ function add_grn(&$po) /* Update location stock records - NB a po cannot be entered for a service/kit parts done automatically */ add_stock_move(ST_SUPPRECEIVE, $order_line->stock_id, $grn, $po->Location, $date_, "", $order_line->receive_qty, $order_line->standard_cost, - $po->supplier_id, 1, $order_line->taxfree_charge_price($po)); + $po->supplier_id, 1, $order_line->taxfree_charge_value($po)/$order_line->receive_qty); } /*quantity received is != 0 */ } /*end of order_line loop */ diff --git a/purchasing/includes/po_class.inc b/purchasing/includes/po_class.inc index f9f75aac..dff291a7 100644 --- a/purchasing/includes/po_class.inc +++ b/purchasing/includes/po_class.inc @@ -236,10 +236,20 @@ class po_line_details $this->standard_cost =0; $this->grn_item_id = $grn_item_id; } - + + // Deprecated, use with care. If you need line value as it is calculated in invoice, use taxfree_charge_value below. function taxfree_charge_price($po) { - return get_tax_free_price_for_item($this->stock_id, $this->price, + return get_tax_free_price_for_item($this->stock_id, $this->price, + $po->tax_group_id, $po->tax_included, $po->tax_group_array); + } + + // + // GRN line tax free value. + // + function taxfree_charge_value($po) + { + return get_tax_free_price_for_item($this->stock_id, $this->receive_qty*$this->price, $po->tax_group_id, $po->tax_included, $po->tax_group_array); } } -- 2.30.2