There are two tables:
bills (each with a unique ID and the amount you need to pay).
payments on these invoices, carried out with indication of the IDI invoice and the amount of payment (each payment has its ID, one invoice may have several payments).
Question: how to display a list of invoices, which will show the amount of all payments on this account and how much is left to pay (that is, the difference between the amount of the invoice and the amount of all payments)?
I tried to do this:
global $wpdb; $rates_sql = $wpdb->get_results("SELECT * FROM factures LEFT JOIN payment ON payment.facture_date=factures.letter_id AND payment.facture_number=factures.id_number WHERE '$date'<='$date_now'"); } foreach ($rates_sql as $result) { $refuseInter=$result->refuse_inter; $refusePay=$result->refuse_pay; $prepayment=$result->prepayment; $sendCourier=$result->send_courier; $expDate=$result->exp_date; $firstIntervDate= $result->first_interv; $date = date('Ym-d', strtotime($firstIntervDate. "+ ".$expDate."days")); $date_now = date("Ymd"); $payment=$result->check_sum; if ($result->tarif_ttc - $results->summary!=0) { ?> <td><?php echo $result->cliend_id; ?></td> <td><?php echo $result->id_number; ?></td> <td><?php echo $result->name; ?></td> <td><?php echo $result->add_code; ?></td> <td><?php echo $results->summary; ?></td> <td><?php echo $result->tarif_ttc - $results->summary ?></td> <td><?php if ($refuseInter == 0) { ?> but in this case, the table repeats the invoices in which two or more prepayments. help, please, sum up these payments and link them to one account.
table structures:
The factures table has columns:
letter_id, id_number, cliend_id, task, metier, check_num, conceil, nex_intervent, creation_date, name, add_num, add_street, add_code, add_city, hotte_number, tarif_ht, tariv_tva, tarif_ttc, first_interv, exp_date, refuse_inter, refuse_pay, prepayment, send_courier payment table has columns:
id_payment, ID, name, facture_date, facture_number, zip-code, contrat_by_courier, check_get_pay, cb_got, virement_got, prelevement_got, lcr_got, check_number, payment_date, send_facture_by_courier, send_facture_by_mail, send_attestation_by_courier, send_attestation_by_mail, check_sum, bank_name, check_num, date_cashed