Clarification on amortization of constant payments
Let $L$ be the loan amount, then $L=P\frac{1-(1+i)^{-n}}{i}$

The balance at time $t$ is defined as the present value of the remaining payments, 

$B_t=P\frac{1-(1+i)^{-(n-t)}}{i}$

By using the following equations

$I_k+C_k=P$ and $I_k=iB_{k-1}$ where $I_k$ is the interest paid at time $k$ we derive the following equation

$C_k=\frac{P}{(1+i)^{n-k+1}}$ and after a simple rearrangement we arrive at the formula you presented.