diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index c5463e3e4e2..031ef60ff6e 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -33,11 +33,18 @@ require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php'; // Load translation files required by the page $langs->loadLangs(array('products', 'stocks', 'productbatch')); -$action = GETPOST('action', 'aZ09'); +$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ... +$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists) +$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'myobjectlist'; // To manage different context of search +$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') +$mode = GETPOST('mode', 'aZ'); + $sref = GETPOST("sref", 'alpha'); $snom = GETPOST("snom", 'alpha'); $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml')); @@ -52,25 +59,21 @@ $fourn_id = GETPOST("fourn_id", 'int'); $sbarcode = GETPOST("sbarcode", 'int'); $search_stock_physique = GETPOST('search_stock_physique', 'alpha'); +// Load variable for pagination +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; $sortfield = GETPOST('sortfield', 'aZ09comma'); $sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); -if (empty($page) || $page < 0) { +if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { + // If $page is not defined, or '' or -1 or if we click on clear filters $page = 0; } -if (!$sortfield) { - $sortfield = "p.ref"; -} -if (!$sortorder) { - $sortorder = "ASC"; -} -$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -if (empty($page) || $page == -1) { - $page = 0; -} // If $page is not defined, or '' or -1 $offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; -// Load sale and categ filters +// Initialize array of search criterias +$object = new Product($db); $search_sale = GETPOST("search_sale"); if (GETPOSTISSET('catid')) { $search_categ = GETPOST('catid', 'int'); @@ -78,6 +81,33 @@ if (GETPOSTISSET('catid')) { $search_categ = GETPOST('search_categ', 'int'); } +// Fetch optionals attributes and labels +$extrafields->fetch_name_optionals_label($object->table_element); +//$extrafields->fetch_name_optionals_label($object->table_element_line); + +$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_'); + +// Default sort order (if not yet defined by previous GETPOST) +if (!$sortfield) { + reset($object->fields); // Reset is required to avoid key() to return null. + $sortfield = "p.".key($object->fields); // Set here default search field. By default 1st field in definition. +} +if (!$sortorder) { + $sortorder = "ASC"; +} + +// Initialize array of search criterias +$search = array(); +foreach ($object->fields as $key => $val) { + if (GETPOST('search_'.$key, 'alpha') !== '') { + $search[$key] = GETPOST('search_'.$key, 'alpha'); + } + if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { + $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int')); + $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int')); + } +} + // Get object canvas (By default, this is not defined, so standard usage of dolibarr) $canvas = GETPOST("canvas"); $objcanvas = null; @@ -98,21 +128,62 @@ $result = restrictedArea($user, 'produit|service', 0, 'product&product'); * Actions */ -if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers - $sref = ""; - $snom = ""; - $sall = ""; - $tosell = ""; - $tobuy = ""; - $search_sale = ""; - $search_categ = ""; - $toolowstock = ''; - $search_batch = ''; - $search_warehouse = ''; - $fourn_id = ''; - $sbarcode = ''; - $search_stock_physique = ''; +if (GETPOST('cancel', 'alpha')) { + $action = 'list'; + $massaction = ''; } +if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { + $massaction = ''; +} + +$parameters = array(); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); +} + +if (empty($reshook)) { + // Selection of new fields + include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + + // Purge search criteria + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers + foreach ($object->fields as $key => $val) { + $search[$key] = ''; + if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) { + $search[$key.'_dtstart'] = ''; + $search[$key.'_dtend'] = ''; + } + } + $sref = ""; + $snom = ""; + $sall = ""; + $tosell = ""; + $tobuy = ""; + $search_sale = ""; + $search_categ = ""; + $toolowstock = ''; + $search_batch = ''; + $search_warehouse = ''; + $fourn_id = ''; + $sbarcode = ''; + $search_stock_physique = ''; + $toselect = array(); + $search_array_options = array(); + } + if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha') + || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) { + $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation + } + + // Mass actions + /*$objectclass = 'MyObject'; + $objectlabel = 'MyObject'; + $uploaddir = $conf->mymodule->dir_output; + include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; + */ +} + /* @@ -122,8 +193,12 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x' $form = new Form($db); $htmlother = new FormOther($db); +$now = dol_now(); + $helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; $title = $langs->trans("ProductsAndServices"); +$morejs = array(); +$morecss = array(); $sql = 'SELECT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type, p.entity,'; $sql .= ' p.fk_product_type, p.tms as datem,'; @@ -217,318 +292,334 @@ if ($search_stock_physique != '') { if (!empty($sql_having)) { $sql .= $sql_having; } -$sql .= $db->order($sortfield, $sortorder); $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); - if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0 + + if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0 $page = 0; $offset = 0; } + $db->free($resql); } -$sql .= $db->plimit($limit + 1, $offset); +// Complete request and execute it with limit +$sql .= $db->order($sortfield, $sortorder); +if ($limit) { + $sql .= $db->plimit($limit + 1, $offset); +} $resql = $db->query($sql); -if ($resql) { - $num = $db->num_rows($resql); - - $i = 0; - - if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall or $snom or $sref)) { - $objp = $db->fetch_object($resql); - header("Location: card.php?id=$objp->rowid"); - exit; - } - - if (isset($type)) { - if ($type == 1) { - $texte = $langs->trans("Services"); - } else { - $texte = $langs->trans("Products"); - } - } else { - $texte = $langs->trans("ProductsAndServices"); - } - $texte .= ' ('.$langs->trans("StocksByLotSerial").')'; - - $param = ''; - if ($limit > 0 && $limit != $conf->liste_limit) { - $param .= '&limit='.urlencode($limit); - } - if ($sall) { - $param .= "&sall=".urlencode($sall); - } - if ($tosell) { - $param .= "&tosell=".urlencode($tosell); - } - if ($tobuy) { - $param .= "&tobuy=".urlencode($tobuy); - } - if ($type != '') { - $param .= "&type=".urlencode($type); - } - if ($fourn_id) { - $param .= "&fourn_id=".urlencode($fourn_id); - } - if ($snom) { - $param .= "&snom=".urlencode($snom); - } - if ($sref) { - $param .= "&sref=".urlencode($sref); - } - if ($search_batch) { - $param .= "&search_batch=".urlencode($search_batch); - } - if ($sbarcode) { - $param .= "&sbarcode=".urlencode($sbarcode); - } - if ($search_warehouse) { - $param .= "&search_warehouse=".urlencode($search_warehouse); - } - if ($toolowstock) { - $param .= "&toolowstock=".urlencode($toolowstock); - } - if ($search_sale) { - $param .= "&search_sale=".urlencode($search_sale); - } - if (!empty($search_categ) && $search_categ != '-1') { - $param .= "&search_categ=".urlencode($search_categ); - } - if ($search_stock_physique) { - $param .= '&search_stock_physique=' . urlencode($search_stock_physique); - } - /*if ($eatby) $param.="&eatby=".$eatby; - if ($sellby) $param.="&sellby=".$sellby;*/ - - llxHeader("", $title, $helpurl, $texte); - - print '
'; - - $db->free($resql); -} else { +if (!$resql) { dol_print_error($db); + exit; } +$num = $db->num_rows($resql); + +$i = 0; + +if ($num == 1 && GETPOST('autojumpifoneonly') && ($sall or $snom or $sref)) { + $objp = $db->fetch_object($resql); + header("Location: card.php?id=$objp->rowid"); + exit; +} + +if (isset($type)) { + if ($type == 1) { + $texte = $langs->trans("Services"); + } else { + $texte = $langs->trans("Products"); + } +} else { + $texte = $langs->trans("ProductsAndServices"); +} +$texte .= ' ('.$langs->trans("StocksByLotSerial").')'; + +$param = ''; +if ($limit > 0 && $limit != $conf->liste_limit) { + $param .= '&limit='.urlencode($limit); +} +if ($sall) { + $param .= "&sall=".urlencode($sall); +} +if ($tosell) { + $param .= "&tosell=".urlencode($tosell); +} +if ($tobuy) { + $param .= "&tobuy=".urlencode($tobuy); +} +if ($type != '') { + $param .= "&type=".urlencode($type); +} +if ($fourn_id) { + $param .= "&fourn_id=".urlencode($fourn_id); +} +if ($snom) { + $param .= "&snom=".urlencode($snom); +} +if ($sref) { + $param .= "&sref=".urlencode($sref); +} +if ($search_batch) { + $param .= "&search_batch=".urlencode($search_batch); +} +if ($sbarcode) { + $param .= "&sbarcode=".urlencode($sbarcode); +} +if ($search_warehouse) { + $param .= "&search_warehouse=".urlencode($search_warehouse); +} +if ($toolowstock) { + $param .= "&toolowstock=".urlencode($toolowstock); +} +if ($search_sale) { + $param .= "&search_sale=".urlencode($search_sale); +} +if (!empty($search_categ) && $search_categ != '-1') { + $param .= "&search_categ=".urlencode($search_categ); +} +if ($search_stock_physique) { + $param .= '&search_stock_physique=' . urlencode($search_stock_physique); +} +/*if ($eatby) $param.="&eatby=".$eatby; +if ($sellby) $param.="&sellby=".$sellby;*/ + +llxHeader("", $title, $helpurl, $texte); + +print ''."\n"; + + // End of page llxFooter(); $db->close();