mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
feat : Cash flow transaction type.
This commit is contained in:
@@ -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 { CreateTransferToAccountFormSchema } from './TransferToAccountForm.schema';
|
||||
import TransferToAccountFromContent from './TransferToAccountFromContent';
|
||||
|
||||
import { useMoneyOutDialogContext } from '../MoneyOutProvider';
|
||||
|
||||
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 to account form.
|
||||
*/
|
||||
function TransferToAccountForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
}) {
|
||||
const {
|
||||
dialogName,
|
||||
accountId,
|
||||
createCashflowTransactionMutate,
|
||||
submitPayload,
|
||||
} = useMoneyOutDialogContext();
|
||||
|
||||
// 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={CreateTransferToAccountFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
>
|
||||
<TransferToAccountFromContent />
|
||||
</Formik>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withCurrentOrganization(),
|
||||
)(TransferToAccountForm);
|
||||
Reference in New Issue
Block a user