Compare commits
No commits in common. "e9b96ccf212659cae53f10171dac0f20c16c5878" and "ff036a7d814f2c2b985decc8a8f2d56d73671c2d" have entirely different histories.
e9b96ccf21
...
ff036a7d81
@ -20,12 +20,17 @@ export const InvoiceTotals = (props: ComponentProps<"fieldset">) => {
|
|||||||
const { control, getValues } = useFormContext<InvoiceFormData>();
|
const { control, getValues } = useFormContext<InvoiceFormData>();
|
||||||
const { currency_code, language_code, readOnly, taxCatalog } = useInvoiceContext();
|
const { currency_code, language_code, readOnly, taxCatalog } = useInvoiceContext();
|
||||||
|
|
||||||
const displayTaxes = useWatch({ control, name: "taxes", defaultValue: [] });
|
const displayTaxes = useWatch({
|
||||||
const subtotal_amount = useWatch({ control, name: "subtotal_amount", defaultValue: 0 });
|
control,
|
||||||
const discount_amount = useWatch({ control, name: "discount_amount", defaultValue: 0 });
|
name: "taxes",
|
||||||
const taxable_amount = useWatch({ control, name: "taxable_amount", defaultValue: 0 });
|
defaultValue: [],
|
||||||
const taxes_amount = useWatch({ control, name: "taxes_amount", defaultValue: 0 });
|
});
|
||||||
const total_amount = useWatch({ control, name: "total_amount", defaultValue: 0 });
|
|
||||||
|
const subtotal_amount = useWatch({
|
||||||
|
control,
|
||||||
|
name: "subtotal_amount",
|
||||||
|
defaultValue: 0,
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FieldSet {...props}>
|
<FieldSet {...props}>
|
||||||
@ -61,7 +66,7 @@ export const InvoiceTotals = (props: ComponentProps<"fieldset">) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span className='font-medium text-destructive tabular-nums'>
|
<span className='font-medium text-destructive tabular-nums'>
|
||||||
-{formatCurrency(discount_amount, 2, currency_code, language_code)}
|
-{formatCurrency(getValues("discount_amount"), 2, currency_code, language_code)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -69,7 +74,7 @@ export const InvoiceTotals = (props: ComponentProps<"fieldset">) => {
|
|||||||
<div className='flex justify-between text-sm'>
|
<div className='flex justify-between text-sm'>
|
||||||
<span className='text-foreground'>Base imponible</span>
|
<span className='text-foreground'>Base imponible</span>
|
||||||
<span className='font-medium tabular-nums'>
|
<span className='font-medium tabular-nums'>
|
||||||
{formatCurrency(taxable_amount, 2, currency_code, language_code)}
|
{formatCurrency(getValues("taxable_amount"), 2, currency_code, language_code)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -121,7 +126,7 @@ export const InvoiceTotals = (props: ComponentProps<"fieldset">) => {
|
|||||||
<div className='flex justify-between text-sm mt-3'>
|
<div className='flex justify-between text-sm mt-3'>
|
||||||
<span className='text-foreground'>Total de impuestos</span>
|
<span className='text-foreground'>Total de impuestos</span>
|
||||||
<span className='font-medium tabular-nums'>
|
<span className='font-medium tabular-nums'>
|
||||||
{formatCurrency(taxes_amount, 2, currency_code, language_code)}
|
{formatCurrency(getValues("taxes_amount"), 2, currency_code, language_code)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -131,7 +136,7 @@ export const InvoiceTotals = (props: ComponentProps<"fieldset">) => {
|
|||||||
<div className='flex justify-between text-sm '>
|
<div className='flex justify-between text-sm '>
|
||||||
<span className='font-bold text-foreground'>Total de la factura</span>
|
<span className='font-bold text-foreground'>Total de la factura</span>
|
||||||
<span className='font-bold tabular-nums'>
|
<span className='font-bold tabular-nums'>
|
||||||
{formatCurrency(total_amount, 2, currency_code, language_code)}
|
{formatCurrency(getValues("total_amount"), 2, currency_code, language_code)}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
|
|||||||
@ -96,14 +96,7 @@ export function useInvoiceAutoRecalc(
|
|||||||
const prev = itemCache.current.get(idx);
|
const prev = itemCache.current.get(idx);
|
||||||
const next = calculateItemTotals(item, deferredDiscount);
|
const next = calculateItemTotals(item, deferredDiscount);
|
||||||
|
|
||||||
const itemHasChanges =
|
if (!prev || JSON.stringify(prev) !== JSON.stringify(next)) {
|
||||||
!prev ||
|
|
||||||
prev.subtotal_amount !== next.subtotal_amount ||
|
|
||||||
prev.total_amount !== next.total_amount ||
|
|
||||||
prev.taxes_amount !== next.taxes_amount;
|
|
||||||
|
|
||||||
//if (!prev || JSON.stringify(prev) !== JSON.stringify(next)) { <-- Costoso y poco preciso
|
|
||||||
if (itemHasChanges) {
|
|
||||||
shouldUpdateHeader = true;
|
shouldUpdateHeader = true;
|
||||||
itemCache.current.set(idx, next);
|
itemCache.current.set(idx, next);
|
||||||
setInvoiceItemTotals(form, idx, next);
|
setInvoiceItemTotals(form, idx, next);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user