From cdc402fa04b69d02faf1223c125bfa1fe902e677 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 14 Feb 2022 09:01:42 -0800 Subject: [PATCH 1/4] WIP formula for linear Depreciation has been corrected. still one variable left to fix. --- app/Models/Depreciable.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 35f494233..41699ad09 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -68,9 +68,15 @@ class Depreciable extends SnipeModel */ public function getLinearDepreciatedValue() { - // fraction of value left + $numerator= (($this->purchase_cost-($this->purchase_cost*12/($this->get_depreciation()->months)))); + $denominator=$this->get_depreciation()->months/12; + $deprecation_per_year= $numerator/$denominator; + $deprecation_per_month= $deprecation_per_year/12; + +// fraction of value left $months_remaining = $this->time_until_depreciated()->m + 12 * $this->time_until_depreciated()->y; //UGlY - $current_value = round(($months_remaining / $this->get_depreciation()->months) * $this->purchase_cost, 2); +// formula for current value is correct now. $months_remaining is not giving me the same value as expected. Considering how to fix this. -Godfrey M. + $current_value = $deprecation_per_month*27; if($this->get_depreciation()->depreciation_min > $current_value) { From e6e68934f73c07e73c34060f3381b29cc6ee5f31 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 14 Feb 2022 09:13:14 -0800 Subject: [PATCH 2/4] adds a months depreciated variable --- app/Models/Depreciable.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 41699ad09..181be0ef4 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -73,10 +73,9 @@ class Depreciable extends SnipeModel $deprecation_per_year= $numerator/$denominator; $deprecation_per_month= $deprecation_per_year/12; -// fraction of value left $months_remaining = $this->time_until_depreciated()->m + 12 * $this->time_until_depreciated()->y; //UGlY -// formula for current value is correct now. $months_remaining is not giving me the same value as expected. Considering how to fix this. -Godfrey M. - $current_value = $deprecation_per_month*27; + $months_depreciated=$this->get_depreciation()->months-$months_remaining; + $current_value = $deprecation_per_month*$months_depreciated; if($this->get_depreciation()->depreciation_min > $current_value) { From 6e204a20ca1fde177b86b9f7497c6dd0a821e947 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 14 Feb 2022 09:28:35 -0800 Subject: [PATCH 3/4] fixed current value formula --- app/Models/Depreciable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 181be0ef4..118a7b893 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -75,7 +75,7 @@ class Depreciable extends SnipeModel $months_remaining = $this->time_until_depreciated()->m + 12 * $this->time_until_depreciated()->y; //UGlY $months_depreciated=$this->get_depreciation()->months-$months_remaining; - $current_value = $deprecation_per_month*$months_depreciated; + $current_value = $this->purchase_cost-($deprecation_per_month*$months_depreciated); if($this->get_depreciation()->depreciation_min > $current_value) { From 7b9a2ae909a015a07e41c41825a9329c6d89b712 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Mon, 14 Feb 2022 09:34:42 -0800 Subject: [PATCH 4/4] added rounding --- app/Models/Depreciable.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 118a7b893..fdb8bdcd1 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -79,7 +79,7 @@ class Depreciable extends SnipeModel if($this->get_depreciation()->depreciation_min > $current_value) { - $current_value=$this->get_depreciation()->depreciation_min; + $current_value=round($this->get_depreciation()->depreciation_min,2); } if ($current_value < 0) { $current_value = 0;