Hi there. It sounds like you are looking for the loan balance equation. It has two parts.

First we must figure out what our accrued interest is.

That is done like so:

Interest rate is dependent on how often you make payments and how often accrual periods occur. For sake of simplicity, lets assume that payments and accrual periods are the same length. If you are given an interest rate of 12% and it is compounded monthly, then n is 12 and interest rate(i) is 12/1 = 1% or 0.01

We then take into consideration what you are paying and how much interest it has negated. Subtract this from the first number and you get your current balance after n payments. If you want to include a loss of income or lump sum payments, simply calculate your balance to the point of the event, and if it is a lump sum subtract it, or if is a nonpayment, accrue however many periods of interest you want and then continue with the first formula. Hope this helps,

Chris