Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Event Request] codeunit 10750 "SII XML Creator" - Procedure PopulateXMLWithPurchInvoice- OnBeforePurchInvoiceAddNodeForTotals #28307

Open
CcamanIT opened this issue Mar 4, 2025 · 0 comments
Labels
extensibility-enhancement New feature or request related to extensibility Finance GitHub request for Finance area

Comments

@CcamanIT
Copy link

CcamanIT commented Mar 4, 2025

Describe the request

Please add an Event OnBeforePurchInvoiceAddNodeForTotals in the procedure PopulateXMLWithPurchInvoice in Codeunit 10750 "SII XML Creator"

local procedure PopulateXMLWithPurchInvoice(XMLNode: DotNet XmlNode; VendorLedgerEntry: Record "Vendor Ledger Entry"): Boolean
    var
        SIIDocUploadState: Record "SII Doc. Upload State";
        TempVATEntryNormalCalculated: Record "VAT Entry" temporary;
        TempVATEntryReverseChargeCalculated: Record "VAT Entry" temporary;
        VATEntry: Record "VAT Entry";
        Vendor: Record Vendor;
        TempXMLNode: DotNet XmlNode;
        VendorLedgerEntryRecRef: RecordRef;
        AddNodeForTotals: Boolean;
        ECVATEntryExists: Boolean;
        CuotaDeducibleValue: Decimal;
        TotalBase: Decimal;
        TotalNonExemptBase: Decimal;
        TotalVATAmount: Decimal;
        TotalAmount: Decimal;
        InvoiceType: Text;
        RegimeCodes: array[3] of Code[2];
        VendNo: Code[20];
        IsHandled: Boolean;
    begin
        Vendor.Get(VendorLedgerEntry."Vendor No.");
        DataTypeManagement.GetRecordRef(VendorLedgerEntry, VendorLedgerEntryRecRef);

        SIIDocUploadState.GetSIIDocUploadStateByVendLedgEntry(VendorLedgerEntry);
        if IsPurchInvoice(InvoiceType, SIIDocUploadState) then begin
            VendNo := SIIManagement.GetVendFromLedgEntryByGLSetup(VendorLedgerEntry);
            InitializePurchXmlBody(
              XMLNode, VendNo, VendorLedgerEntry, SIIDocUploadState.IDType, SIIDocUploadState);

            XMLDOMManagement.AddElementWithPrefix(
              XMLNode, 'NumSerieFacturaEmisor', Format(VendorLedgerEntry."External Document No."), 'sii', SiiTxt, TempXMLNode);
            XMLDOMManagement.AddElementWithPrefix(
              XMLNode, 'FechaExpedicionFacturaEmisor', FormatDate(VendorLedgerEntry."Document Date"), 'sii', SiiTxt, TempXMLNode);
            XMLDOMManagement.FindNode(XMLNode, '..', XMLNode);
            XMLDOMManagement.AddElementWithPrefix(XMLNode, 'FacturaRecibida', '', 'siiLR', SiiLRTxt, XMLNode);

            if InvoiceType = '' then
                XMLDOMManagement.AddElementWithPrefix(XMLNode, 'TipoFactura', 'F1', 'sii', SiiTxt, TempXMLNode)
            else
                XMLDOMManagement.AddElementWithPrefix(
                  XMLNode, 'TipoFactura', InvoiceType, 'sii', SiiTxt, TempXMLNode);

            GenerateNodeForFechaOperacionPurch(XMLNode, VendorLedgerEntry);
            GetClaveRegimenNodePurchases(RegimeCodes, SIIDocUploadState, VendorLedgerEntry, Vendor);
            GenerateClaveRegimenNode(XMLNode, RegimeCodes);
            if SIIManagement.FindVatEntriesFromLedger(VendorLedgerEntryRecRef, VATEntry) then
                repeat
                    CalculatePurchVATEntries(
                      TempVATEntryNormalCalculated, TempVATEntryReverseChargeCalculated,
                      CuotaDeducibleValue, VATEntry,
                      VendNo, VendorLedgerEntry."Posting Date", InvoiceType);
                    ECVATEntryExists := ECVATEntryExists or (VATEntry."EC %" <> 0);
                until VATEntry.Next() = 0;

            AddNodeForTotals :=
              IncludeImporteTotalNode() and
              ((InvoiceType in [GetF2InvoiceType(), 'F4']) and
               (TempVATEntryNormalCalculated.Count + TempVATEntryReverseChargeCalculated.Count = 1)) or
              (SIIDocUploadState."Purch. Special Scheme Code" in [SIIDocUploadState."Purch. Special Scheme Code"::"03 Special System",
                                                                  SIIDocUploadState."Purch. Special Scheme Code"::"05 Travel Agencies"]);
            CalculateTotalVatAndBaseAmounts(VendorLedgerEntryRecRef, TotalBase, TotalNonExemptBase, TotalVATAmount);

            //+ Event
            OnBeforePurchInvoiceAddNodeForTotals(AddNodeForTotals,VendorLedgerEntry,TotalBase,TotalNonExemptBase,TotalVATAmount);
            //- Event

            if AddNodeForTotals then begin
                TotalAmount := TotalBase + TotalVATAmount;
                XMLDOMManagement.AddElementWithPrefix(
                  XMLNode, 'ImporteTotal', FormatNumber(TotalAmount), 'sii', SiiTxt, TempXMLNode);
            end;
            FillBaseImponibleACosteNode(XMLNode, RegimeCodes, TotalNonExemptBase);

            FillOperationDescription(
              XMLNode, GetOperationDescriptionFromDocument(false, VendorLedgerEntry."Document No."),
              VendorLedgerEntry."Posting Date", VendorLedgerEntry.Description);
            FillRefExternaNode(XMLNode, Format(SIIDocUploadState."Entry No"));
            FillSucceededCompanyInfo(XMLNode, SIIDocUploadState);
            if AddNodeForTotals then
                FillMacrodatoNode(XMLNode, TotalAmount);

            XMLDOMManagement.AddElementWithPrefix(XMLNode, 'DesgloseFactura', '', 'sii', SiiTxt, XMLNode);

            IsHandled := false;
            OnPopulateXMLWithPurchInvoiceOnBeforeDesgloseFacturaNode(
                XMLNode, TempVATEntryNormalCalculated, 'DesgloseIVA', RegimeCodes, VendorLedgerEntry, SiiTxt, IsHandled, TempVATEntryNormalCalculated, TempVATEntryReverseChargeCalculated);
            if not IsHandled then begin
                AddPurchVATEntriesWithElement(XMLNode, TempVATEntryReverseChargeCalculated, 'InversionSujetoPasivo', RegimeCodes);
                FillNoTaxableVATEntriesPurch(TempVATEntryNormalCalculated, VendorLedgerEntry);
                AddPurchVATEntriesWithElement(XMLNode, TempVATEntryNormalCalculated, 'DesgloseIVA', RegimeCodes);
            end;

            XMLDOMManagement.FindNode(XMLNode, '..', XMLNode);

            AddPurchTail(
              XMLNode, VendorLedgerEntry."Posting Date", GetRequestDateOfSIIHistoryByVendLedgEntry(VendorLedgerEntry),
              VendNo, CuotaDeducibleValue, SIIDocUploadState.IDType, RegimeCodes, ECVATEntryExists, InvoiceType,
              not TempVATEntryReverseChargeCalculated.IsEmpty(), SIIDocUploadState);

            OnAfterAddPurchTail(XMLNode, VendorLedgerEntry);

            exit(true);
        end;

        // corrective invoice
        exit(HandleCorrectiveInvoicePurchases(XMLNode, SIIDocUploadState, VendorLedgerEntry, Vendor));
    end;

//+ Integration Event
[IntegrationEvent(false, false)]
procedure OnBeforeSalesInvoiceAddNodeForTotals(var AddNodeForTotals: Boolean; VendorLedgerEntry: Record "Vendor Ledger Entry";var TotalBase: Decimal; var TotalNonExemptBase: Decimal; var TotalVATAmount: Decimal)
begin
end;
//- Integration Event

Additional context

This event would allow to check the totals and to send to the SII purch invoices.
Internal work item: AB#568208

@AndersLarsenMicrosoft AndersLarsenMicrosoft added extensibility-enhancement New feature or request related to extensibility Finance GitHub request for Finance area labels Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extensibility-enhancement New feature or request related to extensibility Finance GitHub request for Finance area
Projects
None yet
Development

No branches or pull requests

2 participants