65 lines
2.2 KiB
TypeScript
65 lines
2.2 KiB
TypeScript
import Dexie, { type Table } from 'dexie';
|
|
import type { Productor, Producto, MovimientoInventario, Venta, VentaLinea, Gasto, Ajuste, CuadreCaja, JornadaToldo, Auditoria } from '@toldo/core';
|
|
|
|
export class ToldoDB extends Dexie {
|
|
productores!: Table<Productor, string>;
|
|
productos!: Table<Producto, string>;
|
|
movimientosInventario!: Table<MovimientoInventario, string>;
|
|
ventas!: Table<Venta, string>;
|
|
ventaLineas!: Table<VentaLinea, string>;
|
|
gastos!: Table<Gasto, string>;
|
|
ajustes!: Table<Ajuste, string>;
|
|
cuadres!: Table<CuadreCaja, string>;
|
|
jornadas!: Table<JornadaToldo, string>;
|
|
auditorias!: Table<Auditoria, string>;
|
|
|
|
constructor() {
|
|
super('ToldoConjuntoDB');
|
|
this.version(1).stores({
|
|
productores: 'id, nombre, activo',
|
|
productos: 'id, productorId, nombrePresentacion, [productorId+nombrePresentacion]',
|
|
movimientosInventario: 'id, fecha, tipo, productoId',
|
|
ventas: 'id, fecha',
|
|
ventaLineas: 'id, ventaId, productoId, formaPago',
|
|
gastos: 'id, fecha',
|
|
ajustes: 'id, fecha, productoId',
|
|
cuadres: 'id, fecha'
|
|
});
|
|
this.version(2).stores({
|
|
productores: 'id, nombre, activo',
|
|
productos: 'id, productorId, nombrePresentacion, [productorId+nombrePresentacion]',
|
|
movimientosInventario: 'id, fecha, tipo, productoId',
|
|
ventas: 'id, fecha',
|
|
ventaLineas: 'id, ventaId, productoId, formaPago',
|
|
gastos: 'id, fecha',
|
|
ajustes: 'id, fecha, productoId',
|
|
cuadres: 'id, fecha',
|
|
jornadas: 'id, fecha, estado'
|
|
});
|
|
this.version(3).stores({
|
|
productores: 'id, nombre, activo',
|
|
productos: 'id, productorId, nombrePresentacion, [productorId+nombrePresentacion]',
|
|
movimientosInventario: 'id, fecha, tipo, productoId',
|
|
ventas: 'id, fecha',
|
|
ventaLineas: 'id, ventaId, productoId, formaPago',
|
|
gastos: 'id, fecha',
|
|
ajustes: 'id, fecha, productoId',
|
|
cuadres: 'id, fecha',
|
|
jornadas: 'id, fecha, estado',
|
|
auditorias: 'id, entidad, registroId, fecha'
|
|
});
|
|
}
|
|
}
|
|
|
|
export const db = new ToldoDB();
|
|
|
|
export async function openDatabase() {
|
|
await db.open();
|
|
return db;
|
|
}
|
|
|
|
export async function resetDatabase() {
|
|
await db.delete();
|
|
await db.open();
|
|
}
|