|
@@ -6,7 +6,7 @@ import 'package:sqflite/sqflite.dart';
|
|
import '../models/models.dart';
|
|
import '../models/models.dart';
|
|
|
|
|
|
class RepoService<T> {
|
|
class RepoService<T> {
|
|
- static int dbVersion = 14;
|
|
|
|
|
|
+ static int dbVersion = 16;
|
|
static String dbName = 'joshipos026.db';
|
|
static String dbName = 'joshipos026.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;
|
|
@@ -456,10 +456,49 @@ class RepoService<T> {
|
|
ALTER TABLE Producto ADD COLUMN activo INTEGER;
|
|
ALTER TABLE Producto ADD COLUMN activo INTEGER;
|
|
''');
|
|
''');
|
|
|
|
|
|
|
|
+ break;
|
|
|
|
+
|
|
case 13:
|
|
case 13:
|
|
await db.execute('''
|
|
await db.execute('''
|
|
ALTER TABLE Producto ADD COLUMN activo INTEGER;
|
|
ALTER TABLE Producto ADD COLUMN activo INTEGER;
|
|
''');
|
|
''');
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 14:
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE ProductoTopping ADD COLUMN idCategoria INTEGER;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE ProductoTopping ADD COLUMN creado text;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE ProductoTopping ADD COLUMN modificado text;
|
|
|
|
+ ''');
|
|
|
|
+ await db.execute('''
|
|
|
|
+ ALTER TABLE ProductoTopping ADD COLUMN eliminado text;
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ break;
|
|
|
|
+
|
|
|
|
+ case 15:
|
|
|
|
+ await db.execute('''
|
|
|
|
+ CREATE TABLE Sucursal (
|
|
|
|
+ id INTEGER PRIMARY KEY AUTOINCREMENT,
|
|
|
|
+ nombre TEXT,
|
|
|
|
+ descripcion TEXT,
|
|
|
|
+ direccion TEXT,
|
|
|
|
+ ciudad TEXT,
|
|
|
|
+ activo INTEGER,
|
|
|
|
+ clave TEXT,
|
|
|
|
+ eliminado TEXT,
|
|
|
|
+ creado TEXT,
|
|
|
|
+ modificado TEXT,
|
|
|
|
+ idLocal INTEGER
|
|
|
|
+ )
|
|
|
|
+ ''');
|
|
|
|
+
|
|
|
|
+ break;
|
|
}
|
|
}
|
|
oldVersion++;
|
|
oldVersion++;
|
|
}
|
|
}
|
|
@@ -597,6 +636,9 @@ class RepoService<T> {
|
|
return item.toJson();
|
|
return item.toJson();
|
|
} else if (item is CategoriaProducto) {
|
|
} else if (item is CategoriaProducto) {
|
|
return item.toJson();
|
|
return item.toJson();
|
|
|
|
+ } else if (item is Sucursal) {
|
|
|
|
+ print("Serializando Sucursal: ${item.nombre}, ${item.descripcion}");
|
|
|
|
+ return item.toJson();
|
|
} else if (item is Variable) {
|
|
} else if (item is Variable) {
|
|
return item.toJson();
|
|
return item.toJson();
|
|
}
|
|
}
|
|
@@ -892,4 +934,28 @@ class RepoService<T> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ Future<void> sincronizarSucursales(List<Sucursal> sucursalesApi) async {
|
|
|
|
+ var db = await RepoService().db;
|
|
|
|
+
|
|
|
|
+ var sucursalesLocalesQuery = await db!.query('Sucursal');
|
|
|
|
+ List<Sucursal> sucursalesLocales =
|
|
|
|
+ sucursalesLocalesQuery.map((e) => Sucursal.fromJson(e)).toList();
|
|
|
|
+
|
|
|
|
+ for (var sucursalApi in sucursalesApi) {
|
|
|
|
+ var sucursalLocal = sucursalesLocales.firstWhere(
|
|
|
|
+ (sucursal) => sucursal.id == sucursalApi.id,
|
|
|
|
+ orElse: () => Sucursal(),
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ if (sucursalLocal.id != 0 &&
|
|
|
|
+ sucursalApi.modificado != null &&
|
|
|
|
+ (sucursalLocal.modificado == null ||
|
|
|
|
+ sucursalApi.modificado!.isAfter(sucursalLocal.modificado!))) {
|
|
|
|
+ await RepoService().guardar(sucursalApi);
|
|
|
|
+ } else if (sucursalLocal.id == 0) {
|
|
|
|
+ await RepoService().guardar(sucursalApi);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|