diff --git a/app/Http/Controllers/AssetModelsController.php b/app/Http/Controllers/AssetModelsController.php index ce3056bfed..dd7486f05f 100755 --- a/app/Http/Controllers/AssetModelsController.php +++ b/app/Http/Controllers/AssetModelsController.php @@ -93,7 +93,8 @@ class AssetModelsController extends Controller // Was it created? if ($model->save()) { if ($request->filled('eol')) { - $model->assets()->whereNotNull('purchase_date')->whereNull('eol_explicit')->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL '.$model->eol.' MONTH)')]); + $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])]); } if ($this->shouldAddDefaultValues($request->input())) { if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){ @@ -182,7 +183,8 @@ class AssetModelsController extends Controller if ($model->save()) { if ($model->wasChanged('eol')) { - $model->assets()->whereNotNull('purchase_date')->whereNull('eol_explicit')->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL '.$model->eol.' MONTH)')]); + $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])]); } return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success')); } diff --git a/app/Http/Controllers/Assets/AssetsController.php b/app/Http/Controllers/Assets/AssetsController.php index 4b31e704ab..f77af809f2 100755 --- a/app/Http/Controllers/Assets/AssetsController.php +++ b/app/Http/Controllers/Assets/AssetsController.php @@ -389,7 +389,7 @@ class AssetsController extends Controller if ($asset->save()) { if($asset->wasChanged('purchase_date')){ - $model->assets()->whereNotNull('purchase_date')->whereNull('eol_explicit')->update(['asset_eol_date' => DB::raw('DATE_ADD(purchase_date, INTERVAL '.$model->eol.' MONTH)')]); + $asset->asset_eol_date = Carbon::parse($asset->purchase_date)->addMonths($asset->model->eol)->format('Y-m-d'); } return redirect()->route('hardware.show', $assetId) ->with('success', trans('admin/hardware/message.update.success'));