diff --git a/app/Http/Controllers/Users/BulkUsersController.php b/app/Http/Controllers/Users/BulkUsersController.php index d13f904419..36b20973a7 100644 --- a/app/Http/Controllers/Users/BulkUsersController.php +++ b/app/Http/Controllers/Users/BulkUsersController.php @@ -13,6 +13,7 @@ use App\Models\Group; use App\Models\LicenseSeat; use App\Models\ConsumableAssignment; use App\Models\Consumable; +use App\Models\Setting; use App\Models\User; use Carbon\Carbon; use Illuminate\Http\Request; @@ -76,6 +77,33 @@ class BulkUsersController extends Controller } return redirect()->back()->with('success', trans('admin/users/message.password_resets_sent')); + } elseif ($request->input('bulk_actions') == 'print') { + $users = User::query() + ->with([ + 'assets.assetlog', + 'assets.assignedAssets.assetlog', + 'assets.assignedAssets.defaultLoc', + 'assets.assignedAssets.location', + 'assets.assignedAssets.model.category', + 'assets.defaultLoc', + 'assets.location', + 'assets.model.category', + 'accessories.assetlog', + 'accessories.category', + 'accessories.manufacturer', + 'consumables.assetlog', + 'consumables.category', + 'consumables.manufacturer', + 'licenses.category', + ]) + ->withTrashed() + ->findMany($request->input('ids')); + + $users->each(fn($user) => $this->authorize('view', $user)); + + return view('users.print') + ->with('users', $users) + ->with('settings', Setting::getSettings()); } } diff --git a/app/Http/Controllers/Users/UsersController.php b/app/Http/Controllers/Users/UsersController.php index 61f94bd63a..051db1f4ef 100755 --- a/app/Http/Controllers/Users/UsersController.php +++ b/app/Http/Controllers/Users/UsersController.php @@ -597,23 +597,37 @@ class UsersController extends Controller public function printInventory($id) { $this->authorize('view', User::class); - if ($user = User::where('id', $id)->withTrashed()->first()) { + $user = User::where('id', $id) + ->with([ + 'assets.assetlog', + 'assets.assignedAssets.assetlog', + 'assets.assignedAssets.defaultLoc', + 'assets.assignedAssets.location', + 'assets.assignedAssets.model.category', + 'assets.defaultLoc', + 'assets.location', + 'assets.model.category', + 'accessories.assetlog', + 'accessories.category', + 'accessories.manufacturer', + 'consumables.assetlog', + 'consumables.category', + 'consumables.manufacturer', + 'licenses.category', + ]) + ->withTrashed() + ->first(); + + if ($user) { $this->authorize('view', $user); - $assets = Asset::where('assigned_to', $id)->where('assigned_type', User::class)->with('model', 'model.category')->get(); - $accessories = $user->accessories()->get(); - $consumables = $user->consumables()->get(); - return view('users/print')->with('assets', $assets) - ->with('licenses', $user->licenses()->get()) - ->with('accessories', $accessories) - ->with('consumables', $consumables) - ->with('show_user', $user) + return view('users.print') + ->with('users', [$user]) ->with('settings', Setting::getSettings()); } return redirect()->route('users.index')->with('error', trans('admin/users/message.user_not_found', compact('id'))); - } /** diff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.php index 3092228674..b566b1f19d 100644 --- a/resources/lang/en-US/general.php +++ b/resources/lang/en-US/general.php @@ -282,6 +282,7 @@ return [ 'status_label' => 'Status Label', 'status' => 'Status', 'accept_eula' => 'Acceptance Agreement', + 'show_or_hide_eulas' => 'Show/Hide EULAs', 'supplier' => 'Supplier', 'suppliers' => 'Suppliers', 'sure_to_delete' => 'Are you sure you wish to delete', diff --git a/resources/views/partials/users-bulk-actions.blade.php b/resources/views/partials/users-bulk-actions.blade.php index cf22fde03d..a1dbd25476 100644 --- a/resources/views/partials/users-bulk-actions.blade.php +++ b/resources/views/partials/users-bulk-actions.blade.php @@ -14,10 +14,11 @@ + @endcan @endif {{ Form::close() }} - \ No newline at end of file + diff --git a/resources/views/users/print.blade.php b/resources/views/users/print.blade.php index 26ed2e8127..a1fa3373ff 100644 --- a/resources/views/users/print.blade.php +++ b/resources/views/users/print.blade.php @@ -2,7 +2,11 @@ - {{ trans('general.assigned_to', ['name' => $show_user->present()->fullName()]) }} - {{ date('Y-m-d H:i', time()) }} + @if (count($users) === 1) + {{ trans('general.assigned_to', ['name' => $users[0]->present()->fullName()]) }} - {{ date('Y-m-d H:i', time()) }} + @else + {{ trans('admin/users/general.print_assigned') }} - {{ date('Y-m-d H:i', time()) }} + @endisset @@ -33,6 +37,10 @@ size: A4; } + #start_of_user_section { + break-before: page; + } + .print-logo { max-height: 40px; } @@ -54,6 +62,16 @@ +{{-- If we are rendering multiple users we'll add the ability to show/hide EULAs for all of them at once via this button --}} +@if (count($users) > 1) +
+ {{ trans('general.show_or_hide_eulas') }} + +
+@endif + @if ($snipeSettings->logo_print_assets=='1') @if ($snipeSettings->brand == '3') @@ -72,39 +90,39 @@ @endif @endif -

- {{ trans('general.assigned_to', ['name' => $show_user->present()->fullName()]) }} - {{ ($show_user->employee_num!='') ? ' (#'.$show_user->employee_num.') ' : '' }} - {{ ($show_user->jobtitle!='' ? ' - '.$show_user->jobtitle : '') }} -

-

{{ trans('admin/users/general.all_assigned_list_generation')}} {{ Helper::getFormattedDateObject(now(), 'datetime', false) }} +@foreach ($users as $show_user) +
{{-- used for page breaks when printing --}}
+

+ {{ trans('general.assigned_to', ['name' => $show_user->present()->fullName()]) }} + {{ ($show_user->employee_num!='') ? ' (#'.$show_user->employee_num.') ' : '' }} + {{ ($show_user->jobtitle!='' ? ' - '.$show_user->jobtitle : '') }} +

+

{{ trans('admin/users/general.all_assigned_list_generation')}} {{ Helper::getFormattedDateObject(now(), 'datetime', false) }} - - - @if ($assets->count() > 0) + @if ($show_user->assets->count() > 0) @php $counter = 1; @endphp
-

{{ trans_choice('general.countable.assets', $assets->count(), ['count' => $assets->count()]) }} +

{{ trans_choice('general.countable.assets', $show_user->assets->count(), ['count' => $show_user->assets->count()]) }}

+ class="snipe-table table table-striped inventory" + id="AssetsAssigned" + data-pagination="false" + data-id-table="AssetsAssigned" + data-search="false" + data-side-pagination="client" + data-sortable="true" + data-toolbar="#assets-toolbar" + data-show-columns="true" + data-sort-order="desc" + data-sort-name="created_at" + data-show-columns-toggle-all="true" + data-cookie-id-table="AssetsAssigned"> @@ -119,7 +137,7 @@ - @foreach ($assets as $asset) + @foreach ($show_user->assets as $asset) @php if ($asset->model->category->getEula()) $eulas[] = $asset->model->category->getEula() @endphp @@ -185,25 +203,25 @@
# {{ trans('general.image') }}{{ trans('general.signature') }}
@endif - @if ($licenses->count() > 0) + @if ($show_user->licenses->count() > 0)
-

{{ trans_choice('general.countable.licenses', $licenses->count(), ['count' => $licenses->count()]) }}

+

{{ trans_choice('general.countable.licenses', $show_user->licenses->count(), ['count' => $show_user->licenses->count()]) }}

+ class="snipe-table table table-striped inventory" + id="licensessAssigned" + data-toolbar="#licenses-toolbar" + data-pagination="false" + data-id-table="licensessAssigned" + data-search="false" + data-side-pagination="client" + data-sortable="true" + data-show-columns="true" + data-sort-order="desc" + data-sort-name="created_at" + data-show-columns-toggle-all="true" + data-cookie-id-table="licensessAssigned"> @@ -216,7 +234,7 @@ $lcounter = 1; @endphp - @foreach ($licenses as $license) + @foreach ($show_user->licenses as $license) @php if ($license->category->getEula()) $eulas[] = $license->category->getEula() @endphp @@ -240,25 +258,25 @@ @endif - @if ($accessories->count() > 0) + @if ($show_user->accessories->count() > 0)
-

{{ trans_choice('general.countable.accessories', $accessories->count(), ['count' => $accessories->count()]) }}

+

{{ trans_choice('general.countable.accessories', $show_user->accessories->count(), ['count' => $show_user->accessories->count()]) }}

#
+ class="snipe-table table table-striped inventory" + id="accessoriesAssigned" + data-toolbar="#accessories-toolbar" + data-pagination="false" + data-id-table="accessoriesAssigned" + data-search="false" + data-side-pagination="client" + data-sortable="true" + data-show-columns="true" + data-sort-order="desc" + data-sort-name="created_at" + data-show-columns-toggle-all="true" + data-cookie-id-table="accessoriesAssigned"> @@ -273,7 +291,7 @@ $acounter = 1; @endphp - @foreach ($accessories as $accessory) + @foreach ($show_user->accessories as $accessory) @if ($accessory) @php if ($accessory->category->getEula()) $eulas[] = $accessory->category->getEula() @@ -291,7 +309,7 @@ @@ -303,25 +321,25 @@
# @if (($accessory->assetlog->first()) && ($accessory->assetlog->first()->accept_signature!='')) - + @endif
@endif - @if ($consumables->count() > 0) + @if ($show_user->consumables->count() > 0)
-

{{ trans_choice('general.countable.consumables', $consumables->count(), ['count' => $consumables->count()]) }}

+

{{ trans_choice('general.countable.consumables', $show_user->consumables->count(), ['count' => $show_user->consumables->count()]) }}

+ class="snipe-table table table-striped inventory" + id="consumablesAssigned" + data-pagination="false" + data-toolbar="#consumables-toolbar" + data-id-table="consumablesAssigned" + data-search="false" + data-side-pagination="client" + data-sortable="true" + data-show-columns="true" + data-sort-order="desc" + data-sort-name="created_at" + data-show-columns-toggle-all="true" + data-cookie-id-table="consumablesAssigned"> @@ -336,7 +354,7 @@ $ccounter = 1; @endphp - @foreach ($consumables as $consumable) + @foreach ($show_user->consumables as $consumable) @if ($consumable) @php if ($consumable->category->getEula()) $eulas[] = $consumable->category->getEula() @@ -347,7 +365,7 @@ @if ($consumable->deleted_at!='') @else - {{ ($consumable->manufacturer) ? $consumable->manufacturer->name : '' }} {{ $consumable->name }} {{ $consumable->model_number }} + {{ ($consumable->manufacturer) ? $consumable->manufacturer->name : '' }} {{ $consumable->name }} {{ $consumable->model_number }} @endif @@ -366,15 +384,18 @@
{{ ($consumable->manufacturer) ? $consumable->manufacturer->name : '' }} {{ $consumable->name }} {{ $consumable->model_number }} {{ ($consumable->category) ? $consumable->category->name : ' invalid/deleted category' }}
@endif -

-
- -
+ {{-- This may have been render at the top of the page if we're rendering more than one user... --}} + @if (count($users) === 1) +

+
+ +
+ @endif - - +
+ - + @@ -414,6 +435,7 @@
EULA @php @@ -386,7 +407,7 @@ @endforeach @endif
{{ trans('general.signed_off_by') }}: ______________________________________
+@endforeach {{-- Javascript files --}} diff --git a/routes/web/users.php b/routes/web/users.php index e55541a937..e6aaf644ae 100644 --- a/routes/web/users.php +++ b/routes/web/users.php @@ -153,4 +153,4 @@ Route::resource('users', Users\UsersController::class, [ 'middleware' => ['auth'], 'parameters' => ['user' => 'user_id'], 'except' => ['update'] -]); \ No newline at end of file +]);