clients.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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@inodbox.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 <https://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. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  28. $action = GETPOST('action', 'aZ09');
  29. // Secrutiy check
  30. if ($user->socid > 0) {
  31. $action = '';
  32. $socid = $user->socid;
  33. }
  34. if (!$user->hasRight('facture', 'lire')) {
  35. accessforbidden();
  36. }
  37. // Load translation files required by the page
  38. $langs->load("companies");
  39. $mode = GETPOST("mode");
  40. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  41. $sortfield = GETPOST('sortfield', 'aZ09comma');
  42. $sortorder = GETPOST('sortorder', 'aZ09comma');
  43. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  44. if (empty($page) || $page == -1) {
  45. $page = 0;
  46. } // If $page is not defined, or '' or -1
  47. $offset = $limit * $page;
  48. $pageprev = $page - 1;
  49. $pagenext = $page + 1;
  50. if (!$sortorder) {
  51. $sortorder = "ASC";
  52. }
  53. if (!$sortfield) {
  54. $sortfield = "nom";
  55. }
  56. /*
  57. * View
  58. */
  59. llxHeader();
  60. $thirdpartystatic = new Societe($db);
  61. if ($action == 'note') {
  62. $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$db->escape($note)."' WHERE rowid=".((int) $socid);
  63. $result = $db->query($sql);
  64. }
  65. if ($mode == 'search') {
  66. $resql = $db->query($sql);
  67. if ($resql) {
  68. if ($db->num_rows($resql) == 1) {
  69. $obj = $db->fetch_object($resql);
  70. $socid = $obj->rowid;
  71. }
  72. $db->free($resql);
  73. }
  74. }
  75. /*
  76. * Mode List
  77. */
  78. $sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
  79. $sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
  80. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  81. $sql .= ", sc.fk_soc, sc.fk_user ";
  82. }
  83. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
  84. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  85. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  86. }
  87. $sql .= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)";
  88. $sql .= " AND s.entity IN (".getEntity('societe').")";
  89. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  90. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  91. }
  92. if (dol_strlen($stcomm)) {
  93. $sql .= " AND s.fk_stcomm=".((int) $stcomm);
  94. }
  95. if (GETPOST("search_nom")) {
  96. $sql .= natural_search("s.nom", GETPOST("search_nom"));
  97. }
  98. if (GETPOST("search_compta")) {
  99. $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
  100. }
  101. if (GETPOST("search_code_client")) {
  102. $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
  103. }
  104. if ($socid) {
  105. $sql .= " AND s.rowid = ".((int) $socid);
  106. }
  107. $sql .= " ORDER BY $sortfield $sortorder";
  108. $sql .= $db->plimit($conf->liste_limit + 1, $offset);
  109. //print $sql;
  110. $resql = $db->query($sql);
  111. if ($resql) {
  112. $num = $db->num_rows($resql);
  113. $i = 0;
  114. $langs->load('commercial');
  115. print_barre_liste($langs->trans("Customers"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
  116. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  117. print '<table class="liste centpercent">';
  118. print '<tr class="liste_titre">';
  119. print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
  120. print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "s.town", "", "", 'valign="center"', $sortfield, $sortorder);
  121. print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "", '', $sortfield, $sortorder, 'left ');
  122. print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", '', $sortfield, $sortorder, 'left ');
  123. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", $addu, "", '', $sortfield, $sortorder, 'right ');
  124. print "</tr>\n";
  125. // Fields title search
  126. print '<tr class="liste_titre">';
  127. print '<td class="liste_titre left">';
  128. print '<input class="flat" type="text" name="search_nom" value="'.$_GET["search_nom"].'"></td>';
  129. print '<td class="liste_titre">&nbsp;</td>';
  130. print '<td class="liste_titre left">';
  131. print '<input class="flat" type="text" size="10" name="search_code_client" value="'.$_GET["search_code_client"].'">';
  132. print '</td>';
  133. print '<td class="liste_titre left">';
  134. print '<input class="flat" type="text" size="10" name="search_compta" value="'.$_GET["search_compta"].'">';
  135. print '</td>';
  136. print '<td colspan="2" class="liste_titre right">';
  137. 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")).'">';
  138. print '</td>';
  139. print "</tr>\n";
  140. while ($i < min($num, $conf->liste_limit)) {
  141. $obj = $db->fetch_object($resql);
  142. print '<tr class="oddeven">';
  143. print '<td>';
  144. $thirdpartystatic->id = $obj->rowid;
  145. $thirdpartystatic->name = $obj->name;
  146. $thirdpartystatic->client = $obj->client;
  147. print $thirdpartystatic->getNomUrl(1, 'compta');
  148. print '</td>';
  149. print '<td>'.$obj->town.'&nbsp;</td>';
  150. print '<td class="left">'.$obj->code_client.'&nbsp;</td>';
  151. print '<td class="left">'.$obj->code_compta.'&nbsp;</td>';
  152. print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
  153. print "</tr>\n";
  154. $i++;
  155. }
  156. print "</table>";
  157. print '</form>';
  158. $db->free($resql);
  159. } else {
  160. dol_print_error($db);
  161. }
  162. llxFooter();
  163. $db->close();