Skip to content

Commit

Permalink
NEW: Add sort by ref warehouse/product or ref product/warehouse on in…
Browse files Browse the repository at this point in the history
…ventory product list
  • Loading branch information
kkhelifa-opendsi committed Oct 30, 2024
1 parent 91eeb61 commit 56150a7
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions htdocs/product/inventory/inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -442,6 +452,11 @@
exit;
}

$param = '';
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.((int) $limit);
}


$res = $object->fetch_optionals();

Expand Down Expand Up @@ -577,6 +592,8 @@
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="updateinventorylines">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
if ($backtopage) {
print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
}
Expand Down Expand Up @@ -927,8 +944,8 @@ function barcodeserialforproduct(tabproduct,index,element,barcodeproductqty,sele
print '<table id="tablelines" class="noborder noshadow centpercent">';

print '<tr class="liste_titre">';
print '<td>'.$langs->trans("Warehouse").'</td>';
print '<td>'.$langs->trans("Product").'</td>';
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 '<td>';
print $langs->trans("Batch");
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 56150a7

Please sign in to comment.