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,56 @@
import { db } from '@toldo/data';
import type { CuadreCaja } from '@toldo/core';
import { calcularSaldoEsperadoEfectivo, calcularDescuadreEfectivo, calcularTotalVentas } from '@toldo/core';
export class CuadreService {
async calcularCuadreDelDia(fecha: Date, baseInicial: number): Promise<Partial<CuadreCaja>> {
const start = new Date(fecha);
start.setHours(0, 0, 0, 0);
const end = new Date(fecha);
end.setHours(23, 59, 59, 999);
const ventas = await db.ventas.where('fecha').between(start, end).toArray();
const lineas = await db.ventaLineas.toArray();
const gastos = await db.gastos.where('fecha').between(start, end).toArray();
let totalVentasEfectivo = 0;
let totalVentasQR = 0;
for (const venta of ventas) {
const vLineas = lineas.filter(l => l.ventaId === venta.id);
for (const l of vLineas) {
if (l.formaPago === 'EFECTIVO') totalVentasEfectivo += l.subtotal;
else totalVentasQR += l.subtotal;
}
}
let totalGastosEfectivo = 0;
let totalGastosQR = 0;
for (const g of gastos) {
if (g.formaPago === 'EFECTIVO') totalGastosEfectivo += g.monto;
else if (g.formaPago === 'QR') totalGastosQR += g.monto;
}
const saldoEsperadoEfectivo = calcularSaldoEsperadoEfectivo(baseInicial, totalVentasEfectivo, totalGastosEfectivo);
const totalVentas = calcularTotalVentas(totalVentasEfectivo, totalVentasQR);
return {
fecha,
baseInicial,
totalVentasEfectivo,
totalVentasQR,
totalGastosEfectivo,
totalGastosQR,
saldoEsperadoEfectivo,
totalVentas,
createdAt: new Date()
};
}
async guardarCuadre(cuadre: CuadreCaja) {
if (cuadre.saldoRealEfectivo !== undefined && cuadre.saldoEsperadoEfectivo !== undefined) {
cuadre.descuadreEfectivo = calcularDescuadreEfectivo(cuadre.saldoEsperadoEfectivo, cuadre.saldoRealEfectivo);
}
return db.cuadres.add(cuadre);
}
}