mirror of https://github.com/itflow-org/itflow
Drag and Drop Quote Items
This commit is contained in:
parent
17920e3cda
commit
554c4d99bb
19
ajax.php
19
ajax.php
|
|
@ -726,3 +726,22 @@ if (isset($_POST['update_task_templates_order'])) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (isset($_POST['update_quote_items_order'])) {
|
||||||
|
// Update multiple quote items order
|
||||||
|
enforceUserPermission('module_sales', 2);
|
||||||
|
|
||||||
|
$positions = $_POST['positions'];
|
||||||
|
$quote_id = intval($_POST['quote_id']);
|
||||||
|
|
||||||
|
foreach ($positions as $position) {
|
||||||
|
$id = intval($position['id']);
|
||||||
|
$order = intval($position['order']);
|
||||||
|
|
||||||
|
mysqli_query($mysqli, "UPDATE invoice_items SET item_order = $order WHERE item_quote_id = $quote_id AND item_id = $id");
|
||||||
|
}
|
||||||
|
|
||||||
|
// return a response
|
||||||
|
echo json_encode(['status' => 'success']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
||||||
43
quote.php
43
quote.php
|
|
@ -109,6 +109,7 @@ if (isset($_GET['quote_id'])) {
|
||||||
}
|
}
|
||||||
|
|
||||||
?>
|
?>
|
||||||
|
<link rel="stylesheet" href="/plugins/dragula/dragula.min.css">
|
||||||
|
|
||||||
<ol class="breadcrumb d-print-none">
|
<ol class="breadcrumb d-print-none">
|
||||||
<?php if (isset($_GET['client_id'])) { ?>
|
<?php if (isset($_GET['client_id'])) { ?>
|
||||||
|
|
@ -273,7 +274,7 @@ if (isset($_GET['quote_id'])) {
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<div class="card">
|
<div class="card">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table">
|
<table class="table" id="items">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th class="d-print-none"></th>
|
<th class="d-print-none"></th>
|
||||||
|
|
@ -326,7 +327,7 @@ if (isset($_GET['quote_id'])) {
|
||||||
$up_hidden = "";
|
$up_hidden = "";
|
||||||
} ?>
|
} ?>
|
||||||
|
|
||||||
<tr>
|
<tr data-item-id="<?php echo $item_id; ?>">
|
||||||
<td class="d-print-none">
|
<td class="d-print-none">
|
||||||
<?php if ($quote_status !== "Invoiced" && $quote_status !== "Accepted" && $quote_status !== "Declined" && lookupUserPermission("module_sales") >= 2) { ?>
|
<?php if ($quote_status !== "Invoiced" && $quote_status !== "Accepted" && $quote_status !== "Declined" && lookupUserPermission("module_sales") >= 2) { ?>
|
||||||
<div class="dropdown">
|
<div class="dropdown">
|
||||||
|
|
@ -356,7 +357,7 @@ if (isset($_GET['quote_id'])) {
|
||||||
</div>
|
</div>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
</td>
|
</td>
|
||||||
<td><?php echo $item_name; ?></td>
|
<td class="grab-cursor"><?php echo $item_name; ?></td>
|
||||||
<td><?php echo nl2br($item_description); ?></td>
|
<td><?php echo nl2br($item_description); ?></td>
|
||||||
<td class="text-center"><?php echo number_format($item_quantity, 2); ?></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, $quote_currency_code); ?></td>
|
<td class="text-right"><?php echo numfmt_format_currency($currency_format, $item_price, $quote_currency_code); ?></td>
|
||||||
|
|
@ -961,3 +962,39 @@ require_once "includes/footer.php";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</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_quote_items_order: true,
|
||||||
|
quote_id: <?php echo $quote_id; ?>,
|
||||||
|
positions: positions
|
||||||
|
},
|
||||||
|
success: function(data) {
|
||||||
|
// Handle success
|
||||||
|
},
|
||||||
|
error: function(error) {
|
||||||
|
console.error('Error updating order:', error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue