3
0
mirror of https://github.com/snipe/snipe-it.git synced 2026-02-05 12:55:46 +00:00

Merge pull request #16116 from marcusmoore/bug/sc-20259

This commit is contained in:
snipe
2025-01-22 18:50:12 +00:00
committed by GitHub
2 changed files with 25 additions and 1 deletions

View File

@ -61,7 +61,7 @@ class DepreciationReportTransformer
/**
* 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()));

View File

@ -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);
}
}