feat(Sales & Purchases ): add currency in header & entries.

This commit is contained in:
elforjani13
2022-02-23 14:47:12 +02:00
parent e6a7c7bc58
commit 22eb7a1cc1
17 changed files with 83 additions and 106 deletions

View File

@@ -9,24 +9,16 @@ import InvoiceFormHeaderFields from './InvoiceFormHeaderFields';
import { getEntriesTotal } from 'containers/Entries/utils';
import { PageFormBigNumber } from 'components';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import { compose } from 'redux';
/**
* Invoice form header section.
*/
function InvoiceFormHeader({
// #withCurrentOrganization
organization: { base_currency },
}) {
const { values } = useFormikContext();
function InvoiceFormHeader() {
const {
values: { currency_code, entries },
} = useFormikContext();
// Calculate the total due amount of invoice entries.
const totalDueAmount = useMemo(
() => getEntriesTotal(values.entries),
[values.entries],
);
const totalDueAmount = useMemo(() => getEntriesTotal(entries), [entries]);
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
@@ -34,9 +26,9 @@ function InvoiceFormHeader({
<PageFormBigNumber
label={intl.get('due_amount')}
amount={totalDueAmount}
currencyCode={base_currency}
currencyCode={currency_code}
/>
</div>
);
}
export default compose(withCurrentOrganization())(InvoiceFormHeader);
export default InvoiceFormHeader;

View File

@@ -116,6 +116,7 @@ function InvoiceFormHeaderFields({
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
form.setFieldValue('exchange_rate', '');
form.setFieldValue('currency_code', customer?.currency_code);
setSelectCustomer(customer);
}}
popoverFill={true}

View File

@@ -91,6 +91,10 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
!isEqual(selectCustomer?.currency_code, baseCurrency) &&
!isUndefined(selectCustomer?.currency_code);
const currencyCode = isForeignCustomer
? selectCustomer?.currency_code
: baseCurrency;
const provider = {
invoice,
items,
@@ -103,6 +107,7 @@ function InvoiceFormProvider({ invoiceId, baseCurrency, ...props }) {
baseCurrency,
branches,
warehouses,
currencyCode,
isInvoiceLoading,
isItemsLoading,