FIX filter into the list of product lots
This commit is contained in:
parent
bf86f0ceb4
commit
13d0701351
@ -225,12 +225,13 @@ if ($object->ismultientitymanaged == 1) {
|
|||||||
$sql .= " WHERE 1 = 1";
|
$sql .= " WHERE 1 = 1";
|
||||||
}
|
}
|
||||||
foreach ($search as $key => $val) {
|
foreach ($search as $key => $val) {
|
||||||
|
if (array_key_exists($key, $object->fields)) {
|
||||||
if ($key == 'status' && $search[$key] == -1) {
|
if ($key == 'status' && $search[$key] == -1) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
|
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
|
||||||
if (strpos($object->fields[$key]['type'], 'integer:') === 0) {
|
if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
|
||||||
if ($search[$key] == '-1') {
|
if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
|
||||||
$search[$key] = '';
|
$search[$key] = '';
|
||||||
}
|
}
|
||||||
$mode_search = 2;
|
$mode_search = 2;
|
||||||
@ -238,6 +239,19 @@ foreach ($search as $key => $val) {
|
|||||||
if ($search[$key] != '') {
|
if ($search[$key] != '') {
|
||||||
$sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
|
$sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
|
||||||
|
$columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
|
||||||
|
if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
|
||||||
|
if (preg_match('/_dtstart$/', $key)) {
|
||||||
|
$sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
|
||||||
|
}
|
||||||
|
if (preg_match('/_dtend$/', $key)) {
|
||||||
|
$sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ($search_all) {
|
if ($search_all) {
|
||||||
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
|
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
|
||||||
@ -267,35 +281,45 @@ $sql .= $hookmanager->resPrint;
|
|||||||
$sql=preg_replace('/,\s*$/','', $sql);
|
$sql=preg_replace('/,\s*$/','', $sql);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
// Count total nb of records
|
// Count total nb of records
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
|
/* This old and fast method to get and count full list returns all record so use a high amount of memory.
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
$nbtotalofrecords = $db->num_rows($resql);
|
$nbtotalofrecords = $db->num_rows($resql);
|
||||||
|
*/
|
||||||
|
/* The slow method does not consume memory on mysql (not tested on pgsql) */
|
||||||
|
/*$resql = $db->query($sql, 0, 'auto', 1);
|
||||||
|
while ($db->fetch_object($resql)) {
|
||||||
|
$nbtotalofrecords++;
|
||||||
|
}*/
|
||||||
|
/* The fast and low memory method to get and count full list converts the sql into a sql count */
|
||||||
|
$sqlforcount = preg_replace('/^SELECT[a-z0-9\._\s\(\),]+FROM/i', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
|
||||||
|
$resql = $db->query($sqlforcount);
|
||||||
|
$objforcount = $db->fetch_object($resql);
|
||||||
|
$nbtotalofrecords = $objforcount->nbtotalofrecords;
|
||||||
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
|
||||||
$page = 0;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
|
|
||||||
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
|
|
||||||
$num = $nbtotalofrecords;
|
|
||||||
} else {
|
|
||||||
if ($limit) {
|
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
|
||||||
}
|
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
// Complete request and execute it with limit
|
||||||
if (!$resql) {
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
if ($limit) {
|
||||||
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
$resql = $db->query($sql);
|
||||||
|
if (!$resql) {
|
||||||
dol_print_error($db);
|
dol_print_error($db);
|
||||||
exit;
|
exit;
|
||||||
}
|
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
|
|
||||||
// Direct jump if only one record found
|
// Direct jump if only one record found
|
||||||
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
|
||||||
$obj = $db->fetch_object($resql);
|
$obj = $db->fetch_object($resql);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user