Skip to content
Merged
4 changes: 2 additions & 2 deletions app/Http/Controllers/AssetMaintenancesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public function store(Request $request) : RedirectResponse
) {
$startDate = Carbon::parse($assetMaintenance->start_date);
$completionDate = Carbon::parse($assetMaintenance->completion_date);
$assetMaintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
$assetMaintenance->asset_maintenance_time = (int) $completionDate->diffInDays($startDate, true);
}

// Was the asset maintenance created?
Expand Down Expand Up @@ -210,7 +210,7 @@ public function update(Request $request, AssetMaintenance $maintenance) : View |
) {
$startDate = Carbon::parse($maintenance->start_date);
$completionDate = Carbon::parse($maintenance->completion_date);
$maintenance->asset_maintenance_time = $completionDate->diffInDays($startDate);
$maintenance->asset_maintenance_time = (int) $completionDate->diffInDays($startDate, true);
}

// Was the asset maintenance created?
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Assets/AssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function update(ImageUploadRequest $request, Asset $asset) : RedirectResp
$asset->eol_explicit = false;
} elseif ($request->filled('asset_eol_date')) {
$asset->asset_eol_date = $request->input('asset_eol_date', null);
$months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
$months = (int) Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date, true);
if($asset->model->eol) {
if($months != $asset->model->eol > 0) {
$asset->eol_explicit = true;
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/ReportsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -1081,10 +1081,10 @@ public function exportAssetMaintenancesReport() : Response
$row[] = e($assetMaintenance->start_date);
$row[] = e($assetMaintenance->completion_date);
if (is_null($assetMaintenance->asset_maintenance_time)) {
$improvementTime = intval(Carbon::now()
->diffInDays(Carbon::parse($assetMaintenance->start_date)));
$improvementTime = (int) Carbon::now()
->diffInDays(Carbon::parse($assetMaintenance->start_date), true);
} else {
$improvementTime = intval($assetMaintenance->asset_maintenance_time);
$improvementTime = (int) $assetMaintenance->asset_maintenance_time;
}
$row[] = $improvementTime;
$row[] = trans('general.currency') . Helper::formatCurrencyOutput($assetMaintenance->cost);
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Transformers/AssetsTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function transformAsset(Asset $asset)
'requestable' => ($asset->requestable ? true : false),

'model_number' => (($asset->model) && ($asset->model->model_number)) ? e($asset->model->model_number) : null,
'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date).' months' : null,
'eol' => (($asset->asset_eol_date != '') && ($asset->purchase_date != '')) ? (int) Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date, true) . ' months' : null,
'asset_eol_date' => ($asset->asset_eol_date != '') ? Helper::getFormattedDateObject($asset->asset_eol_date, 'date') : null,
'status_label' => ($asset->assetstatus) ? [
'id' => (int) $asset->assetstatus->id,
Expand Down
4 changes: 2 additions & 2 deletions app/Models/Actionlog.php
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,13 @@ public function daysUntilNextAudit($monthInterval = 12, $asset = null)
$now = Carbon::now();
$last_audit_date = $this->created_at; // this is the action log's created at, not the asset itself
$next_audit = $last_audit_date->addMonth($monthInterval); // this actually *modifies* the $last_audit_date
$next_audit_days = round($now->diffInDays($next_audit, true));
$next_audit_days = (int) round($now->diffInDays($next_audit, true));
$override_default_next = $next_audit;

// Override the default setting for interval if the asset has its own next audit date
if (($asset) && ($asset->next_audit_date)) {
$override_default_next = Carbon::parse($asset->next_audit_date);
$next_audit_days = round($override_default_next->diffInDays($now, true));
$next_audit_days = (int) round($override_default_next->diffInDays($now, true));
}

// Show as negative number if the next audit date is before the audit date we're looking at
Expand Down
2 changes: 1 addition & 1 deletion app/Observers/AssetObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public function saving(Asset $asset)
// determine if explicit and set eol_explicit to true
if (!is_null($asset->asset_eol_date) && !is_null($asset->purchase_date)) {
if($asset->model->eol > 0) {
$months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
$months = (int) Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date, true);
if($months != $asset->model->eol) {
$asset->eol_explicit = true;
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/hardware/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ class="form-inline"
</strong>
</div>
<div class="col-md-9">
{{ Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date) }}
{{ (int) Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date, true) }}
{{ trans('admin/hardware/form.months') }}

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@php
$next_audit_date = Helper::getFormattedDateObject($asset->next_audit_date, 'date', false);
$last_audit_date = Helper::getFormattedDateObject($asset->last_audit_date, 'date', false);
$diff = Carbon::parse(Carbon::now())->diffInDays($asset->next_audit_date, false);
$diff = (int) Carbon::parse(Carbon::now())->diffInDays($asset->next_audit_date, true);
$icon = ($diff <= 7) ? '🚨' : (($diff <= 14) ? '⚠️' : ' ');
@endphp
|{{ $icon }}| [{{ $asset->present()->name }}]({{ route('hardware.show', $asset->id) }}) | {{ $last_audit_date }}| {{ $next_audit_date }} | {{ $diff }} | {{ ($asset->supplier ? e($asset->supplier->name) : '') }}|{{ ($asset->assignedTo ? $asset->assignedTo->present()->name() : '') }}|{{ $asset->notes }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Tests\Feature\AssetMaintenances\Ui;

use App\Models\Asset;
use App\Models\Supplier;
use App\Models\User;
use Tests\TestCase;

Expand All @@ -13,4 +15,41 @@ public function testPageRenders()
->get(route('maintenances.create'))
->assertOk();
}

public function testCanCreateAssetMaintenance()
{
$actor = User::factory()->superuser()->create();

$asset = Asset::factory()->create();
$supplier = Supplier::factory()->create();

$this->actingAs($actor)
->followingRedirects()
->post(route('maintenances.store'), [
'title' => 'Test Maintenance',
'asset_id' => $asset->id,
'supplier_id' => $supplier->id,
'asset_maintenance_type' => 'Maintenance',
'start_date' => '2021-01-01',
'completion_date' => '2021-01-10',
'is_warranty' => '1',
'cost' => '100.00',
'notes' => 'A note',
])
->assertOk();

$this->assertDatabaseHas('asset_maintenances', [
'asset_id' => $asset->id,
'supplier_id' => $supplier->id,
'asset_maintenance_type' => 'Maintenance',
'title' => 'Test Maintenance',
'is_warranty' => 1,
'start_date' => '2021-01-01',
'completion_date' => '2021-01-10',
'asset_maintenance_time' => '9',
'notes' => 'A note',
'cost' => '100.00',
'created_by' => $actor->id,
]);
}
}
41 changes: 41 additions & 0 deletions tests/Feature/AssetMaintenances/Ui/EditAssetMaintenanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Tests\Feature\AssetMaintenances\Ui;

use App\Models\Asset;
use App\Models\AssetMaintenance;
use App\Models\Supplier;
use App\Models\User;
use Tests\TestCase;

Expand All @@ -14,4 +16,43 @@ public function testPageRenders()
->get(route('maintenances.edit', AssetMaintenance::factory()->create()->id))
->assertOk();
}

