Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/Apps/W1/PEPPOL/App/src/Common/PEPPOL30.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -1057,5 +1057,23 @@ codeunit 37200 "PEPPOL30" implements "PEPPOL Attachment Provider"
exit(PEPPOLManagementImpl.MapServiceLineTypeToSalesLineType(ServiceLineType));
end;


/// <summary>
/// Gets allowance charge information for payment discounts from VAT amount line and sales header.
/// </summary>
/// <param name="VATAmtLine">The VAT amount line record containing allowance charge information.</param>
/// <param name="SalesHeader">The sales header record.</param>
/// <param name="ChargeIndicator">Returns the charge indicator.</param>
/// <param name="AllowanceChargeReasonCode">Returns the allowance charge reason code.</param>
/// <param name="AllowanceChargeListID">Returns the allowance charge list ID.</param>
/// <param name="AllowanceChargeReason">Returns the allowance charge reason.</param>
/// <param name="Amount">Returns the amount.</param>
/// <param name="AllowanceChargeCurrencyID">Returns the allowance charge currency ID.</param>
/// <param name="TaxCategoryID">Returns the tax category ID.</param>
/// <param name="TaxCategorySchemeID">Returns the tax category scheme ID.</param>
/// <param name="Percent">Returns the percent.</param>
/// <param name="AllowanceChargeTaxSchemeID">Returns the allowance charge tax scheme ID.</param>
procedure GetAllowanceChargeInfoPaymentDiscount(VATAmtLine: Record "VAT Amount Line"; SalesHeader: Record "Sales Header"; var ChargeIndicator: Text; var AllowanceChargeReasonCode: Text; var AllowanceChargeListID: Text; var AllowanceChargeReason: Text; var Amount: Text; var AllowanceChargeCurrencyID: Text; var TaxCategoryID: Text; var TaxCategorySchemeID: Text; var Percent: Text; var AllowanceChargeTaxSchemeID: Text)
begin
PEPPOLManagementImpl.GetAllowanceChargeInfoPaymentDiscount(VATAmtLine, SalesHeader, ChargeIndicator, AllowanceChargeReasonCode, AllowanceChargeListID, AllowanceChargeReason, Amount, AllowanceChargeCurrencyID, TaxCategoryID, TaxCategorySchemeID, Percent, AllowanceChargeTaxSchemeID);
end;
}
38 changes: 31 additions & 7 deletions src/Apps/W1/PEPPOL/App/src/Common/PEPPOL30Impl.Codeunit.al
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ codeunit 37201 "PEPPOL30 Impl."
SalespersonTxt: Label 'Salesperson';
UoMforPieceINUNECERec20ListIDTxt: Label 'EA', Locked = true;
VATTxt: Label 'VAT', Locked = true;
PaymentDisAmtTxt: Label 'Payment Discount Amount';
AllowanceChargePaymentDiscountReasonCodeTxt: Label '95', Locked = true;

procedure GetGeneralInfo(SalesHeader: Record "Sales Header"; var ID: Text; var IssueDate: Text; var InvoiceTypeCode: Text; var InvoiceTypeCodeListID: Text; var Note: Text; var TaxPointDate: Text; var DocumentCurrencyCode: Text; var DocumentCurrencyCodeListID: Text; var TaxCurrencyCode: Text; var TaxCurrencyCodeListID: Text; var AccountingCost: Text)
var
Expand Down Expand Up @@ -676,7 +678,7 @@ codeunit 37201 "PEPPOL30 Impl."
var
GLSetup: Record "General Ledger Setup";
begin
TaxableAmount := Format(VATAmtLine."VAT Base", 0, 9);
TaxableAmount := Format(VATAmtLine."VAT Base" - VATAmtLine."Pmt. Discount Amount", 0, 9);
TaxAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
SubtotalTaxAmount := Format(VATAmtLine."VAT Amount", 0, 9);
TaxSubtotalCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
Expand Down Expand Up @@ -737,13 +739,13 @@ codeunit 37201 "PEPPOL30 Impl."
Format(VATAmtLine."Amount Including VAT" - Round(VATAmtLine."Amount Including VAT", 0.01), 0, 9);
PayableRndingAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);

PayableAmount := Format(Round(VATAmtLine."Amount Including VAT", 0.01), 0, 9);
PayableAmount := Format(Round(VATAmtLine."Amount Including VAT" - VATAmtLine."Pmt. Discount Amount", 0.01), 0, 9);
PayableAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
end else begin
PayableRoundingAmount := Format(TempSalesLine."Amount Including VAT", 0, 9);
PayableRndingAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);

