Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions app/Http/Controllers/Api/UsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use App\Models\Company;
use App\Models\Consumable;
use App\Models\License;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\CurrentInventory;
use App\Notifications\WelcomeNotification;
Expand Down Expand Up @@ -662,6 +663,49 @@ public function assets(Request $request, $id) : JsonResponse | array

}

/**
* Print inventory
*
* @since [v8.3.2]
* @author Aladin Alaily
*/
public function printInventory($id)
{
$this->authorize('view', User::class);

$user = User::where('id', $id)
->with([
'assets.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
'assets.assignedAssets.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
'assets.assignedAssets.defaultLoc',
'assets.assignedAssets.location',
'assets.assignedAssets.model.category',
'assets.defaultLoc',
'assets.location',
'assets.model.category',
'accessories.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
'accessories.category',
'accessories.manufacturer',
'consumables.log' => fn($query) => $query->withTrashed()->where('target_type', User::class)->where('target_id', $id)->where('action_type', 'accepted'),
'consumables.category',
'consumables.manufacturer',
'licenses.category',
])
->withTrashed()
->first();

if ($user) {
$this->authorize('view', $user);

return response()->json(Helper::formatStandardApiResponse('success',view('users.print')
->with('users', [$user])
->with('settings', Setting::getSettings())
->render(), null));
}

return response()->json(Helper::formatStandardApiResponse('error', null, trans('admin/users/message.user_not_found', compact('id'))));
}

/**
* Notify a specific user via email with all of their assigned assets.
*
Expand Down
8 changes: 8 additions & 0 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -1103,6 +1103,14 @@
]
)->name('api.users.email_assets');

Route::get('{userId}/print',
[
Api\UsersController::class,
'printInventory'
]
)->name('api.users.print');


Route::get('{user}/accessories',
[
Api\UsersController::class,
Expand Down
Loading