Uecko_ERP/modules/customer-invoices/src/web/components/editor/invoice-tax-summary.tsx

68 lines
2.6 KiB
TypeScript
Raw Normal View History

2025-10-13 17:41:21 +00:00
import { formatCurrency } from '@erp/core';
2025-09-29 18:22:59 +00:00
import { Description, FieldGroup, Fieldset, Legend } from "@repo/rdx-ui/components";
import { Badge } from "@repo/shadcn-ui/components";
import { ReceiptIcon } from "lucide-react";
2025-10-12 10:43:06 +00:00
import { ComponentProps } from 'react';
2025-09-29 18:22:59 +00:00
import { useFormContext, useWatch } from "react-hook-form";
2025-10-13 17:41:21 +00:00
import { useInvoiceContext } from '../../context';
2025-09-29 18:22:59 +00:00
import { useTranslation } from "../../i18n";
2025-10-12 10:43:06 +00:00
import { InvoiceFormData } from "../../schemas";
2025-09-29 18:22:59 +00:00
2025-10-12 10:43:06 +00:00
export const InvoiceTaxSummary = (props: ComponentProps<"fieldset">) => {
2025-09-29 18:22:59 +00:00
const { t } = useTranslation();
2025-10-12 18:36:33 +00:00
const { control } = useFormContext<InvoiceFormData>();
2025-10-13 17:41:21 +00:00
const { currency_code, language_code } = useInvoiceContext();
2025-09-29 18:22:59 +00:00
const taxes = useWatch({
control,
name: "taxes",
defaultValue: [],
});
2025-10-12 10:43:06 +00:00
const displayTaxes = taxes || [];
2025-09-29 18:22:59 +00:00
return (
2025-10-12 10:43:06 +00:00
<Fieldset {...props}>
2025-09-29 18:22:59 +00:00
<Legend className='flex items-center gap-2 text-foreground'>
2025-10-12 10:43:06 +00:00
<ReceiptIcon className='size-5' /> {t("form_groups.tax_resume.title")}
2025-09-29 18:22:59 +00:00
</Legend>
<Description>{t("form_groups.tax_resume.description")}</Description>
<FieldGroup className='grid grid-cols-1'>
<div className='space-y-3'>
{displayTaxes.map((tax, index) => (
2025-10-13 17:41:21 +00:00
<div key={`${tax.tax_code}-${index}`} className='border rounded-lg p-3 space-y-2 text-base '>
2025-10-12 10:43:06 +00:00
<div className='flex items-center justify-between mb-2 '>
2025-10-13 17:41:21 +00:00
<Badge variant='secondary' className='text-sm font-semibold'>
2025-10-12 10:43:06 +00:00
{tax.tax_label}
2025-09-29 18:22:59 +00:00
</Badge>
</div>
2025-10-12 10:43:06 +00:00
<div className='space-y-2 text-sm'>
2025-09-29 18:22:59 +00:00
<div className='flex justify-between'>
2025-10-13 17:41:21 +00:00
<span className='text-current'>Base para el impuesto:</span>
<span className='text-base text-current tabular-nums'>{formatCurrency(tax.taxable_amount, 2, currency_code, language_code)}</span>
2025-09-29 18:22:59 +00:00
</div>
<div className='flex justify-between'>
2025-10-13 17:41:21 +00:00
<span className='text-current font-semibold'>Importe de impuesto:</span>
<span className='text-base text-current font-semibold tabular-nums'>
{formatCurrency(tax.taxes_amount, 2, currency_code, language_code)}
2025-09-29 18:22:59 +00:00
</span>
</div>
</div>
</div>
))}
{displayTaxes.length === 0 && (
<div className='text-center py-6 text-muted-foreground'>
2025-10-12 18:36:33 +00:00
<ReceiptIcon className='size-8 mx-auto mb-2 opacity-50' />
2025-09-29 18:22:59 +00:00
<p className='text-sm'>No hay impuestos aplicados</p>
</div>
)}
</div>
</FieldGroup>
</Fieldset>
);
};