Two or more payments in a month to count as one.

kolaboykolaboy Member Posts: 446
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

  • ufukufuk Member Posts: 514
    month count:
    MonthCount :=DATE2DMY(ToDate,2)-DATE2DMY(FromDate,2);

    counting payment once for the period:
    IF FIND('-') THEN BEGIN
      NumPayments := 0;
      REPEAT
        IF ("Document Type" = "Document Type"::Payment) AND
            (InitMonth <> DATE2DMY("Posting Date") ) THEN BEGIN
          NumPayments := NumPayments +1;
          InitMonth:= DATE2DMY("Posting Date")
        END;
      UNTIL NEXT = 0;
    END;
    
    Ufuk Asci
    Pargesoft
  • kolaboykolaboy Member Posts: 446
    Hi ufuk,
    Thanks for the reply. I have used your code and declared the InitMonth as integer, but its giving me an error which runs Thus:
    When the function is called, the minimum no. of parameter should be used. for example,
    MyFunc(..,..,..)
    ROUND(MyVar)
    ROUND(MyVar,0.05)
    what do you think is wrong?
  • ufukufuk Member Posts: 514
    sorry,right one:
    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;
    Ufuk Asci
    Pargesoft
  • kolaboykolaboy Member Posts: 446
    I have used the correct one and the error stopped, but the transcations are not showing. Only the last transcation shows.
  • ufukufuk Member Posts: 514
    I writed the code as a general method for distinct selection. Using in report you have to place the code in triggers like:

    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.
    Ufuk Asci
    Pargesoft
  • ufukufuk Member Posts: 514
    With 2 parameter in DMY of course. I copied from the wrong block. :D
    Ufuk Asci
    Pargesoft
Sign In or Register to comment.