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
+93 -54

No files matched your search

@@ -170,6 +170,11 @@ class TicketModel extends Equatable {
String get publicTrackingUrl => String get publicTrackingUrl =>
id != null && id!.isNotEmpty ? 'https://flux.catelli.it/ticket/$id' : ''; 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 /// Recapito effettivo da usare in base alla preferenza di contatto scelta
String get effectiveContactDestination { String get effectiveContactDestination {
if (contactPreference.isEmail) { if (contactPreference.isEmail) {
+32 -17
View File
@@ -310,24 +310,12 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
crossAxisSpacing: 16, crossAxisSpacing: 16,
childAspectRatio: 1.5, childAspectRatio: 1.5,
children: [ 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) if (company.labelFormat != LabelFormat.none)
_ActionButton( _ActionButton(
icon: Icons.label, icon: Icons.qr_code_2_rounded,
label: "Etichetta", label: "Etichetta Sacchetto",
color: Colors.teal.shade700,
textColor: Colors.white,
onTap: () async { onTap: () async {
final doc = await TicketPdfService().generateLabelPdf( final doc = await TicketPdfService().generateLabelPdf(
ticket, 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( _ActionButton(
icon: Icons.link_rounded, icon: Icons.link_rounded,
label: "Copia Link Stato", label: "Copia Link Stato",
@@ -374,7 +385,11 @@ class _TicketFormScreenState extends State<TicketFormScreen> {
textColor: Colors.white, textColor: Colors.white,
onTap: () { onTap: () {
Navigator.of(sheetCtx).pop(); 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; 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 { Future<pw.Document> generateLabelPdf(TicketModel ticket) async {
final pdf = pw.Document(); final pdf = pw.Document();
final font = await PdfGoogleFonts.robotoRegular(); final font = await PdfGoogleFonts.robotoRegular();
final boldFont = await PdfGoogleFonts.robotoBold(); final boldFont = await PdfGoogleFonts.robotoBold();
// Prendiamo le misure salvate (se custom) o usiamo default final rawW = company.labelWidth ?? 38.0;
final widthMm = company.labelWidth ?? 62.0; final rawH = company.labelHeight ?? 25.0;
final heightMm = company.labelHeight ?? 29.0;
// Creiamo il formato fisico esatto! // Orientamento sempre verticale: lato corto come larghezza, lato lungo come altezza (es. 25x38mm)
final format = company.isLabelVertical final shortSideMm = rawW < rawH ? rawW : rawH;
? PdfPageFormat(heightMm * PdfPageFormat.mm, widthMm * PdfPageFormat.mm) final longSideMm = rawW > rawH ? rawW : rawH;
: PdfPageFormat(
widthMm * PdfPageFormat.mm, final format = PdfPageFormat(
heightMm * PdfPageFormat.mm, 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( pdf.addPage(
pw.Page( pw.Page(
pageFormat: format, pageFormat: format,
margin: const pw.EdgeInsets.all(2), // Margini minimi per le etichette margin: const pw.EdgeInsets.all(margin),
build: (context) { build: (context) {
return pw.Row( return pw.Column(
mainAxisAlignment: pw.MainAxisAlignment.spaceBetween, mainAxisAlignment: pw.MainAxisAlignment.start,
crossAxisAlignment: pw.CrossAxisAlignment.center,
children: [ 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( pw.BarcodeWidget(
barcode: pw.Barcode.qrCode(), barcode: pw.Barcode.qrCode(
data: ticket.id!, errorCorrectLevel: pw.BarcodeQRCorrectionLevel.low,
width: 20, ),
height: 20, 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,
),
), ),
], ],
); );