From ca567eec8afc464085deaef330ab4d93a6684532 Mon Sep 17 00:00:00 2001 From: snipe Date: Wed, 17 Sep 2025 21:08:13 +0100 Subject: [PATCH] Small adjustments for layout --- .../Account/AcceptanceController.php | 77 +++++++++++-------- app/Models/LicenseSeat.php | 16 ++++ .../AcceptanceAssetAcceptedNotification.php | 14 ++-- ...eptanceAssetAcceptedToUserNotification.php | 11 ++- .../markdown/asset-acceptance.blade.php | 3 + 5 files changed, 81 insertions(+), 40 deletions(-) diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.php index de973f284d..8cf970e675 100644 --- a/app/Http/Controllers/Account/AcceptanceController.php +++ b/app/Http/Controllers/Account/AcceptanceController.php @@ -83,7 +83,7 @@ class AcceptanceController extends Controller public function store(Request $request, $id) : RedirectResponse { $acceptance = CheckoutAcceptance::find($id); - + $settings = Setting::getSettings(); if (is_null($acceptance)) { return redirect()->route('account.accept')->with('error', trans('admin/hardware/message.does_not_exist')); } @@ -146,35 +146,31 @@ class AcceptanceController extends Controller $assigned_user = User::find($acceptance->assigned_to_id); - /** - * Gather the data for the PDF. We fire this whether there is a signature required or not, - * since we want the moment-in-time proof of what the EULA was when they accepted it. - */ - $branding_settings = SettingsController::getPDFBranding(); - $path_logo = ""; // Check for the PDF logo path and use that, otherwise use the regular logo path - if (!is_null($branding_settings->acceptance_pdf_logo)) { - $path_logo = public_path() . '/uploads/' . $branding_settings->acceptance_pdf_logo; - } elseif (!is_null($branding_settings->logo)) { - $path_logo = public_path() . '/uploads/' . $branding_settings->logo; + if (!is_null($settings->acceptance_pdf_logo)) { + $path_logo = public_path() . '/uploads/' . $settings->acceptance_pdf_logo; + } elseif (!is_null($settings->logo)) { + $path_logo = public_path() . '/uploads/' . $settings->logo; } $data = [ 'item_tag' => $item->asset_tag, - 'item_model' => $item->model ? $item->model->name : $item->display_name, + 'item_name' => $item->name, // this handles licenses seats, which don't have a 'name' field + 'item_model' => $item->model?->name, 'item_serial' => $item->serial, 'item_status' => $item->assetstatus?->name, 'eula' => $item->getEula(), 'note' => $request->input('note'), - 'check_out_date' => Carbon::parse($acceptance->created_at)->format('Y-m-d H:i:s'), - 'accepted_date' => Carbon::parse($acceptance->accepted_at)->format('Y-m-d H:i:s'), + 'check_out_date' => Helper::getFormattedDateObject($acceptance->created_at, 'datetime', false), + 'accepted_date' => Helper::getFormattedDateObject(now()->format('Y-m-d H:i:s'), 'datetime', false), 'assigned_to' => $assigned_user->display_name, - 'company_name' => $branding_settings->site_name, + 'site_name' => $settings->site_name, + 'company_name' => $item->company?->name?? $settings->site_name, 'signature' => ($sig_filename) ? storage_path() . '/private_uploads/signatures/' . $sig_filename : null, 'logo' => $path_logo, - 'date_settings' => $branding_settings->date_display_format, + 'date_settings' => $settings->date_display_format, 'admin' => auth()->user()->present()?->fullName, 'qty' => $acceptance->qty ?? 1, ]; @@ -192,26 +188,40 @@ class AcceptanceController extends Controller $pdf->SetAuthor($data['assigned_to']); $pdf->SetTitle('Asset Acceptance: '.$data['item_tag']); $pdf->SetSubject('Asset Acceptance: '.$data['item_tag']); - $pdf->SetKeywords('Snipe-IT, assets, acceptance, eula', 'tos'); + $pdf->SetKeywords('Snipe-IT, assets, acceptance, eula, tos'); $pdf->SetFont('dejavusans', '', 8, '', true); $pdf->SetPrintHeader(false); $pdf->SetPrintFooter(false); - $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN)); - $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA)); $pdf->AddPage(); - $pdf->writeHTML('', true, 0, true, 0, ''); + if ($data['logo']) { + $pdf->writeHTML('', true, 0, true, 0, ''); + } - if ($data['item_tag']) { - $pdf->writeHTML("" . trans('general.asset_tag') . ': ' . $data['item_tag'], true, 0, true, 0, ''); + if ($data['site_name']) { + $pdf->writeHTML($data['site_name'], true, 0, true, 0, 'C'); } - $pdf->writeHTML("".trans('general.asset_model').': '.$data['item_model'], true, 0, true, 0, ''); - if ($data['item_serial']) { - $pdf->writeHTML("".trans('admin/hardware/form.serial').': '.$data['item_serial'], true, 0, true, 0, ''); - } - $pdf->writeHTML("".trans('general.assigned_date').': '.$data['check_out_date'], true, 0, true, 0, ''); - $pdf->writeHTML("".trans('general.assignee').': '.$data['assigned_to'], true, 0, true, 0, ''); $pdf->Ln(); + $pdf->writeHTML(trans('general.date') . ': ' . Helper::getFormattedDateObject(now(), 'datetime', false), true, 0, true, 0, ''); + + if ($data['company_name'] != null) { + $pdf->writeHTML(trans('general.company') . ': ' . e($data['company_name']), true, 0, true, 0, ''); + } + if ($data['item_tag'] != null) { + $pdf->writeHTML(trans('general.asset_tag') . ': ' . e($data['item_tag']), true, 0, true, 0, ''); + } + if ($data['item_name'] != null) { + $pdf->writeHTML(trans('general.name') . ': ' . e($data['item_name']), true, 0, true, 0, ''); + } + if ($data['item_model'] != null) { + $pdf->writeHTML(trans('general.asset_model') . ': ' . e($data['item_model']), true, 0, true, 0, ''); + } + if ($data['item_serial'] != null) { + $pdf->writeHTML(trans('admin/hardware/form.serial').': '.e($data['item_serial']), true, 0, true, 0, ''); + } + $pdf->Ln(); + $pdf->writeHTML('
', true, 0, true, 0, ''); + // Break the EULA into lines based on newlines, and check each line for RTL or CJK characters $eula_lines = preg_split("/\r\n|\n|\r/", $item->getEula()); @@ -229,25 +239,28 @@ class AcceptanceController extends Controller if ($data['note'] != null) { Helper::isCjk($data['note']) ? $pdf->SetFont('cid0cs', '', 9) : $pdf->SetFont('dejavusans', '', 8, '', true); - $pdf->writeHTML("".trans('general.notes') . ': ' . $data['note'], true, 0, true, 0, ''); + $pdf->writeHTML(trans('general.notes') . ': ' . e($data['note']), true, 0, true, 0, ''); $pdf->Ln(); } if ($data['signature'] != null) { - $pdf->writeHTML('', true, 0, true, 0, ''); $pdf->writeHTML('
', true, 0, true, 0, ''); } - $pdf->writeHTML("".trans('general.accepted_date').': '.$data['accepted_date'], true, 0, true, 0, ''); + $pdf->writeHTML(trans('general.assignee').': '.e($data['assigned_to']), true, 0, true, 0, ''); + $pdf->writeHTML(trans('general.assigned_date').': '.e($data['check_out_date']), true, 0, true, 0, ''); + $pdf->writeHTML(trans('general.accepted_date').': '.e($data['accepted_date']), true, 0, true, 0, ''); + // close line height div + $pdf->writeHTML('', true, 0, true, 0, ''); $pdf_content = $pdf->Output($pdf_filename, 'S'); Storage::put('private_uploads/eula-pdfs/' .$pdf_filename, $pdf_content); - $acceptance->accept($sig_filename, $item->getEula(), $pdf_filename, $request->input('note')); + $acceptance->accept($sig_filename, $item->getEula(), $pdf_filename, $request->input('note')); // Send the PDF to the signing user if (($request->input('send_copy') == '1') && ($assigned_user->email !='')) { diff --git a/app/Models/LicenseSeat.php b/app/Models/LicenseSeat.php index 9ddd3fb431..39cb53f9d8 100755 --- a/app/Models/LicenseSeat.php +++ b/app/Models/LicenseSeat.php @@ -7,6 +7,7 @@ use App\Models\Traits\CompanyableChildTrait; use App\Notifications\CheckinLicenseNotification; use App\Notifications\CheckoutLicenseNotification; use App\Presenters\Presentable; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\SoftDeletes; @@ -64,6 +65,21 @@ class LicenseSeat extends SnipeModel implements ICompanyableChild return $this->license->getEula(); } + protected function name(): Attribute + { + return Attribute:: make( + get: fn(mixed $value) => $this->license->name, + ); + } + + protected function displayName(): Attribute + { + return Attribute:: make( + get: fn(mixed $value) => $this->license->name, + ); + } + + /** * Establishes the seat -> license relationship * diff --git a/app/Notifications/AcceptanceAssetAcceptedNotification.php b/app/Notifications/AcceptanceAssetAcceptedNotification.php index df7d745de4..6e33a8a823 100644 --- a/app/Notifications/AcceptanceAssetAcceptedNotification.php +++ b/app/Notifications/AcceptanceAssetAcceptedNotification.php @@ -2,6 +2,7 @@ namespace App\Notifications; +use AllowDynamicProperties; use App\Helpers\Helper; use App\Models\Setting; use Illuminate\Bus\Queueable; @@ -10,7 +11,7 @@ use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Messages\SlackMessage; use Illuminate\Notifications\Notification; -class AcceptanceAssetAcceptedNotification extends Notification +#[AllowDynamicProperties] class AcceptanceAssetAcceptedNotification extends Notification { use Queueable; @@ -22,16 +23,18 @@ class AcceptanceAssetAcceptedNotification extends Notification public function __construct($params) { $this->item_tag = $params['item_tag']; + $this->item_name = $params['item_name']; $this->item_model = $params['item_model']; $this->item_serial = $params['item_serial']; $this->item_status = $params['item_status']; - $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false); + $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'datetime', false); $this->assigned_to = $params['assigned_to']; - $this->note = $params['note']; $this->company_name = $params['company_name']; - $this->admin = $params['admin'] ?? null; $this->settings = Setting::getSettings(); + $this->file = $params['file'] ?? null; $this->qty = $params['qty'] ?? null; + $this->note = $params['note'] ?? null; + $this->admin = $params['admin'] ?? null; } @@ -66,6 +69,7 @@ class AcceptanceAssetAcceptedNotification extends Notification $message = (new MailMessage)->markdown('notifications.markdown.asset-acceptance', [ 'item_tag' => $this->item_tag, + 'item_name' => $this->item_name, 'item_model' => $this->item_model, 'item_serial' => $this->item_serial, 'item_status' => $this->item_status, @@ -73,9 +77,9 @@ class AcceptanceAssetAcceptedNotification extends Notification 'accepted_date' => $this->accepted_date, 'assigned_to' => $this->assigned_to, 'company_name' => $this->company_name, + 'admin' => $this->admin, 'qty' => $this->qty, 'intro_text' => trans('mail.acceptance_asset_accepted'), - 'admin' => $this->admin, ]) ->subject(trans('mail.acceptance_asset_accepted')); diff --git a/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php index 57e7b3fad4..246eb3777b 100644 --- a/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php +++ b/app/Notifications/AcceptanceAssetAcceptedToUserNotification.php @@ -2,13 +2,14 @@ namespace App\Notifications; +use AllowDynamicProperties; use App\Helpers\Helper; use App\Models\Setting; use Illuminate\Bus\Queueable; use Illuminate\Notifications\Messages\MailMessage; use Illuminate\Notifications\Notification; -class AcceptanceAssetAcceptedToUserNotification extends Notification +#[AllowDynamicProperties] class AcceptanceAssetAcceptedToUserNotification extends Notification { use Queueable; @@ -20,16 +21,18 @@ class AcceptanceAssetAcceptedToUserNotification extends Notification public function __construct($params) { $this->item_tag = $params['item_tag']; + $this->item_name = $params['item_name']; $this->item_model = $params['item_model']; $this->item_serial = $params['item_serial']; $this->item_status = $params['item_status']; - $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'date', false); + $this->accepted_date = Helper::getFormattedDateObject($params['accepted_date'], 'datetime', false); $this->assigned_to = $params['assigned_to']; - $this->note = $params['note']; + $this->note = $params['note'] ?? null; $this->company_name = $params['company_name']; $this->settings = Setting::getSettings(); $this->file = $params['file'] ?? null; $this->qty = $params['qty'] ?? null; + $this->admin = $params['admin'] ?? null; } /** @@ -59,6 +62,7 @@ class AcceptanceAssetAcceptedToUserNotification extends Notification $message = (new MailMessage)->markdown('notifications.markdown.asset-acceptance', [ 'item_tag' => $this->item_tag, + 'item_name' => $this->item_name, 'item_model' => $this->item_model, 'item_serial' => $this->item_serial, 'item_status' => $this->item_status, @@ -66,6 +70,7 @@ class AcceptanceAssetAcceptedToUserNotification extends Notification 'accepted_date' => $this->accepted_date, 'assigned_to' => $this->assigned_to, 'company_name' => $this->company_name, + 'admin' => $this->admin, 'qty' => $this->qty, 'intro_text' => trans('mail.acceptance_asset_accepted_to_user', ['site_name' => $this->company_name ?? $this->settings->site_name]), ]) diff --git a/resources/views/notifications/markdown/asset-acceptance.blade.php b/resources/views/notifications/markdown/asset-acceptance.blade.php index db2705e52a..52c13500d0 100644 --- a/resources/views/notifications/markdown/asset-acceptance.blade.php +++ b/resources/views/notifications/markdown/asset-acceptance.blade.php @@ -6,6 +6,9 @@ @component('mail::table') | | | | ------------- | ------------- | +@if (isset($item_name)) +| **{{ trans('general.name') }}** | {{ $item_name }} | +@endif | **{{ trans('mail.user') }}** | {{ $assigned_to }} | @if (isset($user->location)) | **{{ trans('general.location') }}** | {{ $user->location->name }} |