diff --git a/database_updates.php b/database_updates.php index d5b577a6..c5c164ab 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1430,6 +1430,49 @@ if (LATEST_DATABASE_VERSION > CURRENT_DATABASE_VERSION) { } // + // Be sure to change database_version.php to reflect the version you are updating to here + // Please add this same comment block to the bottom of this file, and update the version number. + // Uncomment Below Lines, to add additional database updates + // + if (CURRENT_DATABASE_VERSION == '0.8.9') { + // Insert queries here required to update to DB version 0.8.9 + // Update existing quotes and recurrings so that item_order is set to item_id + $sql_quotes = mysqli_query($mysqli, "SELECT quote_id FROM quotes WHERE quote_id IS NOT NULL"); + $sql_recurrings = mysqli_query($mysqli, "SELECT recurring_id FROM recurring WHERE recurring_id IS NOT NULL"); + + foreach ($sql_quotes as $row) { + $quote_id = $row['quote_id']; + $sql_quote_items = mysqli_query($mysqli, "SELECT item_id FROM quote_items WHERE item_quote_id = '$quote_id' ORDER BY item_id ASC"); + $item_order = 1; + foreach ($sql_quote_items as $row) { + $item_id = $row['item_id']; + mysqli_query($mysqli, "UPDATE quote_items SET item_order = '$item_order' WHERE item_id = '$item_id'"); + $item_order++; + //Log changes made to quote + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Quote', log_action = 'Modify', log_description = 'Updated item_order to item_id: $item_order'"); + } + } + + foreach ($sql_recurrings as $row) { + $recurring_id = $row['recurring_id']; + $sql_recurring_items = mysqli_query($mysqli, "SELECT item_id FROM recurring_items WHERE item_recurring_id = '$recurring_id' ORDER BY item_id ASC"); + $item_order = 1; + foreach ($sql_recurring_items as $row) { + $item_id = $row['item_id']; + mysqli_query($mysqli, "UPDATE recurring_items SET item_order = '$item_order' WHERE item_id = '$item_id'"); + $item_order++; + //Log changes made to recurring + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Recurring', log_action = 'Modify', log_description = 'Updated item_order to item_id: $item_order'"); + } + } + + + // + // Then, update the database to the next sequential version + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.10'"); + } + // + } else { // Up-to-date } diff --git a/database_version.php b/database_version.php index dc549dcd..f86589f2 100644 --- a/database_version.php +++ b/database_version.php @@ -5,4 +5,4 @@ * It is used in conjunction with database_updates.php */ -DEFINE("LATEST_DATABASE_VERSION", "0.8.9"); +DEFINE("LATEST_DATABASE_VERSION", "0.8.10"); diff --git a/guest_view_quote.php b/guest_view_quote.php index fcc4d3e6..83a62db0 100644 --- a/guest_view_quote.php +++ b/guest_view_quote.php @@ -158,7 +158,7 @@ if ($quote_status == "Draft" || $quote_status == "Sent" || $quote_status == "Vie - +
diff --git a/post/invoice.php b/post/invoice.php index 5a547b27..6ea3bf49 100644 --- a/post/invoice.php +++ b/post/invoice.php @@ -247,6 +247,7 @@ if (isset($_POST['add_recurring_item'])) { $qty = floatval($_POST['qty']); $price = floatval($_POST['price']); $tax_id = intval($_POST['tax_id']); + $item_order = intval($_POST['item_order']); $subtotal = $price * $qty; @@ -261,7 +262,7 @@ if (isset($_POST['add_recurring_item'])) { $total = $subtotal + $tax_amount; - 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_amount, item_total = $total, item_tax_id = $tax_id, item_recurring_id = $recurring_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_amount, item_total = $total, item_tax_id = $tax_id, item_order = $item_order, item_recurring_id = $recurring_id"); //Update Recurring Balances @@ -1085,6 +1086,42 @@ if (isset($_POST['export_client_payments_csv'])) { } + +if (isset($_POST['update_recurring_item_order'])) { + + $item_id = intval($_POST['item_id']); + $item_recurring_id = intval($_POST['item_recurring_id']); + + $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_id = $item_id"); + $row = mysqli_fetch_array($sql); + $current_order = intval($row['item_order']); + $update_direction = sanitizeInput($_POST['update_recurring_item_order']); + + switch ($update_direction) + { + case 'up': + $new_order = $current_order - 1; + break; + case 'down': + $new_order = $current_order + 1; + break; + } + + //Find item_id of current item in $new_order + $other_sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_recurring_id = $item_recurring_id AND item_order = $new_order"); + $other_row = mysqli_fetch_array($other_sql); + $other_item_id = intval($other_row['item_id']); + $other_row_str = strval($other_row['item_name']); + + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $new_order WHERE item_id = $item_id"); + + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $current_order WHERE item_id = $other_item_id"); + + $_SESSION['alert_message'] = "recurring Item Order Updated"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); +} + if (isset($_POST['update_invoice_item_order'])) { $item_id = intval($_POST['item_id']); @@ -1118,4 +1155,5 @@ if (isset($_POST['update_invoice_item_order'])) { $_SESSION['alert_message'] = "Invoice Item Order Updated"; header("Location: " . $_SERVER["HTTP_REFERER"]); -} \ No newline at end of file +} + diff --git a/post/quote.php b/post/quote.php index 7b679d3c..fa4daa68 100644 --- a/post/quote.php +++ b/post/quote.php @@ -150,6 +150,7 @@ if (isset($_POST['add_quote_item'])) { $qty = floatval($_POST['qty']); $price = floatval($_POST['price']); $tax_id = intval($_POST['tax_id']); + $item_order = intval($_POST['item_order']); $subtotal = $price * $qty; @@ -164,7 +165,7 @@ if (isset($_POST['add_quote_item'])) { $total = $subtotal + $tax_amount; - 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_amount, item_total = $total, item_tax_id = $tax_id, item_quote_id = $quote_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_amount, item_total = $total, item_tax_id = $tax_id, item_order = $item_order, item_quote_id = $quote_id"); //Update Invoice Balances @@ -433,3 +434,60 @@ if(isset($_POST['export_client_quotes_csv'])){ exit; } + +if (isset($_POST['update_quote_item_order'])) { + + if ($_POST['update_quote_item_order'] == 'up') { + $item_id = intval($_POST['item_id']); + $item_quote_id = intval($_POST['item_quote_id']); + + $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_id = $item_id"); + $row = mysqli_fetch_array($sql); + $item_order = intval($row['item_order']); + + $new_item_order = $item_order - 1; + + //Check if new item order is used + $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_quote_id = $item_quote_id AND item_order = $new_item_order"); + + //Redo the entire order of list + while ($row = mysqli_fetch_array($sql)) { + $item_id = intval($row['item_id']); + $item_order = intval($row['item_order']); + + $new_item_order = $item_order + 1; + + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $new_item_order WHERE item_id = $item_id"); + } + + + + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $item_order WHERE item_quote_id = $item_quote_id AND item_order = $new_item_order"); + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $new_item_order WHERE item_id = $item_id"); + + $_SESSION['alert_message'] = "Item moved up"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + + } + + if ($_POST['update_quote_item_order'] == 'down') { + $item_id = intval($_POST['item_id']); + $item_quote_id = intval($_POST['item_quote_id']); + + $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_id = $item_id"); + $row = mysqli_fetch_array($sql); + $item_order = intval($row['item_order']); + + $new_item_order = $item_order + 1; + + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $item_order WHERE item_quote_id = $item_quote_id AND item_order = $new_item_order"); + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $new_item_order WHERE item_id = $item_id"); + + $_SESSION['alert_message'] = "Item moved down"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + + } + +} \ No newline at end of file diff --git a/quote.php b/quote.php index dc33d198..6bada633 100644 --- a/quote.php +++ b/quote.php @@ -239,7 +239,7 @@ if (isset($_GET['quote_id'])) {
- +
@@ -267,6 +267,7 @@ if (isset($_GET['quote_id'])) { $item_id = intval($row['item_id']); $item_name = nullable_htmlentities($row['item_name']); $item_description = nullable_htmlentities($row['item_description']); + $item_order = intval($row['item_order']); $item_quantity = number_format(floatval($row['item_quantity']),2); $item_price = floatval($row['item_price']); $item_tax = floatval($row['item_tax']); @@ -276,11 +277,36 @@ if (isset($_GET['quote_id'])) { $total_tax = $item_tax + $total_tax; $sub_total = $item_price * $item_quantity + $sub_total; - ?> + // Logic to check if top or bottom arrow should be hidden by looking at max and min of item_order + $sql = mysqli_query($mysqli, "SELECT MAX(item_order) AS item_order FROM invoice_items WHERE item_quote_id = $quote_id"); + $row = mysqli_fetch_array($sql); + $max_item_order = intval($row['item_order']); + $sql = mysqli_query($mysqli, "SELECT MIN(item_order) AS item_order FROM invoice_items WHERE item_quote_id = $quote_id"); + $row = mysqli_fetch_array($sql); + $min_item_order = intval($row['item_order']); + + if ($item_order == $max_item_order) { + $down_hidden = "hidden"; + } else { + $down_hidden = ""; + } + + if ($item_order == $min_item_order) { + $up_hidden = "hidden"; + } else { + $up_hidden = ""; + } + + + + //This is prefered over the screen seen in the invoice menu. + ?> + +
@@ -318,6 +352,13 @@ if (isset($_GET['quote_id'])) { >
+ "> diff --git a/recurring_invoice.php b/recurring_invoice.php index 2f6c1647..304826dc 100644 --- a/recurring_invoice.php +++ b/recurring_invoice.php @@ -179,7 +179,7 @@ if (isset($_GET['recurring_id'])) {
- +
@@ -215,7 +215,28 @@ if (isset($_GET['recurring_id'])) { $tax_id = intval($row['item_tax_id']); $total_tax = $item_tax + $total_tax; $sub_total = $item_price * $item_quantity + $sub_total; + $item_order = intval($row['item_order']); + + // Logic to check if top or bottom arrow should be hidden by looking at max and min of item_order + $sql = mysqli_query($mysqli, "SELECT MAX(item_order) AS item_order FROM invoice_items WHERE item_recurring_id = $recurring_id"); + $row = mysqli_fetch_array($sql); + $max_item_order = intval($row['item_order']); + $sql = mysqli_query($mysqli, "SELECT MIN(item_order) AS item_order FROM invoice_items WHERE item_recurring_id = $recurring_id"); + $row = mysqli_fetch_array($sql); + $min_item_order = intval($row['item_order']); + + if ($item_order == $max_item_order) { + $down_hidden = "hidden"; + } else { + $down_hidden = ""; + } + + if ($item_order == $min_item_order) { + $up_hidden = "hidden"; + } else { + $up_hidden = ""; + } ?> @@ -228,6 +249,14 @@ if (isset($_GET['recurring_id'])) { Edit Remove + + + + + + + +
@@ -250,6 +279,13 @@ if (isset($_GET['recurring_id'])) {
+ ">