|
|
|
|
@@ -13,6 +13,7 @@
|
|
|
|
|
<v-card-text>
|
|
|
|
|
<div class="text-subtitle-1 font-weight-bold">{{ prod.nombrePresentacion }}</div>
|
|
|
|
|
<div class="text-h6 text-primary">${{ prod.precioUnitario.toLocaleString() }}</div>
|
|
|
|
|
<div class="text-caption" :class="prod.stock > 0 ? 'text-medium-emphasis' : 'text-error'">Disponible: {{ prod.stock }}</div>
|
|
|
|
|
</v-card-text>
|
|
|
|
|
</v-card>
|
|
|
|
|
</v-col>
|
|
|
|
|
@@ -32,7 +33,7 @@
|
|
|
|
|
<v-list-item-subtitle>
|
|
|
|
|
<v-row align="center" class="mt-1">
|
|
|
|
|
<v-col cols="4">
|
|
|
|
|
<div class="d-flex align-center justify-center ga-1"><v-btn icon="mdi-minus" size="small" variant="tonal" aria-label="Disminuir cantidad" @click="cambiarCantidad(i, -1)" /><span class="quantity-value">{{ l.cantidad }}</span><v-btn icon="mdi-plus" size="small" variant="tonal" aria-label="Aumentar cantidad" @click="cambiarCantidad(i, 1)" /></div>
|
|
|
|
|
<div class="d-flex align-center justify-center ga-1"><v-btn icon="mdi-minus" size="small" variant="tonal" aria-label="Disminuir cantidad" :disabled="l.cantidad <= 1" @click="cambiarCantidad(i, -1)" /><span class="quantity-value">{{ l.cantidad }}</span><v-btn icon="mdi-plus" size="small" variant="tonal" aria-label="Aumentar cantidad" :disabled="l.cantidad >= getStock(l.productoId)" @click="cambiarCantidad(i, 1)" /></div>
|
|
|
|
|
</v-col>
|
|
|
|
|
<v-col cols="4">${{ l.precioUnitario }}</v-col>
|
|
|
|
|
<v-col cols="4">${{ l.subtotal }}</v-col>
|
|
|
|
|
@@ -66,6 +67,7 @@ import { VentasService, JornadaService, EdicionService } from '@toldo/services';
|
|
|
|
|
const ventasService = new VentasService();
|
|
|
|
|
const jornadaService = new JornadaService();
|
|
|
|
|
const productos = ref<any[]>([]);
|
|
|
|
|
const stockByProduct = ref<Record<string, number>>({});
|
|
|
|
|
const lineas = ref<any[]>([]);
|
|
|
|
|
const formaPago = ref('EFECTIVO');
|
|
|
|
|
const jornadaAbierta = ref<any>(null);
|
|
|
|
|
@@ -88,7 +90,9 @@ const edicionService = new EdicionService();
|
|
|
|
|
|
|
|
|
|
async function cargar() {
|
|
|
|
|
const productores = await db.productores.toArray();
|
|
|
|
|
productos.value = (await db.productos.toArray()).map((producto) => ({ ...producto, productorNombre: productores.find((productor) => productor.id === producto.productorId)?.nombre ?? '' }));
|
|
|
|
|
const movimientos = await db.movimientosInventario.toArray();
|
|
|
|
|
stockByProduct.value = movimientos.reduce<Record<string, number>>((stock, movimiento) => { stock[movimiento.productoId] = (stock[movimiento.productoId] ?? 0) + movimiento.cantidad; return stock; }, {});
|
|
|
|
|
productos.value = (await db.productos.toArray()).map((producto) => ({ ...producto, stock: stockByProduct.value[producto.id] ?? 0, productorNombre: productores.find((productor) => productor.id === producto.productorId)?.nombre ?? '' }));
|
|
|
|
|
jornadaAbierta.value = await jornadaService.getJornadaAbierta();
|
|
|
|
|
const ventasDelDia = await ventasService.getVentasDelDia(new Date());
|
|
|
|
|
ventas.value = await Promise.all(ventasDelDia.map(async (venta) => ({ ...venta, lineas: await ventasService.getLineasPorVenta(venta.id) })));
|
|
|
|
|
@@ -97,10 +101,13 @@ async function cargar() {
|
|
|
|
|
function getProdNombre(id: string) {
|
|
|
|
|
return productos.value.find(p => p.id === id)?.nombrePresentacion || id;
|
|
|
|
|
}
|
|
|
|
|
function getStock(id: string) { return stockByProduct.value[id] ?? 0; }
|
|
|
|
|
|
|
|
|
|
function agregarProducto(prod: any) {
|
|
|
|
|
if (getStock(prod.id) <= 0) { error.value = 'Este producto no tiene inventario disponible. Registra primero el inventario inicial.'; return; }
|
|
|
|
|
const existente = lineas.value.findIndex(l => l.productoId === prod.id);
|
|
|
|
|
if (existente >= 0) {
|
|
|
|
|
if (lineas.value[existente].cantidad >= getStock(prod.id)) { error.value = `Stock insuficiente. Disponible: ${getStock(prod.id)}.`; return; }
|
|
|
|
|
lineas.value[existente].cantidad++;
|
|
|
|
|
lineas.value[existente].subtotal = lineas.value[existente].cantidad * lineas.value[existente].precioUnitario;
|
|
|
|
|
} else {
|
|
|
|
|
@@ -162,7 +169,7 @@ async function registrarVenta() {
|
|
|
|
|
lineas.value = [];
|
|
|
|
|
exito.value = `Venta registrada por $${total.value.toLocaleString()} en ${formaPago.value}.`;
|
|
|
|
|
} catch (e: any) {
|
|
|
|
|
error.value = e.message;
|
|
|
|
|
error.value = e.message.includes('objectStore') ? 'No se pudo abrir el almacenamiento local. Cierra y vuelve a abrir la aplicación para actualizar la base de datos.' : e.message;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|