From b408f7fcf2dceb2e6777c40f337a6d910e862f83 Mon Sep 17 00:00:00 2001 From: Luca Haid Date: Tue, 18 Nov 2025 06:33:55 +0100 Subject: [PATCH] Add print label functionality and enhance asset management actions --- Layout/default/AssetManagement/LABEL.php | 52 +++++++++++++++++ .../AssetManagementController.php | 39 ++++++++++++- .../pages/AssetManagement/AssetManagement.js | 57 +++++++++++++++---- .../vue/tt-components/tt-datepicker.js | 7 ++- 4 files changed, 140 insertions(+), 15 deletions(-) create mode 100644 Layout/default/AssetManagement/LABEL.php diff --git a/Layout/default/AssetManagement/LABEL.php b/Layout/default/AssetManagement/LABEL.php new file mode 100644 index 000000000..2397b5257 --- /dev/null +++ b/Layout/default/AssetManagement/LABEL.php @@ -0,0 +1,52 @@ + + +
+ +
+
+ +
+
+ +
+
diff --git a/application/AssetManagement/AssetManagementController.php b/application/AssetManagement/AssetManagementController.php index 0a0ace068..9db10b068 100644 --- a/application/AssetManagement/AssetManagementController.php +++ b/application/AssetManagement/AssetManagementController.php @@ -11,7 +11,6 @@ class AssetManagementController extends TTCrud ['key' => 'currentUser', 'text' => 'Status', 'modal' => false, 'table' => ['sortable' => false, 'filter' => false]], ['key' => 'location', 'text' => 'Lagerort', 'required' => true, 'modal' => ['type' => 'text'], 'table' => ['filter' => 'search']], ['key' => 'serviceDueDate', 'text' => 'Service fällig', 'required' => false, 'modal' => ['type' => 'date'], 'table' => ['filter' => 'date']], - ['key' => 'journal', 'text' => 'Historie', 'modal' => false, 'table' => ['sortable' => false, 'filter' => false]], ['key' => 'actions', 'text' => 'Aktionen', 'modal' => false, 'table' => ['filter' => false, 'sortable' => false]], ]; @@ -21,7 +20,7 @@ class AssetManagementController extends TTCrud // Restrict actions if the user does not have the 'AssetAdmin' permission. if (!$this->user->can('AssetAdmin')) { $this->additionalJSVariables['ASSET_ADMIN'] = '0'; - $this->columns = array_filter($this->columns, fn($col) => !in_array($col['key'], ['actions', 'journal'])); + $this->columns = array_filter($this->columns, fn($col) => $col['key'] !== 'actions'); } } @@ -277,4 +276,40 @@ class AssetManagementController extends TTCrud AssetManagementReservationModel::delete($post['id']); self::returnJson(['success' => true, 'message' => 'Reservierung gelöscht.']); } + + protected function printLabelAction() { + if (!$this->user->can('AssetAdmin')) { + self::sendError("Permission denied", 403); + } + + $assetId = $this->request->id; + $size = $this->request->size ?? '25'; // Default to 25mm + + $asset = AssetManagementModel::get($assetId); + if (!$asset) { + self::sendError("Asset not found", 404); + } + + $pdf_vars = [ + 'companyAddress' => 'Fladnitz 150, 8322 Studenzen', + 'companyPhone' => '+43 3115 40800', + 'invNumber' => $asset->assetNumber, + 'size' => $size + ]; + + $pdf = new PdfForm("AssetManagement/LABEL", $pdf_vars); + + if ($size == '50') { + $wkhtmltopdfArgs = "--page-height 50mm --page-width 80mm --margin-top 1mm --margin-bottom 0 --margin-left 0 --margin-right 0 --disable-smart-shrinking --encoding utf-8"; + } else { // 25mm + $wkhtmltopdfArgs = "--page-height 25mm --page-width 50mm --margin-top 1mm --margin-bottom 0 --margin-left 0 --margin-right 0 --disable-smart-shrinking --encoding utf-8"; + } + + $filename = $pdf->render($wkhtmltopdfArgs); + + header('Content-Type: application/pdf'); + header('Content-Disposition: inline; filename="label-' . $asset->assetNumber . '.pdf"'); + readfile($filename); + die(); + } } \ No newline at end of file diff --git a/public/js/pages/AssetManagement/AssetManagement.js b/public/js/pages/AssetManagement/AssetManagement.js index 0049a9a54..a26bd81d1 100644 --- a/public/js/pages/AssetManagement/AssetManagement.js +++ b/public/js/pages/AssetManagement/AssetManagement.js @@ -1,10 +1,22 @@ window.TT_CONFIG["CRUD_CONFIG"]["additionalActions"] = [ + { + "key": "openHistory", + "title": "Historie", + "class": "fas fa-history text-info", + "condition": (row) => window.TT_CONFIG.ASSET_ADMIN === '1', + }, { "key": "reserve", "title": "Reservieren", - "class": "fas fa-calendar-alt btn-outline-warning", + "class": "fas fa-calendar-alt text-warning", "condition": (row) => window.TT_CONFIG.ASSET_ADMIN === '1', }, + { + "key": "print", + "title": "Label drucken", + "class": "fas fa-print text-secondary", + "condition": (row) => window.TT_CONFIG.ASSET_ADMIN === '1', + } ]; // ================================================================================= // Main Asset Management Component @@ -24,6 +36,10 @@ Vue.component('asset-management', { v-if="reservationModalAsset" :asset="reservationModalAsset" @close="reservationModalAsset = null; $refs.table.$refs.table.refreshTable()"/> + @@ -31,7 +47,9 @@ Vue.component('asset-management', { ref="table" emit-edit @edit="modalId = $event.id" + @openHistory="journalModalAssetId = $event.id" @reserve="reservationModalAsset = $event" + @print="printModalAsset = $event" :crud-config="crudConfig"> - -