mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat(manual journal): add exchange rate input.
This commit is contained in:
@@ -2,5 +2,6 @@
|
||||
|
||||
export const Features = {
|
||||
Warehouses: 'warehouses',
|
||||
Branches: 'branches'
|
||||
Branches: 'branches',
|
||||
ManualJournal: 'manualJournal',
|
||||
}
|
||||
@@ -9,6 +9,7 @@ import { FastField, ErrorMessage } from 'formik';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import classNames from 'classnames';
|
||||
import { Features } from 'common';
|
||||
|
||||
import { CLASSES } from 'common/classes';
|
||||
import {
|
||||
@@ -23,8 +24,11 @@ import {
|
||||
FieldHint,
|
||||
FieldRequiredHint,
|
||||
Icon,
|
||||
If,
|
||||
FeatureCan,
|
||||
InputPrependButton,
|
||||
CurrencySelectList,
|
||||
ExchangeRateInputGroup,
|
||||
} from 'components';
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
import { useMakeJournalFormContext } from './MakeJournalProvider';
|
||||
@@ -48,7 +52,12 @@ function MakeJournalEntriesHeader({
|
||||
journalNextNumber,
|
||||
journalNumberPrefix,
|
||||
}) {
|
||||
const { currencies } = useMakeJournalFormContext();
|
||||
const {
|
||||
currencies,
|
||||
isForeignJournal,
|
||||
baseCurrency,
|
||||
setSelactJournalCurrency,
|
||||
} = useMakeJournalFormContext();
|
||||
|
||||
// Handle journal number change.
|
||||
const handleJournalNumberChange = () => {
|
||||
@@ -185,29 +194,44 @@ function MakeJournalEntriesHeader({
|
||||
</FastField>
|
||||
|
||||
{/*------------ Currency -----------*/}
|
||||
<FastField
|
||||
name={'currency_code'}
|
||||
currencies={currencies}
|
||||
shouldUpdate={currenciesFieldShouldUpdate}
|
||||
>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'currency'} />}
|
||||
className={classNames('form-group--currency', CLASSES.FILL)}
|
||||
inline={true}
|
||||
>
|
||||
<CurrencySelectList
|
||||
currenciesList={currencies}
|
||||
selectedCurrencyCode={value}
|
||||
onCurrencySelected={(currencyItem) => {
|
||||
form.setFieldValue('currency_code', currencyItem.currency_code);
|
||||
}}
|
||||
defaultSelectText={value}
|
||||
disabled={true}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/* <FeatureCan feature={Features.ManualJournal}> */}
|
||||
<FastField
|
||||
name={'currency_code'}
|
||||
currencies={currencies}
|
||||
shouldUpdate={currenciesFieldShouldUpdate}
|
||||
>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'currency'} />}
|
||||
className={classNames('form-group--currency', CLASSES.FILL)}
|
||||
inline={true}
|
||||
>
|
||||
<CurrencySelectList
|
||||
currenciesList={currencies}
|
||||
selectedCurrencyCode={value}
|
||||
onCurrencySelected={(currencyItem) => {
|
||||
form.setFieldValue(
|
||||
'currency_code',
|
||||
currencyItem.currency_code,
|
||||
);
|
||||
setSelactJournalCurrency(currencyItem);
|
||||
}}
|
||||
defaultSelectText={value}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/* </FeatureCan> */}
|
||||
|
||||
{/* ----------- Exchange rate ----------- */}
|
||||
<If condition={isForeignJournal}>
|
||||
<ExchangeRateInputGroup
|
||||
fromCurrency={'USD'}
|
||||
toCurrency={'LYD'}
|
||||
name={'exchange_rate'}
|
||||
formGroupProps={{ label: ' ', inline: true }}
|
||||
/>
|
||||
</If>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6,15 +6,22 @@ import 'style/pages/ManualJournal/MakeJournal.scss';
|
||||
import MakeJournalEntriesForm from './MakeJournalEntriesForm';
|
||||
import { MakeJournalProvider } from './MakeJournalProvider';
|
||||
|
||||
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Make journal entries page.
|
||||
*/
|
||||
export default function MakeJournalEntriesPage() {
|
||||
function MakeJournalEntriesPage({
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
}) {
|
||||
const { id: journalId } = useParams();
|
||||
|
||||
|
||||
return (
|
||||
<MakeJournalProvider journalId={journalId}>
|
||||
<MakeJournalProvider journalId={journalId} baseCurrency={base_currency}>
|
||||
<MakeJournalEntriesForm />
|
||||
</MakeJournalProvider>
|
||||
);
|
||||
}
|
||||
export default compose(withCurrentOrganization())(MakeJournalEntriesPage);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { createContext, useState } from 'react';
|
||||
import { isEqual, isUndefined } from 'lodash';
|
||||
import DashboardInsider from 'components/Dashboard/DashboardInsider';
|
||||
import {
|
||||
useAccounts,
|
||||
@@ -8,7 +9,7 @@ import {
|
||||
useCreateJournal,
|
||||
useEditJournal,
|
||||
useSettings,
|
||||
useSettingsManualJournals
|
||||
useSettingsManualJournals,
|
||||
} from 'hooks/query';
|
||||
|
||||
const MakeJournalFormContext = createContext();
|
||||
@@ -16,15 +17,13 @@ const MakeJournalFormContext = createContext();
|
||||
/**
|
||||
* Make journal form provider.
|
||||
*/
|
||||
function MakeJournalProvider({ journalId, ...props }) {
|
||||
function MakeJournalProvider({ journalId, baseCurrency, ...props }) {
|
||||
// Load the accounts list.
|
||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||
|
||||
// Load the customers list.
|
||||
const {
|
||||
data: contacts,
|
||||
isLoading: isContactsLoading,
|
||||
} = useAutoCompleteContacts();
|
||||
const { data: contacts, isLoading: isContactsLoading } =
|
||||
useAutoCompleteContacts();
|
||||
|
||||
// Load the currencies list.
|
||||
const { data: currencies, isLoading: isCurrenciesLoading } = useCurrencies();
|
||||
@@ -45,12 +44,18 @@ function MakeJournalProvider({ journalId, ...props }) {
|
||||
|
||||
// Submit form payload.
|
||||
const [submitPayload, setSubmitPayload] = useState({});
|
||||
const [selectJournalCurrency, setSelactJournalCurrency] = useState(null);
|
||||
|
||||
const isForeignJournal =
|
||||
!isEqual(selectJournalCurrency?.currency_code, baseCurrency) &&
|
||||
!isUndefined(selectJournalCurrency?.currency_code);
|
||||
|
||||
const provider = {
|
||||
accounts,
|
||||
contacts,
|
||||
currencies,
|
||||
manualJournal,
|
||||
baseCurrency,
|
||||
|
||||
createJournalMutate,
|
||||
editJournalMutate,
|
||||
@@ -60,11 +65,13 @@ function MakeJournalProvider({ journalId, ...props }) {
|
||||
isCurrenciesLoading,
|
||||
isJournalLoading,
|
||||
isSettingsLoading,
|
||||
|
||||
isForeignJournal,
|
||||
isNewMode: !journalId,
|
||||
|
||||
submitPayload,
|
||||
setSubmitPayload
|
||||
setSubmitPayload,
|
||||
selectJournalCurrency,
|
||||
setSelactJournalCurrency,
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -73,7 +80,7 @@ function MakeJournalProvider({ journalId, ...props }) {
|
||||
isJournalLoading ||
|
||||
isAccountsLoading ||
|
||||
isCurrenciesLoading ||
|
||||
isContactsLoading ||
|
||||
isContactsLoading ||
|
||||
isSettingsLoading
|
||||
}
|
||||
name={'make-journal-page'}
|
||||
|
||||
Reference in New Issue
Block a user