This commit is contained in:
slong753 2023-07-13 18:36:14 -05:00 committed by spencerrlongg
parent dc39d2c567
commit c1daabef08
4 changed files with 15 additions and 5 deletions

View file

@ -6,6 +6,7 @@ use App\Helpers\Helper;
use App\Http\Requests\ImageUploadRequest;
use App\Models\AssetModel;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\View;
use Illuminate\Support\Facades\Validator;
@ -91,6 +92,9 @@ 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)')]);
}
if ($this->shouldAddDefaultValues($request->input())) {
if (!$this->assignCustomFieldsDefaultValues($model, $request->input('default_values'))){
return redirect()->back()->withInput()->with('error', trans('admin/custom_fields/message.fieldset_default_value.error'));
@ -173,8 +177,13 @@ 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)')]);
}
return redirect()->route('models.index')->with('success', trans('admin/models/message.update.success'));
}

View file

@ -387,6 +387,9 @@ 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)')]);
}
return redirect()->route('hardware.show', $assetId)
->with('success', trans('admin/hardware/message.update.success'));
}

View file

@ -72,6 +72,7 @@ class Asset extends Depreciable
protected $casts = [
'purchase_date' => 'date',
'asset_eol_date' => 'date',
'last_checkout' => 'datetime',
'last_checkin' => 'datetime',
'expected_checkin' => 'date',

View file

@ -429,10 +429,7 @@ class AssetPresenter extends Presenter
public function eol_date()
{
if (($this->purchase_date) && ($this->model->model) && ($this->model->model->eol)) {
$date = date_create($this->purchase_date);
date_add($date, date_interval_create_from_date_string($this->model->model->eol.' months'));
return date_format($date, 'Y-m-d');
return $this->purchase_date->addMonths($this->model->model->eol)->format('Y-m-d');
}
}