mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-20 14:50:32 +00:00
fix(webapp): payment receive auto-increment
This commit is contained in:
@@ -106,7 +106,7 @@ function CreditNoteForm({
|
|||||||
open: submitPayload.open,
|
open: submitPayload.open,
|
||||||
};
|
};
|
||||||
// Handle the request success.
|
// Handle the request success.
|
||||||
const onSuccess = (response) => {
|
const onSuccess = () => {
|
||||||
AppToaster.show({
|
AppToaster.show({
|
||||||
message: intl.get(
|
message: intl.get(
|
||||||
isNewMode
|
isNewMode
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ export const defaultEstimate = {
|
|||||||
estimate_date: moment(new Date()).format('YYYY-MM-DD'),
|
estimate_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
expiration_date: moment(new Date()).format('YYYY-MM-DD'),
|
expiration_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
estimate_number: '',
|
estimate_number: '',
|
||||||
|
// Holds the estimate number that entered manually only.
|
||||||
estimate_number_manually: '',
|
estimate_number_manually: '',
|
||||||
delivered: '',
|
delivered: '',
|
||||||
reference: '',
|
reference: '',
|
||||||
|
|||||||
@@ -43,6 +43,7 @@ export const defaultInvoice = {
|
|||||||
due_date: moment().format('YYYY-MM-DD'),
|
due_date: moment().format('YYYY-MM-DD'),
|
||||||
delivered: '',
|
delivered: '',
|
||||||
invoice_no: '',
|
invoice_no: '',
|
||||||
|
// Holds the invoice number that entered manually only.
|
||||||
invoice_no_manually: '',
|
invoice_no_manually: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
invoice_message: '',
|
invoice_message: '',
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ import {
|
|||||||
transformToEditForm,
|
transformToEditForm,
|
||||||
transformFormToRequest,
|
transformFormToRequest,
|
||||||
transformErrors,
|
transformErrors,
|
||||||
|
resetFormState,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { PaymentReceiveSyncIncrementSettingsToForm } from './components';
|
import { PaymentReceiveSyncIncrementSettingsToForm } from './components';
|
||||||
|
|
||||||
@@ -76,10 +77,12 @@ function PaymentReceiveForm({
|
|||||||
? transformToEditForm(paymentReceiveEditPage, paymentEntriesEditPage)
|
? transformToEditForm(paymentReceiveEditPage, paymentEntriesEditPage)
|
||||||
: {
|
: {
|
||||||
...defaultPaymentReceive,
|
...defaultPaymentReceive,
|
||||||
|
// If the auto-increment mode is enabled, take the next payment
|
||||||
|
// number from the settings.
|
||||||
...(paymentReceiveAutoIncrement && {
|
...(paymentReceiveAutoIncrement && {
|
||||||
payment_receive_no: nextPaymentNumber,
|
payment_receive_no: nextPaymentNumber,
|
||||||
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
|
||||||
}),
|
}),
|
||||||
|
deposit_account_id: defaultTo(preferredDepositAccount, ''),
|
||||||
currency_code: base_currency,
|
currency_code: base_currency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
@@ -128,7 +131,7 @@ function PaymentReceiveForm({
|
|||||||
history.push('/payment-receives');
|
history.push('/payment-receives');
|
||||||
}
|
}
|
||||||
if (submitPayload.resetForm) {
|
if (submitPayload.resetForm) {
|
||||||
resetForm();
|
resetFormState({ resetForm, initialValues, values });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Handle request response errors.
|
// Handle request response errors.
|
||||||
|
|||||||
@@ -10,8 +10,14 @@ export default function PaymentReceiveFormDialogs() {
|
|||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
const handleUpdatePaymentNumber = (settings) => {
|
const handleUpdatePaymentNumber = (settings) => {
|
||||||
|
// Set the payment transaction no. that cames from dialog to the form.
|
||||||
|
// the `payment_receive_no_manually` will be empty except the increment mode is not auto.
|
||||||
setFieldValue('payment_receive_no', settings.transactionNumber);
|
setFieldValue('payment_receive_no', settings.transactionNumber);
|
||||||
setFieldValue('payment_receive_no_manually', settings.transactionNumber);
|
setFieldValue('payment_receive_no_manually', '');
|
||||||
|
|
||||||
|
if (settings.incrementMode !== 'auto') {
|
||||||
|
setFieldValue('payment_receive_no_manually', settings.transactionNumber);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import { toSafeInteger } from 'lodash';
|
|||||||
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
|
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import { FeatureCan, FormattedMessage as T } from '@/components';
|
import { FInputGroup, FeatureCan, FormattedMessage as T } from '@/components';
|
||||||
import { useAutofocus } from '@/hooks';
|
import { useAutofocus } from '@/hooks';
|
||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import {
|
import {
|
||||||
@@ -83,6 +83,8 @@ const PaymentReceivePaymentNoField = R.compose(
|
|||||||
const handlePaymentNoBlur = (event) => {
|
const handlePaymentNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
|
// Show the confirmation dialog if the value has changed and auto-increment
|
||||||
|
// mode is enabled.
|
||||||
if (
|
if (
|
||||||
values.payment_receive_no !== newValue &&
|
values.payment_receive_no !== newValue &&
|
||||||
paymentReceiveAutoIncrement
|
paymentReceiveAutoIncrement
|
||||||
@@ -94,26 +96,28 @@ const PaymentReceivePaymentNoField = R.compose(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Setting the payment number to the form will be manually in case
|
||||||
|
// auto-increment is disable.
|
||||||
if (!paymentReceiveAutoIncrement) {
|
if (!paymentReceiveAutoIncrement) {
|
||||||
setFieldValue('payment_receive_no', newValue);
|
setFieldValue('payment_receive_no', newValue);
|
||||||
setFieldValue('payment_receive_no_manually', newValue);
|
setFieldValue('payment_receive_no_manually', newValue);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return (
|
return (
|
||||||
<FormGroup
|
<FFormGroup
|
||||||
name={'payment_receive_no'}
|
name={'payment_receive_no'}
|
||||||
label={<T id={'payment_receive_no'} />}
|
label={<T id={'payment_receive_no'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
labelInfo={<FieldRequiredHint />}
|
labelInfo={<FieldRequiredHint />}
|
||||||
helperText={<ErrorMessage name="payment_receive_no" />}
|
|
||||||
>
|
>
|
||||||
<ControlGroup fill={true}>
|
<ControlGroup fill={true}>
|
||||||
<InputGroup
|
<FInputGroup
|
||||||
name={'payment_receive_no'}
|
name={'payment_receive_no'}
|
||||||
minimal={true}
|
minimal={true}
|
||||||
value={values.payment_receive_no}
|
value={values.payment_receive_no}
|
||||||
asyncControl={true}
|
asyncControl={true}
|
||||||
onBlur={handlePaymentNoBlur}
|
onBlur={handlePaymentNoBlur}
|
||||||
|
onChange={() => {}}
|
||||||
/>
|
/>
|
||||||
<InputPrependButton
|
<InputPrependButton
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
@@ -129,7 +133,7 @@ const PaymentReceivePaymentNoField = R.compose(
|
|||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</ControlGroup>
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FFormGroup>
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React, { useEffect } from 'react';
|
import React, { useEffect, useLayoutEffect } from 'react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Button } from '@blueprintjs/core';
|
import { Button } from '@blueprintjs/core';
|
||||||
@@ -134,14 +134,13 @@ export const PaymentReceiveSyncIncrementSettingsToForm = R.compose(
|
|||||||
}) => {
|
}) => {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
useEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (!paymentReceiveAutoIncrement) return;
|
if (!paymentReceiveAutoIncrement) return;
|
||||||
|
|
||||||
const paymentReceiveNo = transactionNumber(
|
setFieldValue(
|
||||||
paymentReceiveNumberPrefix,
|
'payment_receive_no',
|
||||||
paymentReceiveNextNumber,
|
transactionNumber(paymentReceiveNumberPrefix, paymentReceiveNextNumber),
|
||||||
);
|
);
|
||||||
setFieldValue('payment_receive_no', paymentReceiveNo);
|
|
||||||
}, [
|
}, [
|
||||||
setFieldValue,
|
setFieldValue,
|
||||||
paymentReceiveNumberPrefix,
|
paymentReceiveNumberPrefix,
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import {
|
|||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
import { useCurrentOrganization } from '@/hooks/state';
|
import { useCurrentOrganization } from '@/hooks/state';
|
||||||
|
|
||||||
|
|
||||||
// Default payment receive entry.
|
// Default payment receive entry.
|
||||||
export const defaultPaymentReceiveEntry = {
|
export const defaultPaymentReceiveEntry = {
|
||||||
index: '',
|
index: '',
|
||||||
@@ -37,6 +36,8 @@ export const defaultPaymentReceive = {
|
|||||||
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
payment_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
payment_receive_no: '',
|
payment_receive_no: '',
|
||||||
|
// Holds the payment number that entered manually only.
|
||||||
|
payment_receive_no_manually: '',
|
||||||
statement: '',
|
statement: '',
|
||||||
full_amount: '',
|
full_amount: '',
|
||||||
currency_code: '',
|
currency_code: '',
|
||||||
@@ -156,6 +157,8 @@ export const transformFormToRequest = (form) => {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
...omit(form, ['payment_receive_no_manually', 'payment_receive_no']),
|
...omit(form, ['payment_receive_no_manually', 'payment_receive_no']),
|
||||||
|
// The `payment_receive_no_manually` will be presented just if the auto-increment
|
||||||
|
// is disable, always both attributes hold the same value in manual mode.
|
||||||
...(form.payment_receive_no_manually && {
|
...(form.payment_receive_no_manually && {
|
||||||
payment_receive_no: form.payment_receive_no,
|
payment_receive_no: form.payment_receive_no,
|
||||||
}),
|
}),
|
||||||
@@ -252,3 +255,13 @@ export const useEstimateIsForeignCustomer = () => {
|
|||||||
);
|
);
|
||||||
return isForeignCustomer;
|
return isForeignCustomer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resetFormState = ({ initialValues, values, resetForm }) => {
|
||||||
|
resetForm({
|
||||||
|
values: {
|
||||||
|
// Reset the all values except the brand id.
|
||||||
|
...initialValues,
|
||||||
|
brand_id: values.brand_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ import {
|
|||||||
defaultReceipt,
|
defaultReceipt,
|
||||||
handleErrors,
|
handleErrors,
|
||||||
transformFormValuesToRequest,
|
transformFormValuesToRequest,
|
||||||
|
resetFormState,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { ReceiptSyncIncrementSettingsToForm } from './components';
|
import { ReceiptSyncIncrementSettingsToForm } from './components';
|
||||||
|
|
||||||
@@ -122,7 +123,7 @@ function ReceiptForm({
|
|||||||
history.push('/receipts');
|
history.push('/receipts');
|
||||||
}
|
}
|
||||||
if (submitPayload.resetForm) {
|
if (submitPayload.resetForm) {
|
||||||
resetForm();
|
resetFormState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -239,3 +239,14 @@ export const useReceiptIsForeignCustomer = () => {
|
|||||||
);
|
);
|
||||||
return isForeignCustomer;
|
return isForeignCustomer;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const resetFormState = ({ initialValues, values, resetForm }) => {
|
||||||
|
resetForm({
|
||||||
|
values: {
|
||||||
|
// Reset the all values except the warehouse and brand id.
|
||||||
|
...initialValues,
|
||||||
|
warehouse_id: values.warehouse_id,
|
||||||
|
brand_id: values.brand_id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user