Explorar el Código

Permiso de administracion, cancelar pedido y ver reportes

OscarGil03 hace 6 meses
padre
commit
47472236c7

+ 2 - 0
lib/models/usuario_model.dart

@@ -27,6 +27,8 @@ class Usuario extends Basico {
   static const VER_DESC_APP = 'VER_DESC_APP';
   static const VER_SUCURSALES = 'VER_SUCURSALES';
   static const VER_ADMIN = 'VER_ADMIN';
+  static const CANCELAR_PEDIDO = 'CANCELAR_PEDIDO';
+  static const VER_REPORTE = 'VER_REPORTE';
 
   Usuario({
     super.id,

+ 9 - 2
lib/viewmodels/pedido_view_model.dart

@@ -226,8 +226,15 @@ class PedidoViewModel extends ChangeNotifier {
 
   Future<void> cancelarPedido(int idPedido) async {
     var db = await RepoService().db;
-    await db?.update('Pedido', {'estatus': 'CANCELADO'},
-        where: 'id = ?', whereArgs: [idPedido]);
+    await db?.update(
+      'Pedido',
+      {
+        'estatus': 'CANCELADO',
+        'sincronizado': null,
+      },
+      where: 'id = ?',
+      whereArgs: [idPedido],
+    );
     fetchLocalPedidosForScreen();
   }
 

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

@@ -736,7 +736,7 @@ class _PedidoFormState extends State<PedidoForm> {
       peticion: now,
       nombreCliente: nombreCliente,
       comentarios: comentarios,
-      estatus: "NUEVO",
+      estatus: "TERMINADO",
       totalPedido: totalPedido,
       descuento: pedidoActual?.descuento,
       tipoPago: _obtenerTipoPago(),

+ 75 - 70
lib/views/pedido/pedido_screen.dart

@@ -98,6 +98,8 @@ class _PedidoScreenState extends State<PedidoScreen> {
     final double? columnSpacing = isMobile ? null : 0;
     TextStyle estilo = const TextStyle(fontWeight: FontWeight.bold);
     List<DataRow> registros = [];
+    final permisoViewModel = Provider.of<PermisoViewModel>(context);
+    List<String> userPermisos = permisoViewModel.userPermisos;
     for (Pedido item in pvm.pedidos) {
       final sincronizadoStatus =
           item.sincronizado == null || item.sincronizado!.isEmpty
@@ -113,72 +115,74 @@ class _PedidoScreenState extends State<PedidoScreen> {
                 child: const Text('Detalle'),
                 onTap: () => go(item),
               ),
-              PopupMenuItem(
-                child: const Text('Cancelar Pedido'),
-                onTap: () async {
-                  bool confirmado = await showDialog<bool>(
-                        context: context,
-                        builder: (context) {
-                          return AlertDialog(
-                            title: const Text("Cancelar Pedido",
-                                style: TextStyle(
-                                    fontWeight: FontWeight.w500, fontSize: 22)),
-                            content: const Text(
-                                '¿Estás seguro de que deseas cancelar este pedido?',
-                                style: TextStyle(fontSize: 18)),
-                            actions: [
-                              Row(
-                                mainAxisAlignment:
-                                    MainAxisAlignment.spaceBetween,
-                                children: [
-                                  TextButton(
-                                    onPressed: () =>
-                                        Navigator.of(context).pop(false),
-                                    child: const Text('No',
-                                        style: TextStyle(fontSize: 18)),
-                                    style: ButtonStyle(
-                                        padding: MaterialStatePropertyAll(
-                                            EdgeInsets.fromLTRB(
-                                                20, 10, 20, 10)),
-                                        backgroundColor:
-                                            MaterialStatePropertyAll(
-                                                Colors.red),
-                                        foregroundColor:
-                                            MaterialStatePropertyAll(
-                                                AppTheme.secondary)),
-                                  ),
-                                  TextButton(
-                                    onPressed: () =>
-                                        Navigator.of(context).pop(true),
-                                    child: const Text('Sí',
-                                        style: TextStyle(fontSize: 18)),
-                                    style: ButtonStyle(
-                                        padding: MaterialStatePropertyAll(
-                                            EdgeInsets.fromLTRB(
-                                                20, 10, 20, 10)),
-                                        backgroundColor:
-                                            MaterialStatePropertyAll(
-                                                AppTheme.tertiary),
-                                        foregroundColor:
-                                            MaterialStatePropertyAll(
-                                                AppTheme.quaternary)),
-                                  ),
-                                ],
-                              )
-                            ],
-                          );
-                        },
-                      ) ??
-                      false;
+              if (userPermisos.contains(Usuario.CANCELAR_PEDIDO))
+                PopupMenuItem(
+                  child: const Text('Cancelar Pedido'),
+                  onTap: () async {
+                    bool confirmado = await showDialog<bool>(
+                          context: context,
+                          builder: (context) {
+                            return AlertDialog(
+                              title: const Text("Cancelar Pedido",
+                                  style: TextStyle(
+                                      fontWeight: FontWeight.w500,
+                                      fontSize: 22)),
+                              content: const Text(
+                                  '¿Estás seguro de que deseas cancelar este pedido?',
+                                  style: TextStyle(fontSize: 18)),
+                              actions: [
+                                Row(
+                                  mainAxisAlignment:
+                                      MainAxisAlignment.spaceBetween,
+                                  children: [
+                                    TextButton(
+                                      onPressed: () =>
+                                          Navigator.of(context).pop(false),
+                                      child: const Text('No',
+                                          style: TextStyle(fontSize: 18)),
+                                      style: ButtonStyle(
+                                          padding: MaterialStatePropertyAll(
+                                              EdgeInsets.fromLTRB(
+                                                  20, 10, 20, 10)),
+                                          backgroundColor:
+                                              MaterialStatePropertyAll(
+                                                  Colors.red),
+                                          foregroundColor:
+                                              MaterialStatePropertyAll(
+                                                  AppTheme.secondary)),
+                                    ),
+                                    TextButton(
+                                      onPressed: () =>
+                                          Navigator.of(context).pop(true),
+                                      child: const Text('Sí',
+                                          style: TextStyle(fontSize: 18)),
+                                      style: ButtonStyle(
+                                          padding: MaterialStatePropertyAll(
+                                              EdgeInsets.fromLTRB(
+                                                  20, 10, 20, 10)),
+                                          backgroundColor:
+                                              MaterialStatePropertyAll(
+                                                  AppTheme.tertiary),
+                                          foregroundColor:
+                                              MaterialStatePropertyAll(
+                                                  AppTheme.quaternary)),
+                                    ),
+                                  ],
+                                )
+                              ],
+                            );
+                          },
+                        ) ??
+                        false;
 
-                  if (confirmado) {
-                    await Provider.of<PedidoViewModel>(context, listen: false)
-                        .cancelarPedido(item.id);
-                    ScaffoldMessenger.of(context).showSnackBar(SnackBar(
-                        content: Text("Pedido cancelado correctamente")));
-                  }
-                },
-              )
+                    if (confirmado) {
+                      await Provider.of<PedidoViewModel>(context, listen: false)
+                          .cancelarPedido(item.id);
+                      ScaffoldMessenger.of(context).showSnackBar(SnackBar(
+                          content: Text("Pedido cancelado correctamente")));
+                    }
+                  },
+                )
             ],
             icon: const Icon(Icons.more_vert),
           )
@@ -218,11 +222,12 @@ class _PedidoScreenState extends State<PedidoScreen> {
                 color: AppTheme.secondary, fontWeight: FontWeight.w500),
           ),
           actions: <Widget>[
-            IconButton(
-              icon: const Icon(Icons.save_alt),
-              onPressed: exportCSV,
-              tooltip: 'Exportar a CSV',
-            ),
+            if (userPermisos.contains(Usuario.VER_REPORTE))
+              IconButton(
+                icon: const Icon(Icons.save_alt),
+                onPressed: exportCSV,
+                tooltip: 'Exportar a CSV',
+              ),
           ],
           iconTheme: IconThemeData(color: AppTheme.secondary)),
       body: Stack(

+ 36 - 34
lib/widgets/app_drawer.dart

@@ -50,7 +50,7 @@ class AppDrawer extends StatelessWidget {
   @override
   Widget build(BuildContext context) {
     final permisoViewModel = Provider.of<PermisoViewModel>(context);
-    final userPermisos = permisoViewModel.userPermisos;
+    List<String> userPermisos = permisoViewModel.userPermisos;
     return Drawer(
       surfaceTintColor: Colors.white,
       backgroundColor: Colors.white,
@@ -136,49 +136,51 @@ class AppDrawer extends StatelessWidget {
                     ),
                   },
                 ),
-                ExpansionTile(
-                  leading: circulo(const Icon(Icons.admin_panel_settings)),
-                  title: const Text('Administración'),
-                  children: [
-                    ListTile(
-                      leading: circulo(const Icon(Icons.discount)),
-                      title: const Text('Descuentos'),
-                      onTap: () => {
-                        Navigator.pop(context),
-                        Navigator.of(context).push(
-                          MaterialPageRoute(
-                            builder: (context) => DescuentoScreen(),
-                          ),
-                        ),
-                      },
-                    ),
-                    ListTile(
-                      leading: circulo(const Icon(Icons.discount)),
-                      title: const Text('Variables'),
-                      onTap: () => {
-                        Navigator.pop(context),
-                        Navigator.of(context).push(
-                          MaterialPageRoute(
-                            builder: (context) => VariablesScreen(),
+                if (userPermisos.contains(Usuario.VER_ADMIN))
+                  ExpansionTile(
+                    leading: circulo(const Icon(Icons.admin_panel_settings)),
+                    title: const Text('Administración'),
+                    children: [
+                      ListTile(
+                        leading: circulo(const Icon(Icons.discount)),
+                        title: const Text('Descuentos'),
+                        onTap: () => {
+                          Navigator.pop(context),
+                          Navigator.of(context).push(
+                            MaterialPageRoute(
+                              builder: (context) => DescuentoScreen(),
+                            ),
                           ),
-                        ),
-                      },
-                    ),
-                    if (userPermisos.contains(Usuario.VER_SUCURSALES))
+                        },
+                      ),
                       ListTile(
-                        leading: circulo(const Icon(Icons.storefront_outlined)),
-                        title: const Text('Sucursales'),
+                        leading: circulo(const Icon(Icons.discount)),
+                        title: const Text('Variables'),
                         onTap: () => {
                           Navigator.pop(context),
                           Navigator.of(context).push(
                             MaterialPageRoute(
-                              builder: (context) => SucursalesPage(),
+                              builder: (context) => VariablesScreen(),
                             ),
                           ),
                         },
                       ),
-                  ],
-                ),
+                      if (userPermisos.contains(Usuario.VER_SUCURSALES))
+                        ListTile(
+                          leading:
+                              circulo(const Icon(Icons.storefront_outlined)),
+                          title: const Text('Sucursales'),
+                          onTap: () => {
+                            Navigator.pop(context),
+                            Navigator.of(context).push(
+                              MaterialPageRoute(
+                                builder: (context) => SucursalesPage(),
+                              ),
+                            ),
+                          },
+                        ),
+                    ],
+                  ),
                 ListTile(
                   leading: const Icon(Icons.logout),
                   title: const Text('Cerrar sesión'),