Function Cancel Invoice on Delivery of Goods
Function Cancel Tax Invoice on Delivery of Goods (codeunit 4046898 "API Cancel Fin. Cont. Del. G.") finds the last posted tax document (posted sales invoice or credit note) for the given Financing Contract and generates and posts a reverse correction document according to the following rules:
-
After confirming the decision message "Do you really want to cancel the last VAT document on contract no. % when the goods are delivered?" the system checks whether there are any items on the contract some unposted Calculation inputs with Calc. Variant Input = VAT - Supply of Goods:
-
if there are unposted calculation inputs, the task ends with the error message "There are unposted calc. Inputs with code VAT_TFL for contract for supply of goods No. %."
-
If they don't exist, the job continues
-
-
The system searches for posted calculation inputs with the following variant:
-
if no such calculation input exists, the task ends with the error message "There are no posted calculation inputs with a code of type VAT_TFL on contract No. %! There's nothing to cancel!"
-
if they exist, the task finds the calculation input with the highest line number (Line no.), which has not yet been reversed (Reversed upon delivery of goods = No) and according to the document number of this calculation input it further filters all calculation inputs for this document
-
-
The following will be cancelled for the calculation inputs found:
-
The system creates new calculation inputs by copying the original calculation inputs, but with the opposite sign in the amount fields (Base Amount, VAT Amount, etc.), sets the default data of unposted calculation inputs and adds:
-
Reverse Record Line No. = Line numbers from the original calculation input
-
Delivery Calculation Input Type = Reverse
-
-
After creating these reverse calculation inputs, it runs the function for posting the document for VAT on shipment of goods, which posts the reverse calculation inputs, resulting in a Posted Sales Credit Memo
(Note: If a negative calculation input or a document of the Credit Memo type is cancelled, the result is Posted Sales Invoice - Debit Note) -
If the document number in the Document No. - Tax Invoice upon Delivery of Goods is the same as the reversed document number on the contract header, deletes this document number from the contract header and sets flag Delivery Tax Document Cancelled = Yes, Delivery Tax Invoice Posted = No.
-
-
The process is terminated by the informative message "The last document with VAT on the delivery of goods on contract No. % has been cancelled"
-
If new calculation inputs are generated during the recalculation after cancellation, their Date of entry into the calculation is determined by the standard logic for determining this date when generating the calculation input (function SetDates in table 4026450 "API Contract Calculation Input") and the follow-up function GetTransferStartingDate in codeunit 4046864 "API Change Contract Automation"
Corrective Tax Invoice - Credit Memo
The fields are filled in in a similar way as for the initial VAT invoice, see Faktura na DPH při dodání zboží | Faktura na DPH při dodání zboží (při aktivaci smlouvy) , with the following differences:
-
Credit Memo Header
-
Due Date = Working Date
-
Credit Memo Type = Credit Memo
-
Bank Account Code = Customer Bank Account Code from the Financing Contract header; if it is empty or does not exist, then the Preferred Bank Account Code from the Customer Card; If it is empty, then no bank account will be filled
-
-
Credit Memo Lines
-
On the second line for the given calculation input (reverse of the tax base from the first line), the VAT product posting group from the contract header from the field is used VAT Prod. Posting Group Payments on Delivery of Goods - Corrective Document
-
Calculation outputs after cancellation
Changes in calculation inputs after successfully posted cancellation:
-
Original Calculation input with VAT variant - delivery of goods after cancellation:
-
Calculation Input Posted = Yes (does not change)
-
Reversed on delivery = Yes
-
Reverse Record Line No. = 0
-
-
A new Calculation Input with variant VAT - delivery of goods (reverse) is created by copying the original cancelled calculation input and modifying the fields
-
Base Amount = Same Amount, Opposite Sign
-
VAT Amount = Same Amount, Opposite Sign
-
Calculation Input Posted = Yes
-
Reversed on delivery = No
-
Row number of reversed record = Row number copied from the original cancelled calculation input
-
Financing Contract Header After Cancellation
-
Document No. - Tax Invoice upon Delivery of Goods = Primary Document No. is deleted
-
Delivery Invoice Posted = No
-
Tax document cancelled upon delivery of goods = Yes
Note: Document numbers (both the initial invoice and the corrective credit note) are available on the Calculation Input card
Customer ledger entries after cancellation
-
A credit memo is posted
-
If the original invoice was open, the credit memo is automatically applied to that invoice