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