diff --git a/email_invoice.php b/email_invoice.php deleted file mode 100644 index 4b120a3a..00000000 --- a/email_invoice.php +++ /dev/null @@ -1,261 +0,0 @@ - - -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; - - $sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY invoice_item_id ASC"); - - while($row = mysqli_fetch_array($sql_invoice_items)){ - $invoice_item_id = $row['invoice_item_id']; - $invoice_item_name = $row['invoice_item_name']; - $invoice_item_description = $row['invoice_item_description']; - $invoice_item_quantity = $row['invoice_item_quantity']; - $invoice_item_price = $row['invoice_item_price']; - $invoice_item_subtotal = $row['invoice_item_price']; - $invoice_item_tax = $row['invoice_item_tax']; - $invoice_item_total = $row['invoice_item_total']; - $total_tax = $invoice_item_tax + $total_tax; - $sub_total = $invoice_item_price * $invoice_item_quantity + $sub_total; - - - $invoice_items .= " - - $invoice_item_name - $invoice_item_description - $$invoice_item_price - $invoice_item_quantity - $$invoice_item_tax - $$invoice_item_total - - "; - - } - -$html = ' - - - - - - -
Date: '.$invoice_date.'
-
Due: '.$invoice_due.'
- - - - -
BILL TO:

'.$client_name.'
'.$client_address.'
'.$client_city.' '.$client_state.' '.$client_zip.'

'.$client_email.'
'.$client_phone.'
 
-
- - - - - - - - - - - - -'.$invoice_items.' - - - - - - - - - - - - - - - - - - - - - - -
ItemDescriptionUnit CostQuantityTaxLine 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).'
-
'.$config_invoice_footer.'
- - -'; - -$path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__; -require_once $path . '/vendor/autoload.php'; -$mpdf = new \Mpdf\Mpdf([ - 'margin_left' => 20, - 'margin_right' => 15, - 'margin_top' => 48, - 'margin_bottom' => 25, - 'margin_header' => 10, - 'margin_footer' => 10 -]); -$mpdf->SetProtection(array('print')); -$mpdf->SetTitle("$config_company_name - Invoice"); -$mpdf->SetAuthor("$config_company_name"); -if($invoice_status == 'Paid'){ - $mpdf->SetWatermarkText("Paid"); -} -$mpdf->showWatermarkText = true; -$mpdf->watermark_font = 'DejaVuSansCondensed'; -$mpdf->watermarkTextAlpha = 0.1; -$mpdf->SetDisplayMode('fullpage'); -$mpdf->WriteHTML($html); -$mpdf->Output('uploads/invoice.pdf', 'F'); - - - -require("vendor/PHPMailer-6.0.7/src/PHPMailer.php"); -require("vendor/PHPMailer-6.0.7/src/SMTP.php"); - -use PHPMailer\PHPMailer\PHPMailer; -use PHPMailer\PHPMailer\Exception; - -$mail = new PHPMailer(true); - -try { - - //Mail Server Settings - - //$mail->SMTPDebug = 2; // Enable verbose debug output - $mail->isSMTP(); // Set mailer to use SMTP - $mail->Host = $config_smtp_host; // Specify main and backup SMTP servers - $mail->SMTPAuth = true; // Enable SMTP authentication - $mail->Username = $config_smtp_username; // SMTP username - $mail->Password = $config_smtp_password; // SMTP password - $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted - $mail->Port = $config_smtp_port; // TCP port to connect to - - - //Recipients - $mail->setFrom($config_mail_from_email, $config_mail_from_name); - $mail->addAddress("$client_email", "$client_name"); // Add a recipient - - // Attachments - //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments - //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name - $mail->addAttachment('uploads/invoice.pdf'); // Optional name - - // Content - $mail->isHTML(true); // Set email format to HTML - $mail->Subject = "Invoice $invoice_number - $invoice_date - Due $invoice_due"; - $mail->Body = "Hello $client_name,

Thank you for choosing $config_company_name! -- attached to this email is your invoice in PDF form due on $invoice_due Please make all checks payable to $config_company_name and mail to $config_company_address $config_company_city $config_company_state $config_company_zip before $invoice_due.

If you have any questions please contact us at the number below.

