From 3036dbdab26d97e659c0d40d9f3d59c87b31ab07 Mon Sep 17 00:00:00 2001 From: "johnny@pittpc.com" Date: Fri, 7 Feb 2020 01:51:49 -0500 Subject: [PATCH] Updated recurring as well as quote details to mimic invoice details overhaul --- edit_invoice_item_modal.php | 2 +- edit_quote_item_modal.php | 85 ++++++++ edit_recurring_item_modal.php | 85 ++++++++ invoice.php | 5 +- post.php | 189 +++++++++++++----- quote.php | 357 +++++++++++++++++++--------------- quote_note_modal.php | 24 +++ recurring_invoice.php | 346 +++++++++++++++++--------------- recurring_note_modal.php | 24 +++ 9 files changed, 744 insertions(+), 373 deletions(-) create mode 100644 edit_quote_item_modal.php create mode 100644 edit_recurring_item_modal.php create mode 100644 quote_note_modal.php create mode 100644 recurring_note_modal.php diff --git a/edit_invoice_item_modal.php b/edit_invoice_item_modal.php index ecfdead9..27e696b0 100644 --- a/edit_invoice_item_modal.php +++ b/edit_invoice_item_modal.php @@ -76,7 +76,7 @@ diff --git a/edit_quote_item_modal.php b/edit_quote_item_modal.php new file mode 100644 index 00000000..25a7316f --- /dev/null +++ b/edit_quote_item_modal.php @@ -0,0 +1,85 @@ + \ No newline at end of file diff --git a/edit_recurring_item_modal.php b/edit_recurring_item_modal.php new file mode 100644 index 00000000..f738eb27 --- /dev/null +++ b/edit_recurring_item_modal.php @@ -0,0 +1,85 @@ + \ No newline at end of file diff --git a/invoice.php b/invoice.php index 0015b76f..aed315ba 100644 --- a/invoice.php +++ b/invoice.php @@ -232,7 +232,7 @@ if(isset($_GET['invoice_id'])){ - + @@ -245,7 +245,7 @@ if(isset($_GET['invoice_id'])){ - diff --git a/post.php b/post.php index da4b5e67..d6561252 100644 --- a/post.php +++ b/post.php @@ -1551,44 +1551,77 @@ if(isset($_POST['add_quote_to_invoice'])){ } -if(isset($_POST['save_quote'])){ +if(isset($_POST['add_quote_line_item'])){ $quote_id = intval($_POST['quote_id']); - if(!empty($_POST['name'])){ - $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); - $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); - $qty = floatval($_POST['qty']); - $price = floatval($_POST['price']); - $tax = floatval($_POST['tax']); - - $subtotal = $price * $qty; - $tax = $subtotal * $tax; - $total = $subtotal + $tax; + $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); + $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); + $qty = floatval($_POST['qty']); + $price = floatval($_POST['price']); + $tax = floatval($_POST['tax']); + + $subtotal = $price * $qty; + $tax = $subtotal * $tax; + $total = $subtotal + $tax; - mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = '$price', item_subtotal = '$subtotal', item_tax = '$tax', item_total = '$total', item_created_at = NOW(), quote_id = $quote_id, company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = '$price', item_subtotal = '$subtotal', item_tax = '$tax', item_total = '$total', item_created_at = NOW(), quote_id = $quote_id, company_id = $session_company_id"); - //Update Invoice Balances + //Update Invoice Balances - $sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE quote_id = $quote_id AND company_id = $session_company_id"); - $row = mysqli_fetch_array($sql); + $sql = mysqli_query($mysqli,"SELECT * FROM quotes WHERE quote_id = $quote_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); - $new_quote_amount = $row['quote_amount'] + $total; + $new_quote_amount = $row['quote_amount'] + $total; - mysqli_query($mysqli,"UPDATE quotes SET quote_amount = '$new_quote_amount', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id"); + mysqli_query($mysqli,"UPDATE quotes SET quote_amount = '$new_quote_amount', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id"); - $_SESSION['alert_message'] = "Item added"; + $_SESSION['alert_message'] = "Item added"; - } + header("Location: " . $_SERVER["HTTP_REFERER"]); +} - if(isset($_POST['quote_note'])){ - $quote_note = strip_tags(mysqli_real_escape_string($mysqli,$_POST['quote_note'])); +if(isset($_POST['quote_note'])){ + + $quote_id = intval($_POST['quote_id']); + $note = strip_tags(mysqli_real_escape_string($mysqli,$_POST['note'])); - mysqli_query($mysqli,"UPDATE quotes SET quote_note = '$quote_note', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id"); + mysqli_query($mysqli,"UPDATE quotes SET quote_note = '$note', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id"); - $_SESSION['alert_message'] = "Notes added"; - } + $_SESSION['alert_message'] = " Notes added"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + +header("Location: " . $_SERVER["HTTP_REFERER"]); + +if(isset($_POST['edit_quote_item'])){ + + $quote_id = intval($_POST['quote_id']); + $item_id = intval($_POST['item_id']); + $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); + $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); + $qty = floatval($_POST['qty']); + $price = floatval($_POST['price']); + $tax = floatval($_POST['tax']); + + $subtotal = $price * $qty; + $tax = $subtotal * $tax; + $total = $subtotal + $tax; + + mysqli_query($mysqli,"UPDATE invoice_items SET item_name = '$name', item_description = '$description', item_quantity = '$qty', item_price = '$price', item_subtotal = '$subtotal', item_tax = '$tax', item_total = '$total' WHERE item_id = $item_id"); + + //Update Invoice Balances by tallying up invoice items + + $sql_quote_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS quote_total FROM invoice_items WHERE quote_id = $quote_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql_quote_total); + $new_quote_amount = $row['quote_total']; + + mysqli_query($mysqli,"UPDATE quotes SET quote_amount = '$new_quote_amount', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id"); + + $_SESSION['alert_message'] = " Item updated"; header("Location: " . $_SERVER["HTTP_REFERER"]); @@ -1667,6 +1700,23 @@ if(isset($_GET['delete_quote_item'])){ } +if(isset($_GET['mark_quote_sent'])){ + + $quote_id = intval($_GET['mark_quote_sent']); + + mysqli_query($mysqli,"UPDATE quotes SET quote_status = 'Sent', quote_updated_at = NOW() WHERE quote_id = $quote_id AND company_id = $session_company_id"); + + mysqli_query($mysqli,"INSERT INTO history SET history_date = CURDATE(), history_status = 'Sent', history_description = 'QUOTE marked sent', history_created_at = NOW(), quote_id = $quote_id, company_id = $session_company_id"); + + //Logging + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Updated', log_description = '$quote_id marked sent', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id"); + + $_SESSION['alert_message'] = " Quote marked sent"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if(isset($_GET['approve_quote'])){ $quote_id = intval($_GET['approve_quote']); @@ -1678,7 +1728,7 @@ if(isset($_GET['approve_quote'])){ //Logging mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Modified', log_description = 'Approved Quote $quote_id', log_created_at = NOW(), company_id = $session_company_id, user_id = $session_user_id"); - $_SESSION['alert_message'] = "Quote approved"; + $_SESSION['alert_message'] = " Quote approved"; header("Location: " . $_SERVER["HTTP_REFERER"]); @@ -2045,41 +2095,29 @@ if(isset($_GET['recurring_deactivate'])){ } -if(isset($_POST['save_recurring'])){ +if(isset($_POST['add_recurring_line_item'])){ $recurring_id = intval($_POST['recurring_id']); + $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); + $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); + $qty = floatval($_POST['qty']); + $price = floatval($_POST['price']); + $tax = floatval($_POST['tax']); - if(!empty($_POST['name'])){ - $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); - $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); - $qty = floatval($_POST['qty']); - $price = floatval($_POST['price']); - $tax = floatval($_POST['tax']); - - $subtotal = $price * $qty; - $tax = $subtotal * $tax; - $total = $subtotal + $tax; + $subtotal = $price * $qty; + $tax = $subtotal * $tax; + $total = $subtotal + $tax; - mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = '$price', item_subtotal = '$subtotal', item_tax = '$tax', item_total = '$total', item_created_at = NOW(), recurring_id = $recurring_id, company_id = $session_company_id"); + mysqli_query($mysqli,"INSERT INTO invoice_items SET item_name = '$name', item_description = '$description', item_quantity = $qty, item_price = '$price', item_subtotal = '$subtotal', item_tax = '$tax', item_total = '$total', item_created_at = NOW(), recurring_id = $recurring_id, company_id = $session_company_id"); - //Update Invoice Balances + //Update Invoice Balances - $sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); - $row = mysqli_fetch_array($sql); + $sql = mysqli_query($mysqli,"SELECT * FROM recurring WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql); - $new_recurring_amount = $row['recurring_amount'] + $total; + $new_recurring_amount = $row['recurring_amount'] + $total; - mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); - - } - - if(isset($_POST['recurring_note'])){ - - $recurring_note = strip_tags(mysqli_real_escape_string($mysqli,$_POST['recurring_note'])); - - mysqli_query($mysqli,"UPDATE recurring SET recurring_note = '$recurring_note', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); - - } + mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); $_SESSION['alert_message'] = "Recurring Invoice Updated"; @@ -2087,6 +2125,49 @@ if(isset($_POST['save_recurring'])){ } +if(isset($_POST['recurring_note'])){ + + $recurring_id = intval($_POST['recurring_id']); + $note = strip_tags(mysqli_real_escape_string($mysqli,$_POST['note'])); + + mysqli_query($mysqli,"UPDATE recurring SET recurring_note = '$note', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); + + $_SESSION['alert_message'] = " Notes added"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + +if(isset($_POST['edit_recurring_item'])){ + + $recurring_id = intval($_POST['recurring_id']); + $item_id = intval($_POST['item_id']); + $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); + $description = strip_tags(mysqli_real_escape_string($mysqli,$_POST['description'])); + $qty = floatval($_POST['qty']); + $price = floatval($_POST['price']); + $tax = floatval($_POST['tax']); + + $subtotal = $price * $qty; + $tax = $subtotal * $tax; + $total = $subtotal + $tax; + + mysqli_query($mysqli,"UPDATE invoice_items SET item_name = '$name', item_description = '$description', item_quantity = '$qty', item_price = '$price', item_subtotal = '$subtotal', item_tax = '$tax', item_total = '$total' WHERE item_id = $item_id"); + + //Update Invoice Balances by tallying up invoice items + + $sql_recurring_total = mysqli_query($mysqli,"SELECT SUM(item_total) AS recurring_total FROM invoice_items WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); + $row = mysqli_fetch_array($sql_recurring_total); + $new_recurring_amount = $row['recurring_total']; + + mysqli_query($mysqli,"UPDATE recurring SET recurring_amount = '$new_recurring_amount', recurring_updated_at = NOW() WHERE recurring_id = $recurring_id AND company_id = $session_company_id"); + + $_SESSION['alert_message'] = "Item updated"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + +} + if(isset($_GET['delete_recurring_item'])){ $item_id = intval($_GET['delete_recurring_item']); @@ -2184,7 +2265,7 @@ if(isset($_GET['delete_invoice'])){ } -if(isset($_POST['add_invoice_line_item'])){ +if(isset($_POST['add_invoice_item'])){ $invoice_id = intval($_POST['invoice_id']); $name = strip_tags(mysqli_real_escape_string($mysqli,$_POST['name'])); @@ -2228,7 +2309,7 @@ if(isset($_POST['invoice_note'])){ } -if(isset($_POST['edit_item'])){ +if(isset($_POST['edit_invoice_item'])){ $invoice_id = intval($_POST['invoice_id']); $item_id = intval($_POST['item_id']); diff --git a/quote.php b/quote.php index 6735c4dd..21e3f04f 100644 --- a/quote.php +++ b/quote.php @@ -65,190 +65,230 @@ if(isset($_GET['quote_id'])){ -
- -
-
-
-
- Approve +
+
+ +
+ +
+ + + -
- + +
+
+
-
+
-
-
- -
-
-

Quote

-
+
+
+
-
-
-
    -
  • -
  • -
  • -
  • P:
  • -
  • -
-
-
-
    -
  • -
  • -
  • -
  • P:
  • -
  • E:
  • -
-
+
+

Quote

-
-
-
-
- - - - - -
Quote Date
-
-
+
+
+
+
    +
  • +
  • +
  • +
  • P:
  • +
  • +
+
+
+
    +
  • +
  • +
  • +
  • P:
  • +
  • E:
  • +
+
+
+
+
+
+
+ + + + + +
Quote Date
+
+
- + -
-
-
- - - - - - - - - - - - - - - +
+
- 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; +
ProductDescriptionQtyPriceTaxTotal
+ + + + + + + + + + + + + + ?> - - - - - - - - - + + + + + + + + + - + } - + ?> + + + + - - - + + + - - - -
ItemDescriptionQTYPriceTaxTotal
$$$
+ + + $$$
-
-
-
-
- -
-
-
-
-
-
-
- -
- -
- - - - - - - 0){ ?> - - - - - - 0){ ?> - - - - - - - - + +
Subtotal$
Discount$
Tax$
Total$ + +
- +
+ +
+
+
+
+ Notes +
+ + + +
+
+
+
+
+
+
+ +
+ + + + + + + 0){ ?> + + + + + + 0){ ?> + + + + + + + + + + +
Subtotal$
Discount$
Tax$
Total$
+
+

@@ -260,7 +300,15 @@ if(isset($_GET['quote_id'])){
- History + History +
+ + +
@@ -299,6 +347,7 @@ if(isset($_GET['quote_id'])){ + diff --git a/quote_note_modal.php b/quote_note_modal.php new file mode 100644 index 00000000..f3d67ecb --- /dev/null +++ b/quote_note_modal.php @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/recurring_invoice.php b/recurring_invoice.php index 2d1ece7a..ba65cd59 100644 --- a/recurring_invoice.php +++ b/recurring_invoice.php @@ -61,196 +61,211 @@ if(isset($_GET['recurring_id'])){ - - -
-
+
+
-
-
- -
-
-
- - - - - - - - - - - - -
Start Date
Next Date
Last Sent
-
-
+
+
+
+
    +
  • +
  • +
  • +
  • P:
  • +
  • +
+
+
+
    +
  • +
  • +
  • +
  • P:
  • +
  • E:
  • +
+
+
+
+
+
+
+ + + + + + + + + + + + + +
Start Date
Next Date
Last Sent
+
+
- + -
-
-
- - - - - - - - - - - - - - - +
+
- 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; +
ProductDescriptionQtyPriceTaxTotal
+ + + + + + + + + + + + + + ?> - - - - - - - - - + + + + + + + + + - + } - + ?> + + + + - + - + - - - -
ItemDescriptionQTYPriceTaxTotal
- - - $$$
+ + + $$$
-
-
-
-
- -
-
-
-
-
-
-
- -
-
- - - - - - - 0){ ?> - - - - - - 0){ ?> - - - - - - - - + +
Subtotal$
Discount$
Tax$
Amount$ + +
- +
+ +
+
+
+
+ Notes +
+ + + +
+
+
+
+
+
+
+
+ + + + + + + 0){ ?> + + + + + + 0){ ?> + + + + + + + + + + +
Subtotal$
Discount$
Tax$
Amount$
+
+
@@ -258,7 +273,15 @@ if(isset($_GET['recurring_id'])){
- History + History +
+ + +
@@ -293,6 +316,7 @@ if(isset($_GET['recurring_id'])){ + diff --git a/recurring_note_modal.php b/recurring_note_modal.php new file mode 100644 index 00000000..99eb2335 --- /dev/null +++ b/recurring_note_modal.php @@ -0,0 +1,24 @@ + \ No newline at end of file