clients.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
  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 3 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/compta/clients.php
  21. * \ingroup compta
  22. * \brief Show list of customers to add an new invoice
  23. */
  24. require '../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  26. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  27. $action=GETPOST('action','aZ09');
  28. // Secrutiy check
  29. if ($user->societe_id > 0)
  30. {
  31. $action = '';
  32. $socid = $user->societe_id;
  33. }
  34. if (! $user->rights->facture->lire)
  35. accessforbidden();
  36. $langs->load("companies");
  37. $mode=GETPOST("mode");
  38. $sortfield = GETPOST("sortfield",'alpha');
  39. $sortorder = GETPOST("sortorder",'alpha');
  40. $page = GETPOST("page",'int');
  41. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  42. $offset = $conf->liste_limit * $page;
  43. $pageprev = $page - 1;
  44. $pagenext = $page + 1;
  45. if (! $sortorder) $sortorder="ASC";
  46. if (! $sortfield) $sortfield="nom";
  47. /*
  48. * View
  49. */
  50. llxHeader();
  51. $thirdpartystatic=new Societe($db);
  52. if ($action == 'note')
  53. {
  54. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$note."' WHERE rowid=".$socid;
  55. $result = $db->query($sql);
  56. }
  57. if ($mode == 'search')
  58. {
  59. $resql=$db->query($sql);
  60. if ($resql) {
  61. if ( $db->num_rows($resql) == 1) {
  62. $obj = $db->fetch_object($resql);
  63. $socid = $obj->rowid;
  64. }
  65. $db->free($resql);
  66. }
  67. }
  68. /*
  69. * Mode List
  70. */
  71. $sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
  72. $sql.= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
  73. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk_user ";
  74. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
  75. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  76. $sql.= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)";
  77. $sql.= " AND s.entity IN (".getEntity('societe').")";
  78. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  79. if (dol_strlen($stcomm))
  80. {
  81. $sql.= " AND s.fk_stcomm=".$stcomm;
  82. }
  83. if ($socname)
  84. {
  85. $sql.= natural_search("s.nom", $socname);
  86. $sortfield = "s.nom";
  87. $sortorder = "ASC";
  88. }
  89. if ($_GET["search_nom"])
  90. {
  91. $sql.= natural_search("s.nom", GETPOST("search_nom"));
  92. }
  93. if ($_GET["search_compta"])
  94. {
  95. $sql.= natural_search("s.code_compta", GETPOST("search_compta"));
  96. }
  97. if ($_GET["search_code_client"])
  98. {
  99. $sql.= natural_search("s.code_client", GETPOST("search_code_client"));
  100. }
  101. if (dol_strlen($begin))
  102. {
  103. $sql.= natural_search("s.nom", $begin);
  104. }
  105. if ($socid)
  106. {
  107. $sql.= " AND s.rowid = ".$socid;
  108. }
  109. $sql.= " ORDER BY $sortfield $sortorder ";
  110. $sql.= $db->plimit($conf->liste_limit+1, $offset);
  111. //print $sql;
  112. $resql = $db->query($sql);
  113. if ($resql)
  114. {
  115. $num = $db->num_rows($resql);
  116. $i = 0;
  117. $langs->load('commercial');
  118. print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',$num);
  119. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  120. print '<table class="liste" width="100%">';
  121. print '<tr class="liste_titre">';
  122. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder);
  123. print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"s.town","","",'valign="center"',$sortfield,$sortorder);
  124. print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","",'align="left"',$sortfield,$sortorder);
  125. print_liste_field_titre($langs->trans("AccountancyCode"),$_SERVER["PHP_SELF"],"s.code_compta","","",'align="left"',$sortfield,$sortorder);
  126. print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"datec",$addu,"",'align="right"',$sortfield,$sortorder);
  127. print "</tr>\n";
  128. // Lignes des champs de filtre
  129. print '<tr class="liste_titre">';
  130. print '<td align="left" class="liste_titre">';
  131. print '<input class="flat" type="text" name="search_nom" value="'.$_GET["search_nom"].'"></td>';
  132. print '<td class="liste_titre">&nbsp;</td>';
  133. print '<td align="left" class="liste_titre">';
  134. print '<input class="flat" type="text" size="10" name="search_code_client" value="'.$_GET["search_code_client"].'">';
  135. print '</td>';
  136. print '<td align="left" class="liste_titre">';
  137. print '<input class="flat" type="text" size="10" name="search_compta" value="'.$_GET["search_compta"].'">';
  138. print '</td>';
  139. print '<td align="right" colspan="2" class="liste_titre">';
  140. print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"),'search.png','','',1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
  141. print '</td>';
  142. print "</tr>\n";
  143. $var=true;
  144. while ($i < min($num,$conf->liste_limit))
  145. {
  146. $obj = $db->fetch_object($resql);
  147. print '<tr class="oddeven">';
  148. print '<td>';
  149. $thirdpartystatic->id=$obj->rowid;
  150. $thirdpartystatic->name=$obj->name;
  151. $thirdpartystatic->client=$obj->client;
  152. print $thirdpartystatic->getNomUrl(1,'compta');
  153. print '</td>';
  154. print '<td>'.$obj->town.'&nbsp;</td>';
  155. print '<td align="left">'.$obj->code_client.'&nbsp;</td>';
  156. print '<td align="left">'.$obj->code_compta.'&nbsp;</td>';
  157. print '<td align="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
  158. print "</tr>\n";
  159. $i++;
  160. }
  161. print "</table>";
  162. print '</form>';
  163. $db->free($resql);
  164. }
  165. else
  166. {
  167. dol_print_error($db);
  168. }
  169. llxFooter();
  170. $db->close();