Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds quantity of accessories and consumables to checkout. #14342

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/Events/CheckoutableCheckedOut.php
Expand Up @@ -12,6 +12,7 @@ class CheckoutableCheckedOut

public $checkoutable;
public $checkedOutTo;
public $quantity;
public $checkedOutBy;
public $note;
public $originalValues;
Expand All @@ -21,11 +22,12 @@ class CheckoutableCheckedOut
*
* @return void
*/
public function __construct($checkoutable, $checkedOutTo, User $checkedOutBy, $note, $originalValues = [])
public function __construct($checkoutable, $checkedOutTo, User $checkedOutBy, $note, $originalValues = [], $quantity=null)
{
$this->checkoutable = $checkoutable;
$this->checkedOutTo = $checkedOutTo;
$this->checkedOutBy = $checkedOutBy;
$this->quantity = $quantity;
$this->note = $note;
$this->originalValues = $originalValues;
}
Expand Down
Expand Up @@ -81,21 +81,24 @@ public function store(Request $request, $accessoryId)
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.checkout.unavailable'));
}


$quantity =$request->input('assigned_qty');
Godmartinz marked this conversation as resolved.
Show resolved Hide resolved
// Update the accessory data
$accessory->assigned_to = e($request->input('assigned_to'));

$accessory->users()->attach($accessory->id, [
'accessory_id' => $accessory->id,
'created_at' => Carbon::now(),
'user_id' => Auth::id(),
'assigned_to' => $request->get('assigned_to'),
'note' => $request->input('note'),
]);
for($qty=0;$qty< $quantity; $qty++) {
$accessory->users()->attach($accessory->id, [
'accessory_id' => $accessory->id,
'created_at' => Carbon::now(),
'user_id' => Auth::id(),
'assigned_to' => $request->get('assigned_to'),
'note' => $request->input('note'),
]);
}

event(new CheckoutableCheckedOut($accessory, $user, Auth::user(), $request->input('note'), [], $quantity ));

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')));

// Redirect to the new accessory page
return redirect()->route('accessories.index')->with('success', trans('admin/accessories/message.checkout.success'));
Expand Down
20 changes: 10 additions & 10 deletions app/Http/Controllers/Consumables/ConsumableCheckoutController.php
Expand Up @@ -84,18 +84,18 @@ public function store(Request $request, $consumableId)
// Redirect to the consumable management page with error
return redirect()->route('consumables.checkout.show', $consumable)->with('error', trans('admin/consumables/message.checkout.user_does_not_exist'))->withInput();
}

$quantity = $request->input('assigned_qty');
Godmartinz marked this conversation as resolved.
Show resolved Hide resolved
// Update the consumable data
$consumable->assigned_to = e($request->input('assigned_to'));

$consumable->users()->attach($consumable->id, [
'consumable_id' => $consumable->id,
'user_id' => $admin_user->id,
'assigned_to' => e($request->input('assigned_to')),
'note' => $request->input('note'),
]);

event(new CheckoutableCheckedOut($consumable, $user, Auth::user(), $request->input('note')));
for($qty=0;$qty < $quantity; $qty++) {
$consumable->users()->attach($consumable->id, [
'consumable_id' => $consumable->id,
'user_id' => $admin_user->id,
'assigned_to' => e($request->input('assigned_to')),
'note' => $request->input('note'),
]);
}
event(new CheckoutableCheckedOut($consumable, $user, Auth::user(), $request->input('note'), [], $quantity));

// Redirect to the new consumable page
return redirect()->route('consumables.index')->with('success', trans('admin/consumables/message.checkout.success'));
Expand Down
2 changes: 1 addition & 1 deletion app/Listeners/CheckoutableListener.php
Expand Up @@ -231,7 +231,7 @@ private function getCheckoutNotification($event, $acceptance = null)
}


