Fixed Assets fixes, bugs and improvements.
authorJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 7 Dec 2015 22:42:11 +0000 (23:42 +0100)
committerJoe Hunt <joe.hunt.consulting@gmail.com>
Mon, 7 Dec 2015 22:42:11 +0000 (23:42 +0100)
15 files changed:
fixed_assets/includes/depreciation.inc
fixed_assets/includes/fixed_assets_db.inc
fixed_assets/inquiry/stock_inquiry.php
includes/db/inventory_db.inc
includes/sysnames.inc
includes/ui/items_cart.inc
inventory/adjustments.php
inventory/includes/item_adjustments_ui.inc
inventory/inquiry/stock_movements.php
inventory/manage/items.php
inventory/transfers.php
purchasing/includes/db/invoice_db.inc
reporting/rep451.php
sales/sales_order_entry.php
sql/alter2.4rc1.sql

index ab36edd3332c319c6357d80344999362a4c0abc1..cc5390795c3f56b36b3d4f0ead0162bd496a8010 100644 (file)
@@ -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':
index 7f30d8db95004c27fe5b208dd54820f5be1028c8..14dc3860fce3a488f4dbeda4d8fd0a529842ee86 100644 (file)
@@ -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.")"
index 93c79446b88b972e7ebe4e18918a7339eb900530..c456d792823c86c248a316db7eaf6540d2095785 100644 (file)
@@ -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'),
index c01e4eb48b9aca4909716b43e3ae304a43c3276c..ad9fbb7b6a1824e86b76cead0cde8d7c95a917c3 100644 (file)
@@ -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_)
index 80fab81177502a30fd189f9ebc78c52d7f736ce3..507bd698dedecc98451c72b65190a208d8d129e9 100644 (file)
@@ -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(
index 858b05be6d337c1dbdd629ea6896c6233ea04c6f..92cc1a462c2193a30f3b0ed8d5743eacf933fa2c 100644 (file)
@@ -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;
 
index 9dbe1ea6623f42657193d6d45e7977cd43578079..ba5dcf49fbcdbe83e1d9ac1f301b07222d78be4a 100644 (file)
@@ -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);
index 1331f62f6f7531b87808dc33f49ab2e3d03d4f3b..e2f585b6951b7658f672ebcd28f57e05141f94d1 100644 (file)
@@ -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']);
index f9ef425d6140db9188c9c6bf495d6bf3a2d13185..24c12e7cd4b32884f5211d30f1b0db0e6d50d3f6 100644 (file)
@@ -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");
 }
index c69c485498115cb39bd331a30a533c57d6436cd1..21e2ab7a4283405104bffe4559e65ab31dcd0a76 100644 (file)
@@ -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'");
                }
        }
index 0143b0b74d65f3654c438679bc8234ef92bacfd2..3cbc3c2c45d23478fde69917cb7844794322c9ee 100644 (file)
@@ -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");
 
index 372aca3c2fbfeee730863bce684eebad6c9fa8cb..7488e1786face77323572c8d2f559b986b3ad208 100644 (file)
@@ -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, "");
index fe712111a80ebdc8dd3b565143e5dc7b34b42303..d02db0448daa77c2fbb00b33be90f938f72e9e6d 100644 (file)
@@ -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)
                {
index e087804a11ef59e66f76ef00e97e771538aef375..485776933d56ea779482ab0dbe43bd036516b05c 100644 (file)
@@ -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");
index 735c9e3b9c0118411f26f898b463abd4a6886641..c72c81f7cafba95faf35ea7b9fe7cdd097c49a00 100644 (file)
@@ -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');