From 7a0d5063950fafdd9a06c33bfda6ff3bb87f93f0 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 13 Jan 2022 15:25:04 +0200 Subject: [PATCH 01/72] feat: balance sheet comparison --- .../BalanceSheet/BalanceSheet.js | 2 +- .../BalanceSheet/BalanceSheetHeader.js | 8 +- .../BalanceSheetHeaderComparisonPanal.js | 142 ++++++++++++++++++ .../BalanceSheet/BalanceSheetTable.js | 113 +++++++------- .../BalanceSheet/components.js | 15 ++ .../FinancialStatements/BalanceSheet/utils.js | 84 +++++++++++ src/hooks/query/financialReports.js | 28 +++- src/lang/en/index.json | 10 +- 8 files changed, 331 insertions(+), 71 deletions(-) create mode 100644 src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js index 9d3b47c6f..861a10cb7 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheet.js @@ -80,7 +80,7 @@ function BalanceSheet({ - + {/* */} ); } diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js index 6fefd517b..5c713bff0 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js @@ -8,6 +8,7 @@ import withBalanceSheet from './withBalanceSheet'; import withBalanceSheetActions from './withBalanceSheetActions'; import BalanceSheetHeaderGeneralPanal from './BalanceSheetHeaderGeneralPanal'; +import BalanceSheetHeaderComparisonPanal from './BalanceSheetHeaderComparisonPanal'; import FinancialStatementHeader from '../../FinancialStatements/FinancialStatementHeader'; import { compose, transformToForm } from 'utils'; @@ -75,10 +76,15 @@ function BalanceSheetHeader({ >
- } panel={} + /> */} + } + panel={} /> diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js new file mode 100644 index 000000000..51e0f563f --- /dev/null +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js @@ -0,0 +1,142 @@ +import React from 'react'; +import { FastField, Field } from 'formik'; +import { FormGroup, Checkbox } from '@blueprintjs/core'; +import styled from 'styled-components'; + +import { FormattedMessage as T } from 'components'; + +import { Row, Col, FieldHint } from '../../../components'; + +/** + * Balance sheet header - Comparison panal. + */ +export default function BalanceSheetHeaderComparisonPanal() { + return ( +
+ {/*------------ Percentage -----------*/} + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + {/*------------ Previous Year -----------*/} + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + {/*------------ Previous Period -----------*/} + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + + + {({ field }) => ( + }> + } + {...field} + /> + + )} + + + +
+ ); +} diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js index 38aa54e26..69cc36e45 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetTable.js @@ -9,6 +9,8 @@ import { useBalanceSheetContext } from './BalanceSheetProvider'; import { defaultExpanderReducer, getColumnWidth } from 'utils'; +import { useBalanceSheetColumns } from './components'; + /** * Balance sheet table. */ @@ -16,90 +18,77 @@ export default function BalanceSheetTable({ // #ownProps companyName, }) { - - // Balance sheet context. const { balanceSheet: { tableRows, columns, query }, isLoading, } = useBalanceSheetContext(); - const tableColumns = useMemo( - () => [ - { - Header: intl.get('account_name'), - accessor: (row) => (row.code ? `${row.name} - ${row.code}` : row.name), - className: 'account_name', - textOverview: true, - width: 240, - }, - ...(query.display_columns_type === 'total' - ? [ - { - Header: intl.get('total'), - accessor: 'total.formatted_amount', - Cell: CellTextSpan, - className: 'total', - width: 140, - }, - ] - : []), - ...(query.display_columns_type === 'date_periods' - ? columns.map((column, index) => ({ - id: `date_period_${index}`, - Header: column, - Cell: CellTextSpan, - accessor: `total_periods[${index}].formatted_amount`, - className: classNames('total-period', `total-periods-${index}`), - width: getColumnWidth( - tableRows, - `total_periods.${index}.formatted_amount`, - { minWidth: 100 }, - ), - })) - : []), - ], - [query, columns, tableRows], - ); + const tableColumns = useBalanceSheetColumns(); + + // const tableColumns = useMemo( + // () => [ + // { + // Header: intl.get('account_name'), + // accessor: (row) => (row.code ? `${row.name} - ${row.code}` : row.name), + // className: 'account_name', + // textOverview: true, + // width: 240, + // }, + // ...(query.display_columns_type === 'total' + // ? [ + // { + // Header: intl.get('total'), + // accessor: 'total.formatted_amount', + // Cell: CellTextSpan, + // className: 'total', + // width: 140, + // }, + // ] + // : []), + // ...(query.display_columns_type === 'date_periods' + // ? columns.map((column, index) => ({ + // id: `date_period_${index}`, + // Header: column, + // Cell: CellTextSpan, + // accessor: `total_periods[${index}].formatted_amount`, + // className: classNames('total-period', `total-periods-${index}`), + // width: getColumnWidth( + // tableRows, + // `total_periods.${index}.formatted_amount`, + // { minWidth: 100 }, + // ), + // })) + // : []), + // ], + // [query, columns, tableRows], + // ); // Calculates the default expanded rows of balance sheet table. - const expandedRows = useMemo(() => defaultExpanderReducer(tableRows, 4), [tableRows]); - - const rowClassNames = useCallback((row) => { - const { original } = row; - const rowTypes = Array.isArray(original.row_types) - ? original.row_types - : [original.row_types]; - - return { - ...rowTypes.reduce((acc, rowType) => { - acc[`row_type--${rowType}`] = rowType; - return acc; - }, {}), - }; - }, []); + // const expandedRows = useMemo(() => { + // return defaultExpanderReducer(tableRows, 4); + // }, [tableRows]); return ( ); diff --git a/src/containers/FinancialStatements/BalanceSheet/components.js b/src/containers/FinancialStatements/BalanceSheet/components.js index be3962ed9..fcd22362c 100644 --- a/src/containers/FinancialStatements/BalanceSheet/components.js +++ b/src/containers/FinancialStatements/BalanceSheet/components.js @@ -4,6 +4,7 @@ import { Icon, If } from 'components'; import { useBalanceSheetContext } from './BalanceSheetProvider'; import { FormattedMessage as T } from 'components'; import FinancialLoadingBar from '../FinancialLoadingBar'; +import { dynamicColumns } from './utils'; /** * Balance sheet alerts. @@ -46,3 +47,17 @@ export function BalanceSheetLoadingBar() { ); } + +/** + * Retrieve balance sheet columns. + */ +export const useBalanceSheetColumns = () => { + const { + balanceSheet: { columns, tableRows }, + } = useBalanceSheetContext(); + + return React.useMemo( + () => dynamicColumns(columns, tableRows), + [columns, tableRows], + ); +}; diff --git a/src/containers/FinancialStatements/BalanceSheet/utils.js b/src/containers/FinancialStatements/BalanceSheet/utils.js index 0a5301b23..1a4367589 100644 --- a/src/containers/FinancialStatements/BalanceSheet/utils.js +++ b/src/containers/FinancialStatements/BalanceSheet/utils.js @@ -1,6 +1,9 @@ import * as Yup from 'yup'; +import * as R from 'ramda'; import intl from 'react-intl-universal'; import moment from 'moment'; +import { CellTextSpan } from 'components/Datatable/Cells'; +import { getColumnWidth } from 'utils'; export const getBalanceSheetHeaderDefaultValues = () => { return { @@ -23,3 +26,84 @@ export const getBalanceSheetHeaderValidationSchema = () => filterByOption: Yup.string(), displayColumnsType: Yup.string(), }); + +/** + * Account name column mapper. + */ +const accountNameMapper = (data, index, column) => { + return { + id: column.key, + key: column.key, + Header: column.label, + accessor: `cells[${index}].value`, + className: column.key, + textOverview: true, + Cell: CellTextSpan, + width: getColumnWidth(data, `cells[${index}].value`, { + magicSpacing: 10, + minWidth: 240, + }), + }; +}; + +/** + * 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`, { + magicSpacing: 10, + minWidth: 100, + }), + className: `date-period ${column.key}`, + disableSortBy: true, + textOverview: true, +}); + +/** + * Total column mapper. + */ +const totalMapper = (data, index, column) => { + return { + id: column.key, + key: column.key, + Header: column.label, + accessor: `cells[${index}].value`, + className: 'total', + textOverview: true, + Cell: CellTextSpan, + width: getColumnWidth(data, `cells[${index}].value`, { + magicSpacing: 10, + minWidth: 200, + }), + 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'), + R.curry(accountNameMapper)(data, index), + ), + R.when(R.pathEq(['key'], 'total'), R.curry(totalMapper)(data, index)), + )(column); + }; + return columns.map(mapper); +}; diff --git a/src/hooks/query/financialReports.js b/src/hooks/query/financialReports.js index 57023381a..12ac238bd 100644 --- a/src/hooks/query/financialReports.js +++ b/src/hooks/query/financialReports.js @@ -23,20 +23,38 @@ export function useBalanceSheet(query, props) { method: 'get', url: '/financial_statements/balance_sheet', params: query, + headers: { + Accept: 'application/json+table', + }, }, { select: (res) => ({ - tableRows: balanceSheetRowsReducer(res.data.data), - ...res.data, + columns: res.data.table.columns, + tableRows: res.data.table.rows, + // query: res.data.query, + // meta: res.data.meta, }), defaultData: { - data: [], - columns: [], - query: {}, tableRows: [], + columns: [], + // query: {}, + // meta: {}, }, ...props, }, + // { + // select: (res) => ({ + // tableRows: balanceSheetRowsReducer(res.data.data), + // ...res.data, + // }), + // defaultData: { + // data: [], + // columns: [], + // query: {}, + // tableRows: [], + // }, + // ...props, + // }, ); } diff --git a/src/lang/en/index.json b/src/lang/en/index.json index 51cc47d1d..71bc2f1f3 100644 --- a/src/lang/en/index.json +++ b/src/lang/en/index.json @@ -1734,8 +1734,14 @@ "payment_made.drawer.title": "Payment made details {number}", "manual_journal.drawer.title": "Manual journal details ({number})", "expense.drawer.title": "Expense details", - "global_error.you_dont_have_permissions": "You do not have permissions to access this page.", "global_error.transactions_locked": "Transactions before {lockedToDate} has been locked. Hence action cannot be performed.", - "global_error.authorized_user_inactive": "The authorized user is inactive." + "global_error.authorized_user_inactive": "The authorized user is inactive.", + "balance_sheet.comparisons": "Comparisons", + "balance_sheet.percentage_of_column": "% of Columns", + "balance_sheet.percentage_of_row": "% of Rows", + "balance_sheet.previous_year": "Previous Year (PY)", + "balance_sheet.total_change": "Total Change", + "balance_sheet.change": "% Change", + "balance_sheet.previous_period": "Previous Period (PP)" } \ No newline at end of file From 85a78b3809d90af06902cdeb866cb6df98ee0ea1 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 13 Jan 2022 16:25:46 +0200 Subject: [PATCH 02/72] feat: style balance sheet comparison. --- .../BalanceSheetHeaderComparisonPanal.js | 22 +++++++++++++++++-- .../FinancialStatements/BalanceSheet.scss | 4 ++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js index 51e0f563f..ee3fbb152 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeaderComparisonPanal.js @@ -12,7 +12,7 @@ import { Row, Col, FieldHint } from '../../../components'; */ export default function BalanceSheetHeaderComparisonPanal() { return ( -
+ {/*------------ Percentage -----------*/} @@ -137,6 +137,24 @@ export default function BalanceSheetHeaderComparisonPanal() { -
+ ); } + +const BalanceSheetComparisonWrap = styled.div` + .row { + display: flex; + flex-wrap: nowrap; + margin-left: -0.3rem; + margin-right: -0.3rem; + + .col { + padding-left: 0.3rem; + padding-right: 0.3rem; + + .bp3-form-group { + margin-bottom: 0; + } + } + } +`; diff --git a/src/style/pages/FinancialStatements/BalanceSheet.scss b/src/style/pages/FinancialStatements/BalanceSheet.scss index 90b59ca54..eea6edd57 100644 --- a/src/style/pages/FinancialStatements/BalanceSheet.scss +++ b/src/style/pages/FinancialStatements/BalanceSheet.scss @@ -6,8 +6,8 @@ .thead, .tbody{ - .tr .td.account_name ~ .td, - .tr .th.account_name ~ .th{ + .tr .td.name ~ .td, + .tr .th.name ~ .th{ text-align: right; } } From 225619be601498efe04d64f3ac3b827594156ee8 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Thu, 13 Jan 2022 16:33:32 +0200 Subject: [PATCH 03/72] fix(balanceSheet) balance sheet header. --- .../FinancialStatements/BalanceSheet/BalanceSheetHeader.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js index 5c713bff0..0a2c51006 100644 --- a/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js +++ b/src/containers/FinancialStatements/BalanceSheet/BalanceSheetHeader.js @@ -76,11 +76,11 @@ function BalanceSheetHeader({ > - {/* } panel={} - /> */} + /> } From 354d1e8f75b96d63c2a65d19faafb08199dd58e4 Mon Sep 17 00:00:00 2001 From: elforjani13 <39470382+elforjani13@users.noreply.github.com> Date: Mon, 24 Jan 2022 13:55:44 +0200 Subject: [PATCH 04/72] feat(P&L Comparisons): add P&L comparisons. --- .../ProfitLossSheet/ProfitLossSheetHeader.js | 6 + .../ProfitLossSheetHeaderComparisonPanel.js | 170 ++++++++++++++++++ src/lang/en/index.json | 11 +- 3 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeaderComparisonPanel.js diff --git a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js index 5e6ef56e1..6f33077e2 100644 --- a/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js +++ b/src/containers/FinancialStatements/ProfitLossSheet/ProfitLossSheetHeader.js @@ -8,6 +8,7 @@ import { Tabs, Tab, Button, Intent } from '@blueprintjs/core'; import FinancialStatementHeader from 'containers/FinancialStatements/FinancialStatementHeader'; import ProfitLossSheetHeaderGeneralPane from './ProfitLossSheetHeaderGeneralPane'; +import ProfitLossSheetHeaderComparisonPanel from './ProfitLossSheetHeaderComparisonPanel'; import withProfitLoss from './withProfitLoss'; import withProfitLossActions from './withProfitLossActions'; @@ -75,6 +76,11 @@ function ProfitLossHeader({ title={} panel={} /> + } + panel={} + />