diff --git a/invoice.php b/invoice.php index 437fc32c..91f50d93 100644 --- a/invoice.php +++ b/invoice.php @@ -290,14 +290,32 @@ if (isset($_GET['invoice_id'])) { -
+
- + - - + + +
diff --git a/post/invoice.php b/post/invoice.php index 3357cad9..6ea3bf49 100644 --- a/post/invoice.php +++ b/post/invoice.php @@ -1086,6 +1086,7 @@ if (isset($_POST['export_client_payments_csv'])) { } + if (isset($_POST['update_recurring_item_order'])) { $item_id = intval($_POST['item_id']); @@ -1121,3 +1122,38 @@ if (isset($_POST['update_recurring_item_order'])) { 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"]); +} +