sum of PHP and Mysql values

Asked

Viewed 250 times

1

Good afternoon, Friends I am creating here a system of notinhas to use in the company it is very basic, but I am doubtful on how to set up the payment function so that it identifies the values some of low paid value 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

Ai would like to know how to assemble the formula in php so that when I launch the payment it adds up the amounts up to id 3 that are only debited that gives a value of 105.00 subtract the payment that is in id 4 that is a credit picking up the result that is 105.00-65.00=40.00 launch on id 5 as credit and sub-subscribe in paid column N by S to identify who is paid

  • These values pago and saldo are also being inserted in this same table? That’s right?

  • The amount paid it and inserted at each payment, the balance and the result of the values tests - paid. and all stay only on a table and when there is a payment I want to change the value "N" of the paid column to "S" and add the balance

  • It is not clear your doubt... When the customer pays one of these installments, you will update the line pago and add how much he paid? Or just mark the installment as S?

  • So Marcelo, wanted when a person paid he sum the debt with the amount paid mark all debts and cast a new debt with the rest that would be the balance so that when I issue a bill not issue the whole report but only after the release of last balance. let’s for an example equal in id 4 he paid and generated a balance (debit/credit) ai in the id s above would be given an update and inserted S in the paid column in id 5 let’s assume that he makes 5 more purchases the last purchase would be the id 10 would pay would have an id 11 with the amount paid and the id 12 with the balance (debit/credit)

  • Yes, that’s exactly what I understood, but are you using a single table for that? If you really need a record containing the amount paid and the remaining balance, you could have another related table and with these records. In this example of your question, the customer has 3 purchases in the amount of 35 and paid 65, this means that it is possible to make a payment of such a portion with less than the total?

  • That’s right, an example is this post here, http://answall.com/questions/86151/extracto-tipo-banc%C3%A1rio-complex-mysql-how-solve

Show 2 more comments

1 answer

1


Staff managed to settle with the following SELECT

SELECT
(SELECT SUM(IF(debito_credito_financeiro = 'C', valor_financeiro, -valor_financeiro)) FROM cad_financeiro WHERE cad_financeiro.pago_financeiro = 'N') AS saldo
FROM cad_financeiro
JOIN cad_trabalho ON cad_financeiro.id_trabalho = cad_trabalho.id_trabalho
JOIN cad_paciente ON cad_trabalho.id_paciente = cad_paciente.id_paciente
JOIN cad_cliente ON cad_paciente.id_cliente = cad_cliente.id_cliente
WHERE cad_cliente.id_cliente = '$id'
GROUP BY cad_cliente.id_cliente

and creating a function in php to update the bd

Browser other questions tagged

You are not signed in. Login or sign up in order to post.