From f85ac97d8c14fcc66805c7d6b35d5ea1e188217e Mon Sep 17 00:00:00 2001 From: sreyemnayr Date: Thu, 23 May 2019 21:39:30 -0500 Subject: [PATCH] Feedback for Kits; Fix checkins for accessories (#7060) * Kits feedback * Fix accessory checkin --- .../AccessoryCheckinController.php | 7 ++- .../Kits/CheckoutKitController.php | 12 ++-- app/Services/PredefinedKitCheckoutService.php | 13 +++-- resources/views/accessories/checkin.blade.php | 20 ++++++- resources/views/notifications.blade.php | 55 +++++++++++++++++++ 5 files changed, 93 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Accessories/AccessoryCheckinController.php b/app/Http/Controllers/Accessories/AccessoryCheckinController.php index f52ba10547..1cfbaec1b4 100644 --- a/app/Http/Controllers/Accessories/AccessoryCheckinController.php +++ b/app/Http/Controllers/Accessories/AccessoryCheckinController.php @@ -59,11 +59,16 @@ class AccessoryCheckinController extends Controller $this->authorize('checkin', $accessory); + $checkin_at = date('Y-m-d'); + if($request->filled('checkin_at')){ + $checkin_at = $request->input('checkin_at'); + } + // Was the accessory updated? if (DB::table('accessories_users')->where('id', '=', $accessory_user->id)->delete()) { $return_to = e($accessory_user->assigned_to); - event(new CheckoutableCheckedIn($accessory, User::find($return_to), Auth::user(), $request->input('note'))); + event(new CheckoutableCheckedIn($accessory, User::find($return_to), Auth::user(), $request->input('note'), $checkin_at)); return redirect()->route("accessories.show", $accessory->id)->with('success', trans('admin/accessories/message.checkin.success')); } diff --git a/app/Http/Controllers/Kits/CheckoutKitController.php b/app/Http/Controllers/Kits/CheckoutKitController.php index e7f35b69b1..0d99560751 100644 --- a/app/Http/Controllers/Kits/CheckoutKitController.php +++ b/app/Http/Controllers/Kits/CheckoutKitController.php @@ -9,6 +9,7 @@ use App\Models\PredefinedModel; use App\Models\User; use App\Services\PredefinedKitCheckoutService; use Illuminate\Http\Request; +use Illuminate\Support\Arr; /** * This controller handles all access kits management: @@ -57,11 +58,14 @@ class CheckoutKitController extends Controller $kit = new PredefinedKit(); $kit->id = $kit_id; - $errors = $this->kitService->checkout($request, $kit, $user); - if (count($errors) > 0) { - return redirect()->back()->with('error', 'Checkout error')->with('error_messages', $errors); // TODO: trans + $checkout_result = $this->kitService->checkout($request, $kit, $user); + if (Arr::has($checkout_result, 'errors') && count($checkout_result['errors']) > 0 ) { + return redirect()->back()->with('error', 'Checkout error')->with('error_messages', $checkout_result['errors']); // TODO: trans } - return redirect()->back()->with('success', 'Checkout was successfully'); // TODO: trans + return redirect()->back()->with('success', 'Checkout was successful') + ->with('assets', Arr::get($checkout_result, 'assets', null)) + ->with('accessories', Arr::get($checkout_result, 'accessories', null)) + ->with('consumables', Arr::get($checkout_result, 'consumables', null)); // TODO: trans } } diff --git a/app/Services/PredefinedKitCheckoutService.php b/app/Services/PredefinedKitCheckoutService.php index 5b7db980ef..8a1c624cbe 100644 --- a/app/Services/PredefinedKitCheckoutService.php +++ b/app/Services/PredefinedKitCheckoutService.php @@ -29,7 +29,7 @@ class PredefinedKitCheckoutService // Check if the user exists if (is_null($user)) { - return [trans('admin/users/message.user_not_found')]; + return ['errors' => trans('admin/users/message.user_not_found')]; } $errors = []; @@ -40,7 +40,7 @@ class PredefinedKitCheckoutService $accessories_to_add = $this->getAccessoriesToAdd($kit, $errors); if (count($errors) > 0) { - return $errors; + return ['errors' => $errors]; } $checkout_at = date("Y-m-d H:i:s"); @@ -58,11 +58,12 @@ class PredefinedKitCheckoutService $note = e($request->get('note')); $errors = $this->saveToDb($user, $admin, $checkout_at, $expected_checkin, $errors, $assets_to_add, $license_seats_to_add, $consumables_to_add, $accessories_to_add, $note); - return $errors; + + return ['errors' => $errors, 'assets' => $assets_to_add, 'accessories' => $accessories_to_add, 'consumables' => $consumables_to_add ]; } catch (ModelNotFoundException $e) { - return [$e->getMessage()]; + return ['errors' => [$e->getMessage()]]; } catch (CheckoutNotAllowed $e) { - return [$e->getMessage()]; + return ['errors' => [$e->getMessage()]]; } } @@ -134,7 +135,7 @@ class PredefinedKitCheckoutService $accessories = $kit->accessories()->with('users')->get(); foreach ($accessories as $accessory) { if ($accessory->numRemaining() < $accessory->pivot->quantity) { - $errors[] = trans('admin/kits/general.none_accessory', ['consumable'=> $accessory->name, 'qty' => $accessory->pivot->quantity]); + $errors[] = trans('admin/kits/general.none_accessory', ['accessory'=> $accessory->name, 'qty' => $accessory->pivot->quantity]); } } return $accessories; diff --git a/resources/views/accessories/checkin.blade.php b/resources/views/accessories/checkin.blade.php index fed09d8d23..da0c3a6176 100755 --- a/resources/views/accessories/checkin.blade.php +++ b/resources/views/accessories/checkin.blade.php @@ -30,9 +30,7 @@ @endif -
- -
+
@@ -54,12 +52,28 @@ {!! $errors->first('note', ' :message') !!}
+ +
+ {{ Form::label('checkin_at', trans('admin/hardware/form.checkin_date'), array('class' => 'col-md-3 control-label')) }} +
+
+
+ + +
+ {!! $errors->first('checkin_at', ' :message') !!} +
+
+
+ + + diff --git a/resources/views/notifications.blade.php b/resources/views/notifications.blade.php index 4ba0bcae96..960a83019a 100755 --- a/resources/views/notifications.blade.php +++ b/resources/views/notifications.blade.php @@ -34,6 +34,58 @@ @endif + +@if ($assets = Session::get('assets')) + @foreach ($assets as $asset) +
+
+ + + Asset Information: +
    + @isset ($asset->model->name) +
  • Model Name: {{ $asset->model->name }}
  • + @endisset + @isset ($asset->name) +
  • Asset Name: {{ $asset->model->name }}
  • + @endisset +
  • Asset Tag: {{ $asset->asset_tag }}
  • +
+ +
+
+ @endforeach +@endif + + +@if ($consumables = Session::get('consumables')) + @foreach ($consumables as $consumable) +
+
+ + + Consumable Information: +
  • Name: {{ $consumable->name }}
+
+
+ @endforeach +@endif + + +@if ($accessories = Session::get('accessories')) + @foreach ($accessories as $accessory) +
+
+ + + Accessory Information: +
  • Name: {{ $accessory->name }}
+
+
+ @endforeach +@endif + + @if ($message = Session::get('error'))
@@ -45,6 +97,7 @@
@endif + @if ($messages = Session::get('error_messages')) @foreach ($messages as $message)
@@ -58,6 +111,7 @@ @endforeach @endif + @if ($message = Session::get('warning'))
@@ -69,6 +123,7 @@
@endif + @if ($message = Session::get('info'))