diff --git a/app/Http/Transformers/DepreciationReportTransformer.php b/app/Http/Transformers/DepreciationReportTransformer.php index 33d9a1f5fd4..00eb984fa51 100644 --- a/app/Http/Transformers/DepreciationReportTransformer.php +++ b/app/Http/Transformers/DepreciationReportTransformer.php @@ -61,7 +61,7 @@ public function transformAsset(Asset $asset) /** * Override the previously set null values if there is a valid model and associated depreciation */ - if (($asset->model) && ($asset->model->depreciation)) { + if (($asset->model) && ($asset->model->depreciation) && ($asset->model->depreciation->months !== 0)) { $depreciated_value = Helper::formatCurrencyOutput($asset->getDepreciatedValue()); $monthly_depreciation =Helper::formatCurrencyOutput($asset->purchase_cost / $asset->model->depreciation->months); $diff = Helper::formatCurrencyOutput(($asset->purchase_cost - $asset->getDepreciatedValue())); diff --git a/tests/Unit/Transformers/DepreciationReportTransformerTest.php b/tests/Unit/Transformers/DepreciationReportTransformerTest.php new file mode 100644 index 00000000000..7a0017196a4 --- /dev/null +++ b/tests/Unit/Transformers/DepreciationReportTransformerTest.php @@ -0,0 +1,24 @@ +create(); + $depreciation = Depreciation::factory()->create(['months' => 0]); + $asset->model->depreciation()->associate($depreciation); + + $transformer = new DepreciationReportTransformer; + + $result = $transformer->transformAsset($asset); + + $this->assertIsArray($result); + } +}