Hello Everyone,
I have close all opened payments on one button click. My custom codeunit will check all opened payment records and deduct the payment amount from the sale invoices against the same customer. If sales invoice remaining amount become zero than that sale invoice should close.
I write my custom codeunit to solve this problem but issue is that when i get the record from cust. Ledger Entry table the amount against the customer appears zero.
Name DataType Subtype Length
Cust_led Record Cust. Ledger Entry
CustomerNo Code 20
Amount Decimal
Cust_led.FINDSET;
IF (Cust_led.FIND('-')) THEN REPEAT
IF (Cust_led.Open = TRUE) THEN BEGIN
CASE Cust_led."Document Type" OF
Cust_led."Document Type"::Payment:
BEGIN
CustomerNo := Cust_led."Customer No.";
Amount := Cust_led.Amount;
MESSAGE(FORMAT(Amount));
Cust_led.Open := FALSE;
IF (Cust_led.FIND('-')) THEN REPEAT
IF(Cust_led.Open = TRUE) THEN
IF(Cust_led."Customer No." = CustomerNo) AND (Amount < 0) THEN BEGIN
CASE Cust_led."Document Type" OF
Cust_led."Document Type"::Invoice:
BEGIN
Cust_led."Remaining Amount" := Cust_led."Remaining Amount" + Amount;
IF(Cust_led."Remaining Amount" <= 0) THEN BEGIN
Cust_led.Open := FALSE;
Amount := Cust_led."Remaining Amount";
MESSAGE('Payment apply');
END
END
END
END
UNTIL Cust_led.NEXT = 0;
MESSAGE('Payment Close');
END
END
END
UNTIL Cust_led.NEXT = 0;
I write this custom codeunit. Anyone can guide me where am i doing wrong? or any better approach to solve this task?
*This post is locked for comments
Hello,
IF (Cust_led.FIND('-')) THEN REPEAT
after this statement you have to use calcfields to get the flowfield data for your example write below statement.
Cust_led.CALCFIELDS(Amount, "Remaining Amount");
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... 290,900 Super User 2024 Season 2
Martin Dráb 229,275 Most Valuable Professional
nmaenpaa 101,156