diff --git a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php index 6144bb6f92..db41731ddb 100644 --- a/app/Http/Controllers/Accessories/AccessoryCheckoutController.php +++ b/app/Http/Controllers/Accessories/AccessoryCheckoutController.php @@ -77,6 +77,14 @@ class AccessoryCheckoutController extends Controller 'note' => $request->input('note'), ]); + $checkedout=DB::table('accessories_users')->where('accessory_id', '=', $accessory->id)->count(); + $available=DB::table('accessories')->where('id', '=', $accessory->id)->first('qty'); + + if($checkedout >= $available->qty){ + + return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkout.unavailable')); + } + DB::table('accessories_users')->where('assigned_to', '=', $accessory->assigned_to)->where('accessory_id', '=', $accessory->id)->first(); event(new CheckoutableCheckedOut($accessory, $user, Auth::user(), $request->input('note'))); diff --git a/resources/lang/en/admin/accessories/message.php b/resources/lang/en/admin/accessories/message.php index a356463064..542f71f03c 100644 --- a/resources/lang/en/admin/accessories/message.php +++ b/resources/lang/en/admin/accessories/message.php @@ -24,6 +24,7 @@ return array( 'checkout' => array( 'error' => 'Accessory was not checked out, please try again', 'success' => 'Accessory checked out successfully.', + 'unavailable' => 'Accessory is not available for checkout. Check quantity available', 'user_does_not_exist' => 'That user is invalid. Please try again.' ),