feat : Cash flow transaction type.

This commit is contained in:
elforjani13
2021-10-17 18:00:40 +02:00
parent 2078b6bc99
commit c148e2976a
33 changed files with 1273 additions and 63 deletions

View File

@@ -1,20 +1,24 @@
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 'OWNERS':
case 'OWNER_CONTRIBUTION':
return <OwnerContributionForm />;
case 'EQUITY':
case 'OTHER_INCOME':
return <OtherIncomeForm />;
case 'TRANSFER_FROM_ACCOUNT':
return <TransferFromAccountForm />;
default:
break;
}
};
return <div>{handleFromTransaction()}</div>;
return <React.Fragment>{handleFromTransaction()}</React.Fragment>;
}

View File

@@ -2,6 +2,7 @@ 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';
@@ -50,13 +51,13 @@ function OtherIncomeForm({
const initialValues = {
...defaultInitialValues,
currency_code: base_currency,
credit_account_id: accountId,
cashflow_account_id: accountId,
};
// Handles the form submit.
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
const form = {
...values,
...omit(values, ['currency_code']),
published: submitPayload.publish,
};
setSubmitting(true);

View File

@@ -6,12 +6,12 @@ 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().label(intl.get('transaction_type')),
transaction_type: Yup.string().required(),
reference_no: Yup.string(),
credit_account_id: Yup.number().required(),
cashflow_account_id: Yup.string()
credit_account_id: Yup.number()
.required()
.label(intl.get('other_income_account')),
cashflow_account_id: Yup.string().required(),
description: Yup.string()
.min(3)
.max(DATATYPES_LENGTH.TEXT)

View File

@@ -14,10 +14,14 @@ import {
AccountsSuggestField,
InputPrependText,
MoneyInputGroup,
FieldRequiredHint,
Col,
Row,
} from 'components';
import { DateInput } from '@blueprintjs/datetime';
import { useAutofocus } from 'hooks';
import { FieldRequiredHint, Col, Row } from 'components';
import { ACCOUNT_TYPE } from 'common/accountTypes';
import {
inputIntent,
momentFormatter,
@@ -28,7 +32,7 @@ import { CLASSES } from 'common/classes';
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
/**
* Other income form fiedls.
* Other income form fields.
*/
function OtherIncomeFormFields() {
// Money in dialog context.
@@ -120,20 +124,24 @@ function OtherIncomeFormFields() {
<Row>
<Col xs={5}>
{/*------------ other income account -----------*/}
<FastField name={'cashflow_account_id'}>
<FastField name={'credit_account_id'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'cash_flow_transaction.outher_income_account'} />}
label={<T id={'cash_flow_transaction.other_income_account'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="cashflow_account_id" />}
className={'form-group--cashflow_account_id'}
helperText={<ErrorMessage name="credit_account_id" />}
className={'form-group--credit_account_id'}
>
<AccountsSuggestField
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('cashflow_account_id', id)
form.setFieldValue('credit_account_id', id)
}
filterByTypes={[
ACCOUNT_TYPE.INCOME,
ACCOUNT_TYPE.OTHER_INCOME,
]}
inputProps={{
intent: inputIntent({ error, touched }),
}}

View File

@@ -2,6 +2,7 @@ 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';
@@ -50,13 +51,13 @@ function OwnerContributionForm({
const initialValues = {
...defaultInitialValues,
currency_code: base_currency,
credit_account_id: accountId,
cashflow_account_id: accountId,
};
// Handles the form submit.
const handleFormSubmit = (values, { setSubmitting, setErrors }) => {
const form = {
...values,
...omit(values, ['currency_code']),
published: submitPayload.publish,
};
setSubmitting(true);

View File

@@ -6,12 +6,12 @@ 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().label(intl.get('transaction_type')),
transaction_type: Yup.string().required(),
reference_no: Yup.string(),
credit_account_id: Yup.number().required(),
cashflow_account_id: 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)

View File

@@ -14,10 +14,13 @@ import {
AccountsSuggestField,
InputPrependText,
MoneyInputGroup,
FieldRequiredHint,
Col,
Row,
} from 'components';
import { DateInput } from '@blueprintjs/datetime';
import { useAutofocus } from 'hooks';
import { FieldRequiredHint, Col, Row } from 'components';
import { ACCOUNT_TYPE } from 'common/accountTypes';
import {
inputIntent,
momentFormatter,
@@ -118,21 +121,22 @@ function OwnerContributionFormFields() {
<Row>
<Col xs={5}>
{/*------------ cash flow account -----------*/}
<FastField name={'cashflow_account_id'}>
{/*------------ equity account -----------*/}
<FastField name={'credit_account_id'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'cash_flow_transaction.label_equity_account'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="cashflow_account_id" />}
className={'form-group--cashflow_account_id'}
helperText={<ErrorMessage name="credit_account_id" />}
className={'form-group--credit_account_id'}
>
<AccountsSuggestField
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('cashflow_account_id', id)
form.setFieldValue('credit_account_id', id)
}
filterByTypes={ACCOUNT_TYPE.EQUITY}
inputProps={{
intent: inputIntent({ error, touched }),
}}

View File

@@ -0,0 +1,92 @@
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);

View File

@@ -0,0 +1,22 @@
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;

View File

@@ -0,0 +1,14 @@
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>
);
}

View File

@@ -0,0 +1,198 @@
import React from 'react';
import { FastField, ErrorMessage } from 'formik';
import {
Classes,
FormGroup,
InputGroup,
TextArea,
Position,
ControlGroup,
} from '@blueprintjs/core';
import classNames from 'classnames';
import {
FormattedMessage as T,
AccountsSuggestField,
InputPrependText,
MoneyInputGroup,
FieldRequiredHint,
Col,
Row,
} from 'components';
import { DateInput } from '@blueprintjs/datetime';
import { useAutofocus } from 'hooks';
import { ACCOUNT_TYPE } from 'common/accountTypes';
import {
inputIntent,
momentFormatter,
tansformDateValue,
handleDateChange,
} from 'utils';
import { CLASSES } from 'common/classes';
import { useMoneyInDailogContext } from '../MoneyInDialogProvider';
/**
* Transfer from account form fields.
*/
function TransferFromAccountFormFields() {
// Money in dialog context.
const { accounts } = useMoneyInDailogContext();
const amountFieldRef = useAutofocus();
return (
<div className={Classes.DIALOG_BODY}>
<Row>
<Col xs={5}>
{/*------------ Date -----------*/}
<FastField name={'date'}>
{({ form, field: { value }, meta: { error, touched } }) => (
<FormGroup
label={<T id={'date'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="date" />}
minimal={true}
className={classNames(CLASSES.FILL, 'form-group--date')}
>
<DateInput
{...momentFormatter('YYYY/MM/DD')}
onChange={handleDateChange((formattedDate) => {
form.setFieldValue('date', formattedDate);
})}
value={tansformDateValue(value)}
popoverProps={{
position: Position.BOTTOM,
minimal: true,
}}
intent={inputIntent({ error, touched })}
/>
</FormGroup>
)}
</FastField>
</Col>
<Col xs={5}>
{/*------------ Transaction number -----------*/}
<FastField name={'transaction_number'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'transaction_number'} />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="transaction_number" />}
className={'form-group--transaction_number'}
>
<InputGroup
intent={inputIntent({ error, touched })}
{...field}
/>
</FormGroup>
)}
</FastField>
</Col>
</Row>
{/*------------ amount -----------*/}
<FastField name={'amount'}>
{({
form: { values, setFieldValue },
field: { value },
meta: { error, touched },
}) => (
<FormGroup
label={<T id={'amount'} />}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="amount" />}
className={'form-group--amount'}
>
<ControlGroup>
<InputPrependText text={values.currency_code} />
<MoneyInputGroup
value={value}
minimal={true}
onChange={(amount) => {
setFieldValue('amount', amount);
}}
inputRef={(ref) => (amountFieldRef.current = ref)}
intent={inputIntent({ error, touched })}
/>
</ControlGroup>
</FormGroup>
)}
</FastField>
<Row>
<Col xs={5}>
{/*------------ transfer from account -----------*/}
<FastField name={'credit_account_id'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
label={
'Transfer account'
// <T id={'cash_flow_transaction.label_transfer_from_account'} />
}
labelInfo={<FieldRequiredHint />}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name="credit_account_id" />}
className={'form-group--credit_account_id'}
>
<AccountsSuggestField
accounts={accounts}
onAccountSelected={({ id }) =>
form.setFieldValue('credit_account_id', id)
}
filterByTypes={[
ACCOUNT_TYPE.CASH,
ACCOUNT_TYPE.BANK,
ACCOUNT_TYPE.CREDIT_CARD,
]}
inputProps={{
intent: inputIntent({ error, touched }),
}}
/>
</FormGroup>
)}
</FastField>
</Col>
<Col xs={5}>
{/*------------ Reference -----------*/}
<FastField name={'reference_no'}>
{({ form, field, meta: { error, touched } }) => (
<FormGroup
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>
</Row>
{/*------------ description -----------*/}
<FastField name={'description'}>
{({ field, meta: { error, touched } }) => (
<FormGroup
label={<T id={'description'} />}
className={'form-group--description'}
intent={inputIntent({ error, touched })}
helperText={<ErrorMessage name={'description'} />}
>
<TextArea
growVertically={true}
large={true}
intent={inputIntent({ error, touched })}
{...field}
/>
</FormGroup>
)}
</FastField>
</div>
);
}
export default TransferFromAccountFormFields;