mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 06:10:31 +00:00
refactor: implementing new formatted amount hooks
This commit is contained in:
@@ -13,13 +13,13 @@ import { AdjustmentTotalLine } from '../../Invoices/InvoiceForm/AdjustmentTotalL
|
||||
import { DiscountTotalLine } from '../../Invoices/InvoiceForm/DiscountTotalLine';
|
||||
|
||||
export function EstimateFormFooterRight() {
|
||||
const subtotalFormatted = useEstimateSubtotalFormatted();
|
||||
const totalFormatted = useEstimateTotalFormatted();
|
||||
const {
|
||||
values: { currency_code },
|
||||
} = useFormikContext();
|
||||
const discountAmount = useEstimateDiscountFormatted();
|
||||
const adjustmentAmount = useEstimateAdjustmentFormatted();
|
||||
const subtotalFormatted = useEstimateSubtotalFormatted();
|
||||
const totalFormatted = useEstimateTotalFormatted();
|
||||
const discountAmountFormatted = useEstimateDiscountFormatted();
|
||||
const adjustmentAmountFormatted = useEstimateAdjustmentFormatted();
|
||||
|
||||
return (
|
||||
<EstimateTotalLines labelColWidth={'180px'} amountColWidth={'180px'}>
|
||||
@@ -29,9 +29,9 @@ export function EstimateFormFooterRight() {
|
||||
/>
|
||||
<DiscountTotalLine
|
||||
currencyCode={currency_code}
|
||||
discountAmount={discountAmount}
|
||||
discountAmount={discountAmountFormatted}
|
||||
/>
|
||||
<AdjustmentTotalLine adjustmentAmount={adjustmentAmount} />
|
||||
<AdjustmentTotalLine adjustmentAmount={adjustmentAmountFormatted} />
|
||||
<TotalLine
|
||||
title={<T id={'estimate_form.label.total'} />}
|
||||
value={totalFormatted}
|
||||
|
||||
@@ -6,7 +6,7 @@ import * as R from 'ramda';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { ExchangeRateInputGroup } from '@/components';
|
||||
import { useCurrentOrganization } from '@/hooks/state';
|
||||
import { useEstimateIsForeignCustomer, useEstimateTotals } from './utils';
|
||||
import { useEstimateIsForeignCustomer, useEstimateSubtotal } from './utils';
|
||||
import { transactionNumber } from '@/utils';
|
||||
import { useUpdateEffect } from '@/hooks';
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
@@ -102,13 +102,13 @@ export const EstimateSyncAutoExRateToForm = R.compose(withDialogActions)(
|
||||
// #withDialogActions
|
||||
openDialog,
|
||||
}) => {
|
||||
const { total } = useEstimateTotals();
|
||||
const subtotal = useEstimateSubtotal();
|
||||
const timeout = useRef();
|
||||
|
||||
useSyncExRateToForm({
|
||||
onSynced: () => {
|
||||
// If the total bigger then zero show alert to the user after adjusting entries.
|
||||
if (total > 0) {
|
||||
if (subtotal > 0) {
|
||||
clearTimeout(timeout.current);
|
||||
timeout.current = setTimeout(() => {
|
||||
openDialog(DialogsName.InvoiceExchangeRateChangeNotice);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// @ts-nocheck
|
||||
import React from 'react';
|
||||
import React, { useMemo } from 'react';
|
||||
import * as R from 'ramda';
|
||||
import intl from 'react-intl-universal';
|
||||
import moment from 'moment';
|
||||
@@ -64,6 +64,7 @@ export const defaultEstimate = {
|
||||
entries: [...repeatValue(defaultEstimateEntry, MIN_LINES_NUMBER)],
|
||||
attachments: [],
|
||||
pdf_template_id: '',
|
||||
adjustment: '',
|
||||
discount: '',
|
||||
discount_type: 'amount',
|
||||
};
|
||||
@@ -210,35 +211,6 @@ export const useSetPrimaryBranchToForm = () => {
|
||||
}, [isBranchesSuccess, setFieldValue, branches]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Retreives the estimate totals.
|
||||
*/
|
||||
export const useEstimateTotals = () => {
|
||||
const {
|
||||
values: { entries, currency_code: currencyCode },
|
||||
} = useFormikContext();
|
||||
|
||||
// Retrieves the invoice entries total.
|
||||
const total = React.useMemo(() => getEntriesTotal(entries), [entries]);
|
||||
|
||||
// Retrieves the formatted total money.
|
||||
const formattedTotal = React.useMemo(
|
||||
() => formattedAmount(total, currencyCode),
|
||||
[total, currencyCode],
|
||||
);
|
||||
// Retrieves the formatted subtotal.
|
||||
const formattedSubtotal = React.useMemo(
|
||||
() => formattedAmount(total, currencyCode, { money: false }),
|
||||
[total, currencyCode],
|
||||
);
|
||||
|
||||
return {
|
||||
total,
|
||||
formattedTotal,
|
||||
formattedSubtotal,
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the estimate subtotal.
|
||||
* @returns {number}
|
||||
@@ -249,9 +221,9 @@ export const useEstimateSubtotal = () => {
|
||||
} = useFormikContext();
|
||||
|
||||
// Retrieves the invoice entries total.
|
||||
const total = React.useMemo(() => getEntriesTotal(entries), [entries]);
|
||||
const subtotal = useMemo(() => getEntriesTotal(entries), [entries]);
|
||||
|
||||
return total;
|
||||
return subtotal;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user