Skip to content

Commit

Permalink
Merge pull request #14671 from Robert-Azelis/patch-6
Browse files Browse the repository at this point in the history
[FIX] Update EOL date when used bulk update of purchase date
  • Loading branch information
snipe authored Sep 19, 2024
2 parents d7bde37 + 3ea5d4e commit 4f7c8e0
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions app/Http/Controllers/Assets/BulkAssetsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use App\Models\Statuslabel;
use App\Models\Setting;
use App\View\Label;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Crypt;
use Illuminate\Support\Facades\DB;
Expand Down Expand Up @@ -271,6 +272,23 @@ public function update(Request $request) : RedirectResponse
$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
*/
Expand All @@ -281,6 +299,9 @@ public function update(Request $request) : RedirectResponse

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') {
Expand Down

0 comments on commit 4f7c8e0

Please sign in to comment.