mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
feat: Inventory item details report.
feat: Cash flow statement report.
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import moment from 'moment';
|
||||
import 'style/pages/FinancialStatements/CashFlowStatement.scss';
|
||||
|
||||
import { FinancialStatement } from 'components';
|
||||
import DashboardPageContent from 'components/Dashboard/DashboardPageContent';
|
||||
|
||||
import CashFlowStatementHeader from './CashFlowStatementHeader';
|
||||
import CashFlowStatementTable from './CashFlowStatementTable';
|
||||
import CashFlowStatementActionsBar from './CashFlowStatementActionsBar';
|
||||
|
||||
import withSettings from 'containers/Settings/withSettings';
|
||||
import withCashFlowStatementActions from './withCashFlowStatementActions';
|
||||
import { CashFlowStatementProvider } from './CashFlowStatementProvider';
|
||||
import { CashFlowStatementLoadingBar } from './components';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Cash flow statement.
|
||||
*/
|
||||
function CashFlowStatement({
|
||||
// #withPreferences
|
||||
organizationName,
|
||||
//#withCashStatementActions
|
||||
toggleCashFlowStatementFilterDrawer,
|
||||
}) {
|
||||
// filter
|
||||
const [filter, setFilter] = useState({
|
||||
fromDate: moment().startOf('year').format('YYYY-MM-DD'),
|
||||
toDate: moment().endOf('year').format('YYYY-MM-DD'),
|
||||
basis: 'cash',
|
||||
displayColumnsType: 'total',
|
||||
});
|
||||
|
||||
// Handle refetch cash flow after filter change.
|
||||
const handleFilterSubmit = (filter) => {
|
||||
const _filter = {
|
||||
...filter,
|
||||
fromDate: moment(filter.fromDate).format('YYYY-MM-DD'),
|
||||
toDate: moment(filter.toDate).format('YYYY-MM-DD'),
|
||||
};
|
||||
setFilter({ ..._filter });
|
||||
};
|
||||
|
||||
// Handle format number submit.
|
||||
const handleNumberFormatSubmit = (values) => {
|
||||
setFilter({
|
||||
...filter,
|
||||
numberFormat: values,
|
||||
});
|
||||
};
|
||||
|
||||
useEffect(
|
||||
() => () => {
|
||||
toggleCashFlowStatementFilterDrawer(false);
|
||||
},
|
||||
[toggleCashFlowStatementFilterDrawer],
|
||||
);
|
||||
|
||||
return (
|
||||
<CashFlowStatementProvider filter={filter}>
|
||||
<CashFlowStatementActionsBar
|
||||
numberFormat={filter.numberFormat}
|
||||
onNumberFormatSubmit={handleNumberFormatSubmit}
|
||||
/>
|
||||
<CashFlowStatementLoadingBar />
|
||||
<DashboardPageContent>
|
||||
<FinancialStatement>
|
||||
<CashFlowStatementHeader
|
||||
pageFilter={filter}
|
||||
onSubmitFilter={handleFilterSubmit}
|
||||
/>
|
||||
<div class="financial-statement__body">
|
||||
<CashFlowStatementTable companyName={organizationName} />
|
||||
</div>
|
||||
</FinancialStatement>
|
||||
</DashboardPageContent>
|
||||
</CashFlowStatementProvider>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withSettings(({ organizationSettings }) => ({
|
||||
organizationName: organizationSettings?.name,
|
||||
})),
|
||||
withCashFlowStatementActions,
|
||||
)(CashFlowStatement);
|
||||
@@ -0,0 +1,134 @@
|
||||
import React from 'react';
|
||||
import {
|
||||
NavbarGroup,
|
||||
NavbarDivider,
|
||||
Button,
|
||||
Classes,
|
||||
Popover,
|
||||
PopoverInteractionKind,
|
||||
Position,
|
||||
} from '@blueprintjs/core';
|
||||
import { FormattedMessage as T } from 'react-intl';
|
||||
import classNames from 'classnames';
|
||||
|
||||
import { Icon } from 'components';
|
||||
import DashboardActionsBar from 'components/Dashboard/DashboardActionsBar';
|
||||
import NumberFormatDropdown from 'components/NumberFormatDropdown';
|
||||
|
||||
import { useCashFlowStatementContext } from './CashFlowStatementProvider';
|
||||
import withCashFlowStatement from './withCashFlowStatement';
|
||||
import withCashFlowStatementActions from './withCashFlowStatementActions';
|
||||
|
||||
import { compose, saveInvoke } from 'utils';
|
||||
|
||||
/**
|
||||
* Cash flow statement actions bar.
|
||||
*/
|
||||
function CashFlowStatementActionsBar({
|
||||
//#withCashFlowStatement
|
||||
isFilterDrawerOpen,
|
||||
|
||||
//#withCashStatementActions
|
||||
toggleCashFlowStatementFilterDrawer,
|
||||
|
||||
//#ownProps
|
||||
numberFormat,
|
||||
onNumberFormatSubmit,
|
||||
}) {
|
||||
const { isCashFlowLoading, refetchCashFlow } = useCashFlowStatementContext();
|
||||
|
||||
// Handle filter toggle click.
|
||||
const handleFilterToggleClick = () => {
|
||||
toggleCashFlowStatementFilterDrawer();
|
||||
};
|
||||
|
||||
// Handle recalculate report button.
|
||||
const handleRecalculateReport = () => {
|
||||
refetchCashFlow();
|
||||
};
|
||||
|
||||
// handle number format form submit.
|
||||
const handleNumberFormatSubmit = (values) =>
|
||||
saveInvoke(onNumberFormatSubmit, values);
|
||||
|
||||
return (
|
||||
<DashboardActionsBar>
|
||||
<NavbarGroup>
|
||||
<Button
|
||||
className={classNames(Classes.MINIMAL, 'button--gray-highlight')}
|
||||
text={<T id={'recalc_report'} />}
|
||||
onClick={handleRecalculateReport}
|
||||
icon={<Icon icon="refresh-16" iconSize={16} />}
|
||||
/>
|
||||
|
||||
<NavbarDivider />
|
||||
|
||||
<Button
|
||||
className={classNames(Classes.MINIMAL, 'button--table-views')}
|
||||
icon={<Icon icon="cog-16" iconSize={16} />}
|
||||
text={
|
||||
isFilterDrawerOpen ? (
|
||||
<T id={'hide_customizer'} />
|
||||
) : (
|
||||
<T id={'customize_report'} />
|
||||
)
|
||||
}
|
||||
onClick={handleFilterToggleClick}
|
||||
active={isFilterDrawerOpen}
|
||||
/>
|
||||
|
||||
<NavbarDivider />
|
||||
<Popover
|
||||
content={
|
||||
<NumberFormatDropdown
|
||||
numberFormat={numberFormat}
|
||||
onSubmit={handleNumberFormatSubmit}
|
||||
submitDisabled={isCashFlowLoading}
|
||||
/>
|
||||
}
|
||||
minimal={true}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button
|
||||
className={classNames(Classes.MINIMAL, 'button--filter')}
|
||||
text={<T id={'format'} />}
|
||||
icon={<Icon icon="numbers" width={23} height={16} />}
|
||||
/>
|
||||
</Popover>
|
||||
|
||||
<Popover
|
||||
// content={}
|
||||
interactionKind={PopoverInteractionKind.CLICK}
|
||||
position={Position.BOTTOM_LEFT}
|
||||
>
|
||||
<Button
|
||||
className={classNames(Classes.MINIMAL, 'button--filter')}
|
||||
text={<T id={'filter'} />}
|
||||
icon={<Icon icon="filter-16" iconSize={16} />}
|
||||
/>
|
||||
</Popover>
|
||||
|
||||
<NavbarDivider />
|
||||
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="print-16" iconSize={16} />}
|
||||
text={<T id={'print'} />}
|
||||
/>
|
||||
<Button
|
||||
className={Classes.MINIMAL}
|
||||
icon={<Icon icon="file-export-16" iconSize={16} />}
|
||||
text={<T id={'export'} />}
|
||||
/>
|
||||
</NavbarGroup>
|
||||
</DashboardActionsBar>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withCashFlowStatement(({ cashFlowStatementDrawerFilter }) => ({
|
||||
isFilterDrawerOpen: cashFlowStatementDrawerFilter,
|
||||
})),
|
||||
withCashFlowStatementActions,
|
||||
)(CashFlowStatementActionsBar);
|
||||
@@ -0,0 +1,20 @@
|
||||
import React from 'react';
|
||||
import FinancialStatementDateRange from 'containers/FinancialStatements/FinancialStatementDateRange';
|
||||
import FinancialAccountsFilter from '../FinancialAccountsFilter';
|
||||
import RadiosAccountingBasis from '../RadiosAccountingBasis';
|
||||
import SelectDisplayColumnsBy from '../SelectDisplayColumnsBy';
|
||||
|
||||
/**
|
||||
* Cash flow statement header - General panel.
|
||||
*/
|
||||
|
||||
export default function CashFlowStatementHeaderGeneralPanel() {
|
||||
return (
|
||||
<div>
|
||||
<FinancialStatementDateRange />
|
||||
<SelectDisplayColumnsBy />
|
||||
<FinancialAccountsFilter initialSelectedItem={'all-accounts'} />
|
||||
<RadiosAccountingBasis key={'basis'} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,102 @@
|
||||
import React from 'react';
|
||||
import { Tabs, Tab, Button, Intent } from '@blueprintjs/core';
|
||||
import { FormattedMessage as T, useIntl } from 'react-intl';
|
||||
import moment from 'moment';
|
||||
import * as Yup from 'yup';
|
||||
import { Formik, Form } from 'formik';
|
||||
|
||||
import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader';
|
||||
import CashFlowStatementGeneralPanel from './CashFlowStatementGeneralPanel';
|
||||
|
||||
import withCashFlowStatement from './withCashFlowStatement';
|
||||
import withCashFlowStatementActions from './withCashFlowStatementActions';
|
||||
|
||||
import { compose } from 'utils';
|
||||
|
||||
/**
|
||||
* Cash flow statement header.
|
||||
*/
|
||||
function CashFlowStatementHeader({
|
||||
// #ownProps
|
||||
onSubmitFilter,
|
||||
pageFilter,
|
||||
|
||||
//#withCashFlowStatement
|
||||
isFilterDrawerOpen,
|
||||
|
||||
//#withCashStatementActions
|
||||
toggleCashFlowStatementFilterDrawer,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
// filter form initial values.
|
||||
const initialValues = {
|
||||
...pageFilter,
|
||||
fromDate: moment(pageFilter.fromDate).toDate(),
|
||||
toDate: moment(pageFilter.toDate).toDate(),
|
||||
};
|
||||
|
||||
// Validation schema.
|
||||
const validationSchema = Yup.object().shape({
|
||||
dateRange: Yup.string().optional(),
|
||||
fromDate: Yup.date()
|
||||
.required()
|
||||
.label(formatMessage({ id: 'fromDate' })),
|
||||
toDate: Yup.date()
|
||||
.min(Yup.ref('fromDate'))
|
||||
.required()
|
||||
.label(formatMessage({ id: 'toDate' })),
|
||||
displayColumnsType: Yup.string(),
|
||||
});
|
||||
|
||||
// Handle form submit.
|
||||
const handleSubmit = (values, { setSubmitting }) => {
|
||||
onSubmitFilter(values);
|
||||
toggleCashFlowStatementFilterDrawer(false);
|
||||
setSubmitting(false);
|
||||
};
|
||||
|
||||
// Handle drawer close action.
|
||||
const handleDrawerClose = () => {
|
||||
toggleCashFlowStatementFilterDrawer(false);
|
||||
};
|
||||
|
||||
return (
|
||||
<FinancialStatementHeader
|
||||
isOpen={isFilterDrawerOpen}
|
||||
drawerProps={{ onClose: handleDrawerClose }}
|
||||
>
|
||||
<Formik
|
||||
initialValues={initialValues}
|
||||
validationSchema={validationSchema}
|
||||
onSubmit={handleSubmit}
|
||||
>
|
||||
<Form>
|
||||
<Tabs animate={true} vertical={true} renderActiveTabPanelOnly={true}>
|
||||
<Tab
|
||||
id="general"
|
||||
title={<T id={'general'} />}
|
||||
panel={<CashFlowStatementGeneralPanel />}
|
||||
/>
|
||||
</Tabs>
|
||||
|
||||
<div class="financial-header-drawer__footer">
|
||||
<Button className={'mr1'} intent={Intent.PRIMARY} type={'submit'}>
|
||||
<T id={'calculate_report'} />
|
||||
</Button>
|
||||
<Button onClick={handleDrawerClose} minimal={true}>
|
||||
<T id={'cancel'} />
|
||||
</Button>
|
||||
</div>
|
||||
</Form>
|
||||
</Formik>
|
||||
</FinancialStatementHeader>
|
||||
);
|
||||
}
|
||||
|
||||
export default compose(
|
||||
withCashFlowStatement(({ cashFlowStatementDrawerFilter }) => ({
|
||||
isFilterDrawerOpen: cashFlowStatementDrawerFilter,
|
||||
})),
|
||||
withCashFlowStatementActions,
|
||||
)(CashFlowStatementHeader);
|
||||
@@ -0,0 +1,45 @@
|
||||
import React from 'react';
|
||||
import FinancialReportPage from '../FinancialReportPage';
|
||||
import { useCashFlowStatementReport } from 'hooks/query';
|
||||
import { transformFilterFormToQuery } from '../common';
|
||||
|
||||
const CashFLowStatementContext = React.createContext();
|
||||
|
||||
/**
|
||||
* Cash flow statement provider.
|
||||
*/
|
||||
function CashFlowStatementProvider({ filter, ...props }) {
|
||||
// transforms the given filter to query.
|
||||
const query = React.useMemo(
|
||||
() => transformFilterFormToQuery(filter),
|
||||
[filter],
|
||||
);
|
||||
|
||||
// fetch the cash flow statement report.
|
||||
const {
|
||||
data: cashFlowStatement,
|
||||
isFetching: isCashFlowFetching,
|
||||
isLoading: isCashFlowLoading,
|
||||
refetch: refetchCashFlow,
|
||||
} = useCashFlowStatementReport(query, { keepPreviousData: true });
|
||||
|
||||
const provider = {
|
||||
cashFlowStatement,
|
||||
isCashFlowFetching,
|
||||
isCashFlowLoading,
|
||||
refetchCashFlow,
|
||||
query,
|
||||
filter,
|
||||
};
|
||||
|
||||
return (
|
||||
<FinancialReportPage name="cash-flow-statement">
|
||||
<CashFLowStatementContext.Provider value={provider} {...props} />
|
||||
</FinancialReportPage>
|
||||
);
|
||||
}
|
||||
|
||||
const useCashFlowStatementContext = () =>
|
||||
React.useContext(CashFLowStatementContext);
|
||||
|
||||
export { CashFlowStatementProvider, useCashFlowStatementContext };
|
||||
@@ -0,0 +1,63 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { useIntl } from 'react-intl';
|
||||
|
||||
import { DataTable } from 'components';
|
||||
import FinancialSheet from 'components/FinancialSheet';
|
||||
import { useCashFlowStatementColumns } from './components';
|
||||
import { useCashFlowStatementContext } from './CashFlowStatementProvider';
|
||||
|
||||
import { defaultExpanderReducer } from 'utils';
|
||||
|
||||
/**
|
||||
* Cash flow statement table.
|
||||
*/
|
||||
export default function CashFlowStatementTable({
|
||||
// #ownProps
|
||||
companyName,
|
||||
}) {
|
||||
const { formatMessage } = useIntl();
|
||||
|
||||
const {
|
||||
cashFlowStatement: { tableRows },
|
||||
isCashFlowLoading,
|
||||
query,
|
||||
} = useCashFlowStatementContext();
|
||||
|
||||
const columns = useCashFlowStatementColumns();
|
||||
|
||||
const expandedRows = useMemo(
|
||||
() => defaultExpanderReducer(tableRows, 4),
|
||||
[tableRows],
|
||||
);
|
||||
|
||||
const rowClassNames = (row) => {
|
||||
return [
|
||||
`row-type--${row.original.rowTypes}`,
|
||||
`row-type--${row.original.id}`,
|
||||
];
|
||||
};
|
||||
|
||||
return (
|
||||
<FinancialSheet
|
||||
name="cash-flow-statement"
|
||||
companyName={companyName}
|
||||
sheetType={formatMessage({ id: 'statement_of_cash_flow' })}
|
||||
loading={isCashFlowLoading}
|
||||
fromDate={query.from_date}
|
||||
toDate={query.to_date}
|
||||
basis={query.basis}
|
||||
>
|
||||
<DataTable
|
||||
className="bigcapital-datatable--financial-report"
|
||||
columns={columns}
|
||||
data={tableRows}
|
||||
rowClassNames={rowClassNames}
|
||||
noInitialFetch={true}
|
||||
expandable={true}
|
||||
expanded={expandedRows}
|
||||
expandToggleColumn={1}
|
||||
expandColumnSpace={0.8}
|
||||
/>
|
||||
</FinancialSheet>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import React from 'react';
|
||||
import { If } from 'components';
|
||||
|
||||
import { dynamicColumns } from './utils';
|
||||
import { useCashFlowStatementContext } from './CashFlowStatementProvider';
|
||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||
|
||||
/**
|
||||
* Retrieve cash flow statement columns.
|
||||
*/
|
||||
export const useCashFlowStatementColumns = () => {
|
||||
const {
|
||||
cashFlowStatement: { columns, data },
|
||||
} = useCashFlowStatementContext();
|
||||
|
||||
return React.useMemo(() => dynamicColumns(columns, data), [columns, data]);
|
||||
};
|
||||
|
||||
/**
|
||||
* Cash flow statement loading bar.
|
||||
*/
|
||||
export function CashFlowStatementLoadingBar() {
|
||||
const { isCashFlowLoading } = useCashFlowStatementContext();
|
||||
return (
|
||||
<If condition={isCashFlowLoading}>
|
||||
<FinancialLoadingBar />
|
||||
</If>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import * as R from 'ramda';
|
||||
import { CellTextSpan } from 'components/Datatable/Cells';
|
||||
import { getColumnWidth } from 'utils';
|
||||
import { formatMessage } from 'services/intl';
|
||||
|
||||
/**
|
||||
* Account name column mapper.
|
||||
*/
|
||||
const accountNameMapper = (column) => ({
|
||||
id: column.key,
|
||||
key: column.key,
|
||||
Header: formatMessage({ id: 'account_name' }),
|
||||
accessor: 'cells[0].value',
|
||||
className: 'account_name',
|
||||
textOverview: true,
|
||||
width: 240,
|
||||
disableSortBy: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* Date range columns mapper.
|
||||
*/
|
||||
const dateRangeMapper = (data, index, column) => ({
|
||||
id: column.key,
|
||||
Header: column.label,
|
||||
key: column.key,
|
||||
accessor: `cells[${index}].value`,
|
||||
width: getColumnWidth(data, `cells.${index}.value`, { minWidth: 100 }),
|
||||
className: `date-period ${column.key}`,
|
||||
disableSortBy: true,
|
||||
});
|
||||
|
||||
/**
|
||||
* Total column mapper.
|
||||
*/
|
||||
const totalMapper = (data, index, column) => ({
|
||||
key: 'total',
|
||||
Header: formatMessage({ id: 'total' }),
|
||||
accessor: `cells[${index}].value`,
|
||||
className: 'total',
|
||||
textOverview: true,
|
||||
Cell: CellTextSpan,
|
||||
width: getColumnWidth(data, `cells[${index}].value`, { minWidth: 100 }),
|
||||
disableSortBy: true,
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Detarmines the given string starts with `date-range` string.
|
||||
*/
|
||||
const isMatchesDateRange = (r) => R.match(/^date-range/g, r).length > 0;
|
||||
|
||||
/**
|
||||
* Cash flow dynamic columns.
|
||||
*/
|
||||
export const dynamicColumns = (columns, data) => {
|
||||
const mapper = (column, index) => {
|
||||
return R.compose(
|
||||
R.when(
|
||||
R.pathSatisfies(isMatchesDateRange, ['key']),
|
||||
R.curry(dateRangeMapper)(data, index),
|
||||
),
|
||||
R.when(R.pathEq(['key'], 'name'), accountNameMapper),
|
||||
R.when(R.pathEq(['key'], 'total'), R.curry(totalMapper)(data, index)),
|
||||
)(column);
|
||||
};
|
||||
return columns.map(mapper);
|
||||
};
|
||||
@@ -0,0 +1,12 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { getCashFlowStatementFilterDrawer } from 'store/financialStatement/financialStatements.selectors';
|
||||
|
||||
export default (mapState) => {
|
||||
const mapStateToProps = (state, props) => {
|
||||
const mapped = {
|
||||
cashFlowStatementDrawerFilter: getCashFlowStatementFilterDrawer(state),
|
||||
};
|
||||
return mapState ? mapState(mapped, state, props) : mapped;
|
||||
};
|
||||
return connect(mapStateToProps);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
import { connect } from 'react-redux';
|
||||
import { toggleCashFlowStatementFilterDrawer } from 'store/financialStatement/financialStatements.actions';
|
||||
|
||||
const mapDispatchToProps = (dispatch) => ({
|
||||
toggleCashFlowStatementFilterDrawer: (toggle) =>
|
||||
dispatch(toggleCashFlowStatementFilterDrawer(toggle)),
|
||||
});
|
||||
|
||||
export default connect(null, mapDispatchToProps);
|
||||
Reference in New Issue
Block a user