Hallo, i'm new in develop and need Help for my case.

i want to create report and get value like yellow record.
row 1: balance due = invoice amount - payment amount
row 2,3,4... : balance due = balancedue from row 1(previous) - payment amount from record active
how to i convert to my code.
my code:
tmp.InvoiceAmount = custInvoiceJour.InvoiceAmount;
tmp.PaymentAmount = custSettlement.SettleAmountCur;
tmp.BalanceDue = tmp.InvoiceAmount - tmp.PaymentAmount;
i know its read record line not get value from previous.