mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
Merge pull request #179 from bigcapitalhq/abouhuolia/big-29-no-currency-in-amount-field-on-money-inout-dialogs
fix(webapp): No currency in amount field on money in/out dialogs
This commit is contained in:
@@ -25,6 +25,7 @@ import {
|
|||||||
CashflowAction,
|
CashflowAction,
|
||||||
PreferencesAbility,
|
PreferencesAbility,
|
||||||
} from '@/constants/abilityOption';
|
} from '@/constants/abilityOption';
|
||||||
|
import { DialogsName } from './dialogs';
|
||||||
|
|
||||||
export const SidebarMenu = [
|
export const SidebarMenu = [
|
||||||
// ---------------
|
// ---------------
|
||||||
@@ -114,7 +115,7 @@ export const SidebarMenu = [
|
|||||||
text: <T id={'sidebar.new_item_category'} />,
|
text: <T id={'sidebar.new_item_category'} />,
|
||||||
href: '/items/categories/new',
|
href: '/items/categories/new',
|
||||||
type: ISidebarMenuItemType.Dialog,
|
type: ISidebarMenuItemType.Dialog,
|
||||||
dialogName: 'item-category-form',
|
dialogName: DialogsName.ItemCategoryForm,
|
||||||
permission: {
|
permission: {
|
||||||
subject: AbilitySubject.Item,
|
subject: AbilitySubject.Item,
|
||||||
ability: ItemAction.Create,
|
ability: ItemAction.Create,
|
||||||
@@ -458,7 +459,7 @@ export const SidebarMenu = [
|
|||||||
text: <T id={'sidebar.add_money_in'} />,
|
text: <T id={'sidebar.add_money_in'} />,
|
||||||
href: '/cashflow-accounts',
|
href: '/cashflow-accounts',
|
||||||
type: ISidebarMenuItemType.Dialog,
|
type: ISidebarMenuItemType.Dialog,
|
||||||
dialogName: 'money-in',
|
dialogName: DialogsName.MoneyInForm,
|
||||||
permission: {
|
permission: {
|
||||||
subject: AbilitySubject.Cashflow,
|
subject: AbilitySubject.Cashflow,
|
||||||
ability: CashflowAction.Create,
|
ability: CashflowAction.Create,
|
||||||
@@ -468,6 +469,7 @@ export const SidebarMenu = [
|
|||||||
text: <T id={'sidebar.add_money_out'} />,
|
text: <T id={'sidebar.add_money_out'} />,
|
||||||
href: '/cashflow-accounts',
|
href: '/cashflow-accounts',
|
||||||
type: ISidebarMenuItemType.Dialog,
|
type: ISidebarMenuItemType.Dialog,
|
||||||
|
dialogName: DialogsName.MoneyOutForm,
|
||||||
permission: {
|
permission: {
|
||||||
subject: AbilitySubject.Cashflow,
|
subject: AbilitySubject.Cashflow,
|
||||||
ability: CashflowAction.Create,
|
ability: CashflowAction.Create,
|
||||||
@@ -477,6 +479,7 @@ export const SidebarMenu = [
|
|||||||
text: <T id={'sidebar.add_cash_account'} />,
|
text: <T id={'sidebar.add_cash_account'} />,
|
||||||
href: '/cashflow-accounts',
|
href: '/cashflow-accounts',
|
||||||
type: ISidebarMenuItemType.Dialog,
|
type: ISidebarMenuItemType.Dialog,
|
||||||
|
dialogName: DialogsName.AccountForm,
|
||||||
permission: {
|
permission: {
|
||||||
subject: AbilitySubject.Cashflow,
|
subject: AbilitySubject.Cashflow,
|
||||||
ability: CashflowAction.Create,
|
ability: CashflowAction.Create,
|
||||||
@@ -486,6 +489,7 @@ export const SidebarMenu = [
|
|||||||
text: <T id={'sidebar.add_bank_account'} />,
|
text: <T id={'sidebar.add_bank_account'} />,
|
||||||
href: '/cashflow-accounts',
|
href: '/cashflow-accounts',
|
||||||
type: ISidebarMenuItemType.Dialog,
|
type: ISidebarMenuItemType.Dialog,
|
||||||
|
dialogName: DialogsName.AccountForm,
|
||||||
permission: {
|
permission: {
|
||||||
subject: AbilitySubject.Cashflow,
|
subject: AbilitySubject.Cashflow,
|
||||||
ability: CashflowAction.Create,
|
ability: CashflowAction.Create,
|
||||||
|
|||||||
@@ -1,18 +1,22 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import OwnerContributionFormFields from './OwnerContribution/OwnerContributionFormFields';
|
import OwnerContributionFormFields from './OwnerContribution/OwnerContributionFormFields';
|
||||||
import OtherIncomeFormFields from './OtherIncome/OtherIncomeFormFields';
|
import OtherIncomeFormFields from './OtherIncome/OtherIncomeFormFields';
|
||||||
import TransferFromAccountFormFields from './TransferFromAccount/TransferFromAccountFormFields';
|
import TransferFromAccountFormFields from './TransferFromAccount/TransferFromAccountFormFields';
|
||||||
|
import { MoneyInFieldsProvider } from './MoneyInFieldsProvider';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Money-in dialog content.
|
||||||
* @param param0
|
* Switches between fields based on the given transaction type.
|
||||||
* @returns
|
* @returns {JSX.Element}
|
||||||
*/
|
*/
|
||||||
export default function MoneyInContentFields({ accountType }) {
|
export default function MoneyInContentFields() {
|
||||||
const handleTransactionType = () => {
|
const { values } = useFormikContext();
|
||||||
switch (accountType) {
|
|
||||||
|
const transactionFields = useMemo(() => {
|
||||||
|
switch (values.transaction_type) {
|
||||||
case 'owner_contribution':
|
case 'owner_contribution':
|
||||||
return <OwnerContributionFormFields />;
|
return <OwnerContributionFormFields />;
|
||||||
|
|
||||||
@@ -24,6 +28,10 @@ export default function MoneyInContentFields({ accountType }) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}, [values.transaction_type]);
|
||||||
return <React.Fragment>{handleTransactionType()}</React.Fragment>;
|
|
||||||
|
// Cannot continue if transaction type or account is not selected.
|
||||||
|
if (!values.transaction_type || !values.cashflow_account_id) return null;
|
||||||
|
|
||||||
|
return <MoneyInFieldsProvider>{transactionFields}</MoneyInFieldsProvider>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { MoneyInDialogProvider } from './MoneyInDialogProvider';
|
import { MoneyInDialogProvider } from './MoneyInDialogProvider';
|
||||||
import MoneyInForm from './MoneyInForm';
|
import MoneyInForm from './MoneyInForm';
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { DialogContent } from '@/components';
|
import { DialogContent } from '@/components';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
import { useFeatureCan } from '@/hooks/state';
|
||||||
import {
|
import {
|
||||||
useCreateCashflowTransaction,
|
useCreateCashflowTransaction,
|
||||||
useAccount,
|
|
||||||
useAccounts,
|
useAccounts,
|
||||||
useBranches,
|
useBranches,
|
||||||
useCashflowAccounts,
|
useCashflowAccounts,
|
||||||
@@ -18,22 +17,21 @@ const MoneyInDialogContent = React.createContext();
|
|||||||
* Money in dialog provider.
|
* Money in dialog provider.
|
||||||
*/
|
*/
|
||||||
function MoneyInDialogProvider({
|
function MoneyInDialogProvider({
|
||||||
accountId,
|
accountId: defaultAccountId,
|
||||||
accountType,
|
accountType,
|
||||||
dialogName,
|
dialogName,
|
||||||
...props
|
...props
|
||||||
}) {
|
}) {
|
||||||
|
// Holds the selected account id of the dialog.
|
||||||
|
const [accountId, setAccountId] = useState<number | null>(defaultAccountId);
|
||||||
|
|
||||||
|
// Detarmines whether the feature is enabled.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||||
|
|
||||||
// Fetches accounts list.
|
// Fetches accounts list.
|
||||||
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
||||||
|
|
||||||
// Fetches the specific account details.
|
|
||||||
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
|
||||||
enabled: !!accountId,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetches the branches list.
|
// Fetches the branches list.
|
||||||
const {
|
const {
|
||||||
data: branches,
|
data: branches,
|
||||||
@@ -41,10 +39,11 @@ function MoneyInDialogProvider({
|
|||||||
isSuccess: isBranchesSuccess,
|
isSuccess: isBranchesSuccess,
|
||||||
} = useBranches({}, { enabled: isBranchFeatureCan });
|
} = useBranches({}, { enabled: isBranchFeatureCan });
|
||||||
|
|
||||||
// Fetch cash flow list .
|
// Fetch cash flow list.
|
||||||
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
||||||
useCashflowAccounts({}, { keepPreviousData: true });
|
useCashflowAccounts({}, { keepPreviousData: true });
|
||||||
|
|
||||||
|
// Mutation create cashflow transaction.
|
||||||
const { mutateAsync: createCashflowTransactionMutate } =
|
const { mutateAsync: createCashflowTransactionMutate } =
|
||||||
useCreateCashflowTransaction();
|
useCreateCashflowTransaction();
|
||||||
|
|
||||||
@@ -57,9 +56,12 @@ function MoneyInDialogProvider({
|
|||||||
// Provider data.
|
// Provider data.
|
||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
accounts,
|
||||||
account,
|
|
||||||
branches,
|
branches,
|
||||||
|
|
||||||
accountId,
|
accountId,
|
||||||
|
defaultAccountId,
|
||||||
|
setAccountId,
|
||||||
|
|
||||||
accountType,
|
accountType,
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
isBranchesSuccess,
|
isBranchesSuccess,
|
||||||
@@ -77,8 +79,7 @@ function MoneyInDialogProvider({
|
|||||||
isAccountsLoading ||
|
isAccountsLoading ||
|
||||||
isCashFlowAccountsLoading ||
|
isCashFlowAccountsLoading ||
|
||||||
isBranchesLoading ||
|
isBranchesLoading ||
|
||||||
isSettingsLoading ||
|
isSettingsLoading;
|
||||||
isAccountLoading;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isLoading}>
|
<DialogContent isLoading={isLoading}>
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
|
import { ExchangeRateMutedField } from '@/components';
|
||||||
|
import { useForeignAccount } from './utils';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
import { useMoneyInFieldsContext } from './MoneyInFieldsProvider';
|
||||||
|
|
||||||
|
export function MoneyInExchangeRateField() {
|
||||||
|
const { account } = useMoneyInFieldsContext();
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
const isForeigAccount = useForeignAccount();
|
||||||
|
|
||||||
|
if (!isForeigAccount) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ExchangeRateMutedField
|
||||||
|
name={'exchange_rate'}
|
||||||
|
fromCurrency={values.currency_code}
|
||||||
|
toCurrency={account.currency_code}
|
||||||
|
formGroupProps={{ label: '', inline: false }}
|
||||||
|
date={values.date}
|
||||||
|
exchangeRate={values.exchange_rate}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
|
import { DialogContent } from '@/components';
|
||||||
|
import { useAccount } from '@/hooks/query';
|
||||||
|
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
||||||
|
|
||||||
|
const MoneyInFieldsContext = React.createContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money in dialog provider.
|
||||||
|
*/
|
||||||
|
function MoneyInFieldsProvider({ ...props }) {
|
||||||
|
const { accountId } = useMoneyInDailogContext();
|
||||||
|
|
||||||
|
// Fetches the specific account details.
|
||||||
|
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
||||||
|
enabled: !!accountId,
|
||||||
|
});
|
||||||
|
// Provider data.
|
||||||
|
const provider = {
|
||||||
|
account,
|
||||||
|
};
|
||||||
|
const isLoading = isAccountLoading;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent isLoading={isLoading}>
|
||||||
|
<MoneyInFieldsContext.Provider value={provider} {...props} />
|
||||||
|
</DialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const useMoneyInFieldsContext = () => React.useContext(MoneyInFieldsContext);
|
||||||
|
|
||||||
|
export { MoneyInFieldsProvider, useMoneyInFieldsContext };
|
||||||
@@ -53,7 +53,6 @@ function MoneyInForm({
|
|||||||
accountId,
|
accountId,
|
||||||
accountType,
|
accountType,
|
||||||
createCashflowTransactionMutate,
|
createCashflowTransactionMutate,
|
||||||
submitPayload,
|
|
||||||
} = useMoneyInDailogContext();
|
} = useMoneyInDailogContext();
|
||||||
|
|
||||||
// transaction number.
|
// transaction number.
|
||||||
@@ -61,7 +60,6 @@ function MoneyInForm({
|
|||||||
transactionNumberPrefix,
|
transactionNumberPrefix,
|
||||||
transactionNextNumber,
|
transactionNextNumber,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Initial form values.
|
// Initial form values.
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
@@ -95,15 +93,13 @@ function MoneyInForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Formik
|
||||||
<Formik
|
validationSchema={CreateMoneyInFormSchema}
|
||||||
validationSchema={CreateMoneyInFormSchema}
|
initialValues={initialValues}
|
||||||
initialValues={initialValues}
|
onSubmit={handleFormSubmit}
|
||||||
onSubmit={handleFormSubmit}
|
>
|
||||||
>
|
<MoneyInFormContent />
|
||||||
<MoneyInFormContent />
|
</Formik>
|
||||||
</Formik>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,17 +12,13 @@ import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
|||||||
* Money in form fields.
|
* Money in form fields.
|
||||||
*/
|
*/
|
||||||
function MoneyInFormFields() {
|
function MoneyInFormFields() {
|
||||||
const { values } = useFormikContext();
|
|
||||||
|
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accountId } = useMoneyInDailogContext();
|
const { defaultAccountId } = useMoneyInDailogContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
<If condition={!accountId}>
|
{!defaultAccountId && <TransactionTypeFields />}
|
||||||
<TransactionTypeFields />
|
<MoneyInContentFields />
|
||||||
</If>
|
|
||||||
<MoneyInContentFields accountType={values.transaction_type} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import {
|
import {
|
||||||
Classes,
|
Classes,
|
||||||
FormGroup,
|
FormGroup,
|
||||||
InputGroup,
|
|
||||||
TextArea,
|
TextArea,
|
||||||
Position,
|
Position,
|
||||||
ControlGroup,
|
ControlGroup,
|
||||||
@@ -18,14 +17,15 @@ import {
|
|||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
If,
|
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
ExchangeRateMutedField,
|
FInputGroup,
|
||||||
|
FFormGroup,
|
||||||
|
FTextArea,
|
||||||
|
FMoneyInputGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { useAutofocus } from '@/hooks';
|
|
||||||
import { CLASSES, ACCOUNT_TYPE, Features } from '@/constants';
|
import { CLASSES, ACCOUNT_TYPE, Features } from '@/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
@@ -36,22 +36,18 @@ import {
|
|||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
|
|
||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||||
import {
|
import { useSetPrimaryBranchToForm, BranchRowDivider } from '../utils';
|
||||||
useSetPrimaryBranchToForm,
|
|
||||||
useForeignAccount,
|
|
||||||
BranchRowDivider,
|
|
||||||
} from '../utils';
|
|
||||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||||
|
import { useMoneyInFieldsContext } from '../MoneyInFieldsProvider';
|
||||||
|
import { MoneyInExchangeRateField } from '../MoneyInExchangeRateField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other income form fields.
|
* Other income form fields.
|
||||||
*/
|
*/
|
||||||
export default function OtherIncomeFormFields() {
|
export default function OtherIncomeFormFields() {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts, account, branches } = useMoneyInDailogContext();
|
const { accounts, branches } = useMoneyInDailogContext();
|
||||||
const { values } = useFormikContext();
|
const { account } = useMoneyInFieldsContext();
|
||||||
const amountFieldRef = useAutofocus();
|
|
||||||
const isForeigAccount = useForeignAccount();
|
|
||||||
|
|
||||||
// Sets the primary branch to form.
|
// Sets the primary branch to form.
|
||||||
useSetPrimaryBranchToForm();
|
useSetPrimaryBranchToForm();
|
||||||
@@ -61,17 +57,14 @@ export default function OtherIncomeFormFields() {
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup name={'amount'} label={<T id={'branch'} />}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
input={BranchSelectButton}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
@@ -113,48 +106,25 @@ export default function OtherIncomeFormFields() {
|
|||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/*------------ amount -----------*/}
|
{/*------------ Amount -----------*/}
|
||||||
<FastField name={'amount'}>
|
<Row>
|
||||||
{({
|
<Col xs={10}>
|
||||||
form: { values, setFieldValue },
|
<FFormGroup
|
||||||
field: { value },
|
name={'amount'}
|
||||||
meta: { error, touched },
|
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'amount'} />}
|
label={<T id={'amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="amount" />}
|
|
||||||
className={'form-group--amount'}
|
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={account.currency_code} />
|
<InputPrependText text={account.currency_code} />
|
||||||
|
<FMoneyInputGroup name={'amount'} minimal={true} />
|
||||||
<MoneyInputGroup
|
|
||||||
value={value}
|
|
||||||
minimal={true}
|
|
||||||
onChange={(amount) => {
|
|
||||||
setFieldValue('amount', amount);
|
|
||||||
}}
|
|
||||||
inputRef={(ref) => (amountFieldRef.current = ref)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
)}
|
</Col>
|
||||||
</FastField>
|
</Row>
|
||||||
|
|
||||||
|
{/*------------ Exchange rate -----------*/}
|
||||||
|
<MoneyInExchangeRateField />
|
||||||
|
|
||||||
<If condition={isForeigAccount}>
|
|
||||||
{/*------------ exchange rate -----------*/}
|
|
||||||
<ExchangeRateMutedField
|
|
||||||
name={'exchange_rate'}
|
|
||||||
fromCurrency={values.currency_code}
|
|
||||||
toCurrency={account.currency_code}
|
|
||||||
formGroupProps={{ label: '', inline: false }}
|
|
||||||
date={values.date}
|
|
||||||
exchangeRate={values.exchange_rate}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ other income account -----------*/}
|
{/*------------ other income account -----------*/}
|
||||||
@@ -184,43 +154,24 @@ export default function OtherIncomeFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference_no'}>
|
<FFormGroup label={<T id={'reference_no'} />} name={'reference_no'}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
<FInputGroup name={'reference_no'} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'reference_no'} />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="reference_no" />}
|
|
||||||
className={'form-group--reference-no'}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ description -----------*/}
|
|
||||||
<FastField name={'description'}>
|
{/*------------ Description -----------*/}
|
||||||
{({ field, meta: { error, touched } }) => (
|
<FFormGroup name={'description'} label={<T id={'description'} />}>
|
||||||
<FormGroup
|
<FTextArea
|
||||||
label={<T id={'description'} />}
|
name={'description'}
|
||||||
className={'form-group--description'}
|
growVertically={true}
|
||||||
intent={inputIntent({ error, touched })}
|
large={true}
|
||||||
helperText={<ErrorMessage name={'description'} />}
|
fill={true}
|
||||||
>
|
/>
|
||||||
<TextArea
|
</FFormGroup>
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,32 +1,24 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import {
|
import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
|
||||||
Classes,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
TextArea,
|
|
||||||
Position,
|
|
||||||
ControlGroup,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
If,
|
|
||||||
ExchangeRateMutedField,
|
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
|
FFormGroup,
|
||||||
|
FMoneyInputGroup,
|
||||||
|
FTextArea,
|
||||||
|
FInputGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
|
||||||
import { useAutofocus } from '@/hooks';
|
|
||||||
import { ACCOUNT_TYPE, CLASSES, Features } from '@/constants';
|
import { ACCOUNT_TYPE, CLASSES, Features } from '@/constants';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
@@ -37,10 +29,11 @@ import {
|
|||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||||
import {
|
import {
|
||||||
useSetPrimaryBranchToForm,
|
useSetPrimaryBranchToForm,
|
||||||
useForeignAccount,
|
|
||||||
BranchRowDivider,
|
BranchRowDivider,
|
||||||
} from '../../MoneyInDialog/utils';
|
} from '../../MoneyInDialog/utils';
|
||||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||||
|
import { useMoneyInFieldsContext } from '../MoneyInFieldsProvider';
|
||||||
|
import { MoneyInExchangeRateField } from '../MoneyInExchangeRateField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
/**
|
/**
|
||||||
@@ -48,13 +41,8 @@ import { MoneyInOutTransactionNoField } from '../../_components';
|
|||||||
*/
|
*/
|
||||||
export default function OwnerContributionFormFields() {
|
export default function OwnerContributionFormFields() {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts, account, branches } = useMoneyInDailogContext();
|
const { accounts, branches } = useMoneyInDailogContext();
|
||||||
|
const { account } = useMoneyInFieldsContext();
|
||||||
const { values } = useFormikContext();
|
|
||||||
|
|
||||||
const amountFieldRef = useAutofocus();
|
|
||||||
|
|
||||||
const isForeigAccount = useForeignAccount();
|
|
||||||
|
|
||||||
// Sets the primary branch to form.
|
// Sets the primary branch to form.
|
||||||
useSetPrimaryBranchToForm();
|
useSetPrimaryBranchToForm();
|
||||||
@@ -64,21 +52,19 @@ export default function OwnerContributionFormFields() {
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup name={'branch_id'} label={<T id={'branch'} />}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
input={BranchSelectButton}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
</FeatureCan>
|
</FeatureCan>
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -113,47 +99,26 @@ export default function OwnerContributionFormFields() {
|
|||||||
<MoneyInOutTransactionNoField />
|
<MoneyInOutTransactionNoField />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ amount -----------*/}
|
|
||||||
<Field name={'amount'}>
|
{/*------------ Amount -----------*/}
|
||||||
{({
|
<Row>
|
||||||
form: { values, setFieldValue },
|
<Col xs={10}>
|
||||||
field: { value },
|
<FFormGroup
|
||||||
meta: { error, touched },
|
name={'amount'}
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'amount'} />}
|
label={<T id={'amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="amount" />}
|
|
||||||
className={'form-group--amount'}
|
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={account?.currency_code} />
|
<InputPrependText text={account?.currency_code || '--'} />
|
||||||
|
<FMoneyInputGroup name={'amount'} minimal={true} />
|
||||||
<MoneyInputGroup
|
|
||||||
value={value}
|
|
||||||
minimal={true}
|
|
||||||
onChange={(amount) => {
|
|
||||||
setFieldValue('amount', amount);
|
|
||||||
}}
|
|
||||||
inputRef={(ref) => (amountFieldRef.current = ref)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
)}
|
</Col>
|
||||||
</Field>
|
</Row>
|
||||||
<If condition={isForeigAccount}>
|
|
||||||
{/*------------ exchange rate -----------*/}
|
{/*------------ Exchange rate -----------*/}
|
||||||
<ExchangeRateMutedField
|
<MoneyInExchangeRateField />
|
||||||
name={'exchange_rate'}
|
|
||||||
fromCurrency={values.currency_code}
|
|
||||||
toCurrency={account.currency_code}
|
|
||||||
formGroupProps={{ label: '', inline: false }}
|
|
||||||
date={values.date}
|
|
||||||
exchangeRate={values.exchange_rate}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ equity account -----------*/}
|
{/*------------ equity account -----------*/}
|
||||||
@@ -181,43 +146,24 @@ export default function OwnerContributionFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference_no'}>
|
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
<FInputGroup name={'reference_no'} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'reference_no'} />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="reference_no" />}
|
|
||||||
className={'form-group--reference-no'}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ description -----------*/}
|
|
||||||
<FastField name={'description'}>
|
{/*------------ Description -----------*/}
|
||||||
{({ field, meta: { error, touched } }) => (
|
<FFormGroup name={'description'} label={<T id={'description'} />}>
|
||||||
<FormGroup
|
<FTextArea
|
||||||
label={<T id={'description'} />}
|
name={'description'}
|
||||||
className={'form-group--description'}
|
growVertically={true}
|
||||||
intent={inputIntent({ error, touched })}
|
large={true}
|
||||||
helperText={<ErrorMessage name={'description'} />}
|
fill={true}
|
||||||
>
|
/>
|
||||||
<TextArea
|
</FFormGroup>
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ import {
|
|||||||
ListSelect,
|
ListSelect,
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
|
FFormGroup,
|
||||||
|
FSelect,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { inputIntent } from '@/utils';
|
import { inputIntent } from '@/utils';
|
||||||
import { CLASSES, getAddMoneyInOptions } from '@/constants';
|
import { CLASSES, getAddMoneyInOptions } from '@/constants';
|
||||||
@@ -21,7 +23,7 @@ import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
|||||||
*/
|
*/
|
||||||
export default function TransactionTypeFields() {
|
export default function TransactionTypeFields() {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { cashflowAccounts } = useMoneyInDailogContext();
|
const { cashflowAccounts, setAccountId } = useMoneyInDailogContext();
|
||||||
|
|
||||||
// Retrieves the add money in button options.
|
// Retrieves the add money in button options.
|
||||||
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
|
const addMoneyInOptions = useMemo(() => getAddMoneyInOptions(), []);
|
||||||
@@ -29,6 +31,23 @@ export default function TransactionTypeFields() {
|
|||||||
return (
|
return (
|
||||||
<div className="trasnaction-type-fileds">
|
<div className="trasnaction-type-fileds">
|
||||||
<Row>
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
{/*------------ Transaction type -----------*/}
|
||||||
|
<FFormGroup
|
||||||
|
name={'transaction_type'}
|
||||||
|
label={<T id={'transaction_type'} />}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
>
|
||||||
|
<FSelect
|
||||||
|
name={'transaction_type'}
|
||||||
|
items={addMoneyInOptions}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
valueAccessor={'value'}
|
||||||
|
textAccessor={'name'}
|
||||||
|
/>
|
||||||
|
</FFormGroup>
|
||||||
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Current account -----------*/}
|
{/*------------ Current account -----------*/}
|
||||||
<FastField name={'cashflow_account_id'}>
|
<FastField name={'cashflow_account_id'}>
|
||||||
@@ -46,9 +65,10 @@ export default function TransactionTypeFields() {
|
|||||||
>
|
>
|
||||||
<AccountsSuggestField
|
<AccountsSuggestField
|
||||||
accounts={cashflowAccounts}
|
accounts={cashflowAccounts}
|
||||||
onAccountSelected={({ id }) =>
|
onAccountSelected={({ id }) => {
|
||||||
form.setFieldValue('cashflow_account_id', id)
|
form.setFieldValue('cashflow_account_id', id);
|
||||||
}
|
setAccountId(id);
|
||||||
|
}}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
intent: inputIntent({ error, touched }),
|
intent: inputIntent({ error, touched }),
|
||||||
}}
|
}}
|
||||||
@@ -56,39 +76,6 @@ export default function TransactionTypeFields() {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
{/*------------ Transaction type -----------*/}
|
|
||||||
</Col>
|
|
||||||
<Col xs={5}>
|
|
||||||
<Field name={'transaction_type'}>
|
|
||||||
{({
|
|
||||||
form: { values, setFieldValue },
|
|
||||||
field: { value },
|
|
||||||
meta: { error, touched },
|
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'transaction_type'} />}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
helperText={<ErrorMessage name="transaction_type" />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
className={classNames(
|
|
||||||
CLASSES.FILL,
|
|
||||||
'form-group--transaction_type',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<ListSelect
|
|
||||||
items={addMoneyInOptions}
|
|
||||||
onItemSelect={(type) => {
|
|
||||||
setFieldValue('transaction_type', type.value);
|
|
||||||
}}
|
|
||||||
filterable={false}
|
|
||||||
selectedItem={value}
|
|
||||||
selectedItemProp={'value'}
|
|
||||||
textProp={'name'}
|
|
||||||
popoverProps={{ minimal: true }}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,33 +1,27 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import {
|
import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
|
||||||
Classes,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
TextArea,
|
|
||||||
Position,
|
|
||||||
ControlGroup,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
If,
|
|
||||||
ExchangeRateMutedField,
|
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
|
FMoneyInputGroup,
|
||||||
|
FInputGroup,
|
||||||
|
FFormGroup,
|
||||||
|
FTextArea,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { useAutofocus } from '@/hooks';
|
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||||
|
import { MoneyInExchangeRateField } from '../MoneyInExchangeRateField';
|
||||||
import { CLASSES, ACCOUNT_TYPE, Features } from '@/constants';
|
import { CLASSES, ACCOUNT_TYPE, Features } from '@/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
@@ -35,25 +29,19 @@ import {
|
|||||||
handleDateChange,
|
handleDateChange,
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
||||||
|
import { useMoneyInFieldsContext } from '../MoneyInFieldsProvider';
|
||||||
import {
|
import {
|
||||||
useSetPrimaryBranchToForm,
|
useSetPrimaryBranchToForm,
|
||||||
useForeignAccount,
|
|
||||||
BranchRowDivider,
|
BranchRowDivider,
|
||||||
} from '../../MoneyInDialog/utils';
|
} from '../../MoneyInDialog/utils';
|
||||||
|
|
||||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfer from account form fields.
|
* Transfer from account form fields.
|
||||||
*/
|
*/
|
||||||
export default function TransferFromAccountFormFields() {
|
export default function TransferFromAccountFormFields() {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts, account, branches } = useMoneyInDailogContext();
|
const { accounts, branches } = useMoneyInDailogContext();
|
||||||
|
const { account } = useMoneyInFieldsContext();
|
||||||
const isForeigAccount = useForeignAccount();
|
|
||||||
const amountFieldRef = useAutofocus();
|
|
||||||
|
|
||||||
const { values } = useFormikContext();
|
|
||||||
|
|
||||||
// Sets the primary branch to form.
|
// Sets the primary branch to form.
|
||||||
useSetPrimaryBranchToForm();
|
useSetPrimaryBranchToForm();
|
||||||
@@ -63,17 +51,14 @@ export default function TransferFromAccountFormFields() {
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup label={<T id={'branch'} />} name={'branch_id'}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
input={BranchSelectButton}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
@@ -112,50 +97,27 @@ export default function TransferFromAccountFormFields() {
|
|||||||
<MoneyInOutTransactionNoField />
|
<MoneyInOutTransactionNoField />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ amount -----------*/}
|
{/*------------ Amount -----------*/}
|
||||||
<FastField name={'amount'}>
|
<Row>
|
||||||
{({
|
<Col xs={10}>
|
||||||
form: { values, setFieldValue },
|
|
||||||
field: { value },
|
|
||||||
meta: { error, touched },
|
|
||||||
}) => (
|
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'amount'} />}
|
label={<T id={'amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="amount" />}
|
|
||||||
className={'form-group--amount'}
|
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={account.currency_code} />
|
<InputPrependText text={account.currency_code || '--'} />
|
||||||
|
<FMoneyInputGroup name={'amount'} minimal={true} />
|
||||||
<MoneyInputGroup
|
|
||||||
value={value}
|
|
||||||
minimal={true}
|
|
||||||
onChange={(amount) => {
|
|
||||||
setFieldValue('amount', amount);
|
|
||||||
}}
|
|
||||||
inputRef={(ref) => (amountFieldRef.current = ref)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
</Col>
|
||||||
</FastField>
|
</Row>
|
||||||
<If condition={isForeigAccount}>
|
|
||||||
{/*------------ exchange rate -----------*/}
|
{/*------------ Exchange rate -----------*/}
|
||||||
<ExchangeRateMutedField
|
<MoneyInExchangeRateField />
|
||||||
name={'exchange_rate'}
|
|
||||||
fromCurrency={values.currency_code}
|
|
||||||
toCurrency={account.currency_code}
|
|
||||||
formGroupProps={{ label: '', inline: false }}
|
|
||||||
date={values.date}
|
|
||||||
exchangeRate={values.exchange_rate}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ transfer from account -----------*/}
|
{/*------------ Transfer from account -----------*/}
|
||||||
<FastField name={'credit_account_id'}>
|
<FastField name={'credit_account_id'}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
{({ form, field, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
@@ -185,43 +147,24 @@ export default function TransferFromAccountFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference_no'}>
|
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
<FInputGroup name={'reference_no'} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'reference_no'} />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="reference_no" />}
|
|
||||||
className={'form-group--reference-no'}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ description -----------*/}
|
|
||||||
<FastField name={'description'}>
|
{/*------------ Description -----------*/}
|
||||||
{({ field, meta: { error, touched } }) => (
|
<FormGroup name={'description'} label={<T id={'description'} />}>
|
||||||
<FormGroup
|
<FTextArea
|
||||||
label={<T id={'description'} />}
|
name={'description'}
|
||||||
className={'form-group--description'}
|
growVertically={true}
|
||||||
intent={inputIntent({ error, touched })}
|
large={true}
|
||||||
helperText={<ErrorMessage name={'description'} />}
|
fill={true}
|
||||||
>
|
/>
|
||||||
<TextArea
|
</FormGroup>
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import React from 'react';
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Dialog, DialogSuspense } from '@/components';
|
import { Dialog, DialogSuspense } from '@/components';
|
||||||
import withDialogRedux from '@/components/DialogReduxConnect';
|
import withDialogRedux from '@/components/DialogReduxConnect';
|
||||||
|
|
||||||
import { compose } from '@/utils';
|
import { compose } from '@/utils';
|
||||||
|
|
||||||
const MoneyInDialogContent = React.lazy(() => import('./MoneyInDialogContent'));
|
const MoneyInDialogContent = React.lazy(() => import('./MoneyInDialogContent'));
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { transactionNumber } from '@/utils';
|
|||||||
import { isEqual, isNull, first } from 'lodash';
|
import { isEqual, isNull, first } from 'lodash';
|
||||||
|
|
||||||
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
||||||
|
import { useMoneyInFieldsContext } from './MoneyInFieldsProvider';
|
||||||
|
|
||||||
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
@@ -33,7 +34,7 @@ export const useSetPrimaryBranchToForm = () => {
|
|||||||
|
|
||||||
export const useForeignAccount = () => {
|
export const useForeignAccount = () => {
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
const { account } = useMoneyInDailogContext();
|
const { account } = useMoneyInFieldsContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
!isEqual(account.currency_code, values.currency_code) &&
|
!isEqual(account.currency_code, values.currency_code) &&
|
||||||
|
|||||||
@@ -1,13 +1,22 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
import OtherExpnseFormFields from './OtherExpense/OtherExpnseFormFields';
|
import OtherExpnseFormFields from './OtherExpense/OtherExpnseFormFields';
|
||||||
import OwnerDrawingsFormFields from './OwnerDrawings/OwnerDrawingsFormFields';
|
import OwnerDrawingsFormFields from './OwnerDrawings/OwnerDrawingsFormFields';
|
||||||
import TransferToAccountFormFields from './TransferToAccount/TransferToAccountFormFields';
|
import TransferToAccountFormFields from './TransferToAccount/TransferToAccountFormFields';
|
||||||
|
import { MoneyOutFieldsProvider } from './MoneyOutFieldsProvider';
|
||||||
|
|
||||||
function MoneyOutContentFields({ accountType }) {
|
/**
|
||||||
const handleTransactionType = () => {
|
* Money out content fields.
|
||||||
switch (accountType) {
|
* Switches between form fields based on the given transaction type.
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
function MoneyOutContentFields() {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
const transactionType = useMemo(() => {
|
||||||
|
switch (values.transaction_type) {
|
||||||
case 'OwnerDrawing':
|
case 'OwnerDrawing':
|
||||||
return <OwnerDrawingsFormFields />;
|
return <OwnerDrawingsFormFields />;
|
||||||
|
|
||||||
@@ -19,8 +28,12 @@ function MoneyOutContentFields({ accountType }) {
|
|||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}, [values.transaction_type]);
|
||||||
return <React.Fragment>{handleTransactionType()}</React.Fragment>;
|
|
||||||
|
// Cannot continue if transaction type or account is not selected.
|
||||||
|
if (!values.transaction_type || !values.cashflow_account_id) return null;
|
||||||
|
|
||||||
|
return <MoneyOutFieldsProvider>{transactionType}</MoneyOutFieldsProvider>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MoneyOutContentFields;
|
export default MoneyOutContentFields;
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React, { useState } from 'react';
|
||||||
import { DialogContent } from '@/components';
|
import { DialogContent } from '@/components';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
import { useFeatureCan } from '@/hooks/state';
|
import { useFeatureCan } from '@/hooks/state';
|
||||||
import {
|
import {
|
||||||
useAccounts,
|
useAccounts,
|
||||||
useAccount,
|
|
||||||
useBranches,
|
useBranches,
|
||||||
useCreateCashflowTransaction,
|
useCreateCashflowTransaction,
|
||||||
useCashflowAccounts,
|
useCashflowAccounts,
|
||||||
@@ -17,7 +16,15 @@ const MoneyInDialogContent = React.createContext();
|
|||||||
/**
|
/**
|
||||||
* Money out dialog provider.
|
* Money out dialog provider.
|
||||||
*/
|
*/
|
||||||
function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
|
function MoneyOutProvider({
|
||||||
|
accountId: defaultAccountId,
|
||||||
|
accountType,
|
||||||
|
dialogName,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
|
// Holds the selected account id of the dialog.
|
||||||
|
const [accountId, setAccountId] = useState<number | null>(defaultAccountId);
|
||||||
|
|
||||||
// Features guard.
|
// Features guard.
|
||||||
const { featureCan } = useFeatureCan();
|
const { featureCan } = useFeatureCan();
|
||||||
const isBranchFeatureCan = featureCan(Features.Branches);
|
const isBranchFeatureCan = featureCan(Features.Branches);
|
||||||
@@ -25,11 +32,6 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
|
|||||||
// Fetches accounts list.
|
// Fetches accounts list.
|
||||||
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
const { isLoading: isAccountsLoading, data: accounts } = useAccounts();
|
||||||
|
|
||||||
// Fetches the specific account details.
|
|
||||||
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
|
||||||
enabled: !!accountId,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Fetches the branches list.
|
// Fetches the branches list.
|
||||||
const {
|
const {
|
||||||
data: branches,
|
data: branches,
|
||||||
@@ -41,6 +43,7 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
|
|||||||
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
||||||
useCashflowAccounts({}, { keepPreviousData: true });
|
useCashflowAccounts({}, { keepPreviousData: true });
|
||||||
|
|
||||||
|
// Mutation to create a new cashflow account.
|
||||||
const { mutateAsync: createCashflowTransactionMutate } =
|
const { mutateAsync: createCashflowTransactionMutate } =
|
||||||
useCreateCashflowTransaction();
|
useCreateCashflowTransaction();
|
||||||
|
|
||||||
@@ -52,9 +55,11 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
|
|||||||
|
|
||||||
// Provider data.
|
// Provider data.
|
||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
|
||||||
account,
|
|
||||||
accountId,
|
accountId,
|
||||||
|
setAccountId,
|
||||||
|
defaultAccountId,
|
||||||
|
|
||||||
|
accounts,
|
||||||
accountType,
|
accountType,
|
||||||
branches,
|
branches,
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
@@ -73,8 +78,7 @@ function MoneyOutProvider({ accountId, accountType, dialogName, ...props }) {
|
|||||||
isAccountsLoading ||
|
isAccountsLoading ||
|
||||||
isCashFlowAccountsLoading ||
|
isCashFlowAccountsLoading ||
|
||||||
isBranchesLoading ||
|
isBranchesLoading ||
|
||||||
isSettingsLoading ||
|
isSettingsLoading;
|
||||||
isAccountLoading;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isLoading}>
|
<DialogContent isLoading={isLoading}>
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
import { useForeignAccount } from './utils';
|
||||||
|
import { ExchangeRateMutedField } from '@/components';
|
||||||
|
import { useMoneyOutFieldsContext } from './MoneyOutFieldsProvider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money-out exchange rate field.
|
||||||
|
* @returns {JSX.Element}
|
||||||
|
*/
|
||||||
|
export function MoneyOutExchangeRateField() {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
const { account } = useMoneyOutFieldsContext();
|
||||||
|
const isForeigAccount = useForeignAccount();
|
||||||
|
|
||||||
|
// Cannot continue if the account is not foreign account.
|
||||||
|
if (!isForeigAccount) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<ExchangeRateMutedField
|
||||||
|
name={'exchange_rate'}
|
||||||
|
fromCurrency={values?.currency_code}
|
||||||
|
toCurrency={account?.currency_code}
|
||||||
|
formGroupProps={{ label: '', inline: false }}
|
||||||
|
date={values.date}
|
||||||
|
exchangeRate={values.exchange_rate}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
// @ts-nocheck
|
||||||
|
import React from 'react';
|
||||||
|
import { DialogContent } from '@/components';
|
||||||
|
import { useAccount } from '@/hooks/query';
|
||||||
|
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
|
||||||
|
|
||||||
|
const MoneyOutFieldsContext = React.createContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money out fields dialog provider.
|
||||||
|
*/
|
||||||
|
function MoneyOutFieldsProvider({ ...props }) {
|
||||||
|
const { accountId } = useMoneyOutDialogContext();
|
||||||
|
|
||||||
|
// Fetches the specific account details.
|
||||||
|
const { data: account, isLoading: isAccountLoading } = useAccount(accountId, {
|
||||||
|
enabled: !!accountId,
|
||||||
|
});
|
||||||
|
// Provider data.
|
||||||
|
const provider = {
|
||||||
|
account,
|
||||||
|
};
|
||||||
|
const isLoading = isAccountLoading;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent isLoading={isLoading}>
|
||||||
|
<MoneyOutFieldsContext.Provider value={provider} {...props} />
|
||||||
|
</DialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const useMoneyOutFieldsContext = () => React.useContext(MoneyOutFieldsContext);
|
||||||
|
|
||||||
|
export { MoneyOutFieldsProvider, useMoneyOutFieldsContext };
|
||||||
@@ -24,18 +24,16 @@ function MoneyOutFloatingActions({
|
|||||||
useMoneyOutDialogContext();
|
useMoneyOutDialogContext();
|
||||||
|
|
||||||
// handle submit as draft button click.
|
// handle submit as draft button click.
|
||||||
const handleSubmitDraftBtnClick = (event) => {
|
const handleSubmitDraftBtnClick = () => {
|
||||||
setSubmitPayload({ publish: false });
|
setSubmitPayload({ publish: false });
|
||||||
submitForm();
|
submitForm();
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle submit button click.
|
// Handle submit button click.
|
||||||
const handleSubmittBtnClick = (event) => {
|
const handleSubmittBtnClick = () => {
|
||||||
setSubmitPayload({ publish: true });
|
setSubmitPayload({ publish: true });
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle close button click.
|
// Handle close button click.
|
||||||
const handleCloseBtnClick = (event) => {
|
const handleCloseBtnClick = () => {
|
||||||
closeDialog(dialogName);
|
closeDialog(dialogName);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -92,15 +92,13 @@ function MoneyOutForm({
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<div>
|
<Formik
|
||||||
<Formik
|
validationSchema={CreateMoneyOutSchema}
|
||||||
validationSchema={CreateMoneyOutSchema}
|
initialValues={initialValues}
|
||||||
initialValues={initialValues}
|
onSubmit={handleFormSubmit}
|
||||||
onSubmit={handleFormSubmit}
|
>
|
||||||
>
|
<MoneyOutFormContent />
|
||||||
<MoneyOutFormContent />
|
</Formik>
|
||||||
</Formik>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export default function MoneyOutFormDialog() {
|
|||||||
setFieldValue('transaction_number', incrementNumber || '');
|
setFieldValue('transaction_number', incrementNumber || '');
|
||||||
setFieldValue('transaction_number_manually', manually);
|
setFieldValue('transaction_number_manually', manually);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<TransactionNumberDialog
|
<TransactionNumberDialog
|
||||||
|
|||||||
@@ -1,28 +1,18 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { useFormikContext } from 'formik';
|
|
||||||
import { Classes } from '@blueprintjs/core';
|
import { Classes } from '@blueprintjs/core';
|
||||||
|
|
||||||
import { If } from '@/components';
|
|
||||||
|
|
||||||
import MoneyOutContentFields from './MoneyOutContentFields';
|
import MoneyOutContentFields from './MoneyOutContentFields';
|
||||||
import TransactionTypeFields from './TransactionTypeFields';
|
import TransactionTypeFields from './TransactionTypeFields';
|
||||||
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Money out form fields.
|
* Money out form fields.
|
||||||
*/
|
*/
|
||||||
function MoneyOutFormFields() {
|
function MoneyOutFormFields() {
|
||||||
// Money in dialog context.
|
|
||||||
const { accountId } = useMoneyOutDialogContext();
|
|
||||||
|
|
||||||
const { values } = useFormikContext();
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<div className={Classes.DIALOG_BODY}>
|
||||||
<If condition={!accountId}>
|
<TransactionTypeFields />
|
||||||
<TransactionTypeFields />
|
<MoneyOutContentFields />
|
||||||
</If>
|
|
||||||
<MoneyOutContentFields accountType={values.transaction_type} />
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,33 +1,25 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import {
|
import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
|
||||||
Classes,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
TextArea,
|
|
||||||
Position,
|
|
||||||
ControlGroup,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
If,
|
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
ExchangeRateMutedField,
|
FTextArea,
|
||||||
|
FFormGroup,
|
||||||
|
FInputGroup,
|
||||||
|
FMoneyInputGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { useAutofocus } from '@/hooks';
|
|
||||||
import { Features, ACCOUNT_TYPE } from '@/constants';
|
import { Features, ACCOUNT_TYPE } from '@/constants';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
@@ -36,25 +28,18 @@ import {
|
|||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
||||||
import {
|
import { useSetPrimaryBranchToForm, BranchRowDivider } from '../utils';
|
||||||
useSetPrimaryBranchToForm,
|
|
||||||
useForeignAccount,
|
|
||||||
BranchRowDivider,
|
|
||||||
} from '../utils';
|
|
||||||
|
|
||||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||||
|
import { MoneyOutExchangeRateField } from '../MoneyOutExchangeRateField';
|
||||||
|
import { useMoneyOutFieldsContext } from '../MoneyOutFieldsProvider';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Other expense form fields.
|
* Other expense form fields.
|
||||||
*/
|
*/
|
||||||
export default function OtherExpnseFormFields() {
|
export default function OtherExpnseFormFields() {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts, account, branches } = useMoneyOutDialogContext();
|
const { accounts, branches } = useMoneyOutDialogContext();
|
||||||
|
const { account } = useMoneyOutFieldsContext();
|
||||||
const isForeigAccount = useForeignAccount();
|
|
||||||
const { values } = useFormikContext();
|
|
||||||
|
|
||||||
const amountFieldRef = useAutofocus();
|
|
||||||
|
|
||||||
// Sets the primary branch to form.
|
// Sets the primary branch to form.
|
||||||
useSetPrimaryBranchToForm();
|
useSetPrimaryBranchToForm();
|
||||||
@@ -64,21 +49,19 @@ export default function OtherExpnseFormFields() {
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup name={'branch_id'} label={<T id={'branch'} />}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
input={BranchSelectButton}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
</FeatureCan>
|
</FeatureCan>
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -113,47 +96,27 @@ export default function OtherExpnseFormFields() {
|
|||||||
<MoneyInOutTransactionNoField />
|
<MoneyInOutTransactionNoField />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/*------------ amount -----------*/}
|
{/*------------ amount -----------*/}
|
||||||
<FastField name={'amount'}>
|
|
||||||
{({
|
<Row>
|
||||||
form: { values, setFieldValue },
|
<Col xs={10}>
|
||||||
field: { value },
|
<FFormGroup
|
||||||
meta: { error, touched },
|
name={'amount'}
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'amount'} />}
|
label={<T id={'amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="amount" />}
|
|
||||||
className={'form-group--amount'}
|
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={account.currency_code} />
|
<InputPrependText text={account.currency_code} />
|
||||||
|
<FMoneyInputGroup name={'amount'} minimal={true} />
|
||||||
<MoneyInputGroup
|
|
||||||
value={value}
|
|
||||||
minimal={true}
|
|
||||||
onChange={(amount) => {
|
|
||||||
setFieldValue('amount', amount);
|
|
||||||
}}
|
|
||||||
inputRef={(ref) => (amountFieldRef.current = ref)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
)}
|
</Col>
|
||||||
</FastField>
|
</Row>
|
||||||
<If condition={isForeigAccount}>
|
|
||||||
{/*------------ exchange rate -----------*/}
|
{/*------------ Exchange rate -----------*/}
|
||||||
<ExchangeRateMutedField
|
<MoneyOutExchangeRateField />
|
||||||
name={'exchange_rate'}
|
|
||||||
fromCurrency={values.currency_code}
|
|
||||||
toCurrency={account.currency_code}
|
|
||||||
formGroupProps={{ label: '', inline: false }}
|
|
||||||
date={values.date}
|
|
||||||
exchangeRate={values.exchange_rate}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ other expense account -----------*/}
|
{/*------------ other expense account -----------*/}
|
||||||
@@ -183,44 +146,24 @@ export default function OtherExpnseFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference_no'}>
|
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
<FInputGroup name={'reference_no'} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'reference_no'} />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="reference_no" />}
|
|
||||||
className={'form-group--reference-no'}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/*------------ description -----------*/}
|
{/*------------ description -----------*/}
|
||||||
<FastField name={'description'}>
|
<FFormGroup name={'description'} label={<T id={'description'} />}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
<FTextArea
|
||||||
<FormGroup
|
name={'description'}
|
||||||
label={<T id={'description'} />}
|
growVertically={true}
|
||||||
className={'form-group--description'}
|
large={true}
|
||||||
intent={inputIntent({ error, touched })}
|
fill={true}
|
||||||
helperText={<ErrorMessage name={'description'} />}
|
/>
|
||||||
>
|
</FFormGroup>
|
||||||
<TextArea
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,31 +1,24 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import {
|
import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
|
||||||
Classes,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
TextArea,
|
|
||||||
Position,
|
|
||||||
ControlGroup,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
If,
|
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
ExchangeRateMutedField,
|
FFormGroup,
|
||||||
|
FTextArea,
|
||||||
|
FInputGroup,
|
||||||
|
FMoneyInputGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { useAutofocus } from '@/hooks';
|
|
||||||
import { CLASSES, Features, ACCOUNT_TYPE } from '@/constants';
|
import { CLASSES, Features, ACCOUNT_TYPE } from '@/constants';
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
@@ -36,21 +29,19 @@ import {
|
|||||||
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
||||||
import {
|
import {
|
||||||
useSetPrimaryBranchToForm,
|
useSetPrimaryBranchToForm,
|
||||||
useForeignAccount,
|
|
||||||
BranchRowDivider,
|
BranchRowDivider,
|
||||||
} from '../../MoneyOutDialog/utils';
|
} from '../../MoneyOutDialog/utils';
|
||||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||||
|
import { useMoneyOutFieldsContext } from '../MoneyOutFieldsProvider';
|
||||||
|
import { MoneyOutExchangeRateField } from '../MoneyOutExchangeRateField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Owner drawings form fields.
|
* Owner drawings form fields.
|
||||||
*/
|
*/
|
||||||
export default function OwnerDrawingsFormFields() {
|
export default function OwnerDrawingsFormFields() {
|
||||||
// Money out dialog context.
|
// Money out dialog context.
|
||||||
const { accounts, account, branches } = useMoneyOutDialogContext();
|
const { accounts, branches } = useMoneyOutDialogContext();
|
||||||
const { values } = useFormikContext();
|
const { account } = useMoneyOutFieldsContext();
|
||||||
const isForeigAccount = useForeignAccount();
|
|
||||||
|
|
||||||
const amountFieldRef = useAutofocus();
|
|
||||||
|
|
||||||
// Sets the primary branch to form.
|
// Sets the primary branch to form.
|
||||||
useSetPrimaryBranchToForm();
|
useSetPrimaryBranchToForm();
|
||||||
@@ -60,21 +51,19 @@ export default function OwnerDrawingsFormFields() {
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup label={<T id={'branch'} />} name={'branch_id'}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
input={BranchSelectButton}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
</FeatureCan>
|
</FeatureCan>
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -109,48 +98,27 @@ export default function OwnerDrawingsFormFields() {
|
|||||||
<MoneyInOutTransactionNoField />
|
<MoneyInOutTransactionNoField />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ amount -----------*/}
|
|
||||||
<Field name={'amount'}>
|
{/*------------ Amount -----------*/}
|
||||||
{({
|
|
||||||
form: { values, setFieldValue },
|
<Row>
|
||||||
field: { value },
|
<Col xs={10}>
|
||||||
meta: { error, touched },
|
|
||||||
}) => (
|
|
||||||
<FormGroup
|
<FormGroup
|
||||||
|
name={'amount'}
|
||||||
label={<T id={'amount'} />}
|
label={<T id={'amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="amount" />}
|
|
||||||
className={'form-group--amount'}
|
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={account.currency_code} />
|
<InputPrependText text={account.currency_code} />
|
||||||
|
<FMoneyInputGroup name={'amount'} minimal={true} />
|
||||||
<MoneyInputGroup
|
|
||||||
value={value}
|
|
||||||
minimal={true}
|
|
||||||
onChange={(amount) => {
|
|
||||||
setFieldValue('amount', amount);
|
|
||||||
}}
|
|
||||||
inputRef={(ref) => (amountFieldRef.current = ref)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
</Col>
|
||||||
</Field>
|
</Row>
|
||||||
|
|
||||||
|
{/*------------ Exchange rate -----------*/}
|
||||||
|
<MoneyOutExchangeRateField />
|
||||||
|
|
||||||
<If condition={isForeigAccount}>
|
|
||||||
{/*------------ exchange rate -----------*/}
|
|
||||||
<ExchangeRateMutedField
|
|
||||||
name={'exchange_rate'}
|
|
||||||
fromCurrency={values?.currency_code}
|
|
||||||
toCurrency={account?.currency_code}
|
|
||||||
formGroupProps={{ label: '', inline: false }}
|
|
||||||
date={values.date}
|
|
||||||
exchangeRate={values.exchange_rate}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ equitty account -----------*/}
|
{/*------------ equitty account -----------*/}
|
||||||
@@ -177,44 +145,24 @@ export default function OwnerDrawingsFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference_no'}>
|
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
<FInputGroup name={'reference_no'} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'reference_no'} />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="reference_no" />}
|
|
||||||
className={'form-group--reference-no'}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/*------------ description -----------*/}
|
{/*------------ description -----------*/}
|
||||||
<FastField name={'description'}>
|
<FFormGroup name={'description'} label={<T id={'description'} />}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
<FTextArea
|
||||||
<FormGroup
|
name={'description'}
|
||||||
label={<T id={'description'} />}
|
growVertically={true}
|
||||||
className={'form-group--description'}
|
large={true}
|
||||||
intent={inputIntent({ error, touched })}
|
fill={true}
|
||||||
helperText={<ErrorMessage name={'description'} />}
|
/>
|
||||||
>
|
</FFormGroup>
|
||||||
<TextArea
|
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,21 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import { FastField, Field, ErrorMessage } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import { FormGroup } from '@blueprintjs/core';
|
import { FormGroup } from '@blueprintjs/core';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
ListSelect,
|
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
|
FSelect,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
|
|
||||||
import { inputIntent } from '@/utils';
|
import { inputIntent } from '@/utils';
|
||||||
import { CLASSES } from '@/constants/classes';
|
|
||||||
import { getAddMoneyOutOptions } from '@/constants/cashflowOptions';
|
import { getAddMoneyOutOptions } from '@/constants/cashflowOptions';
|
||||||
|
|
||||||
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
|
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
|
||||||
|
import { CLASSES } from '@/constants/classes';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction type fields.
|
* Transaction type fields.
|
||||||
@@ -27,9 +26,32 @@ function TransactionTypeFields() {
|
|||||||
|
|
||||||
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
|
const addMoneyOutOptions = useMemo(() => getAddMoneyOutOptions(), []);
|
||||||
|
|
||||||
|
// Money in dialog context.
|
||||||
|
const { defaultAccountId, setAccountId } = useMoneyOutDialogContext();
|
||||||
|
|
||||||
|
// Cannot continue if the default account id is defined.
|
||||||
|
if (defaultAccountId) return null;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="trasnaction-type-fileds">
|
<div className="trasnaction-type-fileds">
|
||||||
<Row>
|
<Row>
|
||||||
|
{/*------------ Transaction type -----------*/}
|
||||||
|
<Col xs={5}>
|
||||||
|
<FFormGroup
|
||||||
|
name={'transaction_type'}
|
||||||
|
label={<T id={'transaction_type'} />}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
>
|
||||||
|
<FSelect
|
||||||
|
name={'transaction_type'}
|
||||||
|
items={addMoneyOutOptions}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
valueAccessor={'value'}
|
||||||
|
textAccessor={'name'}
|
||||||
|
/>
|
||||||
|
</FFormGroup>
|
||||||
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Current account -----------*/}
|
{/*------------ Current account -----------*/}
|
||||||
<FastField name={'cashflow_account_id'}>
|
<FastField name={'cashflow_account_id'}>
|
||||||
@@ -47,9 +69,10 @@ function TransactionTypeFields() {
|
|||||||
>
|
>
|
||||||
<AccountsSuggestField
|
<AccountsSuggestField
|
||||||
accounts={cashflowAccounts}
|
accounts={cashflowAccounts}
|
||||||
onAccountSelected={({ id }) =>
|
onAccountSelected={({ id }) => {
|
||||||
form.setFieldValue('cashflow_account_id', id)
|
form.setFieldValue('cashflow_account_id', id);
|
||||||
}
|
setAccountId(id);
|
||||||
|
}}
|
||||||
inputProps={{
|
inputProps={{
|
||||||
intent: inputIntent({ error, touched }),
|
intent: inputIntent({ error, touched }),
|
||||||
}}
|
}}
|
||||||
@@ -57,39 +80,6 @@ function TransactionTypeFields() {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
{/*------------ Transaction type -----------*/}
|
|
||||||
</Col>
|
|
||||||
<Col xs={5}>
|
|
||||||
<Field name={'transaction_type'}>
|
|
||||||
{({
|
|
||||||
form: { values, setFieldValue },
|
|
||||||
field: { value },
|
|
||||||
meta: { error, touched },
|
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'transaction_type'} />}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
helperText={<ErrorMessage name="transaction_type" />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
className={classNames(
|
|
||||||
CLASSES.FILL,
|
|
||||||
'form-group--transaction_type',
|
|
||||||
)}
|
|
||||||
>
|
|
||||||
<ListSelect
|
|
||||||
items={addMoneyOutOptions}
|
|
||||||
onItemSelect={(type) => {
|
|
||||||
setFieldValue('transaction_type', type.value);
|
|
||||||
}}
|
|
||||||
filterable={false}
|
|
||||||
selectedItem={value}
|
|
||||||
selectedItemProp={'value'}
|
|
||||||
textProp={'name'}
|
|
||||||
popoverProps={{ minimal: true }}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,65 +1,46 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
import {
|
import { FormGroup, Position, ControlGroup } from '@blueprintjs/core';
|
||||||
Classes,
|
|
||||||
FormGroup,
|
|
||||||
InputGroup,
|
|
||||||
TextArea,
|
|
||||||
Position,
|
|
||||||
ControlGroup,
|
|
||||||
} from '@blueprintjs/core';
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import {
|
import {
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
AccountsSuggestField,
|
AccountsSuggestField,
|
||||||
InputPrependText,
|
InputPrependText,
|
||||||
MoneyInputGroup,
|
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
Icon,
|
|
||||||
Col,
|
Col,
|
||||||
Row,
|
Row,
|
||||||
If,
|
|
||||||
InputPrependButton,
|
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
BranchSelect,
|
BranchSelect,
|
||||||
BranchSelectButton,
|
BranchSelectButton,
|
||||||
ExchangeRateMutedField,
|
FFormGroup,
|
||||||
|
FTextArea,
|
||||||
|
FMoneyInputGroup,
|
||||||
|
FInputGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { useAutofocus } from '@/hooks';
|
|
||||||
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
|
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
inputIntent,
|
inputIntent,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
compose,
|
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
import { useMoneyOutDialogContext } from '../MoneyOutDialogProvider';
|
||||||
import {
|
import { useSetPrimaryBranchToForm, BranchRowDivider } from '../utils';
|
||||||
useObserveTransactionNoSettings,
|
|
||||||
useSetPrimaryBranchToForm,
|
|
||||||
useForeignAccount,
|
|
||||||
BranchRowDivider,
|
|
||||||
} from '../utils';
|
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
|
||||||
import { MoneyInOutTransactionNoField } from '../../_components';
|
import { MoneyInOutTransactionNoField } from '../../_components';
|
||||||
|
import { MoneyOutExchangeRateField } from '../MoneyOutExchangeRateField';
|
||||||
|
import { useMoneyOutFieldsContext } from '../MoneyOutFieldsProvider';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfer to account form fields.
|
* Transfer to account form fields.
|
||||||
*/
|
*/
|
||||||
export default function TransferToAccountFormFields() {
|
export default function TransferToAccountFormFields() {
|
||||||
// Money in dialog context.
|
// Money in dialog context.
|
||||||
const { accounts, account, branches } = useMoneyOutDialogContext();
|
const { accounts, branches } = useMoneyOutDialogContext();
|
||||||
const { values } = useFormikContext();
|
const { account } = useMoneyOutFieldsContext();
|
||||||
const isForeigAccount = useForeignAccount();
|
|
||||||
|
|
||||||
const accountRef = useAutofocus();
|
|
||||||
|
|
||||||
// Sets the primary branch to form.
|
// Sets the primary branch to form.
|
||||||
useSetPrimaryBranchToForm();
|
useSetPrimaryBranchToForm();
|
||||||
@@ -69,21 +50,19 @@ export default function TransferToAccountFormFields() {
|
|||||||
<FeatureCan feature={Features.Branches}>
|
<FeatureCan feature={Features.Branches}>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
<FormGroup
|
<FFormGroup label={<T id={'branch'} />} name={'branch_id'}>
|
||||||
label={<T id={'branch'} />}
|
|
||||||
className={classNames('form-group--select-list', Classes.FILL)}
|
|
||||||
>
|
|
||||||
<BranchSelect
|
<BranchSelect
|
||||||
name={'branch_id'}
|
name={'branch_id'}
|
||||||
branches={branches}
|
branches={branches}
|
||||||
input={BranchSelectButton}
|
input={BranchSelectButton}
|
||||||
popoverProps={{ minimal: true }}
|
popoverProps={{ minimal: true }}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
<BranchRowDivider />
|
<BranchRowDivider />
|
||||||
</FeatureCan>
|
</FeatureCan>
|
||||||
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -113,52 +92,32 @@ export default function TransferToAccountFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Transaction number -----------*/}
|
{/*------------ Transaction number -----------*/}
|
||||||
<MoneyInOutTransactionNoField />
|
<MoneyInOutTransactionNoField />
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ amount -----------*/}
|
|
||||||
<FastField name={'amount'}>
|
{/*------------ Amount -----------*/}
|
||||||
{({
|
<Row>
|
||||||
form: { values, setFieldValue },
|
<Col xs={10}>
|
||||||
field: { value },
|
<FFormGroup
|
||||||
meta: { error, touched },
|
name={'amount'}
|
||||||
}) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'amount'} />}
|
label={<T id={'amount'} />}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="amount" />}
|
|
||||||
className={'form-group--amount'}
|
|
||||||
>
|
>
|
||||||
<ControlGroup>
|
<ControlGroup>
|
||||||
<InputPrependText text={account.currency_code} />
|
<InputPrependText text={account.currency_code} />
|
||||||
|
<FMoneyInputGroup name={'amount'} minimal={true} />
|
||||||
<MoneyInputGroup
|
|
||||||
value={value}
|
|
||||||
minimal={true}
|
|
||||||
onChange={(amount) => {
|
|
||||||
setFieldValue('amount', amount);
|
|
||||||
}}
|
|
||||||
inputRef={accountRef}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
)}
|
</Col>
|
||||||
</FastField>
|
</Row>
|
||||||
<If condition={isForeigAccount}>
|
|
||||||
{/*------------ exchange rate -----------*/}
|
{/*------------ Exchange rate -----------*/}
|
||||||
<ExchangeRateMutedField
|
<MoneyOutExchangeRateField />
|
||||||
name={'exchange_rate'}
|
|
||||||
fromCurrency={values?.currency_code}
|
|
||||||
toCurrency={account?.currency_code}
|
|
||||||
formGroupProps={{ label: '', inline: false }}
|
|
||||||
date={values.date}
|
|
||||||
exchangeRate={values.exchange_rate}
|
|
||||||
/>
|
|
||||||
</If>
|
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ transfer from account -----------*/}
|
{/*------------ transfer from account -----------*/}
|
||||||
@@ -191,43 +150,24 @@ export default function TransferToAccountFormFields() {
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
|
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference_no'}>
|
<FFormGroup name={'reference_no'} label={<T id={'reference_no'} />}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
<FInputGroup name={'reference_no'} />
|
||||||
<FormGroup
|
</FFormGroup>
|
||||||
label={<T id={'reference_no'} />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="reference_no" />}
|
|
||||||
className={'form-group--reference-no'}
|
|
||||||
>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
{/*------------ description -----------*/}
|
|
||||||
<FastField name={'description'}>
|
{/*------------ Description -----------*/}
|
||||||
{({ field, meta: { error, touched } }) => (
|
<FFormGroup name={'description'} label={<T id={'description'} />}>
|
||||||
<FormGroup
|
<FTextArea
|
||||||
label={<T id={'description'} />}
|
name={'description'}
|
||||||
className={'form-group--description'}
|
growVertically={true}
|
||||||
intent={inputIntent({ error, touched })}
|
large={true}
|
||||||
helperText={<ErrorMessage name={'description'} />}
|
fill={true}
|
||||||
>
|
/>
|
||||||
<TextArea
|
</FFormGroup>
|
||||||
growVertically={true}
|
|
||||||
large={true}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import { transactionNumber } from '@/utils';
|
|||||||
import { first, isEqual, isNull } from 'lodash';
|
import { first, isEqual, isNull } from 'lodash';
|
||||||
|
|
||||||
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
|
import { useMoneyOutDialogContext } from './MoneyOutDialogProvider';
|
||||||
|
import { useMoneyOutFieldsContext } from './MoneyOutFieldsProvider';
|
||||||
|
|
||||||
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
export const useObserveTransactionNoSettings = (prefix, nextNumber) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
@@ -33,7 +34,7 @@ export const useSetPrimaryBranchToForm = () => {
|
|||||||
|
|
||||||
export const useForeignAccount = () => {
|
export const useForeignAccount = () => {
|
||||||
const { values } = useFormikContext();
|
const { values } = useFormikContext();
|
||||||
const { account } = useMoneyOutDialogContext();
|
const { account } = useMoneyOutFieldsContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
!isEqual(account.currency_code, values.currency_code) &&
|
!isEqual(account.currency_code, values.currency_code) &&
|
||||||
|
|||||||
@@ -38,11 +38,11 @@ export const MoneyInOutSyncIncrementSettingsToForm = R.compose(
|
|||||||
// Do not update if the invoice auto-increment is disabled.
|
// Do not update if the invoice auto-increment is disabled.
|
||||||
if (!transactionAutoIncrement) return null;
|
if (!transactionAutoIncrement) return null;
|
||||||
|
|
||||||
const transactionNumber = transactionNumber(
|
const newTransactionNumber = transactionNumber(
|
||||||
transactionNumberPrefix,
|
transactionNumberPrefix,
|
||||||
transactionNextNumber,
|
transactionNextNumber,
|
||||||
);
|
);
|
||||||
setFieldValue('transaction_number', transactionNumber);
|
setFieldValue('transaction_number', newTransactionNumber);
|
||||||
}, [setFieldValue, transactionNumberPrefix, transactionNextNumber]);
|
}, [setFieldValue, transactionNumberPrefix, transactionNextNumber]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -1,34 +1,14 @@
|
|||||||
.dialog--money-in,
|
.dialog--money-in,
|
||||||
.dialog--money-out {
|
.dialog--money-out {
|
||||||
.bp3-form-group {
|
|
||||||
margin-bottom: 15px;
|
|
||||||
|
|
||||||
label.bp3-label {
|
|
||||||
font-size: 13px;
|
|
||||||
margin-bottom: 3px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.form-group {
|
|
||||||
&--description {
|
|
||||||
.bp3-form-content {
|
|
||||||
textarea {
|
|
||||||
width: 100%;
|
|
||||||
min-width: 100%;
|
|
||||||
font-size: 14px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
&--reference-no,
|
|
||||||
&--amount,
|
|
||||||
&--credit_account_id {
|
|
||||||
max-width: 380px;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.trasnaction-type-fileds {
|
.trasnaction-type-fileds {
|
||||||
margin-bottom: 18px;
|
margin-bottom: 18px;
|
||||||
padding: 16px 0px 12px 0px;
|
padding: 0 0px 16px 0px;
|
||||||
border-bottom: 2px solid #e9e9e9;
|
border-bottom: 2px solid #e9e9e9;
|
||||||
|
|
||||||
|
.bp3-form-group{
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.bp3-dialog-footer {
|
.bp3-dialog-footer {
|
||||||
|
|||||||
Reference in New Issue
Block a user