From daba90b346fd01aaff5d1751e2a902ddfd6fa257 Mon Sep 17 00:00:00 2001 From: Minaev Dmitriy Date: Sat, 25 Aug 2018 19:17:48 +0300 Subject: [PATCH] fix: add more checks at Depreciable.php --- app/Models/Depreciable.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 9a4fe68b5e..43ea0af601 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -42,6 +42,13 @@ class Depreciable extends SnipeModel public function getDepreciatedValue() { + if (!$this->get_depreciation()) { // will never happen + return $this->purchase_cost; + } + + if ($this->get_depreciation()->months <= 0) { + return $this->purchase_cost; + } $depreciation = 0; $setting = Setting::first(); switch($setting->depreciation_method) { @@ -66,14 +73,6 @@ class Depreciable extends SnipeModel public function getLinearDepreciatedValue() { - if (!$this->get_depreciation()) { // will never happen - return $this->purchase_cost; - } - - if ($this->get_depreciation()->months <= 0) { - return $this->purchase_cost; - } - // 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);