mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 21:30:31 +00:00
fix(webapp): auto-increment estimate transactions
This commit is contained in:
@@ -19,6 +19,7 @@ import EstimateFloatingActions from './EstimateFloatingActions';
|
||||
import EstimateFormFooter from './EstimateFormFooter';
|
||||
import EstimateFormDialogs from './EstimateFormDialogs';
|
||||
import EstimtaeFormTopBar from './EstimtaeFormTopBar';
|
||||
import { EstimateIncrementSyncSettingsToForm } from './components';
|
||||
|
||||
import withSettings from '@/containers/Settings/withSettings';
|
||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||
@@ -31,8 +32,8 @@ import {
|
||||
defaultEstimate,
|
||||
transfromsFormValuesToRequest,
|
||||
handleErrors,
|
||||
resetFormState,
|
||||
} from './utils';
|
||||
import { EstimateIncrementSyncSettingsToForm } from './components';
|
||||
|
||||
/**
|
||||
* Estimate form.
|
||||
@@ -41,7 +42,7 @@ function EstimateForm({
|
||||
// #withSettings
|
||||
estimateNextNumber,
|
||||
estimateNumberPrefix,
|
||||
estimateIncrementMode,
|
||||
estimateAutoIncrementMode,
|
||||
|
||||
// #withCurrentOrganization
|
||||
organization: { base_currency },
|
||||
@@ -67,14 +68,16 @@ function EstimateForm({
|
||||
? { ...transformToEditForm(estimate) }
|
||||
: {
|
||||
...defaultEstimate,
|
||||
...(estimateIncrementMode && {
|
||||
// If the auto-increment mode is enabled, take the next estimate
|
||||
// number from the settings.
|
||||
...(estimateAutoIncrementMode && {
|
||||
estimate_number: estimateNumber,
|
||||
}),
|
||||
entries: orderingLinesIndexes(defaultEstimate.entries),
|
||||
currency_code: base_currency,
|
||||
}),
|
||||
}),
|
||||
[estimate, estimateNumber, estimateIncrementMode, base_currency],
|
||||
[estimate, estimateNumber, estimateAutoIncrementMode, base_currency],
|
||||
);
|
||||
|
||||
// Handles form submit.
|
||||
@@ -119,7 +122,7 @@ function EstimateForm({
|
||||
history.push('/estimates');
|
||||
}
|
||||
if (submitPayload.resetForm) {
|
||||
resetForm();
|
||||
resetFormState({ resetForm, initialValues, values });
|
||||
}
|
||||
};
|
||||
// Handle the request error.
|
||||
@@ -177,7 +180,7 @@ export default compose(
|
||||
withSettings(({ estimatesSettings }) => ({
|
||||
estimateNextNumber: estimatesSettings?.nextNumber,
|
||||
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
||||
estimateIncrementMode: estimatesSettings?.autoIncrement,
|
||||
estimateAutoIncrementMode: estimatesSettings?.autoIncrement,
|
||||
})),
|
||||
withCurrentOrganization(),
|
||||
)(EstimateForm);
|
||||
|
||||
@@ -9,10 +9,14 @@ import EstimateNumberDialog from '@/containers/Dialogs/EstimateNumberDialog';
|
||||
export default function EstimateFormDialogs() {
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
// Update the form once the invoice number form submit confirm.
|
||||
// Update the form once the estimate number form submit confirm.
|
||||
const handleEstimateNumberFormConfirm = (settings) => {
|
||||
setFieldValue('estimate_number', settings.transactionNumber);
|
||||
setFieldValue('estimate_number_manually', settings.transactionNumber);
|
||||
setFieldValue('estimate_number_manually', '');
|
||||
|
||||
if (settings.incrementMode !== 'auto') {
|
||||
setFieldValue('estimate_number_manually', settings.transactionNumber);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
|
||||
@@ -67,9 +67,12 @@ const EstimateFormEstimateNumberField = R.compose(
|
||||
const handleEstimateNumberBtnClick = () => {
|
||||
openDialog('estimate-number-form', {});
|
||||
};
|
||||
// Handle estimate no. field blur.
|
||||
const handleEstimateNoBlur = (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
// Show the confirmation dialog if the value has changed and auto-increment
|
||||
// mode is enabled.
|
||||
if (values.estimate_number !== newValue && estimateAutoIncrement) {
|
||||
openDialog('estimate-number-form', {
|
||||
initialFormValues: {
|
||||
@@ -78,6 +81,8 @@ const EstimateFormEstimateNumberField = R.compose(
|
||||
},
|
||||
});
|
||||
}
|
||||
// Setting the estimate number to the form will be manually in case
|
||||
// auto-increment is disable.
|
||||
if (!estimateAutoIncrement) {
|
||||
setFieldValue('estimate_number', newValue);
|
||||
setFieldValue('estimate_number_manually', newValue);
|
||||
@@ -96,7 +101,7 @@ const EstimateFormEstimateNumberField = R.compose(
|
||||
minimal={true}
|
||||
asyncControl={true}
|
||||
onBlur={handleEstimateNoBlur}
|
||||
fastField={true}
|
||||
onChange={() => {}}
|
||||
/>
|
||||
<InputPrependButton
|
||||
buttonProps={{
|
||||
|
||||
@@ -56,13 +56,13 @@ export const EstimateIncrementSyncSettingsToForm = R.compose(
|
||||
const { setFieldValue } = useFormikContext();
|
||||
|
||||
useUpdateEffect(() => {
|
||||
// Do not update if the estimate auto-increment mode is disabled.
|
||||
if (!estimateAutoIncrement) return null;
|
||||
|
||||
const estimateNo = transactionNumber(
|
||||
estimateNumberPrefix,
|
||||
estimateNextNumber,
|
||||
setFieldValue(
|
||||
'estimate_number',
|
||||
transactionNumber(estimateNumberPrefix, estimateNextNumber),
|
||||
);
|
||||
setFieldValue('estimate_number', estimateNo);
|
||||
}, [
|
||||
setFieldValue,
|
||||
estimateNumberPrefix,
|
||||
|
||||
@@ -7,7 +7,6 @@ import { useFormikContext } from 'formik';
|
||||
import { omit, first } from 'lodash';
|
||||
import {
|
||||
defaultFastFieldShouldUpdate,
|
||||
transactionNumber,
|
||||
repeatValue,
|
||||
transformToForm,
|
||||
formattedAmount,
|
||||
@@ -37,6 +36,7 @@ export const defaultEstimate = {
|
||||
estimate_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
expiration_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
estimate_number: '',
|
||||
estimate_number_manually: '',
|
||||
delivered: '',
|
||||
reference: '',
|
||||
note: '',
|
||||
@@ -142,6 +142,8 @@ export const transfromsFormValuesToRequest = (values) => {
|
||||
);
|
||||
return {
|
||||
...omit(values, ['estimate_number_manually', 'estimate_number']),
|
||||
// The `estimate_number_manually` will be presented just if the auto-increment
|
||||
// is disable, always both attributes hold the same value in manual mode.
|
||||
...(values.estimate_number_manually && {
|
||||
estimate_number: values.estimate_number,
|
||||
}),
|
||||
@@ -223,3 +225,17 @@ export const useEstimateIsForeignCustomer = () => {
|
||||
);
|
||||
return isForeignCustomer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Resets the form values.
|
||||
*/
|
||||
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