mirror of https://github.com/itflow-org/itflow
Invoice product autocomplete - search product code as well as name
This commit is contained in:
parent
8314a115bb
commit
24d8635dac
|
|
@ -163,7 +163,9 @@ if (isset($_GET['invoice_id'])) {
|
||||||
//Product autocomplete
|
//Product autocomplete
|
||||||
$products_sql = mysqli_query($mysqli, "
|
$products_sql = mysqli_query($mysqli, "
|
||||||
SELECT
|
SELECT
|
||||||
product_name AS label,
|
CONCAT(product_code, ' - ', product_name) AS label,
|
||||||
|
product_name,
|
||||||
|
product_code,
|
||||||
product_type AS type,
|
product_type AS type,
|
||||||
product_description AS description,
|
product_description AS description,
|
||||||
product_price AS price,
|
product_price AS price,
|
||||||
|
|
@ -747,12 +749,20 @@ require_once "../includes/footer.php";
|
||||||
<script>
|
<script>
|
||||||
|
|
||||||
$(function() {
|
$(function() {
|
||||||
|
|
||||||
var availableProducts = <?php echo $json_products ?? '[]'?>;
|
var availableProducts = <?php echo $json_products ?? '[]'?>;
|
||||||
|
|
||||||
$("#name").autocomplete({
|
$("#name").autocomplete({
|
||||||
source: availableProducts,
|
|
||||||
minLength: 1,
|
minLength: 1,
|
||||||
delay: 0,
|
delay: 0,
|
||||||
|
source: function(request, response) {
|
||||||
|
var term = $.ui.autocomplete.escapeRegex(request.term.toLowerCase());
|
||||||
|
var matcher = new RegExp(term, "i");
|
||||||
|
var matches = $.grep(availableProducts, function(item) {
|
||||||
|
return matcher.test(item.label) || matcher.test(item.product_name) || matcher.test(item.product_code);
|
||||||
|
});
|
||||||
|
response(matches);
|
||||||
|
},
|
||||||
select: function (event, ui) {
|
select: function (event, ui) {
|
||||||
$("#name").val(ui.item.label);
|
$("#name").val(ui.item.label);
|
||||||
$("#desc").val(ui.item.description);
|
$("#desc").val(ui.item.description);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue