refactor: update estimate and receipt forms to use new subtotal and total formatting utilities

This commit is contained in:
Ahmed Bouhuolia
2024-12-01 18:19:09 +02:00
parent 000c3e40e1
commit 03b0d2519b
4 changed files with 47 additions and 16 deletions

View File

@@ -268,14 +268,40 @@ export const useReceiptSubtotal = () => {
return subtotal;
};
/**
* Retrieves the formatted subtotal.
* @returns {string}
*/
export const useReceiptSubtotalFormatted = () => {
const subtotal = useReceiptSubtotal();
const { values } = useFormikContext();
return formattedAmount(subtotal, values.currency_code, { money: true });
};
/**
* Retrieves the receipt discount amount.
* @returns {number}
*/
export const useReceiptDiscountAmount = () => {
const { values } = useFormikContext();
const subtotal = useReceiptSubtotal();
const discount = toSafeNumber(values.discount);
return values?.discount_type === 'percentage'
? (subtotal * discount) / 100
: discount;
};
/**
* Retrieves the formatted discount amount.
* @returns {string}
*/
export const useReceiptDiscountAmountFormatted = () => {
const { values } = useFormikContext();
const discount = useReceiptDiscountAmount();
return formattedAmount(values.discount, values.currency_code);
return formattedAmount(discount, values.currency_code);
};
/**