Skip to content

Commit

Permalink
TakePOS : setting to choose product field for sort
Browse files Browse the repository at this point in the history
  • Loading branch information
dbeniamine committed Dec 16, 2019
1 parent 828aa9b commit 305a821
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
9 changes: 8 additions & 1 deletion htdocs/categories/class/categorie.class.php
Expand Up @@ -748,10 +748,11 @@ public function del_type($obj, $type)
*
* @param string $type Type of category ('customer', 'supplier', 'contact', 'product', 'member')
* @param int $onlyids Return only ids of objects (consume less memory)
* @param string $orderby field for order
* @return array|int -1 if KO, array of instance of object if OK
* @see containsObject()
*/
public function getObjectsInCateg($type, $onlyids = 0)
public function getObjectsInCateg($type, $onlyids = 0, $orderby='')
{
$objs = array();

Expand All @@ -763,6 +764,12 @@ public function getObjectsInCateg($type, $onlyids = 0)
$sql .= " WHERE o.entity IN (" . getEntity($obj->element).")";
$sql.= " AND c.fk_categorie = ".$this->id;
$sql .= " AND c.fk_" . $this->MAP_CAT_FK[$type] . " = o.rowid";
if ($orderby) {
$prod = new Product($db);
if(array_key_exists($orderby, $prod->fields)){
$sql .= " ORDER BY $orderby";
}
}

dol_syslog(get_class($this)."::getObjectsInCateg", LOG_DEBUG);
$resql = $this->db->query($sql);
Expand Down
13 changes: 13 additions & 0 deletions htdocs/takepos/admin/setup.php
Expand Up @@ -77,6 +77,7 @@
$res = dolibarr_set_const($db, "TAKEPOS_HEADER", GETPOST('TAKEPOS_HEADER', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_FOOTER", GETPOST('TAKEPOS_FOOTER', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_NUMPAD", GETPOST('TAKEPOS_NUMPAD', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_SORTPRODUCTFIELD", GETPOST('TAKEPOS_SORTPRODUCTFIELD', 'alpha'), 'chaine', 0, '', $conf->entity);
$res = dolibarr_set_const($db, "TAKEPOS_NUM_TERMINALS", GETPOST('TAKEPOS_NUM_TERMINALS', 'alpha'), 'chaine', 0, '', $conf->entity);

if ($conf->global->TAKEPOS_ORDER_NOTES==1)
Expand Down Expand Up @@ -213,6 +214,18 @@
print $form->selectarray('TAKEPOS_NUMPAD', $array, (empty($conf->global->TAKEPOS_NUMPAD)?'0':$conf->global->TAKEPOS_NUMPAD), 0);
print "</td></tr>\n";

// Sort product
print '<tr class="oddeven"><td>';
print $langs->trans("SortProductField");
print '<td colspan="2">';
$prod = new Product($db);
$array = [];
foreach($prod->fields as $k => $v) {
$array[$k]=$k;
}
print $form->selectarray('TAKEPOS_SORTPRODUCTFIELD', $array, (empty($conf->global->TAKEPOS_SORTPRODUCTFIELD)?'rowid':$conf->global->TAKEPOS_SORTPRODUCTFIELD), 0);
print "</td></tr>\n";

$substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2);
$substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
Expand Down
6 changes: 1 addition & 5 deletions htdocs/takepos/ajax.php
Expand Up @@ -45,11 +45,7 @@
if ($action=="getProducts") {
$object = new Categorie($db);
$result=$object->fetch($category);
$prods = $object->getObjectsInCateg("product");
function sort_by_ref($a, $b) {
return strcmp($a->ref, $b->ref);
}
usort($prods, "sort_by_ref");
$prods = $object->getObjectsInCateg("product", 0, $conf->global->TAKEPOS_SORTPRODUCTFIELD);
echo json_encode($prods);
}
elseif ($action=="search" && $term != '') {
Expand Down

0 comments on commit 305a821

Please sign in to comment.