mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
chrone: sperate client and server to different repos.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import * as Yup from 'yup';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DATATYPES_LENGTH } from 'common/dataTypes';
|
||||
|
||||
const Schema = Yup.object().shape({
|
||||
vendor_id: Yup.string()
|
||||
.label(intl.get('vendor_name_'))
|
||||
.required(),
|
||||
payment_date: Yup.date()
|
||||
.required()
|
||||
.label(intl.get('payment_date_')),
|
||||
payment_number: Yup.string()
|
||||
.nullable()
|
||||
.max(DATATYPES_LENGTH.STRING)
|
||||
.label(intl.get('payment_no_')),
|
||||
payment_account_id: Yup.number()
|
||||
.required()
|
||||
.label(intl.get('payment_account_')),
|
||||
reference: Yup.string().min(1).max(DATATYPES_LENGTH.STRING).nullable(),
|
||||
// statement: Yup.string().nullable().max(DATATYPES_LENGTH.TEXT),
|
||||
entries: Yup.array().of(
|
||||
Yup.object().shape({
|
||||
payment_amount: Yup.number().nullable(),
|
||||
bill_id: Yup.number()
|
||||
.nullable()
|
||||
.when(['payment_amount'], {
|
||||
is: (payment_amount) => payment_amount,
|
||||
then: Yup.number().required(),
|
||||
}),
|
||||
}),
|
||||
),
|
||||
});
|
||||
|
||||
export const CreateQuickPaymentMadeFormSchema = Schema;
|
||||
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||
import { useFormikContext } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
|
||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
function QuickPaymentMadeFloatingActions({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
// Formik context.
|
||||
const { isSubmitting } = useFormikContext();
|
||||
|
||||
const { dialogName } = useQuickPaymentMadeContext();
|
||||
|
||||
// Handle close button click.
|
||||
const handleCancelBtnClick = () => {
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_FOOTER}>
|
||||
<div className={Classes.DIALOG_FOOTER_ACTIONS}>
|
||||
<Button onClick={handleCancelBtnClick} style={{ minWidth: '75px' }}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
<Button
|
||||
intent={Intent.PRIMARY}
|
||||
disabled={isSubmitting}
|
||||
style={{ minWidth: '75px' }}
|
||||
type="submit"
|
||||
>
|
||||
{<T id={'make_payment'} />}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(QuickPaymentMadeFloatingActions);
|
||||
@@ -0,0 +1,84 @@
|
||||
import React from 'react';
|
||||
import { Formik } from 'formik';
|
||||
import { Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import intl from 'react-intl-universal';
|
||||
import { pick } from 'lodash';
|
||||
|
||||
import { AppToaster } from 'components';
|
||||
import { CreateQuickPaymentMadeFormSchema } from './QuickPaymentMade.schema';
|
||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
import QuickPaymentMadeFormContent from './QuickPaymentMadeFormContent';
|
||||
|
||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { defaultPaymentMade, transformErrors } from './utils';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Quick payment made form.
|
||||
*/
|
||||
function QuickPaymentMadeForm({
|
||||
// #withDialogActions
|
||||
closeDialog,
|
||||
}) {
|
||||
|
||||
const {
|
||||
bill,
|
||||
dialogName,
|
||||
createPaymentMadeMutate,
|
||||
} = useQuickPaymentMadeContext();
|
||||
|
||||
// Initial form values
|
||||
const initialValues = {
|
||||
...defaultPaymentMade,
|
||||
...bill,
|
||||
};
|
||||
|
||||
// Handles the form submit.
|
||||
const handleFormSubmit = (values, { setSubmitting, setFieldError }) => {
|
||||
const entries = [values]
|
||||
.filter((entry) => entry.id && entry.payment_amount)
|
||||
.map((entry) => ({
|
||||
bill_id: entry.id,
|
||||
...pick(entry, ['payment_amount']),
|
||||
}));
|
||||
|
||||
const form = {
|
||||
...values,
|
||||
vendor_id: values?.vendor?.id,
|
||||
entries,
|
||||
};
|
||||
|
||||
// Handle request response success.
|
||||
const onSuccess = () => {
|
||||
AppToaster.show({
|
||||
message: intl.get('the_payment_made_has_been_created_successfully'),
|
||||
intent: Intent.SUCCESS,
|
||||
});
|
||||
closeDialog(dialogName);
|
||||
};
|
||||
// Handle request response errors.
|
||||
const onError = ({
|
||||
response: {
|
||||
data: { errors },
|
||||
},
|
||||
}) => {
|
||||
if (errors) {
|
||||
transformErrors(errors, { setFieldError });
|
||||
}
|
||||
setSubmitting(false);
|
||||
};
|
||||
createPaymentMadeMutate(form).then(onSuccess).catch(onError);
|
||||
};
|
||||
|
||||
return (
|
||||
<Formik
|
||||
validationSchema={CreateQuickPaymentMadeFormSchema}
|
||||
initialValues={initialValues}
|
||||
onSubmit={handleFormSubmit}
|
||||
component={QuickPaymentMadeFormContent}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogActions)(QuickPaymentMadeForm);
|
||||
@@ -0,0 +1,15 @@
|
||||
import React from 'react';
|
||||
import { Form } from 'formik';
|
||||
import QuickPaymentMadeFormFields from './QuickPaymentMadeFormFields';
|
||||
import QuickPaymentMadeFloatingActions from './QuickPaymentMadeFloatingActions';
|
||||
/**
|
||||
* Quick payment made form content.
|
||||
*/
|
||||
export default function QuickPaymentMadeFormContent() {
|
||||
return (
|
||||
<Form>
|
||||
<QuickPaymentMadeFormFields />
|
||||
<QuickPaymentMadeFloatingActions />
|
||||
</Form>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import React from 'react';
|
||||
|
||||
import 'style/pages/PaymentReceive/QuickPaymentReceiveDialog.scss';
|
||||
|
||||
import { QuickPaymentMadeFormProvider } from './QuickPaymentMadeFormProvider';
|
||||
import QuickPaymentMadeForm from './QuickPaymentMadeForm';
|
||||
|
||||
/**
|
||||
* Quick payment made form dialog content.
|
||||
*/
|
||||
export default function QuickPaymentMadeFormDialogContent({
|
||||
// #ownProps
|
||||
dialogName,
|
||||
bill,
|
||||
}) {
|
||||
return (
|
||||
<QuickPaymentMadeFormProvider billId={bill} dialogName={dialogName}>
|
||||
<QuickPaymentMadeForm />
|
||||
</QuickPaymentMadeFormProvider>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,208 @@
|
||||
import React from 'react';
|
||||
import { FastField, ErrorMessage } from 'formik';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import intl from 'react-intl-universal';
|
||||
import {
|
||||
Classes,
|
||||
FormGroup,
|
||||
InputGroup,
|
||||
TextArea,
|
||||
Position,
|
||||
ControlGroup,
|
||||
} from '@blueprintjs/core';
|
||||
import { useAutofocus } from 'hooks';
|
||||
import classNames from 'classnames';
|
||||
import { CLASSES } from 'common/classes';
|
||||
import { DateInput } from '@blueprintjs/datetime';
|
||||
import { FieldRequiredHint, Col, Row } from 'components';
|
||||
import { ACCOUNT_TYPE } from 'common/accountTypes';
|
||||
import {
|
||||
AccountsSuggestField,
|
||||
InputPrependText,
|
||||
MoneyInputGroup,
|
||||
Icon,
|
||||
} from 'components';
|
||||
import {
|
||||
inputIntent,
|
||||
momentFormatter,
|
||||
tansformDateValue,
|
||||
handleDateChange,
|
||||
} from 'utils';
|
||||
import { useQuickPaymentMadeContext } from './QuickPaymentMadeFormProvider';
|
||||
|
||||
/**
|
||||
* Quick payment made form fields.
|
||||
*/
|
||||
export default function QuickPaymentMadeFormFields() {
|
||||
const { accounts } = useQuickPaymentMadeContext();
|
||||
|
||||
// Intl context.
|
||||
|
||||
const paymentMadeFieldRef = useAutofocus();
|
||||
|
||||
return (
|
||||
<div className={Classes.DIALOG_BODY}>
|
||||
<Row>
|
||||
<Col xs={5}>
|
||||
{/* ------------- Vendor name ------------- */}
|
||||
<FastField name={'vendor_id'}>
|
||||
{({ from, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'vendor_name'} />}
|
||||
className={classNames('form-group--select-list', CLASSES.FILL)}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'vendor'} />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
minimal={true}
|
||||
disabled={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/* ------------ Payment number. ------------ */}
|
||||
<FastField name={'payment_number'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'payment_no'} />}
|
||||
className={('form-group--payment_number', CLASSES.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="payment_number" />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
minimal={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
</Row>
|
||||
{/*------------ Amount Received -----------*/}
|
||||
<FastField name={'payment_amount'}>
|
||||
{({
|
||||
form: { values, setFieldValue },
|
||||
field: { value },
|
||||
meta: { error, touched },
|
||||
}) => (
|
||||
<FormGroup
|
||||
label={<T id={'amount_received'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={classNames('form-group--payment_amount', CLASSES.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="payment_amount" />}
|
||||
>
|
||||
<ControlGroup>
|
||||
<InputPrependText text={values.currency_code} />
|
||||
|
||||
<MoneyInputGroup
|
||||
value={value}
|
||||
minimal={true}
|
||||
onChange={(amount) => {
|
||||
setFieldValue('payment_amount', amount);
|
||||
}}
|
||||
intent={inputIntent({ error, touched })}
|
||||
inputRef={(ref) => (paymentMadeFieldRef.current = ref)}
|
||||
/>
|
||||
</ControlGroup>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
<Row>
|
||||
<Col xs={5}>
|
||||
{/* ------------- Payment date ------------- */}
|
||||
<FastField name={'payment_date'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'payment_date'} />}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
className={classNames('form-group--select-list', CLASSES.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="payment_date" />}
|
||||
>
|
||||
<DateInput
|
||||
{...momentFormatter('YYYY/MM/DD')}
|
||||
value={tansformDateValue(value)}
|
||||
onChange={handleDateChange((formattedDate) => {
|
||||
form.setFieldValue('payment_date', formattedDate);
|
||||
})}
|
||||
popoverProps={{ position: Position.BOTTOM, minimal: true }}
|
||||
inputProps={{
|
||||
leftIcon: <Icon icon={'date-range'} />,
|
||||
}}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
<Col xs={5}>
|
||||
{/* ------------ payment account ------------ */}
|
||||
<FastField name={'payment_account_id'}>
|
||||
{({ form, field: { value }, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'payment_account'} />}
|
||||
className={classNames(
|
||||
'form-group--payment_account_id',
|
||||
'form-group--select-list',
|
||||
CLASSES.FILL,
|
||||
)}
|
||||
labelInfo={<FieldRequiredHint />}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name={'payment_account_id'} />}
|
||||
>
|
||||
<AccountsSuggestField
|
||||
accounts={accounts}
|
||||
onAccountSelected={({ id }) =>
|
||||
form.setFieldValue('payment_account_id', id)
|
||||
}
|
||||
inputProps={{
|
||||
placeholder: intl.get('select_account'),
|
||||
}}
|
||||
filterByTypes={[
|
||||
ACCOUNT_TYPE.CASH,
|
||||
ACCOUNT_TYPE.BANK,
|
||||
ACCOUNT_TYPE.OTHER_CURRENT_ASSET,
|
||||
]}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</Col>
|
||||
</Row>
|
||||
{/* ------------ Reference No. ------------ */}
|
||||
<FastField name={'reference'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'reference'} />}
|
||||
className={classNames('form-group--reference', CLASSES.FILL)}
|
||||
intent={inputIntent({ error, touched })}
|
||||
helperText={<ErrorMessage name="reference" />}
|
||||
>
|
||||
<InputGroup
|
||||
intent={inputIntent({ error, touched })}
|
||||
minimal={true}
|
||||
{...field}
|
||||
/>
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
{/* --------- Statement --------- */}
|
||||
<FastField name={'statement'}>
|
||||
{({ form, field, meta: { error, touched } }) => (
|
||||
<FormGroup
|
||||
label={<T id={'statement'} />}
|
||||
className={'form-group--statement'}
|
||||
>
|
||||
<TextArea growVertically={true} {...field} />
|
||||
</FormGroup>
|
||||
)}
|
||||
</FastField>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
import React from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import { useBill, useAccounts, useCreatePaymentMade } from 'hooks/query';
|
||||
|
||||
import { pick } from 'lodash';
|
||||
|
||||
const QuickPaymentMadeContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Quick payment made dialog provider.
|
||||
*/
|
||||
function QuickPaymentMadeFormProvider({ billId, dialogName, ...props }) {
|
||||
// Handle fetch bill details.
|
||||
const { isLoading: isBillLoading, data: bill } = useBill(billId, {
|
||||
enabled: !!billId,
|
||||
});
|
||||
|
||||
// Handle fetch accounts data.
|
||||
const { data: accounts, isLoading: isAccountsLoading } = useAccounts();
|
||||
|
||||
// Create payment made mutations.
|
||||
const { mutateAsync: createPaymentMadeMutate } = useCreatePaymentMade();
|
||||
|
||||
// State provider.
|
||||
const provider = {
|
||||
bill: {
|
||||
...pick(bill, ['id', 'due_amount', 'vendor', 'currency_code']),
|
||||
vendor_id: bill?.vendor?.display_name,
|
||||
payment_amount: bill?.due_amount,
|
||||
},
|
||||
accounts,
|
||||
dialogName,
|
||||
createPaymentMadeMutate,
|
||||
};
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isAccountsLoading || isBillLoading}>
|
||||
<QuickPaymentMadeContext.Provider value={provider} {...props} />
|
||||
</DialogContent>
|
||||
);
|
||||
}
|
||||
|
||||
const useQuickPaymentMadeContext = () =>
|
||||
React.useContext(QuickPaymentMadeContext);
|
||||
|
||||
export { QuickPaymentMadeFormProvider, useQuickPaymentMadeContext };
|
||||
38
src/containers/Dialogs/QuickPaymentMadeFormDialog/index.js
Normal file
38
src/containers/Dialogs/QuickPaymentMadeFormDialog/index.js
Normal file
@@ -0,0 +1,38 @@
|
||||
import React, { lazy } from 'react';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { Dialog, DialogSuspense } from 'components';
|
||||
import withDialogRedux from 'components/DialogReduxConnect';
|
||||
import { compose } from 'redux';
|
||||
|
||||
const QuickPaymentMadeFormDialogContent = lazy(() =>
|
||||
import('./QuickPaymentMadeFormDialogContent'),
|
||||
);
|
||||
|
||||
/**
|
||||
* Quick payment made form dialog.
|
||||
*/
|
||||
function QuickPaymentMadeFormDialog({
|
||||
dialogName,
|
||||
payload = { billId: null },
|
||||
isOpen,
|
||||
}) {
|
||||
return (
|
||||
<Dialog
|
||||
name={dialogName}
|
||||
title={<T id={'quick_made_payment'} />}
|
||||
isOpen={isOpen}
|
||||
canEscapeJeyClose={true}
|
||||
autoFocus={true}
|
||||
className={'dialog--quick-payment-receive'}
|
||||
>
|
||||
<DialogSuspense>
|
||||
<QuickPaymentMadeFormDialogContent
|
||||
bill={payload.billId}
|
||||
dialogName={dialogName}
|
||||
/>
|
||||
</DialogSuspense>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(withDialogRedux())(QuickPaymentMadeFormDialog);
|
||||
30
src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.js
Normal file
30
src/containers/Dialogs/QuickPaymentMadeFormDialog/utils.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import moment from 'moment';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
// Default initial values of payment made.
|
||||
export const defaultPaymentMade = {
|
||||
vendor_id: '',
|
||||
payment_account_id: '',
|
||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
reference: '',
|
||||
payment_number: '',
|
||||
// statement: '',
|
||||
entries: [{ bill_id: '', payment_amount: '' }],
|
||||
};
|
||||
|
||||
export const transformErrors = (errors, { setFieldError }) => {
|
||||
const getError = (errorType) => errors.find((e) => e.type === errorType);
|
||||
|
||||
if (getError('PAYMENT.NUMBER.NOT.UNIQUE')) {
|
||||
setFieldError(
|
||||
'payment_number',
|
||||
intl.get('payment_number_is_not_unique'),
|
||||
);
|
||||
}
|
||||
if (getError('INVALID_PAYMENT_AMOUNT')) {
|
||||
setFieldError(
|
||||
'payment_amount',
|
||||
intl.get('the_payment_amount_bigger_than_invoice_due_amount'),
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user