diff --git a/htdocs/compta/facture/mergepdftool.php b/htdocs/compta/facture/mergepdftool.php
index dfa1207e423..b4d310f2710 100644
--- a/htdocs/compta/facture/mergepdftool.php
+++ b/htdocs/compta/facture/mergepdftool.php
@@ -52,13 +52,16 @@ $filter = GETPOST("filtre");
if (GETPOST('button_search'))
{
$filter=GETPOST('filtre',2);
- if ($filter != 'payed:0') $option='';
+ //if ($filter != 'payed:0') $option='';
}
if ($option == 'late') $filter = 'paye:0';
if ($option == 'unpaidall') $filter = 'paye:0';
if ($mode == 'sendremind' && $filter == '') $filter = 'paye:0';
if ($filter == '') $filter = 'paye:0';
+$search_user = GETPOST('search_user','int');
+$search_sale = GETPOST('search_sale','int');
+
// Security check
if ($user->societe_id) $socid=$user->societe_id;
$result = restrictedArea($user,'facture',$id,'');
@@ -72,6 +75,8 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
{
$search_ref="";
$search_ref_supplier="";
+ $search_user = "";
+ $search_sale = "";
$search_label="";
$search_company="";
$search_amount_no_tax="";
@@ -79,6 +84,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
$year="";
$month="";
$filter="";
+ $option="";
}
@@ -445,6 +451,13 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
$sql.= ",".MAIN_DB_PREFIX."facture as f";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid=pf.fk_facture ";
+// We'll need this table joined to the select in order to filter by sale
+if ($search_sale > 0 || (! $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 f.fk_soc = s.rowid";
$sql.= " AND f.entity = ".$conf->entity;
$sql.= " AND f.type IN (0,1,3,5)";
@@ -480,6 +493,11 @@ else if ($year > 0)
{
$sql.= " AND f.datef BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
}
+if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
+if ($search_user > 0)
+{
+ $sql.= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='facture' AND tc.source='internal' AND ec.element_id = f.rowid AND ec.fk_socpeople = ".$search_user;
+}
$sql.= " GROUP BY s.nom, s.rowid, s.email, f.rowid, f.facnumber, f.ref_client, f.increment, f.total, f.tva, f.total_ttc, f.localtax1, f.localtax2, f.revenuestamp,";
$sql.= " f.datef, f.date_lim_reglement, f.paye, f.fk_statut, f.type, fk_mode_reglement";
if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user ";
@@ -520,8 +538,8 @@ if ($resql)
//else $titre.=' ('.$langs->trans("All").')';
$link='';
- if (empty($option) || $option == 'late') $link.=($link?' - ':'').''.$langs->trans("ShowUnpaidAll").'';
- if (empty($option) || $option == 'unpaidall') $link.=($link?' - ':'').''.$langs->trans("ShowUnpaidLateOnly").'';
+ //if (empty($option) || $option == 'late') $link.=($link?' - ':'').''.$langs->trans("ShowUnpaidAll").'';
+ //if (empty($option) || $option == 'unpaidall') $link.=($link?' - ':'').''.$langs->trans("ShowUnpaidLateOnly").'';
$param.=(! empty($option)?"&option=".$option:"");
@@ -595,6 +613,30 @@ if ($resql)
$i = 0;
print '
';
+
+ // If the user can view prospects other than his'
+ $moreforfilter='';
+ if ($user->rights->societe->client->voir || $socid)
+ {
+ $langs->load("commercial");
+ $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
+ $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user);
+ $moreforfilter.=' ';
+ }
+ // 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 '