Fix filter on dates
This commit is contained in:
parent
7ddf4ef315
commit
2c9c55bc75
@ -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.'/core/class/html.formother.class.php';
|
||||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.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/entrepot.class.php';
|
||||||
|
require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
|
||||||
|
|
||||||
// Load translation files required by the page
|
// Load translation files required by the page
|
||||||
$langs->loadLangs(array('products', 'stocks', 'productbatch'));
|
$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');
|
$sref = GETPOST("sref", 'alpha');
|
||||||
$snom = GETPOST("snom", 'alpha');
|
$snom = GETPOST("snom", 'alpha');
|
||||||
$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
|
$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');
|
$sbarcode = GETPOST("sbarcode", 'int');
|
||||||
$search_stock_physique = GETPOST('search_stock_physique', 'alpha');
|
$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');
|
$sortfield = GETPOST('sortfield', 'aZ09comma');
|
||||||
$sortorder = GETPOST('sortorder', 'aZ09comma');
|
$sortorder = GETPOST('sortorder', 'aZ09comma');
|
||||||
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
|
$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;
|
$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;
|
$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");
|
$search_sale = GETPOST("search_sale");
|
||||||
if (GETPOSTISSET('catid')) {
|
if (GETPOSTISSET('catid')) {
|
||||||
$search_categ = GETPOST('catid', 'int');
|
$search_categ = GETPOST('catid', 'int');
|
||||||
@ -78,6 +81,33 @@ if (GETPOSTISSET('catid')) {
|
|||||||
$search_categ = GETPOST('search_categ', 'int');
|
$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)
|
// Get object canvas (By default, this is not defined, so standard usage of dolibarr)
|
||||||
$canvas = GETPOST("canvas");
|
$canvas = GETPOST("canvas");
|
||||||
$objcanvas = null;
|
$objcanvas = null;
|
||||||
@ -98,7 +128,33 @@ $result = restrictedArea($user, 'produit|service', 0, 'product&product');
|
|||||||
* Actions
|
* Actions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
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
|
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 = "";
|
$sref = "";
|
||||||
$snom = "";
|
$snom = "";
|
||||||
$sall = "";
|
$sall = "";
|
||||||
@ -112,7 +168,22 @@ if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x'
|
|||||||
$fourn_id = '';
|
$fourn_id = '';
|
||||||
$sbarcode = '';
|
$sbarcode = '';
|
||||||
$search_stock_physique = '';
|
$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);
|
$form = new Form($db);
|
||||||
$htmlother = new FormOther($db);
|
$htmlother = new FormOther($db);
|
||||||
|
|
||||||
|
$now = dol_now();
|
||||||
|
|
||||||
$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
|
$helpurl = 'EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks';
|
||||||
$title = $langs->trans("ProductsAndServices");
|
$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 = '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,';
|
$sql .= ' p.fk_product_type, p.tms as datem,';
|
||||||
@ -217,22 +292,31 @@ if ($search_stock_physique != '') {
|
|||||||
if (!empty($sql_having)) {
|
if (!empty($sql_having)) {
|
||||||
$sql .= $sql_having;
|
$sql .= $sql_having;
|
||||||
}
|
}
|
||||||
$sql .= $db->order($sortfield, $sortorder);
|
|
||||||
|
|
||||||
$nbtotalofrecords = '';
|
$nbtotalofrecords = '';
|
||||||
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
|
||||||
$result = $db->query($sql);
|
$result = $db->query($sql);
|
||||||
$nbtotalofrecords = $db->num_rows($result);
|
$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;
|
$page = 0;
|
||||||
$offset = 0;
|
$offset = 0;
|
||||||
}
|
}
|
||||||
|
$db->free($resql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Complete request and execute it with limit
|
||||||
|
$sql .= $db->order($sortfield, $sortorder);
|
||||||
|
if ($limit) {
|
||||||
$sql .= $db->plimit($limit + 1, $offset);
|
$sql .= $db->plimit($limit + 1, $offset);
|
||||||
|
}
|
||||||
|
|
||||||
$resql = $db->query($sql);
|
$resql = $db->query($sql);
|
||||||
if ($resql) {
|
if (!$resql) {
|
||||||
|
dol_print_error($db);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
$num = $db->num_rows($resql);
|
$num = $db->num_rows($resql);
|
||||||
|
|
||||||
$i = 0;
|
$i = 0;
|
||||||
@ -347,6 +431,7 @@ if ($resql) {
|
|||||||
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
|
print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">';
|
||||||
|
|
||||||
// Fields title search
|
// Fields title search
|
||||||
|
// --------------------------------------------------------------------
|
||||||
print '<tr class="liste_titre_filter">';
|
print '<tr class="liste_titre_filter">';
|
||||||
print '<td class="liste_titre">';
|
print '<td class="liste_titre">';
|
||||||
print '<input class="flat" type="text" name="sref" size="6" value="'.$sref.'">';
|
print '<input class="flat" type="text" name="sref" size="6" value="'.$sref.'">';
|
||||||
@ -391,10 +476,10 @@ if ($resql) {
|
|||||||
//print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'',$sortfield,$sortorder, 'right );
|
//print_liste_field_titre("DesiredStock", $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'',$sortfield,$sortorder, 'right );
|
||||||
print_liste_field_titre("Batch", $_SERVER["PHP_SELF"], "pb.batch", '', $param, "", $sortfield, $sortorder, 'center ');
|
print_liste_field_titre("Batch", $_SERVER["PHP_SELF"], "pb.batch", '', $param, "", $sortfield, $sortorder, 'center ');
|
||||||
if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
|
if (empty($conf->global->PRODUCT_DISABLE_SELLBY)) {
|
||||||
print_liste_field_titre("SellByDate", $_SERVER["PHP_SELF"], "pb.sellby", '', $param, "", $sortfield, $sortorder, 'center ');
|
print_liste_field_titre("SellByDate", $_SERVER["PHP_SELF"], "pl.sellby", '', $param, "", $sortfield, $sortorder, 'center ');
|
||||||
}
|
}
|
||||||
if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
|
if (empty($conf->global->PRODUCT_DISABLE_EATBY)) {
|
||||||
print_liste_field_titre("EatByDate", $_SERVER["PHP_SELF"], "pb.eatby", '', $param, "", $sortfield, $sortorder, 'center ');
|
print_liste_field_titre("EatByDate", $_SERVER["PHP_SELF"], "pl.eatby", '', $param, "", $sortfield, $sortorder, 'center ');
|
||||||
}
|
}
|
||||||
print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right ');
|
print_liste_field_titre("PhysicalStock", $_SERVER["PHP_SELF"], "stock_physique", '', $param, "", $sortfield, $sortorder, 'right ');
|
||||||
// TODO Add info of running suppliers/customers orders
|
// TODO Add info of running suppliers/customers orders
|
||||||
@ -409,11 +494,18 @@ if ($resql) {
|
|||||||
$product_lot_static = new Productlot($db);
|
$product_lot_static = new Productlot($db);
|
||||||
$warehousetmp = new Entrepot($db);
|
$warehousetmp = new Entrepot($db);
|
||||||
|
|
||||||
while ($i < min($num, $limit)) {
|
// Loop on record
|
||||||
|
// --------------------------------------------------------------------
|
||||||
|
$i = 0;
|
||||||
|
$savnbfield = $totalarray['nbfield'];
|
||||||
|
$totalarray['nbfield'] = 0;
|
||||||
|
$imaxinloop = ($limit ? min($num, $limit) : $num);
|
||||||
|
while ($i < $imaxinloop) {
|
||||||
$objp = $db->fetch_object($resql);
|
$objp = $db->fetch_object($resql);
|
||||||
|
|
||||||
// Multilangs
|
// Multilangs
|
||||||
if (!empty($conf->global->MAIN_MULTILANGS)) { // si l'option est active
|
if (!empty($conf->global->MAIN_MULTILANGS)) { // si l'option est active
|
||||||
|
// TODO Use a cache
|
||||||
$sql = "SELECT label";
|
$sql = "SELECT label";
|
||||||
$sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
|
$sql .= " FROM ".MAIN_DB_PREFIX."product_lang";
|
||||||
$sql .= " WHERE fk_product = ".((int) $objp->rowid);
|
$sql .= " WHERE fk_product = ".((int) $objp->rowid);
|
||||||
@ -520,14 +612,13 @@ if ($resql) {
|
|||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
print "</table>";
|
|
||||||
print '</div>';
|
|
||||||
print '</form>';
|
|
||||||
|
|
||||||
$db->free($resql);
|
$db->free($resql);
|
||||||
} else {
|
|
||||||
dol_print_error($db);
|
print '</table>'."\n";
|
||||||
}
|
print '</div>'."\n";
|
||||||
|
|
||||||
|
print '</form>'."\n";
|
||||||
|
|
||||||
|
|
||||||
// End of page
|
// End of page
|
||||||
llxFooter();
|
llxFooter();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user