# How are pro rata changes in contracts calculated?

In billwerk, fees for products are charged for either pre-paid or post-paid. Pre-paid billing means that the fees are billed for a period in the future.

If contract changes are made that affect a period that has already been billed. This results in documents that adjust the billed fees for the period affected by the change according to the new contract state. Such documents are created in case of up/downgrades that affect already billed periods or in case of extraordinary contract terminations.

In this article, we use examples to describe how the line items resulting from such contract adjustments are calculated.

Calculating the "Net" of line items:

In the following example, we consider a contract that starts on 01.01.2019 00:00. It is an annual contract, which was billed for exactly one year, until 01.01.2020 00:00: Now this contract is extraordinarily terminated on 25.05.2019 00:00. However, the fee of € 100.00 has already been billed for the whole year. Because of the termination, the customer could only use the offered service between 01.01.2019 00:00 and 25.05.2019 00:00, while he is unable to use the service in the period from 25.05.2019 00:00 to 01.01.2020 00:00. For this reason, billwerk issues a corresponding credit note at the same time as the cancellation: The net value of this credit memo line is calculated as follows: Net = Quantity * Price/ Unit

If instead of an extraordinary cancellation, a downgrade to a cheaper Plan Variant had been carried out, an additional line item would be created in addition to the upper credit note line, with which the new fee for the product booked after the upgrade is billed: The second line deducts the fee for the new Plan Variant booked from the credit note, and the resulting credit note is has a lower total amount.

How to calculate the "Quantity" of correction lines:

The critical part of the calculation is the "Quantity". If we remain in this example, the share of the time interval from 05/25/2019 00:00 to 01/01/2020 00:00 in relation to the interval from 01/01/2019 00:00 to 01/01/2020 00:00 is calculated here.

Calculation of the "Quantity" for fees billed in months or years:

For contracts billed in months or years, the relative share is always calclated based on months.

The quantity from the example above is calculated as follows:

(count of months between 25.05.2019 00:00 and 01.01.2020 00:00) / (count of months
between 01.01.2019 00:00 and 01.01.2020 00:00 ) =
1 - [(count of months between 01.01.2019 00:00 and 25.05.2019 00:00) / (count of months
between 01.01.2019 00:00 and 01.01.2020 00:00)]]

Concrete calculations:

count of months between 01.01.2019 00:00 and 01.01.2020 00:00 = 12

count of months between 01.01.2019 00:00 and 25.05.2019 00:00 =
4 + (count of months between 01.05.2019 00:00 and 25.05.2019 00:00) =
4 + (25 days / (count of days between 01.05.2019 and 01.06.2019)) =
4 + (24 / 31) = 4 + 0.77419354838 = 4.77419354838

For the "quantity" this results in:

1 - [4.77419354838/12] = 1 - 0.39784946236 = 0.60215053764 ≈ 0.602151*

This example can be extended in terms of complexity. When calculating the quanitity, relative proportions of days, hours, minutes, seconds and milliseconds are also taken into account.

Let us assume that the cancellation took place at 12:31 instead of on 25.05.2019 00:00.

The concrete calculation is now:

count of months between 01.01.2019 00:00 and 25.05.2019 12:31 =
count of months between 01.01.2019 00:00 and 25.05.2019 00:00 + count of months between 25.05.2019 00:00 and 25.05.2019 13:31 =
4.77419354838 + count of months between 25.05.2019 00:00 and 25.05.2019 13:31 =
4.77419354838 + (count of days between 25.05.2019 00:00 and 25.05.2019 13:31 / count of days between 25.05.2019 and 25.06.2019) =
4.77419354838 + ((count of hours between 00:00 and 13:31 /24) /31) =
4.77419354838 + (((13+1/2+1/60)/24) /31) =
4.77419354838 + ((13.5166666667/24)/31) =
4.77419354838 + 0.01816756272 = 4.7923611111

For the "quantity" this results in:

1 - [4.7923611111/12] = 0.60063657407 ≈ 0.600637*

Calculation of the "Quantity" for fees billed in days or weeks:

For contracts that are billed in days or weeks, the relative shares are always calculated in days. The calculation is analogous to the above example.

*The final results are rounded to 6 decimal positions.  The rule "round half up" is applied.