Skip to content

Commit

Permalink
formatting UI and filtering data
Browse files Browse the repository at this point in the history
  • Loading branch information
carkom committed Oct 21, 2023
1 parent b2d14d7 commit 318f016
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 8 deletions.
10 changes: 9 additions & 1 deletion packages/desktop-client/src/components/reports/ReportsTable.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';

import * as d from 'date-fns';
//import { useSelector } from 'react-redux';

import { amountToCurrency } from 'loot-core/src/shared/util';
Expand Down Expand Up @@ -65,7 +67,13 @@ export default function ReportsTable({
>
<Cell value={split} width="flex" />
{months.map(header => {
return <Cell key={header} value={header} width="flex" />;
return (
<Cell
key={header}
value={d.format(d.parseISO(`${header}-01`), 'MMMM yyyy')}
width="flex"
/>
);
})}
<Cell value={'Totals'} width="flex" />
</Row>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,14 @@ function BarGraph({
}
};

const getVal = obj => {
if (typeOp === 'totalDebts') {
return -1 * obj[typeOp];
} else {
return obj[typeOp];
}
};

return (
<Container
style={{
Expand Down Expand Up @@ -181,7 +189,7 @@ function BarGraph({
<CartesianGrid strokeDasharray="3 3" />
<XAxis dataKey={yAxis} />
<YAxis />
<Bar dataKey={...typeOp}>
<Bar dataKey={val => getVal(val)}>
{data.data
.filter(i => (empty ? i[typeOp] !== 0 : true))
.map((entry, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,14 @@ export default function createSpreadsheet(
[conditionsOpKey]: filters,
[splitLabel]: splt.id,
'account.offbudget': false,
'category.hidden': false,
date: { $lt: start + '-01' },
$or: [
{
'payee.transfer_acct.offbudget': true,
'payee.transfer_acct': null,
},
],
})
.calculate({ $sum: '$amount' }),
).then(({ data }) => data),
Expand All @@ -90,10 +97,17 @@ export default function createSpreadsheet(
.filter({
[splitLabel]: splt.id,
'account.offbudget': false,
'category.hidden': false,
$and: [
{ date: { $gte: start + '-01' } },
{ date: { $lte: end + '-31' } },
],
$or: [
{
'payee.transfer_acct.offbudget': true,
'payee.transfer_acct': null,
},
],
})
.groupBy({ $month: '$date' })
.select([
Expand All @@ -106,6 +120,7 @@ export default function createSpreadsheet(
return {
id: splt.id,
name: splt.name,
hidden: splt.hidden,
balances: index(balances, 'date'),
starting,
};
Expand All @@ -120,16 +135,19 @@ export default function createSpreadsheet(
months.map(async month => {
let groupedAmount = 0;
graphData.map(async graph => {
if (graph.balances[month]) {
if (group.categories.map(v => v.id).includes(graph.id)) {
groupedAmount += graph.balances[month].amount;
if (graph.hidden === 0 && group.hidden === 0) {
if (graph.balances[month]) {
if (group.categories.map(v => v.id).includes(graph.id)) {
groupedAmount += graph.balances[month].amount;
}
}
}

groupedStarting += graph.starting;
});
return {
date: month,
dateFormatted: d.format(d.parseISO(`${month}-01`), 'MMMM yyyy'),
amount: groupedAmount,
};
}),
Expand Down Expand Up @@ -183,10 +201,10 @@ export default function createSpreadsheet(
totalDebts += perMonthDebts;
totalTotals += perMonthTotals;

const test = index(stacked, 'name');
const indexedSplit = index(stacked, 'name');
return {
date: month,
...test,
date: d.format(d.parseISO(`${month}-01`), 'MMMM yyyy'),
...indexedSplit,
totalDebts: -1 * integerToAmount(perMonthDebts),
totalAssets: integerToAmount(perMonthAssets),
totalTotals:
Expand Down

0 comments on commit 318f016

Please sign in to comment.