fix: Fill totals with correct amount of zeroes for empty reports

This commit is contained in:
aragaer 2024-03-17 21:13:10 +03:00 committed by Simon Michael
parent f1bd46fd57
commit 09e158d31e
5 changed files with 24 additions and 22 deletions

View File

@ -374,7 +374,7 @@ generateMultiBalanceReport rspec@ReportSpec{_rsReportOpts=ropts} j priceoracle u
$ buildReportRows ropts displaynames matrix $ buildReportRows ropts displaynames matrix
-- Calculate column totals -- Calculate column totals
totalsrow = dbg5 "totalsrow" $ calculateTotalsRow ropts rows totalsrow = dbg5 "totalsrow" $ calculateTotalsRow ropts rows $ length colps
-- Sorted report rows. -- Sorted report rows.
sortedrows = dbg5 "sortedrows" $ sortRows ropts j rows sortedrows = dbg5 "sortedrows" $ sortRows ropts j rows
@ -501,8 +501,8 @@ sortRows ropts j
-- | Build the report totals row. -- | Build the report totals row.
-- --
-- Calculate the column totals. These are always the sum of column amounts. -- Calculate the column totals. These are always the sum of column amounts.
calculateTotalsRow :: ReportOpts -> [MultiBalanceReportRow] -> PeriodicReportRow () MixedAmount calculateTotalsRow :: ReportOpts -> [MultiBalanceReportRow] -> Int -> PeriodicReportRow () MixedAmount
calculateTotalsRow ropts rows = calculateTotalsRow ropts rows colcount =
PeriodicReportRow () coltotals grandtotal grandaverage PeriodicReportRow () coltotals grandtotal grandaverage
where where
isTopRow row = flat_ ropts || not (any (`HM.member` rowMap) parents) isTopRow row = flat_ ropts || not (any (`HM.member` rowMap) parents)
@ -511,7 +511,9 @@ calculateTotalsRow ropts rows =
colamts = transpose . map prrAmounts $ filter isTopRow rows colamts = transpose . map prrAmounts $ filter isTopRow rows
coltotals :: [MixedAmount] = dbg5 "coltotals" $ map maSum colamts coltotals :: [MixedAmount] = dbg5 "coltotals" $ case colamts of
[] -> replicate colcount nullmixedamt
_ -> map maSum colamts
-- Calculate the grand total and average. These are always the sum/average -- Calculate the grand total and average. These are always the sum/average
-- of the column totals. -- of the column totals.

View File

@ -19,7 +19,7 @@ Balance Sheet 2016-01-01
Liabilities || Liabilities ||
-------------++------------ -------------++------------
-------------++------------ -------------++------------
|| || 0
=============++============ =============++============
Net: || 1 Net: || 1
@ -42,7 +42,7 @@ Balance Sheet 2016-01-01
Liabilities || Liabilities ||
-------------++------------ -------------++------------
-------------++------------ -------------++------------
|| || 0
=============++============ =============++============
Net: || 1 Net: || 1
@ -171,7 +171,7 @@ Balance Sheet 2017-01-01
Liabilities || Liabilities ||
-------------++------------ -------------++------------
-------------++------------ -------------++------------
|| || 0
=============++============ =============++============
Net: || 1 Net: || 1
@ -193,7 +193,7 @@ Balance Sheet 2017-01-01
Liabilities || Liabilities ||
-------------++------------ -------------++------------
-------------++------------ -------------++------------
|| || 0
=============++============ =============++============
Net: || 1 Net: || 1
@ -215,7 +215,7 @@ Balance Sheet 2017-12-31
Liabilities || Liabilities ||
-------------++--------------------- -------------++---------------------
-------------++--------------------- -------------++---------------------
|| || 0 0
=============++===================== =============++=====================
Net: || $1 $1 Net: || $1 $1
@ -238,7 +238,7 @@ Balance Sheet 2016-01-31
Liabilities ║ Liabilities ║
─────────────╫──────────── ─────────────╫────────────
─────────────╫──────────── ─────────────╫────────────
0
═════════════╬════════════ ═════════════╬════════════
Net: ║ 1 Net: ║ 1
@ -276,7 +276,7 @@ Balance Sheet 2018-10-03
Liabilities || Liabilities ||
-------------------------------------++------------ -------------------------------------++------------
-------------------------------------++------------ -------------------------------------++------------
|| || 0
=====================================++============ =====================================++============
Net: || $120 Net: || $120
@ -303,7 +303,7 @@ Balance Sheet 2020-03-25
Liabilities || Liabilities ||
-------------++------------ -------------++------------
-------------++------------ -------------++------------
|| || 0
=============++============ =============++============
Net: || $1 Net: || $1
@ -315,7 +315,7 @@ $ hledger -f - balancesheet --tree --output-format=csv
"assets:a","$1" "assets:a","$1"
"total","$1" "total","$1"
"Liabilities","" "Liabilities",""
"total" "total","0"
"Net:","$1" "Net:","$1"
# ** 13. CSV output supports --drop. # ** 13. CSV output supports --drop.
@ -326,7 +326,7 @@ $ hledger -f - balancesheet --tree --output-format=csv --drop 1
"a","$1" "a","$1"
"total","$1" "total","$1"
"Liabilities","" "Liabilities",""
"total" "total","0"
"Net:","$1" "Net:","$1"
< <
@ -342,7 +342,7 @@ $ hledger -f - balancesheet --output-format=csv
"assets:a","$-10000.00" "assets:a","$-10000.00"
"total","$-10000.00" "total","$-10000.00"
"Liabilities","" "Liabilities",""
"total" "total","0"
"Net:","$-10000.00" "Net:","$-10000.00"
# ** 15. In compound reports like balancesheet, parent accounts might not have # ** 15. In compound reports like balancesheet, parent accounts might not have

View File

@ -89,7 +89,7 @@ Cashflow Statement 2016-10
Cash flows || Cash flows ||
------------++----- ------------++-----
------------++----- ------------++-----
|| || 0
>2 >2
>= 0 >= 0

View File

@ -10,7 +10,7 @@ Income Statement 2014-01-01..2014-01-02
Revenues || Revenues ||
--------------------------++------------------------ --------------------------++------------------------
--------------------------++------------------------ --------------------------++------------------------
|| || 0
==========================++======================== ==========================++========================
Expenses || Expenses ||
--------------------------++------------------------ --------------------------++------------------------

View File

@ -18,7 +18,7 @@ Income Statement 2016-01-01
Expenses || Expenses ||
----------++------------ ----------++------------
----------++------------ ----------++------------
|| || 0
==========++============ ==========++============
Net: || -1 Net: || -1
@ -138,7 +138,7 @@ Income Statement 2015-10
Expenses || Expenses ||
-------------------++------------ -------------------++------------
-------------------++------------ -------------------++------------
|| || 0
===================++============ ===================++============
Net: || $10,000.00 Net: || $10,000.00
@ -171,14 +171,14 @@ Income Statement 2016-10
Revenues || Revenues ||
----------++----- ----------++-----
----------++----- ----------++-----
|| || 0
==========++===== ==========++=====
Expenses || Expenses ||
----------++----- ----------++-----
----------++----- ----------++-----
|| || 0
==========++===== ==========++=====
Net: || Net: || 0
# ** 6. Multicolumn test # ** 6. Multicolumn test
# old (arithmetic sign): # old (arithmetic sign):