Skip to content

Commit

Permalink
changed to item_order
Browse files Browse the repository at this point in the history
  • Loading branch information
o-psi committed Oct 14, 2023
1 parent 0270a68 commit ed269e1
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 20 deletions.
12 changes: 6 additions & 6 deletions database_updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'");

}
}
Expand Down
2 changes: 1 addition & 1 deletion db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion guest_view_invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");

?>

Expand Down
8 changes: 4 additions & 4 deletions invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@
</div>
</div>

<?php $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order_id ASC"); ?>
<?php $sql_invoice_items = mysqli_query($mysqli, "SELECT * FROM invoice_items WHERE item_invoice_id = $invoice_id ORDER BY item_order ASC"); ?>

<div class="row mb-4">
<div class="col-md-12">
Expand Down Expand Up @@ -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']);

?>

Expand All @@ -295,7 +295,7 @@
<form action="post.php" method="post">
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
<input type="hidden" name="item_id" value="<?php echo $item_id; ?>">
<input type="hidden" name="item_order_id" value="<?php echo $item_order_id; ?>">
<input type="hidden" name="item_order" value="<?php echo $item_order; ?>">
<button class="btn btn-sm btn-light" type="submit" name="update_invoice_item_order" value="up"><i class="fa fa-fw fa-arrow-up"></i></button>
<button class="btn btn-sm btn-light" type="submit" name="update_invoice_item_order" value="down"><i class="fa fa-fw fa-arrow-down"></i></button>
</form>
Expand Down Expand Up @@ -340,7 +340,7 @@
<tr class="d-print-none" <?php if ($invoice_status == "Paid" || $invoice_status == "Cancelled") { echo "hidden"; } ?>>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
<input type="hidden" name="item_order_id" value="<?php echo mysqli_num_rows($sql_invoice_items) + 1; ?>">
<input type="hidden" name="item_order" value="<?php echo mysqli_num_rows($sql_invoice_items) + 1; ?>">
<td></td>
<td></td>
<td>
Expand Down
16 changes: 8 additions & 8 deletions post/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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

Expand Down Expand Up @@ -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)) {
Expand All @@ -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";

Expand All @@ -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";

Expand Down

0 comments on commit ed269e1

Please sign in to comment.