fix: update financial forms to use new formatted amount utilities and add adjustment fields

This commit is contained in:
Ahmed Bouhuolia
2024-12-03 17:53:37 +02:00
parent 542763ddf5
commit 3a19518440
21 changed files with 128 additions and 133 deletions

View File

@@ -1,5 +1,6 @@
// @ts-nocheck
import React from 'react';
import { useFormikContext } from 'formik';
import EstimateNumberDialog from '@/containers/Dialogs/EstimateNumberDialog';
/**

View File

@@ -1,12 +1,10 @@
// @ts-nocheck
import React, { useMemo } from 'react';
import React from 'react';
import intl from 'react-intl-universal';
import { useFormikContext } from 'formik';
import { x } from '@xstyled/emotion';
import EstimateFormHeaderFields from './EstimateFormHeaderFields';
import { getEntriesTotal } from '@/containers/Entries/utils';
import { Group, PageFormBigNumber } from '@/components';
import { useEstimateTotalFormatted } from './utils';
// Estimate form top header.
function EstimateFormHeader() {
@@ -29,19 +27,10 @@ function EstimateFormHeader() {
* @returns {React.ReactNode}
*/
function EstimateFormBigTotal() {
const {
values: { entries, currency_code },
} = useFormikContext();
// Calculate the total due amount of bill entries.
const totalDueAmount = useMemo(() => getEntriesTotal(entries), [entries]);
const totalFormatted = useEstimateTotalFormatted();
return (
<PageFormBigNumber
label={intl.get('amount')}
amount={totalDueAmount}
currencyCode={currency_code}
/>
<PageFormBigNumber label={intl.get('amount')} amount={totalFormatted} />
);
}

View File

@@ -245,6 +245,7 @@ export const useEstimateSubtotalFormatted = () => {
*/
export const useEstimateDiscount = () => {
const { values } = useFormikContext();
const subtotal = useEstimateSubtotal();
const discount = toSafeNumber(values.discount);
return values?.discount_type === 'percentage'