I have previously posted this question. However I was not specific enough, so I am trying to explain it better in this post.
I am currently writing a small program to create invoices. The invoices should be calculated on account of storage time of items e.g. costPerDay * numberOfDaysInStorage.
The invoice is created on a monthly basis, e.g. InvoiceDate = 31/05/2013.
The items start date and end date (in storage) is extracted from a database.
So, I have:
Variables:
DateTime StartInStorageDate;
DateTime EndOfStorageDate;
DateTime InvoiceDate; //(always last date of month)
Rules
- The first five days in storage should always be free.
- Calculation of days, should only be made for a given invoice date.
- If the date prior to the InvoiceDate exist, the days should be taken into account, in order to calculate the "free days". If month date prior has 5 or more days, to the end of its month, we have to assume that these have been calculated, and therefore not take them into account in the invoice month.
Examples
Example 1:
DateTime StartInStorageDate = 07/04/2013;DateTime EndOfStorageDate = 08/06/2013;DateTime InvoiceDate = 31/05/2013;Calculation of days = 31 days (Because Invoice date has a date prior, which has more than five days, the "free days" are already subtracted in that month)
Example 2:
DateTime StartInStorageDate = 28/04/2013DateTime EndOfStorageDate = 08/06/2013DateTime InvoiceDate = 31/05/2013Calculation of days = (11 days total - 5 "free days") = 6 days (Because Invoice date has a date prior, which does not have 5 days to end of its month, we have to add these days to the invoice month, and subtract 5 "free days" from the total)
Example 3:
DateTime StartInStorageDate = 28/04/2013DateTime EndOfStorageDate = 08/05/2013DateTime InvoiceDate = 31/04/2013Calculation of days = 0 (Because the invoiceDate does not have more than 5 days, and does not have a month prior)
I hope someone can provide me with some pointers, or some code to help calculate the days. The part I find tricky, is to "look into" a previous month (if one exists) from the invoice date, to check for days.
Thank you.