Saturday, January 29, 2022

QR Code Tag-Length-Value (TLV) string into Base64 encoding for KSA E-Invoicing in Saudi Arabia Zakat Tax

Hello Everyone,

Link to Application -  https://apex.oracle.com/pls/apex/r/development_test01/tlv-base-64-qr/home?session=3169462546514

I have created a utility which can generate the QR code with TLV string encoded in base64 which is required for the E-Invoicing in Saudi Arab.

I got this requirement from one of my client from Kuwait. And they are using oracle forms 12c and 6i both versions and so many application and they wanted to print the QR code on invoice reports.

I had tried it with PLSQL but i didn't succeed. then i tried java because now the programming language is not a barrier for me. i just need the requirement and try to do it with the best suitable method.

That's it then i decided to help some more people for the same. as i seen so many peoples are seeking to get the information. that how they can implement this on there application.

In this blog,  i will share my understanding and the process which i followed to implement this.

--------------THE TLV FORMAT------------------------

As per Zakat, Tax and Customs Authority (ZATCA) of Saudi Arabia, one of the main requirements is the implementation of QR codes on tax invoices in the e-invoicing project (Fatoora), which will be mandatory starting December 4, 2021

As per the ZATCA instructions(Page No. 23), the minimum requirements that must be shown after scanning a QR code are the following fields, which should be represented in form of based64 encoding:

  1. Seller’s name.
  2. VAT registration number of the seller.
  3. Time stamp of the invoice (date and time).
  4. Invoice total (with VAT).
  5. VAT total.

In this blog,  I will show how to encode the QR data in base64 format using java code and then using it in any invoice to print QR code on Invoice layouts.

I am not going to provide the full code but yes i will give you the utility ( a jar file ) by which you will be able to convert normal data into tlv format then encode it in base64 and generate QR code directly with this single utility and in the output you will get a image file and you can use that image file to print it on any invoice system either the application to generate invoice can be in ORACLE FORMS, JAVA, .NET, APEX,ANGULAR and with any application.

1st Step is to prepare each of the five values in TLV (Tag-Length-Value) structure

Tag is fixed (1 for Seller’s name, 2 for VAT No……5 for VAT Total)

Length is the size of the value field in bytes (it’s not the count of characters but how many bytes the value represents)

Value is the data against each of the five fields.

Let’s take an example to clarify TLV

    1. Seller name; for example, “XYZ AAB
      • Tag      = 1 (1 as a type represents the seller name)
      • Length = 7 (The number of the bytes in “xyz AAB” word)
      • Value   = xyz AAB
    2. VAT Number; for example, 1234567891
      • Tag      = 2 (2 as a type represents the VAT number)
      • Length = 10
      • Value   = 1234567891
    3. Time Stamp; for example, 2021-11-18 08:40:00
      • Tag      = 3 (3 as a type represents invoice time stamp)
      • Length = 19
      • Value   = 2021-11-18 08:40:00
    4. Invoice Total; for example, 100.00
      • Tag      = 4 (4 as a type represents the invoice amount)
      • Length = 6
      • Value   = 100.00
    5. VAT Total; for example, 15.00
      • Tag      = 5 (5 as a type represents the tax amount)
      • Length = 5
      • Value   = 15.00

2nd Step is to convert ‘Tag’ and ‘Length’ to Hexadecimal and then to string. Then concatenate these two strings with ‘Value’ (stored as string)

concatenate all the five TLVs into one string

‘##XYZ AAB##1234567891##2021-11-18 08:40:00##115.00##15.00’

3rd Step is to convert the concatenated string to Base64 format

From the above example we get the following Base64 encoded value

AQxGaXJveiBBc2hyYWYCCjEyMzQ1Njc4OTEDEzIwMjEtMTEtMTcgMDg6MzA6MDAEBjExNS4wMAUFMTUuMDA=

4th Step is to generate the QR code of encoded string 

--------- UTILITY PART---------------------------

Development

*) written a java program to convert information in tlv format and encoding that information in base64.

