From 0b3432ec8fb6911304ab652dc34b63e4a7c758de Mon Sep 17 00:00:00 2001 From: Joe Hunt Date: Mon, 15 May 2017 08:25:39 +0200 Subject: [PATCH] 0003862: Straight Line Depreciation value calculation is wrong 0003863: Fixed Assets Valuation Report Includes inactive Items with Valuation 0003864: [Fixed Assets] GL Transactions for Fixed Asset Sales are wrong (patch provided) --- fixed_assets/includes/depreciation.inc | 2 +- includes/db/inventory_db.inc | 14 ++++++ sales/includes/db/sales_delivery_db.inc | 64 ++++++++++++++++--------- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/fixed_assets/includes/depreciation.inc b/fixed_assets/includes/depreciation.inc index e07a93de..b63ad1a8 100644 --- a/fixed_assets/includes/depreciation.inc +++ b/fixed_assets/includes/depreciation.inc @@ -71,7 +71,7 @@ function compute_gl_rows_for_depreciation($item, $no_months, $period) { case 'S': // purchase_cost stores start cost of item $done_months = months_between_dates($item['depreciation_start'], $item['depreciation_date']); - $remaining_months = 100.0/$item['depreciation_rate'] - $done_months; + $remaining_months = 12.0 * 100.0/$item['depreciation_rate'] - $done_months; $value = $item['purchase_cost']*$item['depreciation_rate']/100/12; break; diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index 55e3b687..52c01674 100644 --- a/includes/db/inventory_db.inc +++ b/includes/db/inventory_db.inc @@ -110,6 +110,20 @@ function get_unit_cost($stock_id) return $myrow[0]; } +//-------------------------------------------------------------------------------------- + +function get_purchase_cost($stock_id) +{ + $sql = "SELECT purchase_cost + FROM ".TB_PREF."stock_master + WHERE stock_id=".db_escape($stock_id); + $result = db_query($sql, "The purchase cost cannot be retrieved"); + + $myrow = db_fetch_row($result); + + return $myrow[0]; +} + //-------------------------------------------------------------------------------------- function is_inventory_item($stock_id) diff --git a/sales/includes/db/sales_delivery_db.inc b/sales/includes/db/sales_delivery_db.inc index 3f8ffc87..273de917 100644 --- a/sales/includes/db/sales_delivery_db.inc +++ b/sales/includes/db/sales_delivery_db.inc @@ -101,7 +101,7 @@ function write_sales_delivery(&$delivery,$bo_policy) $mb_flag = get_mb_flag($delivery_line->stock_id); if (is_fixed_asset($mb_flag)) { - $sql = "UPDATE ".TB_PREF."stock_master SET inactive=1 + $sql = "UPDATE ".TB_PREF."stock_master SET inactive=1, material_cost=0 WHERE stock_id=".db_escape($delivery_line->stock_id); db_query($sql,"The cost details for the fixed asset could not be updated"); } @@ -123,27 +123,47 @@ function write_sales_delivery(&$delivery,$bo_policy) $delivery->customer_id, "The sales price GL posting could not be inserted"); } /* insert gl_trans to credit stock and debit cost of sales at standard cost*/ - if (is_inventory_item($delivery_line->stock_id) && $delivery_line->standard_cost != 0) { - - /*first the cost of sales entry*/ - - $delivery_gl_code = $stock_gl_code["cogs_account"]; - if ($delivery->fixed_asset) - $delivery_gl_code = $stock_gl_code["adjustment_account"]; - - add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, - $delivery->document_date, $delivery_gl_code, $dim, $dim2, "", - $delivery_line->standard_cost * $delivery_line->qty_dispatched, - PT_CUSTOMER, $delivery->customer_id, - "The cost of sales GL posting could not be inserted"); - - /*now the stock entry*/ - - add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, - $stock_gl_code["inventory_account"], 0, 0, "", - (-$delivery_line->standard_cost * $delivery_line->qty_dispatched), - PT_CUSTOMER, $delivery->customer_id, - "The stock side of the cost of sales GL posting could not be inserted"); + + if (is_inventory_item($delivery_line->stock_id)) { + // Fixed Assets + if ($delivery->fixed_asset) { + $fa_purchase_cost = get_purchase_cost($delivery_line->stock_id); + $fa_depreciation = $fa_purchase_cost - $delivery_line->standard_cost; + /*first remove depreciation*/ + add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, + $delivery->document_date, $stock_gl_code["adjustment_account"], $dim, $dim2, "", + $fa_depreciation, + PT_CUSTOMER, $delivery->customer_id, + "The cost of sales GL posting could not be inserted"); + /*then remove asset*/ + add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, + $stock_gl_code["inventory_account"], 0, 0, "", + -$fa_purchase_cost, + PT_CUSTOMER, $delivery->customer_id, + "The stock side of the cost of sales GL posting could not be inserted"); + /*finally adjust sales account with the remaining*/ + add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, + $stock_gl_code["sales_account"], 0, 0, "", + ($fa_purchase_cost - $fa_depreciation), + PT_CUSTOMER, $delivery->customer_id, + "The stock side of the cost of sales GL posting could not be inserted"); + } + // Invetory Items + else if ($delivery_line->standard_cost != 0) { + /*first the cost of sales entry*/ + add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, + $delivery->document_date, $stock_gl_code["cogs_account"], $dim, $dim2, "", + $delivery_line->standard_cost * $delivery_line->qty_dispatched, + PT_CUSTOMER, $delivery->customer_id, + "The cost of sales GL posting could not be inserted"); + + /*now the stock entry*/ + add_gl_trans_std_cost(ST_CUSTDELIVERY, $delivery_no, $delivery->document_date, + $stock_gl_code["inventory_account"], 0, 0, "", + (-$delivery_line->standard_cost * $delivery_line->qty_dispatched), + PT_CUSTOMER, $delivery->customer_id, + "The stock side of the cost of sales GL posting could not be inserted"); + } } /* end of if GL and stock integrated and standard cost !=0 */ -- 2.30.2