diff --git a/htdocs/product/inventory/inventory.php b/htdocs/product/inventory/inventory.php index f90832b61b46c..c8635a95e6a1f 100644 --- a/htdocs/product/inventory/inventory.php +++ b/htdocs/product/inventory/inventory.php @@ -44,6 +44,8 @@ $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'inventorycard'; // To manage different context of search $backtopage = GETPOST('backtopage', 'alpha'); $listoffset = GETPOST('listoffset', 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $limit = GETPOSTINT('limit') > 0 ? GETPOSTINT('limit') : $conf->liste_limit; $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page"); if (empty($page) || $page == -1) { @@ -71,6 +73,13 @@ $extrafields = new ExtraFields($db); $diroutputmassaction = $conf->stock->dir_output.'/temp/massgeneration/'.$user->id; +// Default sort order (if not yet defined by previous GETPOST) +if (!$sortfield) { + $sortfield = "e.ref"; +} +if (!$sortorder) { + $sortorder = "ASC"; +} // Fetch optionals attributes and labels $extrafields->fetch_name_optionals_label($object->table_element); @@ -99,7 +108,8 @@ //$result = restrictedArea($user, 'mymodule', $id); //Parameters Page -$paramwithsearch = ''; +$paramwithsearch = '&sortfield=' . urlencode($sortfield); +$paramwithsearch .= '&sortorder=' . urlencode($sortorder); if ($limit > 0 && $limit != $conf->liste_limit) { $paramwithsearch .= '&limit='.((int) $limit); } @@ -442,6 +452,11 @@ exit; } +$param = ''; +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.((int) $limit); +} + $res = $object->fetch_optionals(); @@ -577,6 +592,8 @@ print ''; print ''; print ''; +print ''; +print ''; if ($backtopage) { print ''; } @@ -927,8 +944,8 @@ function barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,sele print ''; print ''; -print ''; -print ''; +print getTitleFieldOfList($langs->trans("Warehouse"), 0, $_SERVER['PHP_SELF'], 'e.ref', '', 'id=' . $object->id . '&page=' . $page . $param, '', $sortfield, $sortorder, '', 0, '') . "\n"; +print getTitleFieldOfList($langs->trans("Product"), 0, $_SERVER['PHP_SELF'], 'p.ref', '', 'id=' . $object->id . '&page=' . $page . $param, '', $sortfield, $sortorder, '', 0, '') . "\n"; if (isModEnabled('productbatch')) { print '
'.$langs->trans("Warehouse").''.$langs->trans("Product").''; print $langs->trans("Batch"); @@ -1015,9 +1032,11 @@ function barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,sele // Request to show lines of inventory (prefilled after start/validate step) $sql = 'SELECT id.rowid, id.datec as date_creation, id.tms as date_modification, id.fk_inventory, id.fk_warehouse,'; $sql .= ' id.fk_product, id.batch, id.qty_stock, id.qty_view, id.qty_regulated, id.fk_movement, id.pmp_real, id.pmp_expected'; -$sql .= ' FROM '.MAIN_DB_PREFIX.'inventorydet as id'; -$sql .= ' WHERE id.fk_inventory = '.((int) $object->id); -$sql .= $db->order('id.rowid', 'ASC'); +$sql .= ' FROM ' . $db->prefix() . 'inventorydet as id'; +$sql .= ' LEFT JOIN ' . $db->prefix() . 'product as p ON id.fk_product = p.rowid'; +$sql .= ' LEFT JOIN ' . $db->prefix() . 'entrepot as e ON id.fk_warehouse = e.rowid'; +$sql .= ' WHERE id.fk_inventory = ' . ((int) $object->id); +$sql .= $db->order($sortfield . ',' . ($sortfield == 'e.ref' ? 'p.ref' : 'e.ref'), $sortorder . ',' . $sortorder); $sql .= $db->plimit($limit, $offset); $cacheOfProducts = array();