Skip to content

Commit 27edcad

Browse files
committed
add api endpoint to request user asset print
1 parent 80c059b commit 27edcad

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

app/Http/Controllers/Api/UsersController.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use App\Models\Company;
1919
use App\Models\Consumable;
2020
use App\Models\License;
21+
use App\Models\Setting;
2122
use App\Models\User;
2223
use App\Notifications\CurrentInventory;
2324
use App\Notifications\WelcomeNotification;
@@ -662,6 +663,48 @@ public function assets(Request $request, $id) : JsonResponse | array
662663

663664
}
664665

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+
665708
/**
666709
* Notify a specific user via email with all of their assigned assets.
667710
*

routes/api.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,6 +1103,14 @@
11031103
]
11041104
)->name('api.users.email_assets');
11051105

1106+
Route::get('{userId}/print',
1107+
[
1108+
Api\UsersController::class,
1109+
'printInventory'
1110+
]
1111+
)->name('api.users.print');
1112+
1113+
11061114
Route::get('{user}/accessories',
11071115
[
11081116
Api\UsersController::class,

0 commit comments

Comments
 (0)