From d523f91a29a6e5620ac018c80a409e00ddeaa71c Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Mon, 20 Mar 2023 12:28:18 +0100 Subject: [PATCH 1/2] NEW limit load products in takepos --- htdocs/categories/class/categorie.class.php | 18 +++++++++- htdocs/takepos/ajax/ajax.php | 10 +++++- htdocs/takepos/index.php | 40 ++++++++++++--------- 3 files changed, 49 insertions(+), 19 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 5f1b081c46d..875100b465c 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -845,6 +845,8 @@ class Categorie extends CommonObject * @param int $offset Offset * @param string $sortfield Sort fields * @param string $sortorder Sort order ('ASC' or 'DESC'); + * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customsql'=>...) + * @param string $filtermode Filter mode (AND or OR) * @return array|int -1 if KO, array of instance of object if OK * @see containsObject() */ @@ -867,10 +869,24 @@ class Categorie extends CommonObject if (($type == 'customer' || $type == 'supplier') && $user->socid > 0) { $sql .= " AND o.rowid = ".((int) $user->socid); } + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + if ($key == 'o.rowid') { + $sqlwhere[] = $key." = ".((int) $value); + } elseif ($key == 'customsql') { + $sqlwhere[] = $value; + } + } + } + if (count($sqlwhere) > 0) { + $sql .= " AND (".implode(" ".$filtermode." ", $sqlwhere).")"; + } + $sql .= $this->db->order($sortfield, $sortorder); if ($limit > 0 || $offset > 0) { $sql .= $this->db->plimit($limit + 1, $offset); } - $sql .= $this->db->order($sortfield, $sortorder); dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG); $resql = $this->db->query($sql); diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 87357d10091..1fae90b8a42 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -62,6 +62,10 @@ $hookmanager->initHooks(array('takeposproductsearch')); // new context for produ */ if ($action == 'getProducts') { + $tosell = GETPOSTISSET('tosell') ? GETPOST('tosell', 'int') : ''; + $limit = GETPOSTISSET('limit') ? GETPOST('limit', 'int') : 0; + $offset = GETPOSTISSET('offset') ? GETPOST('offset', 'int') : 0; + top_httphead('application/json'); $object = new Categorie($db); @@ -70,7 +74,11 @@ if ($action == 'getProducts') { } $result = $object->fetch($category); if ($result > 0) { - $prods = $object->getObjectsInCateg("product", 0, 0, 0, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD'), 'ASC'); + $filter = array(); + if ($tosell != '') { + $filter = array('customsql' => 'o.tosell = '.((int) $tosell)); + } + $prods = $object->getObjectsInCateg("product", 0, $limit, $offset, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD'), 'ASC'); // Removed properties we don't need $res = array(); if (is_array($prods) && count($prods) > 0) { diff --git a/htdocs/takepos/index.php b/htdocs/takepos/index.php index bbbf9e0cd33..84ec7439ca3 100644 --- a/htdocs/takepos/index.php +++ b/htdocs/takepos/index.php @@ -322,7 +322,12 @@ function LoadProducts(position, issubcat) { }); idata=0; //product data counter - $.getJSON('/takepos/ajax/ajax.php?action=getProducts&token=&category='+currentcat, function(data) { + var limit = 0; + if (maxproduct >= 1) { + limit = maxproduct-1; + } + // Only show products for sale (tosell=1) + $.getJSON('/takepos/ajax/ajax.php?action=getProducts&token=&category='+currentcat+'&tosell=1&limit='+limit+'&offset=0', function(data) { console.log("Call ajax.php (in LoadProducts) to get Products of category "+currentcat+" then loop on result to fill image thumbs"); console.log(data); while (ishow < maxproduct) { @@ -342,10 +347,7 @@ function LoadProducts(position, issubcat) { $("#proprice"+ishow).html(""); $("#prodiv"+ishow).data("rowid",""); $("#prodiv"+ishow).attr("class","wrapper2 divempty"); - $("#prowatermark"+ishow).hide(); - ishow++; //Next product to show after print data product - } - else if ((data[idata]['status']) == "1") { // Only show products with status=1 (for sell) + } else { transnoentities('Ref').': ')."' + data[idata]['ref']"; $titlestring .= " + ' - ".dol_escape_js($langs->trans("Barcode").': ')."' + data[idata]['barcode']"; @@ -376,8 +378,7 @@ function LoadProducts(position, issubcat) { console.log($('#prodiv4').data('rowid')); $("#prodiv"+ishow).data("iscat", 0); $("#prodiv"+ishow).attr("class","wrapper2"); - $("#prowatermark"+ishow).hide(); - ishow++; //Next product to show after print data product + resPrint; ?> } - //console.log("Hide the prowatermark for ishow="+ishow); + $("#prowatermark"+ishow).hide(); + ishow++; //Next product to show after print data product idata++; //Next data everytime } }); @@ -414,15 +416,22 @@ function MoreProducts(moreorless) { if (pageproducts==0) return; //Return if no less pages pageproducts=pageproducts-1; } - $.getJSON('/takepos/ajax/ajax.php?action=getProducts&token=&category='+currentcat, function(data) { + + ishow=0; //product to show counter + idata=0; //product data counter + var limit = 0; + if (maxproduct >= 1) { + limit = maxproduct-1; + } + var offset = * pageproducts; + // Only show products for sale (tosell=1) + $.getJSON('/takepos/ajax/ajax.php?action=getProducts&token=&category='+currentcat+'&tosell=1&limit='+limit+'&offset='+offset, function(data) { console.log("Call ajax.php (in MoreProducts) to get Products of category "+currentcat); - if (typeof (data[(maxproduct * pageproducts)]) == "undefined" && moreorless=="more"){ // Return if no more pages + if (typeof (data[0]) == "undefined" && moreorless=="more"){ // Return if no more pages pageproducts=pageproducts-1; return; } - idata= * pageproducts; //product data counter - ishow=0; //product to show counter while (ishow < maxproduct) { if (typeof (data[idata]) == "undefined") { @@ -434,10 +443,7 @@ function MoreProducts(moreorless) { $("#proprice"+ishow).html(""); $("#proimg"+ishow).attr("src","genimg/empty.png"); $("#prodiv"+ishow).data("rowid",""); - ishow++; //Next product to show after print data product - } - else if ((data[idata]['status']) == "1") { - //Only show products with status=1 (for sell) + } else { $("#prodivdesc"+ishow).show(); @@ -454,9 +460,9 @@ function MoreProducts(moreorless) { $("#proimg"+ishow).attr("src","genimg/index.php?query=pro&id="+data[idata]['id']); $("#prodiv"+ishow).data("rowid",data[idata]['id']); $("#prodiv"+ishow).data("iscat",0); - ishow++; //Next product to show after print data product } $("#prowatermark"+ishow).hide(); + ishow++; //Next product to show after print data product idata++; //Next data everytime } }); From daa34b85fe54fbe6ccd63aede549f7b2327302af Mon Sep 17 00:00:00 2001 From: VESSILLER Date: Mon, 20 Mar 2023 13:27:48 +0100 Subject: [PATCH 2/2] New filter products for sale --- htdocs/categories/class/categorie.class.php | 2 +- htdocs/takepos/ajax/ajax.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 875100b465c..6762770d564 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -850,7 +850,7 @@ class Categorie extends CommonObject * @return array|int -1 if KO, array of instance of object if OK * @see containsObject() */ - public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC') + public function getObjectsInCateg($type, $onlyids = 0, $limit = 0, $offset = 0, $sortfield = '', $sortorder = 'ASC', $filter = array(), $filtermode = 'AND') { global $user; diff --git a/htdocs/takepos/ajax/ajax.php b/htdocs/takepos/ajax/ajax.php index 1fae90b8a42..5b75ef04275 100644 --- a/htdocs/takepos/ajax/ajax.php +++ b/htdocs/takepos/ajax/ajax.php @@ -78,7 +78,7 @@ if ($action == 'getProducts') { if ($tosell != '') { $filter = array('customsql' => 'o.tosell = '.((int) $tosell)); } - $prods = $object->getObjectsInCateg("product", 0, $limit, $offset, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD'), 'ASC'); + $prods = $object->getObjectsInCateg("product", 0, $limit, $offset, getDolGlobalString('TAKEPOS_SORTPRODUCTFIELD'), 'ASC', $filter); // Removed properties we don't need $res = array(); if (is_array($prods) && count($prods) > 0) {