Merge pull request #16116 from marcusmoore/bug/sc-20259
Some checks are pending
Crowdin Action / upload-sources-to-crowdin (push) Waiting to run
Docker images (Alpine) / docker (push) Waiting to run
Docker images / docker (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.1) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.2) (push) Waiting to run
Tests in MySQL / PHP ${{ matrix.php-version }} (8.3) (push) Waiting to run
Tests in SQLite / PHP ${{ matrix.php-version }} (8.1.1) (push) Waiting to run

This commit is contained in:
snipe 2025-01-22 18:50:12 +00:00 committed by GitHub
commit 802fcbafa0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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);
}
}