From 141dad23fe0c4322e3d0f0192c809a1547214914 Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:12:43 -0500 Subject: [PATCH 1/7] Update database, did not do increment --- database_updates.php | 1 + db.sql | 1 + 2 files changed, 2 insertions(+) diff --git a/database_updates.php b/database_updates.php index 8407e94ca..e69dd3bc3 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1407,6 +1407,7 @@ // //if (CURRENT_DATABASE_VERSION == '0.8.8') { // Insert queries here required to update to DB version 0.8.9 + // mysqli_query($mysqli, "ALTER TABLE `invoice_items` ADD `item_order_id` INT(11) NOT NULL DEFAULT 0 AFTER `item_total`"); // // Then, update the database to the next sequential version //mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.9'"); diff --git a/db.sql b/db.sql index a3ea42410..c777a9dcd 100644 --- a/db.sql +++ b/db.sql @@ -682,6 +682,7 @@ CREATE TABLE `invoice_items` ( `item_subtotal` decimal(15,2) NOT NULL DEFAULT 0.00, `item_tax` decimal(15,2) NOT NULL DEFAULT 0.00, `item_total` decimal(15,2) NOT NULL DEFAULT 0.00, + `item_order_id` int(11) NOT NULL DEFAULT 0, `item_created_at` datetime NOT NULL DEFAULT current_timestamp(), `item_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `item_archived_at` datetime DEFAULT NULL, From 097690bfbda3c4fea135082c25ebfd09446beae3 Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:12:58 -0500 Subject: [PATCH 2/7] add sort to guest view --- guest_view_invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/guest_view_invoice.php b/guest_view_invoice.php index 047a1676e..6b2db4709 100644 --- a/guest_view_invoice.php +++ b/guest_view_invoice.php @@ -116,7 +116,7 @@ } // Invoice individual items -$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_id ASC"); +$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order_id ASC"); ?> From ffa02260678741b92a6ad2186bec3a11effc62cf Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:13:28 -0500 Subject: [PATCH 3/7] add item sort dropdowns --- invoice.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/invoice.php b/invoice.php index ab1ac0064..7ebdd7862 100644 --- a/invoice.php +++ b/invoice.php @@ -247,7 +247,7 @@ - +
@@ -256,6 +256,7 @@ + @@ -283,10 +284,28 @@ $tax_id = intval($row['item_tax_id']); $total_tax = $item_tax + $total_tax; $sub_total = $item_price * $item_quantity + $sub_total; + $item_order_id = intval($row['item_order_id']); ?> + + > + + From 0270a680a6492944e0dc5bb4c20e73f718429032 Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:54:41 -0500 Subject: [PATCH 6/7] update invoices --- database_updates.php | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/database_updates.php b/database_updates.php index e69dd3bc3..ca8598fd6 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1405,13 +1405,29 @@ // 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.8') { + if (CURRENT_DATABASE_VERSION == '0.8.8') { // Insert queries here required to update to DB version 0.8.9 - // mysqli_query($mysqli, "ALTER TABLE `invoice_items` ADD `item_order_id` INT(11) NOT NULL DEFAULT 0 AFTER `item_total`"); + mysqli_query($mysqli, "ALTER TABLE `invoice_items` ADD `item_order_id` INT(11) NOT NULL DEFAULT 0 AFTER `item_total`"); + // Update existing invoices so that item_order_id is set to item_id + $sql_invoices = mysqli_query($mysqli, "SELECT invoice_id FROM invoices WHERE invoice_id IS NOT NULL"); + foreach ($sql_invoices as $row) { + $invoice_id = $row['invoice_id']; + $sql_invoice_items = mysqli_query($mysqli, "SELECT item_id FROM invoice_items WHERE item_invoice_id = '$invoice_id' ORDER BY item_id ASC"); + $item_order_id = 1; + foreach ($sql_invoice_items as $row) { + $item_id = $row['item_id']; + mysqli_query($mysqli, "UPDATE invoice_items SET item_order_id = '$item_order_id' WHERE item_id = '$item_id'"); + $item_order_id++; + //Log changes made to invoice + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Modify', log_description = 'Updated item_order_id to item_id: $item_order_id'"); + + } + } + // // Then, update the database to the next sequential version - //mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.9'"); - //} + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.9'"); + } // } else { From ed269e124526e9cb759931cf2b8e03856c65575e Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 22:49:28 -0500 Subject: [PATCH 7/7] changed to item_order --- database_updates.php | 12 ++++++------ db.sql | 2 +- guest_view_invoice.php | 2 +- invoice.php | 8 ++++---- post/invoice.php | 16 ++++++++-------- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/database_updates.php b/database_updates.php index ca8598fd6..d5b577a64 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1407,19 +1407,19 @@ // if (CURRENT_DATABASE_VERSION == '0.8.8') { // Insert queries here required to update to DB version 0.8.9 - mysqli_query($mysqli, "ALTER TABLE `invoice_items` ADD `item_order_id` INT(11) NOT NULL DEFAULT 0 AFTER `item_total`"); - // Update existing invoices so that item_order_id is set to item_id + mysqli_query($mysqli, "ALTER TABLE `invoice_items` ADD `item_order` INT(11) NOT NULL DEFAULT 0 AFTER `item_total`"); + // Update existing invoices so that item_order is set to item_id $sql_invoices = mysqli_query($mysqli, "SELECT invoice_id FROM invoices WHERE invoice_id IS NOT NULL"); foreach ($sql_invoices as $row) { $invoice_id = $row['invoice_id']; $sql_invoice_items = mysqli_query($mysqli, "SELECT item_id FROM invoice_items WHERE item_invoice_id = '$invoice_id' ORDER BY item_id ASC"); - $item_order_id = 1; + $item_order = 1; foreach ($sql_invoice_items as $row) { $item_id = $row['item_id']; - mysqli_query($mysqli, "UPDATE invoice_items SET item_order_id = '$item_order_id' WHERE item_id = '$item_id'"); - $item_order_id++; + mysqli_query($mysqli, "UPDATE invoice_items SET item_order = '$item_order' WHERE item_id = '$item_id'"); + $item_order++; //Log changes made to invoice - mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Modify', log_description = 'Updated item_order_id to item_id: $item_order_id'"); + mysqli_query($mysqli,"INSERT INTO logs SET log_type = 'Invoice', log_action = 'Modify', log_description = 'Updated item_order to item_id: $item_order'"); } } diff --git a/db.sql b/db.sql index c777a9dcd..2ba998006 100644 --- a/db.sql +++ b/db.sql @@ -682,7 +682,7 @@ CREATE TABLE `invoice_items` ( `item_subtotal` decimal(15,2) NOT NULL DEFAULT 0.00, `item_tax` decimal(15,2) NOT NULL DEFAULT 0.00, `item_total` decimal(15,2) NOT NULL DEFAULT 0.00, - `item_order_id` int(11) NOT NULL DEFAULT 0, + `item_order` int(11) NOT NULL DEFAULT 0, `item_created_at` datetime NOT NULL DEFAULT current_timestamp(), `item_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(), `item_archived_at` datetime DEFAULT NULL, diff --git a/guest_view_invoice.php b/guest_view_invoice.php index 6b2db4709..b340c75ba 100644 --- a/guest_view_invoice.php +++ b/guest_view_invoice.php @@ -116,7 +116,7 @@ } // Invoice individual items -$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order_id ASC"); +$sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order ASC"); ?> diff --git a/invoice.php b/invoice.php index 4aa391fac..437fc32c0 100644 --- a/invoice.php +++ b/invoice.php @@ -247,7 +247,7 @@ - +
@@ -284,7 +284,7 @@ $tax_id = intval($row['item_tax_id']); $total_tax = $item_tax + $total_tax; $sub_total = $item_price * $item_quantity + $sub_total; - $item_order_id = intval($row['item_order_id']); + $item_order = intval($row['item_order']); ?> @@ -295,7 +295,7 @@
- + @@ -340,7 +340,7 @@
> - +
Sort Item Description
+
+ +
+ + + + + +
+ + +
+
From b4396fe244a0a5702a44a0e897edc7c99d58cee2 Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:13:40 -0500 Subject: [PATCH 4/7] post actions for changing sort --- post/invoice.php | 61 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/post/invoice.php b/post/invoice.php index 6d3922f57..4c2c0574e 100644 --- a/post/invoice.php +++ b/post/invoice.php @@ -396,6 +396,7 @@ $qty = floatval($_POST['qty']); $price = floatval($_POST['price']); $tax_id = intval($_POST['tax_id']); + $item_order_id = intval($_POST['item_order_id']); $subtotal = $price * $qty; @@ -410,7 +411,7 @@ $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_invoice_id = $invoice_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_order_id = $item_order_id, item_tax_id = $tax_id, item_invoice_id = $invoice_id"); //Update Invoice Balances @@ -1082,3 +1083,61 @@ exit; } + + +if (isset($_POST['update_invoice_item_order'])) { + + if ($_POST['update_invoice_item_order'] == 'up') { + $item_id = intval($_POST['item_id']); + $item_invoice_id = intval($_POST['item_invoice_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_invoice_id = $item_invoice_id AND item_order_id = $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_id = $new_item_order WHERE item_id = $item_id"); + } + + + + mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $item_order WHERE item_invoice_id = $item_invoice_id AND item_order_id = $new_item_order"); + mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $new_item_order WHERE item_id = $item_id"); + + $_SESSION['alert_message'] = "Item moved up"; + + header("Location: " . $_SERVER["HTTP_REFERER"]); + + } + + if ($_POST['update_invoice_item_order'] == 'down') { + $item_id = intval($_POST['item_id']); + $item_invoice_id = intval($_POST['item_invoice_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_id = $item_order WHERE item_invoice_id = $item_invoice_id AND item_order_id = $new_item_order"); + mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $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 From 7a6c3ec4707b1b63840a38174990d5ef26cfa67d Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:48:44 -0500 Subject: [PATCH 5/7] Removed the order_id echo statement for production --- invoice.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/invoice.php b/invoice.php index 7ebdd7862..4aa391fac 100644 --- a/invoice.php +++ b/invoice.php @@ -299,9 +299,7 @@ - +
diff --git a/post/invoice.php b/post/invoice.php index 4c2c0574e..d95964251 100644 --- a/post/invoice.php +++ b/post/invoice.php @@ -396,7 +396,7 @@ $qty = floatval($_POST['qty']); $price = floatval($_POST['price']); $tax_id = intval($_POST['tax_id']); - $item_order_id = intval($_POST['item_order_id']); + $item_order = intval($_POST['item_order']); $subtotal = $price * $qty; @@ -411,7 +411,7 @@ $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_order_id = $item_order_id, item_tax_id = $tax_id, item_invoice_id = $invoice_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_order = $item_order, item_tax_id = $tax_id, item_invoice_id = $invoice_id"); //Update Invoice Balances @@ -1098,7 +1098,7 @@ $new_item_order = $item_order - 1; //Check if new item order is used - $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_invoice_id = $item_invoice_id AND item_order_id = $new_item_order"); + $sql = mysqli_query($mysqli,"SELECT * FROM invoice_items WHERE item_invoice_id = $item_invoice_id AND item_order = $new_item_order"); //Redo the entire order of list while ($row = mysqli_fetch_array($sql)) { @@ -1107,13 +1107,13 @@ $new_item_order = $item_order + 1; - mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $new_item_order WHERE item_id = $item_id"); + 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_id = $item_order WHERE item_invoice_id = $item_invoice_id AND item_order_id = $new_item_order"); - mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $new_item_order WHERE item_id = $item_id"); + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $item_order WHERE item_invoice_id = $item_invoice_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"; @@ -1131,8 +1131,8 @@ $new_item_order = $item_order + 1; - mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $item_order WHERE item_invoice_id = $item_invoice_id AND item_order_id = $new_item_order"); - mysqli_query($mysqli,"UPDATE invoice_items SET item_order_id = $new_item_order WHERE item_id = $item_id"); + mysqli_query($mysqli,"UPDATE invoice_items SET item_order = $item_order WHERE item_invoice_id = $item_invoice_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";