mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
fix(QuickPayment): payment receive number manual/auto-increment mode.
This commit is contained in:
@@ -2,16 +2,17 @@ import React from 'react';
|
|||||||
import { Formik } from 'formik';
|
import { Formik } from 'formik';
|
||||||
import { Intent } from '@blueprintjs/core';
|
import { Intent } from '@blueprintjs/core';
|
||||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||||
import { pick } from 'lodash';
|
import { pick, defaultTo } from 'lodash';
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
||||||
import { CreateQuickPaymentReceiveFormSchema } from './QuickPaymentReceive.schema';
|
import { CreateQuickPaymentReceiveFormSchema } from './QuickPaymentReceive.schema';
|
||||||
import QuickPaymentReceiveFormContent from './QuickPaymentReceiveFormContent';
|
import QuickPaymentReceiveFormContent from './QuickPaymentReceiveFormContent';
|
||||||
|
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
import withDialogActions from 'containers/Dialog/withDialogActions';
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
import { defaultInitialValues, transformErrors } from './utils';
|
import { defaultInitialValues, transformErrors } from './utils';
|
||||||
import { compose } from 'utils';
|
import { compose, transactionNumber } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick payment receive form.
|
* Quick payment receive form.
|
||||||
@@ -19,6 +20,12 @@ import { compose } from 'utils';
|
|||||||
function QuickPaymentReceiveForm({
|
function QuickPaymentReceiveForm({
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
closeDialog,
|
closeDialog,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
paymentReceiveAutoIncrement,
|
||||||
|
paymentReceiveNumberPrefix,
|
||||||
|
paymentReceiveNextNumber,
|
||||||
|
preferredDepositAccount
|
||||||
}) {
|
}) {
|
||||||
const { formatMessage } = useIntl();
|
const { formatMessage } = useIntl();
|
||||||
const {
|
const {
|
||||||
@@ -27,14 +34,25 @@ function QuickPaymentReceiveForm({
|
|||||||
createPaymentReceiveMutate,
|
createPaymentReceiveMutate,
|
||||||
} = useQuickPaymentReceiveContext();
|
} = useQuickPaymentReceiveContext();
|
||||||
|
|
||||||
|
// Payment receive number.
|
||||||
|
const nextPaymentNumber = transactionNumber(
|
||||||
|
paymentReceiveNumberPrefix,
|
||||||
|
paymentReceiveNextNumber,
|
||||||
|
);
|
||||||
|
|
||||||
// Initial form values
|
// Initial form values
|
||||||
const initialValues = {
|
const initialValues = {
|
||||||
...defaultInitialValues,
|
...defaultInitialValues,
|
||||||
|
...(paymentReceiveAutoIncrement && {
|
||||||
|
payment_receive_no: nextPaymentNumber,
|
||||||
|
}),
|
||||||
|
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
||||||
...invoice,
|
...invoice,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handles the form submit.
|
// Handles the form submit.
|
||||||
const handleFormSubmit = (values, { setSubmitting, setFieldError }) => {
|
const handleFormSubmit = (values, { setSubmitting, setFieldError, status }) => {
|
||||||
|
debugger;
|
||||||
const entries = [values]
|
const entries = [values]
|
||||||
.filter((entry) => entry.id && entry.payment_amount)
|
.filter((entry) => entry.id && entry.payment_amount)
|
||||||
.map((entry) => ({
|
.map((entry) => ({
|
||||||
@@ -69,7 +87,6 @@ function QuickPaymentReceiveForm({
|
|||||||
}
|
}
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
createPaymentReceiveMutate(form).then(onSaved).catch(onError);
|
createPaymentReceiveMutate(form).then(onSaved).catch(onError);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -83,4 +100,12 @@ function QuickPaymentReceiveForm({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(withDialogActions)(QuickPaymentReceiveForm);
|
export default compose(
|
||||||
|
withDialogActions,
|
||||||
|
withSettings(({ paymentReceiveSettings }) => ({
|
||||||
|
paymentReceiveNextNumber: paymentReceiveSettings?.nextNumber,
|
||||||
|
paymentReceiveNumberPrefix: paymentReceiveSettings?.numberPrefix,
|
||||||
|
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
||||||
|
preferredDepositAccount: paymentReceiveSettings?.depositAccount,
|
||||||
|
})),
|
||||||
|
)(QuickPaymentReceiveForm);
|
||||||
|
|||||||
@@ -26,13 +26,17 @@ import {
|
|||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
|
compose
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
import { useQuickPaymentReceiveContext } from './QuickPaymentReceiveFormProvider';
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Quick payment receive form fields.
|
* Quick payment receive form fields.
|
||||||
*/
|
*/
|
||||||
export default function QuickPaymentReceiveFormFields({}) {
|
function QuickPaymentReceiveFormFields({
|
||||||
|
paymentReceiveAutoIncrement
|
||||||
|
}) {
|
||||||
const { accounts } = useQuickPaymentReceiveContext();
|
const { accounts } = useQuickPaymentReceiveContext();
|
||||||
|
|
||||||
// Intl context.
|
// Intl context.
|
||||||
@@ -78,6 +82,7 @@ export default function QuickPaymentReceiveFormFields({}) {
|
|||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
{...field}
|
{...field}
|
||||||
|
disabled={paymentReceiveAutoIncrement}
|
||||||
/>
|
/>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
@@ -157,6 +162,7 @@ export default function QuickPaymentReceiveFormFields({}) {
|
|||||||
helperText={<ErrorMessage name={'deposit_account_id'} />}
|
helperText={<ErrorMessage name={'deposit_account_id'} />}
|
||||||
>
|
>
|
||||||
<AccountsSuggestField
|
<AccountsSuggestField
|
||||||
|
selectedAccountId={value}
|
||||||
accounts={accounts}
|
accounts={accounts}
|
||||||
onAccountSelected={({ id }) =>
|
onAccountSelected={({ id }) =>
|
||||||
form.setFieldValue('deposit_account_id', id)
|
form.setFieldValue('deposit_account_id', id)
|
||||||
@@ -208,3 +214,9 @@ export default function QuickPaymentReceiveFormFields({}) {
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withSettings(({ paymentReceiveSettings }) => ({
|
||||||
|
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
||||||
|
})),
|
||||||
|
)(QuickPaymentReceiveFormFields)
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import React, { useContext, createContext } from 'react';
|
import React, { useContext, createContext } from 'react';
|
||||||
import { pick } from 'lodash';
|
import { pick } from 'lodash';
|
||||||
import { DialogContent } from 'components';
|
import { DialogContent } from 'components';
|
||||||
import { useAccounts, useInvoice, useCreatePaymentReceive } from 'hooks/query';
|
import { useAccounts, useInvoice, useSettingsPaymentReceives, useCreatePaymentReceive } from 'hooks/query';
|
||||||
|
|
||||||
const QuickPaymentReceiveContext = createContext();
|
const QuickPaymentReceiveContext = createContext();
|
||||||
|
|
||||||
@@ -16,10 +16,12 @@ function QuickPaymentReceiveFormProvider({ invoiceId, dialogName, ...props }) {
|
|||||||
const { data: invoice, isLoading: isInvoiceLoading } = useInvoice(invoiceId, {
|
const { data: invoice, isLoading: isInvoiceLoading } = useInvoice(invoiceId, {
|
||||||
enabled: !!invoiceId,
|
enabled: !!invoiceId,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create and edit payment receive mutations.
|
// Create and edit payment receive mutations.
|
||||||
const { mutateAsync: createPaymentReceiveMutate } = useCreatePaymentReceive();
|
const { mutateAsync: createPaymentReceiveMutate } = useCreatePaymentReceive();
|
||||||
|
|
||||||
|
// Fetch payment made settings.
|
||||||
|
const { isLoading: isSettingsLoading } = useSettingsPaymentReceives();
|
||||||
|
|
||||||
// State provider.
|
// State provider.
|
||||||
const provider = {
|
const provider = {
|
||||||
accounts,
|
accounts,
|
||||||
@@ -28,8 +30,8 @@ function QuickPaymentReceiveFormProvider({ invoiceId, dialogName, ...props }) {
|
|||||||
customer_id: invoice?.customer?.display_name,
|
customer_id: invoice?.customer?.display_name,
|
||||||
payment_amount: invoice.due_amount,
|
payment_amount: invoice.due_amount,
|
||||||
},
|
},
|
||||||
|
|
||||||
isAccountsLoading,
|
isAccountsLoading,
|
||||||
|
isSettingsLoading,
|
||||||
dialogName,
|
dialogName,
|
||||||
|
|
||||||
createPaymentReceiveMutate,
|
createPaymentReceiveMutate,
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ function PaymentReceiveForm({
|
|||||||
nextPaymentNumber,
|
nextPaymentNumber,
|
||||||
paymentEntriesEditPage,
|
paymentEntriesEditPage,
|
||||||
paymentReceiveAutoIncrement,
|
paymentReceiveAutoIncrement,
|
||||||
|
preferredDepositAccount
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user