-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15185 from arne-kroeger/feat/accesspories-checkou…
…t-to-location-or-asset Added #14979: add checkout to location and assets functionality to accessories
- Loading branch information
Showing
21 changed files
with
411 additions
and
123 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ | |
use App\Helpers\Helper; | ||
use App\Http\Controllers\Controller; | ||
use App\Models\Accessory; | ||
use App\Models\AccessoryCheckout; | ||
use App\Models\User; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\DB; | ||
|
@@ -24,7 +25,7 @@ class AccessoryCheckinController extends Controller | |
*/ | ||
public function create($accessoryUserId = null, $backto = null) : View | RedirectResponse | ||
{ | ||
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) { | ||
if (is_null($accessory_user = DB::table('accessories_checkout')->find($accessoryUserId))) { | ||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.not_found')); | ||
} | ||
|
||
|
@@ -39,16 +40,16 @@ public function create($accessoryUserId = null, $backto = null) : View | Redirec | |
* | ||
* @uses Accessory::checkin_email() to determine if an email can and should be sent | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @param null $accessoryUserId | ||
* @param null $accessoryCheckoutId | ||
* @param string $backto | ||
*/ | ||
public function store(Request $request, $accessoryUserId = null, $backto = null) : RedirectResponse | ||
public function store(Request $request, $accessoryCheckoutId = null, $backto = null) : RedirectResponse | ||
{ | ||
if (is_null($accessory_user = DB::table('accessories_users')->find($accessoryUserId))) { | ||
if (is_null($accessory_checkout = AccessoryCheckout::find($accessoryCheckoutId))) { | ||
return redirect()->route('accessories.index')->with('error', trans('admin/accessories/message.does_not_exist')); | ||
} | ||
|
||
$accessory = Accessory::find($accessory_user->accessory_id); | ||
$accessory = Accessory::find($accessory_checkout->accessory_id); | ||
|
||
$this->authorize('checkin', $accessory); | ||
|
||
|
@@ -59,10 +60,8 @@ public function store(Request $request, $accessoryUserId = null, $backto = null) | |
} | ||
|
||
// 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'), $checkin_at)); | ||
if ($accessory_checkout->delete()) { | ||
event(new CheckoutableCheckedIn($accessory, $accessory_checkout->assignedTo, auth()->user(), $request->input('note'), $checkin_at)); | ||
|
||
session()->put(['redirect_option' => $request->get('redirect_option')]); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,9 +4,11 @@ | |
|
||
use App\Events\CheckoutableCheckedOut; | ||
use App\Helpers\Helper; | ||
use App\Http\Controllers\CheckInOutRequest; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\AccessoryCheckoutRequest; | ||
use App\Models\Accessory; | ||
use App\Models\AccessoryCheckout; | ||
use App\Models\User; | ||
use Carbon\Carbon; | ||
use Illuminate\Http\Request; | ||
|
@@ -16,6 +18,9 @@ | |
|
||
class AccessoryCheckoutController extends Controller | ||
{ | ||
|
||
use CheckInOutRequest; | ||
|
||
/** | ||
* Return the form to checkout an Accessory to a user. | ||
* | ||
|
@@ -25,7 +30,7 @@ class AccessoryCheckoutController extends Controller | |
public function create($id) : View | RedirectResponse | ||
{ | ||
|
||
if ($accessory = Accessory::withCount('users as users_count')->find($id)) { | ||
if ($accessory = Accessory::withCount('checkouts as checkouts_count')->find($id)) { | ||
|
||
$this->authorize('checkout', $accessory); | ||
|
||
|
@@ -58,30 +63,32 @@ public function create($id) : View | RedirectResponse | |
* | ||
* @author [A. Gianotto] [<[email protected]>] | ||
* @param Request $request | ||
* @param int $accessory | ||
* @param Accessory $accessory | ||
*/ | ||
public function store(AccessoryCheckoutRequest $request, Accessory $accessory) : RedirectResponse | ||
{ | ||
|
||
$this->authorize('checkout', $accessory); | ||
$accessory->assigned_to = $request->input('assigned_to'); | ||
$user = User::find($request->input('assigned_to')); | ||
$accessory->checkout_qty = $request->input('checkout_qty', 1); | ||
|
||
$target = $this->determineCheckoutTarget(); | ||
|
||
$accessory->checkout_qty = $request->input('checkout_qty', 1); | ||
|
||
for ($i = 0; $i < $accessory->checkout_qty; $i++) { | ||
$accessory->users()->attach($accessory->id, [ | ||
AccessoryCheckout::create([ | ||
'accessory_id' => $accessory->id, | ||
'created_at' => Carbon::now(), | ||
'user_id' => Auth::id(), | ||
'assigned_to' => $request->input('assigned_to'), | ||
'assigned_to' => $target->id, | ||
'assigned_type' => $target::class, | ||
'note' => $request->input('note'), | ||
]); | ||
} | ||
event(new CheckoutableCheckedOut($accessory, $user, auth()->user(), $request->input('note'))); | ||
event(new CheckoutableCheckedOut($accessory, $target, auth()->user(), $request->input('note'))); | ||
|
||
// Set this as user since we only allow checkout to user for this item type | ||
$request->request->add(['checkout_to_type' => 'user']); | ||
$request->request->add(['assigned_user' => $user->id]); | ||
$request->request->add(['checkout_to_type' => request('checkout_to_type')]); | ||
$request->request->add(['assigned_user' => $target->id]); | ||
|
||
session()->put(['redirect_option' => $request->get('redirect_option'), 'checkout_to_type' => $request->get('checkout_to_type')]); | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.