diff --git a/database_updates.php b/database_updates.php index 8407e94ca..d5b577a64 100644 --- a/database_updates.php +++ b/database_updates.php @@ -1405,12 +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` 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 = 1; + foreach ($sql_invoice_items as $row) { + $item_id = $row['item_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 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.9'"); - //} + mysqli_query($mysqli, "UPDATE `settings` SET `config_current_database_version` = '0.8.9'"); + } // } else { diff --git a/db.sql b/db.sql index a3ea42410..2ba998006 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` 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 047a1676e..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_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 ab1ac0064..437fc32c0 100644 --- a/invoice.php +++ b/invoice.php @@ -247,7 +247,7 @@ - +
Sort | Item | Description | @@ -283,10 +284,26 @@ $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']); ?>|
---|---|---|---|
+
+
+
+
+
+
+ |
+
@@ -323,6 +340,8 @@
|