From 3ea5d4ee4067b236af345416666faa8c6e976669 Mon Sep 17 00:00:00 2001 From: Robert-Azelis <82208283+Robert-Azelis@users.noreply.github.com> Date: Thu, 2 May 2024 12:55:17 +0200 Subject: [PATCH] Update BulkAssetsController.php Fix for bulk updarte of purchase date to calculate new EOL --- .../Assets/BulkAssetsController.php | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/app/Http/Controllers/Assets/BulkAssetsController.php b/app/Http/Controllers/Assets/BulkAssetsController.php index 561e13b200..92a38a6e8b 100644 --- a/app/Http/Controllers/Assets/BulkAssetsController.php +++ b/app/Http/Controllers/Assets/BulkAssetsController.php @@ -11,6 +11,7 @@ use App\Models\AssetModel; use App\Models\Statuslabel; use App\Models\Setting; use App\View\Label; +use Carbon\Carbon; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; @@ -267,11 +268,31 @@ class BulkAssetsController extends Controller $this->conditionallyAddItem($custom_field_column); } + if (!($asset->eol_explicit)) { + if ($request->filled('model_id')) { + $model = AssetModel::find($request->input('model_id')); + if ($model->eol > 0) { + if ($request->filled('purchase_date')) { + $this->update_array['asset_eol_date'] = Carbon::parse($request->input('purchase_date'))->addMonths($model->eol)->format('Y-m-d'); + } else { + $this->update_array['asset_eol_date'] = Carbon::parse($asset->purchase_date)->addMonths($model->eol)->format('Y-m-d'); + } + } else { + $this->update_array['asset_eol_date'] = null; + } + } elseif (($request->filled('purchase_date')) && ($asset->model->eol > 0)) { + $this->update_array['asset_eol_date'] = Carbon::parse($request->input('purchase_date'))->addMonths($asset->model->eol)->format('Y-m-d'); + } + } + /** * Blank out fields that were requested to be blanked out via checkbox */ if ($request->input('null_purchase_date')=='1') { $this->update_array['purchase_date'] = null; + if (!($asset->eol_explicit)) { + $this->update_array['asset_eol_date'] = null; + } } if ($request->input('null_expected_checkin_date')=='1') {