Browse Source

Versión tablet

OscarGil03 8 months ago
parent
commit
c10117011c

+ 15 - 0
lib/viewmodels/variable_view_model.dart

@@ -118,4 +118,19 @@ class VariableViewModel extends ChangeNotifier {
 
     return false;
   }
+
+  Future<Variable?> getVariableByClave(String clave) async {
+    var db = await RepoService().db;
+    var result = await db!.query(
+      'Variable',
+      where: 'clave = ?',
+      whereArgs: [clave],
+    );
+
+    if (result.isNotEmpty) {
+      return Variable.fromJson(result.first);
+    }
+
+    return null;
+  }
 }

+ 75 - 102
lib/views/pedido/pedido_ticket.dart

@@ -28,9 +28,9 @@ Future<void> imprimirTicketsJuntos(BuildContext context, Pedido pedido) async {
   }
 
   if (ticketCocinaActivo) {
-    pdf.addPage(
-      generarPaginaSegundoTicket(pedido),
-    );
+    final paginaSegundoTicket =
+        await generarPaginaSegundoTicket(context, pedido);
+    pdf.addPage(paginaSegundoTicket);
   }
 
   await printPdf(Uint8List.fromList(await pdf.save()));
@@ -63,10 +63,10 @@ pw.Page generarPaginaPrimerTicket(Pedido pedido, pw.MemoryImage image) {
               children: [
                 pw.Text(
                     '- ${topping.topping?.nombre ?? "Topping no especificado"}',
-                    style: const pw.TextStyle(fontSize: 7)),
+                    style: const pw.TextStyle(fontSize: 8)),
                 pw.Spacer(),
                 pw.Text('\$${numberFormat.format(toppingPrice)}',
-                    style: const pw.TextStyle(fontSize: 7)),
+                    style: const pw.TextStyle(fontSize: 8)),
               ],
             );
           }).toList();
@@ -79,20 +79,17 @@ pw.Page generarPaginaPrimerTicket(Pedido pedido, pw.MemoryImage image) {
                   flex: 2,
                   child: pw.Text(
                       producto.producto?.nombre ?? "Producto no especificado",
-                      style: const pw.TextStyle(fontSize: 7)),
+                      style: const pw.TextStyle(fontSize: 8)),
                 ),
                 pw.Expanded(
                   flex: 1,
                   child: pw.Text('x${producto.cantidad}',
-                      style: const pw.TextStyle(fontSize: 7)),
+                      style: const pw.TextStyle(fontSize: 8)),
                 ),
                 pw.Padding(
                   padding: pw.EdgeInsets.only(right: 2),
-                  child: pw.Expanded(
-                    flex: 1,
-                    child: pw.Text('\$${numberFormat.format(productPrice)}',
-                        style: const pw.TextStyle(fontSize: 8)),
-                  ),
+                  child: pw.Text('\$${numberFormat.format(productPrice)}',
+                      style: const pw.TextStyle(fontSize: 8)),
                 )
               ],
             ),
@@ -108,47 +105,33 @@ pw.Page generarPaginaPrimerTicket(Pedido pedido, pw.MemoryImage image) {
 
   return pw.Page(
       pageFormat: PdfPageFormat.roll57,
+      margin: pw.EdgeInsets.all(5),
       build: (pw.Context context) {
         return pw.Column(
             crossAxisAlignment: pw.CrossAxisAlignment.center,
             children: [
-              pw.Padding(
-                  padding: const pw.EdgeInsets.only(right: 20),
-                  child:
-                      pw.Center(child: pw.Image(image, width: 50, height: 50))),
-              pw.SizedBox(height: 10),
-              pw.Padding(
-                  padding: const pw.EdgeInsets.only(right: 15),
-                  child: pw.Column(children: [
-                    pw.SizedBox(height: 5),
-                    pw.Text('Fecha: ${pedido.peticion}',
-                        style: const pw.TextStyle(fontSize: 9)),
-                    pw.Text('Conalep', style: const pw.TextStyle(fontSize: 9)),
-                    pw.Text('Hermosillo',
-                        style: const pw.TextStyle(fontSize: 9)),
-                  ])),
-              pw.SizedBox(height: 10),
+              pw.Center(child: pw.Image(image, width: 50, height: 50)),
+              pw.SizedBox(height: 5),
+              pw.Text('Fecha: ${pedido.peticion}',
+                  style: const pw.TextStyle(fontSize: 8)),
+              pw.Text('Conalep', style: const pw.TextStyle(fontSize: 8)),
+              pw.Text('Hermosillo', style: const pw.TextStyle(fontSize: 8)),
+              pw.SizedBox(height: 5),
               pw.Text('Pedido: ${pedido.folio}',
                   style: pw.TextStyle(
-                      fontWeight: pw.FontWeight.bold, fontSize: 10)),
-              pw.SizedBox(height: 10),
-              pw.Padding(
-                  padding: const pw.EdgeInsets.only(right: 20),
-                  child: pw.Column(children: productList)),
+                      fontWeight: pw.FontWeight.bold, fontSize: 9)),
+              pw.SizedBox(height: 5),
+              pw.Column(children: productList),
               pw.Divider(),
               pw.Row(
                 mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
                 children: [
                   pw.Text('Subtotal:',
                       style: pw.TextStyle(
-                          fontWeight: pw.FontWeight.bold, fontSize: 9)),
-                  pw.Padding(
-                    padding: const pw.EdgeInsets.only(right: 30),
-                    child: pw.Text(
-                        '\$${numberFormat.format(totalSinDescuento)}',
-                        style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 9)),
-                  ),
+                          fontWeight: pw.FontWeight.bold, fontSize: 8)),
+                  pw.Text('\$${numberFormat.format(totalSinDescuento)}',
+                      style: pw.TextStyle(
+                          fontWeight: pw.FontWeight.bold, fontSize: 8)),
                 ],
               ),
               if (descuento > 0) ...[
@@ -157,14 +140,10 @@ pw.Page generarPaginaPrimerTicket(Pedido pedido, pw.MemoryImage image) {
                   children: [
                     pw.Text('Descuento:',
                         style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 9)),
-                    pw.Padding(
-                      padding: const pw.EdgeInsets.only(right: 30),
-                      child: pw.Text(
-                          '-\$${numberFormat.format(precioDescuento)}',
-                          style: pw.TextStyle(
-                              fontWeight: pw.FontWeight.bold, fontSize: 9)),
-                    ),
+                            fontWeight: pw.FontWeight.bold, fontSize: 8)),
+                    pw.Text('-\$${numberFormat.format(precioDescuento)}',
+                        style: pw.TextStyle(
+                            fontWeight: pw.FontWeight.bold, fontSize: 8)),
                   ],
                 ),
               ],
