Hello, i was sorting out a problem at one of our clients, it became evident that i needed to check out for applied entries for a customer ledger entry. First let me put the problem in perspective then i show you how i walked around it.
A customization had been done to help users post refunds on payments made. The system creates a refund journal entry and applies it to the payment and then posts the entry. The problem is that a refund can be posted multiple times which results in jumbled customer balances. We need to stop this by making sure that a full refund is posted strictly once against a particular payment.
Here is how i go about it.
- First pick out a specific payment using its document number and customer Number in customer ledger entry table (21)
- Capture the entry Number of the entry above. The entry Number in customer ledger entry table is a foreign key in detailed customer ledger entry table (379). The field is renamed as "Customer Entry No"
- Search for a record of type "Refund", Entry type "Application" whose Customer Ledger Entry Number corresponds to the one captured above.
- If such a record exists, then its conclusive to say a refund is already posted
Here is a sample code
CustLdgEntry.RESET; // CustLdgEntry is record variable of table 21
CustLdgEntry.SETRANGE(CustLdgEntry."Document Type",CustLdgEntry."Document Type"::Payment);
CustLdgEntry.SETRANGE(CustLdgEntry.Open,FALSE);
CustLdgEntry.SETRANGE(CustLdgEntry."Sell-to Customer No.",CustomerNo);
CustLdgEntry.SETRANGE(CustLdgEntry."Document No.",PaymentDocumentNo);
IF CustLdgEntry.FINDFIRST THEN BEGIN
DetailedLdgEntry.RESET;//DetailedLdgEntry is a record variable of table 379
DetailedLdgEntry.SETRANGE(DetailedLdgEntry."Cust. Ledger Entry No.",CustLdgEntry."Entry No.");
DetailedLdgEntry.SETRANGE(DetailedLdgEntry."Entry Type",DetailedLdgEntry."Entry Type"::Application);
DetailedLdgEntry.SETRANGE(DetailedLdgEntry."Document Type",DetailedLdgEntry."Document Type"::Refund);
IF DetailedLdgEntry.FINDFIRST THEN
ERROR(TXT0004);// TXT0004 text variable informing user that a refund has already been posted against the payment
END;
No comments:
Post a Comment