netgescon-day0/resources/views/filament/print/etichetta-archivio-fisico.blade.php

477 lines
19 KiB
PHP

<!doctype html>
<html lang="it">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Etichetta Archivio Fisico</title>
@php
$fmt = in_array(($format ?? '11354'), ['11354','99014'], true) ? $format : '11354';
$dymoFix = isset($dymoFix) ? (bool) $dymoFix : false;
$dymoRot = isset($dymoRot) ? (int) $dymoRot : 0;
$dymoDx = isset($dymoDx) ? (float) $dymoDx : 0.0;
$dymoDy = isset($dymoDy) ? (float) $dymoDy : 0.0;
$autoPrint = request()->has('autoprint') && filter_var(request()->query('autoprint'), FILTER_VALIDATE_BOOL);
$labelPrinterMode = isset($labelPrinterMode) ? (bool) $labelPrinterMode : false;
$pageWidth = $fmt === '99014' ? '54mm' : '57mm';
$pageHeight = $fmt === '99014' ? '101mm' : '32mm';
$template = is_array(data_get($item->metadati, 'generic_label_template')) ? data_get($item->metadati, 'generic_label_template') : [];
$templateName = (string) ($template['template_name'] ?? 'classic-right');
$qrPosition = (string) ($template['qr_position'] ?? ($fmt === '99014' ? 'bottom-right' : 'right-center'));
$qrScale = (string) ($template['qr_scale'] ?? ($fmt === '99014' ? 'lg' : 'md'));
$isArchive99014 = $fmt === '99014' && $templateName === 'archive-99014';
$payload = [
'mnemonic_code' => (string) ($template['mnemonic_code'] ?? ''),
'titolo' => (string) $item->titolo,
'linea_secondaria' => (string) data_get($item->metadati, 'linea_secondaria', ''),
'tipo_label' => (string) $item->tipo_label,
'supporto_fisico' => (string) ($item->supporto_fisico ?? ''),
'percorso_compatto' => (string) ($item->percorso_fisico ?? ''),
'ubicazione' => trim(implode(' · ', array_filter([$item->magazzino, $item->scaffale, $item->ripiano, $item->ubicazione_dettaglio]))),
'note' => (string) ($item->note ?? ''),
'stabile' => (string) ($item->stabile->denominazione ?? ''),
'stabile_code' => (string) ($item->stabile->codice_stabile ?? ''),
'stabile_address' => (string) ($item->stabile->indirizzo_completo ?? ''),
'stabile_summary' => trim(implode(' · ', array_filter([
(string) ($item->stabile->denominazione ?? ''),
(string) ($item->stabile->codice_stabile ?? ''),
(string) ($item->stabile->indirizzo_completo ?? ''),
]))),
'codice_univoco' => (string) $item->codice_univoco,
'amazon_url' => (string) data_get($item->metadati, 'amazon_url', ''),
];
$slotValue = static function (string $key, array $payload): string {
if ($key === 'none') {
return '';
}
return trim((string) ($payload[$key] ?? ''));
};
$titleText = $slotValue((string) ($template['title_source'] ?? 'titolo'), $payload);
$subtitleText = $slotValue((string) ($template['subtitle_source'] ?? 'linea_secondaria'), $payload);
$metaText = $slotValue((string) ($template['meta_source'] ?? 'percorso_compatto'), $payload);
$noteText = $slotValue((string) ($template['note_source'] ?? 'note'), $payload);
$templateCode = trim((string) ($template['mnemonic_code'] ?? ''));
$stableLineValue = static function (string $key, array $payload): string {
if ($key === 'none') {
return '';
}
if ($key === 'blank_line') {
return '__BLANK_LINE__';
}
return trim((string) ($payload[$key] ?? ''));
};
$templateLineRows = is_array($template['line_rows'] ?? null) && count($template['line_rows']) > 0
? $template['line_rows']
: [
[
'mode' => 'source',
'source' => (string) ($template['stable_line_one_source'] ?? 'stabile_summary'),
'text' => '',
],
[
'mode' => ((string) ($template['stable_line_two_source'] ?? 'blank_line')) === 'blank_line' ? 'blank_line' : 'source',
'source' => (string) ($template['stable_line_two_source'] ?? 'blank_line'),
'text' => '',
],
[
'mode' => ((int) ($template['blank_lines_count'] ?? 0)) >= 1 ? 'blank_line' : 'none',
'source' => 'none',
'text' => '',
],
[
'mode' => ((int) ($template['blank_lines_count'] ?? 0)) >= 2 ? 'blank_line' : 'none',
'source' => 'none',
'text' => '',
],
];
$stableLines = [];
foreach ($templateLineRows as $lineRow) {
if (! is_array($lineRow)) {
continue;
}
$mode = (string) ($lineRow['mode'] ?? 'none');
if ($mode === 'blank_line') {
$stableLines[] = '__BLANK_LINE__';
continue;
}
if ($mode === 'text') {
$stableLines[] = trim((string) ($lineRow['text'] ?? ''));
continue;
}
if ($mode === 'source') {
$stableLines[] = $stableLineValue((string) ($lineRow['source'] ?? 'none'), $payload);
}
}
$blankLinesCount = max(0, min(4, (int) ($template['blank_lines_count'] ?? 2)));
@endphp
<style>
@page {
margin: {{ $labelPrinterMode ? '0' : '10mm' }};
size: {{ $labelPrinterMode ? ($fmt === '99014' ? '54mm 101mm' : '57mm 32mm') : 'A4 portrait' }};
}
html, body {
margin: 0;
padding: 0;
width: 100%;
min-height: 100%;
font-family: Arial, Helvetica, sans-serif;
overflow: visible;
background: {{ $labelPrinterMode ? 'white' : '#eef1f5' }};
}
.sheet {
box-sizing: border-box;
width: {{ $labelPrinterMode ? $pageWidth : '210mm' }};
min-height: {{ $labelPrinterMode ? $pageHeight : '297mm' }};
padding: {{ $labelPrinterMode ? '0' : '12mm' }};
display: flex;
align-items: {{ $labelPrinterMode ? 'stretch' : 'flex-start' }};
justify-content: {{ $labelPrinterMode ? 'stretch' : 'flex-start' }};
margin: 0 auto;
background: white;
overflow: hidden;
-webkit-print-color-adjust: exact;
print-color-adjust: exact;
break-inside: avoid;
break-after: avoid-page;
page-break-inside: avoid;
page-break-after: avoid;
}
.label {
box-sizing: border-box;
width: {{ $pageWidth }};
height: {{ $pageHeight }};
padding: 0;
flex: 0 0 auto;
position: relative;
}
.calib {
position: absolute;
inset: 0;
transform-origin: 0 0;
}
.label-content {
box-sizing: border-box;
width: 100%;
height: 100%;
padding: {{ $fmt === '99014' ? '3.5mm' : '2mm' }};
}
.panel {
width: 100%;
height: 100%;
border: 0.35mm solid #111;
box-sizing: border-box;
display: grid;
grid-template-columns: {{ $fmt === '99014' ? '1fr 18mm' : '1fr 10.8mm' }};
gap: 2mm;
padding: {{ $fmt === '99014' ? '2.4mm' : '1.5mm' }};
align-items: stretch;
}
.panel.panel-99014 {
display: block;
position: relative;
padding: 2.8mm;
}
.content { min-width: 0; }
.panel.panel-99014 .content {
padding-right: 0;
padding-bottom: 21mm;
}
.code { font-weight: 800; font-size: {{ $fmt === '99014' ? '14px' : '10px' }}; letter-spacing: 0.4px; }
.title { font-weight: 700; font-size: {{ $fmt === '99014' ? '13px' : '9px' }}; line-height: 1.15; margin-top: 1mm; }
.meta { font-size: {{ $fmt === '99014' ? '10px' : '7px' }}; line-height: 1.2; color: #222; margin-top: 1.1mm; }
.qr {
display: flex;
align-items: center;
justify-content: center;
overflow: hidden;
min-width: 0;
min-height: 0;
padding: 0.4mm;
box-sizing: border-box;
}
.qr.qr-sm { width: 11mm; height: 11mm; }
.qr.qr-md { width: 15mm; height: 15mm; }
.qr.qr-lg { width: 18mm; height: 18mm; }
.panel.panel-99014 .qr {
position: absolute;
right: 2.8mm;
bottom: 2.8mm;
width: 18mm;
height: 18mm;
padding: 0;
}
.qr svg,
.qr img {
display: block;
width: 100% !important;
max-width: 100%;
max-height: 100%;
height: auto !important;
}
.qr svg {
aspect-ratio: 1 / 1;
}
.path { font-size: {{ $fmt === '99014' ? '9px' : '6.6px' }}; line-height: 1.2; color: #444; margin-top: 1mm; word-break: break-word; }
.archive-99014 {
display: grid;
grid-template-columns: 1fr 18mm;
gap: 2.8mm;
padding: 2.8mm;
align-items: stretch;
}
.archive-99014 .content {
display: flex;
flex-direction: column;
min-width: 0;
}
.archive-99014-code {
border-bottom: 0.35mm solid #111;
padding-bottom: 1.2mm;
font-size: 15px;
line-height: 1.05;
font-weight: 900;
letter-spacing: 0.8px;
text-transform: uppercase;
}
.archive-99014-title {
margin-top: 2mm;
font-size: 13px;
line-height: 1.15;
font-weight: 700;
text-transform: uppercase;
}
.archive-99014-subtitle {
margin-top: 1.5mm;
font-size: 10px;
line-height: 1.25;
}
.archive-99014-stable {
margin-top: 2mm;
display: flex;
flex-direction: column;
gap: 1.4mm;
font-size: 9px;
line-height: 1.2;
}
.archive-99014-line {
min-height: 4.5mm;
}
.archive-99014-line.blank,
.archive-99014-blank {
border-bottom: 0.25mm solid #555;
}
.archive-99014-blanks {
margin-top: 2mm;
display: flex;
flex-direction: column;
gap: 1.5mm;
}
.archive-99014-blank {
min-height: 4.8mm;
}
.archive-99014-note {
margin-top: 2mm;
border: 0.25mm dashed #666;
padding: 1.4mm;
font-size: 8px;
line-height: 1.25;
}
.archive-99014-qr {
display: flex;
flex-direction: column;
justify-content: flex-end;
align-items: center;
gap: 1.2mm;
}
.archive-99014-qr-label {
font-size: 7px;
font-weight: 700;
letter-spacing: 0.6px;
text-transform: uppercase;
color: #666;
}
.qr-right-top .qr {
align-self: flex-start;
}
.qr-right-center .qr {
align-self: center;
}
.qr-bottom-right,
.qr-bottom-center {
grid-template-columns: 1fr;
}
.qr-bottom-right .content,
.qr-bottom-center .content {
padding-right: 0;
}
.qr-bottom-right .qr,
.qr-bottom-center .qr {
position: absolute;
bottom: {{ $fmt === '99014' ? '2.8mm' : '1.5mm' }};
}
.qr-bottom-right .qr {
right: {{ $fmt === '99014' ? '2.8mm' : '1.5mm' }};
}
.qr-bottom-center .qr {
left: 50%;
transform: translateX(-50%);
}
@media screen {
body {
padding: 12mm 0;
}
.sheet {
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.18);
}
}
@media print {
html, body {
width: 100%;
min-height: 100%;
background: white;
}
.sheet {
box-shadow: none;
margin: 0;
padding: {{ $labelPrinterMode ? '0' : '12mm' }};
min-height: auto;
}
@if($labelPrinterMode)
html, body {
overflow: hidden;
}
.sheet {
position: fixed;
left: 0;
top: 0;
}
.calib {
transform: translate({{ $dymoDx }}mm, {{ $dymoDy }}mm) rotate({{ $dymoRot }}deg);
}
@if($fmt === '11354' && $dymoFix)
@page { size: 32mm 57mm; }
html, body {
width: 32mm;
height: 57mm;
}
.sheet {
width: 32mm;
height: 57mm;
padding: 0;
}
.calib {
width: 57mm;
height: 32mm;
@if($dymoRot === 90)
transform: translate({{ $dymoDx }}mm, {{ $dymoDy }}mm) translateX(32mm) rotate(90deg);
@else
transform: translate({{ $dymoDx }}mm, {{ $dymoDy }}mm) translateY(57mm) rotate(-90deg);
@endif
}
@endif
@else
.calib { transform: none !important; }
@endif
}
</style>
@if($autoPrint)
<script>
window.addEventListener('load', () => setTimeout(() => { try { window.print(); } catch (e) {} }, 80));
window.onafterprint = () => { try { window.history.back(); } catch (e) {} };
</script>
@endif
</head>
<body>
<div class="sheet">
<div class="label">
<div class="calib">
<div class="label-content">
@if($isArchive99014)
<div class="panel panel-99014 archive-99014">
<div class="content">
<div class="archive-99014-code">{{ $templateCode !== '' ? $templateCode : $item->codice_univoco }}</div>
<div class="archive-99014-title">{{ $titleText !== '' ? $titleText : $item->titolo }}</div>
@if($subtitleText !== '')
<div class="archive-99014-subtitle">{{ $subtitleText }}</div>
@endif
<div class="archive-99014-stable">
@foreach($stableLines as $stableLine)
@if($stableLine === '__BLANK_LINE__')
<div class="archive-99014-line blank"></div>
@elseif($stableLine !== '')
<div class="archive-99014-line">{{ $stableLine }}</div>
@endif
@endforeach
</div>
@if($blankLinesCount > 0)
<div class="archive-99014-blanks">
@for($line = 0; $line < $blankLinesCount; $line++)
<div class="archive-99014-blank"></div>
@endfor
</div>
@endif
@if($noteText !== '')
<div class="archive-99014-note">{{ $noteText }}</div>
@endif
</div>
<div class="archive-99014-qr">
<div @class(['qr', 'qr-sm' => $qrScale === 'sm', 'qr-md' => $qrScale === 'md', 'qr-lg' => $qrScale === 'lg'])>
{!! $item->qr_code_image !!}
</div>
<div class="archive-99014-qr-label">QR</div>
</div>
</div>
@else
<div @class([
'panel',
'panel-99014' => $fmt === '99014',
'qr-right-top' => $qrPosition === 'right-top',
'qr-right-center' => $qrPosition === 'right-center',
'qr-bottom-right' => $qrPosition === 'bottom-right',
'qr-bottom-center' => $qrPosition === 'bottom-center',
])>
<div class="content">
<div class="code">{{ $templateCode !== '' ? $templateCode : $item->codice_univoco }}</div>
<div class="title">{{ $titleText !== '' ? $titleText : $item->titolo }}</div>
@if($subtitleText !== '')
<div class="meta">{{ $subtitleText }}</div>
@endif
@if($metaText !== '')
<div class="meta">{{ $metaText }}</div>
@endif
@if($stableLines !== [])
<div class="path">
@foreach($stableLines as $stableLine)
@if($stableLine === '__BLANK_LINE__')
<div style="height: 4.5mm; border-bottom: 0.25mm solid #999;"></div>
@elseif($stableLine !== '')
<div>{{ $stableLine }}</div>
@endif
@endforeach
</div>
@endif
@if($noteText !== '')
<div class="meta">{{ $noteText }}</div>
@endif
</div>
<div @class(['qr', 'qr-sm' => $qrScale === 'sm', 'qr-md' => $qrScale === 'md', 'qr-lg' => $qrScale === 'lg'])>
{!! $item->qr_code_image !!}
</div>
</div>
@endif
</div>
</div>
</div>
</div>
</body>
</html>