Procházet zdrojové kódy

Modelo de EstadoPEdiod

c90Beretta před 2 měsíci
rodič
revize
5e04d30b87

+ 9 - 0
lib/core/models/mesa_model.dart

@@ -1,12 +1,20 @@
 import '../models/basico_model.dart';
 import '../services/services.dart';
 
+enum EstadoPedido {
+  disponible,
+  surtida,
+  preparacion,
+  cobrado,
+}
+
 class Mesa extends Basico {
   int? idSucursal;
   String? nombre;
   String? clave;
   String? posicion;
   bool? activa;
+  EstadoPedido? estado;
 
   Mesa(
       {super.id,
@@ -16,6 +24,7 @@ class Mesa extends Basico {
       this.clave,
       this.posicion,
       this.activa,
+      this.estado = EstadoPedido.disponible,
       super.creado,
       super.modificado,
       super.eliminado});

+ 37 - 37
lib/core/models/mesas_model.dart

@@ -1,43 +1,43 @@
-import 'package:flutter/material.dart';
-import 'package:turquessa_mesas_hoster/core/models/basico_model.dart';
-import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
+// import 'package:flutter/material.dart';
+// import 'package:turquessa_mesas_hoster/core/models/basico_model.dart';
+// import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
 
-enum EstadoPedido {
-  disponible,
-  surtida,
-  preparacion,
-  cobrado,
-}
+// enum EstadoPedido {
+//   disponible,
+//   surtida,
+//   preparacion,
+//   cobrado,
+// }
 
-// class Mesas extends Basico {
-//   String? nombre;
-//   EstadoPedido? tipo;
-//   String? folio;
+// // class Mesas extends Basico {
+// //   String? nombre;
+// //   EstadoPedido? tipo;
+// //   String? folio;
 
-//   Mesas({
-//     this.nombre,
-//     this.tipo,
-//     this.folio,
-//   });
+// //   Mesas({
+// //     this.nombre,
+// //     this.tipo,
+// //     this.folio,
+// //   });
 
-//   @override
-//   Map<String, dynamic> toJson() {
-//     return {
-//       'nombre': nombre ?? '',
-//       'tipo': tipo.toString(),
-//       'folio': folio ?? '',
-//     }..addAll(super.toJson());
-//   }
-// }
+// //   @override
+// //   Map<String, dynamic> toJson() {
+// //     return {
+// //       'nombre': nombre ?? '',
+// //       'tipo': tipo.toString(),
+// //       'folio': folio ?? '',
+// //     }..addAll(super.toJson());
+// //   }
+// // }
 
-class TableItem extends Basico {
-  final int id;
-  final String name;
-  final EstadoPedido status;
+// class TableItem extends Basico {
+//   final int id;
+//   final String name;
+//   final EstadoPedido status;
 
-  TableItem({
-    required this.id,
-    required this.name,
-    required this.status,
-  });
-}
+//   TableItem({
+//     required this.id,
+//     required this.name,
+//     required this.status,
+//   });
+// }

+ 19 - 0
lib/mvvm/viewmodels/mesa_view_model.dart

@@ -140,6 +140,25 @@ class MesaViewModel extends ChangeNotifier {
 
     return false;
   }
+  // TODO: Implementar CambiarEstadoMesa, actualizar modelo
+  // void CambiarEstadoPedidoMesa(Mesa mesa) async {
+  //   var db = await DatabaseService().db;
+  //   await db!.update(
+  //     'Mesa',
+  //     {'estado': mesa.estado.toString()},
+  //     where: 'id = ?',
+  //     whereArgs: [mesa.id],
+  //   );
+  //   fetchLocalAll();
+  // }
+
+  //todo: Cambio de estado de mesa provisional
+  void CambiarEstadoPedidoMesa(EstadoPedido nuevoestado) {
+    if (_selectedMesa != null) {
+      _selectedMesa!.estado = nuevoestado;
+      notifyListeners();
+    }
+  }
 
   Future<bool> sincronizarMesas() async {
     String? claveSucursal =

+ 84 - 2
lib/mvvm/views/home/home_screen.dart

@@ -2,8 +2,8 @@ import 'package:flutter/material.dart';
 import 'package:provider/provider.dart';
 import 'package:turquessa_mesas_hoster/core/models/mesa_model.dart';
 import 'package:turquessa_mesas_hoster/utils/widgets/custom_appbar.dart';
-import 'package:turquessa_mesas_hoster/core/models/mesas_model.dart';
 
+import '../../../utils/widgets/ordenes_card.dart';
 import '../../viewmodels/viewmodels.dart';
 
 class HomeScreen extends StatefulWidget {
@@ -117,9 +117,13 @@ class Formulario extends State<HomeScreen> {
                     ],
                   ),
                   child: TablaDetalles(
+                      status: EstadoPedido.disponible,
                       table: mesaViewModel.selectedMesa ??
                           Mesa(
-                              activa: false, id: 0, nombre: 'Mesa sin nombre')),
+                              activa: false,
+                              id: 0,
+                              nombre: 'Mesa sin nombre',
+                              estado: EstadoPedido.disponible)),
                 )),
         ],
       ),
