feat: add internal deep link URL and update bag label and customer receipt in ticket form

This commit is contained in:
brontomark committed 2026-12-04 19:30:24 +01:00
1 parent f6d5a4f0ce
commit 52c1cce878
3 files changed
+94 -55

No files matched your search

@@ -170,6 +170,11 @@ class TicketModel extends Equatable {
String get publicTrackingUrl =>
id != null && id!.isNotEmpty ? 'https://flux.catelli.it/ticket/$id' : '';
/// URL interno (per QR etichetta sacchetto) che apre direttamente la scheda ticket in FLUX
String get internalDeepLinkUrl => id != null && id!.isNotEmpty
? 'https://flux.catelli.it/tickets/form/$id'
: '';
/// Recapito effettivo da usare in base alla preferenza di contatto scelta
String get effectiveContactDestination {
if (contactPreference.isEmail) {
+32 -17
View File
@@ -310,24 +310,12 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
crossAxisSpacing: 16,
childAspectRatio: 1.5,
children: [
_ActionButton(
icon: Icons.print,
label: "Ricevuta A4",
onTap: () async {
final doc = await TicketPdfService()
.generateTicketReceipt(ticket);
final bytes = await doc.save();
final fileName = 'Ricevuta_${ticket.referenceId}.pdf';
await Printing.layoutPdf(
onLayout: (format) async => bytes,
name: fileName,
);
},
),
if (company.labelFormat != LabelFormat.none)
_ActionButton(
icon: Icons.label,
label: "Etichetta",
icon: Icons.qr_code_2_rounded,
label: "Etichetta Sacchetto",
color: Colors.teal.shade700,
textColor: Colors.white,
onTap: () async {
final doc = await TicketPdfService().generateLabelPdf(
ticket,
@@ -348,6 +336,29 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
}
},
),
_ActionButton(
icon: Icons.print,
label: "Ricevuta Cliente",
color: (notificationResult == null ||
!notificationResult.success)
? Colors.indigo.shade600
: null,
textColor: (notificationResult == null ||
!notificationResult.success)
? Colors.white
: null,
onTap: () async {
final doc = await TicketPdfService()
.generateCustomerReceiptPdf(ticket);
final bytes = await doc.save();
final fileName =
'Ricevuta_Cliente_${ticket.referenceId}.pdf';
await Printing.layoutPdf(
onLayout: (format) async => bytes,
name: fileName,
);
},
),
_ActionButton(
icon: Icons.link_rounded,
label: "Copia Link Stato",
@@ -374,7 +385,11 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
textColor: Colors.white,
onTap: () {
Navigator.of(sheetCtx).pop();
Navigator.of(context).pop();
if (context.canPop()) {
context.pop();
} else {
context.goNamed(Routes.tickets);
}
},
),
],
@@ -648,57 +648,76 @@ class TicketPdfService {
return pdf;
}
/// Genera l'etichetta adesiva verticale per il sacchetto del prodotto:
/// QR Code grande in alto (link alla scheda lavorazione), nome cliente e difetto sotto.
Future<pw.Document> generateLabelPdf(TicketModel ticket) async {
final pdf = pw.Document();
final font = await PdfGoogleFonts.robotoRegular();
final boldFont = await PdfGoogleFonts.robotoBold();
// Prendiamo le misure salvate (se custom) o usiamo default
final widthMm = company.labelWidth ?? 62.0;
final heightMm = company.labelHeight ?? 29.0;
final rawW = company.labelWidth ?? 38.0;
final rawH = company.labelHeight ?? 25.0;
// Creiamo il formato fisico esatto!
final format = company.isLabelVertical
? PdfPageFormat(heightMm * PdfPageFormat.mm, widthMm * PdfPageFormat.mm)
: PdfPageFormat(
widthMm * PdfPageFormat.mm,
heightMm * PdfPageFormat.mm,
);
// Orientamento sempre verticale: lato corto come larghezza, lato lungo come altezza (es. 25x38mm)
final shortSideMm = rawW < rawH ? rawW : rawH;
final longSideMm = rawW > rawH ? rawW : rawH;
final format = PdfPageFormat(
shortSideMm * PdfPageFormat.mm,
longSideMm * PdfPageFormat.mm,
);
const margin = 1.5 * PdfPageFormat.mm;
final contentWidth = format.width - (margin * 2);
// QR grande quasi quanto tutta la larghezza disponibile per lettura immediata su 25x38mm
final qrSize = (contentWidth - 1 * PdfPageFormat.mm).clamp(
14 * PdfPageFormat.mm,
24 * PdfPageFormat.mm,
);
final customerName = ticket.customer?.name ?? 'Cliente sconosciuto';
final defectLine = ticket.request.trim().isNotEmpty
? ticket.request.trim()
: (ticket.targetModelName ?? ticket.ticketType.displayValue);
final qrData = ticket.internalDeepLinkUrl.isNotEmpty
? ticket.internalDeepLinkUrl
: (ticket.id ?? '');
pdf.addPage(
pw.Page(
pageFormat: format,
margin: const pw.EdgeInsets.all(2), // Margini minimi per le etichette
margin: const pw.EdgeInsets.all(margin),
build: (context) {
return pw.Row(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
return pw.Column(
mainAxisAlignment: pw.MainAxisAlignment.start,
crossAxisAlignment: pw.CrossAxisAlignment.center,
children: [
pw.Expanded(
child: pw.Column(
crossAxisAlignment: pw.CrossAxisAlignment.start,
mainAxisAlignment: pw.MainAxisAlignment.center,
children: [
pw.Text(
ticket.referenceId ?? '',
style: pw.TextStyle(font: boldFont, fontSize: 10),
),
pw.Text(
ticket.customer?.name ?? 'Cliente sconosciuto',
style: pw.TextStyle(font: font, fontSize: 9),
),
pw.Text(
ticket.createdAt?.toString().substring(0, 10) ?? '',
style: const pw.TextStyle(fontSize: 7),
),
],
),
),
// QR Code compatto
pw.BarcodeWidget(
barcode: pw.Barcode.qrCode(),
data: ticket.id!,
width: 20,
height: 20,
barcode: pw.Barcode.qrCode(
errorCorrectLevel: pw.BarcodeQRCorrectionLevel.low,
),
data: qrData,
width: qrSize,
height: qrSize,
),
pw.SizedBox(height: 1.5 * PdfPageFormat.mm),
pw.Text(
customerName,
style: pw.TextStyle(font: boldFont, fontSize: 9.5),
textAlign: pw.TextAlign.center,
maxLines: 2,
overflow: pw.TextOverflow.clip,
),
pw.SizedBox(height: 0.8 * PdfPageFormat.mm),
pw.Expanded(
child: pw.Text(
defectLine,
style: pw.TextStyle(font: font, fontSize: 7.2),
textAlign: pw.TextAlign.center,
maxLines: 2,
overflow: pw.TextOverflow.clip,
),
),
],
);