@@ -173,53 +152,52 @@ pw.Page generarPaginaPrimerTicket(Pedido pedido, pw.MemoryImage image) {
                 children: [
                   pw.Text('Total:',
                       style: pw.TextStyle(
-                          fontWeight: pw.FontWeight.bold, fontSize: 9)),
-                  pw.Padding(
-                    padding: const pw.EdgeInsets.only(right: 30),
-                    child: pw.Text(
-                        '\$${numberFormat.format(totalConDescuento)}',
-                        style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 9)),
-                  ),
+                          fontWeight: pw.FontWeight.bold, fontSize: 8)),
+                  pw.Text('\$${numberFormat.format(totalConDescuento)}',
+                      style: pw.TextStyle(
+                          fontWeight: pw.FontWeight.bold, fontSize: 8)),
                 ],
               ),
               pw.SizedBox(height: 5),
-              pw.Padding(
-                  padding: const pw.EdgeInsets.only(right: 15),
-                  child: pw.Text('¡GRACIAS POR SU COMPRA!',
-                      style: pw.TextStyle(
-                          fontSize: 8, fontWeight: pw.FontWeight.bold))),
+              pw.Text('¡GRACIAS POR SU COMPRA!',
+                  style: pw.TextStyle(
+                      fontSize: 7, fontWeight: pw.FontWeight.bold)),
               pw.Divider(),
-              pw.SizedBox(height: 20),
-              pw.Text('.', style: pw.TextStyle(fontSize: 1)),
             ]);
       });
 }
 
