From 6db23b9bf871ac83bf383c2a1309f74654b0bf65 Mon Sep 17 00:00:00 2001 From: Marcus Hill Date: Wed, 8 Feb 2023 19:23:43 +0000 Subject: [PATCH] - Only show the options to edit quotes/invoices if they aren't finalized/paid - General tidy --- invoice.php | 848 ++++++++++++++++++++++++++-------------------------- quote.php | 52 ++-- 2 files changed, 459 insertions(+), 441 deletions(-) diff --git a/invoice.php b/invoice.php index 99aa7e9e..698f090a 100644 --- a/invoice.php +++ b/invoice.php @@ -6,482 +6,488 @@ if (isset($_GET['invoice_id'])) { $invoice_id = intval($_GET['invoice_id']); - $sql = mysqli_query($mysqli, "SELECT * FROM invoices - LEFT JOIN clients ON invoice_client_id = client_id - LEFT JOIN locations ON primary_location = location_id - LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON invoices.company_id = companies.company_id - WHERE invoice_id = $invoice_id" + $sql = mysqli_query( + $mysqli, + "SELECT * FROM invoices + LEFT JOIN clients ON invoice_client_id = client_id + LEFT JOIN locations ON primary_location = location_id + LEFT JOIN contacts ON primary_contact = contact_id + LEFT JOIN companies ON invoices.company_id = companies.company_id + WHERE invoice_id = $invoice_id" ); if (mysqli_num_rows($sql) == 0) { - echo "

Nothing to see here

"; - } else { + echo '

Nothing to see here