public function testCanUpdateAssetMaintenance()
{
$actor = User::factory()->superuser()->create();

$assetMaintenance = AssetMaintenance::factory()->create();

$asset = Asset::factory()->create();
$supplier = Supplier::factory()->create();

$this->actingAs($actor)
->followingRedirects()
->put(route('maintenances.update', $assetMaintenance->id), [
'title' => 'Test Maintenance',
'asset_id' => $asset->id,
'supplier_id' => $supplier->id,
'asset_maintenance_type' => 'Maintenance',
'start_date' => '2021-01-01',
'completion_date' => '2021-01-10',
'is_warranty' => '1',
'cost' => '100.00',
'notes' => 'A note',
])
->assertOk();

$this->assertDatabaseHas('asset_maintenances', [
'asset_id' => $asset->id,
'supplier_id' => $supplier->id,
'asset_maintenance_type' => 'Maintenance',
'title' => 'Test Maintenance',
'is_warranty' => 1,
'start_date' => '2021-01-01',
'completion_date' => '2021-01-10',
'asset_maintenance_time' => '9',
'notes' => 'A note',
'cost' => '100.00',
]);
}

}
2 changes: 1 addition & 1 deletion tests/Feature/Assets/Ui/EditAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testNewCheckinIsLoggedIfStatusChangedToUndeployable()
$this->assertEquals($achived_status->id, $asset->status_id);

Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) {
return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;
return (int) Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp, true) < 2;
}, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Checkins/Api/AssetCheckinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function testAssetCanBeCheckedIn()

Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) {
// this could be better mocked but is ok for now.
return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;
return (int) Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp, true) < 2;
}, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Checkins/Ui/AssetCheckinTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public function testAssetCanBeCheckedIn()

Event::assertDispatched(function (CheckoutableCheckedIn $event) use ($currentTimestamp) {
// this could be better mocked but is ok for now.
return Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp) < 2;
return (int) Carbon::parse($event->action_date)->diffInSeconds($currentTimestamp, true) < 2;
}, 1);
}

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Checkouts/Api/AssetCheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,6 @@ public function testLastCheckoutUsesCurrentDateIfNotProvided()

$asset->refresh();

$this->assertTrue(Carbon::parse($asset->last_checkout)->diffInSeconds(now()) < 2);
$this->assertTrue((int) Carbon::parse($asset->last_checkout)->diffInSeconds(now(), true) < 2);
}
}
2 changes: 1 addition & 1 deletion tests/Feature/Checkouts/Ui/AssetCheckoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ public function testLastCheckoutUsesCurrentDateIfNotProvided()

$asset->refresh();

$this->assertTrue(Carbon::parse($asset->last_checkout)->diffInSeconds(now()) < 2);
$this->assertTrue((int) Carbon::parse($asset->last_checkout)->diffInSeconds(now(), true) < 2);
}

public function testAssetCheckoutPageIsRedirectedIfModelIsInvalid()
Expand Down
Loading