diff --git a/guest_post.php b/guest_post.php new file mode 100644 index 00000000..7cae3eed --- /dev/null +++ b/guest_post.php @@ -0,0 +1,214 @@ +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']; + + if(mysqli_num_rows($sql) == 1){ + + //Mark downloaded in history + mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = '$invoice_status', history_description = 'Invoice downloaded', invoice_id = $invoice_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; + + $sql_items = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE invoice_id = $invoice_id ORDER BY item_id ASC"); + + while($row = mysqli_fetch_array($sql_items)){ + $item_id = $row['item_id']; + $item_name = $row['item_name']; + $item_description = $row['item_description']; + $item_quantity = $row['item_quantity']; + $item_price = $row['item_price']; + $item_subtotal = $row['item_price']; + $item_tax = $row['item_tax']; + $item_total = $row['item_total']; + $total_tax = $item_tax + $total_tax; + $sub_total = $item_price * $item_quantity + $sub_total; + + $invoice_items .= " + + $item_name + $item_description + $item_quantity + $$item_price + $$item_tax + $$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.' + + + + + + + + + + + + + + + + + + + + + + +
ProductDescriptionQtyPriceTaxTotal

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:$ '.number_format($balance,2).'
+
'.$config_invoice_footer.'
+ + + '; + + $mpdf = new \Mpdf\Mpdf([ + 'margin_left' => 5, + 'margin_right' => 5, + '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(); + + }else{ + echo "GTFO!!!"; + } +} + +?> \ No newline at end of file diff --git a/guest_view_invoice.php b/guest_view_invoice.php index 9c5c411a..dcfdd64d 100644 --- a/guest_view_invoice.php +++ b/guest_view_invoice.php @@ -41,6 +41,10 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){ if(mysqli_num_rows($sql) == 1){ + //Mark viewed in history + mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = '$invoice_status', history_description = 'Invoice viewed', invoice_id = $invoice_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 @@ -81,7 +85,7 @@ if(isset($_GET['invoice_id'], $_GET['url_key'])){
Print - PDF + PDF diff --git a/post.php b/post.php index db5dee61..f2a6b73d 100644 --- a/post.php +++ b/post.php @@ -759,8 +759,13 @@ if(isset($_POST['add_invoice'])){ $sql = mysqli_query($mysqli,"SELECT invoice_number FROM invoices ORDER BY invoice_number DESC LIMIT 1"); $row = mysqli_fetch_array($sql); $invoice_number = $row['invoice_number'] + 1; - mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $invoice_number, invoice_date = '$date', invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), category_id = $category, invoice_status = 'Draft', client_id = $client"); + + //Generate a unique URL key for clients to access + $url_key = keygen(); + + mysqli_query($mysqli,"INSERT INTO invoices SET invoice_number = $invoice_number, invoice_date = '$date', invoice_due = DATE_ADD(CURDATE(), INTERVAL $client_net_terms day), category_id = $category, invoice_status = 'Draft', invoice_url_key = '$url_key', client_id = $client"); $invoice_id = mysqli_insert_id($mysqli); + mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Draft', history_description = 'INVOICE added!', invoice_id = $invoice_id"); $_SESSION['alert_message'] = "Invoice added";