How to determine the period of monthly payment having old and new price

26 Views Asked by At

We are a company providing a service for our clients monthly. Each our client has his own balance at our billing system. The current price of our service is 85 per month. If the balance of a client is for example -85, this means the client has 85 of the debt for the previous month i.e. for December. If he pays for example 170, his balance becomes 85 (positive) and this means he paid for December and January. Currently I have a formula to determine such period of the payment we print on the payment receipt for our clients.

The problem is there will be a new price from February 1 and it will be 120. And I can't found a new formula.

So we have the following input variables: current_month_number (now is 1 i.e. January), updated_balance (after payment), new_price_month_number (2 that is February), old_price (85), new_price (120) and cash_sum.

Let's consider the following example: a client has the balance -85 i.e. the debt for the December and he pays 410. So the input variables are:

current_month_number = 1 (January)
updated_balance = 325 (-85 + 410)
new_price_month_number = 2 (February)
old_price = 85
new_price = 120
cash_sum = 410

If the cash_sum is 410, this means 170 for December and January (85*2, based on the old price) and 240 for February and March (120*2, based of the new price). So the final numbers of months paid for will be 12-3 (12 is December and 3 is March).

The question is, What formula can I use to determine the period based on the mentioned input variables regardless of their values?


UPDATE

The problem is actual! Can someone post an answer?