mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +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 EstimateFormFooter from './EstimateFormFooter';
|
||||||
import EstimateFormDialogs from './EstimateFormDialogs';
|
import EstimateFormDialogs from './EstimateFormDialogs';
|
||||||
import EstimtaeFormTopBar from './EstimtaeFormTopBar';
|
import EstimtaeFormTopBar from './EstimtaeFormTopBar';
|
||||||
|
import { EstimateIncrementSyncSettingsToForm } from './components';
|
||||||
|
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
||||||
@@ -31,8 +32,8 @@ import {
|
|||||||
defaultEstimate,
|
defaultEstimate,
|
||||||
transfromsFormValuesToRequest,
|
transfromsFormValuesToRequest,
|
||||||
handleErrors,
|
handleErrors,
|
||||||
|
resetFormState,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
import { EstimateIncrementSyncSettingsToForm } from './components';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Estimate form.
|
* Estimate form.
|
||||||
@@ -41,7 +42,7 @@ function EstimateForm({
|
|||||||
// #withSettings
|
// #withSettings
|
||||||
estimateNextNumber,
|
estimateNextNumber,
|
||||||
estimateNumberPrefix,
|
estimateNumberPrefix,
|
||||||
estimateIncrementMode,
|
estimateAutoIncrementMode,
|
||||||
|
|
||||||
// #withCurrentOrganization
|
// #withCurrentOrganization
|
||||||
organization: { base_currency },
|
organization: { base_currency },
|
||||||
@@ -67,14 +68,16 @@ function EstimateForm({
|
|||||||
? { ...transformToEditForm(estimate) }
|
? { ...transformToEditForm(estimate) }
|
||||||
: {
|
: {
|
||||||
...defaultEstimate,
|
...defaultEstimate,
|
||||||
...(estimateIncrementMode && {
|
// If the auto-increment mode is enabled, take the next estimate
|
||||||
|
// number from the settings.
|
||||||
|
...(estimateAutoIncrementMode && {
|
||||||
estimate_number: estimateNumber,
|
estimate_number: estimateNumber,
|
||||||
}),
|
}),
|
||||||
entries: orderingLinesIndexes(defaultEstimate.entries),
|
entries: orderingLinesIndexes(defaultEstimate.entries),
|
||||||
currency_code: base_currency,
|
currency_code: base_currency,
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[estimate, estimateNumber, estimateIncrementMode, base_currency],
|
[estimate, estimateNumber, estimateAutoIncrementMode, base_currency],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Handles form submit.
|
// Handles form submit.
|
||||||
@@ -119,7 +122,7 @@ function EstimateForm({
|
|||||||
history.push('/estimates');
|
history.push('/estimates');
|
||||||
}
|
}
|
||||||
if (submitPayload.resetForm) {
|
if (submitPayload.resetForm) {
|
||||||
resetForm();
|
resetFormState({ resetForm, initialValues, values });
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Handle the request error.
|
// Handle the request error.
|
||||||
@@ -177,7 +180,7 @@ export default compose(
|
|||||||
withSettings(({ estimatesSettings }) => ({
|
withSettings(({ estimatesSettings }) => ({
|
||||||
estimateNextNumber: estimatesSettings?.nextNumber,
|
estimateNextNumber: estimatesSettings?.nextNumber,
|
||||||
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
||||||
estimateIncrementMode: estimatesSettings?.autoIncrement,
|
estimateAutoIncrementMode: estimatesSettings?.autoIncrement,
|
||||||
})),
|
})),
|
||||||
withCurrentOrganization(),
|
withCurrentOrganization(),
|
||||||
)(EstimateForm);
|
)(EstimateForm);
|
||||||
|
|||||||
@@ -9,10 +9,14 @@ import EstimateNumberDialog from '@/containers/Dialogs/EstimateNumberDialog';
|
|||||||
export default function EstimateFormDialogs() {
|
export default function EstimateFormDialogs() {
|
||||||
const { setFieldValue } = useFormikContext();
|
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) => {
|
const handleEstimateNumberFormConfirm = (settings) => {
|
||||||
setFieldValue('estimate_number', settings.transactionNumber);
|
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 (
|
return (
|
||||||
|
|||||||
@@ -67,9 +67,12 @@ const EstimateFormEstimateNumberField = R.compose(
|
|||||||
const handleEstimateNumberBtnClick = () => {
|
const handleEstimateNumberBtnClick = () => {
|
||||||
openDialog('estimate-number-form', {});
|
openDialog('estimate-number-form', {});
|
||||||
};
|
};
|
||||||
|
// Handle estimate no. field blur.
|
||||||
const handleEstimateNoBlur = (event) => {
|
const handleEstimateNoBlur = (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 (values.estimate_number !== newValue && estimateAutoIncrement) {
|
if (values.estimate_number !== newValue && estimateAutoIncrement) {
|
||||||
openDialog('estimate-number-form', {
|
openDialog('estimate-number-form', {
|
||||||
initialFormValues: {
|
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) {
|
if (!estimateAutoIncrement) {
|
||||||
setFieldValue('estimate_number', newValue);
|
setFieldValue('estimate_number', newValue);
|
||||||
setFieldValue('estimate_number_manually', newValue);
|
setFieldValue('estimate_number_manually', newValue);
|
||||||
@@ -96,7 +101,7 @@ const EstimateFormEstimateNumberField = R.compose(
|
|||||||
minimal={true}
|
minimal={true}
|
||||||
asyncControl={true}
|
asyncControl={true}
|
||||||
onBlur={handleEstimateNoBlur}
|
onBlur={handleEstimateNoBlur}
|
||||||
fastField={true}
|
onChange={() => {}}
|
||||||
/>
|
/>
|
||||||
<InputPrependButton
|
<InputPrependButton
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
|
|||||||
@@ -56,13 +56,13 @@ export const EstimateIncrementSyncSettingsToForm = R.compose(
|
|||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
useUpdateEffect(() => {
|
||||||
|
// Do not update if the estimate auto-increment mode is disabled.
|
||||||
if (!estimateAutoIncrement) return null;
|
if (!estimateAutoIncrement) return null;
|
||||||
|
|
||||||
const estimateNo = transactionNumber(
|
setFieldValue(
|
||||||
estimateNumberPrefix,
|
'estimate_number',
|
||||||
estimateNextNumber,
|
transactionNumber(estimateNumberPrefix, estimateNextNumber),
|
||||||
);
|
);
|
||||||
setFieldValue('estimate_number', estimateNo);
|
|
||||||
}, [
|
}, [
|
||||||
setFieldValue,
|
setFieldValue,
|
||||||
estimateNumberPrefix,
|
estimateNumberPrefix,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { useFormikContext } from 'formik';
|
|||||||
import { omit, first } from 'lodash';
|
import { omit, first } from 'lodash';
|
||||||
import {
|
import {
|
||||||
defaultFastFieldShouldUpdate,
|
defaultFastFieldShouldUpdate,
|
||||||
transactionNumber,
|
|
||||||
repeatValue,
|
repeatValue,
|
||||||
transformToForm,
|
transformToForm,
|
||||||
formattedAmount,
|
formattedAmount,
|
||||||
@@ -37,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: '',
|
||||||
|
estimate_number_manually: '',
|
||||||
delivered: '',
|
delivered: '',
|
||||||
reference: '',
|
reference: '',
|
||||||
note: '',
|
note: '',
|
||||||
@@ -142,6 +142,8 @@ export const transfromsFormValuesToRequest = (values) => {
|
|||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...omit(values, ['estimate_number_manually', 'estimate_number']),
|
...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 && {
|
...(values.estimate_number_manually && {
|
||||||
estimate_number: values.estimate_number,
|
estimate_number: values.estimate_number,
|
||||||
}),
|
}),
|
||||||
@@ -223,3 +225,17 @@ export const useEstimateIsForeignCustomer = () => {
|
|||||||
);
|
);
|
||||||
return isForeignCustomer;
|
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,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ function InvoiceForm({
|
|||||||
// #withSettings
|
// #withSettings
|
||||||
invoiceNextNumber,
|
invoiceNextNumber,
|
||||||
invoiceNumberPrefix,
|
invoiceNumberPrefix,
|
||||||
invoiceIncrementMode,
|
invoiceAutoIncrementMode,
|
||||||
|
|
||||||
// #withCurrentOrganization
|
// #withCurrentOrganization
|
||||||
organization: { base_currency },
|
organization: { base_currency },
|
||||||
@@ -71,7 +71,9 @@ function InvoiceForm({
|
|||||||
? { ...transformToEditForm(invoice) }
|
? { ...transformToEditForm(invoice) }
|
||||||
: {
|
: {
|
||||||
...defaultInvoice,
|
...defaultInvoice,
|
||||||
...(invoiceIncrementMode && {
|
// If the auto-increment mode is enabled, take the next invoice
|
||||||
|
// number from the settings.
|
||||||
|
...(invoiceAutoIncrementMode && {
|
||||||
invoice_no: invoiceNumber,
|
invoice_no: invoiceNumber,
|
||||||
}),
|
}),
|
||||||
entries: orderingLinesIndexes(defaultInvoice.entries),
|
entries: orderingLinesIndexes(defaultInvoice.entries),
|
||||||
@@ -184,7 +186,7 @@ export default compose(
|
|||||||
withSettings(({ invoiceSettings }) => ({
|
withSettings(({ invoiceSettings }) => ({
|
||||||
invoiceNextNumber: invoiceSettings?.nextNumber,
|
invoiceNextNumber: invoiceSettings?.nextNumber,
|
||||||
invoiceNumberPrefix: invoiceSettings?.numberPrefix,
|
invoiceNumberPrefix: invoiceSettings?.numberPrefix,
|
||||||
invoiceIncrementMode: invoiceSettings?.autoIncrement,
|
invoiceAutoIncrementMode: invoiceSettings?.autoIncrement,
|
||||||
})),
|
})),
|
||||||
withCurrentOrganization(),
|
withCurrentOrganization(),
|
||||||
)(InvoiceForm);
|
)(InvoiceForm);
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ export function transformValueToRequest(values) {
|
|||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
...omit(values, ['invoice_no', 'invoice_no_manually']),
|
...omit(values, ['invoice_no', 'invoice_no_manually']),
|
||||||
// The `invoice_no_manually` will be presented just in case the auto-increment
|
// The `invoice_no_manually` will be presented just if the auto-increment
|
||||||
// is disable, always both attributes hold the same value in manual mode.
|
// is disable, always both attributes hold the same value in manual mode.
|
||||||
...(values.invoice_no_manually && {
|
...(values.invoice_no_manually && {
|
||||||
invoice_no: values.invoice_no,
|
invoice_no: values.invoice_no,
|
||||||
|
|||||||
Reference in New Issue
Block a user