...
In order to calculate the full period some additional pieces of information must be found. First, the next bill date must be calculated. This is done by using the User Bill Day and finding the next one after the end of the prorate period.
\[
NextBillDate = Jan 1,2015
\]
...
Then, the Previous Bill Date has to be calculated. In order to do this, the beginning of the prorate period is examined and the bill date previous to that is subtracted from the Next Bill Date. This difference is then applied, along with monthly frequency to calculate the Previous Bill Date. In this example, the bill date previous to the prorate Start Date is the bill day prior to December 22, 2014, which is December 1, 2014.
\[
CurrentBillDate = Dec 1,2014
\]
\[
MonthMultipler = Diff(CurrentBillDate,NextBillDate)
\]
\[
MonthMultipler = Diff(Dec 1,2014, Jan 1,2015)
\]
\[
MonthMultipler = 1
\]
\[
PreviousBillDay = NextBillDay.AddMonths(- 1 * MonthMultipler * PackageFrequency)
\]
\[
PreviousBillDay = (Jan 1,2015).AddMonths(-1 * 1 * 1)
\]
\[
PreviousBillday = Dec 1,2014
\]
Now that the NextBillDay and the PreviousBillDay have been calculated, the number of months in the full period are just the difference in the number of months between the two dates.
\[
NumberOfFullPeriodMonths = Diff(PreviousBillday,NextBillDay) = 1
\]
...
With this value we can calculate out the amount that would have been charged if the package was being billed for the full period.
\[
PeriodAmount * NumberOfFullPeriodMonths = FullPeriodAmount
\]
...
The last few calculations involve the number of days in each period. The number of days is obtained by letting the system DateTime library do the heavy lifting.
First the system calculates the actual period days as below:
\[
NextBillDay - PreviousBillDay = NumberOfDaysInFullPeriod
\]
...
Second, the system compares the number of full days in the period to the number of days in the current month (the month in which you are physically billing the customer - todays month), and it will use the greater of the day amounts. If we are billing in December for a February prorate, the system would use 31 days of December as the number of days in a full period rather than 28 days from the actual prorate period as example.
Finally, the prorated amount can be calculated.\[
\frac{ProratePeriodsDays}{FullPeriodDays} * FullPeriodAmount = Prorate
\]\[
\frac{10}{31} * 30 = 9.6774193548387
\]
...
So the final, prorated amount rounded off is \$9.68
...