Skip to content

Commit

Permalink
Update AssetModelsController.php
Browse files Browse the repository at this point in the history
if EOL of model has been changed and value is >0 assets will be updates with new EOL rate, date
if EOL of model has been changes and value is null or 0 then assets will be updates by null EOL rate, date
*asset with set expilicity market will not be updated
  • Loading branch information
Robert-Azelis authored Oct 22, 2023
1 parent 38066bf commit 58062ff
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/Http/Controllers/AssetModelsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,14 @@ public function update(ImageUploadRequest $request, $modelId = null)

if ($model->save()) {
if ($model->wasChanged('eol')) {
$newEol = $model->eol;
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL ' . $newEol . ' MONTH)')]);
if ($model->eol > 0) {
$newEol = $model->eol;
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL ' . $newEol . ' MONTH)')]);
} elseif ($model->eol == 0) {
$model->assets()->whereNotNull('purchase_date')->where('eol_explicit', false)
->update(['asset_eol_date' => DB::raw('null')]);
}
}
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
}
Expand Down

0 comments on commit 58062ff

Please sign in to comment.