feat: repositorios, servicios, UI completa con rutas, Capacitor Android sync

This commit is contained in:
mono
2026-10-24 21:11:50 -05:00
parent 0c7cf651ce
commit df3838c2f3
36 changed files with 4224 additions and 402 deletions

View File

@@ -0,0 +1,37 @@
import { db } from '@toldo/data';
import type { Venta, VentaLinea } from '@toldo/core';
export class VentasService {
async registrarVenta(venta: Venta, lineas: VentaLinea[]) {
// Validar stock mínimo conceptual - se puede expandir
return db.transaction('rw', db.ventas, db.ventaLineas, async () => {
await db.ventas.add(venta);
await db.ventaLineas.bulkAdd(lineas);
// Registrar movimientos de venta
for (const linea of lineas) {
await db.movimientosInventario.add({
id: crypto.randomUUID(),
fecha: venta.fecha,
tipo: 'VENTA',
productoId: linea.productoId,
cantidad: -Math.abs(linea.cantidad),
referenciaId: venta.id,
createdAt: new Date()
});
}
return venta.id;
});
}
async getVentasDelDia(fecha: Date): Promise<Venta[]> {
const start = new Date(fecha);
start.setHours(0, 0, 0, 0);
const end = new Date(fecha);
end.setHours(23, 59, 59, 999);
return db.ventas.where('fecha').between(start, end).toArray();
}
async getLineasPorVenta(ventaId: string): Promise<VentaLinea[]> {
return db.ventaLineas.where('ventaId').equals(ventaId).toArray();
}
}