peiTeX / qrbill

LaTeX package to create qrbills based on the Swiss standard
12 stars 3 forks source link

No padding/truncating after decimal point of amount (CcyAmtDate.Amt ) #21

Open Delok opened 6 months ago

Delok commented 6 months ago

I noticed that in two situations the mandatory two decimal places after the dot in the field "Amount" will be omitted:

I can solve this issue but in a very clumsy way:

  1. \usepackage{calculator}
  2. \TRUNCATE[2]{\mytotal}{\mytotal} the variable \mytotal is where I store the total amount

What I wish qrbill would do instead: Detect if there are not two trailing digits in the amount, either pad or truncate the amount to precisely two trailing digits

TeXhackse commented 6 months ago

Sorry I was a bit confused.

I cannot reconstruct. I get the decimal zeros with the lua qrcode mechanism as well as with the default setting. Could you please either explain more detailed or provide an example? If I simply replace the .42 in the standalone xample file by .00 it works as intended.

TeXhackse commented 6 months ago

Oh sorry, I probably missunderstood. So you have 123.000000 as an input and want to truncate it to 123.00

Well… I am not sure if it's a good idea to truncate without having a real validation …as … there might be numbers where rounding is necessary … and then one would have to ensure its rounded correctly at all places.

I usually do that when calculating the values, as the visible output also should use 2 decimal places.

Is there a real usecase where the output in the main part of an invoice should differ?

Delok commented 6 months ago

The problem is that there is no validation. I tried many, many different attempts before arriving at what I proposed in the original issue. For example, I tried adding 0.0001 CHF to the final amount, hoping that this would force the QR generator to add decimals but truncate them, as the official standard only allows for 2 decimal places. But it did not work. This is the code that generates an invalid QR code with a manually entered amount:

`\documentclass[foldmarks=b]{scrletter} \usepackage[ frame=top, sep-iban=4, sep-reference=-5, ]{qrbill}

\DeclareNewLayer[ align=bl, voffset=\paperheight, hoffset=0pt, contents={\QRbill}, width=\paperwidth, height=105mm, ]{qrbill}

\begin{document}

\qrbillsetdata{ creditor={foobar LLC\ Postfach\ 404\ 2342\ Zurich\ CH}, Account=CH1280808005649899718, vat=123123123,% VAT number with stripped CH and periods debtor={peiTeX\ TeXnikerweg\ 78\ 23420\ Hamburg\ DE}, Amount=1337, Message=Bestellung vom 27.06.2020, invoicenum=100-4242, vatdetails=0,% 0% VAT AV1=LX;F00BAR;2342, }

\setkomavar{fromaddress}{\insertcreditor}

\begin{letter}{\insertdebtor}

\opening{opening}

Text

\closing{closing}

\AddLayersToPageStyle{@everystyle@}{qrbill}

\end{letter} \end{document} \endinput`

The only thing I changed was to remove the decimal point in the Amount

Here an example when some code calculates the Amount (as opposed to above, typing in the amount directly):

`\documentclass{invoice} % Use the custom invoice class (invoice.cls) \usepackage{textcomp} \usepackage{pdftexcmds} \usepackage{fancyhdr} \usepackage{xstring} \usepackage{hyperref} \usepackage[icon=swiss-cross,data-to-string=true]{qrbill} \usepackage{lastpage} \usepackage{calculator}

\def \tab {\hspace*{3ex}} % Define \tab to create some horizontal white space \makeatletter %MD5 as invoice number bc. I am too lazy to come up with a unique IN every time: \ifx\pdf@filemdfivesum\undefined\def\pdf@filemdfivesum#{\mdfivesum file}\fi \let\filesum\pdf@filemdfivesum

%--------------------------------------- %VARIABLE SECTION %--------------------------------------- \def\mytutoringtitle{TSome title} \def\mytutoringdesc{ Description} \def\clientname{Clientname} \def\clientaddress{Client Adress \ \tab 1234 City} \def\mytime{10} \def\myfee{5} \def\mytotal{0} \def\myfixedfee{0} \def\mymonth{March} \MULTIPLY{\myfee}{\mytime}{\mytotal} \ADD{\mytotal}{\myfixedfee}{\mytotal} %\TRUNCATE[2]{\mytotal}{\mytotal} \fancyfoot[C]{\thepage\ of \pageref{LastPage}} \def\myfoot{\clientname_\StrLeft{\filesum{\jobname}}{6}} \fancyfoot[L]{\myfoot} %\fancyfoot[R]{\clientname}

\begin{document} \pagestyle{fancy}

%---------------------------------------------------------------------------------------- % HEADING SECTION %----------------------------------------------------------------------------------------

\hfil{\Huge\bf \mytutoringtitle}\hfil % Company providing the invoice \bigskip\break % Whitespace \hrule % Horizontal line

Some Name \hfill email@placeholder.com\ Company Name LLC \hfill http://web.site \ 1234 City \hfill +555 1234567 \ % Your address and contact information

{\bf Invoice To:} \ \tab \clientaddress \ % Invoice recipient \ \ % Recipient's company {\bf Date:} \hfill {\bf Invoice ID:} \ \tab \today \hfill \myfoot \ % Invoice date + MD5\textsl{} %---------------------------------------------------------------------------------------- % TABLE OF EXPENSES %----------------------------------------------------------------------------------------

\begin{invoiceTable}

\feetype{\mytutoringdesc} % Fee category description \hourrow{\mymonth}{\mytime}{\myfee}

\end{invoiceTable} \qrbillsetdata*{ Amount=\mytotal,% this is expanded at the definition } \newpage \QRbill[ creditor={ My Name\ Street Name\ 1234 City\ CH }, Account=CH921234567890, %invoicenum=, invoicedate=\QRbillParseDate{\the\year}{\the\month}{\the\day}, Reference=, %Amount=\mytotal, Message=\mymonth_\clientname % insert additional data here ]

%----------------------------------------------------------------------------------------

\end{document}`

By the way, thank you for your package and for responding so quickly.

On that topic, I also dealt with unexpected invisible trailing whitespaces in some issues which produced invalid QR codes (though here, I have to blame the online QR-bill validators because they were not able to show me that there was a trailing whitespace, only that the field CcyAmtDate.Amt was invalid) Thanks to a closed issue, I was able to figure out that using \qrbillsetdata*{ Amount=\mytotal,% this is expanded at the definition } would fix the issue, but still, somehow it seems to me that maybe trimming the whitespace automatically would be more elegant than having to break out part of the QRBill.

TeXhackse commented 6 months ago

Ah, thanks for the explanation. I get your point. Actually I would love to add validation, but don't find time to do so. Concerning the numbers, I think it's easily to possible to add it as a feature but I would not enable it by default, because as long as there is no validation at all it's easier to not change anything about the input by default.

The mechanism itself is not that complex at all, I'd just need to find some time… which is a bit of an issue for freetime projects. But I then tag it back to an enhancement.

Delok commented 6 months ago

I understand your point about the validation and the lack of time. If one day I start suffering less from the latter, I will see if I can start contributing.