New: Can filter on user contact
This commit is contained in:
parent
143e524db6
commit
29c7c109fa
@ -42,6 +42,7 @@ $sref_client=GETPOST('sref_client','alpha');
|
||||
$snom=GETPOST('snom','alpha');
|
||||
$sall=GETPOST('sall');
|
||||
$socid=GETPOST('socid','int');
|
||||
$search_user=GETPOST('search_user','int');
|
||||
|
||||
// Security check
|
||||
$id = (GETPOST('orderid')?GETPOST('orderid'):GETPOST('id','int'));
|
||||
@ -80,6 +81,11 @@ $sql.= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture
|
||||
$sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s';
|
||||
$sql.= ', '.MAIN_DB_PREFIX.'commande as c';
|
||||
if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
|
||||
if ($search_user > 0)
|
||||
{
|
||||
$sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
|
||||
$sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
}
|
||||
$sql.= ' WHERE c.fk_soc = s.rowid';
|
||||
$sql.= ' AND c.entity = '.$conf->entity;
|
||||
if ($socid) $sql.= ' AND s.rowid = '.$socid;
|
||||
@ -114,19 +120,29 @@ if ($viewstatut <> '')
|
||||
}
|
||||
if ($ordermonth > 0)
|
||||
{
|
||||
$sql.= " AND date_format(c.date_valid, '%Y-%m') = '".$orderyear."-".$ordermonth."'"; // TODO do not use date_format but a between
|
||||
if ($orderyear > 0 && empty($day))
|
||||
$sql.= " AND c.date_valid BETWEEN '".$db->idate(dol_get_first_day($orderyear,$ordermonth,false))."' AND '".$db->idate(dol_get_last_day($orderyear,$ordermonth,false))."'";
|
||||
else if ($orderyear > 0 && ! empty($day))
|
||||
$sql.= " AND c.date_valid BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $ordermonth, $day, $orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $ordermonth, $day, $orderyear))."'";
|
||||
else
|
||||
$sql.= " AND date_format(c.date_valid, '%m') = '".$ordermonth."'";
|
||||
}
|
||||
if ($orderyear > 0)
|
||||
else if ($orderyear > 0)
|
||||
{
|
||||
$sql.= " AND date_format(c.date_valid, '%Y') = '".$orderyear."'";
|
||||
$sql.= " AND c.date_valid BETWEEN '".$db->idate(dol_get_first_day($orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($orderyear,12,false))."'";
|
||||
}
|
||||
if ($deliverymonth > 0)
|
||||
{
|
||||
$sql.= " AND date_format(c.date_livraison, '%Y-%m') = '".$deliveryyear."-".$deliverymonth."'";
|
||||
if ($deliveryyear > 0 && empty($day))
|
||||
$sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,$deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,$deliverymonth,false))."'";
|
||||
else if ($deliveryyear > 0 && ! empty($day))
|
||||
$sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $deliverymonth, $day, $deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $deliverymonth, $day, $deliveryyear))."'";
|
||||
else
|
||||
$sql.= " AND date_format(c.date_livraison, '%m') = '".$deliverymonth."'";
|
||||
}
|
||||
if ($deliveryyear > 0)
|
||||
else if ($deliveryyear > 0)
|
||||
{
|
||||
$sql.= " AND date_format(c.date_livraison, '%Y') = '".$deliveryyear."'";
|
||||
$sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,12,false))."'";
|
||||
}
|
||||
if (!empty($snom))
|
||||
{
|
||||
@ -136,12 +152,16 @@ if (!empty($sref_client))
|
||||
{
|
||||
$sql.= ' AND c.ref_client LIKE \'%'.$db->escape($sref_client).'%\'';
|
||||
}
|
||||
if ($search_user > 0)
|
||||
{
|
||||
$sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='commande' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".$search_user;
|
||||
}
|
||||
|
||||
$sql.= ' ORDER BY '.$sortfield.' '.$sortorder;
|
||||
$sql.= $db->plimit($limit + 1,$offset);
|
||||
|
||||
//print $sql;
|
||||
$resql = $db->query($sql);
|
||||
|
||||
if ($resql)
|
||||
{
|
||||
if ($socid)
|
||||
@ -172,7 +192,26 @@ if ($resql)
|
||||
$num = $db->num_rows($resql);
|
||||
print_barre_liste($title, $page, 'liste.php','&socid='.$socid.'&viewstatut='.$viewstatut,$sortfield,$sortorder,'',$num);
|
||||
$i = 0;
|
||||
|
||||
// Lignes des champs de filtre
|
||||
print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
|
||||
|
||||
print '<table class="noborder" width="100%">';
|
||||
|
||||
// If the user can view prospects other than his'
|
||||
if ($user->rights->societe->client->voir || $socid)
|
||||
{
|
||||
$moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
|
||||
$moreforfilter.=$form->select_dolusers($search_user,'search_user',1);
|
||||
}
|
||||
if ($moreforfilter)
|
||||
{
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td class="liste_titre" colspan="9">';
|
||||
print $moreforfilter;
|
||||
print '</td></tr>';
|
||||
}
|
||||
|
||||
print '<tr class="liste_titre">';
|
||||
print_liste_field_titre($langs->trans('Ref'),'liste.php','c.ref','','&socid='.$socid.'&viewstatut='.$viewstatut,'width="25%"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Company'),'liste.php','s.nom','','&socid='.$socid.'&viewstatut='.$viewstatut,'',$sortfield,$sortorder);
|
||||
@ -181,8 +220,6 @@ if ($resql)
|
||||
print_liste_field_titre($langs->trans('DeliveryDate'),'liste.php','c.date_livraison','','&socid='.$socid.'&viewstatut='.$viewstatut, 'align="right"',$sortfield,$sortorder);
|
||||
print_liste_field_titre($langs->trans('Status'),'liste.php','c.fk_statut','','&socid='.$socid.'&viewstatut='.$viewstatut,'align="right"',$sortfield,$sortorder);
|
||||
print '</tr>';
|
||||
// Lignes des champs de filtre
|
||||
print '<form method="get" action="liste.php">';
|
||||
print '<tr class="liste_titre">';
|
||||
print '<td class="liste_titre">';
|
||||
print '<input class="flat" size="10" type="text" name="sref" value="'.$sref.'">';
|
||||
@ -195,7 +232,7 @@ if ($resql)
|
||||
print '</td><td align="right" class="liste_titre">';
|
||||
print '<input type="image" class="liste_titre" name="button_search" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
|
||||
print '</td></tr>';
|
||||
print '</form>';
|
||||
|
||||
$var=True;
|
||||
$generic_commande = new Commande($db);
|
||||
while ($i < min($num,$limit))
|
||||
@ -268,6 +305,9 @@ if ($resql)
|
||||
$i++;
|
||||
}
|
||||
print '</table>';
|
||||
|
||||
print '</form>';
|
||||
|
||||
$db->free($resql);
|
||||
}
|
||||
else
|
||||
@ -275,7 +315,7 @@ else
|
||||
print dol_print_error($db);
|
||||
}
|
||||
|
||||
$db->close();
|
||||
|
||||
llxFooter();
|
||||
|
||||
$db->close();
|
||||
?>
|
||||
|
||||
@ -3252,7 +3252,7 @@ else
|
||||
else $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet as fd ON fd.fk_facture = f.rowid';
|
||||
if ($search_user > 0)
|
||||
{
|
||||
$sql.=", ".MAIN_DB_PREFIX."element_contact as c";
|
||||
$sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
|
||||
$sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
|
||||
}
|
||||
$sql.= ' WHERE f.fk_soc = s.rowid';
|
||||
@ -3304,7 +3304,7 @@ else
|
||||
}
|
||||
if ($search_user > 0)
|
||||
{
|
||||
$sql.= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = f.rowid AND c.fk_socpeople = ".$search_user;
|
||||
$sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
|
||||
}
|
||||
if (! $sall)
|
||||
{
|
||||
|
||||
Loading…
Reference in New Issue
Block a user