mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-18 05:40:31 +00:00
feat: fix journal.
This commit is contained in:
@@ -59,6 +59,7 @@ function MakeJournalEntriesForm({
|
||||
journalNumberPrefix,
|
||||
journalNextNumber,
|
||||
);
|
||||
|
||||
// Form initial values.
|
||||
const initialValues = useMemo(
|
||||
() => ({
|
||||
@@ -69,7 +70,7 @@ function MakeJournalEntriesForm({
|
||||
: {
|
||||
...defaultManualJournal,
|
||||
...(journalAutoIncrement && {
|
||||
journal_number: defaultTo(journalNumber, ''),
|
||||
journal_number: journalNumber,
|
||||
}),
|
||||
currency_code: base_currency,
|
||||
}),
|
||||
@@ -187,7 +188,7 @@ function MakeJournalEntriesForm({
|
||||
export default compose(
|
||||
withMediaActions,
|
||||
withSettings(({ manualJournalsSettings }) => ({
|
||||
journalNextNumber: parseInt(manualJournalsSettings?.nextNumber, 10),
|
||||
journalNextNumber: manualJournalsSettings?.nextNumber,
|
||||
journalNumberPrefix: manualJournalsSettings?.numberPrefix,
|
||||
journalAutoIncrement: manualJournalsSettings?.autoIncrement,
|
||||
})),
|
||||
|
||||
@@ -62,14 +62,14 @@ function MakeJournalEntriesHeader({
|
||||
|
||||
// Handle journal number change.
|
||||
const handleJournalNumberChange = () => {
|
||||
openDialog('journal-number-form', {});
|
||||
openDialog('journal-number-form');
|
||||
};
|
||||
|
||||
// Handle journal number blur.
|
||||
const handleJournalNoBlur = (form, field) => (event) => {
|
||||
const newValue = event.target.value;
|
||||
|
||||
if (field.value !== newValue) {
|
||||
if (field.value !== newValue && journalAutoIncrement) {
|
||||
openDialog('journal-number-form', {
|
||||
initialFormValues: {
|
||||
manualTransactionNo: newValue,
|
||||
|
||||
@@ -40,6 +40,7 @@ export const defaultEntry = {
|
||||
|
||||
export const defaultManualJournal = {
|
||||
journal_number: '',
|
||||
journal_number_manually: false,
|
||||
journal_type: 'Journal',
|
||||
date: moment(new Date()).format('YYYY-MM-DD'),
|
||||
description: '',
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import { DialogContent } from 'components';
|
||||
import { useSaveSettings, useSettingsManualJournals } from 'hooks/query';
|
||||
|
||||
@@ -12,7 +13,7 @@ import {
|
||||
transformSettingsToForm,
|
||||
} from 'containers/JournalNumber/utils';
|
||||
|
||||
import 'style/pages/ManualJournal/JournalNumberDialog.scss'
|
||||
import 'style/pages/ManualJournal/JournalNumberDialog.scss';
|
||||
|
||||
/**
|
||||
* Journal number dialog's content.
|
||||
@@ -28,16 +29,14 @@ function JournalNumberDialogContent({
|
||||
|
||||
// #ownProps
|
||||
onConfirm,
|
||||
initialValues
|
||||
initialValues,
|
||||
}) {
|
||||
const { isLoading: isSettingsLoading } = useSettingsManualJournals();
|
||||
const { mutateAsync: saveSettingsMutate } = useSaveSettings();
|
||||
const [referenceFormValues, setReferenceFormValues] = React.useState(null);
|
||||
|
||||
// Handle the form submit.
|
||||
// Handle the form submit.
|
||||
const handleSubmitForm = (values, { setSubmitting }) => {
|
||||
// Transformes the form values to settings to save it.
|
||||
const options = transformFormToSettings(values, 'manual_journals');
|
||||
|
||||
// Handle success.
|
||||
const handleSuccess = () => {
|
||||
setSubmitting(false);
|
||||
@@ -52,6 +51,9 @@ function JournalNumberDialogContent({
|
||||
handleSuccess();
|
||||
return;
|
||||
}
|
||||
// Transformes the form values to settings to save it.
|
||||
const options = transformFormToSettings(values, 'manual_journals');
|
||||
|
||||
saveSettingsMutate({ options }).then(handleSuccess).catch(handleErrors);
|
||||
};
|
||||
|
||||
@@ -59,6 +61,17 @@ function JournalNumberDialogContent({
|
||||
closeDialog('journal-number-form');
|
||||
}, [closeDialog]);
|
||||
|
||||
// Handle form change.
|
||||
const handleChange = (values) => {
|
||||
setReferenceFormValues(values);
|
||||
};
|
||||
|
||||
// Description.
|
||||
const description =
|
||||
referenceFormValues?.incrementMode === 'auto'
|
||||
? intl.get('manual_journals.auto_increment.auto')
|
||||
: intl.get('manual_journals.auto_increment.manually');
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={isSettingsLoading}>
|
||||
<ReferenceNumberForm
|
||||
@@ -71,7 +84,9 @@ function JournalNumberDialogContent({
|
||||
...initialValues,
|
||||
}}
|
||||
onSubmit={handleSubmitForm}
|
||||
description={description}
|
||||
onClose={handleClose}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</DialogContent>
|
||||
);
|
||||
@@ -84,4 +99,4 @@ export default compose(
|
||||
numberPrefix: manualJournalsSettings?.numberPrefix,
|
||||
autoIncrement: manualJournalsSettings?.autoIncrement,
|
||||
})),
|
||||
)(JournalNumberDialogContent);
|
||||
)(JournalNumberDialogContent);
|
||||
|
||||
Reference in New Issue
Block a user