Skip to content

Commit

Permalink
Merge pull request #16116 from marcusmoore/bug/sc-20259
Browse files Browse the repository at this point in the history
  • Loading branch information
snipe authored Jan 22, 2025
2 parents 1212267 + 1098b8c commit 802fcba
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/Http/Transformers/DepreciationReportTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
24 changes: 24 additions & 0 deletions tests/Unit/Transformers/DepreciationReportTransformerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Tests\Unit\Transformers;

use App\Http\Transformers\DepreciationReportTransformer;
use App\Models\Asset;
use App\Models\Depreciation;
use Tests\TestCase;

class DepreciationReportTransformerTest extends TestCase
{
public function testHandlesModelDepreciationMonthsBeingZero()
{
$asset = Asset::factory()->create();
$depreciation = Depreciation::factory()->create(['months' => 0]);
$asset->model->depreciation()->associate($depreciation);

$transformer = new DepreciationReportTransformer;

$result = $transformer->transformAsset($asset);

$this->assertIsArray($result);
}
}

0 comments on commit 802fcba

Please sign in to comment.