Skip to content

Commit

Permalink
Custom Reports: Adjust Net values (#2871)
Browse files Browse the repository at this point in the history
* Add Net value

* notes

* fix

* revert changes

* balanceTypeOpType

* lint fix

* add net numbers

* bar fix

* nit fixes and fix clicks

* remove abs
  • Loading branch information
carkom authored Jun 24, 2024
1 parent 46ea8fb commit 3332f58
Show file tree
Hide file tree
Showing 22 changed files with 210 additions and 52 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ const balanceTypeOptions = [
{ description: 'Payment', format: 'totalDebts' as const },
{ description: 'Deposit', format: 'totalAssets' as const },
{ description: 'Net', format: 'totalTotals' as const },
{ description: 'Net Payment', format: 'netDebts' as const },
{ description: 'Net Deposit', format: 'netAssets' as const },
];

const groupByOptions = [
Expand Down
17 changes: 12 additions & 5 deletions packages/desktop-client/src/components/reports/ReportSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import {
integerToCurrency,
amountToInteger,
} from 'loot-core/src/shared/util';
import { type DataEntity } from 'loot-core/src/types/models/reports';
import {
type balanceTypeOpType,
type DataEntity,
} from 'loot-core/src/types/models/reports';

import { theme, styles } from '../../style';
import { Text } from '../common/Text';
Expand All @@ -19,7 +22,7 @@ type ReportSummaryProps = {
startDate: string;
endDate: string;
data: DataEntity;
balanceTypeOp: 'totalDebts' | 'totalAssets' | 'totalTotals';
balanceTypeOp: balanceTypeOpType;
interval: string;
intervalsCount: number;
};
Expand All @@ -33,9 +36,13 @@ export function ReportSummary({
intervalsCount,
}: ReportSummaryProps) {
const net =
Math.abs(data.totalDebts) > Math.abs(data.totalAssets)
? 'PAYMENT'
: 'DEPOSIT';
balanceTypeOp === 'netAssets'
? 'DEPOSIT'
: balanceTypeOp === 'netDebts'
? 'PAYMENT'
: Math.abs(data.totalDebts) > Math.abs(data.totalAssets)
? 'PAYMENT'
: 'DEPOSIT';
const average = amountToInteger(data[balanceTypeOp]) / intervalsCount;
return (
<View
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const totalGraphOptions: graphOptions[] = [
description: 'BarGraph',
disabledSplit: [],
defaultSplit: 'Category',
disabledType: ['Net'],
disabledType: [],
defaultType: 'Payment',
},
{
Expand All @@ -88,7 +88,7 @@ const timeGraphOptions: graphOptions[] = [
description: 'TableGraph',
disabledSplit: ['Interval'],
defaultSplit: 'Category',
disabledType: [],
disabledType: ['Net Payment', 'Net Deposit'],
defaultType: 'Payment',
disableLegend: true,
disableLabel: true,
Expand All @@ -97,14 +97,14 @@ const timeGraphOptions: graphOptions[] = [
description: 'StackedBarGraph',
disabledSplit: ['Interval'],
defaultSplit: 'Category',
disabledType: ['Net'],
disabledType: [],
defaultType: 'Payment',
},
{
description: 'LineGraph',
disabledSplit: ['Interval'],
defaultSplit: 'Category',
disabledType: ['Net'],
disabledType: [],
defaultType: 'Payment',
disableLegend: false,
disableLabel: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
amountToCurrency,
amountToCurrencyNoDecimal,
} from 'loot-core/src/shared/util';
import { type DataEntity } from 'loot-core/src/types/models/reports';
import {
type balanceTypeOpType,
type DataEntity,
} from 'loot-core/src/types/models/reports';

import { usePrivacyMode } from '../../../hooks/usePrivacyMode';
import { useResponsive } from '../../../ResponsiveProvider';
Expand All @@ -33,14 +36,16 @@ type PayloadItem = {
date: string;
totalAssets: number | string;
totalDebts: number | string;
netAssets: number | string;
netDebts: number | string;
totalTotals: number | string;
};
};

type CustomTooltipProps = {
active?: boolean;
payload?: PayloadItem[];
balanceTypeOp: 'totalAssets' | 'totalTotals' | 'totalDebts';
balanceTypeOp: balanceTypeOpType;
};

const CustomTooltip = ({
Expand Down Expand Up @@ -74,10 +79,22 @@ const CustomTooltip = ({
)}
{['totalDebts', 'totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left="Debt:"
left="Debts:"
right={amountToCurrency(payload[0].payload.totalDebts)}
/>
)}
{['netAssets'].includes(balanceTypeOp) && (
<AlignedText
left="Net Assets:"
right={amountToCurrency(payload[0].payload.netAssets)}
/>
)}
{['netDebts'].includes(balanceTypeOp) && (
<AlignedText
left="Net Debts:"
right={amountToCurrency(payload[0].payload.netDebts)}
/>
)}
{['totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left="Net:"
Expand Down Expand Up @@ -132,7 +149,7 @@ const customLabel = ({
type AreaGraphProps = {
style?: CSSProperties;
data: DataEntity;
balanceTypeOp: 'totalAssets' | 'totalTotals' | 'totalDebts';
balanceTypeOp: balanceTypeOpType;
compact?: boolean;
viewLabels: boolean;
};
Expand Down
35 changes: 28 additions & 7 deletions packages/desktop-client/src/components/reports/graphs/BarGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import {
amountToCurrency,
amountToCurrencyNoDecimal,
} from 'loot-core/src/shared/util';
import { type DataEntity } from 'loot-core/src/types/models/reports';
import {
type balanceTypeOpType,
type DataEntity,
} from 'loot-core/src/types/models/reports';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

import { useAccounts } from '../../../hooks/useAccounts';
Expand Down Expand Up @@ -50,6 +53,8 @@ type PayloadItem = {
name: string;
totalAssets: number | string;
totalDebts: number | string;
netAssets: number | string;
netDebts: number | string;
totalTotals: number | string;
networth: number | string;
totalChange: number | string;
Expand All @@ -60,7 +65,7 @@ type PayloadItem = {
type CustomTooltipProps = {
active?: boolean;
payload?: PayloadItem[];
balanceTypeOp?: 'totalAssets' | 'totalDebts' | 'totalTotals';
balanceTypeOp?: balanceTypeOpType;
yAxis?: string;
};

Expand Down Expand Up @@ -96,10 +101,22 @@ const CustomTooltip = ({
)}
{['totalDebts', 'totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left="Debt:"
left="Debts:"
right={amountToCurrency(payload[0].payload.totalDebts)}
/>
)}
{['netAssets'].includes(balanceTypeOp) && (
<AlignedText
left="Net Assets:"
right={amountToCurrency(payload[0].payload.netAssets)}
/>
)}
{['netDebts'].includes(balanceTypeOp) && (
<AlignedText
left="Net Debts:"
right={amountToCurrency(payload[0].payload.netDebts)}
/>
)}
{['totalTotals'].includes(balanceTypeOp) && (
<AlignedText
left="Net:"
Expand Down Expand Up @@ -137,7 +154,7 @@ type BarGraphProps = {
data: DataEntity;
filters: RuleConditionEntity[];
groupBy: string;
balanceTypeOp: 'totalAssets' | 'totalDebts' | 'totalTotals';
balanceTypeOp: balanceTypeOpType;
compact?: boolean;
viewLabels: boolean;
showHiddenCategories?: boolean;
Expand Down Expand Up @@ -167,11 +184,15 @@ export function BarGraph({
const labelsMargin = viewLabels ? 30 : 0;

const getVal = obj => {
if (balanceTypeOp === 'totalDebts') {
return -1 * obj.totalDebts;
} else {
if (balanceTypeOp === 'totalTotals' && groupBy === 'Interval') {
return obj.totalAssets;
}

if (['totalDebts', 'netDebts'].includes(balanceTypeOp)) {
return -1 * obj[balanceTypeOp];
}

return obj[balanceTypeOp];
};

const longestLabelLength = data[splitData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import React, { useState } from 'react';
import { PieChart, Pie, Cell, Sector, ResponsiveContainer } from 'recharts';

import { amountToCurrency } from 'loot-core/src/shared/util';
import { type DataEntity } from 'loot-core/src/types/models/reports';
import {
type balanceTypeOpType,
type DataEntity,
} from 'loot-core/src/types/models/reports';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

import { useAccounts } from '../../../hooks/useAccounts';
Expand Down Expand Up @@ -181,7 +184,7 @@ type DonutGraphProps = {
data: DataEntity;
filters: RuleConditionEntity[];
groupBy: string;
balanceTypeOp: 'totalAssets' | 'totalDebts' | 'totalTotals';
balanceTypeOp: balanceTypeOpType;
compact?: boolean;
viewLabels: boolean;
showHiddenCategories?: boolean;
Expand Down Expand Up @@ -209,7 +212,7 @@ export function DonutGraph({
const [pointer, setPointer] = useState('');

const getVal = obj => {
if (balanceTypeOp === 'totalDebts') {
if (['totalDebts', 'netDebts'].includes(balanceTypeOp)) {
return -1 * obj[balanceTypeOp];
} else {
return obj[balanceTypeOp];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ import {
amountToCurrency,
amountToCurrencyNoDecimal,
} from 'loot-core/src/shared/util';
import { type DataEntity } from 'loot-core/types/models/reports';
import {
type balanceTypeOpType,
type DataEntity,
} from 'loot-core/types/models/reports';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

import { useAccounts } from '../../../hooks/useAccounts';
Expand Down Expand Up @@ -115,7 +118,7 @@ type LineGraphProps = {
filters: RuleConditionEntity[];
groupBy: string;
compact?: boolean;
balanceTypeOp: 'totalAssets' | 'totalDebts' | 'totalTotals';
balanceTypeOp: balanceTypeOpType;
showHiddenCategories?: boolean;
showOffBudget?: boolean;
interval?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ import {
amountToCurrency,
amountToCurrencyNoDecimal,
} from 'loot-core/src/shared/util';
import { type DataEntity } from 'loot-core/src/types/models/reports';
import {
type balanceTypeOpType,
type DataEntity,
} from 'loot-core/src/types/models/reports';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

import { useAccounts } from '../../../hooks/useAccounts';
Expand Down Expand Up @@ -144,7 +147,7 @@ type StackedBarGraphProps = {
groupBy: string;
compact?: boolean;
viewLabels: boolean;
balanceTypeOp: 'totalAssets' | 'totalDebts' | 'totalTotals';
balanceTypeOp: balanceTypeOpType;
showHiddenCategories?: boolean;
showOffBudget?: boolean;
interval?: string;
Expand Down Expand Up @@ -194,6 +197,7 @@ export function StackedBarGraph({
data={data.intervalData}
margin={{ top: 0, right: 0, left: leftMargin, bottom: 10 }}
style={{ cursor: pointer }}
stackOffset="sign" //stacked by sign
>
{(!isNarrowWidth || !compact) && (
<Tooltip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as monthUtils from 'loot-core/src/shared/months';
import { type AccountEntity } from 'loot-core/types/models/account';
import { type CategoryEntity } from 'loot-core/types/models/category';
import { type CategoryGroupEntity } from 'loot-core/types/models/category-group';
import { type balanceTypeOpType } from 'loot-core/types/models/reports';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

import { ReportOptions } from '../ReportOptions';
Expand All @@ -12,7 +13,7 @@ type showActivityProps = {
navigate: NavigateFunction;
categories: { list: CategoryEntity[]; grouped: CategoryGroupEntity[] };
accounts: AccountEntity[];
balanceTypeOp: 'totalAssets' | 'totalDebts' | 'totalTotals';
balanceTypeOp: balanceTypeOpType;
filters: RuleConditionEntity[];
showHiddenCategories: boolean;
showOffBudget: boolean;
Expand Down Expand Up @@ -50,7 +51,7 @@ export function showActivity({
'FromDate') as 'dayFromDate' | 'monthFromDate' | 'yearFromDate');
const isDateOp = interval === 'Weekly' || type !== 'time';

const conditions = [
const filterConditions = [
...filters,
id && { field, op: 'is', value: id, type: 'id' },
{
Expand All @@ -66,8 +67,9 @@ export function showActivity({
options: { date: true },
},
!(
balanceTypeOp === 'totalTotals' &&
(type === 'totals' || type === 'time')
['netAssets', 'netDebts'].includes(balanceTypeOp) ||
(balanceTypeOp === 'totalTotals' &&
(type === 'totals' || type === 'time'))
) && {
field: 'amount',
op: 'gte',
Expand Down Expand Up @@ -96,7 +98,7 @@ export function showActivity({
navigate('/accounts', {
state: {
goBack: true,
conditions,
filterConditions,
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import React, {
import {
type GroupedEntity,
type DataEntity,
type balanceTypeOpType,
} from 'loot-core/src/types/models/reports';
import { type RuleConditionEntity } from 'loot-core/types/models/rule';

Expand All @@ -28,7 +29,7 @@ type ReportTableProps = {
totalScrollRef: RefObject<HTMLDivElement>;
handleScroll: UIEventHandler<HTMLDivElement>;
groupBy: string;
balanceTypeOp: 'totalDebts' | 'totalTotals' | 'totalAssets';
balanceTypeOp: balanceTypeOpType;
data: DataEntity;
filters?: RuleConditionEntity[];
mode: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import React, { type RefObject, type UIEventHandler } from 'react';

import { type IntervalEntity } from 'loot-core/src/types/models/reports';
import {
type balanceTypeOpType,
type IntervalEntity,
} from 'loot-core/src/types/models/reports';

import { theme } from '../../../../style';
import { type CSSProperties } from '../../../../style/types';
Expand All @@ -12,7 +15,7 @@ type ReportTableHeaderProps = {
groupBy: string;
interval: string;
data: IntervalEntity[];
balanceTypeOp: 'totalDebts' | 'totalTotals' | 'totalAssets';
balanceTypeOp: balanceTypeOpType;
headerScrollRef: RefObject<HTMLDivElement>;
handleScroll: UIEventHandler<HTMLDivElement>;
compact: boolean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function ReportTableList({
date: interval.date,
totalAssets: interval.totalAssets,
totalDebts: interval.totalDebts,
netAssets: interval.netAssets,
netDebts: interval.netDebts,
totalTotals: interval.totalTotals,
intervalData: [],
categories: [],
Expand Down
Loading

0 comments on commit 3332f58

Please sign in to comment.