If you want to calculate totalDebt
per customer you can use query
SELECT Customer_ID, sum(Sales_Payment - Sales_ADiscount) as totalDebt FROM SalesReceipt
GROUP BY Customer_ID
Result contains totalDebts
aggregated by Customer_ID and can be used to update Customer
(all the looping and calculating is done by a database engine).
The query can also update be more complex to do even update for you.