mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-21 07:10:33 +00:00
fix(webapp): invoice transactions increment
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import InvoiceNumberDialog from '@/containers/Dialogs/InvoiceNumberDialog';
|
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
|
import InvoiceNumberDialog from '@/containers/Dialogs/InvoiceNumberDialog';
|
||||||
import { DialogsName } from '@/constants/dialogs';
|
import { DialogsName } from '@/constants/dialogs';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,8 +12,14 @@ export default function InvoiceFormDialogs() {
|
|||||||
|
|
||||||
// Update the form once the invoice number form submit confirm.
|
// Update the form once the invoice number form submit confirm.
|
||||||
const handleInvoiceNumberFormConfirm = (settings) => {
|
const handleInvoiceNumberFormConfirm = (settings) => {
|
||||||
|
// Set the invoice transaction no. that cames from dialog to the form.
|
||||||
|
// the `invoice_no_manually` will be empty except the increment mode is not auto.
|
||||||
setFieldValue('invoice_no', settings.transactionNumber);
|
setFieldValue('invoice_no', settings.transactionNumber);
|
||||||
setFieldValue('invoice_no_manually', settings.transactionNumber);
|
setFieldValue('invoice_no_manually', '');
|
||||||
|
|
||||||
|
if (settings.incrementMode !== 'auto') {
|
||||||
|
setFieldValue('invoice_no_manually', settings.transactionNumber);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -77,7 +77,9 @@ const InvoiceFormInvoiceNumberField = R.compose(
|
|||||||
const handleInvoiceNoBlur = (event) => {
|
const handleInvoiceNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
if (values.invoice_no.value !== newValue && invoiceAutoIncrement) {
|
// Show the confirmation dialog if the value has changed and auto-increment
|
||||||
|
// mode is enabled.
|
||||||
|
if (values.invoice_no !== newValue && invoiceAutoIncrement) {
|
||||||
openDialog(DialogsName.InvoiceNumberSettings, {
|
openDialog(DialogsName.InvoiceNumberSettings, {
|
||||||
initialFormValues: {
|
initialFormValues: {
|
||||||
onceManualNumber: newValue,
|
onceManualNumber: newValue,
|
||||||
@@ -85,6 +87,8 @@ const InvoiceFormInvoiceNumberField = R.compose(
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Setting the invoice number to the form will be manually in case
|
||||||
|
// auto-increment is disable.
|
||||||
if (!invoiceAutoIncrement) {
|
if (!invoiceAutoIncrement) {
|
||||||
setFieldValue('invoice_no', newValue);
|
setFieldValue('invoice_no', newValue);
|
||||||
setFieldValue('invoice_no_manually', newValue);
|
setFieldValue('invoice_no_manually', newValue);
|
||||||
@@ -105,7 +109,7 @@ const InvoiceFormInvoiceNumberField = R.compose(
|
|||||||
minimal={true}
|
minimal={true}
|
||||||
asyncControl={true}
|
asyncControl={true}
|
||||||
onBlur={handleInvoiceNoBlur}
|
onBlur={handleInvoiceNoBlur}
|
||||||
fastField={true}
|
onChange={() => {}}
|
||||||
/>
|
/>
|
||||||
<InputPrependButton
|
<InputPrependButton
|
||||||
buttonProps={{
|
buttonProps={{
|
||||||
@@ -123,6 +127,7 @@ const InvoiceFormInvoiceNumberField = R.compose(
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
InvoiceFormInvoiceNumberField.displayName = 'InvoiceFormInvoiceNumberField';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice form header fields.
|
* Invoice form header fields.
|
||||||
|
|||||||
@@ -55,11 +55,13 @@ export const InvoiceNoSyncSettingsToForm = R.compose(
|
|||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
useUpdateEffect(() => {
|
useUpdateEffect(() => {
|
||||||
// Do not update if the invoice auto-increment is disabled.
|
// Do not update if the invoice auto-increment mode is disabled.
|
||||||
if (!invoiceAutoIncrement) return null;
|
if (!invoiceAutoIncrement) return null;
|
||||||
|
|
||||||
const invoiceNo = transactionNumber(invoiceNumberPrefix, invoiceNextNumber);
|
setFieldValue(
|
||||||
setFieldValue('invoice_no', invoiceNo);
|
'invoice_no',
|
||||||
|
transactionNumber(invoiceNumberPrefix, invoiceNextNumber),
|
||||||
|
);
|
||||||
}, [setFieldValue, invoiceNumberPrefix, invoiceNextNumber]);
|
}, [setFieldValue, invoiceNumberPrefix, invoiceNextNumber]);
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -43,7 +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: '',
|
||||||
invoice_no_manually: false,
|
invoice_no_manually: '',
|
||||||
reference_no: '',
|
reference_no: '',
|
||||||
invoice_message: '',
|
invoice_message: '',
|
||||||
terms_conditions: '',
|
terms_conditions: '',
|
||||||
@@ -154,6 +154,8 @@ 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
|
||||||
|
// 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