|
18 | 18 | use App\Models\Company;
|
19 | 19 | use App\Models\Consumable;
|
20 | 20 | use App\Models\License;
|
| 21 | +use App\Models\Setting; |
21 | 22 | use App\Models\User;
|
22 | 23 | use App\Notifications\CurrentInventory;
|
23 | 24 | use App\Notifications\WelcomeNotification;
|
@@ -662,6 +663,48 @@ public function assets(Request $request, $id) : JsonResponse | array
|
662 | 663 |
|
663 | 664 | }
|
664 | 665 |
|
| 666 | + /** |
| 667 | + * Print inventory |
| 668 | + * |
| 669 | + * @since [v8.3.2] |
| 670 | + * @author Aladin Alaily |
| 671 | + */ |
| 672 | + public function printInventory($id) |
| 673 | + { |
| 674 | + $this->authorize('view', User::class); |
| 675 | + |
| 676 | + $user = User::where('id', $id) |
| 677 | + ->with([ |
| 678 | + 'assets.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'), |
| 679 | + 'assets.assignedAssets.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'), |
| 680 | + 'assets.assignedAssets.defaultLoc', |
| 681 | + 'assets.assignedAssets.location', |
| 682 | + 'assets.assignedAssets.model.category', |
| 683 | + 'assets.defaultLoc', |
| 684 | + 'assets.location', |
| 685 | + 'assets.model.category', |
| 686 | + 'accessories.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'), |
| 687 | + 'accessories.category', |
| 688 | + 'accessories.manufacturer', |
| 689 | + 'consumables.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'), |
| 690 | + 'consumables.category', |
| 691 | + 'consumables.manufacturer', |
| 692 | + 'licenses.category', |
| 693 | + ]) |
| 694 | + ->withTrashed() |
| 695 | + ->first(); |
| 696 | + |
| 697 | + if ($user) { |
| 698 | + $this->authorize('view', $user); |
| 699 | + |
| 700 | + return view('users.print') |
| 701 | + ->with('users', [$user]) |
| 702 | + ->with('settings', Setting::getSettings()); |
| 703 | + } |
| 704 | + |
| 705 | + return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id'))); |
| 706 | + } |
| 707 | + |
665 | 708 | /**
|
666 | 709 | * Notify a specific user via email with all of their assigned assets.
|
667 | 710 | *
|
|
0 commit comments