'; + require_once("footer.php"); + exit(); + } - $row = mysqli_fetch_array($sql); - $invoice_id = $row['invoice_id']; - $invoice_prefix = htmlentities($row['invoice_prefix']); - $invoice_number = htmlentities($row['invoice_number']); - $invoice_scope = htmlentities($row['invoice_scope']); - $invoice_status = htmlentities($row['invoice_status']); - $invoice_date = $row['invoice_date']; - $invoice_due = $row['invoice_due']; - $invoice_amount = floatval($row['invoice_amount']); - $invoice_currency_code = htmlentities($row['invoice_currency_code']); - $invoice_note = htmlentities($row['invoice_note']); - $invoice_url_key = htmlentities($row['invoice_url_key']); - $invoice_created_at = $row['invoice_created_at']; - $category_id = $row['invoice_category_id']; - $client_id = $row['client_id']; - $client_name = htmlentities($row['client_name']); - $location_address = htmlentities($row['location_address']); - $location_city = htmlentities($row['location_city']); - $location_state = htmlentities($row['location_state']); - $location_zip = htmlentities($row['location_zip']); - $contact_email = htmlentities($row['contact_email']); - $contact_phone = formatPhoneNumber($row['contact_phone']); - $contact_extension = htmlentities($row['contact_extension']); - $contact_mobile = formatPhoneNumber($row['contact_mobile']); - $client_website = htmlentities($row['client_website']); - $client_currency_code = htmlentities($row['client_currency_code']); - $client_net_terms = htmlentities($row['client_net_terms']); - if ($client_net_terms == 0) { - $client_net_terms = $config_default_net_terms; + $row = mysqli_fetch_array($sql); + $invoice_id = $row['invoice_id']; + $invoice_prefix = htmlentities($row['invoice_prefix']); + $invoice_number = htmlentities($row['invoice_number']); + $invoice_scope = htmlentities($row['invoice_scope']); + $invoice_status = htmlentities($row['invoice_status']); + $invoice_date = $row['invoice_date']; + $invoice_due = $row['invoice_due']; + $invoice_amount = floatval($row['invoice_amount']); + $invoice_currency_code = htmlentities($row['invoice_currency_code']); + $invoice_note = htmlentities($row['invoice_note']); + $invoice_url_key = htmlentities($row['invoice_url_key']); + $invoice_created_at = $row['invoice_created_at']; + $category_id = $row['invoice_category_id']; + $client_id = $row['client_id']; + $client_name = htmlentities($row['client_name']); + $location_address = htmlentities($row['location_address']); + $location_city = htmlentities($row['location_city']); + $location_state = htmlentities($row['location_state']); + $location_zip = htmlentities($row['location_zip']); + $contact_email = htmlentities($row['contact_email']); + $contact_phone = formatPhoneNumber($row['contact_phone']); + $contact_extension = htmlentities($row['contact_extension']); + $contact_mobile = formatPhoneNumber($row['contact_mobile']); + $client_website = htmlentities($row['client_website']); + $client_currency_code = htmlentities($row['client_currency_code']); + $client_net_terms = htmlentities($row['client_net_terms']); + if ($client_net_terms == 0) { + $client_net_terms = $config_default_net_terms; + } + $company_id = $row['company_id']; + $company_name = htmlentities($row['company_name']); + $company_country = htmlentities($row['company_country']); + $company_address = htmlentities($row['company_address']); + $company_city = htmlentities($row['company_city']); + $company_state = htmlentities($row['company_state']); + $company_zip = htmlentities($row['company_zip']); + $company_phone = formatPhoneNumber($row['company_phone']); + $company_email = htmlentities($row['company_email']); + $company_website = htmlentities($row['company_website']); + $company_logo = htmlentities($row['company_logo']); + if (!empty($company_logo)) { + $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); + } + $sql_history = mysqli_query($mysqli, "SELECT * FROM history WHERE history_invoice_id = $invoice_id ORDER BY history_id DESC"); + + $sql_payments = mysqli_query($mysqli, "SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_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 payment_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" && $invoice_status !== "Draft" && $invoice_status !== "Cancelled") { + $unixtime_invoice_due = strtotime($invoice_due) + 86400; + if ($unixtime_invoice_due < time()) { + $invoice_overdue = "Overdue"; } - $company_id = $row['company_id']; - $company_name = htmlentities($row['company_name']); - $company_country = htmlentities($row['company_country']); - $company_address = htmlentities($row['company_address']); - $company_city = htmlentities($row['company_city']); - $company_state = htmlentities($row['company_state']); - $company_zip = htmlentities($row['company_zip']); - $company_phone = formatPhoneNumber($row['company_phone']); - $company_email = htmlentities($row['company_email']); - $company_website = htmlentities($row['company_website']); - $company_logo = htmlentities($row['company_logo']); - if (!empty($company_logo)) { - $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); + } + + //Set Badge color based off of invoice status + $invoice_badge_color = getInvoiceBadgeColor($invoice_status); + + //Product autocomplete + $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); + + if (mysqli_num_rows($products_sql) > 0) { + while ($row = mysqli_fetch_array($products_sql)) { + $products[] = $row; } - $sql_history = mysqli_query($mysqli, "SELECT * FROM history WHERE history_invoice_id = $invoice_id ORDER BY history_id DESC"); + $json_products = json_encode($products); + } - $sql_payments = mysqli_query($mysqli, "SELECT * FROM payments, accounts WHERE payment_account_id = account_id AND payment_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 payment_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" && $invoice_status !== "Draft" && $invoice_status !== "Cancelled") { - $unixtime_invoice_due = strtotime($invoice_due) + 86400; - if ($unixtime_invoice_due < time()) { - $invoice_overdue = "Overdue"; - } - } +
- //Set Badge color based off of invoice status - $invoice_badge_color = getInvoiceBadgeColor($invoice_status); +
- //Product autocomplete - $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); - - if (mysqli_num_rows($products_sql) > 0) { - while ($row = mysqli_fetch_array($products_sql)) { - $products[] = $row; - } - $json_products = json_encode($products); - } - - ?> - - - -
- -
- -
- -
- - - - - - - Add Payment - -
- -
- - -
- -
-
- " alt="Company logo"> -
-
-
-
- -
-
-

Invoice

-
- -
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
    -
  • -
  • -
  • -
  • -
  • -
  • -
