From f5eedb8d2359454d96473708b40eecc604d7f6ad Mon Sep 17 00:00:00 2001 From: snipe Date: Sat, 22 Feb 2025 18:13:12 +0000 Subject: [PATCH] Added RMB and include $item so the asset fields are populated Signed-off-by: snipe --- .../Assets/AssetCheckinController.php | 35 ++++++++++++++----- .../Assets/AssetCheckoutController.php | 22 +++++++++--- 2 files changed, 45 insertions(+), 12 deletions(-) diff --git a/app/Http/Controllers/Assets/AssetCheckinController.php b/app/Http/Controllers/Assets/AssetCheckinController.php index f84a468a6..0541fa926 100644 --- a/app/Http/Controllers/Assets/AssetCheckinController.php +++ b/app/Http/Controllers/Assets/AssetCheckinController.php @@ -27,18 +27,12 @@ class AssetCheckinController extends Controller * @param string $backto * @since [v1.0] */ - public function create($assetId, $backto = null) : View | RedirectResponse + public function create(Asset $asset, $backto = null) : View | RedirectResponse { - // Check if the asset exists - if (is_null($asset = Asset::find($assetId))) { - // Redirect to the asset management page with error - return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.does_not_exist')); - } $this->authorize('checkin', $asset); // This asset is already checked in, redirect - if (is_null($asset->assignedTo)) { return redirect()->route('hardware.index')->with('error', trans('admin/hardware/message.checkin.already_checked_in')); } @@ -47,7 +41,11 @@ class AssetCheckinController extends Controller return redirect()->route('hardware.show', $asset->id)->with('error', trans('admin/hardware/general.model_invalid_fix')); } - return view('hardware/checkin', compact('asset'))->with('statusLabel_list', Helper::statusLabelList())->with('backto', $backto)->with('table_name', 'Assets'); + return view('hardware/checkin', compact('asset')) + ->with('item', $asset) + ->with('statusLabel_list', Helper::statusLabelList()) + ->with('backto', $backto) + ->with('table_name', 'Assets'); } /** @@ -91,6 +89,17 @@ class AssetCheckinController extends Controller $asset->status_id = e($request->get('status_id')); } + // Check to see if any of the custom fields were included on the form and if they have any values + if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields)) { + foreach ($asset->model->fieldset->fields as $field) { + if ($field->display_checkin == 1) { + if ($request->has($field->db_column)) { + $asset->{$field->db_column} = $request->get($field->db_column); + } + } + } + } + $this->migrateLegacyLocations($asset); $asset->location_id = $asset->rtd_location_id; @@ -127,6 +136,16 @@ class AssetCheckinController extends Controller }); session()->put('redirect_option', $request->get('redirect_option')); + // Check to see if any of the custom fields were included on the form and if they have any values + if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields)) { + foreach ($asset->model->fieldset->fields as $field) { + if ($field->display_checkin == 1) { + if ($request->filled($field->db_column)) { + $asset->{$field->db_column} = $request->get($field->db_column); + } + } + } + } if ($asset->save()) { diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index 871024029..cce8c34d1 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -39,7 +39,8 @@ class AssetCheckoutController extends Controller if ($asset->availableForCheckout()) { return view('hardware/checkout', compact('asset')) ->with('statusLabel_list', Helper::deployableStatusLabelList()) - ->with('table_name', 'Assets'); + ->with('table_name', 'Assets') + ->with('item', $asset); } return redirect()->route('hardware.index') @@ -88,6 +89,7 @@ class AssetCheckoutController extends Controller $asset->status_id = $request->get('status_id'); } + if(!empty($asset->licenseseats->all())){ if(request('checkout_to_type') == 'user') { foreach ($asset->licenseseats as $seat){ @@ -97,23 +99,35 @@ class AssetCheckoutController extends Controller } } + // Check to see if any of the custom fields were included on the form and if they have any values + if (($asset->model) && ($asset->model->fieldset) && ($asset->model->fieldset->fields)) { + foreach ($asset->model->fieldset->fields as $field) { + if ($field->display_checkout == 1) { + if ($request->has($field->db_column)) { + $asset->{$field->db_column} = $request->get($field->db_column); + } + } + } + } + + $settings = \App\Models\Setting::getSettings(); // We have to check whether $target->company_id is null here since locations don't have a company yet if (($settings->full_multiple_companies_support) && ((!is_null($target->company_id)) && (!is_null($asset->company_id)))) { if ($target->company_id != $asset->company_id){ - return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company')); + return redirect()->route('hardware.checkout.create', $asset)->with('error', trans('general.error_user_company')); } } - session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); + session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) { return redirect()->to(Helper::getRedirectOption($request, $asset->id, 'Assets')) ->with('success', trans('admin/hardware/message.checkout.success')); } // Redirect to the asset management page with error - return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors()); + return redirect()->route("hardware.checkout.create", $asset)->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors()); } catch (ModelNotFoundException $e) { return redirect()->back()->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors()); } catch (CheckoutNotAllowed $e) {