From 5aee5a3f3d97da9b8e0f0e3555a67b1d8ea8bb1f Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 7 Nov 2017 17:37:08 -0800 Subject: [PATCH 1/2] Update location on checkout, error if bad target --- app/Http/Controllers/AssetsController.php | 31 +++++++++++++++-------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/AssetsController.php b/app/Http/Controllers/AssetsController.php index ca13e6e2f..84d891d96 100755 --- a/app/Http/Controllers/AssetsController.php +++ b/app/Http/Controllers/AssetsController.php @@ -454,14 +454,32 @@ class AssetsController extends Controller } $this->authorize('checkout', $asset); + + // Fetch the target and set the asset's new location_id if (request('assigned_user')) { $target = User::find(request('assigned_user')); + $asset->location_id = ($target) ? $target->location_id : ''; + } elseif (request('assigned_asset')) { + $target = Asset::where('id','!=',$assetId)->find(request('assigned_asset')); + $asset->location_id = $target->rtd_location_id; + + // Override with the asset's location_id if it has one + if ($target->location_id!='') { + $asset->location_id = ($target) ? $target->location_id : ''; + } + } elseif (request('assigned_location')) { $target = Location::find(request('assigned_location')); + $asset->location_id = ($target) ? $target->id : ''; } - // $user = User::find(Input::get('assigned_to')); + + // No valid target was found - error out + if (!$target) { + return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors()); + } + $admin = Auth::user(); if ((Input::has('checkout_at')) && (Input::get('checkout_at')!= date("Y-m-d"))) { @@ -476,22 +494,13 @@ class AssetsController extends Controller $expected_checkin = ''; } - // Set the location ID to the RTD location id if there is one - if ($asset->rtd_location_id!='') { - $asset->location_id = $target->rtd_location_id; - } - - // Overwrite that if the target has a location ID though - if ($target->location_id!='') { - $asset->location_id = $target->location_id; - } if ($asset->checkOut($target, $admin, $checkout_at, $expected_checkin, e(Input::get('note')), Input::get('name'))) { // Redirect to the new asset page return redirect()->route("hardware.index")->with('success', trans('admin/hardware/message.checkout.success')); } - // Redirect to the asset management page with error + // Redirect to the asset management page with error return redirect()->to("hardware/$assetId/checkout")->with('error', trans('admin/hardware/message.checkout.error'))->withErrors($asset->getErrors()); } From eed50112d5a12868c3231b7d3e8eb9a69bebebb2 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 7 Nov 2017 18:18:27 -0800 Subject: [PATCH 2/2] =?UTF-8?q?Better=20fallback=20for=20local=20that=20wo?= =?UTF-8?q?n=E2=80=99t=20break=20migrations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/app.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/app.php b/config/app.php index d6b52a1de..5b89f5781 100755 --- a/config/app.php +++ b/config/app.php @@ -78,7 +78,7 @@ return [ | */ - 'locale' => env('APP_LOCALE', 'en_US.UTF-8'), + 'locale' => env('APP_LOCALE', 'en'), /* |--------------------------------------------------------------------------