浏览代码

Calculo de cambio de pedidos por día

OscarGil03 6 月之前
父节点
当前提交
967d093c1d
共有 3 个文件被更改,包括 75 次插入44 次删除
  1. 51 27
      lib/views/venta/venta_screen.dart
  2. 23 16
      lib/views/venta/venta_ticket.dart
  3. 1 1
      lib/widgets/app_drawer.dart

+ 51 - 27
lib/views/venta/venta_screen.dart

@@ -25,6 +25,8 @@ class _VentaScreenState extends State<VentaScreen> {
   double totalEfectivoDelDia = 0.0;
   double totalTarjetaDelDia = 0.0;
   double totalTransferenciaDelDia = 0.0;
+  double cambio = 0.0;
+  double totalSinCambio = 0.0;
 
   String formatCurrency(double amount) {
     final format = NumberFormat("#,##0.00", "es_MX");
@@ -200,33 +202,46 @@ class _VentaScreenState extends State<VentaScreen> {
                             fontSize: 20, fontWeight: FontWeight.bold),
                       ),
                     ),
-                    if (totalEfectivoDelDia > 0)
-                      Padding(
-                        padding: const EdgeInsets.all(16.0),
-                        child: Text(
-                          "Total en Efectivo: \$${formatCurrency(totalEfectivoDelDia)}",
-                          style: TextStyle(
-                              fontSize: 20, fontWeight: FontWeight.bold),
-                        ),
-                      ),
-                    if (totalTarjetaDelDia > 0)
-                      Padding(
-                        padding: const EdgeInsets.all(16.0),
-                        child: Text(
-                          "Total en Tarjeta: \$${formatCurrency(totalTarjetaDelDia)}",
-                          style: TextStyle(
-                              fontSize: 20, fontWeight: FontWeight.bold),
-                        ),
-                      ),
-                    if (totalTransferenciaDelDia > 0)
-                      Padding(
-                        padding: const EdgeInsets.all(16.0),
-                        child: Text(
-                          "Total en Transferencia: \$${formatCurrency(totalTransferenciaDelDia)}",
-                          style: TextStyle(
-                              fontSize: 20, fontWeight: FontWeight.bold),
-                        ),
-                      ),
+                    Row(
+                      children: [
+                        if (totalTarjetaDelDia > 0)
+                          Padding(
+                            padding: const EdgeInsets.all(16.0),
+                            child: Text(
+                              "Total en Tarjeta: \$${formatCurrency(totalTarjetaDelDia)}",
+                              style: TextStyle(
+                                  fontSize: 20, fontWeight: FontWeight.bold),
+                            ),
+                          ),
+                        if (totalTransferenciaDelDia > 0)
+                          Padding(
+                            padding: const EdgeInsets.all(16.0),
+                            child: Text(
+                              "Total en Transferencia: \$${formatCurrency(totalTransferenciaDelDia)}",
+                              style: TextStyle(
+                                  fontSize: 20, fontWeight: FontWeight.bold),
+                            ),
+                          ),
+                        if (totalEfectivoDelDia > 0)
+                          Padding(
+                            padding: const EdgeInsets.all(16.0),
+                            child: Text(
+                              "Total en Efectivo: \$${formatCurrency(totalEfectivoDelDia)}",
+                              style: TextStyle(
+                                  fontSize: 20, fontWeight: FontWeight.bold),
+                            ),
+                          ),
+                        if (cambio > 0)
+                          Padding(
+                            padding: const EdgeInsets.all(16.0),
+                            child: Text(
+                              "Cambio Entregado: \$${formatCurrency(cambio)}",
+                              style: TextStyle(
+                                  fontSize: 20, fontWeight: FontWeight.bold),
+                            ),
+                          ),
+                      ],
+                    ),
                     if (totalCancelados > 0)
                       Padding(
                         padding: const EdgeInsets.all(16.0),
@@ -276,14 +291,23 @@ class _VentaScreenState extends State<VentaScreen> {
     totalEfectivoDelDia = 0.0;
     totalTarjetaDelDia = 0.0;
     totalTransferenciaDelDia = 0.0;
+    cambio = 0.0;
+    totalSinCambio = 0.0;
 
     for (var pedido in pedidosNoCancelados) {
       totalDelDia += pedido.totalPedido ?? 0.0;
       totalEfectivoDelDia += pedido.cantEfectivo ?? 0.0;
       totalTarjetaDelDia += pedido.cantTarjeta ?? 0.0;
       totalTransferenciaDelDia += pedido.cantTransferencia ?? 0.0;
+      totalSinCambio =
+          totalEfectivoDelDia + totalTarjetaDelDia + totalTransferenciaDelDia;
+
+      cambio = totalSinCambio - totalDelDia;
     }
 
+    print("Total del dia sin cambios $totalSinCambio");
+    print("Cambio $cambio");
+
     totalCancelados = pedidosCancelados.fold(
         0.0, (sum, current) => sum + (current.totalPedido ?? 0.0));
 

+ 23 - 16
lib/views/venta/venta_ticket.dart

@@ -38,6 +38,9 @@ class VentaTicket {
     double totalTransferencia = pedidosNoCancelados.fold(
         0.0, (sum, p) => sum + (p.cantTransferencia ?? 0.0));
 
+    double totalSinCambio = totalEfectivo + totalTarjeta + totalTransferencia;
+    double cambio = totalSinCambio - totalNoCancelados;
+
     final spelling = SpellingNumber(lang: 'es');
     String totalEnLetras = toTitleCase(spelling.convert(totalNoCancelados));
 
@@ -48,14 +51,12 @@ class VentaTicket {
     String formattedTotalTarjeta = numberFormat.format(totalTarjeta);
     String formattedTotalTransferencia =
         numberFormat.format(totalTransferencia);
+    String formattedCambio = numberFormat.format(cambio);
 
     int centavos =
         ((totalNoCancelados - totalNoCancelados.floor()) * 100).round();
     String centavosEnLetras = centavos.toString().padLeft(2, '0') + "/100 M.N.";
 
-    print("Total en letras: $totalEnLetras $centavosEnLetras");
-    print("Total formateado: $formattedTotalNoCancelados");
-
     pdf.addPage(pw.Page(
         pageFormat: PdfPageFormat.roll57,
         build: (pw.Context context) {
@@ -94,19 +95,25 @@ class VentaTicket {
                 child: pw.Column(
                   crossAxisAlignment: pw.CrossAxisAlignment.start,
                   children: [
-                    pw.Text("- Total en Efectivo: \$${formattedTotalEfectivo}",
-                        style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 11)),
-                    pw.Text("- Total en Tarjeta: \$${formattedTotalTarjeta}",
-                        style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 11)),
-                    pw.Text(
-                        "- Total en Transferencia: \$${formattedTotalTransferencia}",
-                        style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 11)),
-                    pw.Text("- Total General: \$${formattedTotalNoCancelados}",
+                    if (totalTarjeta > 0)
+                      pw.Text("Tarjeta: \$${formattedTotalTarjeta}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    if (totalTransferencia > 0)
+                      pw.Text("Transf: \$${formattedTotalTransferencia}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    if (totalEfectivo > 0)
+                      pw.Text("Efectivo: \$${formattedTotalEfectivo}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    if (cambio > 0)
+                      pw.Text("Cambio: \$${formattedCambio}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    pw.Text("Total: \$${formattedTotalNoCancelados}",
                         style: pw.TextStyle(
-                            fontWeight: pw.FontWeight.bold, fontSize: 11)),
+                            fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
                     pw.Text("Son: $totalEnLetras Pesos $centavosEnLetras",
                         style: pw.TextStyle(fontSize: 10))
                   ],
@@ -126,7 +133,7 @@ class VentaTicket {
                     child: pw.Row(
                       mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
                       children: [
-                        pw.Text("Folio: ${pedido.folio} (Cancelado)",
+                        pw.Text("Folio: ${pedido.folio}",
                             style: pw.TextStyle(fontSize: 10)),
                         pw.Text("\$${pedido.totalPedido?.toStringAsFixed(2)}",
                             style: pw.TextStyle(fontSize: 10)),

+ 1 - 1
lib/widgets/app_drawer.dart

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