I am looking for some assistance in calculating the due dates for a new scheduling system.
At present a schedule is based on Monthly or Weekly payment, starting from a defined date.
In the new schedule we want this to be based on the customers pay frequency, starting from a defined date.
We have 13 options for pay frequency:
Montly - Last Working Day
Monthly - Same Date e.g. 20th, 25th
Monthly - 1st Mon/Tue/Wed/Thurs/Fri
Monthly - 2nd Mon/Tue/Wed/Thurs/Fri
Monthly - 3rd Mon/Tue/Wed/Thurs/Fri
Monthly - Last Mon/Tue/Wed/Thurs/Fri
Weekly Monday
Weekly Tuesday
Weekly Wednesday
Weekly Thursday
Weekly Friday
4 Weekly
Fortnightly
Depending on the pay frequency passed in and the number of payments and balance due, I need to produce a new schedule.
The first payment is straight forward as it is on the passed in date, the other dates in the schedule need to be calculated (depending on pay frequency) from that date.
I also need to ensure that the scheduled dates are on a weekday (Mon-Fri) and do not land on a public/bank holiday - in this instance, I will revert to the next valid week day.
The method I have so far is as follows - with the area I need assistance commented:
At present a schedule is based on Monthly or Weekly payment, starting from a defined date.
In the new schedule we want this to be based on the customers pay frequency, starting from a defined date.
We have 13 options for pay frequency:
Montly - Last Working Day
Monthly - Same Date e.g. 20th, 25th
Monthly - 1st Mon/Tue/Wed/Thurs/Fri
Monthly - 2nd Mon/Tue/Wed/Thurs/Fri
Monthly - 3rd Mon/Tue/Wed/Thurs/Fri
Monthly - Last Mon/Tue/Wed/Thurs/Fri
Weekly Monday
Weekly Tuesday
Weekly Wednesday
Weekly Thursday
Weekly Friday
4 Weekly
Fortnightly
Depending on the pay frequency passed in and the number of payments and balance due, I need to produce a new schedule.
The first payment is straight forward as it is on the passed in date, the other dates in the schedule need to be calculated (depending on pay frequency) from that date.
I also need to ensure that the scheduled dates are on a weekday (Mon-Fri) and do not land on a public/bank holiday - in this instance, I will revert to the next valid week day.
The method I have so far is as follows - with the area I need assistance commented:
Quote
// Calculate next payment date
public IList<ScheduledInstalment> GenerateSchedule(int agreementID, int paymentCount, PayFrequency frequency, double balance, DateTime firstPaymentDate) { IList<ScheduledInstalment> schedule = new List<ScheduledInstalment>(); PaymentCalculation calc = GetPaymentCalculation(frequency, firstPaymentDate); double regularInstalment = Math.Round(balance / paymentCount, 1); double finalInstalment = Math.Round(((regularInstalment * (paymentCount - 1)) - balance), 2); for (int i = 0; i <= paymentCount; i++) { ScheduledInstalment s = new ScheduledInstalment(); s.AgreementID = agreementID; if (i == 0) { // First Payment s.DueDate = firstPaymentDate; s.AmountDue = regularInstalment; } else // Calculate next payment date if (i < paymentCount) { // Regular Payment s.AmountDue = regularInstalment; } else { // Final Payment s.AmountDue = finalInstalment; } schedule.Add(s); } return schedule; }