TakePOS : setting to choose product field for sort
This commit is contained in:
parent
828aa9bd93
commit
305a821b62
@ -748,10 +748,11 @@ class Categorie extends CommonObject
|
||||
*
|
||||
* @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();
|
||||
|
||||
@ -763,6 +764,12 @@ class Categorie extends CommonObject
|
||||
$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);
|
||||
|
||||
@ -77,6 +77,7 @@ if (GETPOST('action', 'alpha') == 'set')
|
||||
$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)
|
||||
@ -213,6 +214,18 @@ $array=array(0=>$langs->trans("Numberspad"), 1=>$langs->trans("BillsCoinsPad"));
|
||||
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>';
|
||||
|
||||
@ -45,11 +45,7 @@ $term = GETPOST('term', 'alpha');
|
||||
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 != '') {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user