From: Joe Hunt Date: Thu, 15 Jul 2010 14:16:12 +0000 (+0000) Subject: Changed calculating of cost update (average material price) for better sync. X-Git-Tag: v2.4.2~19^2~806 X-Git-Url: https://delta.frontaccounting.com/gitweb/?a=commitdiff_plain;h=23bbb34883c1d209aa23a51cf0bfb1eae7731d34;p=fa-stable.git Changed calculating of cost update (average material price) for better sync. --- diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 5756b79f..a25d4097 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -19,6 +19,12 @@ Legend: ! -> Note $ -> Affected files +15-Jul-2010 Chaitanya/Joe Hunt +! Changed calculating of cost update (average material price) for better sync. +$ /purchasing/includes/db/grn_db.inc + /purchasing/includes/db/invoice_db.inc + /manufacturing/includes/db/work_orders_db.inc + ------------------------------- Release 2.3 Beta -------------------------------- 28-Jun-2010 Joe Hunt ! Release 2.3 Beta diff --git a/manufacturing/includes/db/work_orders_db.inc b/manufacturing/includes/db/work_orders_db.inc index 8766ffd1..4a442a8b 100644 --- a/manufacturing/includes/db/work_orders_db.inc +++ b/manufacturing/includes/db/work_orders_db.inc @@ -27,12 +27,13 @@ function add_material_cost($stock_id, $qty, $date_) $result = db_query($sql); $myrow = db_fetch($result); $material_cost = $myrow['material_cost']; - $qoh = get_qoh_on_date($stock_id, null, $date_); + //$qoh = get_qoh_on_date($stock_id, null, $date_); + $qoh = get_qoh_on_date($stock_id); if ($qoh < 0) $qoh = 0; if ($qoh + $qty != 0) $material_cost = ($qoh * $material_cost + $qty * $m_cost) / ($qoh + $qty); - $material_cost = round2($material_cost, $dec); + //$material_cost = round2($material_cost, $dec); $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=$material_cost WHERE stock_id=".db_escape($stock_id); db_query($sql,"The cost details for the inventory item could not be updated"); @@ -49,12 +50,13 @@ function add_overhead_cost($stock_id, $qty, $date_, $costs) $result = db_query($sql); $myrow = db_fetch($result); $overhead_cost = $myrow['overhead_cost']; - $qoh = get_qoh_on_date($stock_id, null, $date_); + //$qoh = get_qoh_on_date($stock_id, null, $date_); + $qoh = get_qoh_on_date($stock_id); if ($qoh < 0) $qoh = 0; if ($qoh + $qty != 0) $overhead_cost = ($qoh * $overhead_cost + $qty * $costs) / ($qoh + $qty); - $overhead_cost = round2($overhead_cost, $dec); + //$overhead_cost = round2($overhead_cost, $dec); $sql = "UPDATE ".TB_PREF."stock_master SET overhead_cost=".db_escape($overhead_cost)." WHERE stock_id=".db_escape($stock_id); db_query($sql,"The cost details for the inventory item could not be updated"); @@ -71,12 +73,13 @@ function add_labour_cost($stock_id, $qty, $date_, $costs) $result = db_query($sql); $myrow = db_fetch($result); $labour_cost = $myrow['labour_cost']; - $qoh = get_qoh_on_date($stock_id, null, $date_); + //$qoh = get_qoh_on_date($stock_id, null, $date_); + $qoh = get_qoh_on_date($stock_id); if ($qoh < 0) $qoh = 0; if ($qoh + $qty != 0) $labour_cost = ($qoh * $labour_cost + $qty * $costs) / ($qoh + $qty); - $labour_cost = round2($labour_cost, $dec); + //$labour_cost = round2($labour_cost, $dec); $sql = "UPDATE ".TB_PREF."stock_master SET labour_cost=".db_escape($labour_cost)." WHERE stock_id=".db_escape($stock_id); db_query($sql,"The cost details for the inventory item could not be updated"); @@ -93,12 +96,13 @@ function add_issue_cost($stock_id, $qty, $date_, $costs) $material_cost = $myrow['material_cost']; $dec = user_price_dec(); price_decimal_format($material_cost, $dec); - $qoh = get_qoh_on_date($stock_id, null, $date_); + //$qoh = get_qoh_on_date($stock_id, null, $date_); + $qoh = get_qoh_on_date($stock_id); if ($qoh < 0) $qoh = 0; if ($qoh + $qty != 0) $material_cost = ($qty * $costs) / ($qoh + $qty); - $material_cost = round2($material_cost, $dec); + //$material_cost = round2($material_cost, $dec); $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=material_cost+" .db_escape($material_cost) ." WHERE stock_id=".db_escape($stock_id); diff --git a/purchasing/includes/db/grn_db.inc b/purchasing/includes/db/grn_db.inc index 2e705357..e0284cec 100644 --- a/purchasing/includes/db/grn_db.inc +++ b/purchasing/includes/db/grn_db.inc @@ -38,7 +38,9 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, else $exclude = 0; $cost_adjust = false; - $qoh = get_qoh_on_date($stock_id, null, $date, $exclude); + //$qoh = get_qoh_on_date($stock_id, null, $date, $exclude); + $qoh = get_qoh_on_date($stock_id); + if ($adj_only) { if ($qoh > 0) @@ -55,7 +57,8 @@ function update_average_material_cost($supplier, $stock_id, $price, $qty, $date, if ($qoh + $qty != 0) $material_cost = ($qoh * $material_cost + $qty * $price_in_home_currency) / ($qoh + $qty); } - $material_cost = round2($material_cost, $dec); + //$material_cost = round2($material_cost, $dec); + if ($cost_adjust) // new 2010-02-10 adjust_deliveries($stock_id, $material_cost, $date); $sql = "UPDATE ".TB_PREF."stock_master SET material_cost=".db_escape($material_cost)." diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index c584115c..de5e8f0a 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -108,7 +108,8 @@ function get_diff_in_home_currency($supplier, $old_date, $date, $amount1, $amoun $ex_rate = get_exchange_rate_to_home_currency($currency, $date); $amount2 = $amount2 / $ex_rate; $diff = $amount2 - $amount1; - return round2($diff, $dec); + //return round2($diff, $dec); + return $diff; } //---------------------------------------------------------------------------------------- @@ -203,9 +204,12 @@ 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 = (is_inventory_item($entered_grn->item_code) ? $stock_gl_code["inventory_account"] : $stock_gl_code["cogs_account"]); - $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $iv_act, + $total += add_gl_trans_supplier($trans_type, $invoice_id, $date_, $supplier_accounts["purchase_account"], $stock_gl_code['dimension_id'], $stock_gl_code['dimension2_id'], - $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id); + $entered_grn->this_quantity_inv * $line_taxfree, $supp_trans->supplier_id); + /*$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) { @@ -227,13 +231,31 @@ 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]); $diff = get_diff_in_home_currency($supp_trans->supplier_id, $old_date, $date_, $old_price, - $entered_grn->chg_price); + $entered_grn->chg_price); + // always return due to change in currency. + /*$mat_cost = update_average_material_cost(null, $entered_grn->item_code, + $diff, $entered_grn->this_quantity_inv, $old_date, true); */ $mat_cost = update_average_material_cost(null, $entered_grn->item_code, - $diff, $entered_grn->this_quantity_inv, $old_date, true); + $diff, $entered_grn->this_quantity_inv, null, true); + + //Add GL transaction for GRN Provision in case of difference + 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, + $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"); + } + // added 2008-12-08 Joe Hunt. Update the purchase data table add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price); - $deliveries = get_deliveries_between($entered_grn->item_code, $old_date, Today()); // extend the period, if invoice is before any deliveries. + /*$deliveries = get_deliveries_between($entered_grn->item_code, $old_date, Today()); // extend the period, if invoice is before any deliveries. if ($deliveries[0] != 0) // have deliveries been done during the period? { $deliveries[1] /= $deliveries[0]; @@ -254,7 +276,7 @@ function add_supp_invoice($supp_trans, $invoice_no=0) // do not receive as ref b "The general ledger transaction could not be added for the price variance of the inventory item"); } update_stock_move_pid(ST_CUSTDELIVERY, $entered_grn->item_code, $old_date, $date_, 0, $mat_cost); - } + } */ update_stock_move_pid(ST_SUPPRECEIVE, $entered_grn->item_code, $old_date, $old_date, $supp_trans->supplier_id, $mat_cost); //} }