mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
refactor: update estimate and receipt forms to use new subtotal and total formatting utilities
This commit is contained in:
@@ -6,13 +6,15 @@ import { T, TotalLines, TotalLine, TotalLineTextStyle } from '@/components';
|
||||
import {
|
||||
useEstimateAdjustmentFormatted,
|
||||
useEstimateDiscountFormatted,
|
||||
useEstimateTotals,
|
||||
useEstimateSubtotalFormatted,
|
||||
useEstimateTotalFormatted,
|
||||
} from './utils';
|
||||
import { AdjustmentTotalLine } from '../../Invoices/InvoiceForm/AdjustmentTotalLine';
|
||||
import { DiscountTotalLine } from '../../Invoices/InvoiceForm/DiscountTotalLine';
|
||||
|
||||
export function EstimateFormFooterRight() {
|
||||
const { formattedSubtotal, formattedTotal } = useEstimateTotals();
|
||||
const subtotalFormatted = useEstimateSubtotalFormatted();
|
||||
const totalFormatted = useEstimateTotalFormatted();
|
||||
const {
|
||||
values: { currency_code },
|
||||
} = useFormikContext();
|
||||
@@ -23,7 +25,7 @@ export function EstimateFormFooterRight() {
|
||||
<EstimateTotalLines labelColWidth={'180px'} amountColWidth={'180px'}>
|
||||
<TotalLine
|
||||
title={<T id={'estimate_form.label.subtotal'} />}
|
||||
value={formattedSubtotal}
|
||||
value={subtotalFormatted}
|
||||
/>
|
||||
<DiscountTotalLine
|
||||
currencyCode={currency_code}
|
||||
@@ -32,7 +34,7 @@ export function EstimateFormFooterRight() {
|
||||
<AdjustmentTotalLine adjustmentAmount={adjustmentAmount} />
|
||||
<TotalLine
|
||||
title={<T id={'estimate_form.label.total'} />}
|
||||
value={formattedTotal}
|
||||
value={totalFormatted}
|
||||
textStyle={TotalLineTextStyle.Bold}
|
||||
/>
|
||||
</EstimateTotalLines>
|
||||
|
||||
@@ -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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user