~
$config_company_name
Automated Billing Department
$config_company_phone"; - //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; - - $mail->send(); - echo 'Message has been sent'; - - - - mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'Emailed Invoice!', invoice_id = $invoice_id"); - - //Don't chnage the status to sent if the status is anything but draf - if($invoice_status == 'Draft'){ - - mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', client_id = $client_id"); - - } - - $_SESSION['alert_message'] = "Invoice has been sent"; - - header("Location: invoice.php?invoice_id=$invoice_id"); - - -} catch (Exception $e) { - echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; -} - -?> \ No newline at end of file diff --git a/invoice.php b/invoice.php index 8a7e1cb7..4ba93a8d 100644 --- a/invoice.php +++ b/invoice.php @@ -87,11 +87,11 @@ if(isset($_GET['invoice_id'])){ Edit Note Copy - Send Email + Send Email Mark Sent Add Payment Print - PDF + PDF Delete diff --git a/pdf_invoice.php b/pdf_invoice.php deleted file mode 100644 index 65fce0f8..00000000 --- a/pdf_invoice.php +++ /dev/null @@ -1,206 +0,0 @@ - - -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; - -?> - - - - - $invoice_item_name - $invoice_item_description - $$invoice_item_price - $invoice_item_quantity - $$invoice_item_tax - $$invoice_item_total - - "; - -} - -$html = ' - - - - - - -
Date: '.$invoice_date.'
-
Due: '.$invoice_due.'
- - - - -
BILL TO:

'.$client_name.'
'.$client_address.'
'.$client_city.' '.$client_state.' '.$client_zip.'

'.$client_email.'
'.$client_phone.'
 
-
- - - - - - - - - - - - -'.$invoice_items.' - - - - - - - - - - - - - - - - - - - - - - -
ItemDescriptionUnit CostQuantityTaxLine 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).'
-
'.$config_invoice_footer.'
- - -'; - -$path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__; -require_once $path . '/vendor/autoload.php'; -$mpdf = new \Mpdf\Mpdf([ - 'margin_left' => 20, - 'margin_right' => 15, - 'margin_top' => 48, - 'margin_bottom' => 25, - 'margin_header' => 10, - 'margin_footer' => 10 -]); -$mpdf->SetProtection(array('print')); -$mpdf->SetTitle("$config_company_name - Invoice"); -$mpdf->SetAuthor("$config_company_name"); -if($invoice_status == 'Paid'){ - $mpdf->SetWatermarkText("Paid"); -} -$mpdf->showWatermarkText = true; -$mpdf->watermark_font = 'DejaVuSansCondensed'; -$mpdf->watermarkTextAlpha = 0.1; -$mpdf->SetDisplayMode('fullpage'); -$mpdf->WriteHTML($html); -$mpdf->Output(); - -} - -?> \ No newline at end of file diff --git a/post.php b/post.php index f7c95856..7812bce4 100644 --- a/post.php +++ b/post.php @@ -7,9 +7,14 @@ include("check_login.php"); require("vendor/PHPMailer-6.0.7/src/PHPMailer.php"); require("vendor/PHPMailer-6.0.7/src/SMTP.php"); +$mpdf_path = (getenv('MPDF_ROOT')) ? getenv('MPDF_ROOT') : __DIR__; +require_once $mpdf_path . '/vendor/autoload.php'; + use PHPMailer\PHPMailer\PHPMailer; use PHPMailer\PHPMailer\Exception; + + $todays_date = date('Y-m-d'); if(isset($_POST['add_user'])){ @@ -739,6 +744,443 @@ if(isset($_GET['delete_payment'])){ } +if(isset($_GET['email_invoice'])){ + $invoice_id = intval($_GET['email_invoice']); + + $sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients + WHERE invoices.client_id = clients.client_id + AND invoices.invoice_id = $invoice_id" + ); + + $row = mysqli_fetch_array($sql); + $invoice_id = $row['invoice_id']; + $invoice_number = $row['invoice_number']; + $invoice_status = $row['invoice_status']; + $invoice_date = $row['invoice_date']; + $invoice_due = $row['invoice_due']; + $invoice_amount = $row['invoice_amount']; + $client_id = $row['client_id']; + $client_name = $row['client_name']; + $client_address = $row['client_address']; + $client_city = $row['client_city']; + $client_state = $row['client_state']; + $client_zip = $row['client_zip']; + $client_email = $row['client_email']; + $client_phone = $row['client_phone']; + if(strlen($client_phone)>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; + + $sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY invoice_item_id ASC"); + + while($row = mysqli_fetch_array($sql_invoice_items)){ + $invoice_item_id = $row['invoice_item_id']; + $invoice_item_name = $row['invoice_item_name']; + $invoice_item_description = $row['invoice_item_description']; + $invoice_item_quantity = $row['invoice_item_quantity']; + $invoice_item_price = $row['invoice_item_price']; + $invoice_item_subtotal = $row['invoice_item_price']; + $invoice_item_tax = $row['invoice_item_tax']; + $invoice_item_total = $row['invoice_item_total']; + $total_tax = $invoice_item_tax + $total_tax; + $sub_total = $invoice_item_price * $invoice_item_quantity + $sub_total; + + + $invoice_items .= " + + $invoice_item_name + $invoice_item_description + $$invoice_item_price + $invoice_item_quantity + $$invoice_item_tax + $$invoice_item_total + + "; + + } + + $html = ' + + + + + + +
Date: '.$invoice_date.'
+
Due: '.$invoice_due.'
+ + + + +
BILL TO:

