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

@@ -7,24 +7,21 @@ import { FormattedMessage as T } from 'components';
import { CLASSES } from 'common/classes';
import PaymentReceiveHeaderFields from './PaymentReceiveHeaderFields';
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
import { compose } from 'utils';
/**
* Payment receive form header.
*/
function PaymentReceiveFormHeader({
// #withCurrentOrganization
organization: { base_currency },
}) {
function PaymentReceiveFormHeader() {
// Formik form context.
const { values } = useFormikContext();
const {
values: { currency_code, entries },
} = useFormikContext();
// Calculates the total payment amount from due amount.
const paymentFullAmount = useMemo(
() => sumBy(values.entries, 'payment_amount'),
[values.entries],
() => sumBy(entries, 'payment_amount'),
[entries],
);
return (
@@ -38,7 +35,7 @@ function PaymentReceiveFormHeader({
<T id={'amount_received'} />
</span>
<h1 class="big-amount__number">
<Money amount={paymentFullAmount} currency={base_currency} />
<Money amount={paymentFullAmount} currency={currency_code} />
</h1>
</div>
</div>
@@ -47,4 +44,4 @@ function PaymentReceiveFormHeader({
);
}
export default compose(withCurrentOrganization())(PaymentReceiveFormHeader);
export default PaymentReceiveFormHeader;

View File

@@ -153,6 +153,8 @@ function PaymentReceiveHeaderFields({
onContactSelected={(customer) => {
form.setFieldValue('customer_id', customer.id);
form.setFieldValue('full_amount', '');
form.setFieldValue('exchange_rate', '');
form.setFieldValue('currency_code', customer?.currency_code);
setSelectCustomer(customer);
}}
popoverFill={true}
@@ -207,7 +209,10 @@ function PaymentReceiveHeaderFields({
{/* ------------ Full amount ------------ */}
<Field name={'full_amount'}>
{({
form: { setFieldValue },
form: {
setFieldValue,
values: { currency_code },
},
field: { value, onChange },
meta: { error, touched },
}) => (
@@ -220,7 +225,7 @@ function PaymentReceiveHeaderFields({
helperText={<ErrorMessage name="full_amount" />}
>
<ControlGroup>
<InputPrependText text={base_currency} />
<InputPrependText text={currency_code} />
<MoneyInputGroup
value={value}
onChange={(value) => {
@@ -237,7 +242,7 @@ function PaymentReceiveHeaderFields({
minimal={true}
>
<T id={'receive_full_amount'} /> (
<Money amount={totalDueAmount} currency={base_currency} />)
<Money amount={totalDueAmount} currency={currency_code} />)
</Button>
</FormGroup>
)}