some more cleanup

This commit is contained in:
slong753 2023-07-18 10:14:00 -05:00 committed by spencerrlongg
parent 20367eecc9
commit 774f21bb7f
4 changed files with 8 additions and 5 deletions

View file

@ -94,7 +94,8 @@ class AssetModelsController extends Controller
if ($model->save()) {
if ($request->filled('eol')) {
$newEol = $model->eol;
$model->assets()->whereNotNull('purchase_date')->whereNull('eol_explicit')->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL :newEol MONTH)', ['newEol' => $newEol])]);
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL :newEol MONTH)', ['newEol' => $newEol])]);
}
if ($this->shouldAddDefaultValues($request->input())) {
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){
@ -184,7 +185,10 @@ class AssetModelsController extends Controller
if ($model->save()) {
if ($model->wasChanged('eol')) {
$newEol = $model->eol;
$model->assets()->whereNotNull('purchase_date')->whereNull('eol_explicit')->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL :newEol MONTH)', ['newEol' => $newEol])]);
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
//this DB::raw is so that we can use an ->update() which is _much_ faster than foreaching
//but, laravel doesn't have a way to access a column inside an update
->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL :newEol MONTH)', ['newEol' => $newEol])]);
}
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
}

View file

@ -391,7 +391,7 @@ class AssetsController extends Controller
if ($asset->save()) {
if($asset->wasChanged('purchase_date')){
if($asset->wasChanged('purchase_date') && !$asset->explicit_eol){
$asset->asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($asset->model->eol)->format('Y-m-d');
}
return redirect()->route('hardware.show', $assetId)

View file

@ -88,7 +88,7 @@ class Asset extends Depreciable
'created_at' => 'datetime',
'updated_at' => 'datetime',
'deleted_at' => 'datetime',
'eol_explicit' => 'boolean',
'eol_explicit' => 'boolean',
];
protected $rules = [

View file

@ -28,7 +28,6 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
if($months != $asset->model->eol) {
$asset->update(['eol_explicit' => true]);
}
}
}