'.$client_name.'
'.$client_address.'
'.$client_city.' '.$client_state.' '.$client_zip.'

'.$client_email.'
'.$client_phone.'
 
+
+ + + + + + + + + + + + + '.$invoice_items.' + + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionUnit CostQuantityTaxLine 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).'
+
'.$config_invoice_footer.'
+ + + '; + + $mpdf = new \Mpdf\Mpdf([ + 'margin_left' => 20, + 'margin_right' => 15, + 'margin_top' => 48, + 'margin_bottom' => 25, + 'margin_header' => 10, + 'margin_footer' => 10 + ]); + $mpdf->SetProtection(array('print')); + $mpdf->SetTitle("$config_company_name - Invoice"); + $mpdf->SetAuthor("$config_company_name"); + if($invoice_status == 'Paid'){ + $mpdf->SetWatermarkText("Paid"); + } + $mpdf->showWatermarkText = true; + $mpdf->watermark_font = 'DejaVuSansCondensed'; + $mpdf->watermarkTextAlpha = 0.1; + $mpdf->SetDisplayMode('fullpage'); + $mpdf->WriteHTML($html); + $mpdf->Output('uploads/invoice.pdf', 'F'); + + $mail = new PHPMailer(true); + + try{ + + //Mail Server Settings + + //$mail->SMTPDebug = 2; // Enable verbose debug output + $mail->isSMTP(); // Set mailer to use SMTP + $mail->Host = $config_smtp_host; // Specify main and backup SMTP servers + $mail->SMTPAuth = true; // Enable SMTP authentication + $mail->Username = $config_smtp_username; // SMTP username + $mail->Password = $config_smtp_password; // SMTP password + $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted + $mail->Port = $config_smtp_port; // TCP port to connect to + + //Recipients + $mail->setFrom($config_mail_from_email, $config_mail_from_name); + $mail->addAddress("$client_email", "$client_name"); // Add a recipient + + // Attachments + //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments + //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name + $mail->addAttachment('uploads/invoice.pdf'); // Optional name + + // Content + $mail->isHTML(true); // Set email format to HTML + $mail->Subject = "Invoice $invoice_number - $invoice_date - Due $invoice_due"; + $mail->Body = "Hello $client_name,

Thank you for choosing $config_company_name! -- attached to this email is your invoice in PDF form due on $invoice_due Please make all checks payable to $config_company_name and mail to $config_company_address $config_company_city $config_company_state $config_company_zip before $invoice_due.

If you have any questions please contact us at the number below.

