From c94a7613ca0a806a93770fd90ff0b86f66c27707 Mon Sep 17 00:00:00 2001 From: Godfrey M Date: Thu, 2 May 2024 12:16:20 -0700 Subject: [PATCH] dropdown redirect options, helper function and session variable added --- app/Helpers/Helper.php | 24 +++++++++++++++++++ .../Assets/AssetCheckoutController.php | 10 +++++--- resources/views/hardware/checkout.blade.php | 11 +++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/app/Helpers/Helper.php b/app/Helpers/Helper.php index e3f2b036e0..8687be1e7e 100644 --- a/app/Helpers/Helper.php +++ b/app/Helpers/Helper.php @@ -14,6 +14,7 @@ use App\Models\Statuslabel; use App\Models\License; use Crypt; use Illuminate\Contracts\Encryption\DecryptException; +use Illuminate\Support\Facades\Session; use Image; use Carbon\Carbon; @@ -1459,4 +1460,27 @@ class Helper return $new_locale; // better that you have some weird locale that doesn't fit into our mappings anywhere than 'void' } + + static public function getRedirectOption($request, $assetId) + { + $redirect_option = session::get('redirect_option'); + + if ($redirect_option == '0') { + return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success')); + } + if ($redirect_option == '1') { + return redirect()->route('hardware.show', $assetId)->with('success', trans('admin/hardware/message.checkout.success')); + } + if ($redirect_option == '2') { + if ($request->assigned_location != null) { + return redirect()->route('users.show', $request->assigned_user)->with('success', trans('admin/hardware/message.checkout.success')); + } + } + if ($redirect_option == '3') { + if ($request->assigned_location != null) { + + return redirect()->route('locations.show', $request->assigned_location)->with('success', trans('admin/hardware/message.checkout.success')); + } + } + } } diff --git a/app/Http/Controllers/Assets/AssetCheckoutController.php b/app/Http/Controllers/Assets/AssetCheckoutController.php index a096f16678..e5f069c411 100644 --- a/app/Http/Controllers/Assets/AssetCheckoutController.php +++ b/app/Http/Controllers/Assets/AssetCheckoutController.php @@ -10,6 +10,7 @@ use App\Http\Requests\AssetCheckoutRequest; use App\Models\Asset; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Session; class AssetCheckoutController extends Controller { @@ -97,11 +98,14 @@ class AssetCheckoutController extends Controller return redirect()->to("hardware/$assetId/checkout")->with('error', trans('general.error_user_company')); } } - - if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) { - return redirect()->route('hardware.index')->with('success', trans('admin/hardware/message.checkout.success')); + $redirect_option = $request->get('redirect_option'); + if($redirect_option != Session::get('redirect_option')) { + Session::put('redirect_option', $redirect_option); } + if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, $request->get('note'), $request->get('name'))) { + return Helper::getRedirectOption($request, $assetId); + } // Redirect to the asset management page with error return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error').$asset->getErrors()); } catch (ModelNotFoundException $e) { diff --git a/resources/views/hardware/checkout.blade.php b/resources/views/hardware/checkout.blade.php index 9f91dace17..c731fa88ae 100755 --- a/resources/views/hardware/checkout.blade.php +++ b/resources/views/hardware/checkout.blade.php @@ -144,6 +144,17 @@