Private
Public Access
fix: ya no se puede cambiar el precio desde la ui
Signed-off-by: fede <federico.nicolas.polidoro@gmail.com>
This commit is contained in:
1 parent
837fd8fa44
commit
0160ba90d4
1 file changed
+67
-27
@@ -35,38 +35,38 @@
|
||||
interface Item {
|
||||
repuestoId: number;
|
||||
cantidad: number;
|
||||
precioUnitario: number;
|
||||
}
|
||||
let items = $state<Item[]>([{ repuestoId: 0, cantidad: 1, precioUnitario: 0 }]);
|
||||
let items = $state<Item[]>([{ repuestoId: 0, cantidad: 1 }]);
|
||||
|
||||
let pagoImporte = $state<number>(0);
|
||||
let pagoFormaId = $state<number>(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}
|
||||
<p class="mt-2 text-sm text-gray-400">Email: {c.email ?? '-'} · CUIT: {c.cuit ?? '-'}</p>
|
||||
<p class="mt-2 text-sm text-gray-400">
|
||||
Email: {c.email ?? '-'} · CUIT: {c.cuit ?? '-'}
|
||||
</p>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
@@ -150,7 +167,10 @@
|
||||
<Select labelText="Almacén de origen" bind:selected={almacenId}>
|
||||
<SelectItem value={0} text="Seleccioná un almacén" />
|
||||
{#each almacenes as a (a.id)}
|
||||
<SelectItem value={a.id} text={a.ubicacion ? `${a.codigo} · ${a.ubicacion}` : a.codigo} />
|
||||
<SelectItem
|
||||
value={a.id}
|
||||
text={a.ubicacion ? `${a.codigo} · ${a.ubicacion}` : a.codigo}
|
||||
/>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
@@ -160,7 +180,10 @@
|
||||
<Select labelText="Descuento" bind:selected={descuentoId}>
|
||||
<SelectItem value={0} text="Sin descuento" />
|
||||
{#each descuentos as d (d.ID)}
|
||||
<SelectItem value={d.ID} text={`${d.Nombre} (${d.Tipo === 'PORCENTAJE' ? d.Valor + '%' : '$' + d.Valor})`} />
|
||||
<SelectItem
|
||||
value={d.ID}
|
||||
text={`${d.Nombre} (${d.Tipo === 'PORCENTAJE' ? d.Valor + '%' : '$' + d.Valor})`}
|
||||
/>
|
||||
{/each}
|
||||
</Select>
|
||||
</div>
|
||||
@@ -197,13 +220,22 @@
|
||||
<NumberInput labelText="Cantidad" bind:value={it.cantidad} min={0} step={1} />
|
||||
</div>
|
||||
<div class="col-span-3">
|
||||
<NumberInput labelText="Precio Unit." bind:value={it.precioUnitario} min={0} step={0.01} />
|
||||
<TextInput
|
||||
labelText="Precio Unit. (catálogo)"
|
||||
value={formatMonto(precioRepuesto(it.repuestoId))}
|
||||
readonly
|
||||
/>
|
||||
</div>
|
||||
<div class="col-span-1 text-right text-sm">
|
||||
{(it.cantidad * (it.precioUnitario || 0)).toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}
|
||||
{formatMonto(it.cantidad * precioRepuesto(it.repuestoId))}
|
||||
</div>
|
||||
<div class="col-span-1">
|
||||
<Button kind="danger-ghost" size="small" icon={TrashCan} onclick={() => quitarItem(i)} />
|
||||
<Button
|
||||
kind="danger-ghost"
|
||||
size="small"
|
||||
icon={TrashCan}
|
||||
onclick={() => quitarItem(i)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
@@ -213,10 +245,18 @@
|
||||
<div class="rounded border p-4">
|
||||
<h2 class="mb-3 text-lg font-semibold">Totales</h2>
|
||||
<div class="space-y-1 text-sm">
|
||||
<div class="flex justify-between"><span>Subtotal</span><span>{subtotal.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}</span></div>
|
||||
<div class="flex justify-between"><span>Descuento</span><span>{descuentoTotal.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}</span></div>
|
||||
<div class="flex justify-between"><span>IVA (21%)</span><span>{impuestos.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}</span></div>
|
||||
<div class="flex justify-between text-lg font-bold"><span>Total</span><span>{total.toLocaleString('es-AR', { style: 'currency', currency: 'ARS' })}</span></div>
|
||||
<div class="flex justify-between">
|
||||
<span>Subtotal</span><span>{formatMonto(subtotal)}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>Descuento</span><span>{formatMonto(descuentoTotal)}</span>
|
||||
</div>
|
||||
<div class="flex justify-between">
|
||||
<span>IVA (21%)</span><span>{formatMonto(impuestos)}</span>
|
||||
</div>
|
||||
<div class="flex justify-between text-lg font-bold">
|
||||
<span>Total</span><span>{formatMonto(total)}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in new issue
Block a user