Tuesday, June 22, 2021

E-Invoicing Phase 1 implementation Saudi Arabia

 

Saudi Arabia’s General Authority of Zakat and Tax (GAZT) published a draft resolution for E-Invoicing.

E-Invoicing will be implemented in 2 Phases.

Phase I: All invoices should be electronically and for B2C, electronic invoice should have QR code. Starting date 4 DEC 2021.

Phase II: Integration with Saudi Arabia’s General Authority of Zakat and Tax (GAZT) System. Starting date 1 JAN 2023.

In this article, I am trying to cover Phase I meaning how to add QR code in Sales invoice.

Lets start..and hope you will enjoy it.

First you need to download MessagingToolkit.QRCode.dll file from here.

Copy MessagingToolkit.QRCode.dll and paste in Dynamics AX client directory as shown in below screen shot.



Add new field in Temp table "SalesInvoiceTmp".



Add new display method "qrcode" in table "CustInvoiceJour".

display container qrcode() 

{

        Bindata bindata = new Bindata();

        Image                   Imgobj;

        FileIOPermission        perm = null;

        System.Drawing.Image    img;

        System.Drawing.Bitmap   obj;

        Filename                filename;

        Filepath                _path;

        container               con;

        str GRate,CustName,CustNumber,GTot,PONox,Company,Amount1,InvDate1,SalesOrder;

        real Amount;

        date InvDate; 

MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder(); 

;

 CustNumber=this.custTable_InvoiceAccount().AccountNum;

 CustName=this.custTable_InvoiceAccount().name();

  Company=this.custTable_InvoiceAccount().company();

  InvDate= this.InvoiceDate;

  Amount = this.InvoiceAmountMST;

 SalesOrder=this.SalesId;

 InvDate1=date2str(InvDate,123,2,DateSeparator::Dot,2,DateSeparator::Dot,4,0);

 Amount1=num2str(Amount,2,2,1,0); 

   obj = new System.Drawing.Bitmap(encoder.Encode("Cust No:" +CustNumber+"Cust Name: "+CustName+" Date: "+ InvDate1 +" Amount: "+ Amount1 +" Seller: "+ Company));\\Note you can add required as per need.This is just example.

 filename = @"C:\temp\newPhoto.bmp"; 

 perm = new FileIOPermission(filename, 'RW');

 perm.assert();

 obj.Save(filename,System.Drawing.Imaging.ImageFormat::get_Bmp());

 bindata.loadFile(filename);

 con = bindata.getData();

 return con;

}

Add qrcode() method to SalesInvoiceDP class.



Now add created QRcode field to SSRS report.

In AOT,Find the Visual Studio Project as given below and right-click-->edit.



Refresh Datasets of SalesInvoiceReport in Visual Studio.

Select report ; Right-click-->Edit using designer.



Insert image in report designer.



Set the properties as shown below of inserted image. And image size 1.2inch,1.2inch



Rebuild,deploy and add to AOT.



Compile AX and restart the AOS service before generating Sales invoice.

Finally try to invoice Sales order.



Completed. Hope you enjoyed it.

Thank you.

Syed Faiz Abbas

 