PayableAmount := Format(Round(VATAmtLine."Amount Including VAT" + TempSalesLine."Amount Including VAT", 0.01), 0, 9);
PayableAmount := Format(Round(VATAmtLine."Amount Including VAT" + TempSalesLine."Amount Including VAT" - VATAmtLine."Pmt. Discount Amount", 0.01), 0, 9);
PayableAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
end;
end;
Expand All @@ -753,13 +755,13 @@ codeunit 37201 "PEPPOL30 Impl."
LineExtensionAmount := Format(Round(VATAmtLine."VAT Base", 0.01) + Round(VATAmtLine."Invoice Discount Amount", 0.01), 0, 9);
LegalMonetaryTotalCurrencyID := GetSalesDocCurrencyCode(SalesHeader);

TaxExclusiveAmount := Format(Round(VATAmtLine."VAT Base", 0.01), 0, 9);
TaxExclusiveAmount := Format(Round(VATAmtLine."VAT Base" - VATAmtLine."Pmt. Discount Amount", 0.01), 0, 9);
TaxExclusiveAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);

TaxInclusiveAmount := Format(Round(VATAmtLine."Amount Including VAT", 0.01, '>'), 0, 9); // Should be two decimal places
TaxInclusiveAmount := Format(Round(VATAmtLine."Amount Including VAT" - VATAmtLine."Pmt. Discount Amount", 0.01, '>'), 0, 9); // Should be two decimal places
TaxInclusiveAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);

AllowanceTotalAmount := Format(Round(VATAmtLine."Invoice Discount Amount", 0.01), 0, 9);
AllowanceTotalAmount := Format(Round(VATAmtLine."Invoice Discount Amount" + VATAmtLine."Pmt. Discount Amount", 0.01), 0, 9);
AllowanceTotalAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
TaxInclusiveAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);

Expand All @@ -768,11 +770,14 @@ codeunit 37201 "PEPPOL30 Impl."
end;

procedure GetLineGeneralInfo(SalesLine: Record "Sales Line"; SalesHeader: Record "Sales Header"; var InvoiceLineID: Text; var InvoiceLineNote: Text; var InvoicedQuantity: Text; var InvoiceLineExtensionAmount: Text; var LineExtensionAmountCurrencyID: Text; var InvoiceLineAccountingCost: Text)
var
SalesLineLineAmount: Decimal;
begin
InvoiceLineID := Format(SalesLine."Line No.", 0, 9);
InvoiceLineNote := DelChr(Format(SalesLine.Type), '<>');
InvoicedQuantity := Format(SalesLine.Quantity, 0, 9);
InvoiceLineExtensionAmount := Format(SalesLine."VAT Base Amount" + SalesLine."Inv. Discount Amount", 0, 9);
SalesLineLineAmount := SalesLine."Line Amount";
InvoiceLineExtensionAmount := Format(SalesLineLineAmount, 0, 9);
LineExtensionAmountCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
InvoiceLineAccountingCost := '';
end;
Expand Down Expand Up @@ -1337,4 +1342,23 @@ codeunit 37201 "PEPPOL30 Impl."
exit("Sales Line Type"::"G/L Account");
end;
end;

procedure GetAllowanceChargeInfoPaymentDiscount(VATAmtLine: Record "VAT Amount Line"; SalesHeader: Record "Sales Header"; var ChargeIndicator: Text; var AllowanceChargeReasonCode: Text; var AllowanceChargeListID: Text; var AllowanceChargeReason: Text; var Amount: Text; var AllowanceChargeCurrencyID: Text; var TaxCategoryID: Text; var TaxCategorySchemeID: Text; var Percent: Text; var AllowanceChargeTaxSchemeID: Text)
begin
if VATAmtLine."Pmt. Discount Amount" = 0 then begin
ChargeIndicator := '';
exit;
end;

ChargeIndicator := 'false';
AllowanceChargeReasonCode := AllowanceChargePaymentDiscountReasonCodeTxt;
AllowanceChargeListID := GetUNCL4465ListID();
AllowanceChargeReason := PaymentDisAmtTxt;
Amount := Format(VATAmtLine."Pmt. Discount Amount", 0, 9);
AllowanceChargeCurrencyID := GetSalesDocCurrencyCode(SalesHeader);
TaxCategoryID := VATAmtLine."Tax Category";
TaxCategorySchemeID := '';
Percent := Format(VATAmtLine."VAT %", 0, 9);
AllowanceChargeTaxSchemeID := VATTxt;
end;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Microsoft.Peppol;

using Microsoft.Sales.Document;
using Microsoft.Finance.VAT.Calculation;

