mirror of
https://github.com/itflow-org/itflow
synced 2026-02-28 10:54:52 +00:00
Merge pull request #1171 from ssteeltm/drag-and-drop-items
Drag and drop items
This commit is contained in:
45
invoice.php
45
invoice.php
@@ -157,6 +157,7 @@ if (isset($_GET['invoice_id'])) {
|
||||
|
||||
|
||||
?>
|
||||
<link rel="stylesheet" href="/plugins/dragula/dragula.min.css">
|
||||
|
||||
<ol class="breadcrumb d-print-none">
|
||||
<?php if (isset($_GET['client_id'])) { ?>
|
||||
@@ -338,7 +339,7 @@ if (isset($_GET['invoice_id'])) {
|
||||
<div class="col-md-12">
|
||||
<div class="card">
|
||||
<div class="table-responsive">
|
||||
<table class="table">
|
||||
<table class="table" id="items">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="d-print-none"></th>
|
||||
@@ -381,7 +382,7 @@ if (isset($_GET['invoice_id'])) {
|
||||
$down_hidden = "";
|
||||
}
|
||||
?>
|
||||
<tr>
|
||||
<tr data-item-id="<?php echo $item_id; ?>">
|
||||
<td class="d-print-none">
|
||||
<?php if ($invoice_status !== "Paid" && $invoice_status !== "Cancelled") { ?>
|
||||
<div class="dropdown">
|
||||
@@ -412,7 +413,7 @@ if (isset($_GET['invoice_id'])) {
|
||||
|
||||
<?php } ?>
|
||||
</td>
|
||||
<td><?php echo $item_name; ?></td>
|
||||
<td class="grab-cursor"><?php echo $item_name; ?></td>
|
||||
<td><?php echo nl2br($item_description); ?></td>
|
||||
<td class="text-center"><?php echo number_format($item_quantity, 2); ?></td>
|
||||
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $item_price, $invoice_currency_code); ?></td>
|
||||
@@ -707,7 +708,7 @@ require_once "includes/footer.php";
|
||||
<script src="plugins/jquery-ui/jquery-ui.min.js"></script>
|
||||
<script>
|
||||
$(function() {
|
||||
var availableProducts = <?php echo $json_products?>;
|
||||
var availableProducts = <?php echo $json_products ?? '""'?>;
|
||||
|
||||
$("#name").autocomplete({
|
||||
source: availableProducts,
|
||||
@@ -1174,3 +1175,39 @@ require_once "includes/footer.php";
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<script src="plugins/dragula/dragula.min.js"></script>
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var container = $('table#items tbody')[0];
|
||||
|
||||
dragula([container])
|
||||
.on('drop', function (el, target, source, sibling) {
|
||||
// Handle the drop event to update the order in the database
|
||||
var rows = $(container).children();
|
||||
var positions = rows.map(function(index, row) {
|
||||
return {
|
||||
id: $(row).data('itemId'),
|
||||
order: index
|
||||
};
|
||||
}).get();
|
||||
|
||||
// Send the new order to the server
|
||||
$.ajax({
|
||||
url: 'ajax.php',
|
||||
method: 'POST',
|
||||
data: {
|
||||
update_invoice_items_order: true,
|
||||
invoice_id: <?php echo $invoice_id; ?>,
|
||||
positions: positions
|
||||
},
|
||||
success: function(data) {
|
||||
// Handle success
|
||||
},
|
||||
error: function(error) {
|
||||
console.error('Error updating order:', error);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user