fix: financial statements.

This commit is contained in:
Ahmed Bouhuolia
2020-05-13 02:39:36 +02:00
parent 5ffb54992e
commit 00de156c9f
23 changed files with 276 additions and 104 deletions

View File

@@ -13,7 +13,7 @@ import DashboardInsider from 'components/Dashboard/DashboardInsider';
import withDashboard from 'containers/Dashboard/withDashboard';
import withTrialBalanceActions from './withTrialBalanceActions';
import withTrialBalance from './withTrialBalance';
import SettingsConnect from 'connectors/Settings.connect';
import withSettings from 'containers/Settings/withSettings';
function TrialBalanceSheet({
@@ -35,13 +35,15 @@ function TrialBalanceSheet({
basis: 'accural',
none_zero: false,
});
const [refetch, setRefetch] = useState(false);
const fetchHook = useQuery(['trial-balance', filter],
(key, query) => { fetchTrialBalanceSheet(query); });
(key, query) => fetchTrialBalanceSheet(query),
{ manual: true });
// handle fetch data of trial balance table.
const handleFetchData = useCallback(() => {
fetchHook.refetch()
setRefetch(true);
}, [fetchHook]);
// Change page title of the dashboard.
@@ -56,7 +58,16 @@ function TrialBalanceSheet({
to_date: moment(filter.to_date).format('YYYY-MM-DD'),
};
setFilter(parsedFilter);
}, [setFilter]);
setRefetch(true);
}, []);
// Refetch sheet effect.
useEffect(() => {
if (refetch) {
fetchHook.refetch({ force: true });
setRefetch(false);
}
}, [fetchHook]);
return (
<DashboardInsider>
@@ -87,5 +98,5 @@ export default compose(
withTrialBalance(({ trialBalanceSheetLoading }) => ({
trialBalanceSheetLoading,
})),
SettingsConnect,
withSettings,
)(TrialBalanceSheet);

View File

@@ -1,7 +1,6 @@
import React, {useState, useCallback, useMemo} from 'react';
import * as Yup from 'yup';
import {Row, Col} from 'react-grid-system';
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
import {
Button,
} from "@blueprintjs/core";
@@ -9,6 +8,7 @@ import moment from 'moment';
import {useIntl} from 'react-intl';
import { useFormik } from 'formik';
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
import FinancialStatementDateRange from 'containers/FinancialStatements/FinancialStatementDateRange';

View File

@@ -18,6 +18,7 @@ function TrialBalanceSheetTable({
// #withTrialBalanceTable
trialBalanceIndex,
trialBalanceQuery,
onFetchData,
loading,
@@ -102,7 +103,8 @@ function TrialBalanceSheetTable({
<FinancialSheet
companyName={companyName}
sheetType={'Trial Balance Sheet'}
date={new Date()}
fromDate={trialBalanceQuery.from_date}
toDate={trialBalanceQuery.to_date}
name="trial-balance"
loading={loading}>
@@ -119,7 +121,10 @@ function TrialBalanceSheetTable({
const mapStateToProps = (state, props) => {
const { trialBalanceQuery } = props;
return {
trialBalanceIndex: getFinancialSheetIndexByQuery(state.financialStatements.trialBalance.sheets, trialBalanceQuery),
trialBalanceIndex: getFinancialSheetIndexByQuery(
state.financialStatements.trialBalance.sheets,
trialBalanceQuery,
),
};
};

View File

@@ -9,9 +9,14 @@ export default (mapState) => {
const mapStateToProps = (state, props) => {
const { trialBalanceIndex } = props;
const mapped = {
trialBalanceAccounts: getFinancialSheetAccounts(state.financialStatements.trialBalance.sheets, trialBalanceIndex),
trialBalanceQuery: getFinancialSheetQuery(state.financialStatements.trialBalance.sheets, trialBalanceIndex),
trialBalanceAccounts: getFinancialSheetAccounts(
state.financialStatements.trialBalance.sheets,
trialBalanceIndex
),
trialBalanceQuery: getFinancialSheetQuery(
state.financialStatements.trialBalance.sheets,
trialBalanceIndex
),
trialBalanceSheetLoading: state.financialStatements.trialBalance.loading,
};
return mapState ? mapState(mapped, state, props) : mapped;