if ($selected_id != -1)
{
update_fixed_asset_class($selected_id, $_POST['parent_id'], $_POST['description'], $_POST['long_description'],
- $_POST['depreciation_method'], $_POST['depreciation_rate'], $_POST['depreciation_period']);
+ $_POST['depreciation_rate']);
display_notification(_('Selected fixed asset class has been updated'));
}
else
{
add_fixed_asset_class($_POST['fa_class_id'], $_POST['parent_id'], $_POST['description'], $_POST['long_description'],
- $_POST['depreciation_method'], $_POST['depreciation_rate'], $_POST['depreciation_period']);
+ $_POST['depreciation_rate']);
display_notification(_('New fixed asset class has been added'));
}
-
+
$Mode = 'RESET';
}
}
start_form();
start_table(TABLESTYLE);
-$th = array(_("Fixed asset class"), _("Description"), _("Depreciation method"), _("Depreciation rate"), _("Depreciation period"), "", "");
+$th = array(_("Fixed asset class"), _("Description"), _("Basic Depreciation Rate"), "", "");
inactive_control_column($th);
table_header($th);
$k = 0; //row colour counter
label_cell($myrow["fa_class_id"]);
label_cell($myrow["description"]);
- label_cell($depreciation_methods[$myrow["depreciation_method"]]);
label_cell($myrow["depreciation_rate"].'%');
- label_cell($myrow["depreciation_period"].' years');
inactive_control_cell($myrow["fa_class_id"], $myrow["inactive"], 'stock_fa_classes', 'fa_class_id');
edit_button_cell("Edit".$myrow["fa_class_id"], _("Edit"));
delete_button_cell("Delete".$myrow["fa_class_id"], _("Delete"));
echo '<br>';
start_form(true);
-
+div_start('par_tbl');
start_table(TABLESTYLE2);
if ($selected_id != -1)
$_POST['parent_id'] = $myrow["parent_id"];
$_POST['description'] = $myrow["description"];
$_POST['long_description'] = $myrow["long_description"];
- $_POST['depreciation_method'] = $myrow["depreciation_method"];
$_POST['depreciation_rate'] = $myrow["depreciation_rate"];
- $_POST['depreciation_period'] = $myrow["depreciation_period"];
}
hidden("selected_id", $selected_id);
hidden("fa_class_id");
text_row(_("Description:"), 'description', null, 42, 200);
textarea_row(_('Long description:'), 'long_description', null, 42, 3);
-array_selector_row(_("Depreciation Method").":", "depreciation_method", null, $depreciation_methods, array('select_submit'=> true));
-small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
-text_row_ex(_("Depreciation Period").':', 'depreciation_period', 3, 3, '', null, null, _("years"));
-
+small_amount_row(_("Basic Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
//text_row(_("Parent id:"), 'parent_id', null, 3, 3);
end_table(1);
-
+div_end();
//if ($selected_id != -1)
submit_add_or_update_center($selected_id == -1, '', 'both');
$y = date('Y', strtotime($year['end']));
switch ($item['depreciation_method']) {
- case 'D':
- $value = $item['material_cost'] * $item['depreciation_rate'] / 100 / 12;
- break;
-
- case 'S':
- // depreciation_rate is the period here.
- $done_months = months_between_dates($item['depreciation_start'], $item['depreciation_date']);
- $remaining_months = $item['depreciation_rate'] * 12 - $done_months;
- $value = $item['material_cost'] / $remaining_months;
- break;
+ case 'D':
+ $line_value = $item['actual_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;
+ 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;
+ break;
case 'O':
- $value = $item['material_cost'];
- break;
+ $value = $item['material_cost'];
+ break;
}
$next = next_depreciation_date($item['depreciation_date']);
return $result;
}
-function update_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_method, $depreciation_rate, $depreciation_period)
+function update_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_rate)
{
$sql = "UPDATE ".TB_PREF."stock_fa_class SET
parent_id=".db_escape($parent_id).",
description=".db_escape($description).",
long_description=".db_escape($long_description).",
- depreciation_method=".db_escape($depreciation_method).",
- depreciation_rate=".db_escape($depreciation_rate).",
- depreciation_period=".db_escape($depreciation_period)."
+ depreciation_rate=".db_escape($depreciation_rate)."
WHERE fa_class_id=".db_escape($fa_class_id);
db_query($sql, "The fixed asset class could not be updated");
}
-function add_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_method, $depreciation_rate, $depreciation_period)
+function add_fixed_asset_class($fa_class_id, $parent_id, $description, $long_description, $depreciation_rate)
{
$sql = "INSERT INTO ".TB_PREF."stock_fa_class (fa_class_id, parent_id, description, long_description,
- depreciation_method, depreciation_rate, depreciation_period) VALUES ("
+ depreciation_rate) VALUES ("
.db_escape($fa_class_id).", ".db_escape($parent_id).", "
- .db_escape($description).", ".db_escape($long_description).", "
- .db_escape($depreciation_method).", ".db_escape($depreciation_rate).", "
- .db_escape($depreciation_period).")";
+ .db_escape($description).", ".db_escape($long_description).", "
+ .db_escape($depreciation_rate).")";
db_query($sql, "The fixed asset class could not be added");
}
{
$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
+ 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
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.")"
return $depreciation_methods[$row['depreciation_method']];
}
-function depr_rate_title($row) {
- if ($row['depreciation_method'] == 'S')
- return $row['depreciation_rate'].' years';
- else
- return $row['depreciation_rate'].'%';
+function depr_par($row) {
+ if ($row['depreciation_method'] == 'D')
+ return $row['depreciation_rate']*$row['depreciation_factor'].'%';
+ elseif ($row['depreciation_method'] == 'N')
+ return $row['depreciation_rate'].' '._('years'
+ );
+ else
+ return $row['depreciation_rate'].'%';
}
function status_title($row) {
_("Class"),
_("UOM") => array('align' => 'center'),
_("Description"),
- _("Rate or Lifecycle") => array('fun' => 'depr_rate_title'),
+ _("Rate or Lifecycle") => array('fun' => 'depr_par'),
_("Method") => array('fun' => 'depr_method_title'),
_("Status") => array('fun' => 'status_title'),
_("Purchased") => array('fun' => 'purchase_link'),
$depreciation_methods = array(
'D' => _("Declining balance"),
'S' => _("Straight line"),
+ 'N' => _("Sum of the Year Digits"),
'O' => _("One-time"),
);
$tax_type_id, $units='', $mb_flag='', $sales_account, $inventory_account,
$cogs_account, $adjustment_account, $assembly_account, $dimension_id,
$dimension2_id, $no_sale, $editable, $no_purchase,
- $depreciation_method = 'D', $depreciation_rate=100, $depreciation_start=null,
- $fa_class_id=null)
+ $depreciation_method = 'D', $depreciation_rate=100, $depreciation_factor=1,
+ $depreciation_start=null, $fa_class_id=null)
{
$sql = "UPDATE ".TB_PREF."stock_master SET long_description=".db_escape($long_description).",
description=".db_escape($description).",
editable=".db_escape($editable).",
depreciation_method=".db_escape($depreciation_method).",
depreciation_rate=".db_escape($depreciation_rate).",
+ depreciation_factor=".db_escape($depreciation_factor).",
fa_class_id=".db_escape($fa_class_id);
if ($units != '')
$tax_type_id, $units, $mb_flag, $sales_account, $inventory_account,
$cogs_account, $adjustment_account, $assembly_account, $dimension_id,
$dimension2_id, $no_sale, $editable, $no_purchase,
- $depreciation_method='D', $depreciation_rate=100, $depreciation_start=null,
+ $depreciation_method='D', $depreciation_rate=100, $depreciation_factor=1, $depreciation_start=null,
$fa_class_id=null)
{
$sql = "INSERT INTO ".TB_PREF."stock_master (stock_id, description, long_description, category_id,
tax_type_id, units, mb_flag, sales_account, inventory_account, cogs_account,
adjustment_account, assembly_account, dimension_id, dimension2_id, no_sale, no_purchase, editable,
- depreciation_method, depreciation_rate, depreciation_start, depreciation_date, fa_class_id)
+ depreciation_method, depreciation_rate, depreciation_factor, depreciation_start, depreciation_date, fa_class_id)
VALUES (".db_escape($stock_id).", ".db_escape($description).", ".db_escape($long_description).",
".db_escape($category_id).", ".db_escape($tax_type_id).", "
.db_escape($units).", ".db_escape($mb_flag).",
.db_escape($no_sale).","
.db_escape($no_purchase).","
.db_escape($editable).","
- .db_escape($depreciation_method).",".db_escape($depreciation_rate).",'"
+ .db_escape($depreciation_method).",".db_escape($depreciation_rate).",".db_escape($depreciation_factor).",'"
.date2sql($depreciation_start)."','".date2sql($depreciation_start)."',"
.db_escape($fa_class_id).")";
unset($_POST['no_purchase']);
unset($_POST['depreciation_method']);
unset($_POST['depreciation_rate']);
+ unset($_POST['depreciation_factor']);
unset($_POST['depreciation_start']);
}
$_POST['adjustment_account'], $_POST['assembly_account'],
$_POST['dimension_id'], $_POST['dimension2_id'],
check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
- get_post('depreciation_method'), get_post('depreciation_rate'), get_post('depreciation_start'),
+ get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start'),
get_post('fa_class_id'));
update_record_status($_POST['NewStockID'], $_POST['inactive'],
$_POST['adjustment_account'], $_POST['assembly_account'],
$_POST['dimension_id'], $_POST['dimension2_id'],
check_value('no_sale'), check_value('editable'), check_value('no_purchase'),
- get_post('depreciation_method'), get_post('depreciation_rate'), get_post('depreciation_start'),
+ get_post('depreciation_method'), input_num('depreciation_rate'), input_num('depreciation_factor'), get_post('depreciation_start'),
get_post('fa_class_id'));
display_notification(_("A new item has been added."));
$_POST['mb_flag'] = $myrow["mb_flag"];
$_POST['depreciation_method'] = $myrow['depreciation_method'];
- $_POST['depreciation_rate'] = $myrow['depreciation_rate'];
+ $_POST['depreciation_rate'] = number_format2($myrow['depreciation_rate'], 1);
+ $_POST['depreciation_factor'] = number_format2($myrow['depreciation_factor'], 1);
$_POST['depreciation_start'] = sql2date($myrow['depreciation_start']);
$_POST['depreciation_date'] = sql2date($myrow['depreciation_date']);
$_POST['fa_class_id'] = $myrow['fa_class_id'];
if (!isset($_POST['depreciation_rate']) || (list_updated('fa_class_id') || list_updated('depreciation_method'))) {
$class_row = get_fixed_asset_class($_POST['fa_class_id']);
- if ($_POST['depreciation_method'] == 'S')
- $_POST['depreciation_rate'] = $class_row['depreciation_period'];
- else
- $_POST['depreciation_rate'] = $class_row['depreciation_rate'];
+ if ($_POST['depreciation_method'] == 'O')
+ {
+ hidden('depreciation_rate', 100);
+ label_row(_("Depreciation Rate").':', "100 %");
}
-
- switch ($_POST['depreciation_method']) {
- case 'D':
- small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
- break;
- case 'S':
- text_row_ex(_("Depreciation Period").':', 'depreciation_rate', 3, 3, '', null, null, _("years"));
- break;
- case 'O':
- hidden('depreciation_rate', 100);
- label_row(_("Depreciation Rate").':', "100 %");
- break;
+ elseif ($_POST['depreciation_method'] == 'N')
+ {
+ small_amount_row(_("Depreciation Years").':', 'depreciation_rate', null, null, _('years'), 0);
}
+ elseif ($_POST['depreciation_method'] == 'D')
+ small_amount_row(_("Base Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
+ else
+ small_amount_row(_("Depreciation Rate").':', 'depreciation_rate', null, null, '%', user_percent_dec());
+
+ if ($_POST['depreciation_method'] == 'D')
+ small_amount_row(_("Rate multiplier").':', 'depreciation_factor', null, null, '', 2);
// do not allow to change the depreciation start after this item has been depreciated
if ($new_item || $_POST['depreciation_start'] == $_POST['depreciation_date'])
label_row(_("Last Depreciation").':', $_POST['depreciation_date']);
}
hidden('depreciation_date');
-
+ }
}
table_section(2);
`parent_id` varchar(20) NOT NULL DEFAULT '',
`description` varchar(200) NOT NULL DEFAULT '',
`long_description` tinytext NOT NULL,
- `depreciation_method` char(1) NOT NULL DEFAULT 'D',
`depreciation_rate` double NOT NULL DEFAULT '0',
- `depreciation_period` tinyint(1) NOT NULL DEFAULT '0',
`inactive` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`fa_class_id`)
) ENGINE=InnoDB;
ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_method` char(1) NOT NULL DEFAULT 'D' AFTER `editable`;
ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_rate` double NOT NULL DEFAULT '0' AFTER `depreciation_method`;
-ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_start` date NOT NULL DEFAULT '0000-00-00' AFTER `depreciation_rate`;
+ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_factor` double NOT NULL DEFAULT '0' AFTER `depreciation_par`;
+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`;
`long_description` tinytext NOT NULL,
`depreciation_method` char(1) NOT NULL DEFAULT 'D',
`depreciation_rate` double NOT NULL DEFAULT '0',
- `depreciation_period` tinyint(1) NOT NULL DEFAULT '0',
`inactive` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`fa_class_id`)
) ENGINE=InnoDB;
`no_sale` tinyint(1) NOT NULL DEFAULT '0',
`no_purchase` tinyint(1) NOT NULL DEFAULT '0',
`editable` tinyint(1) NOT NULL DEFAULT '0',
- `depreciation_method` char(1) NOT NULL DEFAULT 'D',
+ `depreciation_method` char(1) NOT NULL DEFAULT 'S',
`depreciation_rate` double NOT NULL DEFAULT '0',
+ `depreciation_factor` double NOT NULL DEFAULT '1',
`depreciation_start` date NOT NULL DEFAULT '0000-00-00',
`depreciation_date` date NOT NULL DEFAULT '0000-00-00',
`fa_class_id` varchar(20) NOT NULL DEFAULT '',
--
INSERT INTO `0_stock_master` VALUES
-('101', '1', '1', 'iPad Air 2 16GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '200', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''),
-('102', '1', '1', 'iPhone 6 64GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '150', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''),
-('103', '1', '1', 'iPhone Cover Case', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '10', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''),
-('201', '3', '1', 'AP Surf Set', '', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '360', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', ''),
-('202', '4', '1', 'Maintenance', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', 'D', '0', '0000-00-00', '0000-00-00', ''),
-('301', '4', '1', 'Support', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'D', '0', '0000-00-00', '0000-00-00', '');
+('101', '1', '1', 'iPad Air 2 16GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '200', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', ''),
+('102', '1', '1', 'iPhone 6 64GB', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '150', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', ''),
+('103', '1', '1', 'iPhone Cover Case', '', 'each', 'B', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '10', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', ''),
+('201', '3', '1', 'AP Surf Set', '', 'each', 'M', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '360', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', ''),
+('202', '4', '1', 'Maintenance', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '1', 'S', '0', '1', '0000-00-00', '0000-00-00', ''),
+('301', '4', '1', 'Support', '', 'hr', 'D', '4010', '5010', '1510', '5040', '1530', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', '0', 'S', '0', '1', '0000-00-00', '0000-00-00', '');
-- --------------------------------------------------------
`long_description` tinytext NOT NULL,
`depreciation_method` char(1) NOT NULL DEFAULT 'D',
`depreciation_rate` double NOT NULL DEFAULT '0',
- `depreciation_period` tinyint(1) NOT NULL DEFAULT '0',
`inactive` tinyint(1) NOT NULL DEFAULT '0',
PRIMARY KEY (`fa_class_id`)
) ENGINE=InnoDB;
`no_sale` tinyint(1) NOT NULL default '0',
`no_purchase` tinyint(1) NOT NULL default '0',
`editable` tinyint(1) NOT NULL default '0',
- `depreciation_method` char(1) NOT NULL DEFAULT 'D',
+ `depreciation_method` char(1) NOT NULL DEFAULT 'S',
`depreciation_rate` double NOT NULL DEFAULT '0',
+ `depreciation_factor` double NOT NULL DEFAULT '1',
`depreciation_start` date NOT NULL DEFAULT '0000-00-00',
`depreciation_date` date NOT NULL DEFAULT '0000-00-00',
`fa_class_id` varchar(20) NOT NULL DEFAULT '',