~
$config_company_name
Automated Billing Department
$config_company_phone"; + //$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; + + $mail->send(); + echo 'Message has been sent'; + + mysqli_query($mysqli,"INSERT INTO invoice_history SET invoice_history_date = CURDATE(), invoice_history_status = 'Sent', invoice_history_description = 'Emailed Invoice!', invoice_id = $invoice_id"); + + //Don't chnage the status to sent if the status is anything but draf + if($invoice_status == 'Draft'){ + + mysqli_query($mysqli,"UPDATE invoices SET invoice_status = 'Sent', client_id = $client_id"); + + } + + $_SESSION['alert_message'] = "Invoice has been sent"; + + header("Location: invoice.php?invoice_id=$invoice_id"); + + + } catch (Exception $e) { + echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}"; + } +} + +if(isset($_GET['pdf_invoice'])){ + + $invoice_id = intval($_GET['pdf_invoice']); + + $sql = mysqli_query($mysqli,"SELECT * FROM invoices, clients + WHERE invoices.client_id = clients.client_id + AND invoices.invoice_id = $invoice_id" + ); + + $row = mysqli_fetch_array($sql); + $invoice_id = $row['invoice_id']; + $invoice_number = $row['invoice_number']; + $invoice_status = $row['invoice_status']; + $invoice_date = $row['invoice_date']; + $invoice_due = $row['invoice_due']; + $invoice_amount = $row['invoice_amount']; + $invoice_note = $row['invoice_note']; + $invoice_category_id = $row['category_id']; + $client_id = $row['client_id']; + $client_name = $row['client_name']; + $client_address = $row['client_address']; + $client_city = $row['client_city']; + $client_state = $row['client_state']; + $client_zip = $row['client_zip']; + $client_email = $row['client_email']; + $client_phone = $row['client_phone']; + if(strlen($client_phone)>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; + + $sql_invoice_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY invoice_item_id ASC"); + + while($row = mysqli_fetch_array($sql_invoice_items)){ + $invoice_item_id = $row['invoice_item_id']; + $invoice_item_name = $row['invoice_item_name']; + $invoice_item_description = $row['invoice_item_description']; + $invoice_item_quantity = $row['invoice_item_quantity']; + $invoice_item_price = $row['invoice_item_price']; + $invoice_item_subtotal = $row['invoice_item_price']; + $invoice_item_tax = $row['invoice_item_tax']; + $invoice_item_total = $row['invoice_item_total']; + $total_tax = $invoice_item_tax + $total_tax; + $sub_total = $invoice_item_price * $invoice_item_quantity + $sub_total; + + $invoice_items .= " + + $invoice_item_name + $invoice_item_description + $$invoice_item_price + $invoice_item_quantity + $$invoice_item_tax + $$invoice_item_total + + "; + + } + + $html = ' + + + + + + +
Date: '.$invoice_date.'
+
Due: '.$invoice_due.'
+ + + + +
BILL TO:

'.$client_name.'
'.$client_address.'
'.$client_city.' '.$client_state.' '.$client_zip.'

'.$client_email.'
'.$client_phone.'
 
+
+ + + + + + + + + + + + + '.$invoice_items.' + + + + + + + + + + + + + + + + + + + + + + +
ItemDescriptionUnit CostQuantityTaxLine 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).'
+
'.$config_invoice_footer.'
+ + + '; + + $mpdf = new \Mpdf\Mpdf([ + 'margin_left' => 20, + 'margin_right' => 15, + 'margin_top' => 48, + 'margin_bottom' => 25, + 'margin_header' => 10, + 'margin_footer' => 10 + ]); + + $mpdf->SetProtection(array('print')); + $mpdf->SetTitle("$config_company_name - Invoice"); + $mpdf->SetAuthor("$config_company_name"); + if($invoice_status == 'Paid'){ + $mpdf->SetWatermarkText("Paid"); + } + $mpdf->showWatermarkText = true; + $mpdf->watermark_font = 'DejaVuSansCondensed'; + $mpdf->watermarkTextAlpha = 0.1; + $mpdf->SetDisplayMode('fullpage'); + $mpdf->WriteHTML($html); + $mpdf->Output(); + +} + if(isset($_POST['edit_invoice_note'])){ $invoice_id = intval($_POST['invoice_id']); diff --git a/uploads/invoice.pdf b/uploads/invoice.pdf index c7a5102d..4b1b005a 100644 Binary files a/uploads/invoice.pdf and b/uploads/invoice.pdf differ