I have a table called Invoice. It has fields such as
Invoicenum duedate Amount and status. The status could be open or close meaning
whether the invoice has been paid or not. What i basically want to achieve is to
find which invoice is delinquent by (1-30days,31-60,61-90,91-120 and >120).
What happens is if there are open invoices for instance in the month of December
and January and the customer made a payment in february for just one month. That payment
goes towards February invoice leaving December and jan open whearas its supposed to be applied
towards December invoice but its a bug in the system. However i want to create a report to
calculate true delinquency. Let me clarify by the following example
Invoicenum duedate amount status
100 20071001 500 o
101 20071101 500 c
102 20071201 500 c
103 20080101 500 o
104 20080201 500 o
Now my query or report shud display the above results as follows
InvoiceNum delinquency Amount
100 61-90 500
103 31-60 500
104 1-30 500
The open and closed invoices might appear in different variations meaning there could be
10 open invoices between 2 closes invoices or anything like that.
In other words I just want to be able to list all the open invoices 30 days apart from each otther.
I just somehow can't get the right logic for it to work in all cases. If i need to
do it thru a stored procedure give any suggestions please. I hope I explained it
clearly if not i'll try to elaborate on it more. thanks for your help.
Invoicenum duedate Amount and status. The status could be open or close meaning
whether the invoice has been paid or not. What i basically want to achieve is to
find which invoice is delinquent by (1-30days,31-60,61-90,91-120 and >120).
What happens is if there are open invoices for instance in the month of December
and January and the customer made a payment in february for just one month. That payment
goes towards February invoice leaving December and jan open whearas its supposed to be applied
towards December invoice but its a bug in the system. However i want to create a report to
calculate true delinquency. Let me clarify by the following example
Invoicenum duedate amount status
100 20071001 500 o
101 20071101 500 c
102 20071201 500 c
103 20080101 500 o
104 20080201 500 o
Now my query or report shud display the above results as follows
InvoiceNum delinquency Amount
100 61-90 500
103 31-60 500
104 1-30 500
The open and closed invoices might appear in different variations meaning there could be
10 open invoices between 2 closes invoices or anything like that.
In other words I just want to be able to list all the open invoices 30 days apart from each otther.
I just somehow can't get the right logic for it to work in all cases. If i need to
do it thru a stored procedure give any suggestions please. I hope I explained it
clearly if not i'll try to elaborate on it more. thanks for your help.