@@ -161,10 +165,12 @@ class TableCard extends StatelessWidget {
 
 class TablaDetalles extends StatelessWidget {
   final Mesa table;
+  final EstadoPedido status;
 
   const TablaDetalles({
     Key? key,
     required this.table,
+    required this.status,
   }) : super(key: key);
 
   @override
@@ -231,6 +237,35 @@ class TablaDetalles extends StatelessWidget {
                   style: const TextStyle(fontSize: 16),
                 ),
                 const SizedBox(height: 8),
+                SizedBox(
+                  height: 50,
+                  child: Row(
+                    children: [
+                      const Text('Estado: '),
+                      Text(
+                        status.toString().split('.').last,
+                        style: const TextStyle(
+                          fontWeight: FontWeight.bold,
+                          color: Colors.blue,
+                        ),
+                      ),
+                    ],
+                  ),
+                ),
+                const SizedBox(height: 8),
+                // Row(
+                //   children: [
+                //     SizedBox(
+                //       height: 80,
+                //       width: 80,
+                //       child: IconDataByStatus(status: status),
+                //     )
+                //   ],
+                // ),
+                // //  OrdenMesaCard(mesaNumero: table.nombre!, ordenNumero: table.posicion!,),
+                // Container(
+                //     // child: OrdenesScreen(),
+                //     )
               ],
             ),
           ),
@@ -239,3 +274,50 @@ class TablaDetalles extends StatelessWidget {
     );
   }
 }
+
+class IconDataByStatus extends StatelessWidget {
+  final EstadoPedido status;
+  const IconDataByStatus({Key? key, required this.status});
+
+  @override
+  Widget build(BuildContext context) {
+    switch (status) {
+      case EstadoPedido.disponible:
+        return IconButton(
+          onPressed: () {
+            final mesaViewModel =
+                Provider.of<MesaViewModel>(context, listen: false);
+            mesaViewModel.CambiarEstadoPedidoMesa(EstadoPedido.preparacion);
+          },
+          style: ButtonStyle(
+            backgroundColor: MaterialStateProperty.all(
+                const Color.fromARGB(255, 220, 252, 232)),
+          ),
+          icon: const Icon(Icons.table_restaurant_rounded, color: Colors.green),
+        );
+      case EstadoPedido.surtida:
+        return IconButton(
+          onPressed: () {},
+          icon: const Icon(Icons.coffee_rounded,
+              color: Color.fromARGB(255, 220, 234, 254)),
+        );
+      case EstadoPedido.preparacion:
+        return IconButton(
+          onPressed: () {},
+          icon: const Icon(Icons.kitchen_rounded,
+              color: Color.fromARGB(255, 243, 232, 255)),
+        );
+      case EstadoPedido.cobrado:
+        return IconButton(
+          onPressed: () {},
+          icon: const Icon(Icons.money_rounded,
+              color: Color.fromARGB(255, 255, 238, 213)),
+        );
+      default:
+        return IconButton(
+          onPressed: () {},
+          icon: const Icon(Icons.check_circle, color: Colors.grey),
+        );
+    }
+  }
+}

+ 220 - 0
lib/utils/widgets/ordenes_card.dart

