Bug 492831

Summary: Account Balance Report needs HTML improvements
Product: [Applications] kmymoney Reporter: Glenn <gemdancer>
Component: reportsAssignee: KMyMoney Devel Mailing List <kmymoney-devel>
Status: RESOLVED FIXED    
Severity: minor CC: ralf.habacker
Priority: NOR    
Version: 5.1.3   
Target Milestone: ---   
Platform: Microsoft Windows   
OS: Microsoft Windows   
Latest Commit: Version Fixed In: 5.2
Sentry Crash Report:
Attachments: HTML report from 5.1.3
HTML Report from dev version
PDF Report from dev version
test case
Print Preview from dev version showing issue
Print preview from previous major branch
test case (update)

Description Glenn 2024-09-08 18:51:25 UTC
SUMMARY
The Net Worth -> Account Balances report has several HTML and CSS issues.
This probably applies to many other reports also.

STEPS TO REPRODUCE
1.  Run the report Net Worth -> Account Balances by Institution
2.  Export the report as HTML
3. Look at the generated HTML file with a text editor.

OBSERVED RESULT
1. CSS has "background: "  items with a url which points to the kmymoney installation folder.
That is useless if the file is moved to any place else, and probably even when on this computer.
Delete the background items entirely.

2. Account names in the report have HTML links like
<a href=ledger?id=A000001&tid=>Bank Name</a>
These links do not work, so should not be created.
No use for links in this report, so all the "A" css items can be deleted.

3.  HTML DOCTYPE is specified as HTML 4.01 strict.
It would be nice to update the format for HTML 5.

EXPECTED RESULT
No "background:" CSS items with a url
No <a> links in the HTML
No A.xx items in the CSS

SOFTWARE/OS VERSIONS
Windows:  11

ADDITIONAL INFORMATION
KMyMoney 5.1.3-eefo4f1, installed via kmymoney-5.1-3218-windows-cl-msvc2019-x86_64
Comment 1 Jack 2024-09-08 18:59:19 UTC
Are you aware that KMyMoney displays reports using HTML?  There, those links actually work - taking you, for example, to the transaction in the ledger for the relevant account.  I suspect it would be difficult to create different HTML/CSS for display and for export, but that is what would be required for your suggestions..
Comment 2 Glenn 2024-09-08 19:36:41 UTC
You can validate the report HTML using the web page https://validator.w3.org/nu/
Comment 3 Glenn 2024-09-08 19:39:11 UTC
Thanks for the quick reply! 
OK, the link is useful when viewing the report in KmyMoney, but it is useless in the export.
No need to include it in the export.
Comment 4 Jack 2024-09-08 20:10:26 UTC
First, no need for a separate but for each report or type of report, any changes can/will easily be applied wherever applicable.  Feel free to point out which are affected in additional comments.

Next, the report is generated.  If export is requested, the already generated report is exported, it is not generated again for that purpose, thus my comment that to export something different from what is displayed is going to take extra work.  I am also not sure how much of the actual HTML/CSS has been written by the KMM developers vs generated by any underlying KDE/Qt libraries, or even some combination.  I suppose removing specified pieces of HTML/CSS can be done with regexp type editing, it's still extra work.  As usual, patches gratefully accepted.
Comment 5 Glenn 2024-09-08 20:22:02 UTC
OK, I understand better now. The displayed report is actually HTML, and the Export just outputs that same HTML to a file.
It is extra work to modify the HTML during the Export.
By definition, Export means it will be used outside of KyMyMoney, so it would be nice if it actually worked properly outside of KyMyMoney.
You folks might want to think about that.

There is a workaround: Convert the HTML to PDF.
As the treasurer for an organization, I use the Export to generate reports to present to the board.
HTML is not a good format for that, so I end up saving them as PDF from the web browser.
Converting to PDF seems to ignore all the HTML issues and it comes out OK.
I also use Quickbooks for another organization, and it generates reports directly in PDF format.
Although it is an extra step in KyMyMoney to convert from HTML to PDF, it is more flexible because geeks like me can edit the HTML to customize the report.
Since I don't use the HTML format directly, I guess I should not worry about correctness of the HTML, and just accept it as is.
Comment 6 Jack 2024-09-08 21:47:38 UTC
I think (but am not sure) that we have a wishlist filed for being able to output reports directly to PDF.  However, if the exported HTML is opened directly in a browser and then printed to PDF, the extra work is fairly minimal.
One question, though, is the HTML/CSS is simply non-compliant with standards, or does it actually cause any problem in how the report looks in a browser, other than the presence of links that don't work?  This bug is still valid either way, but it would likely affect the priority it receives.
I am also the treasurer for a small non-profit, and I export from KMM as csv, do some further manipulation in LibrOffice, and then save as PDF for presentation, so not quite the same workflow.
Comment 7 Glenn 2024-09-08 22:33:10 UTC
After looking at this more, it is just an issue of non-compliance with standards.
The HTML output looks fine, except the Link for each Account does not work.
The PDF is fine.
When I open the browser Inspector, the Console does not show any errors or warnings.
Very low priority, or maybe even close it with no further action.
Sorry to bother you folks about something so trivial.
You have been very responsive, and I really appreciate that.
Comment 8 Ralf Habacker 2024-10-24 04:23:17 UTC
Git commit aa472d77db0a3b08909e3174d184ee03864450c5 by Ralf Habacker.
Committed on 24/10/2024 at 04:14.
Pushed by habacker into branch 'master'.