*) written a java program to create QR Code image file from output string of first program.

*) downloaded and configured build path for java lib required for QR and tlv&base64 conversion.

*) combined both java programs in single code package.

*) Testing the whole logic as per KSA document standards for e-invoice.

*) created a jar file with variables for bundling all subprograms and libraries and required fields as input.

You can download this utility from below URL.

https://mega.nz/file/PW4Qna5T#kVm9gp8B7BHzbwaOHlqALoalb5EzqVVb3eZeyQfvo3Y

I named this utility as kdutility on the name of my daughters Kanak and Divya (KD).

How to use this utility to generate QR
-     Just create any directory. and place the jar utility and use below command to generate the QR code.


Open Command Prompt (cmd) for windows and terminal for  Unix/Linux.

Copy below highlighted Command and change the value for Seller_Name, Vat_Number, TimeStamp, InvoiceAmt, Vat_Amt and qr_dir ( qr_dir stands for the output directory in which you want the QR image file).

java -jar C:\Abhishek\projects\N_hdd\java_workspace2\kdutility.jar -Seller_Name "Abhishek Test" -Vat_Number 1234567891 -TimeStamp "2014-12-23 11:55:55" -InvoiceAmt 300.00 -Vat_Amt 75.00 -qr_dir C:\\Abhishek\\Oracle\\my_client\\RG_KSA_QR_TEST\\newqrcode.png

And That's it now you have the created QR image and ready to use for any invoice report.

note: - after every parameter there is a space between name of parameter and value of parameter.

And change the utility kdutility.jar path accordingly.

for example  -Seller_Name "Abhishek Jha"  - a Space before -Seller_Name and after -Seller_Name.


Example after Scanning and Output QR image for reference.


After Scanning this QR using below Android app

VAT App by the Zakat

Offered By: General Authority of Zakat and Tax-IT




Output - Screenshots 

                                                                In English Language



Output In Arabic Language



Benefits of having own utility.

*) As we are using java code so the utility is platform independent i.e., windows, Unix, Solaris etc...
*) And we can use the qr image to print on oracle reports, crystal reports etc...
*) we can also create a simple gui tool in forms ERP application to generate qr code on click event.
*) We can also replace third party utility or tools which we are currently in applications for QR codes with our own created utility by separating qr related code from our utility

*) if those third-party tools stop working and as we don't have their source code so it will impact the work. and in respect to this it will also reduce the dependency of any other third-party tools.


I can also share the source code of all above mentioned process on request or demand. 

I can also help you in implementing this functionality in your application. I did it for oracle forms 12c and 6i and printed the QR code on invoice reports.

You can also contact me for any other customization required in the utility or having issue in implementing the solutions.

 Abhishek Kumar - Abhishekjha1991@hotmail.com - only urgent.
                                  Abhishekjha225@gmail.com - for any other information.


EOD---------------------------------------------------------------- 

Buy Me a Coffee....Appreciate my work 

Phone Pay, Google Pay, Paytm etc.. - 9899406098

My Goal is to work full time on providing requested solutions and required programs code, software's etc.. and providing it to all programmers and companies in the world for free.  If you Appreciate my work then please buy me a coffee, if this utility is useful to you. And if you can't buy and still want to support me for my work Please share this page with your friends, family and coworkers if it is helpful to them.


References 
https://blogs.sap.com/2021/11/18/qr-code-in-base64-encoding-for-ksa-e-invoicing/
https://blogs.sap.com/2021/11/26/qr-code-in-base64-encoding-for-ksa-e-invoicing-directly-from-data-in-table-edosainv/
https://stackoverflow.com/questions/70346895/qr-code-in-base64-encoding-for-ksa-e-invoicing-in-java

No comments:

Post a Comment

QR Code Tag-Length-Value (TLV) string into Base64 encoding for KSA E-Invoicing in Saudi Arabia Zakat Tax

Hello Everyone, Link to Application -   https://apex.oracle.com/pls/apex/r/development_test01/tlv-base-64-qr/home?session=3169462546514 I ha...