From 3d78d2d051fe88f78934c122ff21ac0148cc4d59 Mon Sep 17 00:00:00 2001 From: "a.bouhuolia" Date: Sun, 30 Jan 2022 15:57:27 +0200 Subject: [PATCH] feat: integrate balance sheet and P&L sheet with new API. --- .../BalanceSheet/BalanceSheet.js | 26 +--- .../BalanceSheet/BalanceSheetBody.js | 30 ++++ .../BalanceSheet/BalanceSheetProvider.js | 1 - .../BalanceSheet/BalanceSheetTable.js | 9 +- .../BalanceSheet/components.js | 13 +- .../FinancialReportPage.js | 48 +++++- .../ProfitLossSheet/ProfitLossBody.js | 35 +++++ .../ProfitLossSheet/ProfitLossSheet.js | 27 +--- .../ProfitLossSheet/ProfitLossSheetHeader.js | 2 +- .../ProfitLossSheet/ProfitLossSheetTable.js | 8 +- .../FinancialStatements/reducers.js | 143 +----------------- src/hooks/query/financialReports.js | 30 +--- .../FinancialReportPage.scss | 31 +--- 13 files changed, 147 insertions(+), 256 deletions(-) create mode 100644 src/containers/FinancialStatements/BalanceSheet/BalanceSheetBody.js create mode 100644 src/containers/FinancialStatements/ProfitLossSheet/ProfitLossBody.js diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js index 84e91a083..b79940fb0 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js @@ -5,23 +5,21 @@ import { BalanceSheetAlerts, BalanceSheetLoadingBar } from './components'; import { FinancialStatement } from 'components'; import BalanceSheetHeader from './BalanceSheetHeader'; -import BalanceSheetTable from './BalanceSheetTable'; import DashboardPageContent from 'components/Dashboard/DashboardPageContent'; import BalanceSheetActionsBar from './BalanceSheetActionsBar'; import { BalanceSheetProvider } from './BalanceSheetProvider'; +import { BalanceSheetBody } from './BalanceSheetBody'; +import { FinancialReportBody } from '../FinancialReportPage'; import withBalanceSheetActions from './withBalanceSheetActions'; -import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization'; import { compose } from 'utils'; /** * Balance sheet. + * @returns {React.JSX} */ function BalanceSheet({ - // #withCurrentOrganization - organizationName, - // #withBalanceSheetActions toggleBalanceSheetFilterDrawer, }) { @@ -42,7 +40,6 @@ function BalanceSheet({ }; setFilter({ ..._filter }); }; - // Handle number format submit. const handleNumberFormatSubmit = (values) => { setFilter({ @@ -50,7 +47,6 @@ function BalanceSheet({ numberFormat: values, }); }; - // Hides the balance sheet filter drawer once the page unmount. useEffect( () => () => { @@ -66,6 +62,7 @@ function BalanceSheet({ onNumberFormatSubmit={handleNumberFormatSubmit} /> + {/* */} @@ -73,20 +70,13 @@ function BalanceSheet({ pageFilter={filter} onSubmitFilter={handleFilterSubmit} /> -
- -
+ + +
- - {/* */} ); } -export default compose( - withCurrentOrganization(({ organization }) => ({ - organizationName: organization.name, - })), - withBalanceSheetActions, -)(BalanceSheet); +export default compose(withBalanceSheetActions)(BalanceSheet); diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetBody.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetBody.js new file mode 100644 index 000000000..68214e408 --- /dev/null +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetBody.js @@ -0,0 +1,30 @@ +import React from 'react'; + +import BalanceSheetTable from './BalanceSheetTable'; +import withCurrentOrganization from '../../../containers/Organization/withCurrentOrganization'; +import { useBalanceSheetContext } from './BalanceSheetProvider'; + +import { compose } from 'utils'; + +/** + * Balance sheet body JSX. + * @returns {React.JSX} + */ +function BalanceSheetBodyJSX({ + // #withCurrentOrganization + organizationName, +}) { + const { isLoading } = useBalanceSheetContext(); + + return isLoading ? ( + 'loading' + ) : ( + + ); +} + +export const BalanceSheetBody = compose( + withCurrentOrganization(({ organization }) => ({ + organizationName: organization.name, + })), +)(BalanceSheetBodyJSX); diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetProvider.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetProvider.js index 087728cd1..3249e8bc5 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetProvider.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetProvider.js @@ -10,7 +10,6 @@ function BalanceSheetProvider({ filter, ...props }) { const query = React.useMemo(() => transformFilterFormToQuery(filter), [ filter, ]); - // Fetches the balance sheet report. const { data: balanceSheet, diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js index 242b29d8d..d73d14e06 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js @@ -36,14 +36,13 @@ export default function BalanceSheetTable({ name="balance-sheet" companyName={companyName} sheetType={intl.get('balance_sheet')} - // fromDate={query.from_date} - // toDate={query.to_date} - // basis={query.basis} - // loading={isLoading} + fromDate={query.from_date} + toDate={query.to_date} + basis={query.basis} > -
+ {' '} -
+ ); } @@ -57,7 +60,7 @@ export const useBalanceSheetColumns = () => { } = useBalanceSheetContext(); return React.useMemo( - () => dynamicColumns(table?.columns || [], table?.rows || []), + () => dynamicColumns(table.columns, table.rows), [table], ); }; diff --git a/src/containers/FinancialStatements/FinancialReportPage.js b/src/containers/FinancialStatements/FinancialReportPage.js index 8ffc610e1..d637f11ed 100644 --- a/src/containers/FinancialStatements/FinancialReportPage.js +++ b/src/containers/FinancialStatements/FinancialReportPage.js @@ -1,18 +1,60 @@ import React from 'react'; import classNames from 'classnames'; import { DashboardInsider } from 'components'; +import styled from 'styled-components'; import { CLASSES } from 'common/classes'; -import 'style/pages/FinancialStatements/FinancialReportPage.scss'; - /** * Financial report page. */ export default function FinancialReportPage(props) { return ( - ); } + +export const FinancialComputeAlert = styled.div` + position: relative; + padding: 8px 20px; + border-radius: 2px; + background-color: #fdecda; + color: #342515; + font-size: 13px; + + button { + font-size: 12px; + min-height: 16px; + padding: 0 4px; + + &, + &:hover { + color: #824400; + text-decoration: underline; + } + } + svg { + margin-right: 6px; + position: relative; + top: -2px; + fill: #975f19; + } +`; + +export const FinancialProgressbar = styled.div` + .progress-materializecss { + top: -2px; + } +`; + +export const FinancialReportPageRoot = styled(DashboardInsider)``; + +export const FinancialReportBody = styled.div` + padding-left: 15px; + padding-right: 15px; + display: flex; + justify-content: center; + align-items: center; +`; diff --git a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossBody.js b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossBody.js new file mode 100644 index 000000000..8a853e1c3 --- /dev/null +++ b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossBody.js @@ -0,0 +1,35 @@ +import React from 'react'; + +import ProfitLossSheetTable from './ProfitLossSheetTable'; +import { FinancialReportBody } from '../FinancialReportPage'; + +import withCurrentOrganization from '../../Organization/withCurrentOrganization'; +import { useProfitLossSheetContext } from './ProfitLossProvider'; + +import { compose } from 'utils'; + +/** + * @returns {React.JSX} + */ +function ProfitLossBodyJSX({ + // #withPreferences + organizationName, +}) { + const { isLoading } = useProfitLossSheetContext(); + + return ( + + {isLoading ? ( + 'loading' + ) : ( + + )} + + ); +} + +export const ProfitLossBody = compose( + withCurrentOrganization(({ organization }) => ({ + organizationName: organization.name, + })), +)(ProfitLossBodyJSX); diff --git a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheet.js b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheet.js index 70bbcb4cf..7a251da38 100644 --- a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheet.js +++ b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheet.js @@ -3,25 +3,21 @@ import moment from 'moment'; import { compose } from 'utils'; import ProfitLossSheetHeader from './ProfitLossSheetHeader'; -import ProfitLossSheetTable from './ProfitLossSheetTable'; import ProfitLossActionsBar from './ProfitLossActionsBar'; import DashboardPageContent from 'components/Dashboard/DashboardPageContent'; import withDashboardActions from 'containers/Dashboard/withDashboardActions'; import withProfitLossActions from './withProfitLossActions'; -import withCurrentOrganization from '../../Organization/withCurrentOrganization'; import { ProfitLossSheetProvider } from './ProfitLossProvider'; import { ProfitLossSheetLoadingBar, ProfitLossSheetAlerts } from './components'; +import { ProfitLossBody } from './ProfitLossBody'; /** * Profit/Loss financial statement sheet. */ function ProfitLossSheet({ - // #withPreferences - organizationName, - // #withProfitLossActions toggleProfitLossFilterDrawer: toggleDisplayFilterDrawer, }) { @@ -32,7 +28,6 @@ function ProfitLossSheet({ displayColumnsType: 'total', filterByOption: 'with-transactions', }); - // Handle submit filter. const handleSubmitFilter = (filter) => { const _filter = { @@ -42,7 +37,6 @@ function ProfitLossSheet({ }; setFilter(_filter); }; - // Handle number format submit. const handleNumberFormatSubmit = (numberFormat) => { setFilter({ @@ -64,19 +58,15 @@ function ProfitLossSheet({ numberFormat={filter.numberFormat} onNumberFormatSubmit={handleNumberFormatSubmit} /> - {/* */} + {/* */} -
- -
- -
-
+ +
); @@ -85,7 +75,4 @@ function ProfitLossSheet({ export default compose( withDashboardActions, withProfitLossActions, - withCurrentOrganization(({ organization }) => ({ - organizationName: organization.name, - })), )(ProfitLossSheet); diff --git a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js index 6f33077e2..1a958a447 100644 --- a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js +++ b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js @@ -1,4 +1,4 @@ -import React, { useEffect } from 'react'; +import React from 'react'; import moment from 'moment'; import { Formik, Form } from 'formik'; import { FormattedMessage as T } from 'components'; diff --git a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.js b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.js index 5b655ece2..501838dc7 100644 --- a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.js +++ b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetTable.js @@ -17,7 +17,7 @@ export default function ProfitLossSheetTable({ }) { // Profit/Loss sheet context. const { - profitLossSheet: { table }, + profitLossSheet: { table, query }, isLoading, } = useProfitLossSheetContext(); @@ -34,11 +34,11 @@ export default function ProfitLossSheetTable({ } - // fromDate={query.from_date} - // toDate={query.to_date} + fromDate={query.from_date} + toDate={query.to_date} name="profit-loss-sheet" loading={isLoading} - // basis={query.basis} + basis={query.basis} > { - return accounts.map((account) => { - return { - ...account, - children: balanceSheetRowsReducer([ - ...(account.children ? account.children : []), - ...(account.total && account.children && account.children.length > 0 - ? [ - { - name: intl.get('total_name', { name: account.name }), - row_types: ['total-row', account.section_type], - total: { ...account.total }, - ...(account.total_periods && { - total_periods: account.total_periods, - }), - }, - ] - : []), - ]), - }; - }); -}; - export const trialBalanceSheetReducer = (sheet) => { const results = []; @@ -44,124 +21,6 @@ export const trialBalanceSheetReducer = (sheet) => { return results; }; -export const profitLossSheetReducer = (profitLoss) => { - const results = []; - - if (profitLoss.income) { - results.push({ - name: , - total: profitLoss.income.total, - children: [ - ...profitLoss.income.accounts, - { - name: , - total: profitLoss.income.total, - total_periods: profitLoss.income.total_periods, - rowTypes: ['income_total', 'section_total', 'total'], - }, - ], - total_periods: profitLoss.income.total_periods, - }); - } - if (profitLoss.cost_of_sales) { - results.push({ - name: , - total: profitLoss.cost_of_sales.total, - children: [ - ...profitLoss.cost_of_sales.accounts, - { - name: , - total: profitLoss.cost_of_sales.total, - total_periods: profitLoss.cost_of_sales.total_periods, - rowTypes: ['cogs_total', 'section_total', 'total'], - }, - ], - total_periods: profitLoss.cost_of_sales.total_periods, - }); - } - if (profitLoss.gross_profit) { - results.push({ - name: , - total: profitLoss.gross_profit.total, - total_periods: profitLoss.gross_profit.total_periods, - rowTypes: ['gross_total', 'section_total', 'total'], - }); - } - if (profitLoss.expenses) { - results.push({ - name: , - total: profitLoss.expenses.total, - children: [ - ...profitLoss.expenses.accounts, - { - name: , - total: profitLoss.expenses.total, - total_periods: profitLoss.expenses.total_periods, - rowTypes: ['expenses_total', 'section_total', 'total'], - }, - ], - total_periods: profitLoss.expenses.total_periods, - }); - } - if (profitLoss.operating_profit) { - results.push({ - name: , - total: profitLoss.operating_profit.total, - total_periods: profitLoss.income.total_periods, - rowTypes: ['net_operating_total', 'section_total', 'total'], - }); - } - if (profitLoss.other_income) { - results.push({ - - name:, - total: profitLoss.other_income.total, - total_periods: profitLoss.other_income.total_periods, - children: [ - ...profitLoss.other_income.accounts, - { - name: , - total: profitLoss.other_income.total, - total_periods: profitLoss.other_income.total_periods, - rowTypes: ['expenses_total', 'section_total', 'total'], - }, - ], - }); - } - if (profitLoss.other_expenses) { - results.push({ - name: , - total: profitLoss.other_expenses.total, - total_periods: profitLoss.other_expenses.total_periods, - children: [ - ...profitLoss.other_expenses.accounts, - { - name: , - total: profitLoss.other_expenses.total, - total_periods: profitLoss.other_expenses.total_periods, - rowTypes: ['expenses_total', 'section_total', 'total'], - }, - ], - }); - } - if (profitLoss.net_other_income) { - results.push({ - name: , - total: profitLoss.net_other_income.total, - total_periods: profitLoss.net_other_income.total_periods, - rowTypes: ['net_other_income', 'section_total', 'total'], - }); - } - if (profitLoss.net_income) { - results.push({ - name: , - total: profitLoss.net_income.total, - total_periods: profitLoss.net_income.total_periods, - rowTypes: ['net_income_total', 'section_total', 'total'], - }); - } - return results; -}; export const journalTableRowsReducer = (journal) => { const TYPES = { diff --git a/src/hooks/query/financialReports.js b/src/hooks/query/financialReports.js index dce611916..018ab3d4f 100644 --- a/src/hooks/query/financialReports.js +++ b/src/hooks/query/financialReports.js @@ -1,8 +1,6 @@ import { useRequestQuery } from '../useQueryRequest'; import { trialBalanceSheetReducer, - balanceSheetRowsReducer, - profitLossSheetReducer, generalLedgerTableRowsReducer, journalTableRowsReducer, ARAgingSummaryTableRowsMapper, @@ -28,27 +26,9 @@ export function useBalanceSheet(query, props) { }, }, { - select: (res) => ({ - table: res.data.table - }), - defaultData: { - table: {}, - }, + select: (res) => res.data, ...props, }, - // { - // select: (res) => ({ - // tableRows: balanceSheetRowsReducer(res.data.data), - // ...res.data, - // }), - // defaultData: { - // data: [], - // columns: [], - // query: {}, - // tableRows: [], - // }, - // ...props, - // }, ); } @@ -62,7 +42,6 @@ export function useTrialBalanceSheet(query, props) { method: 'get', url: '/financial_statements/trial_balance_sheet', params: query, - }, { select: (res) => ({ @@ -94,12 +73,7 @@ export function useProfitLossSheet(query, props) { }, }, { - select: (res) => ({ - table: res.data.table - }), - defaultData: { - table: {}, - }, + select: (res) => res.data, ...props, }, ); diff --git a/src/style/pages/FinancialStatements/FinancialReportPage.scss b/src/style/pages/FinancialStatements/FinancialReportPage.scss index 213fcd485..686646f18 100644 --- a/src/style/pages/FinancialStatements/FinancialReportPage.scss +++ b/src/style/pages/FinancialStatements/FinancialReportPage.scss @@ -4,35 +4,8 @@ .dashboard__insider--financial-report{ .alert-compute-running{ - position: relative; - padding: 8px 20px; - border-radius: 2px; - background-color: #fdecda; - color: #342515; - font-size: 13px; - - button{ - font-size: 12px; - min-height: 16px; - padding: 0 4px; - - &, - &:hover{ - color: #824400; - text-decoration: underline; - } - } - svg{ - margin-right: 6px; - position: relative; - top: -2px; - fill: #975f19; - } + } - .financial-progressbar{ - .progress-materializecss{ - top: -2px; - } - } + } \ No newline at end of file