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

@@ -10,6 +10,7 @@ import {
repeatValue,
transformToForm,
formattedAmount,
toSafeNumber,
} from '@/utils';
import { useEstimateFormContext } from './EstimateFormProvider';
import {
@@ -272,9 +273,11 @@ export const useEstimateSubtotalFormatted = () => {
*/
export const useEstimateDiscount = () => {
const { values } = useFormikContext();
const discountAmount = parseFloat(values.discount);
const discount = toSafeNumber(values.discount);
return discountAmount;
return values?.discount_type === 'percentage'
? (subtotal * discount) / 100
: discount;
};
/**
@@ -296,7 +299,7 @@ export const useEstimateDiscountFormatted = () => {
*/
export const useEstimateAdjustment = () => {
const { values } = useFormikContext();
const adjustmentAmount = parseFloat(values.adjustment);
const adjustmentAmount = toSafeNumber(values.adjustment);
return adjustmentAmount;
};