-
-
-
-
-
-
- - - - - - - - - -
Date
Due
-
-
- - - -
-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
ItemDescriptionQtyPriceTaxTotal
- - -
- - - -
-
-
-
-
- -
-
-
-
- Notes -
- - - -
-
-
-
-
-
-
-
- - - - - - - 0) { ?> - - - - - - 0) { ?> - - - - - - - - - - -
Subtotal
Tax
Paid
Balance
-
-
- -
- -
-
-
-
-
-
- History -
- - +
+ +
+
+ " alt="Company logo"> +
+
+
+
+
-
- - - - - - - - - - Invoice
+ - while ($row = mysqli_fetch_array($sql_history)) { - $history_created_at = $row['history_created_at']; - $history_status = htmlentities($row['history_status']); - $history_description = htmlentities($row['history_description']); - - ?> - - - - - - - - -
DateStatusDescription
-
+
+
+
+
    +
  • +
  • +
  • +
  • +
  • +
  • +
+
+
+
    +
  • +
  • +
  • +
  • +
  • +
  • +
-
-
-
- Payments -
- - -
-
-
+
+
+
+
+ + + + + + + + + +
Date
Due
+
+
+ + + +
+
+
- - - - - + + + + + + + + - - - - - + + + + + + + + + + > + + + + + + + + + + +
DateAmountReferenceAccountActionItemDescriptionQtyPriceTaxTotal
+ + + + +
+ + + +
+ +
+
+
+
+ Notes +
+ + + +
+
+
+
+
+
+
+
+ + + + + + + 0) { ?> + + + + + + 0) { ?> + + + + + + + + + + +
Subtotal
Tax
Paid
Balance
+
+
+ +
+ +
+
- +
+
+
+ History +
+ + +
+
+
+ + + + + + + + + + + + + + + + + + +
DateStatusDescription
+
+
+
+
+
+
+ Payments +
+ + +
+
+
+
+ + + + + + + + + + + + + + + + + + + + + +
DateAmountReferenceAccountAction
+
+
+
+
+
+ + diff --git a/quote.php b/quote.php index 696d730f..aa321c82 100644 --- a/quote.php +++ b/quote.php @@ -5,14 +5,22 @@ if (isset($_GET['quote_id'])) { $quote_id = intval($_GET['quote_id']); - $sql = mysqli_query($mysqli,"SELECT * FROM quotes - LEFT JOIN clients ON quote_client_id = client_id - LEFT JOIN locations ON primary_location = location_id - LEFT JOIN contacts ON primary_contact = contact_id - LEFT JOIN companies ON quotes.company_id = companies.company_id - WHERE quote_id = $quote_id" + $sql = mysqli_query( + $mysqli, + "SELECT * FROM quotes + LEFT JOIN clients ON quote_client_id = client_id + LEFT JOIN locations ON primary_location = location_id + LEFT JOIN contacts ON primary_contact = contact_id + LEFT JOIN companies ON quotes.company_id = companies.company_id + WHERE quote_id = $quote_id" ); + if (mysqli_num_rows($sql) == 0) { + echo '

Nothing to see here

'; + require_once("footer.php"); + exit(); + } + $row = mysqli_fetch_array($sql); $quote_id = $row['quote_id']; $quote_prefix = htmlentities($row['quote_prefix']); @@ -57,25 +65,25 @@ if (isset($_GET['quote_id'])) { $company_logo_base64 = base64_encode(file_get_contents("uploads/settings/$company_id/$company_logo")); } - $sql_history = mysqli_query($mysqli,"SELECT * FROM history WHERE history_quote_id = $quote_id ORDER BY history_id DESC"); + $sql_history = mysqli_query($mysqli, "SELECT * FROM history WHERE history_quote_id = $quote_id ORDER BY history_id DESC"); //Set Badge color based off of quote status if ($quote_status == "Sent") { $quote_badge_color = "warning text-white"; - }elseif ($quote_status == "Viewed") { + } elseif ($quote_status == "Viewed") { $quote_badge_color = "primary"; - }elseif ($quote_status == "Accepted") { + } elseif ($quote_status == "Accepted") { $quote_badge_color = "success"; - }elseif ($quote_status == "Declined") { + } elseif ($quote_status == "Declined") { $quote_badge_color = "danger"; - }elseif ($quote_status == "Invoiced") { + } elseif ($quote_status == "Invoiced") { $quote_badge_color = "info"; - }else{ + } else { $quote_badge_color = "secondary"; } //Product autocomplete - $products_sql = mysqli_query($mysqli,"SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); + $products_sql = mysqli_query($mysqli, "SELECT product_name AS label, product_description AS description, product_price AS price FROM products WHERE company_id = $session_company_id"); if (mysqli_num_rows($products_sql) > 0) { while ($row = mysqli_fetch_array($products_sql)) { @@ -194,7 +202,7 @@ if (isset($_GET['quote_id'])) {
- +
@@ -235,8 +243,10 @@ if (isset($_GET['quote_id'])) { - - + + + +
@@ -248,13 +258,15 @@ if (isset($_GET['quote_id'])) { - + >
@@ -267,7 +279,7 @@ if (isset($_GET['quote_id'])) {