From: Joe Hunt Date: Mon, 7 Dec 2015 22:42:11 +0000 (+0100) Subject: Fixed Assets fixes, bugs and improvements. X-Git-Tag: v2.4.2~19^2~113 X-Git-Url: https://delta.frontaccounting.com/gitweb/?p=fa-stable.git;a=commitdiff_plain;h=f0e1edfccbf3608463c9da99b40f9c65fd298bb3 Fixed Assets fixes, bugs and improvements. --- diff --git a/fixed_assets/includes/depreciation.inc b/fixed_assets/includes/depreciation.inc index ab36edd3..cc539079 100644 --- a/fixed_assets/includes/depreciation.inc +++ b/fixed_assets/includes/depreciation.inc @@ -63,20 +63,20 @@ function compute_gl_rows_for_depreciation($item, $no_months, $period) { switch ($item['depreciation_method']) { case 'D': - $line_value = $item['actual_cost']*$item['depreciation_rate']/100/12; + $line_value = $item['purchase_cost']*$item['depreciation_rate']/100/12; $value = $item['material_cost'] * $item['depreciation_rate'] * $item['depreciation_factor']/100/12; if ($value < $line_value) $value = $line_value; break; case 'S': // actual_cost stores start cost of item - $value = $item['actual_cost']*$item['depreciation_rate']/100/12; + $value = $item['purchase_cost']*$item['depreciation_rate']/100/12; break; case 'N': $N = $item['depreciation_rate']; $done_years = months_between_dates($item['depreciation_start'], $item['depreciation_date'])/12; - $value = $item['material_cost']* ($N-$done_years)/($N*($N+1)/2)/12; + $value = $item['purchase_cost']* ($N-$done_years)/($N*($N+1)/2)/12; break; case 'O': diff --git a/fixed_assets/includes/fixed_assets_db.inc b/fixed_assets/includes/fixed_assets_db.inc index 7f30d8db..14dc3860 100644 --- a/fixed_assets/includes/fixed_assets_db.inc +++ b/fixed_assets/includes/fixed_assets_db.inc @@ -45,7 +45,7 @@ function process_fixed_asset_depreciation($stock_id, $gl_rows, $refline, $memo_) if (empty($memo_)) $cart->memo_ = sprintf(_("Fixed asset has been deprecated by the value of %s"), - number_format2($value_of_change, 2)); + number_format2($value_of_change, user_price_dec())); else $cart->memo_ = $memo_; @@ -118,13 +118,6 @@ function get_fixed_asset_purchase($stock_id) { //-------------------------------------------------------------------------------------------------- -function get_initial_price($stock_id) { - $row = get_fixed_asset_move($stock_id, ST_SUPPRECEIVE); - return $row['price']; -} - -//-------------------------------------------------------------------------------------------------- - function get_fixed_asset_class($id) { $sql="SELECT * FROM ".TB_PREF."stock_fa_class WHERE fa_class_id=".db_escape($id); @@ -140,7 +133,7 @@ function get_sql_for_fixed_assets($show_inactive = false) { $sql = "SELECT s.stock_id, c.description, s.units, s.description as name, s.depreciation_rate, s.depreciation_method, s.inactive, rcv.tran_date as purchase_date, rcv.trans_no as purchase_no, - adj.tran_date as disposal_date, adj.type as disposal_type, adj.trans_no as disposal_no, s.material_cost, s.last_cost, s.depreciation_factor + adj.tran_date as disposal_date, adj.type as disposal_type, adj.trans_no as disposal_no, s.material_cost, s.purchase_cost, s.depreciation_factor FROM ".TB_PREF."stock_master s" ." LEFT JOIN ".TB_PREF."stock_moves rcv ON rcv.stock_id=s.stock_id AND rcv.type=".ST_SUPPRECEIVE ." LEFT JOIN ".TB_PREF."stock_moves adj ON adj.stock_id=s.stock_id AND adj.type IN(".ST_INVADJUST.",".ST_CUSTDELIVERY.")" diff --git a/fixed_assets/inquiry/stock_inquiry.php b/fixed_assets/inquiry/stock_inquiry.php index 93c79446..c456d792 100644 --- a/fixed_assets/inquiry/stock_inquiry.php +++ b/fixed_assets/inquiry/stock_inquiry.php @@ -117,12 +117,12 @@ function disposal_link($row) function amount_link($row) { - return price_format($row['last_cost']); + return price_format($row['purchase_cost']); } function depr_link($row) { - return price_format($row['last_cost'] - $row['material_cost']); + return price_format($row['purchase_cost'] - $row['material_cost']); } function balance_link($row) @@ -146,9 +146,9 @@ $cols = array( _("Method") => array('fun' => 'depr_method_title'), _("Status") => array('fun' => 'status_title'), _("Purchased") => array('fun' => 'purchase_link'), - _("Amount") => array('align'=>'right', 'fun' => 'amount_link'), + _("Initial") => array('align'=>'right', 'fun' => 'amount_link'), _("Depreciations") => array('align'=>'right', 'fun' => 'depr_link'), - _("Balance") => array('align'=>'right', 'fun' => 'balance_link'), + _("Current") => array('align'=>'right', 'fun' => 'balance_link'), _("Liquidation or Sale") => array('align' => 'center', 'fun' => 'disposal_link'), //array('insert'=>true, 'fun'=>'gl_view'), //array('insert'=>true, 'fun'=>'rm_link'), diff --git a/includes/db/inventory_db.inc b/includes/db/inventory_db.inc index c01e4eb4..ad9fbb7b 100644 --- a/includes/db/inventory_db.inc +++ b/includes/db/inventory_db.inc @@ -309,6 +309,23 @@ function get_stock_gl_code($stock_id) return db_fetch($get); } +function get_purchase_value($stock_id) +{ + $sql = "SELECT purchase_cost FROM + ".TB_PREF."stock_master WHERE stock_id = ".db_escape($stock_id); + + $result = db_query($sql,"retreive stock purchase price"); + $row = db_fetch_row($result); + return $row[0]; +} + +function update_purchase_value($stock_id, $price) +{ + $price = round2($price, user_price_dec()); + $sql = "UPDATE ".TB_PREF."stock_master SET purchase_cost=".db_escape($price) + ." WHERE stock_id=".db_escape($stock_id); + db_query($sql, "The stock master purchase_cost cannot be updated"); +} //----------------------------------------------------------------------------------------- function handle_negative_inventory($stock_id, $quantity, $standard_cost, $date_) diff --git a/includes/sysnames.inc b/includes/sysnames.inc index 80fab811..507bd698 100644 --- a/includes/sysnames.inc +++ b/includes/sysnames.inc @@ -44,8 +44,8 @@ $systypes_array = array ( ); $fa_systypes_array = array ( - ST_INVADJUST => _("FA Disposal"), - ST_COSTUPDATE => _("FA Revaluation"), + ST_INVADJUST => _("Fixed Assets Disposal"), + ST_COSTUPDATE => _("Fixed Assets Revaluation"), ); $type_shortcuts = array( diff --git a/includes/ui/items_cart.inc b/includes/ui/items_cart.inc index 858b05be..92cc1a46 100644 --- a/includes/ui/items_cart.inc +++ b/includes/ui/items_cart.inc @@ -481,7 +481,7 @@ class line_item $this->item_description = $description; if ($standard_cost == null) - $this->standard_cost = $item_row["actual_cost"]; + $this->standard_cost = $item_row["purchase_cost"]; else $this->standard_cost = $standard_cost; diff --git a/inventory/adjustments.php b/inventory/adjustments.php index 9dbe1ea6..ba5dcf49 100644 --- a/inventory/adjustments.php +++ b/inventory/adjustments.php @@ -47,7 +47,7 @@ if (isset($_GET['AddedID'])) $row = db_fetch($result); if (is_fixed_asset($row['mb_flag'])) { - display_notification_centered(_("FA disposal has been processed")); + display_notification_centered(_("Fixed Assets disposal has been processed")); display_note(get_trans_view_str($trans_type, $trans_no, _("&View this disposal"))); display_note(get_gl_view_str($trans_type, $trans_no, _("View the GL &Postings for this Disposal")), 1, 0); diff --git a/inventory/includes/item_adjustments_ui.inc b/inventory/includes/item_adjustments_ui.inc index 1331f62f..e2f585b6 100644 --- a/inventory/includes/item_adjustments_ui.inc +++ b/inventory/includes/item_adjustments_ui.inc @@ -91,7 +91,7 @@ function display_adjustment_items($title, &$order) amount_decimal_cell($stock_item->standard_cost); if ($order->fixed_asset) { - $price = get_initial_price($stock_item->stock_id); + $price = get_purchase_value($stock_item->stock_id); amount_cell($price); } else amount_cell($stock_item->standard_cost * $stock_item->quantity); @@ -166,7 +166,7 @@ function adjustment_edit_item_controls(&$order, $line_no=-1) } if ($order->fixed_asset) { - hidden('qty', 1); + hidden('qty', -1); qty_cell(1, false, 0); } else qty_cells(null, 'qty', $_POST['qty'], null, null, $dec); @@ -178,7 +178,7 @@ function adjustment_edit_item_controls(&$order, $line_no=-1) that still has to be submitted in the form */ hidden('std_cost'); label_cell($_POST['std_cost'], "nowrap align=right ", 'std_cost_view'); - $price = get_initial_price($_POST['stock_id']); + $price = get_purchase_value($_POST['stock_id']); amount_cell($price, false, '', 'initial_price'); } else { //amount_cells(null, 'std_cost', $_POST['std_cost']); diff --git a/inventory/inquiry/stock_movements.php b/inventory/inquiry/stock_movements.php index f9ef425d..24c12e7c 100644 --- a/inventory/inquiry/stock_movements.php +++ b/inventory/inquiry/stock_movements.php @@ -27,7 +27,7 @@ if (user_use_date_picker()) if (isset($_GET['FixedAsset'])) { $page_security = 'SA_ASSETSTRANSVIEW'; $_POST['fixed_asset'] = 1; - $_SESSION['page_title'] = _($help_context = "FA Item Movement"); + $_SESSION['page_title'] = _($help_context = "Fixed Assets Movement"); } else { $_SESSION['page_title'] = _($help_context = "Inventory Item Movement"); } diff --git a/inventory/manage/items.php b/inventory/manage/items.php index c69c4854..21e2ab7a 100644 --- a/inventory/manage/items.php +++ b/inventory/manage/items.php @@ -21,7 +21,7 @@ if (user_use_date_picker()) if (isset($_GET['FixedAsset'])) { $page_security = 'SA_ASSET'; - $_SESSION['page_title'] = _($help_context = "FA Items"); + $_SESSION['page_title'] = _($help_context = "Fixed Assets"); $_POST['mb_flag'] = 'F'; $_POST['fixed_asset'] = 1; } @@ -342,7 +342,7 @@ function item_settings(&$stock_id, $new_item) $_POST['depreciation_date'] = sql2date($myrow['depreciation_date']); $_POST['fa_class_id'] = $myrow['fa_class_id']; $_POST['material_cost'] = $myrow['material_cost']; - $_POST['last_cost'] = $myrow['last_cost']; + $_POST['purchase_cost'] = $myrow['purchase_cost']; $_POST['sales_account'] = $myrow['sales_account']; $_POST['inventory_account'] = $myrow['inventory_account']; @@ -521,9 +521,9 @@ function item_settings(&$stock_id, $new_item) table_section_title(_("Values")); if (!$new_item) { hidden('material_cost'); - hidden('last_cost'); - label_row(_("Amount").":", price_format($_POST['last_cost']), "", "align='right'"); - label_row(_("Depreciations").":", price_format($_POST['last_cost'] - $_POST['material_cost']), "", "align='right'"); + hidden('purchase_cost'); + label_row(_("Initial Value").":", price_format($_POST['purchase_cost']), "", "align='right'"); + label_row(_("Depreciations").":", price_format($_POST['purchase_cost'] - $_POST['material_cost']), "", "align='right'"); label_row(_("Current Value").':', price_format($_POST['material_cost']), "", "align='right'"); } } diff --git a/inventory/transfers.php b/inventory/transfers.php index 0143b0b7..3cbc3c2c 100644 --- a/inventory/transfers.php +++ b/inventory/transfers.php @@ -29,7 +29,7 @@ if (user_use_date_picker()) if (isset($_GET['NewTransfer'])) { if (isset($_GET['FixedAsset'])) { $page_security = 'SA_ASSETTRANSFER'; - $_SESSION['page_title'] = _($help_context = "FA Location Transfers"); + $_SESSION['page_title'] = _($help_context = "Fixed Assets Location Transfers"); } else { $_SESSION['page_title'] = _($help_context = "Inventory Location Transfers"); @@ -54,7 +54,7 @@ if (isset($_GET['AddedID'])) $itm = db_fetch(get_stock_transfer_items($_GET['AddedID'])); if (is_fixed_asset($itm['mb_flag'])) - hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another FA Item Transfer"), "NewTransfer=1&FixedAsset=1"); + hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Fixed Assets Transfer"), "NewTransfer=1&FixedAsset=1"); else hyperlink_params($_SERVER['PHP_SELF'], _("Enter &Another Inventory Transfer"), "NewTransfer=1"); diff --git a/purchasing/includes/db/invoice_db.inc b/purchasing/includes/db/invoice_db.inc index 372aca3c..7488e178 100644 --- a/purchasing/includes/db/invoice_db.inc +++ b/purchasing/includes/db/invoice_db.inc @@ -354,7 +354,7 @@ function add_supp_invoice(&$supp_trans) } add_or_update_purchase_data($supp_trans->supplier_id, $entered_grn->item_code, $entered_grn->chg_price); } - + update_purchase_value($entered_grn->item_code, $entered_grn->chg_price * $ex_rate); add_supp_invoice_item($trans_type, $invoice_id, $entered_grn->item_code, $entered_grn->item_description, 0, $entered_grn->chg_price, $line_tax/$entered_grn->this_quantity_inv, $entered_grn->this_quantity_inv, $entered_grn->id, $entered_grn->po_detail_item, ""); diff --git a/reporting/rep451.php b/reporting/rep451.php index fe712111..d02db044 100644 --- a/reporting/rep451.php +++ b/reporting/rep451.php @@ -66,7 +66,7 @@ function print_fixed_assets_valuation_report() $cols = array(0, 75, 225, 250, 350, 450, 515); - $headers = array(_('Class'), '', _('UOM'), _('Amount'), _('Depreciations'), _('Balance')); + $headers = array(_('Class'), '', _('UOM'), _('Initial'), _('Depreciations'), _('Current')); $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right'); @@ -113,8 +113,8 @@ function print_fixed_assets_valuation_report() if ($detail) $rep->NewLine(); } - $UnitCost = $trans['last_cost']; - $Depreciation = $trans['last_cost'] - $trans['material_cost'];; + $UnitCost = $trans['purchase_cost']; + $Depreciation = $trans['purchase_cost'] - $trans['material_cost'];; $Balance = $trans['material_cost']; if ($detail) { diff --git a/sales/sales_order_entry.php b/sales/sales_order_entry.php index e087804a..48577693 100644 --- a/sales/sales_order_entry.php +++ b/sales/sales_order_entry.php @@ -69,7 +69,7 @@ if (isset($_GET['NewDelivery']) && is_numeric($_GET['NewDelivery'])) { create_cart(ST_SALESINVOICE, $_GET['NewInvoice']); if (isset($_GET['FixedAsset'])) { - $_SESSION['page_title'] = _($help_context = "FA Sale"); + $_SESSION['page_title'] = _($help_context = "Fixed Assets Sale"); $_SESSION['Items']->fixed_asset = true; } else $_SESSION['page_title'] = _($help_context = "Direct Sales Invoice"); diff --git a/sql/alter2.4rc1.sql b/sql/alter2.4rc1.sql index 735c9e3b..c72c81f7 100644 --- a/sql/alter2.4rc1.sql +++ b/sql/alter2.4rc1.sql @@ -17,6 +17,7 @@ ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_factor` double NOT NULL DE ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_start` date NOT NULL DEFAULT '0000-00-00' AFTER `depreciation_factor`; ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_date` date NOT NULL DEFAULT '0000-00-00' AFTER `depreciation_start`; ALTER TABLE `0_stock_master` ADD COLUMN `fa_class_id` varchar(20) NOT NULL DEFAULT '' AFTER `depreciation_date`; +ALTER TABLE `0_stock_master` CHANGE `actual_cost` `purchase_cost` double NOT NULL default 0; INSERT INTO `0_sys_prefs` VALUES ('default_loss_on_asset_disposal_act', 'glsetup.items', 'varchar', '15', '5660'); INSERT INTO `0_sys_prefs` VALUES ('depreciation_period', 'glsetup.company', 'tinyint', '1', '1');