mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
fix: auto-increment settings
This commit is contained in:
@@ -118,7 +118,6 @@ function MakeJournalEntriesForm({
|
|||||||
entries: R.compose(orderingLinesIndexes)(entries),
|
entries: R.compose(orderingLinesIndexes)(entries),
|
||||||
publish: submitPayload.publish,
|
publish: submitPayload.publish,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle the request error.
|
// Handle the request error.
|
||||||
const handleError = ({
|
const handleError = ({
|
||||||
response: {
|
response: {
|
||||||
@@ -149,7 +148,6 @@ function MakeJournalEntriesForm({
|
|||||||
resetForm();
|
resetForm();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if (isNewMode) {
|
if (isNewMode) {
|
||||||
createJournalMutate(form).then(handleSuccess).catch(handleError);
|
createJournalMutate(form).then(handleSuccess).catch(handleError);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -6,14 +6,14 @@ import {
|
|||||||
Position,
|
Position,
|
||||||
ControlGroup,
|
ControlGroup,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { FastField, ErrorMessage } from 'formik';
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
|
import * as R from 'ramda';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
compose,
|
|
||||||
inputIntent,
|
inputIntent,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
@@ -35,36 +35,88 @@ import withSettings from '@/containers/Settings/withSettings';
|
|||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make journal entries header.
|
* Journal number field of make journal form.
|
||||||
*/
|
*/
|
||||||
function MakeJournalEntriesHeader({
|
const MakeJournalTransactionNoField = R.compose(
|
||||||
|
withDialogActions,
|
||||||
|
withSettings(({ manualJournalsSettings }) => ({
|
||||||
|
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
|
||||||
|
})),
|
||||||
|
)(
|
||||||
|
({
|
||||||
// #withDialog
|
// #withDialog
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
journalAutoIncrement,
|
journalAutoIncrement,
|
||||||
}) {
|
}) => {
|
||||||
const { currencies } = useMakeJournalFormContext();
|
const { setFieldValue, values } = useFormikContext();
|
||||||
|
|
||||||
// Handle journal number change.
|
// Handle journal number change.
|
||||||
const handleJournalNumberChange = () => {
|
const handleJournalNumberChange = () => {
|
||||||
openDialog('journal-number-form');
|
openDialog('journal-number-form');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle journal number blur.
|
// Handle journal number blur.
|
||||||
const handleJournalNoBlur = (form, field) => (event) => {
|
const handleJournalNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
if (field.value !== newValue && journalAutoIncrement) {
|
if (values.journal_number !== newValue && journalAutoIncrement) {
|
||||||
openDialog('journal-number-form', {
|
openDialog('journal-number-form', {
|
||||||
initialFormValues: {
|
initialFormValues: {
|
||||||
manualTransactionNo: newValue,
|
onceManualNumber: newValue,
|
||||||
incrementMode: 'manual-transaction',
|
incrementMode: 'manual-transaction',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!journalAutoIncrement) {
|
||||||
|
setFieldValue('journal_number', newValue);
|
||||||
|
setFieldValue('journal_number_manually', newValue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormGroup
|
||||||
|
name={'journal_number'}
|
||||||
|
label={<T id={'journal_no'} />}
|
||||||
|
labelInfo={
|
||||||
|
<>
|
||||||
|
<FieldRequiredHint />
|
||||||
|
<FieldHint />
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
fill={true}
|
||||||
|
inline={true}
|
||||||
|
>
|
||||||
|
<ControlGroup fill={true}>
|
||||||
|
<InputGroup
|
||||||
|
fill={true}
|
||||||
|
value={values.journal_number}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handleJournalNoBlur}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleJournalNumberChange,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: <T id={'setting_your_auto_generated_journal_number'} />,
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
|
</FormGroup>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Make journal entries header.
|
||||||
|
*/
|
||||||
|
export default function MakeJournalEntriesHeader({}) {
|
||||||
|
const { currencies } = useMakeJournalFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/*------------ Posting date -----------*/}
|
{/*------------ Posting date -----------*/}
|
||||||
@@ -98,46 +150,7 @@ function MakeJournalEntriesHeader({
|
|||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
{/*------------ Journal number -----------*/}
|
{/*------------ Journal number -----------*/}
|
||||||
<FastField name={'journal_number'}>
|
<MakeJournalTransactionNoField />
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'journal_no'} />}
|
|
||||||
labelInfo={
|
|
||||||
<>
|
|
||||||
<FieldRequiredHint />
|
|
||||||
<FieldHint />
|
|
||||||
</>
|
|
||||||
}
|
|
||||||
className={'form-group--journal-number'}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="journal_number" />}
|
|
||||||
fill={true}
|
|
||||||
inline={true}
|
|
||||||
>
|
|
||||||
<ControlGroup fill={true}>
|
|
||||||
<InputGroup
|
|
||||||
fill={true}
|
|
||||||
value={field.value}
|
|
||||||
asyncControl={true}
|
|
||||||
onBlur={handleJournalNoBlur(form, field)}
|
|
||||||
/>
|
|
||||||
<InputPrependButton
|
|
||||||
buttonProps={{
|
|
||||||
onClick: handleJournalNumberChange,
|
|
||||||
icon: <Icon icon={'settings-18'} />,
|
|
||||||
}}
|
|
||||||
tooltip={true}
|
|
||||||
tooltipProps={{
|
|
||||||
content: (
|
|
||||||
<T id={'setting_your_auto_generated_journal_number'} />
|
|
||||||
),
|
|
||||||
position: Position.BOTTOM_LEFT,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
|
|
||||||
{/*------------ Reference -----------*/}
|
{/*------------ Reference -----------*/}
|
||||||
<FastField name={'reference'}>
|
<FastField name={'reference'}>
|
||||||
@@ -211,10 +224,3 @@ function MakeJournalEntriesHeader({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withSettings(({ manualJournalsSettings }) => ({
|
|
||||||
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
|
|
||||||
})),
|
|
||||||
)(MakeJournalEntriesHeader);
|
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export default function MakeJournalFormDialogs() {
|
|||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
// Update the form once the journal number form submit confirm.
|
// Update the form once the journal number form submit confirm.
|
||||||
const handleConfirm = ({ manually, incrementNumber }) => {
|
const handleConfirm = (settings) => {
|
||||||
setFieldValue('journal_number', incrementNumber || '');
|
setFieldValue('journal_number', settings.transactionNumber);
|
||||||
setFieldValue('journal_number_manually', manually);
|
setFieldValue('journal_number_manually', settings.transactionNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -65,7 +65,6 @@ function CreditNoteNumberDialogContent({
|
|||||||
const handleChange = (values) => {
|
const handleChange = (values) => {
|
||||||
setReferenceFormValues(values);
|
setReferenceFormValues(values);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Description.
|
// Description.
|
||||||
const description =
|
const description =
|
||||||
referenceFormValues?.incrementMode === 'auto'
|
referenceFormValues?.incrementMode === 'auto'
|
||||||
|
|||||||
@@ -2,15 +2,29 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
import * as Yup from 'yup';
|
import * as Yup from 'yup';
|
||||||
import { Formik, Form } from 'formik';
|
import { Formik, Form } from 'formik';
|
||||||
import { FormattedMessage as T } from '@/components';
|
|
||||||
import { Intent, Button, Classes } from '@blueprintjs/core';
|
import { Intent, Button, Classes } from '@blueprintjs/core';
|
||||||
|
|
||||||
import '@/style/pages/ReferenceNumber/ReferenceNumber.scss';
|
import '@/style/pages/ReferenceNumber/ReferenceNumber.scss';
|
||||||
|
|
||||||
import { FormObserver } from '@/components';
|
import { FormattedMessage as T, FormObserver } from '@/components';
|
||||||
import ReferenceNumberFormContent from './ReferenceNumberFormContent';
|
import ReferenceNumberFormContent from './ReferenceNumberFormContent';
|
||||||
import { transformValuesToForm } from './utils';
|
import { transformValuesToForm } from './utils';
|
||||||
import { saveInvoke } from '@/utils';
|
import { saveInvoke, transformToForm } from '@/utils';
|
||||||
|
|
||||||
|
const initialFormValues = {
|
||||||
|
incrementMode: 'auto',
|
||||||
|
numberPrefix: '',
|
||||||
|
nextNumber: '',
|
||||||
|
onceManualNumber: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
// Validation schema.
|
||||||
|
const validationSchema = Yup.object().shape({
|
||||||
|
incrementMode: Yup.string(),
|
||||||
|
numberPrefix: Yup.string(),
|
||||||
|
nextNumber: Yup.number(),
|
||||||
|
onceManualNumber: Yup.string(),
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference number form.
|
* Reference number form.
|
||||||
@@ -22,29 +36,15 @@ export default function ReferenceNumberForm({
|
|||||||
onClose,
|
onClose,
|
||||||
onChange,
|
onChange,
|
||||||
}) {
|
}) {
|
||||||
// Validation schema.
|
|
||||||
const validationSchema = Yup.object().shape({
|
|
||||||
incrementMode: Yup.string(),
|
|
||||||
numberPrefix: Yup.string(),
|
|
||||||
nextNumber: Yup.number(),
|
|
||||||
manualTransactionNo: Yup.string(),
|
|
||||||
});
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const formInitialValues = useMemo(
|
const formInitialValues = {
|
||||||
() => ({
|
...initialFormValues,
|
||||||
...initialValues,
|
...transformToForm(initialValues, initialFormValues),
|
||||||
incrementMode:
|
};
|
||||||
initialValues.incrementMode === 'auto' &&
|
|
||||||
initialValues.manualTransactionNo
|
|
||||||
? 'manual-transaction'
|
|
||||||
: initialValues.incrementMode,
|
|
||||||
}),
|
|
||||||
[initialValues],
|
|
||||||
);
|
|
||||||
// Handle the form submit.
|
// Handle the form submit.
|
||||||
const handleSubmit = (values, methods) => {
|
const handleSubmit = (values, methods) => {
|
||||||
const parsed = transformValuesToForm(values);
|
const parsed = transformValuesToForm(values);
|
||||||
saveInvoke(onSubmit, { ...parsed, ...values }, methods);
|
saveInvoke(onSubmit, { ...values, ...parsed }, methods);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FastField, useFormikContext } from 'formik';
|
import { FastField, useFormikContext } from 'formik';
|
||||||
import { FormattedMessage as T } from '@/components';
|
|
||||||
import { FormGroup, InputGroup, Radio } from '@blueprintjs/core';
|
import { FormGroup, InputGroup, Radio } from '@blueprintjs/core';
|
||||||
import { If, Row, Col, ErrorMessage } from '@/components';
|
|
||||||
|
import { FormattedMessage as T, Row, Col, ErrorMessage } from '@/components';
|
||||||
import { inputIntent } from '@/utils';
|
import { inputIntent } from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reference number form content.
|
* Reference number form content.
|
||||||
*/
|
*/
|
||||||
export default function ReferenceNumberFormContent() {
|
export default function ReferenceNumberFormContent() {
|
||||||
const { values } = useFormikContext();
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{/* ------------- Auto increment mode ------------- */}
|
{/* ------------- Auto increment mode ------------- */}
|
||||||
@@ -27,8 +25,33 @@ export default function ReferenceNumberFormContent() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
|
<ReferenceNumberAutoIncrement />
|
||||||
|
|
||||||
<If condition={values.incrementMode === 'auto'}>
|
{/* ------------- Manual increment mode ------------- */}
|
||||||
|
<FastField name={'incrementMode'}>
|
||||||
|
{({ form, field, meta: { error, touched } }) => (
|
||||||
|
<Radio
|
||||||
|
label={<T id={'auto_increment.field.manually'} />}
|
||||||
|
value="manual"
|
||||||
|
onChange={() => {
|
||||||
|
form.setFieldValue('incrementMode', 'manual');
|
||||||
|
}}
|
||||||
|
checked={field.value === 'manual'}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</FastField>
|
||||||
|
|
||||||
|
{/* ------------- Transaction manual increment mode ------------- */}
|
||||||
|
<ReferenceNumberManualOnce />
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function ReferenceNumberAutoIncrement() {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
if (!values.incrementMode === 'auto') return null;
|
||||||
|
|
||||||
|
return (
|
||||||
<Row>
|
<Row>
|
||||||
{/* ------------- Prefix ------------- */}
|
{/* ------------- Prefix ------------- */}
|
||||||
<Col xs={4}>
|
<Col xs={4}>
|
||||||
@@ -40,10 +63,7 @@ export default function ReferenceNumberFormContent() {
|
|||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
helperText={<ErrorMessage name={'numberPrefix'} />}
|
helperText={<ErrorMessage name={'numberPrefix'} />}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
@@ -59,38 +79,27 @@ export default function ReferenceNumberFormContent() {
|
|||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
helperText={<ErrorMessage name={'nextNumber'} />}
|
helperText={<ErrorMessage name={'nextNumber'} />}
|
||||||
>
|
>
|
||||||
<InputGroup
|
<InputGroup intent={inputIntent({ error, touched })} {...field} />
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
{...field}
|
|
||||||
/>
|
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</Col>
|
</Col>
|
||||||
</Row>
|
</Row>
|
||||||
</If>
|
);
|
||||||
|
}
|
||||||
|
|
||||||
{/* ------------- Manual increment mode ------------- */}
|
function ReferenceNumberManualOnce() {
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
|
// Do not show the field if the one manual transaction number is not presented.
|
||||||
|
if (!values.onceManualNumber) return null;
|
||||||
|
|
||||||
|
return (
|
||||||
<FastField name={'incrementMode'}>
|
<FastField name={'incrementMode'}>
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
{({ form, field, meta: { error, touched } }) => (
|
||||||
<Radio
|
<Radio
|
||||||
label={<T id={'auto_increment.field.manual_this_transaction'} />}
|
label={<T id={'auto_increment.field.manual_this_transaction'} />}
|
||||||
value="manual"
|
value="manual"
|
||||||
onChange={() => {
|
|
||||||
form.setFieldValue('incrementMode', 'manual');
|
|
||||||
}}
|
|
||||||
checked={field.value === 'manual'}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
|
|
||||||
{/* ------------- Transaction manual increment mode ------------- */}
|
|
||||||
<If condition={values.manualTransactionNo}>
|
|
||||||
<FastField name={'incrementMode'}>
|
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<Radio
|
|
||||||
label={<T id={'auto_increment.field.manually'} />}
|
|
||||||
value="manual"
|
|
||||||
onChange={() => {
|
onChange={() => {
|
||||||
form.setFieldValue('incrementMode', 'manual-transaction');
|
form.setFieldValue('incrementMode', 'manual-transaction');
|
||||||
}}
|
}}
|
||||||
@@ -98,7 +107,5 @@ export default function ReferenceNumberFormContent() {
|
|||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
</If>
|
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import {
|
|||||||
transfromToSnakeCase,
|
transfromToSnakeCase,
|
||||||
transactionNumber,
|
transactionNumber,
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
|
import { omit } from 'lodash';
|
||||||
|
|
||||||
export const defaultInvoiceNoSettings = {
|
export const defaultInvoiceNoSettings = {
|
||||||
nextNumber: '',
|
nextNumber: '',
|
||||||
@@ -13,7 +14,7 @@ export const defaultInvoiceNoSettings = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const transformSettingsToForm = (settings) => ({
|
export const transformSettingsToForm = (settings) => ({
|
||||||
...settings,
|
...omit(settings, ['autoIncrement']),
|
||||||
incrementMode: settings.autoIncrement ? 'auto' : 'manual',
|
incrementMode: settings.autoIncrement ? 'auto' : 'manual',
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -25,13 +26,21 @@ export const transformFormToSettings = (values, group) => {
|
|||||||
return optionsMapToArray(options).map((option) => ({ ...option, group }));
|
return optionsMapToArray(options).map((option) => ({ ...option, group }));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Transaction number returns auto-increment if the increment mode is auto or
|
||||||
|
* returns empty string if the increment mode is manually or returns the entered
|
||||||
|
* manual text if the increment mode is manual once just in this transaction.
|
||||||
|
*/
|
||||||
export const transformValuesToForm = (values) => {
|
export const transformValuesToForm = (values) => {
|
||||||
const incrementNumber =
|
const autoIncrementNumber = transactionNumber(
|
||||||
|
values.numberPrefix,
|
||||||
|
values.nextNumber,
|
||||||
|
);
|
||||||
|
const _transactionNumber =
|
||||||
values.incrementMode === 'auto'
|
values.incrementMode === 'auto'
|
||||||
? transactionNumber(values.numberPrefix, values.nextNumber)
|
? autoIncrementNumber
|
||||||
: values.manualTransactionNo;
|
: values.incrementMode === 'manual-transaction'
|
||||||
|
? values.onceManualNumber
|
||||||
const manually = values.incrementMode === 'auto' ? false : true;
|
: '';
|
||||||
|
return { transactionNumber: _transactionNumber };
|
||||||
return { incrementNumber, manually };
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,25 +1,24 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import CreditNoteNumberDialog from '@/containers/Dialogs/CreditNoteNumberDialog';
|
|
||||||
import { useFormikContext } from 'formik';
|
import { useFormikContext } from 'formik';
|
||||||
|
import CreditNoteNumberDialog from '@/containers/Dialogs/CreditNoteNumberDialog';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Credit note form dialogs.
|
* Credit note form dialogs.
|
||||||
*/
|
*/
|
||||||
export default function CreditNoteFormDialogs() {
|
export default function CreditNoteFormDialogs() {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
// Update the form once the credit number form submit confirm.
|
// Update the form once the credit number form submit confirm.
|
||||||
const handleCreditNumberFormConfirm = ({ incrementNumber, manually }) => {
|
const handleCreditNumberFormConfirm = (settings) => {
|
||||||
setFieldValue('credit_note_number', incrementNumber || '');
|
setFieldValue('credit_note_number', settings.transactionNumber);
|
||||||
setFieldValue('credit_note_no_manually', manually);
|
setFieldValue('credit_note_no_manually', settings.transactionNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
const { setFieldValue } = useFormikContext();
|
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
|
||||||
<CreditNoteNumberDialog
|
<CreditNoteNumberDialog
|
||||||
dialogName={'credit-number-form'}
|
dialogName={'credit-number-form'}
|
||||||
onConfirm={handleCreditNumberFormConfirm}
|
onConfirm={handleCreditNumberFormConfirm}
|
||||||
/>
|
/>
|
||||||
</React.Fragment>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
// @ts-nocheck
|
// @ts-nocheck
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import * as R from 'ramda';
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
import styled from 'styled-components';
|
import styled from 'styled-components';
|
||||||
import {
|
import {
|
||||||
@@ -9,7 +10,8 @@ import {
|
|||||||
ControlGroup,
|
ControlGroup,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FastField, Field, ErrorMessage } from 'formik';
|
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { CLASSES } from '@/constants/classes';
|
import { CLASSES } from '@/constants/classes';
|
||||||
import {
|
import {
|
||||||
CustomerSelectField,
|
CustomerSelectField,
|
||||||
@@ -18,10 +20,9 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
CustomerDrawerLink,
|
CustomerDrawerLink,
|
||||||
|
FFormGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import {
|
import { customerNameFieldShouldUpdate } from './utils';
|
||||||
customerNameFieldShouldUpdate,
|
|
||||||
} from './utils';
|
|
||||||
|
|
||||||
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
|
import { useCreditNoteFormContext } from './CreditNoteFormProvider';
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
@@ -29,44 +30,93 @@ import withDialogActions from '@/containers/Dialog/withDialogActions';
|
|||||||
import { CreditNoteExchangeRateInputField } from './components';
|
import { CreditNoteExchangeRateInputField } from './components';
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
compose,
|
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
inputIntent,
|
inputIntent,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Credit note form header fields.
|
* Credit note transaction number field.
|
||||||
*/
|
*/
|
||||||
function CreditNoteFormHeaderFields({
|
const CreditNoteTransactionNoField = R.compose(
|
||||||
|
withDialogActions,
|
||||||
|
withSettings(({ creditNoteSettings }) => ({
|
||||||
|
creditAutoIncrement: creditNoteSettings?.autoIncrement,
|
||||||
|
creditNextNumber: creditNoteSettings?.nextNumber,
|
||||||
|
creditNumberPrefix: creditNoteSettings?.numberPrefix,
|
||||||
|
})),
|
||||||
|
)(
|
||||||
|
({
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
creditAutoIncrement,
|
creditAutoIncrement,
|
||||||
}) {
|
}) => {
|
||||||
// Credit note form context.
|
const { values, setFieldValue } = useFormikContext();
|
||||||
const { customers } = useCreditNoteFormContext();
|
|
||||||
|
|
||||||
// Handle credit number changing.
|
// Handle credit number changing.
|
||||||
const handleCreditNumberChange = () => {
|
const handleCreditNumberChange = () => {
|
||||||
openDialog('credit-number-form');
|
openDialog('credit-number-form');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle credit no. field blur.
|
// Handle credit no. field blur.
|
||||||
const handleCreditNoBlur = (form, field) => (event) => {
|
const handleCreditNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
if (field.value !== newValue && creditAutoIncrement) {
|
if (values.credit_note_no !== newValue && creditAutoIncrement) {
|
||||||
openDialog('credit-number-form', {
|
openDialog('credit-number-form', {
|
||||||
initialFormValues: {
|
initialFormValues: {
|
||||||
manualTransactionNo: newValue,
|
onceManualNumber: newValue,
|
||||||
incrementMode: 'manual-transaction',
|
incrementMode: 'manual-transaction',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!creditAutoIncrement) {
|
||||||
|
setFieldValue('credit_note_number', newValue);
|
||||||
|
setFieldValue('credit_note_number_manually', newValue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FFormGroup
|
||||||
|
name={'credit_note_number'}
|
||||||
|
label={<T id={'credit_note.label_credit_note'} />}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
inline={true}
|
||||||
|
>
|
||||||
|
<ControlGroup fill={true}>
|
||||||
|
<InputGroup
|
||||||
|
minimal={true}
|
||||||
|
value={values.credit_note_number}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handleCreditNoBlur}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleCreditNumberChange,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: (
|
||||||
|
<T id={'setting_your_auto_generated_credit_note_number'} />
|
||||||
|
),
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
|
</FFormGroup>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Credit note form header fields.
|
||||||
|
*/
|
||||||
|
export default function CreditNoteFormHeaderFields({}) {
|
||||||
|
// Credit note form context.
|
||||||
|
const { customers } = useCreditNoteFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/* ----------- Customer name ----------- */}
|
{/* ----------- Customer name ----------- */}
|
||||||
@@ -140,43 +190,8 @@ function CreditNoteFormHeaderFields({
|
|||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
{/* ----------- Credit note # ----------- */}
|
{/* ----------- Credit note # ----------- */}
|
||||||
<Field name={'credit_note_number'}>
|
<CreditNoteTransactionNoField />
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'credit_note.label_credit_note'} />}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
inline={true}
|
|
||||||
className={classNames(
|
|
||||||
'form-group--credit_note_number',
|
|
||||||
CLASSES.FILL,
|
|
||||||
)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="credit_note_number" />}
|
|
||||||
>
|
|
||||||
<ControlGroup fill={true}>
|
|
||||||
<InputGroup
|
|
||||||
minimal={true}
|
|
||||||
value={field.value}
|
|
||||||
asyncControl={true}
|
|
||||||
onBlur={handleCreditNoBlur(form, field)}
|
|
||||||
/>
|
|
||||||
<InputPrependButton
|
|
||||||
buttonProps={{
|
|
||||||
onClick: handleCreditNumberChange,
|
|
||||||
icon: <Icon icon={'settings-18'} />,
|
|
||||||
}}
|
|
||||||
tooltip={true}
|
|
||||||
tooltipProps={{
|
|
||||||
content: (
|
|
||||||
<T id={'setting_your_auto_generated_credit_note_number'} />
|
|
||||||
),
|
|
||||||
position: Position.BOTTOM_LEFT,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
{/* ----------- Reference ----------- */}
|
{/* ----------- Reference ----------- */}
|
||||||
<FastField name={'reference_no'}>
|
<FastField name={'reference_no'}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
{({ field, meta: { error, touched } }) => (
|
||||||
@@ -194,14 +209,6 @@ function CreditNoteFormHeaderFields({
|
|||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withSettings(({ creditNoteSettings }) => ({
|
|
||||||
creditAutoIncrement: creditNoteSettings?.autoIncrement,
|
|
||||||
creditNextNumber: creditNoteSettings?.nextNumber,
|
|
||||||
creditNumberPrefix: creditNoteSettings?.numberPrefix,
|
|
||||||
})),
|
|
||||||
)(CreditNoteFormHeaderFields);
|
|
||||||
|
|
||||||
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
|
|||||||
@@ -161,7 +161,11 @@ function EstimateForm({
|
|||||||
<EstimateItemsEntriesField />
|
<EstimateItemsEntriesField />
|
||||||
<EstimateFormFooter />
|
<EstimateFormFooter />
|
||||||
<EstimateFloatingActions />
|
<EstimateFloatingActions />
|
||||||
|
|
||||||
|
{/*------- Dialogs -------*/}
|
||||||
<EstimateFormDialogs />
|
<EstimateFormDialogs />
|
||||||
|
|
||||||
|
{/*------- Effects -------*/}
|
||||||
<EstimateIncrementSyncSettingsToForm />
|
<EstimateIncrementSyncSettingsToForm />
|
||||||
</Form>
|
</Form>
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ 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 invoice number form submit confirm.
|
||||||
const handleEstimateNumberFormConfirm = ({ incrementNumber, manually }) => {
|
const handleEstimateNumberFormConfirm = (settings) => {
|
||||||
setFieldValue('estimate_number', incrementNumber || '');
|
setFieldValue('estimate_number', settings.transactionNumber);
|
||||||
setFieldValue('estimate_number_manually', manually);
|
setFieldValue('estimate_number_manually', settings.transactionNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,12 +10,13 @@ import {
|
|||||||
ControlGroup,
|
ControlGroup,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
|
|
||||||
import { FeatureCan, FFormGroup, FormattedMessage as T } from '@/components';
|
import { FeatureCan, FFormGroup, FormattedMessage as T } from '@/components';
|
||||||
import { FastField, Field, ErrorMessage } from 'formik';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
compose,
|
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
inputIntent,
|
inputIntent,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
@@ -41,36 +42,78 @@ import {
|
|||||||
|
|
||||||
import { useEstimateFormContext } from './EstimateFormProvider';
|
import { useEstimateFormContext } from './EstimateFormProvider';
|
||||||
|
|
||||||
/**
|
const EstimateFormEstimateNumberField = R.compose(
|
||||||
* Estimate form header.
|
withDialogActions,
|
||||||
*/
|
withSettings(({ estimatesSettings }) => ({
|
||||||
function EstimateFormHeader({
|
estimateNextNumber: estimatesSettings?.nextNumber,
|
||||||
|
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
||||||
|
estimateAutoIncrement: estimatesSettings?.autoIncrement,
|
||||||
|
})),
|
||||||
|
)(
|
||||||
|
({
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
estimateAutoIncrement,
|
estimateAutoIncrement,
|
||||||
estimateNumberPrefix,
|
}) => {
|
||||||
estimateNextNumber,
|
const { values, setFieldValue } = useFormikContext();
|
||||||
}) {
|
|
||||||
const { customers, projects } = useEstimateFormContext();
|
|
||||||
|
|
||||||
const handleEstimateNumberBtnClick = () => {
|
const handleEstimateNumberBtnClick = () => {
|
||||||
openDialog('estimate-number-form', {});
|
openDialog('estimate-number-form', {});
|
||||||
};
|
};
|
||||||
const handleEstimateNoBlur = (form, field) => (event) => {
|
const handleEstimateNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
if (field.value !== newValue && estimateAutoIncrement) {
|
if (values.estimate_number !== newValue && estimateAutoIncrement) {
|
||||||
openDialog('estimate-number-form', {
|
openDialog('estimate-number-form', {
|
||||||
initialFormValues: {
|
initialFormValues: {
|
||||||
manualTransactionNo: newValue,
|
onceManualNumber: newValue,
|
||||||
incrementMode: 'manual-transaction',
|
incrementMode: 'manual-transaction',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!estimateAutoIncrement) {
|
||||||
|
setFieldValue('estimate_number', newValue);
|
||||||
|
setFieldValue('estimate_number_manually', newValue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FFormGroup
|
||||||
|
name={'estimate_number'}
|
||||||
|
label={<T id={'estimate'} />}
|
||||||
|
inline={true}
|
||||||
|
>
|
||||||
|
<ControlGroup fill={true}>
|
||||||
|
<InputGroup
|
||||||
|
minimal={true}
|
||||||
|
value={values.estimate_number}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handleEstimateNoBlur}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleEstimateNumberBtnClick,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: <T id={'setting_your_auto_generated_estimate_number'} />,
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
|
</FFormGroup>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Estimate form header.
|
||||||
|
*/
|
||||||
|
export default function EstimateFormHeader() {
|
||||||
|
const { customers, projects } = useEstimateFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
@@ -174,40 +217,7 @@ function EstimateFormHeader({
|
|||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
{/* ----------- Estimate number ----------- */}
|
{/* ----------- Estimate number ----------- */}
|
||||||
<Field name={'estimate_number'}>
|
<EstimateFormEstimateNumberField />
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'estimate'} />}
|
|
||||||
inline={true}
|
|
||||||
className={('form-group--estimate-number', CLASSES.FILL)}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="estimate_number" />}
|
|
||||||
>
|
|
||||||
<ControlGroup fill={true}>
|
|
||||||
<InputGroup
|
|
||||||
minimal={true}
|
|
||||||
value={field.value}
|
|
||||||
asyncControl={true}
|
|
||||||
onBlur={handleEstimateNoBlur(form, field)}
|
|
||||||
/>
|
|
||||||
<InputPrependButton
|
|
||||||
buttonProps={{
|
|
||||||
onClick: handleEstimateNumberBtnClick,
|
|
||||||
icon: <Icon icon={'settings-18'} />,
|
|
||||||
}}
|
|
||||||
tooltip={true}
|
|
||||||
tooltipProps={{
|
|
||||||
content: (
|
|
||||||
<T id={'setting_your_auto_generated_estimate_number'} />
|
|
||||||
),
|
|
||||||
position: Position.BOTTOM_LEFT,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
|
|
||||||
{/* ----------- Reference ----------- */}
|
{/* ----------- Reference ----------- */}
|
||||||
<FastField name={'reference'}>
|
<FastField name={'reference'}>
|
||||||
@@ -244,15 +254,6 @@ function EstimateFormHeader({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withSettings(({ estimatesSettings }) => ({
|
|
||||||
estimateNextNumber: estimatesSettings?.nextNumber,
|
|
||||||
estimateNumberPrefix: estimatesSettings?.numberPrefix,
|
|
||||||
estimateAutoIncrement: estimatesSettings?.autoIncrement,
|
|
||||||
})),
|
|
||||||
)(EstimateFormHeader);
|
|
||||||
|
|
||||||
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
|
|||||||
@@ -140,7 +140,6 @@ function InvoiceForm({
|
|||||||
createInvoiceMutate(form).then(onSuccess).catch(onError);
|
createInvoiceMutate(form).then(onSuccess).catch(onError);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Create invoice form schema.
|
// Create invoice form schema.
|
||||||
const CreateInvoiceFormSchema = getCreateInvoiceFormSchema();
|
const CreateInvoiceFormSchema = getCreateInvoiceFormSchema();
|
||||||
|
|
||||||
@@ -168,7 +167,11 @@ function InvoiceForm({
|
|||||||
<InvoiceItemsEntriesEditorField />
|
<InvoiceItemsEntriesEditorField />
|
||||||
<InvoiceFormFooter />
|
<InvoiceFormFooter />
|
||||||
<InvoiceFloatingActions />
|
<InvoiceFloatingActions />
|
||||||
|
|
||||||
|
{/*---------- Dialogs ----------*/}
|
||||||
<InvoiceFormDialogs />
|
<InvoiceFormDialogs />
|
||||||
|
|
||||||
|
{/*---------- Effects ----------*/}
|
||||||
<InvoiceNoSyncSettingsToForm />
|
<InvoiceNoSyncSettingsToForm />
|
||||||
</Form>
|
</Form>
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ export default function InvoiceFormDialogs() {
|
|||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
// Update the form once the invoice number form submit confirm.
|
// Update the form once the invoice number form submit confirm.
|
||||||
const handleInvoiceNumberFormConfirm = ({ incrementNumber, manually }) => {
|
const handleInvoiceNumberFormConfirm = (settings) => {
|
||||||
setFieldValue('invoice_no', incrementNumber || '');
|
setFieldValue('invoice_no', settings.transactionNumber);
|
||||||
setFieldValue('invoice_no_manually', manually);
|
setFieldValue('invoice_no_manually', settings.transactionNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
import { FastField, Field, ErrorMessage, useFormikContext } from 'formik';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
FFormGroup,
|
FFormGroup,
|
||||||
@@ -23,13 +24,16 @@ import {
|
|||||||
Icon,
|
Icon,
|
||||||
InputPrependButton,
|
InputPrependButton,
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
|
FInputGroup,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import { momentFormatter, compose, tansformDateValue } from '@/utils';
|
|
||||||
import { CLASSES } from '@/constants/classes';
|
|
||||||
import { inputIntent, handleDateChange } from '@/utils';
|
|
||||||
import {
|
import {
|
||||||
customerNameFieldShouldUpdate,
|
momentFormatter,
|
||||||
} from './utils';
|
tansformDateValue,
|
||||||
|
inputIntent,
|
||||||
|
handleDateChange,
|
||||||
|
} from '@/utils';
|
||||||
|
import { CLASSES } from '@/constants/classes';
|
||||||
|
import { customerNameFieldShouldUpdate } from './utils';
|
||||||
|
|
||||||
import { useInvoiceFormContext } from './InvoiceFormProvider';
|
import { useInvoiceFormContext } from './InvoiceFormProvider';
|
||||||
import {
|
import {
|
||||||
@@ -47,39 +51,87 @@ import withSettings from '@/containers/Settings/withSettings';
|
|||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Invoice form header fields.
|
* Invoice number field of invoice form.
|
||||||
*/
|
*/
|
||||||
function InvoiceFormHeaderFields({
|
const InvoiceFormInvoiceNumberField = R.compose(
|
||||||
|
withDialogActions,
|
||||||
|
withSettings(({ invoiceSettings }) => ({
|
||||||
|
invoiceAutoIncrement: invoiceSettings?.autoIncrement,
|
||||||
|
})),
|
||||||
|
)(
|
||||||
|
({
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
invoiceAutoIncrement,
|
invoiceAutoIncrement,
|
||||||
}) {
|
}) => {
|
||||||
// Invoice form context.
|
|
||||||
const { customers, projects } = useInvoiceFormContext();
|
|
||||||
|
|
||||||
// Formik context.
|
// Formik context.
|
||||||
const { values } = useFormikContext();
|
const { values, setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
// Handle invoice number changing.
|
// Handle invoice number changing.
|
||||||
const handleInvoiceNumberChange = () => {
|
const handleInvoiceNumberChange = () => {
|
||||||
openDialog(DialogsName.InvoiceNumberSettings);
|
openDialog(DialogsName.InvoiceNumberSettings);
|
||||||
};
|
};
|
||||||
// Handle invoice no. field blur.
|
// Handle invoice no. field blur.
|
||||||
const handleInvoiceNoBlur = (form, field) => (event) => {
|
const handleInvoiceNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
if (field.value !== newValue && invoiceAutoIncrement) {
|
if (values.invoice_no.value !== newValue && invoiceAutoIncrement) {
|
||||||
openDialog(DialogsName.InvoiceNumberSettings, {
|
openDialog(DialogsName.InvoiceNumberSettings, {
|
||||||
initialFormValues: {
|
initialFormValues: {
|
||||||
manualTransactionNo: newValue,
|
onceManualNumber: newValue,
|
||||||
incrementMode: 'manual-transaction',
|
incrementMode: 'manual-transaction',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!invoiceAutoIncrement) {
|
||||||
|
setFieldValue('invoice_no', newValue);
|
||||||
|
setFieldValue('invoice_no_manually', newValue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FFormGroup
|
||||||
|
name={'invoice_no'}
|
||||||
|
label={<T id={'invoice_no'} />}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
inline={true}
|
||||||
|
fastField={true}
|
||||||
|
>
|
||||||
|
<ControlGroup fill={true}>
|
||||||
|
<FInputGroup
|
||||||
|
name={'invoice_no'}
|
||||||
|
minimal={true}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handleInvoiceNoBlur}
|
||||||
|
fastField={true}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleInvoiceNumberChange,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: <T id={'setting_your_auto_generated_invoice_number'} />,
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
|
</FFormGroup>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Invoice form header fields.
|
||||||
|
*/
|
||||||
|
export default function InvoiceFormHeaderFields() {
|
||||||
|
// Invoice form context.
|
||||||
|
const { customers, projects } = useInvoiceFormContext();
|
||||||
|
const { values } = useFormikContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/* ----------- Customer name ----------- */}
|
{/* ----------- Customer name ----------- */}
|
||||||
@@ -185,40 +237,7 @@ function InvoiceFormHeaderFields({
|
|||||||
</Row>
|
</Row>
|
||||||
|
|
||||||
{/* ----------- Invoice number ----------- */}
|
{/* ----------- Invoice number ----------- */}
|
||||||
<Field name={'invoice_no'}>
|
<InvoiceFormInvoiceNumberField />
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'invoice_no'} />}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
inline={true}
|
|
||||||
className={classNames('form-group--invoice-no', CLASSES.FILL)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="invoice_no" />}
|
|
||||||
>
|
|
||||||
<ControlGroup fill={true}>
|
|
||||||
<InputGroup
|
|
||||||
minimal={true}
|
|
||||||
value={field.value}
|
|
||||||
asyncControl={true}
|
|
||||||
onBlur={handleInvoiceNoBlur(form, field)}
|
|
||||||
/>
|
|
||||||
<InputPrependButton
|
|
||||||
buttonProps={{
|
|
||||||
onClick: handleInvoiceNumberChange,
|
|
||||||
icon: <Icon icon={'settings-18'} />,
|
|
||||||
}}
|
|
||||||
tooltip={true}
|
|
||||||
tooltipProps={{
|
|
||||||
content: (
|
|
||||||
<T id={'setting_your_auto_generated_invoice_number'} />
|
|
||||||
),
|
|
||||||
position: Position.BOTTOM_LEFT,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</Field>
|
|
||||||
|
|
||||||
{/* ----------- Reference ----------- */}
|
{/* ----------- Reference ----------- */}
|
||||||
<FastField name={'reference_no'}>
|
<FastField name={'reference_no'}>
|
||||||
@@ -260,13 +279,6 @@ function InvoiceFormHeaderFields({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withSettings(({ invoiceSettings }) => ({
|
|
||||||
invoiceAutoIncrement: invoiceSettings?.autoIncrement,
|
|
||||||
})),
|
|
||||||
)(InvoiceFormHeaderFields);
|
|
||||||
|
|
||||||
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
|
|||||||
@@ -177,6 +177,7 @@ function PaymentReceiveForm({
|
|||||||
<PaymentReceiveFormFooter />
|
<PaymentReceiveFormFooter />
|
||||||
<PaymentReceiveFloatingActions />
|
<PaymentReceiveFloatingActions />
|
||||||
|
|
||||||
|
{/* ------- Effects ------- */}
|
||||||
<PaymentReceiveSyncIncrementSettingsToForm />
|
<PaymentReceiveSyncIncrementSettingsToForm />
|
||||||
|
|
||||||
{/* ------- Alerts & Dialogs ------- */}
|
{/* ------- Alerts & Dialogs ------- */}
|
||||||
|
|||||||
@@ -9,17 +9,15 @@ import PaymentReceiveNumberDialog from '@/containers/Dialogs/PaymentReceiveNumbe
|
|||||||
export default function PaymentReceiveFormDialogs() {
|
export default function PaymentReceiveFormDialogs() {
|
||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
const handleUpdatePaymentNumber = ({ incrementNumber, manually }) => {
|
const handleUpdatePaymentNumber = (settings) => {
|
||||||
setFieldValue('payment_receive_no', incrementNumber);
|
setFieldValue('payment_receive_no', settings.transactionNumber);
|
||||||
setFieldValue('payment_receive_no_manually', manually)
|
setFieldValue('payment_receive_no_manually', settings.transactionNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
|
||||||
<PaymentReceiveNumberDialog
|
<PaymentReceiveNumberDialog
|
||||||
dialogName={'payment-receive-number-form'}
|
dialogName={'payment-receive-number-form'}
|
||||||
onConfirm={handleUpdatePaymentNumber}
|
onConfirm={handleUpdatePaymentNumber}
|
||||||
/>
|
/>
|
||||||
</>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ import {
|
|||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { toSafeInteger } from 'lodash';
|
import { toSafeInteger } from 'lodash';
|
||||||
import { FeatureCan, FormattedMessage as T } from '@/components';
|
|
||||||
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
|
import { FastField, Field, useFormikContext, ErrorMessage } from 'formik';
|
||||||
|
import * as R from 'ramda';
|
||||||
|
|
||||||
|
import { 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 {
|
||||||
compose,
|
|
||||||
safeSumBy,
|
safeSumBy,
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
@@ -48,7 +48,6 @@ import {
|
|||||||
|
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
import withCurrentOrganization from '@/containers/Organization/withCurrentOrganization';
|
|
||||||
|
|
||||||
import {
|
import {
|
||||||
amountPaymentEntries,
|
amountPaymentEntries,
|
||||||
@@ -59,18 +58,85 @@ import {
|
|||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Payment receive header fields.
|
* Payment receive number field.
|
||||||
*/
|
*/
|
||||||
function PaymentReceiveHeaderFields({
|
const PaymentReceivePaymentNoField = R.compose(
|
||||||
// #withCurrentOrganization
|
withSettings(({ paymentReceiveSettings }) => ({
|
||||||
organization: { base_currency },
|
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
||||||
|
})),
|
||||||
|
withDialogActions,
|
||||||
|
)(
|
||||||
|
({
|
||||||
// #withDialogActions
|
// #withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
paymentReceiveAutoIncrement,
|
paymentReceiveAutoIncrement,
|
||||||
}) {
|
}) => {
|
||||||
|
const { values, setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
|
// Handle click open payment receive number dialog.
|
||||||
|
const handleClickOpenDialog = () => {
|
||||||
|
openDialog('payment-receive-number-form');
|
||||||
|
};
|
||||||
|
// Handle payment number field blur.
|
||||||
|
const handlePaymentNoBlur = (event) => {
|
||||||
|
const newValue = event.target.value;
|
||||||
|
|
||||||
|
if (
|
||||||
|
values.payment_receive_no !== newValue &&
|
||||||
|
paymentReceiveAutoIncrement
|
||||||
|
) {
|
||||||
|
openDialog('payment-receive-number-form', {
|
||||||
|
initialFormValues: {
|
||||||
|
onceManualNumber: newValue,
|
||||||
|
incrementMode: 'manual-transaction',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (!paymentReceiveAutoIncrement) {
|
||||||
|
setFieldValue('payment_receive_no', newValue);
|
||||||
|
setFieldValue('payment_receive_no_manually', newValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
return (
|
||||||
|
<FormGroup
|
||||||
|
name={'payment_receive_no'}
|
||||||
|
label={<T id={'payment_receive_no'} />}
|
||||||
|
inline={true}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
helperText={<ErrorMessage name="payment_receive_no" />}
|
||||||
|
>
|
||||||
|
<ControlGroup fill={true}>
|
||||||
|
<InputGroup
|
||||||
|
minimal={true}
|
||||||
|
value={values.payment_receive_no}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handlePaymentNoBlur}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleClickOpenDialog,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: (
|
||||||
|
<T id={'setting_your_auto_generated_payment_receive_number'} />
|
||||||
|
),
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
|
</FormGroup>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Payment receive header fields.
|
||||||
|
*/
|
||||||
|
export default function PaymentReceiveHeaderFields({}) {
|
||||||
// Payment receive form context.
|
// Payment receive form context.
|
||||||
const { customers, accounts, projects, isNewMode } =
|
const { customers, accounts, projects, isNewMode } =
|
||||||
usePaymentReceiveFormContext();
|
usePaymentReceiveFormContext();
|
||||||
@@ -101,24 +167,6 @@ function PaymentReceiveHeaderFields({
|
|||||||
const newEntries = amountPaymentEntries(toSafeInteger(value), entries);
|
const newEntries = amountPaymentEntries(toSafeInteger(value), entries);
|
||||||
setFieldValue('entries', newEntries);
|
setFieldValue('entries', newEntries);
|
||||||
};
|
};
|
||||||
// Handle click open payment receive number dialog.
|
|
||||||
const handleClickOpenDialog = () => {
|
|
||||||
openDialog('payment-receive-number-form');
|
|
||||||
};
|
|
||||||
|
|
||||||
// Handle payment number field blur.
|
|
||||||
const handlePaymentNoBlur = (form, field) => (event) => {
|
|
||||||
const newValue = event.target.value;
|
|
||||||
|
|
||||||
if (field.value !== newValue && paymentReceiveAutoIncrement) {
|
|
||||||
openDialog('payment-receive-number-form', {
|
|
||||||
initialFormValues: {
|
|
||||||
manualTransactionNo: newValue,
|
|
||||||
incrementMode: 'manual-transaction',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
@@ -237,43 +285,7 @@ function PaymentReceiveHeaderFields({
|
|||||||
</Field>
|
</Field>
|
||||||
|
|
||||||
{/* ------------ Payment receive no. ------------ */}
|
{/* ------------ Payment receive no. ------------ */}
|
||||||
<FastField name={'payment_receive_no'}>
|
<PaymentReceivePaymentNoField />
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'payment_receive_no'} />}
|
|
||||||
inline={true}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
className={('form-group--payment_receive_no', CLASSES.FILL)}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="payment_receive_no" />}
|
|
||||||
>
|
|
||||||
<ControlGroup fill={true}>
|
|
||||||
<InputGroup
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
minimal={true}
|
|
||||||
value={field.value}
|
|
||||||
asyncControl={true}
|
|
||||||
onBlur={handlePaymentNoBlur(form, field)}
|
|
||||||
/>
|
|
||||||
<InputPrependButton
|
|
||||||
buttonProps={{
|
|
||||||
onClick: handleClickOpenDialog,
|
|
||||||
icon: <Icon icon={'settings-18'} />,
|
|
||||||
}}
|
|
||||||
tooltip={true}
|
|
||||||
tooltipProps={{
|
|
||||||
content: (
|
|
||||||
<T
|
|
||||||
id={'setting_your_auto_generated_payment_receive_number'}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
position: Position.BOTTOM_LEFT,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
|
|
||||||
{/* ------------ Deposit account ------------ */}
|
{/* ------------ Deposit account ------------ */}
|
||||||
<FFormGroup
|
<FFormGroup
|
||||||
@@ -340,14 +352,6 @@ function PaymentReceiveHeaderFields({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withSettings(({ paymentReceiveSettings }) => ({
|
|
||||||
paymentReceiveAutoIncrement: paymentReceiveSettings?.autoIncrement,
|
|
||||||
})),
|
|
||||||
withDialogActions,
|
|
||||||
withCurrentOrganization(),
|
|
||||||
)(PaymentReceiveHeaderFields);
|
|
||||||
|
|
||||||
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
|
|||||||
@@ -165,7 +165,11 @@ function ReceiptForm({
|
|||||||
<ReceiptItemsEntriesEditor />
|
<ReceiptItemsEntriesEditor />
|
||||||
<ReceiptFormFooter />
|
<ReceiptFormFooter />
|
||||||
<ReceiptFormFloatingActions />
|
<ReceiptFormFloatingActions />
|
||||||
|
|
||||||
|
{/*---------- Dialogs ---------*/}
|
||||||
<ReceiptFormDialogs />
|
<ReceiptFormDialogs />
|
||||||
|
|
||||||
|
{/*---------- Effects ---------*/}
|
||||||
<ReceiptSyncIncrementSettingsToForm />
|
<ReceiptSyncIncrementSettingsToForm />
|
||||||
</Form>
|
</Form>
|
||||||
</Formik>
|
</Formik>
|
||||||
|
|||||||
@@ -10,9 +10,9 @@ export default function ReceiptFormDialogs() {
|
|||||||
const { setFieldValue } = useFormikContext();
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
// Update the form once the receipt number form submit confirm.
|
// Update the form once the receipt number form submit confirm.
|
||||||
const handleReceiptNumberFormConfirm = ({ incrementNumber, manually }) => {
|
const handleReceiptNumberFormConfirm = (settings) => {
|
||||||
setFieldValue('receipt_number', incrementNumber || '');
|
setFieldValue('receipt_number', settings.transactionNumber);
|
||||||
setFieldValue('receipt_number_manually', manually);
|
setFieldValue('receipt_number_manually', settings.transactionNumber);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -10,9 +10,10 @@ import {
|
|||||||
ControlGroup,
|
ControlGroup,
|
||||||
} from '@blueprintjs/core';
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FastField, ErrorMessage } from 'formik';
|
import { FastField, ErrorMessage, useFormikContext } from 'formik';
|
||||||
import { CLASSES } from '@/constants/classes';
|
import * as R from 'ramda';
|
||||||
|
|
||||||
|
import { CLASSES } from '@/constants/classes';
|
||||||
import {
|
import {
|
||||||
FFormGroup,
|
FFormGroup,
|
||||||
AccountsSelect,
|
AccountsSelect,
|
||||||
@@ -24,57 +25,102 @@ import {
|
|||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
FeatureCan,
|
FeatureCan,
|
||||||
} from '@/components';
|
} from '@/components';
|
||||||
import withSettings from '@/containers/Settings/withSettings';
|
|
||||||
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
|
||||||
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
|
import { ACCOUNT_TYPE } from '@/constants/accountTypes';
|
||||||
import { ProjectsSelect } from '@/containers/Projects/components';
|
import { ProjectsSelect } from '@/containers/Projects/components';
|
||||||
import {
|
import {
|
||||||
momentFormatter,
|
momentFormatter,
|
||||||
compose,
|
|
||||||
tansformDateValue,
|
tansformDateValue,
|
||||||
handleDateChange,
|
handleDateChange,
|
||||||
inputIntent,
|
inputIntent,
|
||||||
} from '@/utils';
|
} from '@/utils';
|
||||||
import { useReceiptFormContext } from './ReceiptFormProvider';
|
import { useReceiptFormContext } from './ReceiptFormProvider';
|
||||||
import {
|
import { accountsFieldShouldUpdate, customersFieldShouldUpdate } from './utils';
|
||||||
accountsFieldShouldUpdate,
|
|
||||||
customersFieldShouldUpdate,
|
|
||||||
} from './utils';
|
|
||||||
import {
|
import {
|
||||||
ReceiptExchangeRateInputField,
|
ReceiptExchangeRateInputField,
|
||||||
ReceiptProjectSelectButton,
|
ReceiptProjectSelectButton,
|
||||||
} from './components';
|
} from './components';
|
||||||
import { Features } from '@/constants';
|
import { Features } from '@/constants';
|
||||||
|
import withSettings from '@/containers/Settings/withSettings';
|
||||||
|
import withDialogActions from '@/containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
/**
|
const ReceiptFormReceiptNumberField = R.compose(
|
||||||
* Receipt form header fields.
|
withDialogActions,
|
||||||
*/
|
withSettings(({ receiptSettings }) => ({
|
||||||
function ReceiptFormHeader({
|
receiptAutoIncrement: receiptSettings?.autoIncrement,
|
||||||
|
})),
|
||||||
|
)(
|
||||||
|
({
|
||||||
//#withDialogActions
|
//#withDialogActions
|
||||||
openDialog,
|
openDialog,
|
||||||
|
|
||||||
// #withSettings
|
// #withSettings
|
||||||
receiptAutoIncrement,
|
receiptAutoIncrement,
|
||||||
}) {
|
}) => {
|
||||||
const { accounts, customers, projects } = useReceiptFormContext();
|
const { values, setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
const handleReceiptNumberChange = useCallback(() => {
|
const handleReceiptNumberChange = useCallback(() => {
|
||||||
openDialog('receipt-number-form', {});
|
openDialog('receipt-number-form', {});
|
||||||
}, [openDialog]);
|
}, [openDialog]);
|
||||||
|
|
||||||
const handleReceiptNoBlur = (form, field) => (event) => {
|
const handleReceiptNoBlur = (event) => {
|
||||||
const newValue = event.target.value;
|
const newValue = event.target.value;
|
||||||
|
|
||||||
if (field.value !== newValue && receiptAutoIncrement) {
|
if (values.receipt_number !== newValue && receiptAutoIncrement) {
|
||||||
openDialog('receipt-number-form', {
|
openDialog('receipt-number-form', {
|
||||||
initialFormValues: {
|
initialFormValues: {
|
||||||
manualTransactionNo: newValue,
|
onceManualNumber: newValue,
|
||||||
incrementMode: 'manual-transaction',
|
incrementMode: 'manual-transaction',
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
if (!receiptAutoIncrement) {
|
||||||
|
setFieldValue('receipt_number', newValue);
|
||||||
|
setFieldValue('receipt_number_manually', newValue);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FFormGroup
|
||||||
|
name={'receipt_number'}
|
||||||
|
label={<T id={'receipt'} />}
|
||||||
|
inline={true}
|
||||||
|
labelInfo={<FieldRequiredHint />}
|
||||||
|
>
|
||||||
|
<ControlGroup fill={true}>
|
||||||
|
<InputGroup
|
||||||
|
minimal={true}
|
||||||
|
value={values.receipt_number}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handleReceiptNoBlur}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleReceiptNumberChange,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: (
|
||||||
|
<T id={'setting_your_auto_generated_payment_receive_number'} />
|
||||||
|
),
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
inputProps={{
|
||||||
|
leftIcon: <Icon icon={'date-range'} />,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
|
</FFormGroup>
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Receipt form header fields.
|
||||||
|
*/
|
||||||
|
export default function ReceiptFormHeader() {
|
||||||
|
const { accounts, customers, projects } = useReceiptFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/* ----------- Customer name ----------- */}
|
{/* ----------- Customer name ----------- */}
|
||||||
@@ -170,45 +216,7 @@ function ReceiptFormHeader({
|
|||||||
</FastField>
|
</FastField>
|
||||||
|
|
||||||
{/* ----------- Receipt number ----------- */}
|
{/* ----------- Receipt number ----------- */}
|
||||||
<FastField name={'receipt_number'}>
|
<ReceiptFormReceiptNumberField />
|
||||||
{({ form, field, meta: { error, touched } }) => (
|
|
||||||
<FormGroup
|
|
||||||
label={<T id={'receipt'} />}
|
|
||||||
inline={true}
|
|
||||||
className={('form-group--receipt_number', CLASSES.FILL)}
|
|
||||||
labelInfo={<FieldRequiredHint />}
|
|
||||||
intent={inputIntent({ error, touched })}
|
|
||||||
helperText={<ErrorMessage name="receipt_number" />}
|
|
||||||
>
|
|
||||||
<ControlGroup fill={true}>
|
|
||||||
<InputGroup
|
|
||||||
minimal={true}
|
|
||||||
value={field.value}
|
|
||||||
asyncControl={true}
|
|
||||||
onBlur={handleReceiptNoBlur(form, field)}
|
|
||||||
/>
|
|
||||||
<InputPrependButton
|
|
||||||
buttonProps={{
|
|
||||||
onClick: handleReceiptNumberChange,
|
|
||||||
icon: <Icon icon={'settings-18'} />,
|
|
||||||
}}
|
|
||||||
tooltip={true}
|
|
||||||
tooltipProps={{
|
|
||||||
content: (
|
|
||||||
<T
|
|
||||||
id={'setting_your_auto_generated_payment_receive_number'}
|
|
||||||
/>
|
|
||||||
),
|
|
||||||
position: Position.BOTTOM_LEFT,
|
|
||||||
}}
|
|
||||||
inputProps={{
|
|
||||||
leftIcon: <Icon icon={'date-range'} />,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ControlGroup>
|
|
||||||
</FormGroup>
|
|
||||||
)}
|
|
||||||
</FastField>
|
|
||||||
|
|
||||||
{/* ----------- Reference ----------- */}
|
{/* ----------- Reference ----------- */}
|
||||||
<FastField name={'reference_no'}>
|
<FastField name={'reference_no'}>
|
||||||
@@ -245,13 +253,6 @@ function ReceiptFormHeader({
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(
|
|
||||||
withDialogActions,
|
|
||||||
withSettings(({ receiptSettings }) => ({
|
|
||||||
receiptAutoIncrement: receiptSettings?.autoIncrement,
|
|
||||||
})),
|
|
||||||
)(ReceiptFormHeader);
|
|
||||||
|
|
||||||
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
const CustomerButtonLink = styled(CustomerDrawerLink)`
|
||||||
font-size: 11px;
|
font-size: 11px;
|
||||||
margin-top: 6px;
|
margin-top: 6px;
|
||||||
|
|||||||
@@ -1376,7 +1376,7 @@
|
|||||||
"receipt.auto_increment.manually": "Your receipt numbers are set on manual mode. Are you sure chaning this settings?",
|
"receipt.auto_increment.manually": "Your receipt numbers are set on manual mode. Are you sure chaning this settings?",
|
||||||
"payment_receive.auto_increment.auto": "Your payment numbers are set on auto-increment mode. Are you sure changing this setting?",
|
"payment_receive.auto_increment.auto": "Your payment numbers are set on auto-increment mode. Are you sure changing this setting?",
|
||||||
"payment_receive.auto_increment.manually": "Your payment numbers are set on manual mode. Are you sure chaning this settings?",
|
"payment_receive.auto_increment.manually": "Your payment numbers are set on manual mode. Are you sure chaning this settings?",
|
||||||
"auto_increment.field.manually": "I will enter them manually each time",
|
"auto_increment.field.manually": "I will enter them manually each time.",
|
||||||
"auto_increment.field.manual_this_transaction": "Manual entering for this transaction.",
|
"auto_increment.field.manual_this_transaction": "Manual entering for this transaction.",
|
||||||
"auto_increment.field.auto": "Auto-incrementing number.",
|
"auto_increment.field.auto": "Auto-incrementing number.",
|
||||||
"date_formats": {
|
"date_formats": {
|
||||||
|
|||||||
Reference in New Issue
Block a user