public static function PHPExcel_Calculation_Financial::DB in Loft Data Grids 7.2
Same name and namespace in other branches
- 6.2 vendor/phpoffice/phpexcel/Classes/PHPExcel/Calculation/Financial.php \PHPExcel_Calculation_Financial::DB()
* DB * * Returns the depreciation of an asset for a specified period using the * fixed-declining balance method. * This form of depreciation is used if you want to get a higher depreciation value * at the beginning of the depreciation (as opposed to linear depreciation). The * depreciation value is reduced with every depreciation period by the depreciation * already deducted from the initial cost. * * Excel Function: * DB(cost,salvage,life,period[,month]) * * @access public * @category Financial Functions *
Parameters
float cost Initial cost of the asset.: * @param float salvage Value at the end of the depreciation. * (Sometimes called the salvage value of the asset) * @param integer life Number of periods over which the asset is depreciated. * (Sometimes called the useful life of the asset) * @param integer period The period for which you want to calculate the * depreciation. Period must use the same units as life. * @param integer month Number of months in the first year. If month is omitted, * it defaults to 12. * @return float
File
- vendor/
phpoffice/ phpexcel/ Classes/ PHPExcel/ Calculation/ Financial.php, line 908
Class
- PHPExcel_Calculation_Financial
- PHPExcel_Calculation_Financial
Code
public static function DB($cost, $salvage, $life, $period, $month = 12) {
$cost = PHPExcel_Calculation_Functions::flattenSingleValue($cost);
$salvage = PHPExcel_Calculation_Functions::flattenSingleValue($salvage);
$life = PHPExcel_Calculation_Functions::flattenSingleValue($life);
$period = PHPExcel_Calculation_Functions::flattenSingleValue($period);
$month = PHPExcel_Calculation_Functions::flattenSingleValue($month);
// Validate
if (is_numeric($cost) && is_numeric($salvage) && is_numeric($life) && is_numeric($period) && is_numeric($month)) {
$cost = (double) $cost;
$salvage = (double) $salvage;
$life = (int) $life;
$period = (int) $period;
$month = (int) $month;
if ($cost == 0) {
return 0.0;
}
elseif ($cost < 0 || $salvage / $cost < 0 || $life <= 0 || $period < 1 || $month < 1) {
return PHPExcel_Calculation_Functions::NaN();
}
// Set Fixed Depreciation Rate
$fixedDepreciationRate = 1 - pow($salvage / $cost, 1 / $life);
$fixedDepreciationRate = round($fixedDepreciationRate, 3);
// Loop through each period calculating the depreciation
$previousDepreciation = 0;
for ($per = 1; $per <= $period; ++$per) {
if ($per == 1) {
$depreciation = $cost * $fixedDepreciationRate * $month / 12;
}
elseif ($per == $life + 1) {
$depreciation = ($cost - $previousDepreciation) * $fixedDepreciationRate * (12 - $month) / 12;
}
else {
$depreciation = ($cost - $previousDepreciation) * $fixedDepreciationRate;
}
$previousDepreciation += $depreciation;
}
if (PHPExcel_Calculation_Functions::getCompatibilityMode() == PHPExcel_Calculation_Functions::COMPATIBILITY_GNUMERIC) {
$depreciation = round($depreciation, 2);
}
return $depreciation;
}
return PHPExcel_Calculation_Functions::VALUE();
}