feat: repositorios, servicios, UI completa con rutas, Capacitor Android sync
This commit is contained in:
31
packages/services/src/ajustes/AjustesService.ts
Normal file
31
packages/services/src/ajustes/AjustesService.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { db } from '@toldo/data';
|
||||
import type { Ajuste, MovimientoInventario } from '@toldo/core';
|
||||
import { validateAjusteMotivo } from '@toldo/core';
|
||||
|
||||
export class AjustesService {
|
||||
async crearAjuste(ajuste: Ajuste) {
|
||||
validateAjusteMotivo(ajuste.motivo);
|
||||
return db.transaction('rw', db.ajustes, db.movimientosInventario, async () => {
|
||||
await db.ajustes.add(ajuste);
|
||||
await db.movimientosInventario.add({
|
||||
id: crypto.randomUUID(),
|
||||
fecha: ajuste.fecha,
|
||||
tipo: 'AJUSTE',
|
||||
productoId: ajuste.productoId,
|
||||
cantidad: ajuste.diferencia,
|
||||
motivo: ajuste.motivo,
|
||||
referenciaId: ajuste.id,
|
||||
createdAt: new Date()
|
||||
});
|
||||
return ajuste.id;
|
||||
});
|
||||
}
|
||||
|
||||
async getAjustesDelDia(fecha: Date): Promise<Ajuste[]> {
|
||||
const start = new Date(fecha);
|
||||
start.setHours(0, 0, 0, 0);
|
||||
const end = new Date(fecha);
|
||||
end.setHours(23, 59, 59, 999);
|
||||
return db.ajustes.where('fecha').between(start, end).toArray();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user