Skip to content

Commit

Permalink
post actions for changing sort
Browse files Browse the repository at this point in the history
  • Loading branch information
o-psi committed Oct 14, 2023
1 parent ffa0226 commit b4396fe
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion post/invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

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

}

}

0 comments on commit b4396fe

Please sign in to comment.