mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 04:40:32 +00:00
fix: journal number increment.
This commit is contained in:
@@ -3,10 +3,10 @@ import { Intent, Button } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
|
||||
export default function MakeJournalEntriesFooter({
|
||||
formik: { isSubmitting },
|
||||
isSubmitting,
|
||||
onSubmitClick,
|
||||
onCancelClick,
|
||||
manualJournal,
|
||||
manualJournalId,
|
||||
}) {
|
||||
return (
|
||||
<div>
|
||||
@@ -19,11 +19,7 @@ export default function MakeJournalEntriesFooter({
|
||||
onSubmitClick({ publish: true, redirect: true });
|
||||
}}
|
||||
>
|
||||
{manualJournal && manualJournal.id ? (
|
||||
<T id={'edit'} />
|
||||
) : (
|
||||
<T id={'save'} />
|
||||
)}
|
||||
{manualJournalId ? <T id={'edit'} /> : <T id={'save'} />}
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
|
||||
@@ -52,6 +52,7 @@ function MakeJournalEntriesForm({
|
||||
// #withJournalsActions
|
||||
requestMakeJournalEntries,
|
||||
requestEditManualJournal,
|
||||
setJournalNumberChanged,
|
||||
|
||||
// #withDashboard
|
||||
changePageTitle,
|
||||
@@ -60,12 +61,11 @@ function MakeJournalEntriesForm({
|
||||
// #withSettings
|
||||
journalNextNumber,
|
||||
journalNumberPrefix,
|
||||
|
||||
|
||||
// #withManualJournals
|
||||
nextJournalNumberChanged,
|
||||
|
||||
setJournalNumberChanged,
|
||||
journalNumberChanged,
|
||||
|
||||
// #ownProps
|
||||
manualJournalId,
|
||||
manualJournal,
|
||||
onFormSubmit,
|
||||
@@ -93,7 +93,7 @@ function MakeJournalEntriesForm({
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
if (manualJournal && manualJournal.id) {
|
||||
if (manualJournal && manualJournal.id) {
|
||||
changePageTitle(formatMessage({ id: 'edit_journal' }));
|
||||
changePageSubtitle(`No. ${manualJournal.journal_number}`);
|
||||
} else {
|
||||
@@ -161,8 +161,9 @@ function MakeJournalEntriesForm({
|
||||
[],
|
||||
);
|
||||
|
||||
const journalNumber = (journalNumberPrefix) ?
|
||||
`${journalNumberPrefix}-${journalNextNumber}` : journalNextNumber;
|
||||
const journalNumber = journalNumberPrefix
|
||||
? `${journalNumberPrefix}-${journalNextNumber}`
|
||||
: journalNextNumber;
|
||||
|
||||
const defaultInitialValues = useMemo(
|
||||
() => ({
|
||||
@@ -269,12 +270,20 @@ function MakeJournalEntriesForm({
|
||||
}
|
||||
};
|
||||
|
||||
const formik = useFormik({
|
||||
const {
|
||||
values,
|
||||
errors,
|
||||
setFieldError,
|
||||
setFieldValue,
|
||||
handleSubmit,
|
||||
getFieldProps,
|
||||
touched,
|
||||
isSubmitting
|
||||
} = useFormik({
|
||||
validationSchema,
|
||||
initialValues: {
|
||||
...initialValues,
|
||||
},
|
||||
onSubmit: async (values, { setErrors, setSubmitting, resetForm }) => {
|
||||
initialValues,
|
||||
onSubmit: (values, { setErrors, setSubmitting, resetForm }) => {
|
||||
setSubmitting(true);
|
||||
const entries = values.entries.filter(
|
||||
(entry) => entry.debit || entry.credit,
|
||||
);
|
||||
@@ -369,17 +378,24 @@ function MakeJournalEntriesForm({
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
formik.setFieldValue('journal_number', journalNumber);
|
||||
setJournalNumberChanged(false);
|
||||
}, [nextJournalNumberChanged, journalNumber]);
|
||||
if (journalNumberChanged) {
|
||||
setFieldValue('journal_number', journalNumber);
|
||||
setJournalNumberChanged(false);
|
||||
}
|
||||
}, [journalNumberChanged, setJournalNumberChanged, journalNumber, setFieldValue]);
|
||||
|
||||
// Change page subtitle.
|
||||
useEffect(() => {
|
||||
changePageSubtitle(`No. ${journalNumber}`);
|
||||
}, [changePageSubtitle, journalNumber]);
|
||||
|
||||
const handleSubmitClick = useCallback(
|
||||
(payload) => {
|
||||
setPayload(payload);
|
||||
// formik.resetForm();
|
||||
formik.handleSubmit();
|
||||
handleSubmit();
|
||||
},
|
||||
[setPayload, formik],
|
||||
[setPayload, handleSubmit],
|
||||
);
|
||||
|
||||
const handleCancelClick = useCallback(
|
||||
@@ -401,38 +417,53 @@ function MakeJournalEntriesForm({
|
||||
);
|
||||
|
||||
// Handle click on add a new line/row.
|
||||
const handleClickAddNewRow = () => {
|
||||
formik.setFieldValue(
|
||||
const handleClickAddNewRow = useCallback(() => {
|
||||
setFieldValue(
|
||||
'entries',
|
||||
reorderingEntriesIndex([...formik.values.entries, defaultEntry]),
|
||||
reorderingEntriesIndex([...values.entries, defaultEntry]),
|
||||
);
|
||||
};
|
||||
}, [values.entries, defaultEntry, setFieldValue]);
|
||||
|
||||
// Handle click `Clear all lines` button.
|
||||
const handleClickClearLines = () => {
|
||||
formik.setFieldValue(
|
||||
const handleClickClearLines = useCallback(() => {
|
||||
setFieldValue(
|
||||
'entries',
|
||||
reorderingEntriesIndex([...repeatValue(defaultEntry, 4)]),
|
||||
);
|
||||
};
|
||||
}, [defaultEntry, setFieldValue]);
|
||||
|
||||
// Handle journal number field change.
|
||||
const handleJournalNumberChanged = useCallback(
|
||||
(journalNumber) => {
|
||||
changePageSubtitle(`No. ${journalNumber}`);
|
||||
},
|
||||
[changePageSubtitle],
|
||||
);
|
||||
|
||||
return (
|
||||
<div class="make-journal-entries">
|
||||
<form onSubmit={formik.handleSubmit}>
|
||||
<MakeJournalEntriesHeader formik={formik} />
|
||||
|
||||
<form onSubmit={handleSubmit}>
|
||||
<MakeJournalEntriesHeader
|
||||
errors={errors}
|
||||
touched={touched}
|
||||
values={values}
|
||||
setFieldValue={setFieldValue}
|
||||
getFieldProps={getFieldProps}
|
||||
onJournalNumberChanged={handleJournalNumberChanged}
|
||||
/>
|
||||
<MakeJournalEntriesTable
|
||||
values={formik.values.entries}
|
||||
formik={formik}
|
||||
values={values.entries}
|
||||
errors={errors}
|
||||
setFieldValue={setFieldValue}
|
||||
defaultRow={defaultEntry}
|
||||
onClickClearAllLines={handleClickClearLines}
|
||||
onClickAddNewRow={handleClickAddNewRow}
|
||||
/>
|
||||
<MakeJournalEntriesFooter
|
||||
formik={formik}
|
||||
isSubmitting={isSubmitting}
|
||||
onSubmitClick={handleSubmitClick}
|
||||
onCancelClick={handleCancelClick}
|
||||
manualJournal={manualJournal}
|
||||
manualJournal={manualJournalId}
|
||||
/>
|
||||
</form>
|
||||
|
||||
@@ -449,15 +480,15 @@ function MakeJournalEntriesForm({
|
||||
export default compose(
|
||||
withJournalsActions,
|
||||
withManualJournalDetail,
|
||||
withManualJournals(({ nextJournalNumberChanged }) => ({
|
||||
nextJournalNumberChanged,
|
||||
withManualJournals(({ journalNumberChanged }) => ({
|
||||
journalNumberChanged,
|
||||
})),
|
||||
withAccountsActions,
|
||||
withDashboardActions,
|
||||
withMediaActions,
|
||||
withSettings(({ manualJournalsSettings }) => ({
|
||||
journalNextNumber: manualJournalsSettings.nextNumber,
|
||||
journalNumberPrefix: manualJournalsSettings.numberPrefix
|
||||
journalNumberPrefix: manualJournalsSettings.numberPrefix,
|
||||
})),
|
||||
withManualJournalsActions,
|
||||
)(MakeJournalEntriesForm);
|
||||
|
||||
@@ -11,7 +11,7 @@ import { FormattedMessage as T } from 'react-intl';
|
||||
import { Row, Col } from 'react-grid-system';
|
||||
import moment from 'moment';
|
||||
import classNames from 'classnames';
|
||||
import { momentFormatter, tansformDateValue } from 'utils';
|
||||
import { momentFormatter, tansformDateValue, saveInvoke } from 'utils';
|
||||
import {
|
||||
CurrenciesSelectList,
|
||||
ErrorMessage,
|
||||
@@ -27,7 +27,14 @@ import withDialogActions from 'containers/Dialog/withDialogActions';
|
||||
import { compose } from 'utils';
|
||||
|
||||
function MakeJournalEntriesHeader({
|
||||
formik: { errors, touched, values, setFieldValue, getFieldProps },
|
||||
errors,
|
||||
touched,
|
||||
values,
|
||||
setFieldValue,
|
||||
getFieldProps,
|
||||
|
||||
// #ownProps
|
||||
onJournalNumberChanged,
|
||||
|
||||
// #withDialog
|
||||
openDialog,
|
||||
@@ -43,6 +50,11 @@ function MakeJournalEntriesHeader({
|
||||
openDialog('journal-number-form', {});
|
||||
}, [openDialog]);
|
||||
|
||||
// Handle journal number field blur event.
|
||||
const handleJournalNumberChanged = (event) => {
|
||||
saveInvoke(onJournalNumberChanged, event.currentTarget.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="make-journal-entries__header">
|
||||
<Row>
|
||||
@@ -82,6 +94,7 @@ function MakeJournalEntriesHeader({
|
||||
}}
|
||||
/>}
|
||||
{...getFieldProps('journal_number')}
|
||||
onBlur={handleJournalNumberChanged}
|
||||
/>
|
||||
</FormGroup>
|
||||
</Col>
|
||||
|
||||
@@ -36,7 +36,10 @@ function MakeJournalEntriesPage({
|
||||
requestFetchCustomers(),
|
||||
);
|
||||
|
||||
const fetchSettings = useQuery(['settings'], () => requestFetchOptions({}));
|
||||
const fetchSettings = useQuery(
|
||||
['settings'],
|
||||
() => requestFetchOptions({}),
|
||||
);
|
||||
|
||||
const fetchJournal = useQuery(
|
||||
['manual-journal', id],
|
||||
|
||||
@@ -103,7 +103,7 @@ function MakeJournalEntriesTable({
|
||||
onClickClearAllLines,
|
||||
defaultRow,
|
||||
values,
|
||||
formik: { errors, setFieldValue },
|
||||
errors, setFieldValue,
|
||||
}) {
|
||||
const [rows, setRows] = useState([]);
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
@@ -20,7 +20,7 @@ export default (mapState) => {
|
||||
manualJournalsPagination: getManualJournalsPagination(state, props, query),
|
||||
manualJournalsLoading: state.manualJournals.loading,
|
||||
|
||||
nextJournalNumberChanged: state.manualJournals.nextJournalNumberChanged,
|
||||
journalNumberChanged: state.manualJournals.journalNumberChanged,
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { getCustomersItems } from 'store/customers/customers.selectors';
|
||||
import { getCustomersItems, getCustomersListFactory } from 'store/customers/customers.selectors';
|
||||
import { getResourceViews } from 'store/customViews/customViews.selectors';
|
||||
|
||||
export default (mapState) => {
|
||||
const getCustomersList = getCustomersListFactory();
|
||||
|
||||
const mapStateToProps = (state, props) => {
|
||||
|
||||
const mapped = {
|
||||
customersViews: getResourceViews(state, props, 'customers'),
|
||||
customersItems: Object.values(state.customers.items),
|
||||
customersItems: getCustomersList(state, props),
|
||||
customers: getCustomersItems(state, state.customers.currentViewId),
|
||||
customersLoading: state.customers.loading,
|
||||
customerErrors: state.customers.errors,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import React from 'react';
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import { DialogContent } from 'components';
|
||||
import { useQuery, queryCache } from 'react-query';
|
||||
|
||||
@@ -29,29 +29,40 @@ function JournalNumberDialogContent({
|
||||
// #withManualJournalsActions
|
||||
setJournalNumberChanged,
|
||||
}) {
|
||||
const fetchSettings = useQuery(['settings'], () => requestFetchOptions({}));
|
||||
const [isChanged, setIsChanged] = useState(false);
|
||||
|
||||
const fetchSettings = useQuery(
|
||||
['settings', { group: 'manual_journal' }],
|
||||
() => requestFetchOptions({}),
|
||||
{
|
||||
onSuccess: () => {
|
||||
if (isChanged) {
|
||||
setJournalNumberChanged(true);
|
||||
setIsChanged(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
const handleSubmitForm = (values, { setSubmitting }) => {
|
||||
const options = optionsMapToArray(values).map((option) => {
|
||||
return { key: option.key, ...option, group: 'manual_journals' };
|
||||
});
|
||||
const options = optionsMapToArray(values).map((option) => ({
|
||||
key: option.key, ...option, group: 'manual_journals',
|
||||
}));
|
||||
|
||||
requestSubmitOptions({ options }).then(() => {
|
||||
setSubmitting(false);
|
||||
setIsChanged(true);
|
||||
|
||||
queryCache.invalidateQueries('settings');
|
||||
closeDialog('journal-number-form');
|
||||
setJournalNumberChanged(true);
|
||||
|
||||
setTimeout(() => {
|
||||
queryCache.invalidateQueries('settings');
|
||||
}, 250);
|
||||
}).catch(() => {
|
||||
setSubmitting(false);
|
||||
});
|
||||
};
|
||||
|
||||
const handleClose = () => {
|
||||
const handleClose = useCallback(() => {
|
||||
closeDialog('journal-number-form');
|
||||
};
|
||||
}, [closeDialog]);
|
||||
|
||||
return (
|
||||
<DialogContent isLoading={fetchSettings.isFetching}>
|
||||
@@ -62,15 +73,15 @@ function JournalNumberDialogContent({
|
||||
onClose={handleClose}
|
||||
/>
|
||||
</DialogContent>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withDialogActions,
|
||||
withSettingsActions,
|
||||
withSettings(({ manualJournalsSettings }) => ({
|
||||
nextNumber: manualJournalsSettings?.next_number,
|
||||
numberPrefix: manualJournalsSettings?.number_prefix,
|
||||
nextNumber: manualJournalsSettings?.nextNumber,
|
||||
numberPrefix: manualJournalsSettings?.numberPrefix,
|
||||
})),
|
||||
withManualJournalsActions,
|
||||
)(JournalNumberDialogContent);
|
||||
@@ -16,4 +16,11 @@ export const getCustomersItems = createSelector(
|
||||
? pickItemsFromIds(customersItems, customersView.ids) || []
|
||||
: [];
|
||||
},
|
||||
);
|
||||
|
||||
export const getCustomersListFactory = () => createSelector(
|
||||
customersItemsSelector,
|
||||
(customersItems) => {
|
||||
return Object.values(customersItems);
|
||||
}
|
||||
);
|
||||
7
client/src/store/journalNumber.reducer.js
Normal file
7
client/src/store/journalNumber.reducer.js
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
export const journalNumberReducers = (type) => ({
|
||||
[type]: (state, action) => {
|
||||
const { isChanged } = action.payload;
|
||||
state.journalNumberChanged = isChanged;
|
||||
},
|
||||
});
|
||||
@@ -2,6 +2,7 @@ import t from 'store/types';
|
||||
import { createReducer } from '@reduxjs/toolkit';
|
||||
import { createTableQueryReducers } from 'store/queryReducers';
|
||||
import { omit } from 'lodash';
|
||||
import { journalNumberReducers } from 'store/journalNumber.reducer';
|
||||
|
||||
const initialState = {
|
||||
items: {},
|
||||
@@ -15,7 +16,7 @@ const initialState = {
|
||||
paginationMeta: {
|
||||
total: 0,
|
||||
},
|
||||
nextJournalNumberChanged: false,
|
||||
journalNumberChanged: false,
|
||||
};
|
||||
|
||||
const defaultJournal = {
|
||||
@@ -117,10 +118,7 @@ const reducer = createReducer(initialState, {
|
||||
};
|
||||
},
|
||||
|
||||
[t.MANUAL_JOURNAL_NUMBER_CHANGED]: (state, action) => {
|
||||
const { isChanged } = action.payload;
|
||||
state.nextJournalNumberChanged = isChanged;
|
||||
}
|
||||
...journalNumberReducers(t.MANUAL_JOURNAL_NUMBER_CHANGED),
|
||||
});
|
||||
|
||||
export default createTableQueryReducers('manual_journals', reducer);
|
||||
|
||||
@@ -273,4 +273,8 @@ export const transformToObject = (arr, key) => {
|
||||
|
||||
export const itemsStartWith = (items, char) => {
|
||||
return items.filter((item) => item.indexOf(char) === 0);
|
||||
};
|
||||
};
|
||||
|
||||
export const saveInvoke = (func, ...rest) => {
|
||||
return func && func(...rest);
|
||||
}
|
||||
@@ -249,7 +249,11 @@ export default class ItemsController extends BaseController {
|
||||
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
|
||||
}
|
||||
try {
|
||||
const { items, pagination, filterMeta } = await this.itemsService.itemsList(tenantId, filter);
|
||||
const {
|
||||
items,
|
||||
pagination,
|
||||
filterMeta
|
||||
} = await this.itemsService.itemsList(tenantId, filter);
|
||||
|
||||
return res.status(200).send({
|
||||
items,
|
||||
|
||||
@@ -338,7 +338,6 @@ export default class BillsController extends BaseController {
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log(error.errorType);
|
||||
next(error);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user