Add print label functionality and enhance asset management actions
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user