瀏覽代碼

13208: GRID PEDIDOS de mesa: Informar en una columna la MESA

ElPoteito 6 月之前
父節點
當前提交
5d1bfd03e0

+ 7 - 0
lib/models/pedido_model.dart

@@ -1,3 +1,4 @@
+import 'package:conalep_pos/models/mesa_model.dart';
 import 'package:intl/intl.dart';
 
 import 'basico_model.dart';
@@ -25,6 +26,7 @@ class Pedido extends Basico {
   double? cantTransferencia;
   List<PedidoProducto> productos = [];
   int? idWeb;
+  Mesa? mesa;
 
   String? sincronizado;
 
@@ -50,6 +52,7 @@ class Pedido extends Basico {
     this.cantTransferencia,
     this.productos = const [],
     this.idWeb,
+    this.mesa,
     this.sincronizado,
   });
 
@@ -75,6 +78,7 @@ class Pedido extends Basico {
       'cantEfectivo': cantEfectivo,
       'cantTarjeta': cantTarjeta,
       'cantTransferencia': cantTransferencia,
+      'mesa': mesa,
       'sincronizado': sincronizado,
     }..addAll(super.toJson());
   }
@@ -95,6 +99,7 @@ class Pedido extends Basico {
       'cantEfectivo': cantEfectivo,
       'cantTarjeta': cantTarjeta,
       'cantTransferencia': cantTransferencia,
+      'mesa': mesa,
       'productos': productos.map((producto) => producto.toApi()).toList(),
     };
     Map<String, dynamic> basicoMap = super.toJson();
@@ -128,6 +133,8 @@ class Pedido extends Basico {
     cantTransferencia = Basico.parseDouble(json['cantTransferencia']);
     idWeb = Basico.parseInt(json['idWeb']);
     sincronizado = Basico.parseString(json['sincronizado']);
+    mesa =
+        json["mesa"] == null ? null : Mesa.fromJson(json["mesa"]);
 
     List<PedidoProducto> _productos = [];
     if (json["productos"] != null && (json["productos"] as List).isNotEmpty) {

+ 7 - 5
lib/services/repo_service.dart

@@ -557,11 +557,13 @@ class RepoService<T> {
   Future<List<Pedido>> obtenerMesaPedidosPaginados(
       int limit, int offset) async {
     Database? dbClient = await db;
-    List<Map<String, dynamic>> result = await dbClient!.query('Pedido',
-        limit: limit,
-        offset: offset,
-        orderBy: 'id DESC',
-        where: 'idMesa IS NOT NULL');
+    List<Map<String, dynamic>> result = await dbClient!.query(
+      'Pedido',
+      limit: limit,
+      offset: offset,
+      orderBy: 'id DESC',
+      where: 'idMesa IS NOT NULL',
+    );
     return result.map((map) => Pedido.fromJson(map)).toList();
   }
 

+ 5 - 0
lib/viewmodels/mesa_view_model.dart

@@ -65,6 +65,11 @@ class MesaViewModel extends ChangeNotifier {
     notifyListeners();
   }
 
+  Mesa fetchLocalById({required int? idMesa}) {
+    final mesa = mesas.firstWhere((mesa) => mesa.id == idMesa, orElse: () => Mesa(id: 0, nombre: 'Mesa desconocida'));
+    return mesa;
+  }
+
   Future<void> addMesa(Mesa mesa) async {
     await RepoService().guardar(mesa);
     fetchLocalAll();

+ 1 - 1
lib/views/pedido/pedido_screen.dart

@@ -609,7 +609,7 @@ class _PedidoScreenState extends State<PedidoScreen> {
   }
 
   String _formatDateTime(String? dateTimeString) {
-    if (dateTimeString == null) return "Sin fecha";
+    if (dateTimeString == null || dateTimeString == "") return "Sin fecha";
 
     DateTime parsedDate = DateTime.parse(dateTimeString);
 

+ 6 - 0
lib/views/pedido_mesa/pedido_mesa_screen.dart

@@ -191,6 +191,10 @@ class _PedidoMesaScreenState extends State<PedidoMesaScreen> {
           Text(item.peticion ?? "Sin fecha"),
           onTap: () => go(item),
         ),
+        DataCell(
+          Text(Provider.of<MesaViewModel>(context, listen: false).fetchLocalById(idMesa: item.idMesa).nombre.toString()),
+          onTap: () => go(item),
+        ),
         /* DataCell(
           Text(item.id.toString()),
           onTap: () => go(item),
@@ -325,6 +329,8 @@ class _PedidoMesaScreenState extends State<PedidoMesaScreen> {
                                     DataColumn(label: Text(" ", style: estilo)),
                                     DataColumn(
                                         label: Text("FECHA", style: estilo)),
+                                    DataColumn(
+                                        label: Text("MESA", style: estilo)),
                                     /* DataColumn(
                                         label: Text("ID", style: estilo)), */
                                     DataColumn(