/// <summary>
/// OnAfterCalcPurchaseDiscount.
/// </summary>
/// <param name="PurchaseHeader">VAR Record "Purchase Header".</param>
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Calc.Discount", 'OnAfterCalcPurchaseDiscount', '', true, true)]
procedure OnAfterCalcPurchaseDiscount(var PurchaseHeader: Record "Purchase Header")
var
PurchaseLine: Record "Purchase Line";
GLAccount: Record "G/L Account";
DiscIgnored: Boolean;
begin
TotalDiscount := 0;
PurchaseLine.Reset();
PurchaseLine.SetFilter("Document No.", '=%1', PurchaseHeader."No.");
if PurchaseLine.FindSet() then
repeat
if PurchaseLine.Type = PurchaseLine.Type::"G/L Account" then
DiscIgnored := GLAccount.DiscountsIgnored(PurchaseLine."No.");
if DiscIgnored then begin
PurchaseLine."Allow Invoice Disc." := false;
PurchaseLine."Pmt. Discount Amount" := 0;
PurchaseLine.Modify();
PurchaseLine.UpdateAmounts();
PurchaseLine.UpdateUnitCost();
end else begin
PurchaseLine."Allow Invoice Disc." := true;
PurchaseLine."Pmt. Discount Amount" := PurchaseLine.Amount * (PurchaseHeader."Payment Discount %" / 100);
PurchaseLine.Modify();
PurchaseLine.UpdateAmounts();
PurchaseLine.UpdateUnitCost();
TotalDiscount += PurchaseLine."Pmt. Discount Amount";
end;
until PurchaseLine.Next() = 0;
end;
[EventSubscriber(ObjectType::Codeunit, Codeunit::"Purch.-Post", 'OnAfterPostInvoice', '', true, true)]
procedure OnAfterPostInvoice(var PurchHeader: Record "Purchase Header"; var GenJnlPostLine: Codeunit "Gen. Jnl.-Post Line"; TotalPurchLine: Record "Purchase Line"; TotalPurchLineLCY: Record "Purchase Line"; CommitIsSupressed: Boolean; var VendorLedgerEntry: Record "Vendor Ledger Entry")
begin
VendorLedgerEntry."Original Pmt. Disc. Possible" := -TotalDiscount;
VendorLedgerEntry."Remaining Pmt. Disc. Possible" := -TotalDiscount;
VendorLedgerEntry.Modify();
end;
/// <summary>
/// TableExtension DCH GL Account Ext (ID 50101) extends Record G/L Account.
/// </summary>
tableextension 50101 "DCH GL Account Ext" extends "G/L Account"
{
fields
{
field(50100; "Ignore Discounts"; Boolean)
{
Caption = 'Ignore Discounts';
DataClassification = ToBeClassified;
InitValue = false;
}
}
/// <summary>
/// InvoiceDiscountAllowed.
/// </summary>
/// <param name="GLAccNo">Code[20].</param>
/// <returns>Return value of type Boolean.</returns>
procedure DiscountsIgnored(GLAccNo: Code[20]): Boolean
var
GLAccount: Record "G/L Account";
begin
if GLAccount.Get(GLAccNo) then
exit(GLAccount."Ignore Discounts");
end;
}
/// <summary>
/// PageExtension DCH GL Acc Card Ext (ID 50100) extends Record G/L Account Card.
/// </summary>
pageextension 50100 "DCH GL Acc Card Ext" extends "G/L Account Card"
{
layout
{
addafter("Default Deferral Template Code")
{
field("Ignore Discounts"; Rec."Ignore Discounts")
{
ApplicationArea = All;
Importance = Promoted;
ToolTip = 'Specifies if you do not want to calculate discounts on invoices or payment discounts.';
}
}
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,280 Super User 2024 Season 2
Martin Dráb 230,235 Most Valuable Professional
nmaenpaa 101,156