Hi Experts,
I have a report that is counting payments for every payment made. I am also counting non-payments. The idea is, payments are to be made every months and this payments counted. each month should be one payment.
this is working fine. It also capture non-payments by counts the no. of months skipped.
Now the issue is, somebody paying two or more times in a months is counting as two or more months. this should not be the case. When two or more payments are made in a months, It should still count as one.
Below is the code i have:
FromDate := 010107D;
ToDate := TODAY;
//Amount := 0;
CustLedEntryMonth := '';
MonthsArrears := 0;
//Code to Count Months
IF (FromDate <> 0D) AND (ToDate > FromDate) THEN BEGIN
Calendar.RESET;
Calendar.SETRANGE("Period Type",Calendar."Period Type"::Month);
Calendar.SETRANGE("Period Start",FromDate,ToDate);
Months := Calendar.COUNT - 1;
END ELSE
Months := 0;
//Code to count no. of payments
IF "Document Type"="Document Type"::Payment THEN BEGIN
NumPayments := NumPayments +1;
END;
The idea is to count the total no. of months from 01/01/07 to date. also count no. of payments which represents months. Then subtract the payments from the total months to date and the difference serves as arreas or months not paid.
Now paying two or more times in one months is still counting the payments as months. Now i want the two or more payments done in one month to count as one payment or one month.
Does anybody have any idea. How can i modify the above code to make it work like i wanted it. I also welcome any code that will do what i wanted different from the above. Any ideas please?
Thanks.
Comments
MonthCount :=DATE2DMY(ToDate,2)-DATE2DMY(FromDate,2);
counting payment once for the period:
Pargesoft
Thanks for the reply. I have used your code and declared the InitMonth as integer, but its giving me an error which runs Thus: what do you think is wrong?
IF FIND('-') THEN BEGIN
NumPayments := 0;
REPEAT
IF ("Document Type" = "Document Type"::Payment) AND
(InitMonth <> DATE2DMY("Posting Date",2 )) THEN BEGIN
NumPayments := NumPayments +1;
InitMonth:= DATE2DMY("Posting Date",2)
END;
UNTIL NEXT = 0;
END;
Pargesoft
OnPreDataItem
NumPayments := 0;
OnAfterGetRecord
IF ("Document Type" = "Document Type"::Payment) AND
(InitMonth <> DATE2DMY("Posting Date") ) THEN BEGIN
NumPayments := NumPayments +1;
InitMonth:= DATE2DMY("Posting Date")
Hope, this will work for your case.
Pargesoft
Pargesoft