This doesn't seem like it should be difficult. I'm keeping a running decremented total owed, where each line may apply some payment against the outstanding debt. Basically:
A: Outstanding Owed | B: Amount Applied | Other Fields
R2: 5000 | 1000
R3: 4000 | 100
R4: 3900 | XXYY
R5: A4 - B4 | XXYY
But ARRAYFORMULA gives circular reference when applied.