new variable search_term to be more clear, term is only for terminal number

This commit is contained in:
Eric Seigne 2024-11-21 19:51:29 +01:00
parent 6e9bbe42bb
commit 101ee350d3
2 changed files with 9 additions and 8 deletions

View File

@ -54,6 +54,7 @@ require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
$category = GETPOST('category', 'alphanohtml'); // Can be id of category or 'supplements'
$action = GETPOST('action', 'aZ09');
$term = GETPOST('term', 'alpha');
$search_term = GETPOST('search_term', 'alpha');
$id = GETPOSTINT('id');
$search_start = GETPOSTINT('search_start');
$search_limit = GETPOSTINT('search_limit');
@ -130,11 +131,11 @@ if ($action == 'getProducts' && $user->hasRight('takepos', 'run')) {
} else {
echo 'Failed to load category with id='.dol_escape_htmltag($category);
}
} elseif ($action == 'search' && $term != '' && $user->hasRight('takepos', 'run')) {
} elseif ($action == 'search' && $search_term != '' && $user->hasRight('takepos', 'run')) {
top_httphead('application/json');
// Search barcode into thirdparties. If found, it means we want to change thirdparties.
$result = $thirdparty->fetch('', '', '', $term);
$result = $thirdparty->fetch('', '', '', $search_term);
if ($result && $thirdparty->id > 0) {
$rows = array();
@ -187,7 +188,7 @@ if ($action == 'getProducts' && $user->hasRight('takepos', 'run')) {
$barcode_value_list = array();
$barcode_offset = 0;
$barcode_length = dol_strlen($term);
$barcode_length = dol_strlen($search_term);
if ($barcode_length == $barcode_char_nb) {
$rows = array();
@ -195,7 +196,7 @@ if ($action == 'getProducts' && $user->hasRight('takepos', 'run')) {
foreach ($barcode_rules_list as $barcode_rule_arr) {
$code = $barcode_rule_arr['code'];
$char_nb = $barcode_rule_arr['char_nb'];
$barcode_value_list[$code] = substr($term, $barcode_offset, $char_nb);
$barcode_value_list[$code] = substr($search_term, $barcode_offset, $char_nb);
$barcode_offset += $char_nb;
}
@ -209,7 +210,7 @@ if ($action == 'getProducts' && $user->hasRight('takepos', 'run')) {
$sql .= " AND EXISTS (SELECT cp.fk_product FROM " . $db->prefix() . "categorie_product as cp WHERE cp.fk_product = p.rowid AND cp.fk_categorie IN (".$db->sanitize($filteroncategids)."))";
}
$sql .= " AND tosell = 1";
$sql .= " AND (barcode IS NULL OR barcode <> '" . $db->escape($term) . "')";
$sql .= " AND (barcode IS NULL OR barcode <> '" . $db->escape($search_term) . "')";
$resql = $db->query($sql);
if ($resql && $db->num_rows($resql) == 1) {
@ -249,7 +250,7 @@ if ($action == 'getProducts' && $user->hasRight('takepos', 'run')) {
'label' => $obj->label,
'tosell' => $obj->tosell,
'tobuy' => $obj->tobuy,
'barcode' => $term, // there is only one product matches the barcode rule and so the term is considered as the barcode of this product
'barcode' => $search_term, // there is only one product matches the barcode rule and so the term is considered as the barcode of this product
'price' => empty($objProd->multiprices[$pricelevel]) ? $obj->price : $objProd->multiprices[$pricelevel],
'price_ttc' => empty($objProd->multiprices_ttc[$pricelevel]) ? $obj->price_ttc : $objProd->multiprices_ttc[$pricelevel],
'object' => 'product',
@ -317,7 +318,7 @@ if ($action == 'getProducts' && $user->hasRight('takepos', 'run')) {
if (getDolGlobalInt('TAKEPOS_PRODUCT_IN_STOCK') == 1 && getDolGlobalInt('CASHDESK_ID_WAREHOUSE'.$_SESSION['takeposterminal'])) {
$sql .= ' AND ps.reel > 0';
}
$sql .= natural_search(array('ref', 'label', 'barcode'), $term);
$sql .= natural_search(array('ref', 'label', 'barcode'), $search_term);
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters);

View File

@ -744,7 +744,7 @@ function Search2(keyCodeForEnter, moreorless) {
pageproducts = 0;
jQuery(".wrapper2 .catwatermark").hide();
var nbsearchresults = 0;
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
$.getJSON('<?php echo DOL_URL_ROOT ?>/takepos/ajax/ajax.php?action=search&token=<?php echo newToken();?>&search_term=' + search_term + '&thirdpartyid=' + jQuery('#thirdpartyid').val() + '&search_start=' + search_start + '&search_limit=' + search_limit, function (data) {
for (i = 0; i < <?php echo $MAXPRODUCT ?>; i++) {
if (typeof (data[i]) == "undefined") {
$("#prowatermark" + i).html("");