added asset_eol_date and explicit to factory

This commit is contained in:
slong753 2023-07-25 17:41:55 -05:00 committed by spencerrlongg
parent 78c400e948
commit 1b18cd7fe6
2 changed files with 15 additions and 1 deletions

View file

@ -129,7 +129,8 @@ class AssetObserver
}
//determine if explicit and set eol_explit to true
if(!is_null($asset->asset_eol_date) && !is_null($asset->purchase_date) || ($asset->isDirty($asset->asset_eol_date) || $asset->isDirty($asset->purchase_date))) {
//conditions might need more work
if(!is_null($asset->asset_eol_date) && !is_null($asset->purchase_date)) {
if($asset->model->eol) {
$months = Carbon::parse($asset->asset_eol_date)->diffInMonths($asset->purchase_date);
if($months != $asset->model->eol) {

View file

@ -8,6 +8,7 @@ use App\Models\Location;
use App\Models\Statuslabel;
use App\Models\Supplier;
use App\Models\User;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Factories\Factory;
class AssetFactory extends Factory
@ -48,6 +49,17 @@ class AssetFactory extends Factory
'last_checkout' => null,
];
}
public function configure()
{
return $this->afterMaking(function (Asset $asset) {
// $asset->asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
$asset->asset_eol_date = $this->faker->boolean(5)
? Carbon::parse($asset->purchase_date)->addMonths(rand(0, 20))->format('Y-m-d')
: Carbon::parse($asset->purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
});
}
public function laptopMbp()
{
@ -338,4 +350,5 @@ class AssetFactory extends Factory
{
return $this->state(['requestable' => false]);
}
}