35 public static function DB($cost, $salvage, $life, $period, $month = 12)
44 $cost = self::validateCost($cost);
45 $salvage = self::validateSalvage($salvage);
46 $life = self::validateLife($life);
47 $period = self::validatePeriod($period);
48 $month = self::validateMonth($month);
50 return $e->getMessage();
58 $fixedDepreciationRate = 1 - ($salvage / $cost) ** (1 / $life);
59 $fixedDepreciationRate = round($fixedDepreciationRate, 3);
63 $previousDepreciation = 0;
65 for ($per = 1; $per <= $period; ++$per) {
67 $depreciation = $cost * $fixedDepreciationRate * $month / 12;
68 } elseif ($per == ($life + 1)) {
69 $depreciation = ($cost - $previousDepreciation) * $fixedDepreciationRate * (12 - $month) / 12;
71 $depreciation = ($cost - $previousDepreciation) * $fixedDepreciationRate;
73 $previousDepreciation += $depreciation;
101 public static function DDB($cost, $salvage, $life, $period, $factor = 2.0)
110 $cost = self::validateCost($cost);
111 $salvage = self::validateSalvage($salvage);
112 $life = self::validateLife($life);
113 $period = self::validatePeriod($period);
114 $factor = self::validateFactor($factor);
116 return $e->getMessage();
119 if ($period > $life) {
125 $previousDepreciation = 0;
127 for ($per = 1; $per <= $period; ++$per) {
129 ($cost - $previousDepreciation) * ($factor / $life),
130 ($cost - $salvage - $previousDepreciation)
132 $previousDepreciation += $depreciation;
135 return $depreciation;
149 public static function SLN($cost, $salvage, $life)
156 $cost = self::validateCost($cost,
true);
157 $salvage = self::validateSalvage($salvage,
true);
158 $life = self::validateLife($life,
true);
160 return $e->getMessage();
167 return ($cost - $salvage) / $life;
182 public static function SYD($cost, $salvage, $life, $period)
190 $cost = self::validateCost($cost,
true);
191 $salvage = self::validateSalvage($salvage);
192 $life = self::validateLife($life);
193 $period = self::validatePeriod($period);
195 return $e->getMessage();
198 if ($period > $life) {
202 $syd = (($cost - $salvage) * ($life - $period + 1) * 2) / ($life * ($life + 1));
207 private static function validateCost($cost,
bool $negativeValueAllowed =
false): float
210 if ($cost < 0.0 && $negativeValueAllowed ===
false) {
217 private static function validateSalvage($salvage,
bool $negativeValueAllowed =
false): float
220 if ($salvage < 0.0 && $negativeValueAllowed ===
false) {
227 private static function validateLife($life,
bool $negativeValueAllowed =
false): float
230 if ($life < 0.0 && $negativeValueAllowed ===
false) {
237 private static function validatePeriod($period,
bool $negativeValueAllowed =
false): float
240 if ($period <= 0.0 && $negativeValueAllowed ===
false) {
260 if ($factor <= 0.0) {
static validatePeriod($period, bool $negativeValueAllowed=false)
static SYD($cost, $salvage, $life, $period)
SYD.
static validateFactor($factor)
static DB($cost, $salvage, $life, $period, $month=12)
DB.
static validateSalvage($salvage, bool $negativeValueAllowed=false)
static DDB($cost, $salvage, $life, $period, $factor=2.0)
DDB.
static SLN($cost, $salvage, $life)
SLN.
static validateMonth($month)
static validateCost($cost, bool $negativeValueAllowed=false)
static validateFloat($value)
static validateInt($value)
static validateLife($life, bool $negativeValueAllowed=false)
static flattenSingleValue($value='')
Convert an array to a single scalar value by extracting the first element.