From 0270a680a6492944e0dc5bb4c20e73f718429032 Mon Sep 17 00:00:00 2001 From: o-psi Date: Fri, 13 Oct 2023 20:54:41 -0500 Subject: [PATCH] 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 {