interface "PEPPOL Payment Info Provider"
{
Expand Down Expand Up @@ -58,4 +59,21 @@ interface "PEPPOL Payment Info Provider"
/// <param name="SalesHeader">The sales header record.</param>
/// <param name="PaymentTermsNote">Return value: Payment terms note.</param>
procedure GetPaymentTermsInfo(SalesHeader: Record "Sales Header"; var PaymentTermsNote: Text)

/// <summary>
/// Gets allowance charge information for payment discounts from VAT amount line and sales header.
/// </summary>
/// <param name="VATAmtLine">The VAT amount line record containing allowance charge information.</param>
/// <param name="SalesHeader">The sales header record.</param>
/// <param name="ChargeIndicator">Returns the charge indicator.</param>
/// <param name="AllowanceChargeReasonCode">Returns the allowance charge reason code.</param>
/// <param name="AllowanceChargeListID">Returns the allowance charge list ID.</param>
/// <param name="AllowanceChargeReason">Returns the allowance charge reason.</param>
/// <param name="Amount">Returns the amount.</param>
/// <param name="AllowanceChargeCurrencyID">Returns the allowance charge currency ID.</param>
/// <param name="TaxCategoryID">Returns the tax category ID.</param>
/// <param name="TaxCategorySchemeID">Returns the tax category scheme ID.</param>
/// <param name="Percent">Returns the percent.</param>
/// <param name="AllowanceChargeTaxSchemeID">Returns the allowance charge tax scheme ID.</param>
procedure GetAllowanceChargeInfoPaymentDiscount(VATAmtLine: Record "VAT Amount Line"; SalesHeader: Record "Sales Header"; var ChargeIndicator: Text; var AllowanceChargeReasonCode: Text; var AllowanceChargeListID: Text; var AllowanceChargeReason: Text; var Amount: Text; var AllowanceChargeCurrencyID: Text; var TaxCategoryID: Text; var TaxCategorySchemeID: Text; var Percent: Text; var AllowanceChargeTaxSchemeID: Text)
}
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,93 @@ xmlport 37200 "Sales Cr.Memo - PEPPOL30"
currXMLport.Skip();
end;
}
tableelement(allowancechargepaymentdiscountloop; Integer)
{
NamespacePrefix = 'cac';
XmlName = 'AllowanceCharge';
SourceTableView = sorting(Number) where(Number = filter(1 ..));
textelement(ChargeIndicatorPaymentDiscount)
{
XmlName = 'ChargeIndicator';
NamespacePrefix = 'cbc';
}
textelement(AllowanceChargeReasonCodePaymentDiscount)
{
XmlName = 'AllowanceChargeReasonCode';
NamespacePrefix = 'cbc';
}
textelement(AllowanceChargeReasonPaymentDiscount)
{
XmlName = 'AllowanceChargeReason';
NamespacePrefix = 'cbc';
}
textelement(AmountPaymentDiscount)
{
XmlName = 'Amount';
NamespacePrefix = 'cbc';
textattribute(allowancechargecurrencyidPaymentDiscount)
{
XmlName = 'currencyID';
}
}
textelement(TaxCategoryPaymentDiscount)
{
XmlName = 'TaxCategory';
NamespacePrefix = 'cac';
textelement(taxcategoryidPaymentDiscount)
{
NamespacePrefix = 'cbc';
XmlName = 'ID';
}
textelement(PercentPaymentDiscount)
{
XmlName = 'Percent';
NamespacePrefix = 'cbc';

trigger OnBeforePassVariable()
begin
if PercentPaymentDiscount = '' then
currXMLport.Skip();
end;
}
textelement(TaxSchemePaymentDiscount)
{
XmlName = 'TaxScheme';
NamespacePrefix = 'cac';
textelement(allowancechargetaxschemeidPaymentDiscount)
{
NamespacePrefix = 'cbc';
XmlName = 'ID';
}
}
}

trigger OnAfterGetRecord()
var
PEPPOLPaymentInfoProvider: Interface "PEPPOL Payment Info Provider";
begin
if not FindNextVATAmtRec(TempVATAmtLine, AllowanceChargePaymentDiscountLoop.Number) then
currXMLport.Break();

PEPPOLPaymentInfoProvider := GetFormat();
PEPPOLPaymentInfoProvider.GetAllowanceChargeInfoPaymentDiscount(
TempVATAmtLine,
SalesHeader,
ChargeIndicatorPaymentDiscount,
AllowanceChargeReasonCodePaymentDiscount,
DummyVar,
AllowanceChargeReasonPaymentDiscount,
AmountPaymentDiscount,
AllowanceChargeCurrencyIDPaymentDiscount,
TaxCategoryIDPaymentDiscount,
DummyVar,
PercentPaymentDiscount,
AllowanceChargeTaxSchemeIDPaymentDiscount);

if ChargeIndicatorPaymentDiscount = '' then
currXMLport.Skip();
end;
}
textelement(TaxTotal)
{
NamespacePrefix = 'cac';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,93 @@ xmlport 37201 "Sales Invoice - PEPPOL30"
currXMLport.Skip();
end;
}
tableelement(allowancechargepaymentdiscountloop; Integer)
{
NamespacePrefix = 'cac';
XmlName = 'AllowanceCharge';
SourceTableView = sorting(Number) where(Number = filter(1 ..));
textelement(ChargeIndicatorPaymentDiscount)
{
XmlName = 'ChargeIndicator';
NamespacePrefix = 'cbc';
}
textelement(AllowanceChargeReasonCodePaymentDiscount)
{
XmlName = 'AllowanceChargeReasonCode';
NamespacePrefix = 'cbc';
}
textelement(AllowanceChargeReasonPaymentDiscount)
{
XmlName = 'AllowanceChargeReason';
NamespacePrefix = 'cbc';
}
textelement(AmountPaymentDiscount)
{
XmlName = 'Amount';
NamespacePrefix = 'cbc';
textattribute(allowancechargecurrencyidPaymentDiscount)
{
XmlName = 'currencyID';
}
}
textelement(TaxCategoryPaymentDiscount)
{
XmlName = 'TaxCategory';
NamespacePrefix = 'cac';
textelement(taxcategoryidPaymentDiscount)
{
NamespacePrefix = 'cbc';
XmlName = 'ID';
}
textelement(PercentPaymentDiscount)
{
XmlName = 'Percent';
NamespacePrefix = 'cbc';

trigger OnBeforePassVariable()
begin
if PercentPaymentDiscount = '' then
currXMLport.Skip();
end;
}
textelement(TaxSchemePaymentDiscount)
{
XmlName = 'TaxScheme';
NamespacePrefix = 'cac';
textelement(allowancechargetaxschemeidPaymentDiscount)
{
NamespacePrefix = 'cbc';
XmlName = 'ID';
}
}
}

trigger OnAfterGetRecord()
var
PEPPOLPaymentInfoProvider: Interface "PEPPOL Payment Info Provider";
begin
if not FindNextVATAmtRec(TempVATAmtLine, AllowanceChargePaymentDiscountLoop.Number) then
currXMLport.Break();

PEPPOLPaymentInfoProvider := GetFormat();
PEPPOLPaymentInfoProvider.GetAllowanceChargeInfoPaymentDiscount(
TempVATAmtLine,
SalesHeader,
ChargeIndicatorPaymentDiscount,
AllowanceChargeReasonCodePaymentDiscount,
DummyVar,
AllowanceChargeReasonPaymentDiscount,
AmountPaymentDiscount,
AllowanceChargeCurrencyIDPaymentDiscount,
TaxCategoryIDPaymentDiscount,
DummyVar,
PercentPaymentDiscount,
AllowanceChargeTaxSchemeIDPaymentDiscount);

if ChargeIndicatorPaymentDiscount = '' then
currXMLport.Skip();
end;
}
textelement(TaxTotal)
{
NamespacePrefix = 'cac';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3954,6 +3954,7 @@ codeunit 139235 "PEPPOL30 Management Tests"
LineExtensionAmountCurrencyID: Text;
unitCode: Text;
unitCodeListID: Text;
SalesInvoiceLineLineAmount: Decimal;
begin
SalesInvoiceHeader.Get(PostedInvoiceNo);
SalesHeader.TransferFields(SalesInvoiceHeader);
Expand All @@ -3975,9 +3976,8 @@ codeunit 139235 "PEPPOL30 Management Tests"
Assert.AreEqual(Format(SalesInvoiceLine.Quantity, 0, 9), InvoicedQuantity, '');
Assert.AreEqual(UnitOfMeasure."International Standard Code", unitCode, '');
Assert.AreEqual('UNECERec20', unitCodeListID, '');
Assert.AreEqual(
Format(SalesInvoiceLine."VAT Base Amount" + SalesInvoiceLine."Inv. Discount Amount", 0, 9),
InvoiceLineExtensionAmount, '');
SalesInvoiceLineLineAmount := SalesInvoiceLine."Line Amount";
Assert.AreEqual(Format(SalesInvoiceLineLineAmount, 0, 9), InvoiceLineExtensionAmount, '');
Assert.AreEqual(SalesHeader."Currency Code", LineExtensionAmountCurrencyID, '');
Assert.AreEqual('', InvoiceLineAccountingCost, '');
end;
Expand Down
Loading