mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-19 14:20:31 +00:00
refactor(GeneralLedger)
This commit is contained in:
@@ -25,9 +25,6 @@ import { getDefaultGeneralLedgerQuery } from './common';
|
|||||||
function GeneralLedger({
|
function GeneralLedger({
|
||||||
// #withGeneralLedgerActions
|
// #withGeneralLedgerActions
|
||||||
toggleGeneralLedgerFilterDrawer,
|
toggleGeneralLedgerFilterDrawer,
|
||||||
|
|
||||||
// #withSettings
|
|
||||||
organizationName,
|
|
||||||
}) {
|
}) {
|
||||||
const [filter, setFilter] = useState({
|
const [filter, setFilter] = useState({
|
||||||
...getDefaultGeneralLedgerQuery(),
|
...getDefaultGeneralLedgerQuery(),
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import React, { useMemo } from 'react';
|
import React, { useMemo } from 'react';
|
||||||
|
|
||||||
import { defaultExpanderReducer } from 'utils';
|
|
||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
|
import styled from 'styled-components';
|
||||||
|
|
||||||
import { FinancialSheet } from 'components';
|
import { defaultExpanderReducer, tableRowTypesToClassnames } from 'utils';
|
||||||
import DataTable from 'components/DataTable';
|
|
||||||
|
import { FinancialSheet, DataTable } from 'components';
|
||||||
import TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows';
|
import TableVirtualizedListRows from 'components/Datatable/TableVirtualizedRows';
|
||||||
import TableFastCell from 'components/Datatable/TableFastCell';
|
import TableFastCell from 'components/Datatable/TableFastCell';
|
||||||
|
|
||||||
@@ -27,11 +27,10 @@ export default function GeneralLedgerTable({ companyName }) {
|
|||||||
const columns = useGeneralLedgerTableColumns();
|
const columns = useGeneralLedgerTableColumns();
|
||||||
|
|
||||||
// Default expanded rows of general ledger table.
|
// Default expanded rows of general ledger table.
|
||||||
const expandedRows = useMemo(() => defaultExpanderReducer(tableRows, 1), [
|
const expandedRows = useMemo(
|
||||||
tableRows,
|
() => defaultExpanderReducer(tableRows, 1),
|
||||||
]);
|
[tableRows],
|
||||||
|
);
|
||||||
const rowClassNames = (row) => [`row-type--${row.original.rowType}`];
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FinancialSheet
|
<FinancialSheet
|
||||||
@@ -42,11 +41,13 @@ export default function GeneralLedgerTable({ companyName }) {
|
|||||||
loading={isLoading}
|
loading={isLoading}
|
||||||
fullWidth={true}
|
fullWidth={true}
|
||||||
>
|
>
|
||||||
<DataTable
|
<GeneralLedgerDataTable
|
||||||
noResults={intl.get('this_report_does_not_contain_any_data_between_date_period')}
|
noResults={intl.get(
|
||||||
|
'this_report_does_not_contain_any_data_between_date_period',
|
||||||
|
)}
|
||||||
columns={columns}
|
columns={columns}
|
||||||
data={tableRows}
|
data={tableRows}
|
||||||
rowClassNames={rowClassNames}
|
rowClassNames={tableRowTypesToClassnames}
|
||||||
expanded={expandedRows}
|
expanded={expandedRows}
|
||||||
virtualizedRows={true}
|
virtualizedRows={true}
|
||||||
fixedItemSize={30}
|
fixedItemSize={30}
|
||||||
@@ -55,14 +56,64 @@ export default function GeneralLedgerTable({ companyName }) {
|
|||||||
expandToggleColumn={1}
|
expandToggleColumn={1}
|
||||||
sticky={true}
|
sticky={true}
|
||||||
TableRowsRenderer={TableVirtualizedListRows}
|
TableRowsRenderer={TableVirtualizedListRows}
|
||||||
|
|
||||||
// #TableVirtualizedListRows props.
|
// #TableVirtualizedListRows props.
|
||||||
vListrowHeight={28}
|
vListrowHeight={28}
|
||||||
vListOverscanRowCount={0}
|
vListOverscanRowCount={0}
|
||||||
TableCellRenderer={TableFastCell}
|
TableCellRenderer={TableFastCell}
|
||||||
|
|
||||||
styleName={TableStyle.Constrant}
|
styleName={TableStyle.Constrant}
|
||||||
/>
|
/>
|
||||||
</FinancialSheet>
|
</FinancialSheet>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const GeneralLedgerDataTable = styled(DataTable)`
|
||||||
|
.tbody {
|
||||||
|
.tr .td {
|
||||||
|
padding-top: 0.2rem;
|
||||||
|
padding-bottom: 0.2rem;
|
||||||
|
}
|
||||||
|
.tr.is-expanded {
|
||||||
|
.td:not(.date) .cell-inner {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.tr:not(.no-results) .td {
|
||||||
|
border-left: 1px solid #ececec;
|
||||||
|
}
|
||||||
|
.tr:last-child .td {
|
||||||
|
border-bottom: 1px solid #ececec;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tr.row_type {
|
||||||
|
&--ACCOUNT_ROW {
|
||||||
|
.td {
|
||||||
|
&.date {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
|
||||||
|
&.name {
|
||||||
|
border-left-color: transparent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&:not(:first-child).is-expanded .td {
|
||||||
|
border-top: 1px solid #ddd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--OPENING_BALANCE,
|
||||||
|
&--CLOSING_BALANCE {
|
||||||
|
.amount {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
&--CLOSING_BALANCE {
|
||||||
|
.name {
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|||||||
@@ -2,12 +2,14 @@ import React from 'react';
|
|||||||
import intl from 'react-intl-universal';
|
import intl from 'react-intl-universal';
|
||||||
import { Button } from '@blueprintjs/core';
|
import { Button } from '@blueprintjs/core';
|
||||||
import { Icon, If } from 'components';
|
import { Icon, If } from 'components';
|
||||||
import { FormattedMessage as T } from 'components';
|
import { ForceWidth, FormattedMessage as T } from 'components';
|
||||||
|
|
||||||
import { getForceWidth, getColumnWidth } from 'utils';
|
import { getColumnWidth } from 'utils';
|
||||||
import { useGeneralLedgerContext } from './GeneralLedgerProvider';
|
import { useGeneralLedgerContext } from './GeneralLedgerProvider';
|
||||||
import FinancialLoadingBar from '../FinancialLoadingBar';
|
import FinancialLoadingBar from '../FinancialLoadingBar';
|
||||||
|
|
||||||
|
import { Align } from 'common';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the general ledger table columns.
|
* Retrieve the general ledger table columns.
|
||||||
*/
|
*/
|
||||||
@@ -23,19 +25,11 @@ export function useGeneralLedgerTableColumns() {
|
|||||||
Header: intl.get('date'),
|
Header: intl.get('date'),
|
||||||
accessor: (row) => {
|
accessor: (row) => {
|
||||||
if (row.rowType === 'ACCOUNT_ROW') {
|
if (row.rowType === 'ACCOUNT_ROW') {
|
||||||
return (
|
return <ForceWidth children={row.date} />;
|
||||||
<span
|
|
||||||
className={'force-width'}
|
|
||||||
style={{ minWidth: getForceWidth(row.date) }}
|
|
||||||
>
|
|
||||||
{row.date}
|
|
||||||
</span>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
return row.date;
|
return row.date;
|
||||||
},
|
},
|
||||||
className: 'date',
|
className: 'date',
|
||||||
// textOverview: true,
|
|
||||||
width: 120,
|
width: 120,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -73,6 +67,7 @@ export function useGeneralLedgerTableColumns() {
|
|||||||
magicSpacing: 10,
|
magicSpacing: 10,
|
||||||
}),
|
}),
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('debit'),
|
Header: intl.get('debit'),
|
||||||
@@ -83,6 +78,7 @@ export function useGeneralLedgerTableColumns() {
|
|||||||
magicSpacing: 10,
|
magicSpacing: 10,
|
||||||
}),
|
}),
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('amount'),
|
Header: intl.get('amount'),
|
||||||
@@ -93,6 +89,7 @@ export function useGeneralLedgerTableColumns() {
|
|||||||
magicSpacing: 10,
|
magicSpacing: 10,
|
||||||
}),
|
}),
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Header: intl.get('running_balance'),
|
Header: intl.get('running_balance'),
|
||||||
@@ -103,6 +100,7 @@ export function useGeneralLedgerTableColumns() {
|
|||||||
magicSpacing: 10,
|
magicSpacing: 10,
|
||||||
}),
|
}),
|
||||||
textOverview: true,
|
textOverview: true,
|
||||||
|
align: Align.Right,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
[tableRows],
|
[tableRows],
|
||||||
|
|||||||
@@ -73,13 +73,13 @@ export const generalLedgerTableRowsReducer = (accounts) => {
|
|||||||
return {
|
return {
|
||||||
name: '',
|
name: '',
|
||||||
code: account.code,
|
code: account.code,
|
||||||
rowType: 'ACCOUNT_ROW',
|
row_types: 'ACCOUNT_ROW',
|
||||||
date: account.name,
|
date: account.name,
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
...account.opening_balance,
|
...account.opening_balance,
|
||||||
name: <T id={'opening_balance'} />,
|
name: <T id={'opening_balance'} />,
|
||||||
rowType: 'OPENING_BALANCE',
|
row_types: 'OPENING_BALANCE',
|
||||||
date: moment(account.opening_balance.date).format('DD MMM YYYY'),
|
date: moment(account.opening_balance.date).format('DD MMM YYYY'),
|
||||||
},
|
},
|
||||||
...account.transactions.map((transaction) => ({
|
...account.transactions.map((transaction) => ({
|
||||||
@@ -91,7 +91,7 @@ export const generalLedgerTableRowsReducer = (accounts) => {
|
|||||||
{
|
{
|
||||||
...account.closing_balance,
|
...account.closing_balance,
|
||||||
name: <T id={'closing_balance'} />,
|
name: <T id={'closing_balance'} />,
|
||||||
rowType: 'CLOSING_BALANCE',
|
row_types: 'CLOSING_BALANCE',
|
||||||
date: moment(account.closing_balance.date).format('DD MMM YYYY'),
|
date: moment(account.closing_balance.date).format('DD MMM YYYY'),
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -1,93 +0,0 @@
|
|||||||
.financial-sheet {
|
|
||||||
&--general-ledger {
|
|
||||||
.financial-sheet__table {
|
|
||||||
|
|
||||||
.tbody,
|
|
||||||
.thead {
|
|
||||||
|
|
||||||
.tr .td,
|
|
||||||
.tr .th {
|
|
||||||
|
|
||||||
&.credit,
|
|
||||||
&.debit,
|
|
||||||
&.running_balance,
|
|
||||||
&.amount {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tbody {
|
|
||||||
.tr .td {
|
|
||||||
padding-top: 0.2rem;
|
|
||||||
padding-bottom: 0.2rem;
|
|
||||||
border-top-color: transparent;
|
|
||||||
border-bottom-color: transparent;
|
|
||||||
|
|
||||||
&.date {
|
|
||||||
>div {
|
|
||||||
display: flex;
|
|
||||||
}
|
|
||||||
|
|
||||||
span.force-width {
|
|
||||||
position: relative;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tr:not(.no-results) .td {
|
|
||||||
border-left: 1px solid #ececec;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tr:last-child .td {
|
|
||||||
border-bottom: 1px solid #ececec;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tr {
|
|
||||||
&.is-expanded {
|
|
||||||
|
|
||||||
.td.amount {
|
|
||||||
|
|
||||||
.cell-inner {
|
|
||||||
display: none
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.tr.row-type {
|
|
||||||
|
|
||||||
|
|
||||||
&--ACCOUNT_ROW {
|
|
||||||
.td {
|
|
||||||
&.date {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
|
|
||||||
&.name {
|
|
||||||
border-left-color: transparent;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&:not(:first-child).is-expanded .td {
|
|
||||||
border-top: 1px solid #DDD;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&--OPENING_BALANCE,
|
|
||||||
&--CLOSING_BALANCE {
|
|
||||||
.amount {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
&--CLOSING_BALANCE {
|
|
||||||
.name {
|
|
||||||
font-weight: 500;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,32 +0,0 @@
|
|||||||
|
|
||||||
.financial-sheet{
|
|
||||||
|
|
||||||
&--trial-balance{
|
|
||||||
min-width: 720px;
|
|
||||||
|
|
||||||
.financial-sheet__table{
|
|
||||||
.thead,
|
|
||||||
.tbody{
|
|
||||||
.tr .td:not(:first-child),
|
|
||||||
.tr .th:not(:first-child) {
|
|
||||||
text-align: right;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.tbody{
|
|
||||||
.tr .td{
|
|
||||||
border-bottom: 0;
|
|
||||||
padding-top: 0.4rem;
|
|
||||||
padding-bottom: 0.4rem;
|
|
||||||
}
|
|
||||||
.balance.td{
|
|
||||||
border-top-color: #000;
|
|
||||||
}
|
|
||||||
.tr.row_type--total .td{
|
|
||||||
border-top: 1px solid #bbb;
|
|
||||||
font-weight: 500;
|
|
||||||
border-bottom: 3px double #000;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user