32 comments:

  1. Hi Syed Can you share your email id please. vaibhawkj@gmail.com

    ReplyDelete
  2. i am getting error MessagingToolkit.QRCode.Codec.QRCodeEncoder is not referenced. while executing the report my report server is not same as AOS server.

    ReplyDelete
    Replies
    1. Make sure copy MessagingToolkit.QRCode.dll and paste in Dynamics AX client/Server directory. Then restart AOS it will work.

      Let me know if you face any problem.

      Delete
    2. copying at client also work it. thanks.

      Delete
    3. Assalam aly Kum Syed Bhai! Great Job.

      But Still Received this error after full CIL as well. pls advise

      Assembly containing type MessagingToolkit.QRCode.Codec.QRCodeEncoder is not referenced.
      Object 'CLRObject' could not be created

      Delete
  3. Hi Syed,

    Thanks for your very useful code.

    Tiny update to avoid the limitation of the string length (122 characters only) is to add:
    encoder.set_QRCodeVersion(0);

    after the line of:
    MessagingToolkit.QRCode.Codec.QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();

    ReplyDelete
  4. Hi Syed,
    I'm getting this error while adding qrcode method to CustInvoiceJour
    "Variable MessagingToolkit has not been declared."
    dll file has been added to client and server folders , I did full compile and same issue
    any suggestions

    ReplyDelete
    Replies
    1. Follow these steps correctly:

      1- Register the Dlls file as references.
      2- Import the xpo project.
      3- Stop the AOS service.
      4- Delete all files in XppIL folders (Only files).
      5- Start the AOS service again.
      6- Compile the AOS from AOT (F7).
      7- Generate Incremental CIL.

      Delete
    2. Note:
      Step 2 can be skipped if you follow Syed process on the same server.
      What I did, is tried the process on TEST server then export from TEST and Import into Live server following the 7 steps.

      Delete
  5. Variable MessagingToolkit has not been declared, error while saving in the display method underCustInvoiceJour.

    ReplyDelete
  6. Hi Ramji,

    What error you are getting. Share error message.

    Thanks,

    ReplyDelete
  7. what about storage of invoice on public domain. do you have any understanding of this requirement of ZATCA ?

    ReplyDelete
    Replies
    1. Hi syed,

      Phase 1, no need to store invoices on public domain.

      Delete
  8. Dear All
    we're using Dynamics GP 10 can help us to implement the same above topic

    thanks in advance

    ReplyDelete
    Replies
    1. Hi Mustafa,

      Sorry, I do not know about GP at all.

      Delete
  9. Hi Syed,
    Thank you very much for your valuable post.
    I followed your instructions and it worked successfully, but I'm having trouble if the string contains Arabic characters. Where the text is required to be in Arabic. How to solve this problem and include UTF-8 format?

    ReplyDelete
  10. Hi Ahmed,
    Sorry to say but Arabic characters. I do not know.

    ReplyDelete
  11. Assembly containing type MessagingToolkit.QRCode.Codec.QRCodeEncoder is not referenced.
    Object 'CLRObject' could not be created

    ReplyDelete
  12. Hi Umair Khan,

    Make sure copy MessagingToolkit.QRCode.dll and paste in Dynamics AX client/Server directory. Then restart AOS it will work.

    Let me know if you face any problem.

    Regards,
    Syed

    ReplyDelete
    Replies
    1. Already paste it than to same error... is it required to enables

      "Enable the hot-swapping of assemblies for each development session"?

      Delete
  13. Will this QRCode after scanning values will display in encoded base64 format? or normal text

    ReplyDelete
    Replies
    1. Hi,

      It will display normal text(string).

      Best Regard,
      Syed Faiz Abbas

      Delete
    2. Thank you for reply, but as per the ZATCA requirement the QRCode Values should be encoded in TLV format and then HEX and then to base64 format

      Delete
    3. Hi,
      I don't think so, For Phase 1 implementation.
      If you have any document/article from ZATCA.Please share.
      Thanks,
      Syed Faiz Abbas

      Delete
    4. Pls check your email on faizabbas@outlook.com. i sent the document which was shared by Zatka recently fyi.

      Delete
    5. I will check the document.
      Thanks,
      Syed Faiz Abbas

      Delete
    6. I hope you have gone through the document. Just eager to know that you are going to update or not this requirement in the Messaging Toolkit DLL?

      Delete
    7. Yes, Not yet.

      Thanks,
      Syed Faiz Abbas

      Delete
  14. Hi Syed, Thanks for this valuable post, Do we need to follow same procedure for D365FO as well?

    ReplyDelete
  15. Hi Noor,

    You can go through below link.
    https://dynamicsax-fico.com/2020/08/19/do-you-know-how-to-embed-qr-payment-codes-in-customer-invoices/

    regards,
    Syed Faiz Abbas

    ReplyDelete
  16. Hi Syed, I have a question about D365's capabilities to meet any Arabic language requirements with regards to printing reports. Reports such as VAT, WHT, and other ZAKAT specific reports. Some of these reports are only available with the (SA) localization. For example, in the Tax module I have the option to print a "Saudi Arabia monthly withholding tax report." This is an SSRS report that comes pre-formatted, and even has a unique logo I assume represents their sales tax authority. However, I am unable to print this report in Arabic. I have tried changing the my user language and the legal entity language, but it only prints in English.

    I'm helping roll out a new legal entity for a company that's going to do business in Saudi Arabia, and I would imagine these reports must be submitted to authorities in Arabic. Perhaps I'm missing something, but wouldn't a report specifically made for Saudi Arabia have a translation component to it?

    ReplyDelete

Error The total, internal size of the records in your joined SELECT statement is XXXXX bytes

 Hi Friends, Today users getting error while creating new Vendor in AX 2012 R3. When I was investigating I found that this is due to user Us...