clients.php 6.2 KB

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