Changes in code for posting documents
In some countries the law requires companies to send information about posted documents to a legal authority ( eg. like IRS in the US )
Two of the most critical aspects of this requirements are: a) a document must not be reported if it will not be posted ( suppresscommit, previewmode, error, ... ) b) a certain part of the web-service response must be printed on an invoice
OnAfterPostSalesDoc event in CU80 appears to be in a very good spot for this, but there is no guarantee that what the subscriber receives will actually become a posted document.
We have tried hard to find a workaround, but we think there needs to be a more general solution to this problem.
We could insert a commit call, but while this would ensure that this document gets posted, it would also introduce all kinds of side-effects.
We need some mechanism that would trigger an event for each document that was actually posted.
We have tried doing it in a separate session via StartSession, but in order to prevent reading uncommited documents we would need to use some sort of locking. If we do that, then we run into issues with the first session that needs to wait for results. The results have to be printed on the document if Post & Print is used.
We believe this should be an event we could subscribe to, but preferably this would be one event publisher for all documents that get posted.
We would gladly accept any other alternatives.
Hi @gregoral, thanks for filing this issue. I will transfer this issue to the app repository, which might be able to help you.
More than a moth has passed and there are no responses. This is still an issue. In some countries companies have to ( by law ) send data about some of the issued invoices to a government server and print a government issued response string on the printed invoice.
It is not acceptable to send data about an invoice before that invoice is actually posted. ( there are no errors or there is a commit before the error is thrown )
On top of that these invoices might need a separate No.Series, since gaps in the issued invoice number series for such invoices might not be allowed ( mandated by law in some countries ).
Is there a way to do this reliably? Thank you
This request in not valid for this forum. First of all you need to know what you have Posted Documents and these documents needs to be sent to authorities. We have special team for legal requirements, if you have it please be explicit about country code and reference to legal requirement. If there is a gap, we will fix it on our side.
We have special team for legal requirements
Please forward their contact information. Microsoft also has an office in Slovenia, maybe you can forward this to their legal department for verification.
Affected countries: Slovenia, Croatia, Serbia, Italy and potentially more. The summary: Companies have to obtain a code from tax authority webservice on some or potentially all sales invoices.
This verification code is based on invoice Amount, Issuer information and more. If an invoice is printed this code must be on the printed invoice. The procedure uses public key cryptography, digital signatures, hashing functions, TLS sessions, ... Both the client and the server identify with digital certificates.
So before any sales invoice is printed a UniqueInvoiceID must be obtained from a government WebService and printed on the issued sales invoice ( in text form and as QR code ).
Here is a link to bilingual technical specification for Slovenia, published by Slovenian Ministry of Finance. http://www.datoteke.fu.gov.si/dpr/files/TehnicnaDokumentacijaVer1.9.pdf
This presents a problem especially when users post documents using Post+Print.
We have added subscribers to several events in CU 80. For instance this one: Sales-Post :: OnAfterPostSalesDoc
This event appears to be in the "right place" and has the required parameters. SalesInvHdrNo for the posted "Sales Invoice Header" is the most important one.
But unfortunately this event does not guarantee that an invoice will actually get posted!
This is the code from CU 80 ( I have ommited a few un-importatnt details for clarity):
IF NOT (InvtPickPutaway OR SuppressCommit) THEN COMMIT; OnAfterPostSalesDoc(...)
So if we're in the middle of InvtPickPutaway our subscriber does not receive this information at all. And when SuppressCommit is used we can only hope the invoice will be posted later in the cycle.
We cannot wait until the invoice is printed, since data for all invoices that meet certain criteria has to be sent to tax authority even if the invoice is not printed at all or is printed sometime later.
Under normal circumstances sales invoices must be sent to tax authority in the same order as they are issued.
Eg: if invoices INV-01, INV-02 and INV-03 are issued we have to send them to tax authority in the same order sending INV-01 then INV-03 and maybe sometime later also INV-02 is not allowed
Printing an invoice before sending it to tax authority is only allowed in extreme circumstances ( eg. loss of internet connectivity ). All such invoices must be marked with ( late fiscalization flag ) and reported to tax auth webservice as soon as possible ( eg. internet conectivity is restored ).
Sending an invoice to tax authority before commit is not an option, since this would be illegal if the sales invoice is later not issued for some reason.
So a reliable event that happens after commit and before print for all sales invoices is needed. What are we supposed to do or how can this issue be solved?
Hi @gregoral I am in the team that is driving our localization efforts. We monitor country legislation through partners and have not heard of the requirement yuo mention. Would it be possible for you to send a link to the legislation describing this requirement for Italy specifically? Of the countries you mention, Italy is the only one localized by Microsoft. Then we can investigate if we have a gap in the Itaian localization. Thanks Søren
Hello Søren, I have to admit I don't have complete information for Italy. According to the information I have fiscal regulation in Italy was introduced in 1983.
I don't know the exact details for Italy, I just wanted to point out that several countries have introduced regulation related to sales invoices and Italy is one of those.
Sorry for not describing it in a more precise way, Gregor
So a reliable event that happens after commit and before print for all sales invoices is needed. What are we supposed to do or how can this issue be solved?
Hi @gregoral As you said there is OnAfterPostSalesDoc() right after commit and it includes SuppressCommit parameter. So you can control missed COMMIT by tracking SuppressCommit.
The second part is related to InvtPickPutaway. If we add it as the last parameter to OnAfterPostSalesDoc() you will know that document is not committed.
if not (InvtPickPutaway or SuppressCommit) then begin
Commit;
UpdateAnalysisView.UpdateAll(0, true);
UpdateItemAnalysisView.UpdateAll(0, true);
end;
OnAfterPostSalesDoc(
Rec, GenJnlPostLine, SalesShptHeader."No.", ReturnRcptHeader."No.", SalesInvHeader."No.",
SalesCrMemoHeader."No.", SuppressCommit, **InvtPickPutaway**);
To cover it completely we need another event in codeunit 7324 "Whse.-Activity-Post". There is one - OnAfterCode() in local procedure "Code", but it is called right before COMMIT.
Hence we can add another event right after COMMIT e.g. OnAfterPostWhseActivity(WhseActivHeader).
OnAfterCode(WhseActivLine);
Commit;
**OnAfterPostWhseActivity(WhseActivHeader).**
Clear(WhseJnlRegisterLine);
Would it be enough to control if the sales document is really posted?
We'll proceed as per Stan's suggestion, as agreed on the call.