Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

Payment Terms Discounts Being Applied

Posted on by 627
So we haven't moved inventory over to BC 365 SaaS (yet). To create new Purchase Invoices from our vendors we are just populating a line item for hitting the appropriate GL account for the purchase. Assuming that when payments are being generated any payment terms discounts will automatically be factored into the amount being paid. Most vendors included shipping charges to their invoices. We had planned on just adding a line item to the Purchase Invoice for the GL account associated with freight/shipping charges. But wouldn't this also be reduced when payment terms discounts are being applied? Standard business practices usually point to only the actual purchase lines being discounted. Not taking discounts against shipping charges.
 
How would you all recommend handling this? 
Categories:
  • Suggested answer
    Greg Kujawa Profile Picture
    Greg Kujawa 627 on at
    Payment Terms Discounts Being Applied
    I believe I have a workable solution. Below are the two codeunit procedures I have that accomplish this. First off, the procedure that calculates the payment discounts for the purchase invoice lines. Summing up the total discount.
     
    /// <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;
     
    Next, the procedure that modifies the vendor ledger entry with the proper total discount based on this.
     
    [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;
     
    At this stage it's just a proof of concept in a sandbox environment. And for now we are only populating GL entry lines in the purchase invoices. So still more work to be done over the long haul :)
  • Greg Kujawa Profile Picture
    Greg Kujawa 627 on at
    Payment Terms Discounts Being Applied
    Thanks for confirming this! So I downloaded the Spain-localized on-prem install and looked at what was implemented. I applied the similar logic in the GL account sense as a table extension and page extension.
     
    /// <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.';
                }
            }
        }
    }
    
     
    Now I'm looking for the proper event subscriber to attach myself to, in order to properly ignore any GL account code line in a purchase invoice that's to be ignored. Therein lies my challenge. :) We aren't taking invoice discounts up-front, but taking payment discounts when generating vendor payments. I've tried to implement this behavior, and can see that the proper Pmt. Discount Amount is being defined on the purchase line. But when the purchase invoice posts the vendor ledger entries still appear to be applying the payment terms discount to any/all lines. Ignoring my logic. I'm looking in the Purch. Post Invoice Events, but obviously am not attaching to the correct event. :(
  • Suggested answer
    YUN ZHU Profile Picture
    YUN ZHU 73,698 Super User 2024 Season 2 on at
    Payment Terms Discounts Being Applied
    Hi, yes, this is a feature of the local version.
     
    I'm not sure if this will meet your needs, but you can check the following setup if you don't want to use the discount.
     
     
    Hope this helps.
    Thanks.
    ZHU
  • Greg Kujawa Profile Picture
    Greg Kujawa 627 on at
    Payment Terms Discounts Being Applied
    When I raised an issue on Microsoft's GitHub documentation site, this appears to be region-specific feature perhaps. Only available in Spain?
  • Greg Kujawa Profile Picture
    Greg Kujawa 627 on at
    Payment Terms Discounts Being Applied

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans