|
@@ -9,19 +9,23 @@ import 'services.dart';
|
|
import '../views/producto/producto_imagen.dart';
|
|
import '../views/producto/producto_imagen.dart';
|
|
|
|
|
|
class RepoService<T> {
|
|
class RepoService<T> {
|
|
- static int dbVersion = 19;
|
|
|
|
- static String dbName = 'joshipos026.db';
|
|
|
|
|
|
+ static int dbVersion = 21;
|
|
|
|
+ static String dbName = 'posTurquessa.db';
|
|
static const String id = Basico.identificadorWeb;
|
|
static const String id = Basico.identificadorWeb;
|
|
static const String idLocal = Basico.identificadorLocal;
|
|
static const String idLocal = Basico.identificadorLocal;
|
|
static Database? _db;
|
|
static Database? _db;
|
|
final Map<String, dynamic> contexto = {
|
|
final Map<String, dynamic> contexto = {
|
|
'Categoria': CategoriaProducto(),
|
|
'Categoria': CategoriaProducto(),
|
|
'Producto': Producto(),
|
|
'Producto': Producto(),
|
|
|
|
+ 'ProductoTopping': ProductoTopping(),
|
|
'Pedido': Pedido(productos: []),
|
|
'Pedido': Pedido(productos: []),
|
|
'PedidoProducto': PedidoProducto(),
|
|
'PedidoProducto': PedidoProducto(),
|
|
- 'Gasto': Gasto(),
|
|
|
|
- 'Deposito': Deposito(),
|
|
|
|
- 'CorteCaja': CorteCaja(),
|
|
|
|
|
|
+ 'PedidoProductoTopping': PedidoProductoTopping(),
|
|
|
|
+ 'Sucursal': Sucursal(),
|
|
|
|
+ 'Usuario': Usuario(),
|
|
|
|
+ 'UsuarioPermiso': UsuarioPermiso(),
|
|
|
|
+ 'Variable': Variable(),
|
|
|
|
+ 'Descuento': Descuento(),
|
|
};
|
|
};
|
|
|
|
|
|
Future<Database?> get db async {
|
|
Future<Database?> get db async {
|
|
@@ -66,73 +70,8 @@ class RepoService<T> {
|
|
});
|
|
});
|
|
sql += ")";
|
|
sql += ")";
|
|
await db.execute(sql);
|
|
await db.execute(sql);
|
|
-
|
|
|
|
- await db.execute('''
|
|
|
|
- CREATE TABLE PedidoProductoTopping (
|
|
|
|
- id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
- idPedidoProducto INTEGER,
|
|
|
|
- idTopping INTEGER,
|
|
|
|
- FOREIGN KEY (idPedidoProducto) REFERENCES PedidoProducto(id),
|
|
|
|
- FOREIGN KEY (idTopping) REFERENCES Producto(id)
|
|
|
|
- )
|
|
|
|
- ''');
|
|
|
|
-
|
|
|
|
- if (modelo.runtimeType.toString() == 'Pedido') {
|
|
|
|
- await db.execute(
|
|
|
|
- 'ALTER TABLE Pedido ADD COLUMN descuento INTEGER DEFAULT 0');
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- await db.execute('''
|
|
|
|
- CREATE TABLE Descuento (
|
|
|
|
- id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
- porcentaje INTEGER
|
|
|
|
- )
|
|
|
|
- ''');
|
|
|
|
-
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 0});
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 5});
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 10});
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 15});
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 20});
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 25});
|
|
|
|
- await db.insert('Descuento', {'porcentaje': 30});
|
|
|
|
});
|
|
});
|
|
|
|
|
|
- await db.execute('''
|
|
|
|
- CREATE TABLE ProductoTopping (
|
|
|
|
- id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
- idProducto INTEGER,
|
|
|
|
- idTopping INTEGER,
|
|
|
|
- FOREIGN KEY (idProducto) REFERENCES Producto(id),
|
|
|
|
- FOREIGN KEY (idTopping) REFERENCES Producto(id)
|
|
|
|
- )
|
|
|
|
- ''');
|
|
|
|
-
|
|
|
|
- await db.execute('''
|
|
|
|
- CREATE TABLE Variable (
|
|
|
|
- id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
- nombre TEXT,
|
|
|
|
- clave TEXT,
|
|
|
|
- descripcion TEXT,
|
|
|
|
- activo BOOLEAN,
|
|
|
|
- idLocal INTEGER,
|
|
|
|
- eliminado TEXT
|
|
|
|
- )
|
|
|
|
- ''');
|
|
|
|
-
|
|
|
|
- await db.execute('''
|
|
|
|
- ALTER TABLE Pedido ADD COLUMN idWeb INTEGER;
|
|
|
|
- ''');
|
|
|
|
- await db.execute('''
|
|
|
|
- ALTER TABLE Pedido ADD COLUMN sincronizado TEXT;
|
|
|
|
- ''');
|
|
|
|
- await db.execute('''
|
|
|
|
- ALTER TABLE PedidoProducto ADD COLUMN idWeb INTEGER;
|
|
|
|
- ''');
|
|
|
|
- await db.execute('''
|
|
|
|
- ALTER TABLE PedidoProducto ADD COLUMN sincronizado TEXT;
|
|
|
|
- ''');
|
|
|
|
-
|
|
|
|
await db.insert('Variable', {
|
|
await db.insert('Variable', {
|
|
'nombre': 'Imprimir Ticket Cocina',
|
|
'nombre': 'Imprimir Ticket Cocina',
|
|
'clave': 'ticket_cocina',
|
|
'clave': 'ticket_cocina',
|
|
@@ -151,13 +90,103 @@ class RepoService<T> {
|
|
'idLocal': -1,
|
|
'idLocal': -1,
|
|
});
|
|
});
|
|
|
|
|
|
- await db.insert('Variable', {
|
|
|
|
- 'nombre': 'Sucursal',
|
|
|
|
- 'clave': 'PRUEBA',
|
|
|
|
- 'descripcion': 'Sucursal Prueba',
|
|
|
|
- 'activo': 1,
|
|
|
|
- 'idLocal': -1,
|
|
|
|
- });
|
|
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 0});
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 5});
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 10});
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 15});
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 20});
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 25});
|
|
|
|
+ await db.insert('Descuento', {'porcentaje': 30});
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Permiso (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idModulo TEXT,
|
|
|
|
+ nombre TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ eliminado TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE CorteCaja (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ fechaApertura TEXT,
|
|
|
|
+ fechaCorte TEXT,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ fondo REAL,
|
|
|
|
+ fondoDiaSig REAL,
|
|
|
|
+ ventaPuntos REAL,
|
|
|
|
+ ventaEfe REAL,
|
|
|
|
+ ventaTrans REAL,
|
|
|
|
+ ventaTarj REAL,
|
|
|
|
+ gasto REAL,
|
|
|
|
+ retiro REAL,
|
|
|
|
+ deposito REAL,
|
|
|
|
+ corteFinal REAL,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT,
|
|
|
|
+ idWeb TEXT,
|
|
|
|
+ sincronizado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Deposito (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idCorteCaja TEXT,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ fechaDeposito TEXT,
|
|
|
|
+ monto REAL,
|
|
|
|
+ persona TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT,
|
|
|
|
+ idWeb TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Retiro (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idCorteCaja TEXT,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ fechaRetiro TEXT,
|
|
|
|
+ monto REAL,
|
|
|
|
+ persona TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT,
|
|
|
|
+ sincronizado TEXT,
|
|
|
|
+ idWeb TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Gasto (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idCorteCaja TEXT,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ fechaGasto TEXT,
|
|
|
|
+ monto REAL,
|
|
|
|
+ persona TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT,
|
|
|
|
+ idWeb TEXT,
|
|
|
|
+ sincronizado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
}
|
|
}
|
|
|
|
|
|
void _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
|
void _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
|
@@ -173,139 +202,6 @@ class RepoService<T> {
|
|
await db.execute(
|
|
await db.execute(
|
|
"ALTER TABLE CategoriaProducto ADD COLUMN maximo INTEGER");
|
|
"ALTER TABLE CategoriaProducto ADD COLUMN maximo INTEGER");
|
|
|
|
|
|
- await db.insert('CategoriaProducto', {
|
|
|
|
- 'nombre': 'BASE PRODUCTO',
|
|
|
|
- 'descripcion': 'Base del producto',
|
|
|
|
- 'esToping': 1,
|
|
|
|
- 'maximo': 1,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('CategoriaProducto', {
|
|
|
|
- 'nombre': 'SALSAS PRODUCTO',
|
|
|
|
- 'descripcion': 'Elige tus salsas (Máx. 2)',
|
|
|
|
- 'esToping': 1,
|
|
|
|
- 'maximo': 2,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('CategoriaProducto', {
|
|
|
|
- 'nombre': 'ADEREZO PRODUCTO',
|
|
|
|
- 'descripcion': 'Elige tu aderezo (Máx. 2)',
|
|
|
|
- 'esToping': 1,
|
|
|
|
- 'maximo': 2,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('CategoriaProducto', {
|
|
|
|
- 'nombre': 'TOPPING PRODUCTO',
|
|
|
|
- 'descripcion': 'Elige tus toppings (Máx. 2)',
|
|
|
|
- 'esToping': 1,
|
|
|
|
- 'maximo': 2,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'Papa Gajo',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'Papa Regilla',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'Papa Curly',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'Papa Smile',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'Papa Francesa',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'BBQ',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'HOTBBQ',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'BUFFALO',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'TERIYAKI',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'PARMESAN GARLIC',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'QUESO AMARILLO',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'RANCH',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'CHIPOTLE',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'ADEREZO JALAPEÑO',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'KETCHUP',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'JALAPEÑO',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'QUESO BLANCO',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'TAKIS',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'RUFFLES',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'QUESO PARMESANO',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
- await db.insert('Producto', {
|
|
|
|
- 'nombre': 'ELOTE',
|
|
|
|
- 'precio': 0,
|
|
|
|
- });
|
|
|
|
-
|
|
|
|
break;
|
|
break;
|
|
|
|
|
|
case 2:
|
|
case 2:
|
|
@@ -581,12 +477,129 @@ class RepoService<T> {
|
|
|
|
|
|
case 18:
|
|
case 18:
|
|
await db.execute('''
|
|
await db.execute('''
|
|
-
|
|
|
|
-
|
|
|
|
ALTER TABLE Usuario ADD COLUMN clave TEXT;
|
|
ALTER TABLE Usuario ADD COLUMN clave TEXT;
|
|
''');
|
|
''');
|
|
|
|
|
|
break;
|
|
break;
|
|
|
|
+
|
|
|
|
+ case 19:
|
|
|
|
+ await db.execute('DROP TABLE CorteCaja');
|
|
|
|
+ await db.execute('DROP TABLE Deposito');
|
|
|
|
+ await db.execute('DROP TABLE Gasto');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE CorteCaja (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ fechaApertura TEXT,
|
|
|
|
+ fechaCorte TEXT,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ fondo REAL,
|
|
|
|
+ fondoDiaSig REAL,
|
|
|
|
+ ventaPuntos REAL,
|
|
|
|
+ ventaEfe REAL,
|
|
|
|
+ ventaTrans REAL,
|
|
|
|
+ ventaTarj REAL,
|
|
|
|
+ gasto REAL,
|
|
|
|
+ retiro REAL,
|
|
|
|
+ corteFinal REAL,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Deposito (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idCorteCaja TEXT,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ fechaDeposito TEXT,
|
|
|
|
+ monto REAL,
|
|
|
|
+ persona TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Retiro (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idCorteCaja TEXT,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ fechaRetiro TEXT,
|
|
|
|
+ monto REAL,
|
|
|
|
+ persona TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Gasto (
|
|
|
|
+ id TEXT PRIMARY KEY,
|
|
|
|
+ idCorteCaja TEXT,
|
|
|
|
+ idSucursal INTEGER,
|
|
|
|
+ idUsuario INTEGER,
|
|
|
|
+ fechaGasto TEXT,
|
|
|
|
+ monto REAL,
|
|
|
|
+ persona TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ eliminado TEXT
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.execute('''
|
|
|
|
+ update Pedido set sincronizado = null where estatus = 'CANCELADO'
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ await db.insert('Variable', {
|
|
|
|
+ 'nombre': 'Imprimir ticket PC/Tablet',
|
|
|
|
+ 'clave': 'ticket_pc',
|
|
|
|
+ 'descripcion':
|
|
|
|
+ 'Al estar activo imprime ticket para pc, el estar desactivado imprime ticket para tablet',
|
|
|
|
+ 'activo': 1,
|
|
|
|
+ 'idLocal': -1,
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 20:
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE CorteCaja ADD COLUMN deposito REAL;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE CorteCaja ADD COLUMN idWeb TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE CorteCaja ADD COLUMN sincronizado TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE Gasto ADD COLUMN idWeb TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE Gasto ADD COLUMN sincronizado TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE Retiro ADD COLUMN idWeb TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE Retiro ADD COLUMN sincronizado TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE Deposito ADD COLUMN idWeb TEXT;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE Deposito ADD COLUMN sincronizado TEXT;
|
|
|
|
+ ''');
|
|
}
|
|
}
|
|
oldVersion++;
|
|
oldVersion++;
|
|
}
|
|
}
|
|
@@ -594,24 +607,24 @@ class RepoService<T> {
|
|
|
|
|
|
Future<int> guardar(T model) async {
|
|
Future<int> guardar(T model) async {
|
|
try {
|
|
try {
|
|
- //print("Guardando modelo en la base de datos: ${model.runtimeType}");
|
|
|
|
-
|
|
|
|
- // Convertir el modelo a JSON para la base de datos
|
|
|
|
|
|
+ // Convert the model to JSON for the database
|
|
String modelo = json.encode(model, toEncodable: toEncodable);
|
|
String modelo = json.encode(model, toEncodable: toEncodable);
|
|
- //print("Modelo convertido a JSON: $modelo");
|
|
|
|
-
|
|
|
|
Map<String, dynamic> modelMap = json.decode(modelo);
|
|
Map<String, dynamic> modelMap = json.decode(modelo);
|
|
var dbClient = await db;
|
|
var dbClient = await db;
|
|
String nombreTabla = model.runtimeType.toString();
|
|
String nombreTabla = model.runtimeType.toString();
|
|
|
|
|
|
- // Verificar si el modelo es de tipo Permiso (con id de tipo String)
|
|
|
|
- if (model is Permiso) {
|
|
|
|
- String? id = modelMap['id'];
|
|
|
|
|
|
+ // Check if the model has a String ID or an int ID
|
|
|
|
+ dynamic id = modelMap['id'];
|
|
|
|
+ bool isStringId = id is String;
|
|
|
|
+ bool isIntId = id is int;
|
|
|
|
|
|
- if (id == null || id.isEmpty) {
|
|
|
|
- throw Exception('El ID del permiso no puede ser nulo o vacío');
|
|
|
|
|
|
+ // If id is of type String (e.g., Permiso)
|
|
|
|
+ if (isStringId) {
|
|
|
|
+ if (id == null || (id as String).isEmpty) {
|
|
|
|
+ throw Exception('El ID del modelo no puede ser nulo o vacío');
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ // Check for existing record with the String ID
|
|
List<Map> existing = await dbClient!.query(
|
|
List<Map> existing = await dbClient!.query(
|
|
nombreTabla,
|
|
nombreTabla,
|
|
where: 'id = ?',
|
|
where: 'id = ?',
|
|
@@ -619,8 +632,7 @@ class RepoService<T> {
|
|
);
|
|
);
|
|
|
|
|
|
if (existing.isNotEmpty) {
|
|
if (existing.isNotEmpty) {
|
|
- //print("Actualizando registro existente con ID: $id");
|
|
|
|
- await dbClient!.update(
|
|
|
|
|
|
+ await dbClient.update(
|
|
nombreTabla,
|
|
nombreTabla,
|
|
modelMap,
|
|
modelMap,
|
|
where: 'id = ?',
|
|
where: 'id = ?',
|
|
@@ -629,25 +641,23 @@ class RepoService<T> {
|
|
} else {
|
|
} else {
|
|
print(
|
|
print(
|
|
"Insertando nuevo registro en la tabla $nombreTabla con ID: $id");
|
|
"Insertando nuevo registro en la tabla $nombreTabla con ID: $id");
|
|
- await dbClient!.insert(nombreTabla, modelMap);
|
|
|
|
|
|
+ await dbClient.insert(nombreTabla, modelMap);
|
|
}
|
|
}
|
|
-
|
|
|
|
return 1;
|
|
return 1;
|
|
- } else {
|
|
|
|
- int? id = modelMap['id'];
|
|
|
|
-
|
|
|
|
|
|
+ } else if (isIntId) {
|
|
|
|
+ // If id is of type int (e.g., other models)
|
|
if (id == null || id == 0) {
|
|
if (id == null || id == 0) {
|
|
- modelMap.remove('id');
|
|
|
|
|
|
+ modelMap
|
|
|
|
+ .remove('id'); // Remove id if it's null or 0 for auto-increment
|
|
}
|
|
}
|
|
|
|
|
|
- List<Map> existing = id != null && id > 0
|
|
|
|
|
|
+ List<Map> existing = (id != null && id > 0)
|
|
? await dbClient!
|
|
? await dbClient!
|
|
.query(nombreTabla, where: 'id = ?', whereArgs: [id])
|
|
.query(nombreTabla, where: 'id = ?', whereArgs: [id])
|
|
: [];
|
|
: [];
|
|
|
|
|
|
if (existing.isNotEmpty) {
|
|
if (existing.isNotEmpty) {
|
|
- print(
|
|
|
|
- "Actualizando registro existente con ID: $id y modificado: ${modelMap['modificado']}");
|
|
|
|
|
|
+ print("Actualizando registro existente con ID: $id");
|
|
await dbClient!.update(
|
|
await dbClient!.update(
|
|
nombreTabla,
|
|
nombreTabla,
|
|
modelMap,
|
|
modelMap,
|
|
@@ -658,8 +668,9 @@ class RepoService<T> {
|
|
print("Insertando nuevo registro en la tabla $nombreTabla");
|
|
print("Insertando nuevo registro en la tabla $nombreTabla");
|
|
id = await dbClient!.insert(nombreTabla, modelMap);
|
|
id = await dbClient!.insert(nombreTabla, modelMap);
|
|
}
|
|
}
|
|
-
|
|
|
|
- return id!;
|
|
|
|
|
|
+ return id as int;
|
|
|
|
+ } else {
|
|
|
|
+ throw Exception('Tipo de ID no soportado');
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
print('Error al guardar en dynamic: $e');
|
|
print('Error al guardar en dynamic: $e');
|
|
@@ -756,6 +767,8 @@ class RepoService<T> {
|
|
return Producto.fromJson(map) as T;
|
|
return Producto.fromJson(map) as T;
|
|
case Usuario:
|
|
case Usuario:
|
|
return Usuario.fromJson(map) as T;
|
|
return Usuario.fromJson(map) as T;
|
|
|
|
+ case CorteCaja:
|
|
|
|
+ return CorteCaja.fromJson(map) as T;
|
|
default:
|
|
default:
|
|
throw Exception('Tipo no soportado');
|
|
throw Exception('Tipo no soportado');
|
|
}
|
|
}
|
|
@@ -780,21 +793,34 @@ class RepoService<T> {
|
|
.toList();
|
|
.toList();
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<Deposito>> obtenerDepositosPorIdCorteCaja(int idCorteCaja) async {
|
|
|
|
|
|
+ //CORTE CAJA
|
|
|
|
+
|
|
|
|
+ Future<List<Deposito>> obtenerDepositosPorIdCorteCaja(
|
|
|
|
+ String idCorteCaja) async {
|
|
var dbClient = await db;
|
|
var dbClient = await db;
|
|
List<Map<String, dynamic>> maps = await dbClient!.query(
|
|
List<Map<String, dynamic>> maps = await dbClient!.query(
|
|
'Deposito',
|
|
'Deposito',
|
|
- where: 'idCorteCaja = ?',
|
|
|
|
|
|
+ where: 'idCorteCaja = ? AND eliminado IS NULL',
|
|
whereArgs: [idCorteCaja],
|
|
whereArgs: [idCorteCaja],
|
|
);
|
|
);
|
|
return maps.map((map) => Deposito.fromJson(map)).toList();
|
|
return maps.map((map) => Deposito.fromJson(map)).toList();
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<Gasto>> obtenerGastosPorIdCorteCaja(int idCorteCaja) async {
|
|
|
|
|
|
+ Future<List<Retiro>> obtenerRetirosPorIdCorteCaja(String idCorteCaja) async {
|
|
|
|
+ var dbClient = await db;
|
|
|
|
+ List<Map<String, dynamic>> maps = await dbClient!.query(
|
|
|
|
+ 'Retiro',
|
|
|
|
+ where: 'idCorteCaja = ? AND eliminado IS NULL',
|
|
|
|
+ whereArgs: [idCorteCaja],
|
|
|
|
+ );
|
|
|
|
+ return maps.map((map) => Retiro.fromJson(map)).toList();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Future<List<Gasto>> obtenerGastosPorIdCorteCaja(String idCorteCaja) async {
|
|
var dbClient = await db;
|
|
var dbClient = await db;
|
|
List<Map<String, dynamic>> maps = await dbClient!.query(
|
|
List<Map<String, dynamic>> maps = await dbClient!.query(
|
|
'Gasto',
|
|
'Gasto',
|
|
- where: 'idCorteCaja = ?',
|
|
|
|
|
|
+ where: 'idCorteCaja = ? AND eliminado IS NULL',
|
|
whereArgs: [idCorteCaja],
|
|
whereArgs: [idCorteCaja],
|
|
);
|
|
);
|
|
return maps.map((map) => Gasto.fromJson(map)).toList();
|
|
return maps.map((map) => Gasto.fromJson(map)).toList();
|
|
@@ -806,6 +832,21 @@ class RepoService<T> {
|
|
return Sqflite.firstIntValue(result) ?? 0;
|
|
return Sqflite.firstIntValue(result) ?? 0;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Future<double?> obtenerFondoDiaSigDelUltimoCorte() async {
|
|
|
|
+ var dbClient = await db;
|
|
|
|
+ List<Map<String, dynamic>> result = await dbClient!.query(
|
|
|
|
+ 'CorteCaja',
|
|
|
|
+ orderBy: 'fechaApertura DESC',
|
|
|
|
+ limit: 1,
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (result.isNotEmpty) {
|
|
|
|
+ return result.first['fondoDiaSig'] as double?;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
Future<List<Pedido>> obtenerPedidosPaginados(int limit, int offset) async {
|
|
Future<List<Pedido>> obtenerPedidosPaginados(int limit, int offset) async {
|
|
Database? dbClient = await db;
|
|
Database? dbClient = await db;
|
|
List<Map<String, dynamic>> result = await dbClient!
|
|
List<Map<String, dynamic>> result = await dbClient!
|