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

@@ -8,24 +8,17 @@ import { CLASSES } from 'common/classes';
import BillFormHeaderFields from './BillFormHeaderFields';
import { PageFormBigNumber } from 'components';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import { compose } from 'redux';
/**
* Fill form header.
*/
function BillFormHeader({
// #withCurrentOrganization
organization: { base_currency },
}) {
const { values } = useFormikContext();
function BillFormHeader() {
const {
values: { currency_code, entries },
} = useFormikContext();
// Calculate the total due amount of bill entries.
const totalDueAmount = useMemo(
() => sumBy(values.entries, 'amount'),
[values.entries],
);
const totalDueAmount = useMemo(() => sumBy(entries, 'amount'), [entries]);
return (
<div className={classNames(CLASSES.PAGE_FORM_HEADER)}>
@@ -33,9 +26,9 @@ function BillFormHeader({
<PageFormBigNumber
label={intl.get('due_amount')}
amount={totalDueAmount}
currencyCode={base_currency}
currencyCode={currency_code}
/>
</div>
);
}
export default compose(withCurrentOrganization())(BillFormHeader);
export default BillFormHeader;

View File

@@ -70,6 +70,7 @@ function BillFormHeader() {
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
form.setFieldValue('exchange_rate', '');
form.setFieldValue('currency_code', contact?.currency_code);
setSelectVendor(contact);
}}
popoverFill={true}

View File

@@ -8,23 +8,17 @@ import VendorCreditNoteFormHeaderFields from './VendorCreditNoteFormHeaderFields
import { getEntriesTotal } from 'containers/Entries/utils';
import { PageFormBigNumber } from 'components';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import { compose } from 'utils';
/**
* Vendor Credit note header.
*/
function VendorCreditNoteFormHeader({
// #withCurrentOrganization
organization: { base_currency },
}) {
const { values } = useFormikContext();
function VendorCreditNoteFormHeader() {
const { values:{entries ,currency_code} } = useFormikContext();
// Calculate the total amount.
const totalAmount = React.useMemo(
() => getEntriesTotal(values.entries),
[values.entries],
() => getEntriesTotal(entries),
[entries],
);
return (
@@ -33,10 +27,10 @@ function VendorCreditNoteFormHeader({
<PageFormBigNumber
label={intl.get('vendor_credits.label.amount_to_credit')}
amount={totalAmount}
currencyCode={base_currency}
currencyCode={currency_code}
/>
</div>
);
}
export default compose(withCurrentOrganization())(VendorCreditNoteFormHeader);
export default VendorCreditNoteFormHeader;

View File

@@ -108,6 +108,7 @@ function VendorCreditNoteFormHeaderFields({
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
form.setFieldValue('exchange_rate', '');
form.setFieldValue('currency_code', contact?.currency_code);
setSelectVendor(contact);
}}
popoverFill={true}

View File

@@ -3,23 +3,18 @@ import classNames from 'classnames';
import { useFormikContext } from 'formik';
import { sumBy } from 'lodash';
import { CLASSES } from 'common/classes';
import { compose } from 'utils';
import { Money } from 'components';
import { FormattedMessage as T } from 'components';
import PaymentMadeFormHeaderFields from './PaymentMadeFormHeaderFields';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
/**
* Payment made header form.
*/
function PaymentMadeFormHeader({
// #withCurrentOrganization
organization: { base_currency },
}) {
function PaymentMadeFormHeader() {
// Formik form context.
const {
values: { entries },
values: { entries, currency_code },
} = useFormikContext();
// Calculate the payment amount of the entries.
@@ -36,7 +31,7 @@ function PaymentMadeFormHeader({
<T id={'amount_received'} />
</span>
<h1 class="big-amount__number">
<Money amount={amountPaid} currency={base_currency} />
<Money amount={amountPaid} currency={currency_code} />
</h1>
</div>
</div>
@@ -45,4 +40,4 @@ function PaymentMadeFormHeader({
);
}
export default compose(withCurrentOrganization())(PaymentMadeFormHeader);
export default PaymentMadeFormHeader;

View File

@@ -111,6 +111,7 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
onContactSelected={(contact) => {
form.setFieldValue('vendor_id', contact.id);
form.setFieldValue('exchange_rate', '');
form.setFieldValue('currency_code', contact?.currency_code);
setPaymentVendorId(contact.id);
setSelectVendor(contact);
}}
@@ -162,7 +163,13 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
{/* ------------ Full amount ------------ */}
<Field name={'full_amount'}>
{({ form, field: { value }, meta: { error, touched } }) => (
{({
form: {
values: { currency_code },
},
field: { value },
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'full_amount'} />}
inline={true}
@@ -172,7 +179,7 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
helperText={<ErrorMessage name="full_amount" />}
>
<ControlGroup>
<InputPrependText text={base_currency} />
<InputPrependText text={currency_code} />
<MoneyInputGroup
value={value}
onChange={(value) => {
@@ -189,7 +196,7 @@ function PaymentMadeFormHeaderFields({ organization: { base_currency } }) {
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={payableFullAmount} currency={base_currency} />)
<Money amount={payableFullAmount} currency={currency_code} />)
</Button>
</FormGroup>
)}