-
Notifications
You must be signed in to change notification settings - Fork 688
Closed
Closed
Copy link
Labels
FinanceGitHub request for Finance areaGitHub request for Finance areaextensibility-enhancementNew feature or request related to extensibilityNew feature or request related to extensibilityships-in-future-updateFix ships in a future updateFix ships in a future update
Description
Why do you need this change?
The request for the change will let calculate the custom discount amount based on the custom derived formula. The code that needs to be merged can be compared between the followings Base Code and After Merge sections.
Base Code
> protected procedure HandleChosenEntries(Type: Enum "Customer Apply Calculation Type"; CurrentAmount: Decimal; CurrencyCode: Code[10]; PostingDate: Date)
> var
> TempAppliedCustLedgEntry: Record "Cust. Ledger Entry" temporary;
> PossiblePmtDisc: Decimal;
> -
> begin
> IsHandled := false;
> OnBeforeHandledChosenEntries(Type.AsInteger(), CurrentAmount, CurrencyCode, PostingDate, AppliedCustLedgEntry, IsHandled, CustLedgEntry);
> if IsHandled then
> exit;
> -
> -
> TempAppliedCustLedgEntry.SetRange(Positive);
>
> until not TempAppliedCustLedgEntry.FindFirst();
> CheckRounding();
> end
After Merge
`
protected procedure HandleChosenEntries(Type: Enum "Customer Apply Calculation Type"; CurrentAmount: Decimal; CurrencyCode: Code[10]; PostingDate: Date) var TempAppliedCustLedgEntry: Record "Cust. Ledger Entry" temporary; PossiblePmtDisc: Decimal; OldPmtDisc: Decimal; CorrectionAmount: Decimal; RemainingAmountExclDiscounts: Decimal; CanUseDisc: Boolean; FromZeroGenJnl: Boolean; IsHandled: Boolean; begin IsHandled := false; OnBeforeHandledChosenEntries(Type.AsInteger(), CurrentAmount, CurrencyCode, PostingDate, AppliedCustLedgEntry, IsHandled, CustLedgEntry); if IsHandled then exit; if not AppliedCustLedgEntry.FindSet(false) then exit; repeat TempAppliedCustLedgEntry := AppliedCustLedgEntry; TempAppliedCustLedgEntry.Insert(); OnHandleChosenEntriesOnAfterTempAppliedCustLedgEntryInsert(TempAppliedCustLedgEntry); until AppliedCustLedgEntry.Next() = 0; FromZeroGenJnl := (CurrentAmount = 0) and (Type = Type::"Gen. Jnl. Line"); repeat if not FromZeroGenJnl then TempAppliedCustLedgEntry.SetRange(Positive, CurrentAmount < 0); if TempAppliedCustLedgEntry.FindFirst() then begin ExchangeLedgerEntryAmounts(Type, CurrencyCode, TempAppliedCustLedgEntry, PostingDate); case Type of Type::Direct: CanUseDisc := PaymentToleranceMgt.CheckCalcPmtDiscCust(CustLedgEntry, TempAppliedCustLedgEntry, 0, false, false); Type::"Gen. Jnl. Line": CanUseDisc := PaymentToleranceMgt.CheckCalcPmtDiscGenJnlCust(GenJnlLine2, TempAppliedCustLedgEntry, 0, false) else CanUseDisc := false; end; if CanUseDisc and (Abs(TempAppliedCustLedgEntry."Amount to Apply") >= Abs(TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate))) then if Abs(CurrentAmount) > Abs(TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate)) then begin PmtDiscAmount += TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); CurrentAmount += TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); end else if Abs(CurrentAmount) = Abs(TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate)) then begin PmtDiscAmount += TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); CurrentAmount += TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); AppliedAmount += CorrectionAmount; end else if FromZeroGenJnl then begin PmtDiscAmount += TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); CurrentAmount += TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); end else begin PossiblePmtDisc := TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); RemainingAmountExclDiscounts := TempAppliedCustLedgEntry."Remaining Amount" - PossiblePmtDisc - TempAppliedCustLedgEntry."Max. Payment Tolerance"; if Abs(CurrentAmount) + Abs(CalcOppositeEntriesAmount(TempAppliedCustLedgEntry)) >= Abs(RemainingAmountExclDiscounts) then begin PmtDiscAmount += PossiblePmtDisc; AppliedAmount += CorrectionAmount; end; CurrentAmount += TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry.GetRemainingPmtDiscPossible(PostingDate); end else begin if ((CurrentAmount + TempAppliedCustLedgEntry."Amount to Apply") * CurrentAmount) < 0 then AppliedAmount += CorrectionAmount; CurrentAmount += TempAppliedCustLedgEntry."Amount to Apply"; end; // Custome Code Begin else begin Customer.GET(TempAppliedCustLedgEntry."Customer No."); IF CanUseDisc AND Customer."Take Discount with Short Pay" THEN BEGIN PmtDiscAmount := PmtDiscAmount + TempAppliedCustLedgEntry."Remaining Pmt. Disc. Possible"; CurrentAmount := CurrentAmount + TempAppliedCustLedgEntry."Amount to Apply" - TempAppliedCustLedgEntry."Remaining Pmt. Disc. Possible"; AppliedAmount := AppliedAmount + CorrectionAmount; END ELSE BEGIN // BDL999-01.ne IF ((CurrentAmount + TempAppliedCustLedgEntry."Amount to Apply") * CurrentAmount) <= 0 THEN AppliedAmount += CorrectionAmount; CurrentAmount += TempAppliedCustLedgEntry."Amount to Apply"; END; end // Custome Code End end else begin TempAppliedCustLedgEntry.SetRange(Positive); TempAppliedCustLedgEntry.FindFirst(); ExchangeLedgerEntryAmounts(Type, CurrencyCode, TempAppliedCustLedgEntry, PostingDate); end; // Custom Code Begin Customer.GET(TempAppliedCustLedgEntry."Customer No."); IF Customer."Take Discount with Short Pay" THEN//AND (AppliedCustLedgEntryTemp."Amount to Apply" < AppliedCustLedgEntryTemp."Remaining Amount") THEN AppliedAmount := AppliedAmount + TempAppliedCustLedgEntry."Amount to Apply" ELSE // Custom Code End if OldPmtDisc <> PmtDiscAmount then AppliedAmount += TempAppliedCustLedgEntry."Remaining Amount" else AppliedAmount += TempAppliedCustLedgEntry."Amount to Apply"; OldPmtDisc := PmtDiscAmount; if PossiblePmtDisc <> 0 then CorrectionAmount := TempAppliedCustLedgEntry."Remaining Amount" - TempAppliedCustLedgEntry."Amount to Apply" else CorrectionAmount := 0; if not DifferentCurrenciesInAppln then DifferentCurrenciesInAppln := ApplnCurrencyCode <> TempAppliedCustLedgEntry."Currency Code"; OnHandleChosenEntriesOnBeforeDeleteTempAppliedCustLedgEntry(Rec, TempAppliedCustLedgEntry, CurrencyCode); TempAppliedCustLedgEntry.Delete(); TempAppliedCustLedgEntry.SetRange(Positive); until not TempAppliedCustLedgEntry.FindFirst(); CheckRounding(); end;
`
Describe the request
The request is for modifying an existing event with three extra parameters which are originally global parameter of the page 232:
Original Event:
[IntegrationEvent(true, false)]
local procedure OnBeforeHandledChosenEntries(Type: Option Direct,GenJnlLine,SalesHeader; CurrentAmount: Decimal; CurrencyCode: Code[10]; PostingDate: Date; var AppliedCustLedgerEntry: Record "Cust. Ledger Entry"; var IsHandled: Boolean; var CustLedgEntry: Record "Cust. Ledger Entry")
begin
end;
Requested Event:
[IntegrationEvent(true, false)] local procedure OnBeforeHandledChosenEntries(Type: Option Direct,GenJnlLine,SalesHeader; CurrentAmount: Decimal; CurrencyCode: Code[10]; PostingDate: Date; var AppliedCustLedgerEntry: Record "Cust. Ledger Entry"; var IsHandled: Boolean; var CustLedgEntry: Record "Cust. Ledger Entry"; GenJournalLine: Record "Gen. Journal Line"; var PaymentDiscountAmount: Decimal; var AppliedAmount: Decimal) begin end;
Internal work item: AB#610705
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
FinanceGitHub request for Finance areaGitHub request for Finance areaextensibility-enhancementNew feature or request related to extensibilityNew feature or request related to extensibilityships-in-future-updateFix ships in a future updateFix ships in a future update