Good afternoon, Friends I am creating here a system of notes to use in the company he is very basic, but I am in doubt on how to set up the payment function so that it identifies the values goes down the amount paid and create a balance. my table and as follows
id | cliente | valor | pago | Deb/Cred
1 | teste | 35.00 | N | D
2 | teste | 35.00 | N | D
3 | teste | 35.00 | N | D
4 | pago | 65.00 | S | C
5 | saldo | 40.00 | N | C
I would like to know how to mount the formula in php so that when I launch the payment it adds the values to the id 3 that are only debits that give a value of 105.00 subtract the payment that is in the id 4 that is a credit taking the result that is 105.00-65.00 = 40.00 to launch in id 5 as credit and substitute in the column payment N for S to identify that this payment