mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
feat(moneyIn): add exchange rate detail.
This commit is contained in:
@@ -2,10 +2,12 @@ import React from 'react';
|
|||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
import {
|
import {
|
||||||
useCreateCashflowTransaction,
|
useCreateCashflowTransaction,
|
||||||
|
useAccount,
|
||||||
useAccounts,
|
useAccounts,
|
||||||
useCashflowAccounts,
|
useCashflowAccounts,
|
||||||
useSettingCashFlow,
|
useSettingCashFlow,
|
||||||
} from 'hooks/query';
|
} from 'hooks/query';
|
||||||
|
import { isEqual, isUndefined } from 'lodash';
|
||||||
|
|
||||||
const MoneyInDialogContent = React.createContext();
|
const MoneyInDialogContent = React.createContext();
|
||||||
|
|
||||||
@@ -21,6 +23,11 @@ function MoneyInDialogProvider({
|
|||||||
// Fetches accounts list.
|
// Fetches accounts list.
|
||||||
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
||||||
|
|
||||||
|
// Fetches the specific account details.
|
||||||
|
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
||||||
|
enabled: !!accountId,
|
||||||
|
});
|
||||||
|
|
||||||
// Fetch cash flow list .
|
// Fetch cash flow list .
|
||||||
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
||||||
useCashflowAccounts({}, { keepPreviousData: true });
|
useCashflowAccounts({}, { keepPreviousData: true });
|
||||||
@@ -34,9 +41,14 @@ function MoneyInDialogProvider({
|
|||||||
// Submit payload.
|
// Submit payload.
|
||||||
const [submitPayload, setSubmitPayload] = React.useState({});
|
const [submitPayload, setSubmitPayload] = React.useState({});
|
||||||
|
|
||||||
|
// Determines whether the foreign currency.
|
||||||
|
const isForeignCurrency = (toCurrency, fromCurrency) =>
|
||||||
|
!isEqual(toCurrency, fromCurrency) && !isUndefined(toCurrency);
|
||||||
|
|
||||||
// provider.
|
// provider.
|
||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
accounts,
|
||||||
|
account,
|
||||||
accountId,
|
accountId,
|
||||||
accountType,
|
accountType,
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
@@ -48,6 +60,7 @@ function MoneyInDialogProvider({
|
|||||||
|
|
||||||
createCashflowTransactionMutate,
|
createCashflowTransactionMutate,
|
||||||
setSubmitPayload,
|
setSubmitPayload,
|
||||||
|
isForeignCurrency,
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ const defaultInitialValues = {
|
|||||||
reference_no: '',
|
reference_no: '',
|
||||||
cashflow_account_id: '',
|
cashflow_account_id: '',
|
||||||
credit_account_id: '',
|
credit_account_id: '',
|
||||||
|
currency_code: '',
|
||||||
description: '',
|
description: '',
|
||||||
publish: '',
|
publish: '',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage } from 'formik';
|
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import {
|
import {
|
||||||
Classes,
|
Classes,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
@@ -18,7 +18,9 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
|
If,
|
||||||
InputPrependButton,
|
InputPrependButton,
|
||||||
|
ExchangeRateInputGroup,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { useAutofocus } from 'hooks';
|
import { useAutofocus } from 'hooks';
|
||||||
@@ -50,7 +52,9 @@ function OwnerContributionFormFields({
|
|||||||
transactionNextNumber,
|
transactionNextNumber,
|
||||||
}) {
|
}) {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts } = useMoneyInDailogContext();
|
const { accounts, account, isForeignCurrency } = useMoneyInDailogContext();
|
||||||
|
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
const amountFieldRef = useAutofocus();
|
const amountFieldRef = useAutofocus();
|
||||||
|
|
||||||
@@ -151,7 +155,7 @@ function OwnerContributionFormFields({
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ amount -----------*/}
|
{/*------------ amount -----------*/}
|
||||||
<FastField name={'amount'}>
|
<Field name={'amount'}>
|
||||||
{({
|
{({
|
||||||
form: { values, setFieldValue },
|
form: { values, setFieldValue },
|
||||||
field: { value },
|
field: { value },
|
||||||
@@ -165,7 +169,7 @@ function OwnerContributionFormFields({
|
|||||||
className={'form-group--amount'}
|
className={'form-group--amount'}
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={values.currency_code} />
|
<InputPrependText text={account?.currency_code} />
|
||||||
|
|
||||||
<MoneyInputGroup
|
<MoneyInputGroup
|
||||||
value={value}
|
value={value}
|
||||||
@@ -179,7 +183,22 @@ function OwnerContributionFormFields({
|
|||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</Field>
|
||||||
|
|
||||||
|
{/*------------ exchange rate -----------*/}
|
||||||
|
<If
|
||||||
|
condition={isForeignCurrency(
|
||||||
|
account?.currency_code,
|
||||||
|
values?.currency_code,
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<ExchangeRateInputGroup
|
||||||
|
fromCurrency={values?.currency_code}
|
||||||
|
toCurrency={account?.currency_code}
|
||||||
|
name={'exchange_rate'}
|
||||||
|
formGroupProps={{ label: ' ', inline: false }}
|
||||||
|
/>
|
||||||
|
</If>
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
@@ -195,9 +214,10 @@ function OwnerContributionFormFields({
|
|||||||
>
|
>
|
||||||
<AccountsSuggestField
|
<AccountsSuggestField
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
onAccountSelected={({ id }) =>
|
onAccountSelected={(account) => {
|
||||||
form.setFieldValue('credit_account_id', id)
|
form.setFieldValue('credit_account_id', account.id);
|
||||||
}
|
form.setFieldValue('currency_code', account.currency_code);
|
||||||
|
}}
|
||||||
filterByTypes={ACCOUNT_TYPE.EQUITY}
|
filterByTypes={ACCOUNT_TYPE.EQUITY}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
intent: inputIntent({ error, touched }),
|
intent: inputIntent({ error, touched }),
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ export default function WarehouseLocationsTable() {
|
|||||||
isFetching: isItemWarehousesFetching,
|
isFetching: isItemWarehousesFetching,
|
||||||
data: itemWarehouses,
|
data: itemWarehouses,
|
||||||
} = useItemWarehouseLocation(itemId, { enabled: !!itemId });
|
} = useItemWarehouseLocation(itemId, { enabled: !!itemId });
|
||||||
console.log(itemWarehouses, 'XXX');
|
|
||||||
return (
|
return (
|
||||||
<WarehouseLocationsGLEntriesRoot>
|
<WarehouseLocationsGLEntriesRoot>
|
||||||
<DataTable
|
<DataTable
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ function CreditNoteForm({
|
|||||||
credit_note_number: creditNumber,
|
credit_note_number: creditNumber,
|
||||||
}),
|
}),
|
||||||
entries: orderingLinesIndexes(defaultCreditNote.entries),
|
entries: orderingLinesIndexes(defaultCreditNote.entries),
|
||||||
|
currency_code: base_currency,
|
||||||
...newCreditNote,
|
...newCreditNote,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
|
|||||||
Reference in New Issue
Block a user