2){ $client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4); } $client_website = $row['client_website']; $sql_payments = mysqli_query($mysqli,"SELECT * FROM payments, accounts WHERE payments.account_id = accounts.account_id AND payments.invoice_id = $invoice_id ORDER BY payments.payment_id DESC"); //Add up all the payments for the invoice and get the total amount paid to the invoice $sql_amount_paid = mysqli_query($mysqli,"SELECT SUM(payment_amount) AS amount_paid FROM payments WHERE invoice_id = $invoice_id"); $row = mysqli_fetch_array($sql_amount_paid); $amount_paid = $row['amount_paid']; $balance = $invoice_amount - $amount_paid; ?>
| BILL TO: '.$client_name.' '.$client_address.' '.$client_city.' '.$client_state.' '.$client_zip.' '.$client_email.' '.$client_phone.' |
| Item | Description | Unit Cost | Quantity | Tax | Line Total |
Notes'.$invoice_note.' |
Subtotal: | $ '.number_format($sub_total,2).' | |||
| Tax: | $ '.number_format($total_tax,2).' | ||||
| Total: | $ '.number_format($invoice_amount,2).' | ||||
| Paid: | $ '.number_format($amount_paid,2).' | ||||
| Balance due: | $ '.number_format($balance,2).' | ||||