Просмотр исходного кода

Solo puede seleccionarse exacto una vez en el pedido y ajuste diseño

OscarGil03 месяцев назад: 5
Родитель
Сommit
90dd32de34

+ 1 - 1
lib/viewmodels/pedido_view_model.dart

@@ -254,7 +254,7 @@ class PedidoViewModel extends ChangeNotifier {
       Map<String, dynamic> pedidoJson =
           await prepararPedidoParaApi(pedidoNoSincronizado);
 
-      print('JSON enviado: $pedidoJson');
+      //print('JSON enviado: $pedidoJson');
 
       var response = ApiResponse(await BaseService()
           .post('/pos/pedido/sincronizar', body: pedidoJson));

+ 5 - 5
lib/views/corte_caja/corte_caja_finalizado_screen.dart

@@ -39,13 +39,13 @@ class _CorteCajaFinalizadoScreenState extends State<CorteCajaFinalizadoScreen> {
 
     return Scaffold(
       appBar: AppBar(
-        title: Text('Resumen Corte de Caja',
-            style: TextStyle(color: AppTheme.quaternary)),
-        iconTheme: IconThemeData(color: AppTheme.quaternary),
-      ),
+          title: Text('Resumen Corte de Caja',
+              style: TextStyle(
+                  color: AppTheme.secondary, fontWeight: FontWeight.w500)),
+          iconTheme: IconThemeData(color: AppTheme.secondary)),
       body: SingleChildScrollView(
         child: Padding(
-          padding: EdgeInsets.symmetric(horizontal: 50, vertical: 20),
+          padding: EdgeInsets.symmetric(horizontal: 250, vertical: 20),
           child: Column(
             crossAxisAlignment: CrossAxisAlignment.start,
             children: [

+ 6 - 2
lib/views/corte_caja/corte_caja_form.dart

@@ -100,8 +100,12 @@ class _CorteCajaFormState extends State<CorteCajaForm> {
 
     return Scaffold(
         appBar: AppBar(
-          title: Text('Caja', style: TextStyle(color: AppTheme.quaternary)),
-          iconTheme: IconThemeData(color: AppTheme.quaternary),
+          title: Text(
+            'Caja',
+            style: TextStyle(
+                color: AppTheme.secondary, fontWeight: FontWeight.w500),
+          ),
+          iconTheme: IconThemeData(color: AppTheme.secondary),
         ),
         body: SingleChildScrollView(
           child: Padding(

+ 30 - 64
lib/views/corte_caja/corte_caja_screen.dart

@@ -112,9 +112,10 @@ class _CorteCajaScreenState extends State<CorteCajaScreen> {
       appBar: AppBar(
           title: Text(
             'Corte De Caja',
-            style: TextStyle(color: AppTheme.quaternary),
+            style: TextStyle(
+                color: AppTheme.secondary, fontWeight: FontWeight.w500),
           ),
-          iconTheme: IconThemeData(color: AppTheme.quaternary)),
+          iconTheme: IconThemeData(color: AppTheme.secondary)),
       floatingActionButton: FloatingActionButton.extended(
         onPressed: () async {
           final viewModel =
@@ -147,8 +148,8 @@ class _CorteCajaScreenState extends State<CorteCajaScreen> {
           borderRadius: BorderRadius.circular(8),
         ),
         materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
-        backgroundColor: AppTheme.primary,
-        foregroundColor: AppTheme.tertiary,
+        backgroundColor: AppTheme.secondary,
+        foregroundColor: AppTheme.quaternary,
       ),
       body: Column(
         children: [
@@ -164,6 +165,7 @@ class _CorteCajaScreenState extends State<CorteCajaScreen> {
                       builder: (context, constraints) {
                         if (screenWidth > 1000) {
                           return Row(
+                            crossAxisAlignment: CrossAxisAlignment.end,
                             children: [
                               Expanded(
                                 flex: 7,
@@ -313,68 +315,32 @@ class _CorteCajaScreenState extends State<CorteCajaScreen> {
     return Row(
       children: [
         Expanded(
-            flex: 2,
-            child: clase.tarjeta(
-                ListTile(
-                    title: Text(
-                      "Fecha Inicial",
-                      style: TextStyle(
-                          color: AppTheme.quaternary,
-                          fontWeight: FontWeight.bold),
-                    ),
-                    subtitle: Text(
-                      fechaInicio == null
-                          ? ""
-                          : DateFormat("dd/MM/yyyy").format(fechaInicio!),
-                      style: TextStyle(
-                          color: AppTheme.quaternary,
-                          fontWeight: FontWeight.bold),
-                    ),
-                    trailing:
-                        Icon(Icons.calendar_month, color: AppTheme.quaternary),
-                    onTap: () async {
-                      DateTime? d = await clase.showDatetimePicker(
-                          context, fechaInicio,
-                          tipo: OmniDateTimePickerType.date, solofecha: true);
-                      if (d == null) return;
-                      setState(() {
-                        fechaInicio = d;
-                      });
-                    }),
-                color: AppTheme.primary)),
+          flex: 3,
+          child: clase.FechaSelectWidget(
+            fecha: fechaInicio,
+            onFechaChanged: (d) {
+              setState(() {
+                fechaInicio = d;
+              });
+            },
+            etiqueta: "Fecha Inicial",
+            context: context,
+          ),
+        ),
         const SizedBox(width: 5),
         Expanded(
-            flex: 2,
-            child: clase.tarjeta(
-                ListTile(
-                    title: Text(
-                      "Fecha Final",
-                      style: TextStyle(
-                          color: AppTheme.quaternary,
-                          fontWeight: FontWeight.bold),
-                    ),
-                    subtitle: Text(
-                      fechaFin == null
-                          ? ""
-                          : DateFormat("dd/MM/yyyy").format(fechaFin!),
-                      style: TextStyle(
-                          color: AppTheme.quaternary,
-                          fontWeight: FontWeight.bold),
-                    ),
-                    trailing:
-                        Icon(Icons.calendar_month, color: AppTheme.quaternary),
-                    onTap: () async {
-                      DateTime? d = await clase.showDatetimePicker(
-                          context, fechaInicio,
-                          inicia: fechaInicio,
-                          tipo: OmniDateTimePickerType.date,
-                          solofecha: true);
-                      if (d == null) return;
-                      setState(() {
-                        fechaFin = d;
-                      });
-                    }),
-                color: AppTheme.primary)),
+          flex: 3,
+          child: clase.FechaSelectWidget(
+            fecha: fechaFin,
+            onFechaChanged: (d) {
+              setState(() {
+                fechaFin = d;
+              });
+            },
+            etiqueta: "Fecha Final",
+            context: context,
+          ),
+        ),
       ],
     );
   }

+ 3 - 0
lib/views/home/home_screen.dart

@@ -1,3 +1,4 @@
+import 'package:conalep_pos/models/corte_caja_model.dart';
 import 'package:conalep_pos/themes/themes.dart';
 import 'package:conalep_pos/widgets/widgets.dart';
 import 'package:flutter/material.dart';
@@ -33,6 +34,8 @@ class Formulario extends State<HomeScreen> {
       if (permisoViewModel.userPermisos.isEmpty) {
         permisoViewModel.fetchUserPermisos();
       }
+
+      Provider.of<CorteCajaViewModel>(context, listen: false).fetchCortes();
     });
   }
 

+ 329 - 541
lib/views/pedido/pedido_form.dart

@@ -48,6 +48,8 @@ class _PedidoFormState extends State<PedidoForm> {
   TextEditingController tarjetaController = TextEditingController();
   TextEditingController transferenciaController = TextEditingController();
   double cambio = 0.0;
+  double faltante = 0.0;
+  bool totalCompletado = false;
 
   double calcularTotalPedido() {
     double total = 0;
@@ -164,8 +166,11 @@ class _PedidoFormState extends State<PedidoForm> {
   Future<void> _promptForCustomerName() async {
     TextEditingController nombreController = TextEditingController();
     TextEditingController comentarioController = TextEditingController();
-    String errorMessage = '';
-    double faltante = totalPedido;
+    TextEditingController efectivoController = TextEditingController();
+    TextEditingController tarjetaController = TextEditingController();
+    TextEditingController transferenciaController = TextEditingController();
+
+    faltante = totalPedido;
     bool totalCompletado = false;
     bool efectivoCompleto = false;
     bool tarjetaCompleto = false;
@@ -178,586 +183,369 @@ class _PedidoFormState extends State<PedidoForm> {
 
       setState(() {
         cambio = totalPagado - totalPedido;
-        if (cambio < 0) {
-          faltante = totalPedido - totalPagado;
-          cambio = 0;
-          totalCompletado = false;
-        } else {
-          faltante = 0;
-          totalCompletado = true;
-        }
-
-        // Si el total ha sido alcanzado o excedido, desactivar otros métodos de pago
-        if (totalPagado >= totalPedido) {
-          if (!efectivoSeleccionado) efectivoSeleccionado = false;
-          if (!tarjetaSeleccionada) tarjetaSeleccionada = false;
-          if (!transferenciaSeleccionada) transferenciaSeleccionada = false;
-        }
+        faltante = cambio < 0 ? totalPedido - totalPagado : 0;
+        totalCompletado = cambio >= 0;
       });
     }
 
-    void _validarCantidad(
-        StateSetter setState, TextEditingController controller) {
-      double cantidad = double.tryParse(controller.text) ?? 0;
-      if (cantidad > totalPedido) {
-        setState(() {
-          controller.text = totalPedido.toStringAsFixed(2);
-        });
-      }
-      _calcularCambio(setState);
-    }
-
-    bool _isPaymentOptionEnabled(bool isSelected) {
-      return !totalCompletado || isSelected;
-    }
-
     bool? shouldSave = await showDialog<bool>(
       context: context,
       builder: (BuildContext context) {
         return StatefulBuilder(
           builder: (context, setState) {
-            return RawKeyboardListener(
-                focusNode: FocusNode(),
-                onKey: (RawKeyEvent event) {
-                  if (event.isKeyPressed(LogicalKeyboardKey.enter) &&
-                      totalCompletado) {
-                    Navigator.of(context).pop(true);
-                  }
-                },
-                child: AlertDialog(
-                  actionsPadding: EdgeInsets.fromLTRB(50, 10, 50, 30),
-                  title: const Text(
-                    'Finalizar Pedido',
-                    style: TextStyle(fontSize: 22, fontWeight: FontWeight.w500),
-                  ),
-                  content: Container(
-                    height: 600,
-                    child: Column(
-                      children: [
-                        Expanded(
-                          child: SingleChildScrollView(
-                            child: Column(
-                              children: [
-                                AppTextField(
-                                  controller: nombreController,
-                                  etiqueta: 'Nombre',
-                                  hintText: "Nombre del Cliente",
-                                ),
-                                const SizedBox(height: 10),
-                                AppTextField(
-                                  controller: comentarioController,
-                                  etiqueta: 'Comentarios (opcional)',
-                                  hintText: 'Comentarios',
-                                  maxLines: 2,
-                                ),
-                                const SizedBox(height: 10),
-                                Align(
-                                  alignment: Alignment.center,
-                                  child: Text(
-                                    'Métodos de pago',
-                                    style: TextStyle(
-                                        fontWeight: FontWeight.bold,
-                                        fontSize: 20),
-                                  ),
-                                ),
-                                const SizedBox(height: 10),
-                                // Efectivo
-                                GestureDetector(
-                                  onTap: () {
-                                    if (_isPaymentOptionEnabled(
-                                        efectivoSeleccionado)) {
-                                      setState(() {
-                                        efectivoSeleccionado =
-                                            !efectivoSeleccionado;
-                                        if (!efectivoSeleccionado) {
-                                          efectivoCompleto = false;
-                                          efectivoController.clear();
-                                          _calcularCambio(setState);
-                                        } else if (efectivoCompleto) {
-                                          efectivoController.text =
-                                              totalPedido.toStringAsFixed(2);
-                                          _calcularCambio(setState);
-                                        }
-                                      });
-                                    }
-                                  },
-                                  child: Row(
-                                    mainAxisAlignment:
-                                        MainAxisAlignment.spaceBetween,
-                                    crossAxisAlignment:
-                                        CrossAxisAlignment.center,
-                                    children: [
-                                      Row(
-                                        children: [
-                                          Checkbox(
-                                            activeColor: AppTheme.primary,
-                                            value: efectivoSeleccionado,
-                                            onChanged: _isPaymentOptionEnabled(
-                                                    efectivoSeleccionado)
-                                                ? (bool? value) {
-                                                    setState(() {
-                                                      efectivoSeleccionado =
-                                                          value ?? false;
-                                                      if (!efectivoSeleccionado) {
-                                                        efectivoCompleto =
-                                                            false;
-                                                        efectivoController
-                                                            .clear();
-                                                        _calcularCambio(
-                                                            setState);
-                                                      } else if (efectivoCompleto) {
-                                                        efectivoController
-                                                                .text =
-                                                            totalPedido
-                                                                .toStringAsFixed(
-                                                                    2);
-                                                        _calcularCambio(
-                                                            setState);
-                                                      }
-                                                    });
-                                                  }
-                                                : null,
-                                          ),
-                                          const Text(
-                                            "Efectivo",
-                                            style: TextStyle(
-                                                fontSize: 18,
-                                                fontWeight: FontWeight.bold),
-                                          ),
-                                        ],
-                                      ),
-                                      if (efectivoSeleccionado)
-                                        SizedBox(
-                                          width: 180,
-                                          child: Row(
-                                            crossAxisAlignment:
-                                                CrossAxisAlignment.start,
-                                            children: [
-                                              Column(
-                                                children: [
-                                                  const Text('Exacto',
-                                                      style: TextStyle(
-                                                          fontSize: 18,
-                                                          fontWeight:
-                                                              FontWeight.bold,
-                                                          color: Colors.black)),
-                                                  const SizedBox(
-                                                    height: 17,
-                                                  ),
-                                                  Checkbox(
-                                                    activeColor:
-                                                        AppTheme.primary,
-                                                    value: efectivoCompleto,
-                                                    onChanged:
-                                                        efectivoSeleccionado
-                                                            ? (bool? value) {
-                                                                setState(() {
-                                                                  efectivoCompleto =
-                                                                      value ??
-                                                                          false;
-                                                                  if (efectivoCompleto) {
-                                                                    efectivoController
-                                                                            .text =
-                                                                        totalPedido
-                                                                            .toStringAsFixed(2);
-                                                                    _calcularCambio(
-                                                                        setState);
-                                                                  } else {
-                                                                    efectivoController
-                                                                        .clear();
-                                                                    _calcularCambio(
-                                                                        setState);
-                                                                  }
-                                                                });
-                                                              }
-                                                            : null,
-                                                  ),
-                                                ],
-                                              ),
-                                              const SizedBox(
-                                                width: 5,
-                                              ),
-                                              Expanded(
-                                                child: AppTextField(
-                                                  controller:
-                                                      efectivoController,
-                                                  etiqueta: 'Cantidad',
-                                                  hintText: '0.00',
-                                                  keyboardType:
-                                                      TextInputType.number,
-                                                  onChanged: (value) =>
-                                                      _calcularCambio(setState),
-                                                ),
-                                              ),
-                                            ],
-                                          ),
-                                        ),
-                                    ],
-                                  ),
-                                ),
-                                const SizedBox(height: 10),
-                                // Tarjeta
-                                GestureDetector(
-                                  onTap: () {
-                                    if (_isPaymentOptionEnabled(
-                                        tarjetaSeleccionada)) {
-                                      setState(() {
-                                        tarjetaSeleccionada =
-                                            !tarjetaSeleccionada;
-                                        if (!tarjetaSeleccionada) {
-                                          tarjetaController.clear();
-                                          _calcularCambio(setState);
-                                        }
-                                      });
-                                    }
-                                  },
-                                  child: Row(
-                                    mainAxisAlignment:
-                                        MainAxisAlignment.spaceBetween,
-                                    crossAxisAlignment:
-                                        CrossAxisAlignment.center,
-                                    children: [
-                                      Row(
-                                        children: [
-                                          Checkbox(
-                                            activeColor: AppTheme.primary,
-                                            value: tarjetaSeleccionada,
-                                            onChanged: _isPaymentOptionEnabled(
-                                                    tarjetaSeleccionada)
-                                                ? (bool? value) {
-                                                    setState(() {
-                                                      tarjetaSeleccionada =
-                                                          value ?? false;
-                                                      if (!tarjetaSeleccionada) {
-                                                        tarjetaController
-                                                            .clear();
-                                                        _calcularCambio(
-                                                            setState);
-                                                      }
-                                                    });
-                                                  }
-                                                : null,
-                                          ),
-                                          const Text(
-                                            "Tarjeta",
-                                            style: TextStyle(
-                                                fontSize: 18,
-                                                fontWeight: FontWeight.bold),
-                                          ),
-                                        ],
-                                      ),
-                                      if (tarjetaSeleccionada)
-                                        SizedBox(
-                                          width: 180,
-                                          child: Row(
-                                            crossAxisAlignment:
-                                                CrossAxisAlignment.start,
-                                            children: [
-                                              Column(
-                                                children: [
-                                                  const Text('Exacto',
-                                                      style: TextStyle(
-                                                          fontSize: 18,
-                                                          fontWeight:
-                                                              FontWeight.bold,
-                                                          color: Colors.black)),
-                                                  const SizedBox(
-                                                    height: 17,
-                                                  ),
-                                                  Checkbox(
-                                                    activeColor:
-                                                        AppTheme.primary,
-                                                    value: tarjetaCompleto,
-                                                    onChanged:
-                                                        tarjetaSeleccionada
-                                                            ? (bool? value) {
-                                                                setState(() {
-                                                                  tarjetaCompleto =
-                                                                      value ??
-                                                                          false;
-                                                                  if (tarjetaCompleto) {
-                                                                    tarjetaController
-                                                                            .text =
-                                                                        totalPedido
-                                                                            .toStringAsFixed(2);
-                                                                    _calcularCambio(
-                                                                        setState);
-                                                                  } else {
-                                                                    tarjetaController
-                                                                        .clear();
-                                                                    _calcularCambio(
-                                                                        setState);
-                                                                  }
-                                                                });
-                                                              }
-                                                            : null,
-                                                  ),
-                                                ],
-                                              ),
-                                              const SizedBox(
-                                                width: 5,
-                                              ),
-                                              Expanded(
-                                                child: AppTextField(
-                                                  controller: tarjetaController,
-                                                  etiqueta: 'Cantidad',
-                                                  hintText: '0.00',
-                                                  keyboardType:
-                                                      TextInputType.number,
-                                                  onChanged: (value) {
-                                                    _validarCantidad(setState,
-                                                        tarjetaController);
-                                                  },
-                                                ),
-                                              ),
-                                            ],
-                                          ),
-                                        ),
-                                    ],
-                                  ),
-                                ),
-                                const SizedBox(height: 10),
-                                // Transferencia
-                                GestureDetector(
-                                  onTap: () {
-                                    if (_isPaymentOptionEnabled(
-                                        transferenciaSeleccionada)) {
-                                      setState(() {
-                                        transferenciaSeleccionada =
-                                            !transferenciaSeleccionada;
-                                        if (!transferenciaSeleccionada) {
-                                          transferenciaController.clear();
-                                          _calcularCambio(setState);
-                                        }
-                                      });
-                                    }
-                                  },
-                                  child: Row(
-                                    mainAxisAlignment:
-                                        MainAxisAlignment.spaceBetween,
-                                    crossAxisAlignment:
-                                        CrossAxisAlignment.center,
-                                    children: [
-                                      Row(
-                                        children: [
-                                          Checkbox(
-                                            activeColor: AppTheme.primary,
-                                            value: transferenciaSeleccionada,
-                                            onChanged: _isPaymentOptionEnabled(
-                                                    transferenciaSeleccionada)
-                                                ? (bool? value) {
-                                                    setState(() {
-                                                      transferenciaSeleccionada =
-                                                          value ?? false;
-                                                      if (!transferenciaSeleccionada) {
-                                                        transferenciaController
-                                                            .clear();
-                                                        _calcularCambio(
-                                                            setState);
-                                                      }
-                                                    });
-                                                  }
-                                                : null,
-                                          ),
-                                          const Text(
-                                            "Transferencia",
-                                            style: TextStyle(
-                                                fontSize: 18,
-                                                fontWeight: FontWeight.bold),
-                                          ),
-                                        ],
-                                      ),
-                                      if (transferenciaSeleccionada)
-                                        SizedBox(
-                                          width: 180,
-                                          child: Row(
-                                            crossAxisAlignment:
-                                                CrossAxisAlignment.start,
-                                            children: [
-                                              Column(
-                                                children: [
-                                                  const Text('Exacto',
-                                                      style: TextStyle(
-                                                          fontSize: 18,
-                                                          fontWeight:
-                                                              FontWeight.bold,
-                                                          color: Colors.black)),
-                                                  const SizedBox(
-                                                    height: 17,
-                                                  ),
-                                                  Checkbox(
-                                                    activeColor:
-                                                        AppTheme.primary,
-                                                    value:
-                                                        transferenciaCompleto,
-                                                    onChanged:
-                                                        transferenciaSeleccionada
-                                                            ? (bool? value) {
-                                                                setState(() {
-                                                                  transferenciaCompleto =
-                                                                      value ??
-                                                                          false;
-                                                                  if (transferenciaCompleto) {
-                                                                    transferenciaController
-                                                                            .text =
-                                                                        totalPedido
-                                                                            .toStringAsFixed(2);
-                                                                    _calcularCambio(
-                                                                        setState);
-                                                                  } else {
-                                                                    transferenciaController
-                                                                        .clear();
-                                                                    _calcularCambio(
-                                                                        setState);
-                                                                  }
-                                                                });
-                                                              }
-                                                            : null,
-                                                  ),
-                                                ],
-                                              ),
-                                              const SizedBox(
-                                                width: 5,
-                                              ),
-                                              Expanded(
-                                                child: AppTextField(
-                                                  controller:
-                                                      transferenciaController,
-                                                  etiqueta: 'Cantidad',
-                                                  hintText: '0.00',
-                                                  keyboardType:
-                                                      TextInputType.number,
-                                                  onChanged: (value) {
-                                                    _validarCantidad(setState,
-                                                        transferenciaController);
-                                                  },
-                                                ),
-                                              ),
-                                            ],
-                                          ),
-                                        ),
-                                    ],
-                                  ),
-                                ),
-                                const SizedBox(height: 10),
-                                // Mostrar el total del pedido y la cantidad faltante
-                                Align(
-                                  alignment: Alignment.centerRight,
-                                  child: Column(
-                                      crossAxisAlignment:
-                                          CrossAxisAlignment.end,
-                                      children: [
-                                        Text(
-                                          'Total del pedido: \$${totalPedido.toStringAsFixed(2)}',
-                                          style: const TextStyle(
-                                              fontWeight: FontWeight.bold,
-                                              fontSize: 18),
-                                        ),
-                                        if (faltante > 0)
-                                          Text(
-                                            'Faltante: \$${faltante.toStringAsFixed(2)}',
-                                            style: const TextStyle(
-                                                color: Colors.red,
-                                                fontSize: 18,
-                                                fontWeight: FontWeight.bold),
-                                          )
-                                        else if (cambio > 0)
-                                          Text(
-                                              'Cambio: \$${cambio.toStringAsFixed(2)}',
-                                              style: const TextStyle(
-                                                  color: Colors.green,
-                                                  fontSize: 18,
-                                                  fontWeight: FontWeight.bold)),
-                                      ]),
-                                ),
-                              ],
-                            ),
-                          ),
-                        ),
-                        // Aquí mantenemos los botones fijos
-                        Row(
-                          mainAxisAlignment: MainAxisAlignment.spaceBetween,
+            return AlertDialog(
+              actionsPadding: EdgeInsets.fromLTRB(50, 10, 50, 30),
+              title: const Text(
+                'Finalizar Pedido',
+                style: TextStyle(fontSize: 22, fontWeight: FontWeight.w500),
+              ),
+              content: Container(
+                height: 600,
+                child: Column(
+                  children: [
+                    Expanded(
+                      child: SingleChildScrollView(
+                        child: Column(
                           children: [
-                            TextButton(
-                              child: const Text('Cancelar',
-                                  style: TextStyle(fontSize: 18)),
-                              onPressed: () {
-                                Navigator.of(context).pop(false);
+                            AppTextField(
+                              controller: nombreController,
+                              etiqueta: 'Nombre',
+                              hintText: "Nombre del Cliente",
+                            ),
+                            const SizedBox(height: 10),
+                            AppTextField(
+                              controller: comentarioController,
+                              etiqueta: 'Comentarios (opcional)',
+                              hintText: 'Comentarios',
+                              maxLines: 2,
+                            ),
+                            const SizedBox(height: 10),
+                            Align(
+                              alignment: Alignment.center,
+                              child: Text(
+                                'Métodos de pago',
+                                style: TextStyle(
+                                    fontWeight: FontWeight.bold, fontSize: 20),
+                              ),
+                            ),
+                            const SizedBox(height: 10),
+                            // Efectivo
+                            _buildPaymentMethodRow(
+                              setState,
+                              label: 'Efectivo',
+                              selected: efectivoSeleccionado,
+                              exactSelected: efectivoCompleto,
+                              controller: efectivoController,
+                              onSelected: (value) {
+                                setState(() {
+                                  efectivoSeleccionado = value;
+                                  if (!efectivoSeleccionado) {
+                                    efectivoCompleto = false;
+                                    efectivoController.clear();
+                                  }
+                                  _calcularCambio(setState);
+                                });
                               },
-                              style: ButtonStyle(
-                                  padding: MaterialStatePropertyAll(
-                                      EdgeInsets.fromLTRB(30, 20, 30, 20)),
-                                  backgroundColor:
-                                      MaterialStatePropertyAll(Colors.red),
-                                  foregroundColor: MaterialStatePropertyAll(
-                                      AppTheme.secondary)),
+                              onExactSelected: (value) {
+                                setState(() {
+                                  efectivoCompleto = value;
+                                  if (efectivoCompleto) {
+                                    efectivoController.text =
+                                        totalPedido.toStringAsFixed(2);
+                                    efectivoSeleccionado = true;
+                                    tarjetaSeleccionada = false;
+                                    transferenciaSeleccionada = false;
+                                    tarjetaController.clear();
+                                    transferenciaController.clear();
+                                  } else {
+                                    efectivoController.clear();
+                                  }
+                                  _calcularCambio(setState);
+                                });
+                              },
+                              disableOtherMethods:
+                                  tarjetaCompleto || transferenciaCompleto,
+                              onChangedMonto: () => _calcularCambio(setState),
                             ),
-                            const SizedBox(width: 100),
-                            TextButton(
-                              child: const Text('Guardar',
-                                  style: TextStyle(fontSize: 18)),
-                              onPressed: totalCompletado
-                                  ? () {
-                                      Navigator.of(context).pop(true);
-                                    }
-                                  : null,
-                              style: ButtonStyle(
-                                  padding: MaterialStatePropertyAll(
-                                      EdgeInsets.fromLTRB(30, 20, 30, 20)),
-                                  backgroundColor: MaterialStatePropertyAll(
-                                      totalCompletado
-                                          ? AppTheme.tertiary
-                                          : Colors.grey),
-                                  foregroundColor: MaterialStatePropertyAll(
-                                      AppTheme.quaternary)),
+                            // Tarjeta
+                            _buildPaymentMethodRow(
+                              setState,
+                              label: 'Tarjeta',
+                              selected: tarjetaSeleccionada,
+                              exactSelected: tarjetaCompleto,
+                              controller: tarjetaController,
+                              onSelected: (value) {
+                                setState(() {
+                                  tarjetaSeleccionada = value;
+                                  if (!tarjetaSeleccionada) {
+                                    tarjetaCompleto = false;
+                                    tarjetaController.clear();
+                                  }
+                                  _calcularCambio(setState);
+                                });
+                              },
+                              onExactSelected: (value) {
+                                setState(() {
+                                  tarjetaCompleto = value;
+                                  if (tarjetaCompleto) {
+                                    tarjetaController.text =
+                                        totalPedido.toStringAsFixed(2);
+                                    tarjetaSeleccionada = true;
+                                    efectivoSeleccionado = false;
+                                    transferenciaSeleccionada = false;
+                                    efectivoController.clear();
+                                    transferenciaController.clear();
+                                  } else {
+                                    tarjetaController.clear();
+                                  }
+                                  _calcularCambio(setState);
+                                });
+                              },
+                              disableOtherMethods:
+                                  efectivoCompleto || transferenciaCompleto,
+                              onChangedMonto: () => _calcularCambio(setState),
+                            ),
+                            // Transferencia
+                            _buildPaymentMethodRow(
+                              setState,
+                              label: 'Transferencia',
+                              selected: transferenciaSeleccionada,
+                              exactSelected: transferenciaCompleto,
+                              controller: transferenciaController,
+                              onSelected: (value) {
+                                setState(() {
+                                  transferenciaSeleccionada = value;
+                                  if (!transferenciaSeleccionada) {
+                                    transferenciaCompleto = false;
+                                    transferenciaController.clear();
+                                  }
+                                  _calcularCambio(setState);
+                                });
+                              },
+                              onExactSelected: (value) {
+                                setState(() {
+                                  transferenciaCompleto = value;
+                                  if (transferenciaCompleto) {
+                                    transferenciaController.text =
+                                        totalPedido.toStringAsFixed(2);
+                                    transferenciaSeleccionada = true;
+                                    efectivoSeleccionado = false;
+                                    tarjetaSeleccionada = false;
+                                    efectivoController.clear();
+                                    tarjetaController.clear();
+                                  } else {
+                                    transferenciaController.clear();
+                                  }
+                                  _calcularCambio(setState);
+                                });
+                              },
+                              disableOtherMethods:
+                                  efectivoCompleto || tarjetaCompleto,
+                              onChangedMonto: () => _calcularCambio(setState),
                             ),
                           ],
                         ),
-                      ],
+                      ),
                     ),
+                    // Total y Faltante
+                    Align(
+                      alignment: Alignment.centerRight,
+                      child: Column(
+                        crossAxisAlignment: CrossAxisAlignment.end,
+                        children: [
+                          Text(
+                            'Total del pedido: \$${totalPedido.toStringAsFixed(2)}',
+                            style: const TextStyle(
+                                fontWeight: FontWeight.bold, fontSize: 18),
+                          ),
+                          if (faltante > 0)
+                            Text(
+                              'Faltante: \$${faltante.toStringAsFixed(2)}',
+                              style: const TextStyle(
+                                  color: Colors.red,
+                                  fontSize: 18,
+                                  fontWeight: FontWeight.bold),
+                            )
+                          else if (cambio > 0)
+                            Text(
+                              'Cambio: \$${cambio.toStringAsFixed(2)}',
+                              style: const TextStyle(
+                                  color: Colors.green,
+                                  fontSize: 18,
+                                  fontWeight: FontWeight.bold),
+                            ),
+                        ],
+                      ),
+                    ),
+                  ],
+                ),
+              ),
+              actions: [
+                TextButton(
+                  child: const Text('Cancelar', style: TextStyle(fontSize: 18)),
+                  onPressed: () => Navigator.of(context).pop(false),
+                  style: ButtonStyle(
+                    padding: MaterialStateProperty.all(
+                        EdgeInsets.fromLTRB(30, 20, 30, 20)),
+                    backgroundColor: MaterialStateProperty.all(Colors.red),
+                    foregroundColor:
+                        MaterialStateProperty.all(AppTheme.secondary),
                   ),
-                ));
+                ),
+                const SizedBox(width: 100),
+                TextButton(
+                  child: const Text('Guardar', style: TextStyle(fontSize: 18)),
+                  onPressed: totalCompletado
+                      ? () => Navigator.of(context).pop(true)
+                      : null,
+                  style: ButtonStyle(
+                    padding: MaterialStateProperty.all(
+                        EdgeInsets.fromLTRB(30, 20, 30, 20)),
+                    backgroundColor: MaterialStateProperty.all(
+                        totalCompletado ? AppTheme.tertiary : Colors.grey),
+                    foregroundColor:
+                        MaterialStateProperty.all(AppTheme.quaternary),
+                  ),
+                ),
+              ],
+            );
           },
         );
       },
     );
 
     if (shouldSave ?? false) {
-      prepararPedidoActual(nombreController.text, comentarioController.text);
+      prepararPedidoActual(
+        nombreController.text,
+        comentarioController.text,
+        efectivoController,
+        tarjetaController,
+        transferenciaController,
+      );
     }
   }
 
-  void prepararPedidoActual(String nombreCliente, String comentarios) async {
+  Widget _buildPaymentMethodRow(
+    StateSetter setState, {
+    required String label,
+    required bool selected,
+    required bool exactSelected,
+    required TextEditingController controller,
+    required Function(bool) onSelected,
+    required Function(bool) onExactSelected,
+    required bool disableOtherMethods,
+    required Function() onChangedMonto,
+  }) {
+    return Row(
+      mainAxisAlignment: MainAxisAlignment.spaceBetween,
+      crossAxisAlignment: CrossAxisAlignment.center,
+      children: [
+        Row(
+          children: [
+            Checkbox(
+              activeColor: AppTheme.primary,
+              value: selected,
+              onChanged: disableOtherMethods
+                  ? null
+                  : (value) {
+                      onSelected(value ?? false);
+                    },
+            ),
+            Text(
+              label,
+              style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
+            ),
+          ],
+        ),
+        SizedBox(
+          width: 180,
+          child: Row(
+            crossAxisAlignment: CrossAxisAlignment.start,
+            children: [
+              Column(
+                children: [
+                  const Text(
+                    'Exacto',
+                    style: TextStyle(
+                        fontSize: 18,
+                        fontWeight: FontWeight.bold,
+                        color: Colors.black),
+                  ),
+                  const SizedBox(height: 17),
+                  Checkbox(
+                    activeColor: AppTheme.primary,
+                    value: exactSelected,
+                    onChanged: !disableOtherMethods
+                        ? (value) {
+                            onExactSelected(value ?? false);
+                            if (value == true) {
+                              setState(() {
+                                disableOtherMethods = true;
+                              });
+                            }
+                          }
+                        : null,
+                  ),
+                ],
+              ),
+              const SizedBox(width: 5),
+              Expanded(
+                child: AppTextField(
+                  controller: controller,
+                  enabled: selected,
+                  etiqueta: 'Cantidad',
+                  hintText: '0.00',
+                  keyboardType: TextInputType.number,
+                  onChanged: (_) {
+                    onChangedMonto();
+                  },
+                ),
+              ),
+            ],
+          ),
+        ),
+      ],
+    );
+  }
+
+  void prepararPedidoActual(
+    String nombreCliente,
+    String comentarios,
+    TextEditingController efectivoController,
+    TextEditingController tarjetaController,
+    TextEditingController transferenciaController,
+  ) async {
     String now = DateTime.now().toUtc().toIso8601String();
 
+    double cantEfectivo = efectivoSeleccionado
+        ? double.tryParse(efectivoController.text) ?? 0
+        : 0;
+    double cantTarjeta =
+        tarjetaSeleccionada ? double.tryParse(tarjetaController.text) ?? 0 : 0;
+    double cantTransferencia = transferenciaSeleccionada
+        ? double.tryParse(transferenciaController.text) ?? 0
+        : 0;
+
     Pedido nuevoPedido = Pedido(
       peticion: now,
       nombreCliente: nombreCliente,
       comentarios: comentarios,
-      estatus: "NUEVO",
+      estatus: "TERMINADO",
       totalPedido: totalPedido,
       descuento: pedidoActual?.descuento,
       tipoPago: _obtenerTipoPago(),
-      cantEfectivo:
-          efectivoSeleccionado ? double.tryParse(efectivoController.text) : 0,
-      cantTarjeta:
-          tarjetaSeleccionada ? double.tryParse(tarjetaController.text) : 0,
-      cantTransferencia: transferenciaSeleccionada
-          ? double.tryParse(transferenciaController.text)
-          : 0,
+      cantEfectivo: cantEfectivo,
+      cantTarjeta: cantTarjeta,
+      cantTransferencia: cantTransferencia,
     );
 
     List<PedidoProducto> listaPedidoProducto = carrito.map((item) {
       List<PedidoProductoTopping> selectedToppings = [];
-
       item.selectedToppings.forEach((categoryId, selectedToppingIds) {
         for (int toppingId in selectedToppingIds) {
-          selectedToppings.add(PedidoProductoTopping(
-            idTopping: toppingId,
-          ));
+          selectedToppings.add(PedidoProductoTopping(idTopping: toppingId));
         }
       });
-
       return PedidoProducto(
         idProducto: item.producto.id,
         producto: item.producto,
@@ -794,7 +582,7 @@ class _PedidoFormState extends State<PedidoForm> {
     if (efectivoSeleccionado) tiposPago.add('Efectivo');
     if (tarjetaSeleccionada) tiposPago.add('Tarjeta');
     if (transferenciaSeleccionada) tiposPago.add('Transferencia');
-    return tiposPago.join(',');
+    return tiposPago.isNotEmpty ? tiposPago.join(',') : 'No Definido';
   }
 
   void _limpiarBusqueda() async {