Add exporting reports as pdf file to reports user inferface
FIXED-IN:5.2

M  +2    -1    kmymoney/plugins/views/reports/kreportsview.cpp
M  +8    -1    kmymoney/plugins/views/reports/kreportsview_p.h

https://invent.kde.org/office/kmymoney/-/commit/aa472d77db0a3b08909e3174d184ee03864450c5
Comment 9 Ralf Habacker 2024-10-24 04:23:25 UTC
Git commit a55c9ab3f936c81909749d2caa17649f9b0106a7 by Ralf Habacker.
Committed on 24/10/2024 at 04:18.
Pushed by habacker into branch 'master'.

Add support to export selected reports as pdf file

M  +58   -0    kmymoney/plugins/views/reports/kreportsview.cpp
M  +1    -0    kmymoney/plugins/views/reports/kreportsview.h
M  +1    -1    kmymoney/plugins/views/reports/kreportsview_p.h

https://invent.kde.org/office/kmymoney/-/commit/a55c9ab3f936c81909749d2caa17649f9b0106a7
Comment 10 Glenn 2024-11-04 00:32:07 UTC
Created attachment 175499 [details]
HTML report from 5.1.3
Comment 11 Glenn 2024-11-04 00:33:03 UTC
Created attachment 175500 [details]
HTML Report from dev version
Comment 12 Glenn 2024-11-04 00:33:35 UTC
Created attachment 175501 [details]
PDF Report from dev version
Comment 13 Glenn 2024-11-04 00:42:25 UTC
I had tried to add a new comment, but apparently it did not get saved...
WOW, I was not expecting the addition of PDF report output. Nice. Thanks!
I downloaded kmymoney-master-3632-windows-cl-msvc2019-x86_64 and tried it.
Unfortunately, there are some formatting quirks.
The PDF output seems to use fixed width columns.
If the data does not fit in the column, there is some text wrapping, which is OK.
However, there is not enough space between columns, 
so some of the numbers are so smashed together that you can't tell what's what.
Also, the HTML output seems to have changed, for the worse.
The first column with the Account names has much more indentation and white space than it used to.
My normal version of KMM is 5.1.3-eef04f1.
I have attached 3 versions of the same report, so you can see what I am talking about:
HTML from 5.1.3, HTML from dev, and PDF from dev.
 Thanks.
Comment 14 Glenn 2024-11-04 00:45:27 UTC
One more comment about the PDF report output.
It would be nice to have some options to control of the output, at least whether it is in Portrait or Landscape orientation.
Comment 15 Ralf Habacker 2024-11-04 12:51:06 UTC
Created attachment 175516 [details]
test case

