mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 13:50:31 +00:00
feat: add auto increment in vendor credit number.
This commit is contained in:
@@ -0,0 +1,102 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import intl from 'react-intl-universal';
|
||||||
|
import { useSaveSettings } from 'hooks/query';
|
||||||
|
|
||||||
|
import { VendorCreditNumberDilaogProvider } from './VendorCreditNumberDilaogProvider';
|
||||||
|
import ReferenceNumberForm from 'containers/JournalNumber/ReferenceNumberForm';
|
||||||
|
|
||||||
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
import withSettingsActions from 'containers/Settings/withSettingsActions';
|
||||||
|
import { compose } from 'utils';
|
||||||
|
import {
|
||||||
|
transformFormToSettings,
|
||||||
|
transformSettingsToForm,
|
||||||
|
} from 'containers/JournalNumber/utils';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vendor credit number dialog
|
||||||
|
*/
|
||||||
|
function VendorCreditNumberDialogContent({
|
||||||
|
// #ownProps
|
||||||
|
initialValues,
|
||||||
|
onConfirm,
|
||||||
|
|
||||||
|
// #withSettings
|
||||||
|
nextNumber,
|
||||||
|
numberPrefix,
|
||||||
|
autoIncrement,
|
||||||
|
|
||||||
|
// #withDialogActions
|
||||||
|
closeDialog,
|
||||||
|
}) {
|
||||||
|
const { mutateAsync: saveSettings } = useSaveSettings();
|
||||||
|
const [referenceFormValues, setReferenceFormValues] = React.useState(null);
|
||||||
|
|
||||||
|
// Handle the submit form.
|
||||||
|
const handleSubmitForm = (values, { setSubmitting }) => {
|
||||||
|
// Handle the form success.
|
||||||
|
const handleSuccess = () => {
|
||||||
|
setSubmitting(false);
|
||||||
|
closeDialog('vendor-credit-form');
|
||||||
|
onConfirm(values);
|
||||||
|
};
|
||||||
|
// Handle the form errors.
|
||||||
|
const handleErrors = () => {
|
||||||
|
setSubmitting(false);
|
||||||
|
};
|
||||||
|
if (values.incrementMode === 'manual-transaction') {
|
||||||
|
handleSuccess();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Transformes the form values to settings to save it.
|
||||||
|
const options = transformFormToSettings(values, 'vendor_credit');
|
||||||
|
|
||||||
|
// Save the settings.
|
||||||
|
saveSettings({ options }).then(handleSuccess).catch(handleErrors);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle the dialog close.
|
||||||
|
const handleClose = () => {
|
||||||
|
closeDialog('vendor-credit-form');
|
||||||
|
};
|
||||||
|
// Handle form change.
|
||||||
|
const handleChange = (values) => {
|
||||||
|
setReferenceFormValues(values);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Description.
|
||||||
|
const description =
|
||||||
|
referenceFormValues?.incrementMode === 'auto'
|
||||||
|
? intl.get('vendor_credit.auto_increment.auto')
|
||||||
|
: intl.get('vendor_credit.auto_increment.manually');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<VendorCreditNumberDilaogProvider>
|
||||||
|
<ReferenceNumberForm
|
||||||
|
initialValues={{
|
||||||
|
...transformSettingsToForm({
|
||||||
|
nextNumber,
|
||||||
|
numberPrefix,
|
||||||
|
autoIncrement,
|
||||||
|
}),
|
||||||
|
...initialValues,
|
||||||
|
}}
|
||||||
|
description={description}
|
||||||
|
onSubmit={handleSubmitForm}
|
||||||
|
onClose={handleClose}
|
||||||
|
onChange={handleChange}
|
||||||
|
/>
|
||||||
|
</VendorCreditNumberDilaogProvider>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default compose(
|
||||||
|
withDialogActions,
|
||||||
|
withSettingsActions,
|
||||||
|
withSettings(({ vendorsCreditNoteSetting }) => ({
|
||||||
|
autoIncrement: vendorsCreditNoteSetting?.autoIncrement,
|
||||||
|
nextNumber: vendorsCreditNoteSetting?.nextNumber,
|
||||||
|
numberPrefix: vendorsCreditNoteSetting?.numberPrefix,
|
||||||
|
})),
|
||||||
|
)(VendorCreditNumberDialogContent);
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { DialogContent } from 'components';
|
||||||
|
import { useSettingsVendorCredits } from 'hooks/query';
|
||||||
|
|
||||||
|
const VendorCreditNumberDialogContext = React.createContext();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vendor credit number dialog provider
|
||||||
|
*/
|
||||||
|
function VendorCreditNumberDilaogProvider({ query, ...props }) {
|
||||||
|
const { isLoading: isSettingsLoading } = useSettingsVendorCredits();
|
||||||
|
|
||||||
|
// Provider payload.
|
||||||
|
const provider = {
|
||||||
|
isSettingsLoading,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<DialogContent isLoading={isSettingsLoading}>
|
||||||
|
<VendorCreditNumberDialogContext.Provider value={provider} {...props} />
|
||||||
|
</DialogContent>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const useVendorCreditNumberDialogContext = () =>
|
||||||
|
React.useContext(VendorCreditNumberDialogContext);
|
||||||
|
|
||||||
|
export { VendorCreditNumberDilaogProvider, useVendorCreditNumberDialogContext };
|
||||||
40
src/containers/Dialogs/VendorCreditNumberDialog/index.js
Normal file
40
src/containers/Dialogs/VendorCreditNumberDialog/index.js
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import { Dialog, DialogSuspense, FormattedMessage as T } from 'components';
|
||||||
|
import withDialogRedux from 'components/DialogReduxConnect';
|
||||||
|
import { compose, saveInvoke } from 'utils';
|
||||||
|
|
||||||
|
const VendorCreditNumberDialogContent = React.lazy(() =>
|
||||||
|
import('./VendorCreditNumberDialogContent'),
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vendor Credit number dialog.
|
||||||
|
*/
|
||||||
|
function VendorCreditNumberDialog({
|
||||||
|
dialogName,
|
||||||
|
payload: { initialFormValues },
|
||||||
|
isOpen,
|
||||||
|
onConfirm,
|
||||||
|
}) {
|
||||||
|
const handleConfirm = (values) => {
|
||||||
|
saveInvoke(onConfirm, values);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Dialog
|
||||||
|
title={<T id={'vendor_credit_number_settings'} />}
|
||||||
|
name={dialogName}
|
||||||
|
autoFocus={true}
|
||||||
|
canEscapeKeyClose={true}
|
||||||
|
isOpen={isOpen}
|
||||||
|
>
|
||||||
|
<DialogSuspense>
|
||||||
|
<VendorCreditNumberDialogContent
|
||||||
|
initialValues={{ ...initialFormValues }}
|
||||||
|
onConfirm={handleConfirm}
|
||||||
|
/>
|
||||||
|
</DialogSuspense>
|
||||||
|
</Dialog>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
export default compose(withDialogRedux())(VendorCreditNumberDialog);
|
||||||
@@ -15,23 +15,31 @@ import VendorCreditNoteFormHeader from './VendorCreditNoteFormHeader';
|
|||||||
import VendorCreditNoteItemsEntriesEditor from './VendorCreditNoteItemsEntriesEditor';
|
import VendorCreditNoteItemsEntriesEditor from './VendorCreditNoteItemsEntriesEditor';
|
||||||
import VendorCreditNoteFormFooter from './VendorCreditNoteFormFooter';
|
import VendorCreditNoteFormFooter from './VendorCreditNoteFormFooter';
|
||||||
import VendorCreditNoteFloatingActions from './VendorCreditNoteFloatingActions';
|
import VendorCreditNoteFloatingActions from './VendorCreditNoteFloatingActions';
|
||||||
|
import VendorCreditNoteFormDialogs from './VendorCreditNoteFormDialogs';
|
||||||
|
|
||||||
import { useVendorCreditNoteFormContext } from './VendorCreditNoteFormProvider';
|
import { useVendorCreditNoteFormContext } from './VendorCreditNoteFormProvider';
|
||||||
|
|
||||||
import { AppToaster } from 'components';
|
import { AppToaster } from 'components';
|
||||||
|
import { compose, safeSumBy, transactionNumber } from 'utils';
|
||||||
import { compose, safeSumBy } from 'utils';
|
|
||||||
import {
|
import {
|
||||||
defaultVendorsCreditNote,
|
defaultVendorsCreditNote,
|
||||||
filterNonZeroEntries,
|
filterNonZeroEntries,
|
||||||
transformToEditForm,
|
transformToEditForm,
|
||||||
transformFormValuesToRequest,
|
transformFormValuesToRequest,
|
||||||
} from './utils';
|
} from './utils';
|
||||||
|
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
import withCurrentOrganization from 'containers/Organization/withCurrentOrganization';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vendor Credit note form.
|
* Vendor Credit note form.
|
||||||
*/
|
*/
|
||||||
function VendorCreditNoteForm({
|
function VendorCreditNoteForm({
|
||||||
|
// #withSettings
|
||||||
|
vendorcreditAutoIncrement,
|
||||||
|
vendorcreditNumberPrefix,
|
||||||
|
vendorcreditNextNumber,
|
||||||
|
|
||||||
// #withCurrentOrganization
|
// #withCurrentOrganization
|
||||||
organization: { base_currency },
|
organization: { base_currency },
|
||||||
}) {
|
}) {
|
||||||
@@ -46,6 +54,12 @@ function VendorCreditNoteForm({
|
|||||||
editVendorCreditMutate,
|
editVendorCreditMutate,
|
||||||
} = useVendorCreditNoteFormContext();
|
} = useVendorCreditNoteFormContext();
|
||||||
|
|
||||||
|
// Credit number.
|
||||||
|
const vendorCreditNumber = transactionNumber(
|
||||||
|
vendorcreditNumberPrefix,
|
||||||
|
vendorcreditNextNumber,
|
||||||
|
);
|
||||||
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = React.useMemo(
|
const initialValues = React.useMemo(
|
||||||
() => ({
|
() => ({
|
||||||
@@ -55,6 +69,9 @@ function VendorCreditNoteForm({
|
|||||||
}
|
}
|
||||||
: {
|
: {
|
||||||
...defaultVendorsCreditNote,
|
...defaultVendorsCreditNote,
|
||||||
|
...(vendorcreditAutoIncrement && {
|
||||||
|
vendor_credit_number: vendorCreditNumber,
|
||||||
|
}),
|
||||||
}),
|
}),
|
||||||
}),
|
}),
|
||||||
[vendorCredit, base_currency],
|
[vendorCredit, base_currency],
|
||||||
@@ -134,12 +151,19 @@ function VendorCreditNoteForm({
|
|||||||
<VendorCreditNoteFormHeader />
|
<VendorCreditNoteFormHeader />
|
||||||
<VendorCreditNoteItemsEntriesEditor />
|
<VendorCreditNoteItemsEntriesEditor />
|
||||||
<VendorCreditNoteFormFooter />
|
<VendorCreditNoteFormFooter />
|
||||||
|
|
||||||
<VendorCreditNoteFloatingActions />
|
<VendorCreditNoteFloatingActions />
|
||||||
|
<VendorCreditNoteFormDialogs />
|
||||||
</Form>
|
</Form>
|
||||||
</Formik>
|
</Formik>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default compose(withCurrentOrganization())(VendorCreditNoteForm);
|
export default compose(
|
||||||
|
withSettings(({ vendorsCreditNoteSetting }) => ({
|
||||||
|
vendorcreditAutoIncrement: vendorsCreditNoteSetting?.autoIncrement,
|
||||||
|
vendorcreditNextNumber: vendorsCreditNoteSetting?.nextNumber,
|
||||||
|
vendorcreditNumberPrefix: vendorsCreditNoteSetting?.numberPrefix,
|
||||||
|
})),
|
||||||
|
withCurrentOrganization(),
|
||||||
|
)(VendorCreditNoteForm);
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import VendorCreditNumberDialog from '../../../Dialogs/VendorCreditNumberDialog';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Vendor credit form dialog.
|
||||||
|
*/
|
||||||
|
export default function VendorCreditNoteFormDialogs() {
|
||||||
|
// Update the form once the vendor credit number form submit confirm.
|
||||||
|
const handleVendorCreditNumberFormConfirm = ({
|
||||||
|
incrementNumber,
|
||||||
|
manually,
|
||||||
|
}) => {
|
||||||
|
setFieldValue('vendor_credit_number', incrementNumber || '');
|
||||||
|
setFieldValue('vendor_credit_no_manually', manually);
|
||||||
|
};
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<React.Fragment>
|
||||||
|
<VendorCreditNumberDialog
|
||||||
|
dialogName={'vendor-credit-form'}
|
||||||
|
onConfirm={handleVendorCreditNumberFormConfirm}
|
||||||
|
/>
|
||||||
|
</React.Fragment>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,5 +1,10 @@
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { FormGroup, InputGroup, Position } from '@blueprintjs/core';
|
import {
|
||||||
|
FormGroup,
|
||||||
|
InputGroup,
|
||||||
|
Position,
|
||||||
|
ControlGroup,
|
||||||
|
} from '@blueprintjs/core';
|
||||||
import { DateInput } from '@blueprintjs/datetime';
|
import { DateInput } from '@blueprintjs/datetime';
|
||||||
import { FastField, Field, ErrorMessage } from 'formik';
|
import { FastField, Field, ErrorMessage } from 'formik';
|
||||||
import { CLASSES } from 'common/classes';
|
import { CLASSES } from 'common/classes';
|
||||||
@@ -7,10 +12,14 @@ import classNames from 'classnames';
|
|||||||
import {
|
import {
|
||||||
ContactSelecetList,
|
ContactSelecetList,
|
||||||
FieldRequiredHint,
|
FieldRequiredHint,
|
||||||
|
InputPrependButton,
|
||||||
Icon,
|
Icon,
|
||||||
FormattedMessage as T,
|
FormattedMessage as T,
|
||||||
} from 'components';
|
} from 'components';
|
||||||
import { vendorsFieldShouldUpdate } from './utils';
|
import {
|
||||||
|
vendorsFieldShouldUpdate,
|
||||||
|
useObserveVendorCreditNoSettings,
|
||||||
|
} from './utils';
|
||||||
|
|
||||||
import { useVendorCreditNoteFormContext } from './VendorCreditNoteFormProvider';
|
import { useVendorCreditNoteFormContext } from './VendorCreditNoteFormProvider';
|
||||||
|
|
||||||
@@ -22,13 +31,48 @@ import {
|
|||||||
handleDateChange,
|
handleDateChange,
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
|
|
||||||
|
import withSettings from 'containers/Settings/withSettings';
|
||||||
|
import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Vendor Credit note form header fields.
|
* Vendor Credit note form header fields.
|
||||||
*/
|
*/
|
||||||
|
function VendorCreditNoteFormHeaderFields({
|
||||||
|
// #withDialogActions
|
||||||
|
openDialog,
|
||||||
|
|
||||||
function VendorCreditNoteFormHeaderFields() {
|
// #withSettings
|
||||||
// Credit note form context.
|
vendorcreditAutoIncrement,
|
||||||
|
vendorcreditNumberPrefix,
|
||||||
|
vendorcreditNextNumber,
|
||||||
|
}) {
|
||||||
|
// Vendor Credit form context.
|
||||||
const { vendors } = useVendorCreditNoteFormContext();
|
const { vendors } = useVendorCreditNoteFormContext();
|
||||||
|
|
||||||
|
// Handle vendor credit number changing.
|
||||||
|
const handleVendorCreditNumberChange = () => {
|
||||||
|
openDialog('vendor-credit-form');
|
||||||
|
};
|
||||||
|
|
||||||
|
// Handle vendor credit no. field blur.
|
||||||
|
const handleVendorCreditNoBlur = (form, field) => (event) => {
|
||||||
|
const newValue = event.target.value;
|
||||||
|
|
||||||
|
if (field.value !== newValue && vendorcreditAutoIncrement) {
|
||||||
|
openDialog('vendor-credit-form', {
|
||||||
|
initialFormValues: {
|
||||||
|
manualTransactionNo: newValue,
|
||||||
|
incrementMode: 'manual-transaction',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
// Syncs vendor credit number settings with form.
|
||||||
|
useObserveVendorCreditNoSettings(
|
||||||
|
vendorcreditNumberPrefix,
|
||||||
|
vendorcreditNextNumber,
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
<div className={classNames(CLASSES.PAGE_FORM_HEADER_FIELDS)}>
|
||||||
{/* ----------- Vendor name ----------- */}
|
{/* ----------- Vendor name ----------- */}
|
||||||
@@ -94,7 +138,7 @@ function VendorCreditNoteFormHeaderFields() {
|
|||||||
|
|
||||||
{/* ----------- Vendor Credit No # ----------- */}
|
{/* ----------- Vendor Credit No # ----------- */}
|
||||||
<FastField name={'vendor_credit_number'}>
|
<FastField name={'vendor_credit_number'}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
{({ form, field, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'credit_note.label_credit_note'} />}
|
label={<T id={'credit_note.label_credit_note'} />}
|
||||||
inline={true}
|
inline={true}
|
||||||
@@ -102,12 +146,34 @@ function VendorCreditNoteFormHeaderFields() {
|
|||||||
intent={inputIntent({ error, touched })}
|
intent={inputIntent({ error, touched })}
|
||||||
helperText={<ErrorMessage name="vendor_credit_number" />}
|
helperText={<ErrorMessage name="vendor_credit_number" />}
|
||||||
>
|
>
|
||||||
<InputGroup minimal={true} {...field} />
|
<ControlGroup fill={true}>
|
||||||
|
<InputGroup
|
||||||
|
minimal={true}
|
||||||
|
value={field.value}
|
||||||
|
asyncControl={true}
|
||||||
|
onBlur={handleVendorCreditNoBlur(form, field)}
|
||||||
|
/>
|
||||||
|
<InputPrependButton
|
||||||
|
buttonProps={{
|
||||||
|
onClick: handleVendorCreditNumberChange,
|
||||||
|
icon: <Icon icon={'settings-18'} />,
|
||||||
|
}}
|
||||||
|
tooltip={true}
|
||||||
|
tooltipProps={{
|
||||||
|
content: (
|
||||||
|
<T
|
||||||
|
id={'setting_your_auto_generated_vendor_credit_number'}
|
||||||
|
/>
|
||||||
|
),
|
||||||
|
position: Position.BOTTOM_LEFT,
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
</ControlGroup>
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField>
|
</FastField>
|
||||||
{/* ----------- Reference ----------- */}
|
{/* ----------- Reference ----------- */}
|
||||||
{/* <FastField name={'reference_no'}>
|
<FastField name={'reference_no'}>
|
||||||
{({ field, meta: { error, touched } }) => (
|
{({ field, meta: { error, touched } }) => (
|
||||||
<FormGroup
|
<FormGroup
|
||||||
label={<T id={'reference_no'} />}
|
label={<T id={'reference_no'} />}
|
||||||
@@ -119,9 +185,16 @@ function VendorCreditNoteFormHeaderFields() {
|
|||||||
<InputGroup minimal={true} {...field} />
|
<InputGroup minimal={true} {...field} />
|
||||||
</FormGroup>
|
</FormGroup>
|
||||||
)}
|
)}
|
||||||
</FastField> */}
|
</FastField>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default VendorCreditNoteFormHeaderFields;
|
export default compose(
|
||||||
|
withDialogActions,
|
||||||
|
withSettings(({ vendorsCreditNoteSetting }) => ({
|
||||||
|
vendorcreditAutoIncrement: vendorsCreditNoteSetting?.autoIncrement,
|
||||||
|
vendorcreditNextNumber: vendorsCreditNoteSetting?.nextNumber,
|
||||||
|
vendorcreditNumberPrefix: vendorsCreditNoteSetting?.numberPrefix,
|
||||||
|
})),
|
||||||
|
)(VendorCreditNoteFormHeaderFields);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
useVendorCredit,
|
useVendorCredit,
|
||||||
useItems,
|
useItems,
|
||||||
useVendors,
|
useVendors,
|
||||||
|
useSettingsVendorCredits,
|
||||||
} from 'hooks/query';
|
} from 'hooks/query';
|
||||||
|
|
||||||
const VendorCreditNoteFormContext = React.createContext();
|
const VendorCreditNoteFormContext = React.createContext();
|
||||||
@@ -23,6 +24,9 @@ function VendorCreditNoteFormProvider({ vendorCreditId, ...props }) {
|
|||||||
page_size: 10000,
|
page_size: 10000,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Handle fetching settings.
|
||||||
|
useSettingsVendorCredits();
|
||||||
|
|
||||||
// Handle fetch vendors data table or list
|
// Handle fetch vendors data table or list
|
||||||
const {
|
const {
|
||||||
data: { vendors },
|
data: { vendors },
|
||||||
|
|||||||
@@ -6,12 +6,14 @@ import {
|
|||||||
defaultFastFieldShouldUpdate,
|
defaultFastFieldShouldUpdate,
|
||||||
transformToForm,
|
transformToForm,
|
||||||
repeatValue,
|
repeatValue,
|
||||||
|
transactionNumber,
|
||||||
orderingLinesIndexes,
|
orderingLinesIndexes,
|
||||||
} from 'utils';
|
} from 'utils';
|
||||||
import {
|
import {
|
||||||
updateItemsEntriesTotal,
|
updateItemsEntriesTotal,
|
||||||
ensureEntriesHaveEmptyLine,
|
ensureEntriesHaveEmptyLine,
|
||||||
} from 'containers/Entries/utils';
|
} from 'containers/Entries/utils';
|
||||||
|
import { useFormikContext } from 'formik';
|
||||||
|
|
||||||
export const MIN_LINES_NUMBER = 4;
|
export const MIN_LINES_NUMBER = 4;
|
||||||
|
|
||||||
@@ -30,6 +32,7 @@ export const defaultCreditNoteEntry = {
|
|||||||
export const defaultVendorsCreditNote = {
|
export const defaultVendorsCreditNote = {
|
||||||
vendor_id: '',
|
vendor_id: '',
|
||||||
vendor_credit_number: '',
|
vendor_credit_number: '',
|
||||||
|
vendor_credit_no_manually: false,
|
||||||
vendor_credit_date: moment(new Date()).format('YYYY-MM-DD'),
|
vendor_credit_date: moment(new Date()).format('YYYY-MM-DD'),
|
||||||
// reference_no: '',
|
// reference_no: '',
|
||||||
note: '',
|
note: '',
|
||||||
@@ -112,3 +115,15 @@ export const entriesFieldShouldUpdate = (newProps, oldProps) => {
|
|||||||
defaultFastFieldShouldUpdate(newProps, oldProps)
|
defaultFastFieldShouldUpdate(newProps, oldProps)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Syncs invoice no. settings with form.
|
||||||
|
*/
|
||||||
|
export const useObserveVendorCreditNoSettings = (prefix, nextNumber) => {
|
||||||
|
const { setFieldValue } = useFormikContext();
|
||||||
|
|
||||||
|
React.useEffect(() => {
|
||||||
|
const creditNo = transactionNumber(prefix, nextNumber);
|
||||||
|
setFieldValue('vendor_credit_number', creditNo);
|
||||||
|
}, [setFieldValue, prefix, nextNumber]);
|
||||||
|
};
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ function VendorsCreditNoteActionsBar({
|
|||||||
|
|
||||||
// Handle table row size change.
|
// Handle table row size change.
|
||||||
const handleTableRowSizeChange = (size) => {
|
const handleTableRowSizeChange = (size) => {
|
||||||
addSetting('vendorCredits', 'tableSize', size);
|
addSetting('vendorCredit', 'tableSize', size);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -19,8 +19,8 @@ export default (mapState) => {
|
|||||||
cashflowSettings: state.settings.data.cashflowAccounts,
|
cashflowSettings: state.settings.data.cashflowAccounts,
|
||||||
cashflowTransactionsSettings: state.settings.data.cashflowTransactions,
|
cashflowTransactionsSettings: state.settings.data.cashflowTransactions,
|
||||||
cashflowSetting: state.settings.data.cashflow,
|
cashflowSetting: state.settings.data.cashflow,
|
||||||
creditNoteSettings: state.settings.data.creditNotes,
|
creditNoteSettings: state.settings.data.creditNote,
|
||||||
vendorsCreditNoteSetting: state.settings.data.vendorCredits,
|
vendorsCreditNoteSetting: state.settings.data.vendorCredit,
|
||||||
};
|
};
|
||||||
return mapState ? mapState(mapped, state, props) : mapped;
|
return mapState ? mapState(mapped, state, props) : mapped;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -123,6 +123,27 @@ export function useSettingCashFlow(props) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve credit notes settings.
|
||||||
|
*/
|
||||||
|
export function useSettingsCreditNotes(props) {
|
||||||
|
return useSettingsQuery(
|
||||||
|
[t.SETTING, t.SETTING_CREDIT_NOTES],
|
||||||
|
{ group: 'credit_note' },
|
||||||
|
props,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Retrieve vendor credit settings.
|
||||||
|
*/
|
||||||
|
export function useSettingsVendorCredits(props) {
|
||||||
|
return useSettingsQuery(
|
||||||
|
[t.SETTING, t.SETTING_VENDOR_CREDITS],
|
||||||
|
{ group: 'vendor_credit' },
|
||||||
|
props,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve SMS Notifications settings.
|
* Retrieve SMS Notifications settings.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -130,6 +130,8 @@ const SETTING = {
|
|||||||
SETTING_SMS_NOTIFICATION: 'SETTING_SMS_NOTIFICATION',
|
SETTING_SMS_NOTIFICATION: 'SETTING_SMS_NOTIFICATION',
|
||||||
SETTING_SMS_NOTIFICATIONS: 'SETTING_SMS_NOTIFICATIONS',
|
SETTING_SMS_NOTIFICATIONS: 'SETTING_SMS_NOTIFICATIONS',
|
||||||
SETTING_EDIT_SMS_NOTIFICATION: 'SETTING_EDIT_SMS_NOTIFICATION',
|
SETTING_EDIT_SMS_NOTIFICATION: 'SETTING_EDIT_SMS_NOTIFICATION',
|
||||||
|
SETTING_CREDIT_NOTES: 'SETTING_CREDIT_NOTES',
|
||||||
|
SETTING_VENDOR_CREDITS: 'SETTING_VENDOR_CREDITS',
|
||||||
};
|
};
|
||||||
|
|
||||||
const ORGANIZATIONS = {
|
const ORGANIZATIONS = {
|
||||||
|
|||||||
@@ -21,6 +21,9 @@ const commonInvalidateQueries = (queryClient) => {
|
|||||||
queryClient.invalidateQueries(t.ACCOUNTS);
|
queryClient.invalidateQueries(t.ACCOUNTS);
|
||||||
queryClient.invalidateQueries(t.ACCOUNT);
|
queryClient.invalidateQueries(t.ACCOUNT);
|
||||||
|
|
||||||
|
// Invalidate settings.
|
||||||
|
queryClient.invalidateQueries([t.SETTING, t.SETTING_VENDOR_CREDITS]);
|
||||||
|
|
||||||
// Invalidate financial reports.
|
// Invalidate financial reports.
|
||||||
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
queryClient.invalidateQueries(t.FINANCIAL_REPORT);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1516,5 +1516,13 @@
|
|||||||
"vendor_credits.success_message": "The vendor credit has been created successfully",
|
"vendor_credits.success_message": "The vendor credit has been created successfully",
|
||||||
"vendor_credits.edit_success_message": "The vendor credit has been edited successfully.",
|
"vendor_credits.edit_success_message": "The vendor credit has been edited successfully.",
|
||||||
"vendor_credits.alert.success_message": "The given vendor credit has been deleted successfully.",
|
"vendor_credits.alert.success_message": "The given vendor credit has been deleted successfully.",
|
||||||
"vendor_credits.note.once_delete_this_vendor_credit_note": "Once you delete this vendor credit , you won't be able to restore it later. Are you sure you want to delete this vendor credit ?"
|
"vendor_credits.note.once_delete_this_vendor_credit_note": "Once you delete this vendor credit , you won't be able to restore it later. Are you sure you want to delete this vendor credit ?",
|
||||||
|
"credit_note_number_settings": "Credit Note Number Settings",
|
||||||
|
"credit_note.auto_increment.auto": "Your credit note numbers are set on auto-increment mode. Are you sure changing this setting?",
|
||||||
|
"credit_note.auto_increment.manually": "Your credit note numbers are set on manual mode. Are you sure chaning this settings?",
|
||||||
|
"setting_your_auto_generated_credit_note_number": "Setting your auto-generated credit note number",
|
||||||
|
"vendor_credit_number_settings": "Vendor Credit Number Settings",
|
||||||
|
"vendor_credit.auto_increment.auto": "Your vendor credit numbers are set on auto-increment mode. Are you sure changing this setting?",
|
||||||
|
"vendor_credit.auto_increment.manually": "Your vendor credit numbers are set on manual mode. Are you sure chaning this settings?",
|
||||||
|
"setting_your_auto_generated_vendor_credit_number": "Setting your auto-generated vendor credit number"
|
||||||
}
|
}
|
||||||
@@ -52,10 +52,10 @@ const initialState = {
|
|||||||
cashflowTransactions: {
|
cashflowTransactions: {
|
||||||
tableSize: 'medium',
|
tableSize: 'medium',
|
||||||
},
|
},
|
||||||
creditNotes: {
|
creditNote: {
|
||||||
tableSize: 'medium',
|
tableSize: 'medium',
|
||||||
},
|
},
|
||||||
vendorCredits: {
|
vendorCredit: {
|
||||||
tableSize: 'medium',
|
tableSize: 'medium',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user