2024-07-19 15:22:13 +00:00
|
|
|
import { FormPercentageField } from "@/components";
|
2024-07-18 18:26:44 +00:00
|
|
|
import { useLocalization } from "@/lib/hooks";
|
2024-07-19 15:22:13 +00:00
|
|
|
import { Card, CardContent, CardDescription, CardTitle, Separator } from "@/ui";
|
|
|
|
|
import { t } from "i18next";
|
2024-07-18 16:41:46 +00:00
|
|
|
import { useFormContext } from "react-hook-form";
|
|
|
|
|
|
|
|
|
|
export const QuotePricesResume = () => {
|
2024-07-19 15:22:13 +00:00
|
|
|
const { watch, register, formState } = useFormContext();
|
|
|
|
|
const { formatNumber, formatPercentage } = useLocalization();
|
2024-07-18 16:41:46 +00:00
|
|
|
|
2024-07-19 15:02:19 +00:00
|
|
|
const subtotal_price = formatNumber(watch("subtotal_price"));
|
2024-07-19 15:22:13 +00:00
|
|
|
const discount_price = formatPercentage(watch("discount_price"));
|
|
|
|
|
const tax_price = formatPercentage(watch("tax_price"));
|
2024-07-19 15:02:19 +00:00
|
|
|
const total_price = formatNumber(watch("total_price"));
|
2024-07-18 16:41:46 +00:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Card className='w-full'>
|
|
|
|
|
<CardContent className='flex flex-row items-end gap-2 p-4 border-t'>
|
|
|
|
|
<div className='grid flex-1 h-16 grid-cols-1 auto-rows-max'>
|
|
|
|
|
<div className='grid gap-1 font-semibold text-muted-foreground'>
|
|
|
|
|
<CardDescription className='text-sm'>Importe neto</CardDescription>
|
2024-07-18 18:26:44 +00:00
|
|
|
<CardTitle className='flex items-baseline text-2xl tabular-nums'>
|
|
|
|
|
{subtotal_price}
|
|
|
|
|
<span className='ml-1 text-lg tracking-normal'>€</span>
|
2024-07-18 16:41:46 +00:00
|
|
|
</CardTitle>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Separator orientation='vertical' className='w-px h-16 mx-2' />
|
2024-07-19 15:22:13 +00:00
|
|
|
<div className='grid flex-1 h-16 grid-cols-2 gap-6 auto-rows-max'>
|
2024-07-18 16:41:46 +00:00
|
|
|
<div className='grid gap-1 font-medium text-muted-foreground'>
|
2024-07-19 15:22:13 +00:00
|
|
|
<CardDescription className='text-sm'>
|
|
|
|
|
{t("quotes.form_fields.discount.label")}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
<FormPercentageField
|
|
|
|
|
scale={2}
|
|
|
|
|
disabled={formState.disabled}
|
|
|
|
|
placeholder={t("quotes.form_fields.discount.placeholder")}
|
|
|
|
|
{...register("discount", {
|
|
|
|
|
required: false,
|
|
|
|
|
})}
|
|
|
|
|
/>
|
2024-07-18 16:41:46 +00:00
|
|
|
</div>
|
|
|
|
|
<div className='grid gap-1 font-semibold text-muted-foreground'>
|
|
|
|
|
<CardDescription className='text-sm'>Imp. descuento</CardDescription>
|
2024-07-18 18:26:44 +00:00
|
|
|
<CardTitle className='flex items-baseline text-2xl tabular-nums'>
|
2024-07-19 15:22:13 +00:00
|
|
|
{discount_price}
|
2024-07-18 18:26:44 +00:00
|
|
|
<span className='ml-1 text-lg tracking-normal'>€</span>
|
2024-07-18 16:41:46 +00:00
|
|
|
</CardTitle>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<Separator orientation='vertical' className='w-px h-16 mx-2' />
|
2024-07-19 15:22:13 +00:00
|
|
|
<div className='grid flex-1 h-16 grid-cols-2 gap-6 auto-rows-max'>
|
2024-07-18 16:41:46 +00:00
|
|
|
<div className='grid gap-1 font-medium text-muted-foreground'>
|
2024-07-19 15:22:13 +00:00
|
|
|
<CardDescription className='text-sm'>
|
|
|
|
|
{t("quotes.form_fields.tax.label")}
|
|
|
|
|
</CardDescription>
|
|
|
|
|
|
|
|
|
|
<FormPercentageField
|
|
|
|
|
scale={2}
|
|
|
|
|
disabled={formState.disabled}
|
|
|
|
|
placeholder={t("quotes.form_fields.tax.placeholder")}
|
|
|
|
|
{...register("tax", {
|
|
|
|
|
required: false,
|
|
|
|
|
})}
|
|
|
|
|
/>
|
2024-07-18 16:41:46 +00:00
|
|
|
</div>
|
|
|
|
|
<div className='grid gap-1 font-semibold text-muted-foreground'>
|
|
|
|
|
<CardDescription className='text-sm'>Importe IVA</CardDescription>
|
2024-07-18 18:26:44 +00:00
|
|
|
<CardTitle className='flex items-baseline gap-1 text-2xl tabular-nums'>
|
2024-07-19 15:22:13 +00:00
|
|
|
{tax_price}
|
2024-07-18 16:41:46 +00:00
|
|
|
<span className='text-base font-medium tracking-normal'>€</span>
|
|
|
|
|
</CardTitle>
|
|
|
|
|
</div>
|
|
|
|
|
</div>{" "}
|
|
|
|
|
<Separator orientation='vertical' className='w-px h-16 mx-2' />
|
|
|
|
|
<div className='grid flex-1 h-16 grid-cols-1 auto-rows-max'>
|
|
|
|
|
<div className='grid gap-0'>
|
|
|
|
|
<CardDescription className='text-sm font-semibold'>Importe total</CardDescription>
|
2024-07-18 18:26:44 +00:00
|
|
|
<CardTitle className='flex items-baseline gap-1 text-3xl tabular-nums'>
|
|
|
|
|
{total_price}
|
|
|
|
|
<span className='ml-1 text-lg tracking-normal'>€</span>
|
2024-07-18 16:41:46 +00:00
|
|
|
</CardTitle>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</CardContent>
|
|
|
|
|
</Card>
|
|
|
|
|
);
|
|
|
|
|
};
|