mirror of
https://github.com/snipe/snipe-it.git
synced 2024-11-09 23:24:06 -08:00
some more cleanup
This commit is contained in:
parent
20367eecc9
commit
774f21bb7f
|
@ -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'));
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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 = [
|
||||
|
|
|
@ -28,7 +28,6 @@ class DenormalizedEolAndAddColumnForExplicitDateToAssets extends Migration
|
|||
if($months != $asset->model->eol) {
|
||||
$asset->update(['eol_explicit' => true]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue