OscarGil03 před 6 měsíci
rodič
revize
f2153f60e9

+ 65 - 29
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),
@@ -249,11 +264,23 @@ class _VentaScreenState extends State<VentaScreen> {
   }
 
   void cargarPedidos(DateTime fecha) async {
-    final inicioDelDia = DateTime(fecha.year, fecha.month, fecha.day);
-    final finDelDia = DateTime(fecha.year, fecha.month, fecha.day, 23, 59, 59);
+    // Convertir el inicio y fin del día local a UTC
+    final inicioDelDia = DateTime(fecha.year, fecha.month, fecha.day)
+        .toUtc(); // Convierte la fecha local de inicio del día a UTC
+
+    final finDelDia = DateTime(fecha.year, fecha.month, fecha.day, 23, 59, 59)
+        .toUtc(); // Convierte la fecha local de fin del día a UTC
+
+    print('Buscando pedidos desde: $inicioDelDia hasta: $finDelDia (en UTC)');
+
+    // Realizar la búsqueda en UTC
     final pedidos = await Provider.of<PedidoViewModel>(context, listen: false)
         .buscarPorFecha(inicioDelDia, finDelDia);
 
+    print('Pedidos obtenidos: ${pedidos.length}');
+    pedidos.forEach((pedido) => print(
+        'Pedido: ${pedido.folio}, Total: ${pedido.totalPedido}, Estatus: ${pedido.estatus}'));
+
     final pedidosNoCancelados =
         pedidos.where((p) => p.estatus != "CANCELADO").toList();
     final pedidosCancelados =
@@ -264,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 - 14
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,27 @@ 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)),
+                    if (totalTarjeta > 0)
+                      pw.Text("- Total en Tarjeta: \$${formattedTotalTarjeta}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    if (totalTransferencia > 0)
+                      pw.Text(
+                          "- Total en Transferencia: \$${formattedTotalTransferencia}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    if (totalEfectivo > 0)
+                      pw.Text(
+                          "- Total en Efectivo: \$${formattedTotalEfectivo}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
+                    if (cambio > 0)
+                      pw.Text("- Cambio Entregado: \$${formattedCambio}",
+                          style: pw.TextStyle(
+                              fontWeight: pw.FontWeight.bold, fontSize: 9.5)),
                     pw.Text("- Total General: \$${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))
                   ],

+ 1 - 1
lib/widgets/app_drawer.dart

@@ -216,7 +216,7 @@ class _AppDrawerState extends State<AppDrawer> {
               child: Align(
                 alignment: Alignment.bottomCenter,
                 child: Text(
-                  'v1.24.09.12+13',
+                  'v1.24.10.03',
                   style: TextStyle(fontWeight: FontWeight.w300),
                 ),
               ),