add check for default consumable qty
This commit is contained in:
parent
bb013d5c3c
commit
457f4c410a
1 changed files with 8 additions and 2 deletions
|
@ -57,8 +57,14 @@ class ConsumableCheckoutController extends Controller
|
||||||
|
|
||||||
$this->authorize('checkout', $consumable);
|
$this->authorize('checkout', $consumable);
|
||||||
|
|
||||||
|
// If the quantity is not present in the request or is not a positive integer, set it to 1
|
||||||
|
$quantity = $request->input('qty');
|
||||||
|
if (!isset($quantity) || !ctype_digit((string)$quantity) || $quantity <= 0) {
|
||||||
|
$quantity = 1;
|
||||||
|
}
|
||||||
|
|
||||||
// Make sure there is at least one available to checkout
|
// Make sure there is at least one available to checkout
|
||||||
if ($consumable->numRemaining() <= 0 || $request->qty > $consumable->numRemaining()) {
|
if ($consumable->numRemaining() <= 0 || $quantity > $consumable->numRemaining()) {
|
||||||
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.checkout.unavailable'));
|
return redirect()->route('consumables.index')->with('error', trans('admin/consumables/message.checkout.unavailable'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,7 +81,7 @@ class ConsumableCheckoutController extends Controller
|
||||||
// Update the consumable data
|
// Update the consumable data
|
||||||
$consumable->assigned_to = e($request->input('assigned_to'));
|
$consumable->assigned_to = e($request->input('assigned_to'));
|
||||||
|
|
||||||
for($i = 0; $i < $request->qty; $i++){
|
for($i = 0; $i < $quantity; $i++){
|
||||||
$consumable->users()->attach($consumable->id, [
|
$consumable->users()->attach($consumable->id, [
|
||||||
'consumable_id' => $consumable->id,
|
'consumable_id' => $consumable->id,
|
||||||
'user_id' => $admin_user->id,
|
'user_id' => $admin_user->id,
|
||||||
|
|
Loading…
Add table
Reference in a new issue