return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note);
return new $notificationClass($event->checkoutable, $event->checkedOutTo, $event->checkedOutBy, $acceptance, $event->note, $event->quantity);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/CheckoutAccessoryNotification.php
Expand Up @@ -24,11 +24,12 @@ class CheckoutAccessoryNotification extends Notification
/**
* Create a new notification instance.
*/
public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
public function __construct(Accessory $accessory, $checkedOutTo, User $checkedOutBy, $acceptance, $note, $quantity)
{
$this->item = $accessory;
$this->admin = $checkedOutBy;
$this->note = $note;
$this->quantity = $quantity;
$this->target = $checkedOutTo;
$this->acceptance = $acceptance;
$this->settings = Setting::getSettings();
Expand Down Expand Up @@ -180,6 +181,7 @@ public function toMail()
'admin' => $this->admin,
'note' => $this->note,
'target' => $this->target,
'quantity' => $this->quantity,
'eula' => $eula,
'req_accept' => $req_accept,
'accept_url' => $accept_url,
Expand Down
4 changes: 3 additions & 1 deletion app/Notifications/CheckoutConsumableNotification.php
Expand Up @@ -30,11 +30,12 @@ class CheckoutConsumableNotification extends Notification
*
* @param $params
*/
public function __construct(Consumable $consumable, $checkedOutTo, User $checkedOutBy, $acceptance, $note)
public function __construct(Consumable $consumable, $checkedOutTo, User $checkedOutBy, $acceptance, $note, $quantity)
{
$this->item = $consumable;
$this->admin = $checkedOutBy;
$this->note = $note;
$this->quantity = $quantity;
$this->target = $checkedOutTo;
$this->acceptance = $acceptance;

Expand Down Expand Up @@ -183,6 +184,7 @@ public function toMail()
'item' => $this->item,
'admin' => $this->admin,
'note' => $this->note,
'quantity' => $this->quantity,
'target' => $this->target,
'eula' => $eula,
'req_accept' => $req_accept,
Expand Down
2 changes: 1 addition & 1 deletion config/debugbar.php
Expand Up @@ -12,7 +12,7 @@
|
*/

'enabled' => null,
'enabled' => false,
Godmartinz marked this conversation as resolved.
Show resolved Hide resolved

/*
|--------------------------------------------------------------------------
Expand Down
13 changes: 13 additions & 0 deletions resources/views/accessories/checkout.blade.php
Expand Up @@ -53,6 +53,19 @@

@include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to'])

<div class="form-group {{ $errors->has('assigned_qty') ? ' has-error' : '' }}">
<label for="assigned_qty" class="col-md-3 control-label">
{{ trans('general.qty') }}
</label>
<div class="col-md-2 col-sm-5 col-xs-5">
<input class="form-control required col-md-12" type="text" name="assigned_qty" id="assigned_qty" value="{{ old('assigned_qty') ?? 1 }}" />
Godmartinz marked this conversation as resolved.
Show resolved Hide resolved
</div>
@if ($errors->first('assigned_qty'))
<div class="col-md-9 col-md-offset-3">
{!! $errors->first('assigned_qty', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
@endif
</div>

@if ($accessory->requireAcceptance() || $accessory->getEula() || ($snipeSettings->webhook_endpoint!=''))
<div class="form-group notification-callout">
Expand Down
13 changes: 13 additions & 0 deletions resources/views/consumables/checkout.blade.php
Expand Up @@ -40,6 +40,19 @@
<!-- User -->
@include ('partials.forms.edit.user-select', ['translated_name' => trans('general.select_user'), 'fieldname' => 'assigned_to', 'required'=> 'true'])

<div class="form-group {{ $errors->has('assigned_qty') ? ' has-error' : '' }}">
<label for="assigned_qty" class="col-md-3 control-label">
{{ trans('general.qty') }}
</label>
<div class="col-md-2 col-sm-5 col-xs-5">
<input class="form-control required col-md-12" type="text" name="assigned_qty" id="assigned_qty" value="{{ old('assigned_qty') ?? 1 }}" />
</div>
@if ($errors->first('assigned_qty'))
<div class="col-md-9 col-md-offset-3">
{!! $errors->first('assigned_qty', '<span class="alert-msg" aria-hidden="true"><i class="fas fa-times" aria-hidden="true"></i> :message</span>') !!}
</div>
@endif
</div>

@if ($consumable->requireAcceptance() || $consumable->getEula() || ($snipeSettings->webhook_endpoint!=''))
<div class="form-group notification-callout">
Expand Down
Expand Up @@ -14,6 +14,9 @@
| **{{ trans('mail.checkout_date') }}** | {{ $checkout_date }} |
@endif
| **{{ trans('general.accessory') }}** | {{ $item->name }} |
@if (isset($quantity))
| **{{ trans('general.qty') }}** | {{ $quantity }} |
@endif
@if (isset($item->manufacturer))
| **{{ trans('general.manufacturer') }}** | {{ $item->manufacturer->name }} |
@endif
Expand Down
Expand Up @@ -11,6 +11,9 @@
| **{{ trans('mail.checkout_date') }}** | {{ $checkout_date }} |
@endif
| **{{ trans('general.consumable') }}** | {{ $item->name }} |
@if (isset($quantity))
| **{{ trans('general.qty') }}** | {{ $quantity }} |
@endif
@if (isset($item->manufacturer))
| **{{ trans('general.manufacturer') }}** | {{ $item->manufacturer->name }} |
@endif
Expand Down