mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 15:50:32 +00:00
feat: money in .
This commit is contained in:
@@ -3,29 +3,30 @@ import intl from 'react-intl-universal';
|
|||||||
export const addMoneyIn = [
|
export const addMoneyIn = [
|
||||||
{
|
{
|
||||||
name: intl.get('cash_flow.option_owner_contribution'),
|
name: intl.get('cash_flow.option_owner_contribution'),
|
||||||
type: 'OWNER_CONTRIBUTION',
|
value: 'owner_contribution',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: intl.get('cash_flow.option_other_income'),
|
name: intl.get('cash_flow.option_other_income'),
|
||||||
type: 'OTHER_INCOME',
|
type: 'OTHER_INCOME',
|
||||||
|
value: 'other_income',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: intl.get('cash_flow.option_transfer_form_account'),
|
name: intl.get('cash_flow.option_transfer_form_account'),
|
||||||
type: 'TRANSFER_FROM_ACCOUNT',
|
value: 'transfer_from_account',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const addMoneyOut = [
|
export const addMoneyOut = [
|
||||||
{
|
{
|
||||||
name: intl.get('cash_flow.option_owner_drawings'),
|
name: intl.get('cash_flow.option_owner_drawings'),
|
||||||
type: 'ONWERS_DRAWING',
|
value: 'onwers_drawing',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: intl.get('cash_flow.option_expenses'),
|
name: intl.get('cash_flow.option_expenses'),
|
||||||
type: 'OTHER_EXPENSE',
|
value: 'other_expense',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: intl.get('cash_flow.option_transfer_to_account'),
|
name: intl.get('cash_flow.option_transfer_to_account'),
|
||||||
type: 'TRANSFER_TO_ACCOUNT',
|
value: 'transfer_to_account',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|||||||
@@ -40,17 +40,17 @@ function AccountTransactionsActionsBar({
|
|||||||
const { accountId } = useAccountTransactionsContext();
|
const { accountId } = useAccountTransactionsContext();
|
||||||
|
|
||||||
// Handle money in form
|
// Handle money in form
|
||||||
const handleMoneyInFormTransaction = (value) => {
|
const handleMoneyInFormTransaction = (account) => {
|
||||||
openDialog('money-in', {
|
openDialog('money-in', {
|
||||||
account_type: value.type,
|
account_type: account,
|
||||||
account_id: accountId,
|
account_id: accountId,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle money out form
|
// Handle money out form
|
||||||
const handlMoneyOutFormTransaction = (value) => {
|
const handlMoneyOutFormTransaction = (account) => {
|
||||||
openDialog('money-out', {
|
openDialog('money-out', {
|
||||||
account_type: value.type,
|
account_type: account,
|
||||||
account_id: accountId,
|
account_id: accountId,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
23
src/containers/Dialogs/MoneyInDialog/MoneyInContentFields.js
Normal file
23
src/containers/Dialogs/MoneyInDialog/MoneyInContentFields.js
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import OwnerContributionFormFields from './OwnerContribution/OwnerContributionFormFields';
|
||||||
|
import OtherIncomeFormFields from './OtherIncome/OtherIncomeFormFields';
|
||||||
|
import TransferFromAccountFormFields from './TransferFromAccount/TransferFromAccountFormFields';
|
||||||
|
|
||||||
|
export default function MoneyInContentFields({ accountType }) {
|
||||||
|
const handleTransactionType = () => {
|
||||||
|
switch (accountType) {
|
||||||
|
case 'owner_contribution':
|
||||||
|
return <OwnerContributionFormFields />;
|
||||||
|
|
||||||
|
case 'other_income':
|
||||||
|
return <OtherIncomeFormFields />;
|
||||||
|
|
||||||
|
case 'transfer_from_account':
|
||||||
|
return <TransferFromAccountFormFields />;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return <React.Fragment>{handleTransactionType()}</React.Fragment>;
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { MoneyInDialogProvider } from './MoneyInDialogProvider';
|
import { MoneyInDialogProvider } from './MoneyInDialogProvider';
|
||||||
import MoneyInDialogForm from './MoneyInDialogForm';
|
import MoneyInForm from './MoneyInForm';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Money in dialog content.
|
* Money in dialog content.
|
||||||
@@ -13,8 +13,12 @@ export default function MoneyInDialogContent({
|
|||||||
accountType,
|
accountType,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<MoneyInDialogProvider accountId={accountId} dialogName={dialogName}>
|
<MoneyInDialogProvider
|
||||||
<MoneyInDialogForm accountType={accountType} />
|
accountId={accountId}
|
||||||
|
accountType={accountType}
|
||||||
|
dialogName={dialogName}
|
||||||
|
>
|
||||||
|
<MoneyInForm />
|
||||||
</MoneyInDialogProvider>
|
</MoneyInDialogProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,24 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import OwnerContributionForm from './OwnerContribution/OwnerContributionForm';
|
|
||||||
import OtherIncomeForm from './OtherIncome/OtherIncomeForm';
|
|
||||||
import TransferFromAccountForm from './TransferFromAccount/TransferFromAccountForm';
|
|
||||||
|
|
||||||
export default function MoneyInDialogForm({ accountType }) {
|
|
||||||
// Handle from transaction.
|
|
||||||
const handleFromTransaction = () => {
|
|
||||||
switch (accountType) {
|
|
||||||
case 'OWNER_CONTRIBUTION':
|
|
||||||
return <OwnerContributionForm />;
|
|
||||||
|
|
||||||
case 'OTHER_INCOME':
|
|
||||||
return <OtherIncomeForm />;
|
|
||||||
|
|
||||||
case 'TRANSFER_FROM_ACCOUNT':
|
|
||||||
return <TransferFromAccountForm />;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return <React.Fragment>{handleFromTransaction()}</React.Fragment>;
|
|
||||||
}
|
|
||||||
@@ -1,16 +1,29 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
import { useCreateCashflowTransaction, useAccounts } from 'hooks/query';
|
import {
|
||||||
|
useCreateCashflowTransaction,
|
||||||
|
useAccounts,
|
||||||
|
useCashflowAccounts,
|
||||||
|
} from 'hooks/query';
|
||||||
|
|
||||||
const MoneyInDialogContent = React.createContext();
|
const MoneyInDialogContent = React.createContext();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Money in dialog provider.
|
* Money in dialog provider.
|
||||||
*/
|
*/
|
||||||
function MoneyInDialogProvider({ accountId, dialogName, ...props }) {
|
function MoneyInDialogProvider({
|
||||||
|
accountId,
|
||||||
|
accountType,
|
||||||
|
dialogName,
|
||||||
|
...props
|
||||||
|
}) {
|
||||||
// Fetches accounts list.
|
// Fetches accounts list.
|
||||||
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
const { isFetching: isAccountsLoading, data: accounts } = useAccounts();
|
||||||
|
|
||||||
|
// Fetch cash flow list .
|
||||||
|
const { data: cashflowAccounts, isLoading: isCashFlowAccountsLoading } =
|
||||||
|
useCashflowAccounts({}, { keepPreviousData: true });
|
||||||
|
|
||||||
const { mutateAsync: createCashflowTransactionMutate } =
|
const { mutateAsync: createCashflowTransactionMutate } =
|
||||||
useCreateCashflowTransaction();
|
useCreateCashflowTransaction();
|
||||||
|
|
||||||
@@ -21,8 +34,11 @@ function MoneyInDialogProvider({ accountId, dialogName, ...props }) {
|
|||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
accounts,
|
||||||
accountId,
|
accountId,
|
||||||
|
accountType,
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
|
|
||||||
|
cashflowAccounts,
|
||||||
|
|
||||||
submitPayload,
|
submitPayload,
|
||||||
dialogName,
|
dialogName,
|
||||||
|
|
||||||
@@ -31,7 +47,7 @@ function MoneyInDialogProvider({ accountId, dialogName, ...props }) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DialogContent isLoading={isAccountsLoading}>
|
<DialogContent isLoading={isAccountsLoading || isCashFlowAccountsLoading}>
|
||||||
<MoneyInDialogContent.Provider value={provider} {...props} />
|
<MoneyInDialogContent.Provider value={provider} {...props} />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ import intl from 'react-intl-universal';
|
|||||||
import 'style/pages/CashFlow/CashflowTransactionForm.scss';
|
import 'style/pages/CashFlow/CashflowTransactionForm.scss';
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
import { CreateOtherIncomeFormSchema } from './OtherIncomeForm.schema';
|
|
||||||
import OtherIncomeFormContent from './OtherIncomeFormContent';
|
|
||||||
|
|
||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
import MoneyInFormContent from './MoneyInFormContent';
|
||||||
|
import { CreateMoneyInFormSchema } from './MoneyInForm.schema';
|
||||||
|
|
||||||
|
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
||||||
@@ -22,7 +23,7 @@ const defaultInitialValues = {
|
|||||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
amount: '',
|
amount: '',
|
||||||
transaction_number: '',
|
transaction_number: '',
|
||||||
transaction_type: 'other_income',
|
transaction_type: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
cashflow_account_id: '',
|
cashflow_account_id: '',
|
||||||
credit_account_id: '',
|
credit_account_id: '',
|
||||||
@@ -30,10 +31,7 @@ const defaultInitialValues = {
|
|||||||
published: '',
|
published: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
function MoneyInForm({
|
||||||
* Other income form.
|
|
||||||
*/
|
|
||||||
function OtherIncomeForm({
|
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
closeDialog,
|
closeDialog,
|
||||||
|
|
||||||
@@ -43,6 +41,7 @@ function OtherIncomeForm({
|
|||||||
const {
|
const {
|
||||||
dialogName,
|
dialogName,
|
||||||
accountId,
|
accountId,
|
||||||
|
accountType,
|
||||||
createCashflowTransactionMutate,
|
createCashflowTransactionMutate,
|
||||||
submitPayload,
|
submitPayload,
|
||||||
} = useMoneyInDailogContext();
|
} = useMoneyInDailogContext();
|
||||||
@@ -51,6 +50,7 @@ function OtherIncomeForm({
|
|||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
currency_code: base_currency,
|
currency_code: base_currency,
|
||||||
|
transaction_type: accountType,
|
||||||
cashflow_account_id: accountId,
|
cashflow_account_id: accountId,
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -76,17 +76,19 @@ function OtherIncomeForm({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Formik
|
<div>
|
||||||
validationSchema={CreateOtherIncomeFormSchema}
|
<Formik
|
||||||
initialValues={initialValues}
|
validationSchema={CreateMoneyInFormSchema}
|
||||||
onSubmit={handleFormSubmit}
|
initialValues={initialValues}
|
||||||
>
|
onSubmit={handleFormSubmit}
|
||||||
<OtherIncomeFormContent />
|
>
|
||||||
</Formik>
|
<MoneyInFormContent />
|
||||||
|
</Formik>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
export default compose(
|
||||||
withDialogActions,
|
withDialogActions,
|
||||||
withCurrentOrganization(),
|
withCurrentOrganization(),
|
||||||
)(OtherIncomeForm);
|
)(MoneyInForm);
|
||||||
@@ -8,9 +8,7 @@ const Schema = Yup.object().shape({
|
|||||||
transaction_number: Yup.string(),
|
transaction_number: Yup.string(),
|
||||||
transaction_type: Yup.string().required(),
|
transaction_type: Yup.string().required(),
|
||||||
reference_no: Yup.string(),
|
reference_no: Yup.string(),
|
||||||
credit_account_id: Yup.number()
|
credit_account_id: Yup.number().required(),
|
||||||
.required()
|
|
||||||
.label(intl.get('other_income_account')),
|
|
||||||
cashflow_account_id: Yup.string().required(),
|
cashflow_account_id: Yup.string().required(),
|
||||||
description: Yup.string()
|
description: Yup.string()
|
||||||
.min(3)
|
.min(3)
|
||||||
@@ -19,4 +17,4 @@ const Schema = Yup.object().shape({
|
|||||||
published: Yup.boolean(),
|
published: Yup.boolean(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export const CreateOtherIncomeFormSchema = Schema;
|
export const CreateMoneyInFormSchema = Schema;
|
||||||
17
src/containers/Dialogs/MoneyInDialog/MoneyInFormContent.js
Normal file
17
src/containers/Dialogs/MoneyInDialog/MoneyInFormContent.js
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Form } from 'formik';
|
||||||
|
|
||||||
|
import MoneyInFormFields from './MoneyInFormFields';
|
||||||
|
import MoneyInFloatingActions from './MoneyInFloatingActions';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money In form content.
|
||||||
|
*/
|
||||||
|
export default function MoneyInFormContent() {
|
||||||
|
return (
|
||||||
|
<Form>
|
||||||
|
<MoneyInFormFields />
|
||||||
|
<MoneyInFloatingActions />
|
||||||
|
</Form>
|
||||||
|
);
|
||||||
|
}
|
||||||
27
src/containers/Dialogs/MoneyInDialog/MoneyInFormFields.js
Normal file
27
src/containers/Dialogs/MoneyInDialog/MoneyInFormFields.js
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Classes } from '@blueprintjs/core';
|
||||||
|
|
||||||
|
import { If } from 'components';
|
||||||
|
|
||||||
|
import MoneyInContentFields from './MoneyInContentFields';
|
||||||
|
import TransactionTypeFields from './TransactionTypeFields';
|
||||||
|
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Money in form fields.
|
||||||
|
*/
|
||||||
|
function MoneyInFormFields() {
|
||||||
|
// Money in dialog context.
|
||||||
|
const { accountId, accountType } = useMoneyInDailogContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className={Classes.DIALOG_BODY}>
|
||||||
|
<If condition={!accountId}>
|
||||||
|
<TransactionTypeFields />
|
||||||
|
</If>
|
||||||
|
<MoneyInContentFields accountType={accountType} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default MoneyInFormFields;
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Form } from 'formik';
|
|
||||||
|
|
||||||
import OtherIncomeFormFields from './OtherIncomeFormFields';
|
|
||||||
import MoneyInFloatingActions from '../MoneyInFloatingActions';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Other income form content.
|
|
||||||
*/
|
|
||||||
export default function OtherIncomeFormContent() {
|
|
||||||
return (
|
|
||||||
<Form>
|
|
||||||
<OtherIncomeFormFields />
|
|
||||||
<MoneyInFloatingActions />
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,7 @@ function OtherIncomeFormFields() {
|
|||||||
const amountFieldRef = useAutofocus();
|
const amountFieldRef = useAutofocus();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<React.Fragment>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -187,7 +187,7 @@ function OtherIncomeFormFields() {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</div>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,92 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import moment from 'moment';
|
|
||||||
import { Intent } from '@blueprintjs/core';
|
|
||||||
import { Formik } from 'formik';
|
|
||||||
import { omit } from 'lodash';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
|
|
||||||
import 'style/pages/CashFlow/CashflowTransactionForm.scss';
|
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
|
||||||
import { CreateOwnerContributionFormSchema } from './OwnerContributionForm.schema';
|
|
||||||
import OwnerContributionFormContent from './OwnerContributionFormContent';
|
|
||||||
|
|
||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
|
||||||
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
|
||||||
|
|
||||||
const defaultInitialValues = {
|
|
||||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
|
||||||
amount: '',
|
|
||||||
transaction_number: '',
|
|
||||||
transaction_type: 'owner_contribution',
|
|
||||||
reference_no: '',
|
|
||||||
cashflow_account_id: '',
|
|
||||||
credit_account_id: '',
|
|
||||||
description: '',
|
|
||||||
published: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Owner contribution form
|
|
||||||
*/
|
|
||||||
function OwnerContributionForm({
|
|
||||||
// #withDialogActions
|
|
||||||
closeDialog,
|
|
||||||
|
|
||||||
// #withCurrentOrganization
|
|
||||||
organization: { base_currency },
|
|
||||||
}) {
|
|
||||||
const {
|
|
||||||
dialogName,
|
|
||||||
accountId,
|
|
||||||
submitPayload,
|
|
||||||
createCashflowTransactionMutate,
|
|
||||||
} = useMoneyInDailogContext();
|
|
||||||
|
|
||||||
// Initial form values.
|
|
||||||
const initialValues = {
|
|
||||||
...defaultInitialValues,
|
|
||||||
currency_code: base_currency,
|
|
||||||
cashflow_account_id: accountId,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handles the form submit.
|
|
||||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
|
||||||
const form = {
|
|
||||||
...omit(values, ['currency_code']),
|
|
||||||
published: submitPayload.publish,
|
|
||||||
};
|
|
||||||
setSubmitting(true);
|
|
||||||
createCashflowTransactionMutate(form)
|
|
||||||
.then(() => {
|
|
||||||
closeDialog(dialogName);
|
|
||||||
|
|
||||||
AppToaster.show({
|
|
||||||
message: intl.get('cash_flow_transaction_success_message'),
|
|
||||||
intent: Intent.SUCCESS,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setSubmitting(true);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Formik
|
|
||||||
validationSchema={CreateOwnerContributionFormSchema}
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={handleFormSubmit}
|
|
||||||
>
|
|
||||||
<OwnerContributionFormContent />
|
|
||||||
</Formik>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withCurrentOrganization(),
|
|
||||||
)(OwnerContributionForm);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import * as Yup from 'yup';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
|
||||||
|
|
||||||
const Schema = Yup.object().shape({
|
|
||||||
date: Yup.date().required().label(intl.get('date')),
|
|
||||||
amount: Yup.number().required().label(intl.get('amount')),
|
|
||||||
transaction_number: Yup.string(),
|
|
||||||
transaction_type: Yup.string().required(),
|
|
||||||
reference_no: Yup.string(),
|
|
||||||
credit_account_id: Yup.number()
|
|
||||||
.required()
|
|
||||||
.label(intl.get('cash_flow_transaction.label_equity_account')),
|
|
||||||
cashflow_account_id: Yup.string().required(),
|
|
||||||
description: Yup.string()
|
|
||||||
.min(3)
|
|
||||||
.max(DATATYPES_LENGTH.TEXT)
|
|
||||||
.label(intl.get('description')),
|
|
||||||
published: Yup.boolean(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const CreateOwnerContributionFormSchema = Schema;
|
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Form } from 'formik';
|
|
||||||
|
|
||||||
import OwnerContributionFormFields from './OwnerContributionFormFields';
|
|
||||||
import MoneyInFloatingActions from '../MoneyInFloatingActions';
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Owner contribution form content.
|
|
||||||
*/
|
|
||||||
export default function OwnerContributionFormContent() {
|
|
||||||
return (
|
|
||||||
<Form>
|
|
||||||
<OwnerContributionFormFields />
|
|
||||||
<MoneyInFloatingActions />
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -39,7 +39,7 @@ function OwnerContributionFormFields() {
|
|||||||
|
|
||||||
const amountFieldRef = useAutofocus();
|
const amountFieldRef = useAutofocus();
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<React.Fragment>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -183,7 +183,7 @@ function OwnerContributionFormFields() {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</div>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,94 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { FastField, ErrorMessage } from 'formik';
|
||||||
|
import { Classes, FormGroup } from '@blueprintjs/core';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import {
|
||||||
|
FormattedMessage as T,
|
||||||
|
AccountsSuggestField,
|
||||||
|
FieldRequiredHint,
|
||||||
|
ListSelect,
|
||||||
|
Col,
|
||||||
|
Row,
|
||||||
|
} from 'components';
|
||||||
|
|
||||||
|
import { inputIntent } from 'utils';
|
||||||
|
import { CLASSES } from 'common/classes';
|
||||||
|
import { addMoneyIn } from '../../../common/cashflowOptions';
|
||||||
|
|
||||||
|
import { useMoneyInDailogContext } from './MoneyInDialogProvider';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transaction type fields.
|
||||||
|
*/
|
||||||
|
export default function TransactionTypeFields() {
|
||||||
|
// Money in dialog context.
|
||||||
|
const { cashflowAccounts } = useMoneyInDailogContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="trasnaction-type-fileds">
|
||||||
|
<Row>
|
||||||
|
<Col xs={5}>
|
||||||
|
{/*------------ Current account -----------*/}
|
||||||
|
<FastField name={'cashflow_account_id'}>
|
||||||
|
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||||
|
<FormGroup
|
||||||
|
label={'Current account'}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
intent={inputIntent({ error, touched })}
|
||||||
|
helperText={<ErrorMessage name="cashflow_account_id" />}
|
||||||
|
minimal={true}
|
||||||
|
className={classNames(
|
||||||
|
CLASSES.FILL,
|
||||||
|
'form-group--cashflow_account_id',
|
||||||
|
)}
|
||||||
|
>
|
||||||
|
<AccountsSuggestField
|
||||||
|
accounts={cashflowAccounts}
|
||||||
|
onAccountSelected={({ id }) =>
|
||||||
|
form.setFieldValue('cashflow_account_id', id)
|
||||||
|
}
|
||||||
|
inputProps={{
|
||||||
|
intent: inputIntent({ error, touched }),
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
{/*------------ Transaction type -----------*/}
|
||||||
|
</Col>
|
||||||
|
<Col xs={5}>
|
||||||
|
<FastField 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={addMoneyIn}
|
||||||
|
onItemSelect={(type) => {
|
||||||
|
setFieldValue('transaction_type', type.value);
|
||||||
|
}}
|
||||||
|
filterable={false}
|
||||||
|
selectedItem={value}
|
||||||
|
selectedItemProp={'value'}
|
||||||
|
textProp={'name'}
|
||||||
|
popoverProps={{ minimal: true }}
|
||||||
|
/>
|
||||||
|
</FormGroup>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
</Col>
|
||||||
|
</Row>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,92 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import moment from 'moment';
|
|
||||||
import { Intent } from '@blueprintjs/core';
|
|
||||||
import { Formik } from 'formik';
|
|
||||||
import { omit } from 'lodash';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
|
|
||||||
import 'style/pages/CashFlow/CashflowTransactionForm.scss';
|
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
|
||||||
import { CreateTransferFromAccountFormSchema } from './TransferFromAccountForm.schema';
|
|
||||||
import TransferFromAccountFormContent from './TransferFromAccountFormContent';
|
|
||||||
|
|
||||||
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
|
|
||||||
|
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
|
||||||
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
|
||||||
|
|
||||||
import { compose } from 'utils';
|
|
||||||
|
|
||||||
const defaultInitialValues = {
|
|
||||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
|
||||||
amount: '',
|
|
||||||
transaction_number: '',
|
|
||||||
transaction_type: 'transfer_from_account',
|
|
||||||
reference_no: '',
|
|
||||||
cashflow_account_id: '',
|
|
||||||
credit_account_id: '',
|
|
||||||
description: '',
|
|
||||||
published: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Transfer from account form.
|
|
||||||
*/
|
|
||||||
function TransferFromAccountForm({
|
|
||||||
// #withDialogActions
|
|
||||||
closeDialog,
|
|
||||||
|
|
||||||
// #withCurrentOrganization
|
|
||||||
organization: { base_currency },
|
|
||||||
}) {
|
|
||||||
const {
|
|
||||||
dialogName,
|
|
||||||
accountId,
|
|
||||||
createCashflowTransactionMutate,
|
|
||||||
submitPayload,
|
|
||||||
} = useMoneyInDailogContext();
|
|
||||||
|
|
||||||
// Initial form values.
|
|
||||||
const initialValues = {
|
|
||||||
...defaultInitialValues,
|
|
||||||
currency_code: base_currency,
|
|
||||||
cashflow_account_id: accountId,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handles the form submit.
|
|
||||||
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
|
|
||||||
const form = {
|
|
||||||
...omit(values, ['currency_code']),
|
|
||||||
published: submitPayload.publish,
|
|
||||||
};
|
|
||||||
setSubmitting(true);
|
|
||||||
createCashflowTransactionMutate(form)
|
|
||||||
.then(() => {
|
|
||||||
closeDialog(dialogName);
|
|
||||||
|
|
||||||
AppToaster.show({
|
|
||||||
message: intl.get('cash_flow_transaction_success_message'),
|
|
||||||
intent: Intent.SUCCESS,
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
setSubmitting(true);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Formik
|
|
||||||
validationSchema={CreateTransferFromAccountFormSchema}
|
|
||||||
initialValues={initialValues}
|
|
||||||
onSubmit={handleFormSubmit}
|
|
||||||
>
|
|
||||||
<TransferFromAccountFormContent />
|
|
||||||
</Formik>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withCurrentOrganization(),
|
|
||||||
)(TransferFromAccountForm);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import * as Yup from 'yup';
|
|
||||||
import intl from 'react-intl-universal';
|
|
||||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
|
||||||
|
|
||||||
const Schema = Yup.object().shape({
|
|
||||||
date: Yup.date().required().label(intl.get('date')),
|
|
||||||
amount: Yup.number().required().label(intl.get('amount')),
|
|
||||||
transaction_number: Yup.string(),
|
|
||||||
transaction_type: Yup.string().required(),
|
|
||||||
reference_no: Yup.string(),
|
|
||||||
credit_account_id: Yup.number()
|
|
||||||
.required()
|
|
||||||
.label(intl.get('cash_flow_transaction.label_transfer_account')),
|
|
||||||
cashflow_account_id: Yup.string().required(),
|
|
||||||
description: Yup.string()
|
|
||||||
.min(3)
|
|
||||||
.max(DATATYPES_LENGTH.TEXT)
|
|
||||||
.label(intl.get('description')),
|
|
||||||
published: Yup.boolean(),
|
|
||||||
});
|
|
||||||
|
|
||||||
export const CreateTransferFromAccountFormSchema = Schema;
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
import React from 'react';
|
|
||||||
import { Form } from 'formik';
|
|
||||||
|
|
||||||
import TransferFromAccountFormFields from './TransferFromAccountFormFields';
|
|
||||||
import MoneyInFloatingActions from '../MoneyInFloatingActions';
|
|
||||||
|
|
||||||
export default function TransferFromAccountFormContent() {
|
|
||||||
return (
|
|
||||||
<Form>
|
|
||||||
<TransferFromAccountFormFields />
|
|
||||||
<MoneyInFloatingActions />
|
|
||||||
</Form>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -41,7 +41,7 @@ function TransferFromAccountFormFields() {
|
|||||||
const amountFieldRef = useAutofocus();
|
const amountFieldRef = useAutofocus();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={Classes.DIALOG_BODY}>
|
<React.Fragment>
|
||||||
<Row>
|
<Row>
|
||||||
<Col xs={5}>
|
<Col xs={5}>
|
||||||
{/*------------ Date -----------*/}
|
{/*------------ Date -----------*/}
|
||||||
@@ -190,7 +190,7 @@ function TransferFromAccountFormFields() {
|
|||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</div>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormattedMessage as T } from 'components';
|
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 'redux';
|
import { compose } from 'redux';
|
||||||
@@ -11,13 +11,15 @@ const MoneyInDialogContent = React.lazy(() => import('./MoneyInDialogContent'));
|
|||||||
*/
|
*/
|
||||||
function MoneyInDialog({
|
function MoneyInDialog({
|
||||||
dialogName,
|
dialogName,
|
||||||
payload = { action: '', account_type: null, account_id: null },
|
payload = { account_type: '', account_id: null },
|
||||||
isOpen,
|
isOpen,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
name={dialogName}
|
name={dialogName}
|
||||||
title={<T id={'cash_flow_transaction.money_in'} />}
|
title={intl.get('cash_flow_transaction.money_in', {
|
||||||
|
value: payload.account_type?.name,
|
||||||
|
})}
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
canEscapeJeyClose={true}
|
canEscapeJeyClose={true}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
@@ -27,7 +29,7 @@ function MoneyInDialog({
|
|||||||
<MoneyInDialogContent
|
<MoneyInDialogContent
|
||||||
dialogName={dialogName}
|
dialogName={dialogName}
|
||||||
accountId={payload.account_id}
|
accountId={payload.account_id}
|
||||||
accountType={payload.account_type}
|
accountType={payload.account_type?.value}
|
||||||
/>
|
/>
|
||||||
</DialogSuspense>
|
</DialogSuspense>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormattedMessage as T } from 'components';
|
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 'redux';
|
import { compose } from 'redux';
|
||||||
@@ -13,13 +13,15 @@ const MoneyOutDialogContent = React.lazy(() =>
|
|||||||
*/
|
*/
|
||||||
function MoneyOutDialog({
|
function MoneyOutDialog({
|
||||||
dialogName,
|
dialogName,
|
||||||
payload = { action: '', account_type: null, account_id: null },
|
payload = { account_type: null, account_id: null },
|
||||||
isOpen,
|
isOpen,
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<Dialog
|
<Dialog
|
||||||
name={dialogName}
|
name={dialogName}
|
||||||
title={<T id={'cash_flow_transaction.money_out'} />}
|
title={intl.get('cash_flow_transaction.money_out', {
|
||||||
|
value: payload.account_type,
|
||||||
|
})}
|
||||||
isOpen={isOpen}
|
isOpen={isOpen}
|
||||||
canEscapeJeyClose={true}
|
canEscapeJeyClose={true}
|
||||||
autoFocus={true}
|
autoFocus={true}
|
||||||
|
|||||||
@@ -1382,8 +1382,8 @@
|
|||||||
"cash_flow_transaction.label_equity_account":"Equity account",
|
"cash_flow_transaction.label_equity_account":"Equity account",
|
||||||
"cash_flow_transaction.label_expense_account":"Expense account",
|
"cash_flow_transaction.label_expense_account":"Expense account",
|
||||||
"cash_flow_transaction_success_message":" The cashflow transaction has been created successfully.",
|
"cash_flow_transaction_success_message":" The cashflow transaction has been created successfully.",
|
||||||
"cash_flow_transaction.money_in":"Money In",
|
"cash_flow_transaction.money_in":"Money In {value}",
|
||||||
"cash_flow_transaction.money_out":"Money Out",
|
"cash_flow_transaction.money_out":"Money Out {value}",
|
||||||
"cash_flow_transaction.other_income_account":"Other income account",
|
"cash_flow_transaction.other_income_account":"Other income account",
|
||||||
"cash_flow_transaction.other_expense_account":"Other expense account",
|
"cash_flow_transaction.other_expense_account":"Other expense account",
|
||||||
"save_and_publish": "Save & Publish",
|
"save_and_publish": "Save & Publish",
|
||||||
|
|||||||
@@ -25,6 +25,12 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.trasnaction-type-fileds {
|
||||||
|
margin-bottom: 18px;
|
||||||
|
padding: 16px 0px 12px 0px;
|
||||||
|
border-bottom: 2px solid #e9e9e9;
|
||||||
|
}
|
||||||
|
|
||||||
.bp3-dialog-footer {
|
.bp3-dialog-footer {
|
||||||
padding-top: 10px;
|
padding-top: 10px;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user