From 0160ba90d4ce4acd57c99dadd2b46336c6222f0f Mon Sep 17 00:00:00 2001 From: fede Date: Sat, 28 Nov 2026 16:49:17 -0300 Subject: [PATCH] fix: ya no se puede cambiar el precio desde la ui Signed-off-by: fede --- front/src/routes/facturas/nueva/+page.svelte | 94 ++++++++++++++------ 1 file changed, 67 insertions(+), 27 deletions(-) diff --git a/front/src/routes/facturas/nueva/+page.svelte b/front/src/routes/facturas/nueva/+page.svelte index dc378e6..bdecfac 100644 --- a/front/src/routes/facturas/nueva/+page.svelte +++ b/front/src/routes/facturas/nueva/+page.svelte @@ -35,38 +35,38 @@ interface Item { repuestoId: number; cantidad: number; - precioUnitario: number; } - let items = $state([{ repuestoId: 0, cantidad: 1, precioUnitario: 0 }]); + let items = $state([{ repuestoId: 0, cantidad: 1 }]); let pagoImporte = $state(0); let pagoFormaId = $state(0); let registrarPago = $state(false); function agregarItem() { - items = [...items, { repuestoId: 0, cantidad: 1, precioUnitario: 0 }]; + items = [...items, { repuestoId: 0, cantidad: 1 }]; } function quitarItem(i: number) { items = items.filter((_, idx) => idx !== i); - if (items.length === 0) items = [{ repuestoId: 0, cantidad: 1, precioUnitario: 0 }]; + if (items.length === 0) items = [{ repuestoId: 0, cantidad: 1 }]; } + // El precio siempre sale del catálogo; el usuario sólo elige el repuesto + // y la cantidad. function precioRepuesto(id: number): number { const r = repuestos.find((x) => x.ID === id); return r ? r.precio : 0; } - $effect(() => { - for (const it of items) { - if (it.repuestoId > 0 && it.precioUnitario === 0) { - it.precioUnitario = precioRepuesto(it.repuestoId); - } - } - }); + function formatMonto(monto: number): string { + return monto.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' }); + } let subtotal = $derived( - items.reduce((acc, it) => acc + (it.cantidad > 0 ? it.cantidad * (it.precioUnitario || 0) : 0), 0) + items.reduce( + (acc, it) => acc + (it.cantidad > 0 ? it.cantidad * precioRepuesto(it.repuestoId) : 0), + 0 + ) ); let descuentoTotal = $derived.by(() => { @@ -85,10 +85,22 @@ enviando = true; error = ''; - if (!clienteId) { error = 'Seleccioná un cliente.'; enviando = false; return; } - if (!almacenId) { error = 'Seleccioná un almacén.'; enviando = false; return; } + if (!clienteId) { + error = 'Seleccioná un cliente.'; + enviando = false; + return; + } + if (!almacenId) { + error = 'Seleccioná un almacén.'; + enviando = false; + return; + } const itemsValidos = items.filter((i) => i.repuestoId > 0 && i.cantidad > 0); - if (itemsValidos.length === 0) { error = 'Agregá al menos un ítem válido.'; enviando = false; return; } + if (itemsValidos.length === 0) { + error = 'Agregá al menos un ítem válido.'; + enviando = false; + return; + } const payload = { clienteId, @@ -96,10 +108,13 @@ items: itemsValidos.map((i) => ({ repuestoId: i.repuestoId, cantidad: i.cantidad, - precioUnitario: i.precioUnitario || precioRepuesto(i.repuestoId) + precioUnitario: precioRepuesto(i.repuestoId) })), descuentoId: descuentoId || undefined, - pagos: registrarPago && pagoImporte > 0 ? [{ formaDePagoId: pagoFormaId, importe: pagoImporte }] : undefined, + pagos: + registrarPago && pagoImporte > 0 + ? [{ formaDePagoId: pagoFormaId, importe: pagoImporte }] + : undefined, enviarEmail, observacion: observacion.trim() || undefined }; @@ -140,7 +155,9 @@ {#if clienteId} {@const c = clientes.find((x) => x.ID === clienteId)} {#if c} -

Email: {c.email ?? '-'} · CUIT: {c.cuit ?? '-'}

+

+ Email: {c.email ?? '-'} · CUIT: {c.cuit ?? '-'} +

{/if} {/if} @@ -150,7 +167,10 @@ @@ -160,7 +180,10 @@ @@ -197,13 +220,22 @@
- +
- {(it.cantidad * (it.precioUnitario || 0)).toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })} + {formatMonto(it.cantidad * precioRepuesto(it.repuestoId))}
-
{/each} @@ -213,10 +245,18 @@

Totales

-
Subtotal{subtotal.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}
-
Descuento{descuentoTotal.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}
-
IVA (21%){impuestos.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}
-
Total{total.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}
+
+ Subtotal{formatMonto(subtotal)} +
+
+ Descuento{formatMonto(descuentoTotal)} +
+
+ IVA (21%){formatMonto(impuestos)} +
+
+ Total{formatMonto(total)} +