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