Skip to content

Commit

Permalink
Merge branch 'master' into other-sorts
Browse files Browse the repository at this point in the history
  • Loading branch information
o-psi authored Oct 16, 2023
2 parents 3c391b9 + cce1dc8 commit 2d061c0
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
26 changes: 22 additions & 4 deletions invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,14 +290,32 @@

<tr>
<td>
<div class="d-print-none">
<div class="d-print-none row">
<?php if ($invoice_status !== "Paid" && $invoice_status !== "Cancelled") { ?>
<form action="post.php" method="post">
<input type="hidden" name="invoice_id" value="<?php echo $invoice_id; ?>">
<input type="hidden" name="item_invoice_id" value="<?php echo $invoice_id; ?>">
<input type="hidden" name="item_id" value="<?php echo $item_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>
<?php
// Logic to check if top or bottom arrow should be hidden
if ($item_order == 1) {
$up_hidden = "hidden";
} else {
$up_hidden = "";
}

if ($item_order == mysqli_num_rows($sql_invoice_items)) {
$down_hidden = "hidden";
} else {
$down_hidden = "";
}
?>
<button class="btn btn-sm btn-light" type="submit" name="update_invoice_item_order" value="up" <?php echo $up_hidden; ?>>
<i class="fas fa-arrow-up"></i>
</button>
<button class="btn btn-sm btn-light" type="submit" name="update_invoice_item_order" value="down" <?php echo $down_hidden; ?>>
<i class="fas fa-arrow-down"></i>
</button>
</form>
<?php } ?>

Expand Down
36 changes: 36 additions & 0 deletions post/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -1086,6 +1086,7 @@
}



if (isset($_POST['update_recurring_item_order'])) {

$item_id = intval($_POST['item_id']);
Expand Down Expand Up @@ -1121,3 +1122,38 @@
header("Location: " . $_SERVER["HTTP_REFERER"]);
}

if (isset($_POST['update_invoice_item_order'])) {

$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);
$current_order = intval($row['item_order']);
$update_direction = sanitizeInput($_POST['update_invoice_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_invoice_id = $item_invoice_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'] = "Invoice Item Order Updated";

header("Location: " . $_SERVER["HTTP_REFERER"]);
}

0 comments on commit 2d061c0

Please sign in to comment.