This commit is contained in:
Laurent Destailleur 2017-11-17 13:56:41 +01:00
parent 97d38f32ad
commit 25a2e6f577

View File

@ -29,7 +29,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.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.'/fourn/class/fournisseur.commande.class.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
require_once './lib/replenishment.lib.php'; require_once DOL_DOCUMENT_ROOT.'/product/stock/lib/replenishment.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
$langs->load("products"); $langs->load("products");
$langs->load("stocks"); $langs->load("stocks");
@ -44,9 +45,13 @@ $sref = GETPOST('search_ref', 'alpha');
$snom = GETPOST('search_nom', 'alpha'); $snom = GETPOST('search_nom', 'alpha');
$suser = GETPOST('search_user', 'alpha'); $suser = GETPOST('search_user', 'alpha');
$sttc = GETPOST('search_ttc', 'alpha'); $sttc = GETPOST('search_ttc', 'alpha');
$sdate = GETPOST('search_date', 'alpha');
$page = GETPOST('page', 'int'); $page = GETPOST('page', 'int');
$sproduct = GETPOST('sproduct', 'int'); $sproduct = GETPOST('sproduct', 'int');
$search_dateyear = GETPOST('search_dateyear', 'int');
$search_datemonth = GETPOST('search_datemonth', 'int');
$search_dateday = GETPOST('search_dateday', 'int');
$search_date = dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear);
if (GETPOST('search_date', 'alpha')) $search_date = dol_stringtotime(GETPOST('search_date', 'alpha')); // For backward compatibility
$limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit;
$sortfield = GETPOST("sortfield"); $sortfield = GETPOST("sortfield");
@ -70,7 +75,10 @@ if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x',
$snom=""; $snom="";
$suser=""; $suser="";
$sttc=""; $sttc="";
$sdate=''; $search_date='';
$search_datemonth='';
$search_dateday='';
$search_dateyear='';
$sproduct=0; $sproduct=0;
} }
@ -125,17 +133,19 @@ if ($sref) $sql .= natural_search('cf.ref', $sref);
if ($snom) $sql .= natural_search('s.nom', $snom); if ($snom) $sql .= natural_search('s.nom', $snom);
if ($suser) $sql .= natural_search('u.login', $suser); if ($suser) $sql .= natural_search('u.login', $suser);
if ($sttc) $sql .= natural_search('cf.total_ttc', $sttc, 1); if ($sttc) $sql .= natural_search('cf.total_ttc', $sttc, 1);
if ($sdate)
if ($search_datemonth > 0)
{ {
if (GETPOST('search_datemonth', 'int') && GETPOST('search_dateday', 'int') && GETPOST('search_dateyear', 'int')) if ($search_dateyear > 0 && empty($search_dateday))
{ $sql.= " AND cf.date_creation BETWEEN '".$db->idate(dol_get_first_day($search_dateyear,$search_datemonth,false))."' AND '".$db->idate(dol_get_last_day($search_dateyear,$search_datemonth,false))."'";
$date = dol_mktime(0, 0, 0, GETPOST('search_datemonth', 'int'), GETPOST('search_dateday', 'int'), GETPOST('search_dateyear', 'int')); else if ($search_dateyear > 0 && ! empty($search_dateday))
} $sql.= " AND cf.date_creation BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_datemonth, $search_dateday, $search_dateyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_datemonth, $search_dateday, $search_dateyear))."'";
else else
{ $sql.= " AND date_format(cf.date_creation, '%m') = '".$search_datemonth."'";
$date = dol_stringtotime($sdate); }
} else if ($search_dateyear > 0)
$sql .= " AND cf.date_creation = '" . $db->idate($date) . "'"; {
$sql.= " AND cf.date_creation BETWEEN '".$db->idate(dol_get_first_day($search_dateyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_dateyear,12,false))."'";
} }
if ($sall) $sql .= natural_search(array('cf.ref','cf.note'), $sall); if ($sall) $sql .= natural_search(array('cf.ref','cf.note'), $sall);
if (!empty($socid)) $sql .= ' AND s.rowid = ' . $socid; if (!empty($socid)) $sql .= ' AND s.rowid = ' . $socid;
@ -146,7 +156,6 @@ $sql .= ' GROUP BY cf.rowid, cf.ref, cf.date_creation, cf.fk_statut';
$sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom'; $sql .= ', cf.total_ttc, cf.fk_user_author, u.login, s.rowid, s.nom';
$sql .= $db->order($sortfield, $sortorder); $sql .= $db->order($sortfield, $sortorder);
$sql .= $db->plimit($limit+1, $offset); $sql .= $db->plimit($limit+1, $offset);
//print $sql;
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
@ -158,25 +167,38 @@ if ($resql)
print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, ''); print_barre_liste('', $page, $_SERVER["PHP_SELF"], '', $sortfield, $sortorder, '', $num, 0, '');
$param='';
if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
if ($sref) $param.='&search_ref='.urlencode($sref);
if ($snom) $param.='&search_nom='.urlencode($snom);
if ($suser) $param.='&search_user='.urlencode($suser);
if ($sttc) $param.='&search_ttc='.urlencode($sttc);
if ($search_dateyear) $param.='&search_dateyear='.urlencode($search_dateyear);
if ($search_datemonth) $param.='&search_datemonth='.urlencode($search_datemonth);
if ($search_dateday) $param.='&search_dateday='.urlencode($search_dateday);
if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
print '<form action="'.$_SERVER["PHP_SELF"].'" method="GET">'; print '<form action="'.$_SERVER["PHP_SELF"].'" method="GET">';
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
print '<tr class="liste_titre_filter">'. print '<tr class="liste_titre_filter">';
'<td class="liste_titre">'. print '<td class="liste_titre">'.
'<input type="text" class="flat" name="search_ref" value="' . $sref . '">'. '<input type="text" class="flat" name="search_ref" value="' . dol_escape_htmltag($sref) . '">'.
'</td>'. '</td>'.
'<td class="liste_titre">'. '<td class="liste_titre">'.
'<input type="text" class="flat" name="search_nom" value="' . $snom . '">'. '<input type="text" class="flat" name="search_nom" value="' . dol_escape_htmltag($snom) . '">'.
'</td>'. '</td>'.
'<td class="liste_titre">'. '<td class="liste_titre">'.
'<input type="text" class="flat" name="search_user" value="' . $suser . '">'. '<input type="text" class="flat" name="search_user" value="' . dol_escape_htmltag($suser) . '">'.
'</td>'. '</td>'.
'<td class="liste_titre">'. '<td class="liste_titre">'.
'<input type="text" class="flat" name="search_ttc" value="' . $sttc . '">'. '<input type="text" class="flat" name="search_ttc" value="' . dol_escape_htmltag($sttc) . '">'.
'</td>'. '</td>'.
'<td class="liste_titre">'. '<td class="liste_titre">'.
$form->select_date('', 'search_date', 0, 0, 1, '', 1, 0, 1, 0, ''). $form->select_date($search_date, 'search_date', 0, 0, 1, '', 1, 0, 1, 0, '').
'</td>'. '</td>'.
'<td class="liste_titre" align="right">'; '<td class="liste_titre" align="right">';
$searchpicto=$form->showFilterAndCheckAddButtons(0); $searchpicto=$form->showFilterAndCheckAddButtons(0);
@ -190,7 +212,7 @@ if ($resql)
$_SERVER['PHP_SELF'], $_SERVER['PHP_SELF'],
'cf.ref', 'cf.ref',
'', '',
'', $param,
'', '',
$sortfield, $sortfield,
$sortorder $sortorder
@ -200,7 +222,7 @@ if ($resql)
$_SERVER['PHP_SELF'], $_SERVER['PHP_SELF'],
's.nom', 's.nom',
'', '',
'', $param,
'', '',
$sortfield, $sortfield,
$sortorder $sortorder
@ -220,7 +242,7 @@ if ($resql)
$_SERVER['PHP_SELF'], $_SERVER['PHP_SELF'],
'cf.total_ttc', 'cf.total_ttc',
'', '',
'', $param,
'', '',
$sortfield, $sortfield,
$sortorder $sortorder
@ -230,7 +252,7 @@ if ($resql)
$_SERVER['PHP_SELF'], $_SERVER['PHP_SELF'],
'cf.date_creation', 'cf.date_creation',
'', '',
'', $param,
'', '',
$sortfield, $sortfield,
$sortorder $sortorder
@ -240,7 +262,7 @@ if ($resql)
$_SERVER['PHP_SELF'], $_SERVER['PHP_SELF'],
'cf.fk_statut', 'cf.fk_statut',
'', '',
'', $param,
'align="right"', 'align="right"',
$sortfield, $sortfield,
$sortorder $sortorder