diff --git a/app/Models/Depreciable.php b/app/Models/Depreciable.php index 02b319eeb4..c1452728ca 100644 --- a/app/Models/Depreciable.php +++ b/app/Models/Depreciable.php @@ -76,7 +76,7 @@ class Depreciable extends SnipeModel if ($months_passed >= $this->get_depreciation()->months){ //if there is a floor use it - if((!$this->get_depreciation()->depreciation_min) === null) { + if($this->get_depreciation()->depreciation_min) { $current_value = $this->calculateDepreciation(); diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index 4dd8422276..e07edc6bef 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -1,10 +1,13 @@ assertEquals(5, $depreciation->models->count()); } + public function testDepreciationAmount() + { + $depreciation = Depreciation::factory()->create([ + 'depreciation_type' => 'amount', + 'depreciation_min' => 1000, + 'months'=> 36, + ]); + + $asset = Asset::factory() + ->laptopMbp() + ->create( + [ + 'category_id' => Category::factory()->assetLaptopCategory()->create(), + 'purchase_date' => now()->subDecade(), + 'purchase_cost' => 4000, + ]); + $asset->model->update([ + 'depreciation_id' => $depreciation->id, + ]); + + $asset->getLinearDepreciatedValue(); + + $this->assertEquals($depreciation->depreciation_min, $asset->getLinearDepreciatedValue()); + } + public function testDepreciationPercentage() + { + $depreciation = Depreciation::factory()->create([ + 'depreciation_type' => 'percent', + 'depreciation_min' => 50, + 'months'=> 36, + ]); + + $asset = Asset::factory() + ->laptopMbp() + ->create( + [ + 'category_id' => Category::factory()->assetLaptopCategory()->create(), + 'purchase_date' => now()->subDecade(), + 'purchase_cost' => 4000, + ]); + $asset->model->update([ + 'depreciation_id' => $depreciation->id, + ]); + + $asset->getLinearDepreciatedValue(); + + $this->assertEquals(2000, $asset->getLinearDepreciatedValue()); + } public function testADepreciationHasLicenses() {