-pw.Page generarPaginaSegundoTicket(Pedido pedido) {
+Future<pw.Page> generarPaginaSegundoTicket(
+    BuildContext context, Pedido pedido) async {
   final numberFormat = NumberFormat('#,##0.00', 'es_MX');
   double subtotal = 0;
   double totalConDescuento = 0;
   double descuento = pedido.descuento?.toDouble() ?? 0.0;
   double precioDescuento = 0;
 
+  final sucursalVariable =
+      await Provider.of<VariableViewModel>(context, listen: false)
+          .getVariableByClave('sucursal');
+  final sucursalDescripcion = sucursalVariable?.descripcion ?? '';
+
   List<pw.Widget> content = [
-    pw.SizedBox(height: 20),
-    pw.Text('.', style: pw.TextStyle(fontSize: 1)),
     pw.Row(
       mainAxisAlignment: pw.MainAxisAlignment.spaceAround,
       children: [
-        pw.Text('${pedido.folio}',
-            style: pw.TextStyle(fontSize: 12, fontWeight: pw.FontWeight.bold)),
+        pw.Text('${pedido.folio}/ ',
+            style: pw.TextStyle(fontSize: 7, fontWeight: pw.FontWeight.bold)),
+        if (sucursalDescripcion.isNotEmpty)
+          pw.Text('$sucursalDescripcion/ ',
+              style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
         pw.Text('${pedido.peticion}',
-            style: pw.TextStyle(fontSize: 12, fontWeight: pw.FontWeight.bold)),
+            style: pw.TextStyle(fontSize: 7, fontWeight: pw.FontWeight.bold)),
       ],
     ),
-    pw.SizedBox(height: 5),
+    pw.SizedBox(height: 2),
     if (pedido.nombreCliente != null && pedido.nombreCliente!.isNotEmpty)
       pw.Text('Cliente: ${pedido.nombreCliente}',
-          style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
-    pw.SizedBox(height: 10),
+          style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
+    pw.SizedBox(height: 2),
   ];
 
   // Mostrar los productos con la cantidad, el precio total y el precio de los toppings
@@ -241,14 +219,14 @@ pw.Page generarPaginaSegundoTicket(Pedido pedido) {
                 flex: 3,
                 child: pw.Text(
                     '-${topping.topping?.nombre ?? "Topping no especificado"}',
-                    style: const pw.TextStyle(fontSize: 9)),
+                    style: const pw.TextStyle(fontSize: 6)),
               ),
               if (toppingPrice > 0)
                 pw.Expanded(
                   flex: 1,
                   child: pw.Text(
                     '\$${numberFormat.format(toppingTotal)}',
-                    style: const pw.TextStyle(fontSize: 9),
+                    style: const pw.TextStyle(fontSize: 6),
                     textAlign: pw.TextAlign.right,
                   ),
                 ),
@@ -263,22 +241,23 @@ pw.Page generarPaginaSegundoTicket(Pedido pedido) {
               pw.Expanded(
                 flex: 1,
                 child: pw.Text('${producto.cantidad}',
-                    style: const pw.TextStyle(fontSize: 12)),
+                    style: const pw.TextStyle(fontSize: 7)),
               ),
               pw.Expanded(
-                flex: 3,
+                flex: 5,
                 child: pw.Text(
                     producto.producto?.nombre ?? "Producto no especificado",
-                    style: const pw.TextStyle(fontSize: 11)),
+                    style: const pw.TextStyle(fontSize: 7)),
               ),
               pw.Expanded(
-                flex: 2,
-                child: pw.Text(
-                  '\$${numberFormat.format(productTotal)}',
-                  style: const pw.TextStyle(fontSize: 12),
-                  textAlign: pw.TextAlign.right,
-                ),
-              ),
+                  flex: 2,
+                  child: pw.Align(
+                    alignment: pw.Alignment.centerRight,
+                    child: pw.Text(
+                      '\$${numberFormat.format(productTotal)}',
+                      style: const pw.TextStyle(fontSize: 7),
+                    ),
+                  )),
             ],
           ),
           ...toppingsList,
@@ -299,22 +278,18 @@ pw.Page generarPaginaSegundoTicket(Pedido pedido) {
         mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
         children: [
           pw.Text('Subtotal:',
-              style:
-                  pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
+              style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
           pw.Text('\$${numberFormat.format(subtotal)}',
-              style:
-                  pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
+              style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
         ],
       ),
       pw.Row(
         mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
         children: [
           pw.Text('Descuento:',
-              style:
-                  pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
+              style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
           pw.Text('-\$${numberFormat.format(precioDescuento)}',
-              style:
-                  pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
+              style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
         ],
       ),
     ]);
@@ -325,32 +300,30 @@ pw.Page generarPaginaSegundoTicket(Pedido pedido) {
       mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
       children: [
         pw.Text('Total:',
-            style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
+            style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
         pw.Text(
             '\$${numberFormat.format(descuento > 0 ? totalConDescuento : subtotal)}',
-            style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)),
+            style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)),
       ],
     ),
   );
 
   if (pedido.comentarios != null && pedido.comentarios!.isNotEmpty) {
-    content.add(pw.SizedBox(height: 10));
+    content.add(pw.SizedBox(height: 1));
     content.add(pw.Text('Comentarios:',
-        style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 12)));
+        style: pw.TextStyle(fontWeight: pw.FontWeight.bold, fontSize: 7)));
     content.add(pw.Padding(
       padding: const pw.EdgeInsets.only(right: 15),
       child:
-          pw.Text(pedido.comentarios!, style: const pw.TextStyle(fontSize: 12)),
+          pw.Text(pedido.comentarios!, style: const pw.TextStyle(fontSize: 7)),
     ));
-    content.add(pw.Text('.', style: pw.TextStyle(fontSize: 1)));
-    content.add(pw.Text('.', style: pw.TextStyle(fontSize: 1)));
   }
 
-  content.add(pw.SizedBox(height: 20));
-  content.add(pw.Text('.', style: pw.TextStyle(fontSize: 1)));
+  content.add(pw.SizedBox(height: 1));
 
   return pw.Page(
     pageFormat: PdfPageFormat.roll57,
+    margin: pw.EdgeInsets.all(5),
     build: (pw.Context context) {
       return pw.Column(
           crossAxisAlignment: pw.CrossAxisAlignment.center, children: content);

+ 1 - 1
lib/widgets/app_drawer.dart

@@ -202,7 +202,7 @@ class AppDrawer extends StatelessWidget {
               child: Align(
                 alignment: Alignment.bottomCenter,
                 child: Text(
-                  'v1.24.08.27',
+                  'v1.24.08.29',
                   style: TextStyle(fontWeight: FontWeight.w300),
                 ),
               ))