diff --git a/client/src/app/quotes/components/QuotePricesResume.tsx b/client/src/app/quotes/components/QuotePricesResume.tsx index 3013e62..2544f36 100644 --- a/client/src/app/quotes/components/QuotePricesResume.tsx +++ b/client/src/app/quotes/components/QuotePricesResume.tsx @@ -1,15 +1,16 @@ -import { DollarSign } from "lucide-react"; - +import { FormPercentageField } from "@/components"; import { useLocalization } from "@/lib/hooks"; -import { Card, CardContent, CardDescription, CardHeader, CardTitle, Separator } from "@/ui"; +import { Card, CardContent, CardDescription, CardTitle, Separator } from "@/ui"; +import { t } from "i18next"; import { useFormContext } from "react-hook-form"; export const QuotePricesResume = () => { - const { watch } = useFormContext(); - const { formatNumber, formatCurrency, formatPercentage } = useLocalization(); + const { watch, register, formState } = useFormContext(); + const { formatNumber, formatPercentage } = useLocalization(); const subtotal_price = formatNumber(watch("subtotal_price")); - const discount = formatPercentage(watch("discount")); + const discount_price = formatPercentage(watch("discount_price")); + const tax_price = formatPercentage(watch("tax_price")); const total_price = formatNumber(watch("total_price")); return ( @@ -25,35 +26,48 @@ export const QuotePricesResume = () => { -
+
- Descuento - - {discount} - % - + + {t("quotes.form_fields.discount.label")} + +
Imp. descuento - {subtotal_price} + {discount_price}
-
+
- IVA - - {discount} - % - + + {t("quotes.form_fields.tax.label")} + + +
Importe IVA - {subtotal_price} + {tax_price}
@@ -71,99 +85,4 @@ export const QuotePricesResume = () => { ); - - return ( - - -
-
- Descuento - - 62 - % - -
-
- Importe dto. - - 3.346 - - -
-
- -
-
-
- Importe neto -
- {subtotal_price.amount} - - {subtotal_price.currency_code} - -
-
-
- - - -
-
-
Descuento
-
-
- 73 - % -
-
-
-
-
Descuento
-
- 73 - -
-
-
- - -
-
Base imponible
-
- 14 - -
-
- -
-
IVA
-
- 14 - -
-
- -
-
Importe total
-
- 14 - -
-
-
-
- ); - - return ( - - - Total Revenue - - - -
$45,231.89
-

+20.1% from last month

-
-
- ); }; diff --git a/client/src/lib/calc.ts b/client/src/lib/calc.ts index a6ab57d..df85c83 100644 --- a/client/src/lib/calc.ts +++ b/client/src/lib/calc.ts @@ -1,7 +1,7 @@ import { MoneyValue, Percentage, Quantity } from "@shared/contexts"; export const calculateQuoteTotals = (quote: any) => { - const { discount: discount_dto /* tax: tax_dto */ } = quote; + const { discount: discount_dto, tax: tax_dto } = quote || {}; const discountOrError = Percentage.create(discount_dto); if (discountOrError.isFailure) { @@ -9,15 +9,11 @@ export const calculateQuoteTotals = (quote: any) => { } const discount = discountOrError.object; - /*const taxOrError = Percentage.create(tax_dto); + const taxOrError = Percentage.create(tax_dto); if (taxOrError.isFailure) { throw taxOrError.error; } - const tax = taxOrError.object;*/ - const tax = Percentage.create({ - amount: 2100, - scale: 2, - }).object; + const tax = taxOrError.object; const subtotalPrice = calculateQuoteItemsTotals(quote.items).convertScale(2); @@ -56,9 +52,12 @@ export const calculateQuoteItemsTotals = (items: any[]) => { }; export const calculateQuoteItemTotals = (item: any) => { - const { quantity: quantity_dto, unit_price: unit_price_dto, discount: discount_dto } = item; + const { quantity: quantity_dto, unit_price: unit_price_dto, discount: discount_dto } = item || {}; - if (quantity_dto.amount === null || unit_price_dto.amount === null) { + if ( + (quantity_dto && quantity_dto.amount === null) || + (unit_price_dto && unit_price_dto.amount === null) + ) { return { quantity: Quantity.create({ amount: quantity_dto.amount, diff --git a/client/src/locales/es.json b/client/src/locales/es.json index 0cd4891..0342087 100644 --- a/client/src/locales/es.json +++ b/client/src/locales/es.json @@ -177,6 +177,16 @@ "placeholder": "", "desc": "desc" }, + "discount": { + "label": "Descuento", + "placeholder": "", + "desc": "" + }, + "tax": { + "label": "IVA", + "placeholder": "", + "desc": "" + }, "items": { "quantity": { "label": "Cantidad",