@@ -0,0 +1,220 @@
+import 'package:flutter/material.dart';
+
+class OrdenMesaCard extends StatelessWidget {
+  final String mesaNumero;
+  final String ordenNumero;
+  final List<OrdenItem> items;
+  final bool tieneItemsListos;
+  final VoidCallback onLiberarOrden;
+
+  const OrdenMesaCard({
+    Key? key,
+    required this.mesaNumero,
+    required this.ordenNumero,
+    required this.items,
+    this.tieneItemsListos = false,
+    required this.onLiberarOrden,
+  }) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    return Card(
+      margin: const EdgeInsets.all(8.0),
+      child: Column(
+        crossAxisAlignment: CrossAxisAlignment.stretch,
+        mainAxisSize: MainAxisSize.min,
+        children: [
+          // Encabezado de la mesa
+          Padding(
+            padding: const EdgeInsets.all(16.0),
+            child: Row(
+              mainAxisAlignment: MainAxisAlignment.spaceBetween,
+              children: [
+                Text(
+                  'Mesa $mesaNumero',
+                  style: const TextStyle(
+                    fontSize: 18,
+                    fontWeight: FontWeight.bold,
+                  ),
+                ),
+                Row(
+                  children: [
+                    const Icon(Icons.access_time, size: 16),
+                    const SizedBox(width: 4),
+                    Text('15:03'),
+                  ],
+                ),
+              ],
+            ),
+          ),
+          const Divider(height: 1),
+          // Número de orden
+          Padding(
+            padding:
+                const EdgeInsets.symmetric(horizontal: 16.0, vertical: 8.0),
+            child: Text(
+              'Orden #$ordenNumero',
+              style: TextStyle(
+                color: Colors.grey[600],
+                fontSize: 14,
+              ),
+            ),
+          ),
+          // Lista de items
+          ListView.builder(
+            shrinkWrap: true,
+            physics: const NeverScrollableScrollPhysics(),
+            itemCount: items.length,
+            itemBuilder: (context, index) {
+              final item = items[index];
+              return ListTile(
+                contentPadding: const EdgeInsets.symmetric(horizontal: 16.0),
+                leading: Text(
+                  '${item.cantidad}x',
+                  style: const TextStyle(
+                    fontSize: 16,
+                    fontWeight: FontWeight.bold,
+                  ),
+                ),
+                title: Text(
+                  item.nombre,
+                  style: const TextStyle(
+                    fontSize: 16,
+                    fontWeight: FontWeight.w500,
+                  ),
+                ),
+                subtitle: Column(
+                  crossAxisAlignment: CrossAxisAlignment.start,
+                  children: [
+                    Text(
+                      item.descripcion,
+                      style: TextStyle(
+                        color: Colors.grey[600],
+                        fontSize: 14,
+                      ),
+                    ),
+                    if (item.notas != null)
+                      Text(
+                        item.notas!,
+                        style: TextStyle(
+                          color: Colors.red[400],
+                          fontSize: 14,
+                        ),
+                      ),
+                  ],
+                ),
+                trailing: item.isListo
+                    ? Container(
+                        padding: const EdgeInsets.symmetric(
+                            horizontal: 12, vertical: 6),
+                        decoration: BoxDecoration(
+                          color: Colors.black,
+                          borderRadius: BorderRadius.circular(20),
+                        ),
+                        child: const Text(
+                          'Listo',
+                          style: TextStyle(
+                            color: Colors.white,
+                            fontSize: 12,
+                          ),
+                        ),
+                      )
+                    : const Icon(Icons.chevron_right),
+              );
+            },
+          ),
+
+          Padding(
+            padding: const EdgeInsets.all(16.0),
+            child: ElevatedButton(
+              onPressed: onLiberarOrden,
+              style: ElevatedButton.styleFrom(
+                backgroundColor: const Color(0xFF4CAF50),
+                padding: const EdgeInsets.symmetric(vertical: 16),
+                shape: RoundedRectangleBorder(
+                  borderRadius: BorderRadius.circular(8),
+                ),
+              ),
+              child: const Text(
+                'Liberar Orden Completa',
+                style: TextStyle(
+                  color: Colors.white,
+                  fontSize: 16,
+                  fontWeight: FontWeight.w500,
+                ),
+              ),
+            ),
+          ),
+        ],
+      ),
+    );
+  }
+}
+
+class OrdenItem {
+  final int cantidad;
+  final String nombre;
+  final String descripcion;
+  final String? notas;
+  final bool isListo;
+
+  OrdenItem({
+    required this.cantidad,
+    required this.nombre,
+    required this.descripcion,
+    this.notas,
+    this.isListo = false,
+  });
+}
+
+class OrdenesScreen extends StatelessWidget {
+  const OrdenesScreen({Key? key}) : super(key: key);
+
+  @override
+  Widget build(BuildContext context) {
+    final items = [
+      OrdenItem(
+        cantidad: 1,
+        nombre: 'Chilaquiles Verdes',
+        descripcion: 'Tortillas fritas en salsa verde con pollo',
+        notas: 'Sin cebolla ni tomate',
+      ),
+      OrdenItem(
+        cantidad: 2,
+        nombre: 'Huevos Rancheros',
+        descripcion: 'Huevos fritos sobre tortilla con salsa roja',
+      ),
+    ];
+
+    final items2 = [
+      OrdenItem(
+        cantidad: 1,
+        nombre: 'Club Sandwich',
+        descripcion: 'Sándwich triple con pollo, jamón y tocino',
+        isListo: true,
+      ),
+    ];
+
+    return ListView(
+      children: [
+        OrdenMesaCard(
+          mesaNumero: '5',
+          ordenNumero: 'A-123',
+          items: items,
+          onLiberarOrden: () {
+            // Implementar lógica para liberar orden
+          },
+        ),
+        OrdenMesaCard(
+          mesaNumero: '3',
+          ordenNumero: 'A-124',
+          items: items2,
+          tieneItemsListos: true,
+          onLiberarOrden: () {
+            // Implementar lógica para liberar orden
+          },
+        ),
+      ],
+    );
+  }
+}