mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-23 16:19:49 +00:00
feat(GeneralLedger): location query.
This commit is contained in:
@@ -15,9 +15,8 @@ import { GeneralLedgerBody } from './GeneralLedgerBody';
|
|||||||
|
|
||||||
import withGeneralLedgerActions from './withGeneralLedgerActions';
|
import withGeneralLedgerActions from './withGeneralLedgerActions';
|
||||||
|
|
||||||
import { transformFilterFormToQuery } from 'containers/FinancialStatements/common';
|
import { useGeneralLedgerQuery } from './common';
|
||||||
import { compose } from 'utils';
|
import { compose } from 'utils';
|
||||||
import { getDefaultGeneralLedgerQuery } from './common';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General Ledger (GL) sheet.
|
* General Ledger (GL) sheet.
|
||||||
@@ -26,9 +25,8 @@ function GeneralLedger({
|
|||||||
// #withGeneralLedgerActions
|
// #withGeneralLedgerActions
|
||||||
toggleGeneralLedgerFilterDrawer,
|
toggleGeneralLedgerFilterDrawer,
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
// General ledger query.
|
||||||
...getDefaultGeneralLedgerQuery(),
|
const { query, setLocationQuery } = useGeneralLedgerQuery();
|
||||||
});
|
|
||||||
|
|
||||||
// Handle financial statement filter change.
|
// Handle financial statement filter change.
|
||||||
const handleFilterSubmit = useCallback(
|
const handleFilterSubmit = useCallback(
|
||||||
@@ -38,9 +36,9 @@ function GeneralLedger({
|
|||||||
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
||||||
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
||||||
};
|
};
|
||||||
setFilter(parsedFilter);
|
setLocationQuery(parsedFilter);
|
||||||
},
|
},
|
||||||
[setFilter],
|
[setLocationQuery],
|
||||||
);
|
);
|
||||||
|
|
||||||
// Hide the filter drawer once the page unmount.
|
// Hide the filter drawer once the page unmount.
|
||||||
@@ -52,13 +50,13 @@ function GeneralLedger({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<GeneralLedgerProvider query={transformFilterFormToQuery(filter)}>
|
<GeneralLedgerProvider query={query}>
|
||||||
<GeneralLedgerActionsBar />
|
<GeneralLedgerActionsBar />
|
||||||
|
|
||||||
<DashboardPageContent>
|
<DashboardPageContent>
|
||||||
<FinancialStatement>
|
<FinancialStatement>
|
||||||
<GeneralLedgerHeader
|
<GeneralLedgerHeader
|
||||||
pageFilter={filter}
|
pageFilter={query}
|
||||||
onSubmitFilter={handleFilterSubmit}
|
onSubmitFilter={handleFilterSubmit}
|
||||||
/>
|
/>
|
||||||
<GeneralLedgerSheetLoadingBar />
|
<GeneralLedgerSheetLoadingBar />
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import GeneralLedgerHeaderDimensionsPanel from './GeneralLedgerHeaderDimensionsP
|
|||||||
import withGeneralLedger from './withGeneralLedger';
|
import withGeneralLedger from './withGeneralLedger';
|
||||||
import withGeneralLedgerActions from './withGeneralLedgerActions';
|
import withGeneralLedgerActions from './withGeneralLedgerActions';
|
||||||
|
|
||||||
|
import { getDefaultGeneralLedgerQuery } from './common';
|
||||||
import { compose, transformToForm, saveInvoke } from 'utils';
|
import { compose, transformToForm, saveInvoke } from 'utils';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,11 +32,7 @@ function GeneralLedgerHeader({
|
|||||||
isFilterDrawerOpen,
|
isFilterDrawerOpen,
|
||||||
}) {
|
}) {
|
||||||
// Default values.
|
// Default values.
|
||||||
const defaultValues = {
|
const defaultValues = getDefaultGeneralLedgerQuery();
|
||||||
fromDate: moment().toDate(),
|
|
||||||
toDate: moment().toDate(),
|
|
||||||
branchesIds: [],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Initial values.
|
// Initial values.
|
||||||
const initialValues = transformToForm(
|
const initialValues = transformToForm(
|
||||||
@@ -43,30 +40,25 @@ function GeneralLedgerHeader({
|
|||||||
...pageFilter,
|
...pageFilter,
|
||||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||||
toDate: moment(pageFilter.toDate).toDate(),
|
toDate: moment(pageFilter.toDate).toDate(),
|
||||||
branchesIds: [],
|
|
||||||
},
|
},
|
||||||
defaultValues,
|
defaultValues,
|
||||||
);
|
);
|
||||||
|
|
||||||
// Validation schema.
|
// Validation schema.
|
||||||
const validationSchema = Yup.object().shape({
|
const validationSchema = Yup.object().shape({
|
||||||
dateRange: Yup.string().optional(),
|
dateRange: Yup.string().optional(),
|
||||||
fromDate: Yup.date().required(),
|
fromDate: Yup.date().required(),
|
||||||
toDate: Yup.date().min(Yup.ref('fromDate')).required(),
|
toDate: Yup.date().min(Yup.ref('fromDate')).required(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// Handle form submit.
|
// Handle form submit.
|
||||||
const handleSubmit = (values, { setSubmitting }) => {
|
const handleSubmit = (values, { setSubmitting }) => {
|
||||||
saveInvoke(onSubmitFilter, values);
|
saveInvoke(onSubmitFilter, values);
|
||||||
toggleDisplayFilterDrawer();
|
toggleDisplayFilterDrawer(false);
|
||||||
setSubmitting(false);
|
setSubmitting(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle cancel button click.
|
// Handle cancel button click.
|
||||||
const handleCancelClick = () => {
|
const handleCancelClick = () => {
|
||||||
toggleDisplayFilterDrawer(false);
|
toggleDisplayFilterDrawer(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Handle drawer close action.
|
// Handle drawer close action.
|
||||||
const handleDrawerClose = () => {
|
const handleDrawerClose = () => {
|
||||||
toggleDisplayFilterDrawer(false);
|
toggleDisplayFilterDrawer(false);
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
import React, { createContext, useContext } from 'react';
|
import React, { createContext, useContext } from 'react';
|
||||||
|
|
||||||
import FinancialReportPage from '../FinancialReportPage';
|
import FinancialReportPage from '../FinancialReportPage';
|
||||||
import { useGeneralLedgerSheet, useAccounts } from 'hooks/query';
|
import { useGeneralLedgerSheet } from 'hooks/query';
|
||||||
|
import { transformFilterFormToQuery } from '../common';
|
||||||
|
|
||||||
const GeneralLedgerContext = createContext();
|
const GeneralLedgerContext = createContext();
|
||||||
|
|
||||||
@@ -8,12 +10,18 @@ const GeneralLedgerContext = createContext();
|
|||||||
* General ledger provider.
|
* General ledger provider.
|
||||||
*/
|
*/
|
||||||
function GeneralLedgerProvider({ query, ...props }) {
|
function GeneralLedgerProvider({ query, ...props }) {
|
||||||
|
// Transformes the report query to request query.
|
||||||
|
const requestQuery = React.useMemo(
|
||||||
|
() => transformFilterFormToQuery(query),
|
||||||
|
[query],
|
||||||
|
);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
data: generalLedger,
|
data: generalLedger,
|
||||||
isFetching,
|
isFetching,
|
||||||
isLoading,
|
isLoading,
|
||||||
refetch,
|
refetch,
|
||||||
} = useGeneralLedgerSheet(query, { keepPreviousData: true });
|
} = useGeneralLedgerSheet(requestQuery, { keepPreviousData: true });
|
||||||
|
|
||||||
const provider = {
|
const provider = {
|
||||||
generalLedger,
|
generalLedger,
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
|
import React from 'react';
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import { castArray } from 'lodash';
|
||||||
|
|
||||||
|
import { useAppQueryString } from 'hooks';
|
||||||
|
import { transformToForm } from 'utils';
|
||||||
|
|
||||||
|
// Filters accounts options.
|
||||||
export const filterAccountsOptions = [
|
export const filterAccountsOptions = [
|
||||||
{
|
{
|
||||||
key: 'all-accounts',
|
key: 'all-accounts',
|
||||||
@@ -25,5 +31,39 @@ export const getDefaultGeneralLedgerQuery = () => {
|
|||||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||||
basis: 'accural',
|
basis: 'accural',
|
||||||
filterByOption: 'with-transactions',
|
filterByOption: 'with-transactions',
|
||||||
|
branchesIds: [],
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parses general ledger query of browser location.
|
||||||
|
*/
|
||||||
|
const parseGeneralLedgerQuery = (locationQuery) => {
|
||||||
|
const defaultQuery = getDefaultGeneralLedgerQuery();
|
||||||
|
|
||||||
|
const transformed = {
|
||||||
|
...defaultQuery,
|
||||||
|
...transformToForm(locationQuery, defaultQuery),
|
||||||
|
};
|
||||||
|
return {
|
||||||
|
...transformed,
|
||||||
|
|
||||||
|
// Ensures the branches ids is always array.
|
||||||
|
branchesIds: castArray(transformed.branchesIds),
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the general ledger location query.
|
||||||
|
*/
|
||||||
|
export const useGeneralLedgerQuery = () => {
|
||||||
|
// Retrieves location query.
|
||||||
|
const [locationQuery, setLocationQuery] = useAppQueryString();
|
||||||
|
|
||||||
|
// Merges the default filter query with location URL query.
|
||||||
|
const query = React.useMemo(
|
||||||
|
() => parseGeneralLedgerQuery(locationQuery),
|
||||||
|
[locationQuery],
|
||||||
|
);
|
||||||
|
return { query, locationQuery, setLocationQuery };
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user