Skip to content

Create new events in Codeunit 10750 ‘SII XML Creator’ #29586

@NekaneBachillerMayoral

Description

@NekaneBachillerMayoral

Why do you need this change?

Invoices corresponding to work certifications are considered advance payments, and for the advance payment to accrue VAT, you must wait for payment/collection of the same (or the first payment/collection).
Invoices for work certifications with a future due date are not even considered invoices until the moment of their first payment, whether partial or total. The AEAT (Spanish Tax Agency) states that invoices can be sent with code 14 and that the final invoice should be sent when payment is received.
The reality is that only one invoice is issued, and it must be sent at the time of payment/collection and not before. In other words, if a certification invoice is issued for both sales and purchases, it is not sent to the AEAT, and only when payment/collection occurs is the invoice sent, but with the date of collection/payment. If there are several payments for that invoice, everything is sent at the time of the first payment.


Describe the request

In codeunit 10750 ΓÇÿSII XML CreatorΓÇÖ, events that allow us to manipulate the 'FechaExpedicionFacturaEmisor', 'FechaOperacion', and corresponding tax period 'Ejercicio' and 'Periodo' (since payment/collection may occur in a tax period other than that of the invoice) in all cases of certification documents just before generating the corresponding node in the XML document (Invoices, Credits, Document Corrections).

We need to modify this procedure with a function that allows us to modify the document date

XMLDOMManagement.AddElementWithPrefix(
XMLNode, ΓÇ£IssuerInvoiceIssueDateΓÇ¥, FormatDate(VendorLedgerEntry.ΓÇÿDocument DateΓÇÖ), ΓÇ£siiΓÇ¥, SiiTxt, TempXMLNode);

XMLDOMManagement.AddElementWithPrefix(
XMLNode, ΓÇ£IssuerInvoiceIssueDateΓÇ¥, GetPurchaseExpeditionDate(VendorLedgerEntry), ΓÇ£siiΓÇ¥, SiiTxt, TempXMLNode);

**_local procedure GetPurchaseExpeditionDate(VendorLedgerEntry: Record "Vendor Ledger Entry"): Text
var
    PostingDate: Date;
begin
    PostingDate := VendorLedgerEntry."Document Date";
    OnAfterGetPurchaseExpeditionDate(VendorLedgerEntry, PostingDate);
    exit(FormatDate(PostingDate));
end;_**

in the following procedures:

  • CreateEmittedPaymentsXml
  • PopulateXMLWithPurchInvoice
  • InitializeCorrectiveRemovalXmlBody
  • HandleReplacementPurchCorrectiveInvoice
  • HandleNormalPurchCorrectiveInvoice

In calls to the GenerateFacturasRectificadasNode procedure, we need to use functions to manipulate dates in both sales and purchase functions:

**_local procedure GetRectificadasSalesExpeditionDate(CustLedgerEntry: Record "Cust. Ledger Entry"): Text
var
PostingDate: Date;
begin
PostingDate := CustLedgerEntry."Posting Date";
OnAfterGetSalesRectificadasExpeditionDate(CustLedgerEntry, PostingDate);
exit(FormatDate(PostingDate));
end;

local procedure GetRectificadasPurchaseExpeditionDate(VendorLedgerEntry: Record "Vendor. Ledger Entry"): Text
var
PostingDate: Date;
begin
PostingDate := VendorLedgerEntry."Posting Date";
OnAfterGetPurchaseRectificadasExpeditionDate(VendorLedgerEntry, PostingDate);
exit(FormatDate(PostingDate));
end;_**

With this, calls to this procedure would be as follows:

In the CorrectiveInvoiceSalesDifference procedure, the call would be:
GenerateCorrectiveInvoicesNode(XMLNode, OldCustLedgerEntry.ΓÇÿDocument No.ΓÇÖ, GetCorrectiveSalesExpeditionDate(OldCustLedgerEntry));

In the HandleReplacementPurchCorrectiveInvoice procedure, the call would be:
GenerateFacturasRectificadasNode(XMLNode, OldVendorLedgerEntry.ΓÇÿExternal Document No.ΓÇÖ, GetRectificadasPurchaseExpeditionDate(OldVendorLedgerEntry));

In the HandleNormalPurchCorrectiveInvoice procedure, the call would be:
GenerateFacturasRectificadasNode(XMLNode, OldVendorLedgerEntry.ΓÇÿExternal Document No.ΓÇÖ, GetRectificadasPurchaseExpeditionDate(OldVendorLedgerEntry));

In the HandleReplacementSalesCorrectiveInvoice procedure, the call would be
GenerateCorrectiveInvoicesNode(XMLNode, OldCustLedgerEntry.ΓÇÿDocument No.ΓÇÖ, GetCorrectiveSalesExpeditionDate(OldCustLedgerEntry));

In the FillFechaOperacion procedure, we need an event in the else clause of the Case to handle new options from the ΓÇÿSII Operation Date TypeΓÇÖ Enum.

    case SIISetup."Operation Date" of
        SIISetup."Operation Date"::"Posting Date":
            begin
                if ((LastShptRcptDate = 0D) or (LastShptRcptDate = PostingDate)) and
                not (IsSales and RegimeCodesContainsValue(RegimeCodes, '14'))
                then
                    exit;

                if LastShptRcptDate > WorkDate() then
                    LastShptRcptDate := PostingDate;
                if IsSales then begin
                    if not IncludeFechaOperationForSales(PostingDate, LastShptRcptDate, RegimeCodes) then
                        exit;
                    if IsShptDateMustBeAfterPostingDate(RegimeCodes) then
                        LastShptRcptDate := PostingDate + 1;
                end;
            end;
        SIISetup."Operation Date"::"Document Date":
            begin
                if PostingDate = DocumentDate then
                    exit;
                LastShptRcptDate := DocumentDate;
            end;
        SIISetup."Operation Date"::"VAT Reporting Date":
            begin
                if PostingDate = VATDate then
                    exit;
                LastShptRcptDate := VATDate;
            end
      **else
        OnOtherOperationDate(LastShptRcptDate,PostingDate,RegimeCodes)

**
end;

**[IntegrationEvent(false, false)]
local procedure OnOtherOperationDate(var LastShptRcptDate,var PostingDate,RegimeCodes: array[3] of Code[2])
begin
end;**

Internal work item: AB#618054

Metadata

Metadata

Assignees

No one assigned

    Labels

    FinanceGitHub request for Finance areaevent-requestRequest for adding an event

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions