mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-17 13:20:31 +00:00
refactor: re-structure financial reports components.
This commit is contained in:
@@ -1,38 +1,31 @@
|
||||
import React, { useState, useCallback, useEffect } from 'react';
|
||||
import moment from 'moment';
|
||||
|
||||
import 'style/pages/FinancialStatements/ARAgingSummary.scss';
|
||||
// import 'style/pages/FinancialStatements/ARAgingSummary.scss';
|
||||
|
||||
import { FinancialStatement } from 'components';
|
||||
|
||||
import ARAgingSummaryHeader from './ARAgingSummaryHeader';
|
||||
import ARAgingSummaryActionsBar from './ARAgingSummaryActionsBar';
|
||||
import ARAgingSummaryTable from './ARAgingSummaryTable';
|
||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||
import { ARAgingSummaryProvider } from './ARAgingSummaryProvider';
|
||||
import { ARAgingSummarySheetLoadingBar } from './components';
|
||||
import { ARAgingSummaryBody } from './ARAgingSummaryBody';
|
||||
|
||||
import withARAgingSummaryActions from './withARAgingSummaryActions'
|
||||
import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization';
|
||||
import withARAgingSummaryActions from './withARAgingSummaryActions';
|
||||
|
||||
import { getDefaultARAgingSummaryQuery } from './common';
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* A/R aging summary report.
|
||||
*/
|
||||
function ReceivableAgingSummarySheet({
|
||||
// #withSettings
|
||||
organizationName,
|
||||
|
||||
// #withARAgingSummaryActions
|
||||
toggleARAgingSummaryFilterDrawer: toggleDisplayFilterDrawer
|
||||
toggleARAgingSummaryFilterDrawer: toggleDisplayFilterDrawer,
|
||||
}) {
|
||||
const [filter, setFilter] = useState({
|
||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||
agingDaysBefore: 30,
|
||||
agingPeriods: 3,
|
||||
customersIds: [],
|
||||
filterByOption: 'without-zero-balance',
|
||||
...getDefaultARAgingSummaryQuery(),
|
||||
});
|
||||
|
||||
// Handle filter submit.
|
||||
@@ -48,11 +41,13 @@ function ReceivableAgingSummarySheet({
|
||||
const handleNumberFormatSubmit = (numberFormat) => {
|
||||
setFilter({ ...filter, numberFormat });
|
||||
};
|
||||
|
||||
// Hide the filter drawer once the page unmount.
|
||||
useEffect(() => () => {
|
||||
toggleDisplayFilterDrawer(false);
|
||||
}, [toggleDisplayFilterDrawer]);
|
||||
useEffect(
|
||||
() => () => {
|
||||
toggleDisplayFilterDrawer(false);
|
||||
},
|
||||
[toggleDisplayFilterDrawer],
|
||||
);
|
||||
|
||||
return (
|
||||
<ARAgingSummaryProvider filter={filter}>
|
||||
@@ -68,18 +63,11 @@ function ReceivableAgingSummarySheet({
|
||||
pageFilter={filter}
|
||||
onSubmitFilter={handleFilterSubmit}
|
||||
/>
|
||||
<div class="financial-statement__body">
|
||||
<ARAgingSummaryTable organizationName={organizationName} />
|
||||
</div>
|
||||
<ARAgingSummaryBody />
|
||||
</FinancialStatement>
|
||||
</DashboardPageContent>
|
||||
</ARAgingSummaryProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withCurrentOrganization(({ organization }) => ({
|
||||
organizationName: organization.name,
|
||||
})),
|
||||
withARAgingSummaryActions
|
||||
)(ReceivableAgingSummarySheet);
|
||||
export default compose(withARAgingSummaryActions)(ReceivableAgingSummarySheet);
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import React from 'react';
|
||||
import * as R from 'ramda';
|
||||
|
||||
import ARAgingSummaryTable from './ARAgingSummaryTable';
|
||||
import {
|
||||
FinancialReportBody,
|
||||
FinancialSheetSkeleton,
|
||||
} from '../../../components';
|
||||
|
||||
import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization';
|
||||
import { useARAgingSummaryContext } from './ARAgingSummaryProvider';
|
||||
|
||||
/**
|
||||
* A/R Aging summary body.
|
||||
* @returns {JSX.Element}
|
||||
*/
|
||||
function ARAgingSummaryBodyJSX({
|
||||
// #withCurrentOrganization
|
||||
organizationName,
|
||||
}) {
|
||||
const { isARAgingLoading } = useARAgingSummaryContext();
|
||||
|
||||
return (
|
||||
<FinancialReportBody>
|
||||
{isARAgingLoading ? (
|
||||
<FinancialSheetSkeleton />
|
||||
) : (
|
||||
<ARAgingSummaryTable organizationName={organizationName} />
|
||||
)}
|
||||
</FinancialReportBody>
|
||||
);
|
||||
}
|
||||
|
||||
export const ARAgingSummaryBody = R.compose(
|
||||
withCurrentOrganization(({ organization }) => ({
|
||||
organizationName: organization.name,
|
||||
})),
|
||||
)(ARAgingSummaryBodyJSX);
|
||||
@@ -1,7 +1,9 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
import styled from 'styled-components';
|
||||
|
||||
import { DataTable, FinancialSheet } from 'components';
|
||||
import { TableStyle } from 'common';
|
||||
|
||||
import { useARAgingSummaryContext } from './ARAgingSummaryProvider';
|
||||
import { useARAgingSummaryColumns } from './components';
|
||||
@@ -29,14 +31,26 @@ export default function ReceivableAgingSummaryTable({
|
||||
asDate={new Date()}
|
||||
loading={isARAgingLoading}
|
||||
>
|
||||
<DataTable
|
||||
className="bigcapital-datatable--financial-report"
|
||||
<ARAgingSummaryDataTable
|
||||
columns={columns}
|
||||
data={ARAgingSummary.tableRows}
|
||||
rowClassNames={rowClassNames}
|
||||
noInitialFetch={true}
|
||||
sticky={true}
|
||||
styleName={TableStyle.Constrant}
|
||||
/>
|
||||
</FinancialSheet>
|
||||
);
|
||||
}
|
||||
|
||||
const ARAgingSummaryDataTable = styled(DataTable)`
|
||||
.table {
|
||||
.tbody .tr {
|
||||
.td {
|
||||
border-bottom: 0;
|
||||
padding-top: 0.32rem;
|
||||
padding-bottom: 0.32rem;
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,5 +1,19 @@
|
||||
import moment from 'moment';
|
||||
import { transformToCamelCase, flatObject } from 'utils';
|
||||
|
||||
export const transfromFilterFormToQuery = (form) => {
|
||||
return flatObject(transformToCamelCase(form));
|
||||
};
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the default A/R aging summary query.
|
||||
*/
|
||||
export const getDefaultARAgingSummaryQuery = () => {
|
||||
return {
|
||||
asDate: moment().endOf('day').format('YYYY-MM-DD'),
|
||||
agingDaysBefore: 30,
|
||||
agingPeriods: 3,
|
||||
customersIds: [],
|
||||
filterByOption: 'without-zero-balance',
|
||||
};
|
||||
};
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
import React from 'react';
|
||||
import intl from 'react-intl-universal';
|
||||
|
||||
import { useARAgingSummaryContext } from './ARAgingSummaryProvider';
|
||||
import { If, FormattedMessage as T } from 'components';
|
||||
|
||||
import { getColumnWidth } from 'utils';
|
||||
import { FormattedMessage as T } from 'components';
|
||||
import { If } from 'components';
|
||||
import { Align } from 'common';
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
|
||||
/**
|
||||
@@ -40,6 +42,7 @@ export const useARAgingSummaryColumns = () => {
|
||||
width: getColumnWidth(tableRows, `current`, {
|
||||
minWidth: 120,
|
||||
}),
|
||||
align: Align.Right
|
||||
},
|
||||
...agingColumns.map((agingColumn, index) => ({
|
||||
Header: agingColumn,
|
||||
@@ -47,6 +50,7 @@ export const useARAgingSummaryColumns = () => {
|
||||
width: getColumnWidth(tableRows, `aging-${index}`, {
|
||||
minWidth: 120,
|
||||
}),
|
||||
align: Align.Right
|
||||
})),
|
||||
{
|
||||
Header: <T id={'total'} />,
|
||||
@@ -56,6 +60,7 @@ export const useARAgingSummaryColumns = () => {
|
||||
width: getColumnWidth(tableRows, 'total', {
|
||||
minWidth: 120,
|
||||
}),
|
||||
align: Align.Right
|
||||
},
|
||||
],
|
||||
[tableRows, agingColumns],
|
||||
|
||||
Reference in New Issue
Block a user