PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/list.php

https://github.com/asterix14/dolibarr
PHP | 252 lines | 173 code | 38 blank | 41 comment | 34 complexity | 7834f10c9c17f027e61d1c862f7ebcd4 MD5 | raw file
Possible License(s): LGPL-2.0
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/list.php
  21. * \ingroup commercial societe
  22. * \brief List of customers
  23. */
  24. require("../main.inc.php");
  25. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php");
  26. $langs->load("companies");
  27. $langs->load("customers");
  28. $langs->load("suppliers");
  29. $langs->load("commercial");
  30. // Security check
  31. $socid = GETPOST("socid");
  32. if ($user->societe_id) $socid=$user->societe_id;
  33. $result = restrictedArea($user,'societe',$socid,'');
  34. $sortfield = isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
  35. $sortorder = isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
  36. $page=isset($_GET["page"])?$_GET["page"]:$_POST["page"];
  37. if ($page == -1) { $page = 0 ; }
  38. $offset = $conf->liste_limit * $page;
  39. $pageprev = $page - 1;
  40. $pagenext = $page + 1;
  41. if (! $sortorder) $sortorder="ASC";
  42. if (! $sortfield) $sortfield="s.nom";
  43. $search_nom=GETPOST("search_nom");
  44. $search_ville=GETPOST("search_ville");
  45. $search_code=GETPOST("search_code");
  46. $search_compta=GETPOST("search_compta");
  47. // Load sale and categ filters
  48. $search_sale = GETPOST("search_sale");
  49. $search_categ = GETPOST("search_categ");
  50. /*
  51. * Actions
  52. */
  53. // Do we click on purge search criteria ?
  54. if (GETPOST("button_removefilter_x"))
  55. {
  56. $search_categ='';
  57. $search_sale='';
  58. $socname="";
  59. $search_nom="";
  60. $search_ville="";
  61. $search_idprof1='';
  62. $search_idprof2='';
  63. $search_idprof3='';
  64. $search_idprof4='';
  65. }
  66. /*
  67. * view
  68. */
  69. $htmlother=new FormOther($db);
  70. $thirdpartystatic=new Societe($db);
  71. $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
  72. llxHeader('',$langs->trans("ThirdParty"),$help_url);
  73. $sql = "SELECT s.rowid, s.nom as name, s.client, s.ville, st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta, s.status as status,";
  74. $sql.= " s.datec, s.datea, s.canvas";
  75. // We'll need these fields in order to filter by sale (including the case where the user can only see his prospects)
  76. if ($search_sale) $sql .= ", sc.fk_soc, sc.fk_user";
  77. // We'll need these fields in order to filter by categ
  78. if ($search_categ) $sql .= ", cs.fk_categorie, cs.fk_societe";
  79. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,";
  80. $sql.= " ".MAIN_DB_PREFIX."c_stcomm as st";
  81. // We'll need this table joined to the select in order to filter by sale
  82. if ($search_sale || !$user->rights->societe->client->voir) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  83. // We'll need this table joined to the select in order to filter by categ
  84. if ($search_categ) $sql.= ", ".MAIN_DB_PREFIX."categorie_societe as cs";
  85. $sql.= " WHERE s.fk_stcomm = st.id";
  86. $sql.= " AND s.client IN (1, 3)";
  87. $sql.= " AND s.entity = ".$conf->entity;
  88. if (!$user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  89. if ($socid) $sql.= " AND s.rowid = ".$socid;
  90. if ($search_sale) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale
  91. if ($search_categ) $sql.= " AND s.rowid = cs.fk_societe"; // Join for the needed table to filter by categ
  92. if ($search_nom) $sql.= " AND s.nom like '%".$db->escape(strtolower($search_nom))."%'";
  93. if ($search_ville) $sql.= " AND s.ville like '%".$db->escape(strtolower($search_ville))."%'";
  94. if ($search_code) $sql.= " AND s.code_client like '%".$db->escape(strtolower($search_code))."%'";
  95. if ($search_compta) $sql .= " AND s.code_compta LIKE '%".$db->escape($search_compta)."%'";
  96. // Insert sale filter
  97. if ($search_sale)
  98. {
  99. $sql .= " AND sc.fk_user = ".$search_sale;
  100. }
  101. // Insert categ filter
  102. if ($search_categ)
  103. {
  104. $sql .= " AND cs.fk_categorie = ".$search_categ;
  105. }
  106. if ($socname)
  107. {
  108. $sql.= " AND s.nom like '%".$db->escape(strtolower($socname))."%'";
  109. $sortfield = "s.nom";
  110. $sortorder = "ASC";
  111. }
  112. // Count total nb of records
  113. $nbtotalofrecords = 0;
  114. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  115. {
  116. $result = $db->query($sql);
  117. $nbtotalofrecords = $db->num_rows($result);
  118. }
  119. $sql.= $db->order($sortfield,$sortorder);
  120. $sql.= $db->plimit($conf->liste_limit +1, $offset);
  121. $result = $db->query($sql);
  122. if ($result)
  123. {
  124. $num = $db->num_rows($result);
  125. $param = "&amp;search_nom=".$search_nom."&amp;search_code=".$search_code."&amp;search_ville=".$search_ville;
  126. if ($search_categ != '') $param.='&amp;search_categ='.$search_categ;
  127. if ($search_sale != '') $param.='&amp;search_sale='.$search_sale;
  128. print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords);
  129. $i = 0;
  130. print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  131. print '<table class="liste" width="100%">'."\n";
  132. // Filter on categories
  133. $moreforfilter='';
  134. if ($conf->categorie->enabled)
  135. {
  136. $moreforfilter.=$langs->trans('Categories'). ': ';
  137. $moreforfilter.=$htmlother->select_categories(2,$search_categ,'search_categ');
  138. $moreforfilter.=' &nbsp; &nbsp; &nbsp; ';
  139. }
  140. // If the user can view prospects other than his'
  141. if ($user->rights->societe->client->voir || $socid)
  142. {
  143. $moreforfilter.=$langs->trans('SalesRepresentatives'). ': ';
  144. $moreforfilter.=$htmlother->select_salesrepresentatives($search_sale,'search_sale',$user);
  145. }
  146. if ($moreforfilter)
  147. {
  148. print '<tr class="liste_titre">';
  149. print '<td class="liste_titre" colspan="6">';
  150. print $moreforfilter;
  151. print '</td></tr>';
  152. }
  153. print '<tr class="liste_titre">';
  154. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  155. print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"s.ville","",$param,"",$sortfield,$sortorder);
  156. print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","",$param,"",$sortfield,$sortorder);
  157. print_liste_field_titre($langs->trans("AccountancyCode"),$_SERVER["PHP_SELF"],"s.code_compta","",$param,'align="left"',$sortfield,$sortorder);
  158. print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"datec","",$param,'align="right"',$sortfield,$sortorder);
  159. print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$params,'align="right"',$sortfield,$sortorder);
  160. print "</tr>\n";
  161. print '<tr class="liste_titre">';
  162. print '<td class="liste_titre">';
  163. print '<input type="text" class="flat" name="search_nom" value="'.$search_nom.'" size="10">';
  164. print '</td>';
  165. print '<td class="liste_titre">';
  166. print '<input type="text" class="flat" name="search_ville" value="'.$search_ville.'" size="10">';
  167. print '</td>';
  168. print '<td class="liste_titre">';
  169. print '<input type="text" class="flat" name="search_code" value="'.$search_code.'" size="10">';
  170. print '</td>';
  171. print '<td align="left" class="liste_titre">';
  172. print '<input type="text" class="flat" name="search_compta" value="'.$search_compta.'" size="10">';
  173. print '</td>';
  174. print '</td><td>&nbsp;</td>';
  175. print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  176. print '&nbsp; ';
  177. print '<input type="image" class="liste_titre" name="button_removefilter" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/searchclear.png" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
  178. print '</td>';
  179. print "</tr>\n";
  180. $var=True;
  181. while ($i < min($num,$conf->liste_limit))
  182. {
  183. $obj = $db->fetch_object($result);
  184. $var=!$var;
  185. print "<tr $bc[$var]>";
  186. print '<td>';
  187. $thirdpartystatic->id=$obj->rowid;
  188. $thirdpartystatic->name=$obj->name;
  189. $thirdpartystatic->client=$obj->client;
  190. $thirdpartystatic->canvas=$obj->canvas;
  191. $thirdpartystatic->status=$obj->status;
  192. print $thirdpartystatic->getNomUrl(1);
  193. print '</td>';
  194. print '<td>'.$obj->ville.'</td>';
  195. print '<td>'.$obj->code_client.'</td>';
  196. print '<td>'.$obj->code_compta.'</td>';
  197. print '<td align="right">'.dol_print_date($db->jdate($obj->datec),'day').'</td>';
  198. print '<td align="right">'.$thirdpartystatic->getLibStatut(3);
  199. print '</td>';
  200. print "</tr>\n";
  201. $i++;
  202. }
  203. //print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],'',$sortfield,$sortorder,'',$num);
  204. print "</table>\n";
  205. print "</form>\n";
  206. $db->free($result);
  207. }
  208. else
  209. {
  210. dol_print_error($db);
  211. }
  212. $db->close();
  213. llxFooter();
  214. ?>