(In reply to Glenn from comment #13)
> However, there is not enough space between columns, 
> so some of the numbers are so smashed together that you can't tell what's
> what.

This problem is not caused by the currently added PDF export, as it can already be reproduced with the attached test case in the print preview by opening the “7-Day Cash Flow Forecast” report, clicking on the menu item “File”->“Print Preview” and zooming in on the view.
Comment 16 Ralf Habacker 2024-11-04 12:53:39 UTC
Created attachment 175517 [details]
Print Preview from dev version showing issue
Comment 17 Ralf Habacker 2024-11-04 13:19:50 UTC
Created attachment 175518 [details]
Print preview from previous major branch

This problem seems to have arisen with the use of Qt5 or the conversion of the report output to QTextBrowser, (https://invent.kde.org/office/kmymoney/-/merge_requests/118), as it does not occur with the previous major version.
Comment 18 Ralf Habacker 2024-11-04 13:52:46 UTC
(In reply to Glenn from comment #13)
> The HTML output also seems to have changed, and for the worse.
> The first column of account names has a lot more indentation and whitespace than it used to.
> Whitespace than before.
... 
> HTML of 5.1.3 
In this file there is

<td class=“left” style=“text-indent: 1.0em”>Investment&nbsp;Sales&nbsp;Cash&nbsp;Income</td>

> HTML of dev
and in this file 

<td class=“left” style=“text-indent: 16.0em”>Investment&nbsp;Sale&nbsp;Cash&nbsp;Income</td>

whereby there are differences in the inline css attribute “text-indent” which explain these deviations.
Comment 19 Ralf Habacker 2024-11-04 15:04:54 UTC
Git commit ffa7449ae467e428c0fd3be02edd60ef26c01602 by Ralf Habacker.
Committed on 04/11/2024 at 15:04.
Pushed by habacker into branch 'master'.

Restore indentation for reports based on pivot tables

The commit below increased the indentation to 16 times the
value previously used, which significantly increased the
width of the report when exporting to an HTML file; this
has now been corrected.

If a higher value is required, this should be done via an
option in the settings.

Fixup for commit f0a9807dd.

M  +2    -2    kmymoney/plugins/views/reports/core/pivottable.cpp

https://invent.kde.org/office/kmymoney/-/commit/ffa7449ae467e428c0fd3be02edd60ef26c01602
Comment 20 Ralf Habacker 2024-11-04 15:06:13 UTC
Created attachment 175520 [details]
test case (update)
Comment 21 Ralf Habacker 2024-11-04 22:53:34 UTC
Git commit 36277eec247a78227e0c20ed612c17965c6d95a4 by Ralf Habacker.
Committed on 04/11/2024 at 20:57.
Pushed by habacker into branch 'master'.

Add spacing between columns for printing or previewing reports

This prevents some numbers from being mixed up so much that you
no longer know what is what.

Since the use of a 'width' attribute in the HTML table does not
work with QTextBrowser, a space is added in the individual
elements of the QTextDocument instance used.

M  +8    -0    kmymoney/misc/kmmtextbrowser.cpp

https://invent.kde.org/office/kmymoney/-/commit/36277eec247a78227e0c20ed612c17965c6d95a4
Comment 22 Ralf Habacker 2024-11-05 11:10:06 UTC
Git commit 37de9b0a4ac298c374708631b612106e10edc6a8 by Ralf Habacker.
Committed on 05/11/2024 at 11:09.
Pushed by habacker into branch 'master'.

Fix the indentation when displaying reports in the application

The mentioned commit corrected the html export of a report, but not
the display of the report, because the HTML import of QTextDocument,
which is used here, does not support the unit “em” for the css
attribute “text-indent”. To fix this, the unit “px” is always used
in the generated HTML text.

Fixup for commit ffa7449ae

M  +3    -3    kmymoney/plugins/views/reports/core/pivottable.cpp

https://invent.kde.org/office/kmymoney/-/commit/37de9b0a4ac298c374708631b612106e10edc6a8
Comment 23 Ralf Habacker 2024-11-05 11:37:21 UTC
Git commit 581bf742bdccee226d7bd0f84f1797296ba70a23 by Ralf Habacker.
Committed on 05/11/2024 at 11:37.
Pushed by habacker into branch 'master'.

Fix display of reports printig and print preview

After switching to the QTextBrowser class for printing and the print
view of reports, too little space is output between the individual
columns. This is corrected by defining a left margin in front of
each column.
Related: bug 495821
FIXED-IN:5.2

M  +3    -3    kmymoney/misc/kmmtextbrowser.cpp

https://invent.kde.org/office/kmymoney/-/commit/581bf742bdccee226d7bd0f84f1797296ba70a23
Comment 24 Ralf Habacker 2024-11-05 15:05:04 UTC
Git commit 5ee78051fc635637a706c3e79bda5effbf6af84d by Ralf Habacker.
Committed on 05/11/2024 at 14:46.
Pushed by habacker into branch 'master'.

Add control of output settings in PDF format

When exporting to a PDF file, a dialog is now displayed for each
selected report with which various output settings can be adjusted.

M  +45   -0    kmymoney/misc/kmm_printer.cpp
M  +14   -0    kmymoney/misc/kmm_printer.h
M  +5    -4    kmymoney/plugins/views/reports/kreportsview_p.h

https://invent.kde.org/office/kmymoney/-/commit/5ee78051fc635637a706c3e79bda5effbf6af84d
Comment 25 Ralf Habacker 2024-11-05 15:05:06 UTC
Git commit 3a5f40c79dfb74670f1f2adfb419b4c17d4fd1ab by Ralf Habacker.
Committed on 05/11/2024 at 15:01.
Pushed by habacker into branch 'master'.

Removed font sizes in the unit 'px' in kmymoney.css

As the unit “pt” for the size of fonts is already used elsewhere in this
stylesheet, the use of “px” makes no sense here, as it is much too small,
which is noticeable when printing or previewing larger page formats.

M  +0    -3    kmymoney/html/kmymoney.css

https://invent.kde.org/office/kmymoney/-/commit/3a5f40c79dfb74670f1f2adfb419b4c17d4fd1ab