2){
$client_phone = substr($row['client_phone'],0,3)."-".substr($row['client_phone'],3,3)."-".substr($row['client_phone'],6,4);
}
$client_extension = $row['client_extension'];
$client_mobile = $row['client_mobile'];
if(strlen($client_mobile)>2){
$client_mobile = substr($row['client_mobile'],0,3)."-".substr($row['client_mobile'],3,3)."-".substr($row['client_mobile'],6,4);
}
$client_website = $row['client_website'];
$client_currency_code = $row['client_currency_code'];
$client_currency_symbol = get_currency_symbol($client_currency_code);
$client_net_terms = $row['client_net_terms'];
if($client_net_terms == 0){
$client_net_terms = $config_default_net_terms;
}
$company_id = $row['company_id'];
$company_name = $row['company_name'];
$company_address = $row['company_address'];
$company_city = $row['company_city'];
$company_state = $row['company_state'];
$company_zip = $row['company_zip'];
$company_phone = $row['company_phone'];
if(strlen($company_phone)>2){
$company_phone = substr($row['company_phone'],0,3)."-".substr($row['company_phone'],3,3)."-".substr($row['company_phone'],6,4);
}
$company_email = $row['company_email'];
$company_logo = $row['company_logo'];
if(!empty($company_logo)){
$company_logo_base64 = base64_encode(file_get_contents($row['company_logo']));
}
$config_invoice_footer = $row['config_invoice_footer'];
$config_stripe_enable = $row['config_stripe_enable'];
$config_stripe_publishable = $row['config_stripe_publishable'];
$config_stripe_secret = $row['config_stripe_secret'];
$ip = get_ip();
$os = get_os();
$browser = get_web_browser();
$device = get_device();
//Set Badge color based off of invoice status
if($invoice_status == "Sent"){
$invoice_badge_color = "warning text-white";
}elseif($invoice_status == "Viewed"){
$invoice_badge_color = "info";
}elseif($invoice_status == "Partial"){
$invoice_badge_color = "primary";
}elseif($invoice_status == "Paid"){
$invoice_badge_color = "success";
}elseif($invoice_status == "Cancelled"){
$invoice_badge_color = "danger";
}else{
$invoice_badge_color = "secondary";
}
//Update status to Viewed only if invoice_status = "Sent"
if($invoice_status == 'Sent'){
mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Viewed' WHERE invoice_id = $invoice_id");
}
//Mark viewed in history
mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = '$invoice_status', history_description = 'Invoice viewed - $ip - $os - $browser - $device', history_created_at = NOW(), invoice_id = $invoice_id, company_id = $company_id");
mysqli_query($mysqli,"INSERT INTO alerts SET alert_type = 'Invoice Viewed', alert_message = 'Invoice $invoice_number has been viewed by $client_name - $ip - $os - $browser - $device', alert_date = NOW(), company_id = $company_id");
$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;
//check to see if overdue
if($invoice_status !== "Paid" AND $invoice_status !== "Draft" AND $invoice_status !== "Cancelled"){
$unixtime_invoice_due = strtotime($invoice_due) + 86400;
if($unixtime_invoice_due < time()){
$invoice_color = "text-danger";
}
}
?>
| Product |
Description |
Qty |
Price |
Tax |
Total |
|
|
|
|
|
|
| Subtotal |
|
0){ ?>
| Tax |
|
0){ ?>
Paid to Date |
|
| Balance Due |
|
1){
?>
| Invoice # |
Date |
Due Date |
Amount |
|
|
( Days Late) |
|
CURDATE() AND(invoice_status = 'Sent' OR invoice_status = 'Viewed' OR invoice_status = 'Partial') ORDER BY invoice_number DESC");
if(mysqli_num_rows($sql) > 1){
?>
| Invoice # |
Date |
Due |
Amount |
|
|
(Due in Days) |
|
1){
?>
| Invoice # |
Date |
Due Date |
Amount |
|
|
|
|
| Payments |
strtotime($invoice_due)){
$payment_note = "Late";
$difference = strtotime($payment_date) - strtotime($invoice_due);
$days = floor($difference / (60*60*24) ) . " Days";
}else{
$payment_note = "";
$days = "";
}
$invoice_tally_total = $invoice_amount + $invoice_tally_total;
?>
| - - - - |