peiTeX / qrbill

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

Using a macro as an argument for the amount of the bill #19

Closed JamesMenetrey closed 1 year ago

JamesMenetrey commented 1 year ago

Dear developers,

First, I would like to thank you for your great work developing this package!

I open this issue because I have found a use case where some QR code scanning banks do not recognize the QR-bill (e.g., BCV).

This happens when I assign the Amount parameter to a macro. After investigating the generated QR-code, the package generates a trailing whitespace after the amount, which is not appreciated by some bank applications.

Here is a minimum non-working example to illustrate my use code:

\documentclass{standalone}
\usepackage[nswissgerman]{babel}

\RequirePackage{xcolor}
\usepackage[
  icon=swiss-cross,
  separate=false,
  sep-iban=4,
  sep-reference=-5
]{qrbill}

\begin{document}

\newcommand{\amount}{1337.42}

\QRbill[
  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=\amount,
  Message=Bestellung vom 27.06.2020,
  invoicenum=100-4242,
  vatdetails=0,% 0% VAT
  AV1=LX;F00BAR;2342,
]

\end{document}
\endinput

Note that I'm defining a new command called \amount and assigning the Amount using it, which generates a trailing whitespace after the amount in the QR-code. A macro is convenient since I can reuse that amount in other places in my bill.

Is there any way to use a macro for the amount, and if not so, should the package be enhanced to remove any trailing space of the amount to prevent this issue from arising without the writer noticing?

Thanks!

TeXhackse commented 1 year ago

The issue is caused because \QRbill does not expand it's argument. Therefore the macro \qrbillsetdata* exists. There you can insert parts of the data you want to be expanded. To make that setting local you always can group that one.

\documentclass{standalone}
\usepackage[nswissgerman]{babel}

\RequirePackage{xcolor}
\usepackage[
  icon=swiss-cross,
  separate=false,
  sep-iban=4,
  sep-reference=-5
]{qrbill}

\begin{document}

\newcommand*{\amount}{1337.42}

\qrbillsetdata*{
  Amount=\amount,% this is expanded at the definition
}

\QRbill[
    Message=Bestellung vom 27.06.2020,
  invoicenum=100-4242,
  vatdetails=0,% 0% VAT
  AV1=LX;F00BAR;2342,
 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},
]

\end{document}
JamesMenetrey commented 1 year ago

Hey @TeXhackse, thanks for your prompt reply! That's working great with this method!

Have a nice end of the year! Cheers