customer.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * Copyright (C) 2012 Andreu Bisquerra Gaya <jove@bisquerra.com>
  6. * Copyright (C) 2012 David Rodriguez Martinez <davidrm146@gmail.com>
  7. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/commande/customer.php
  24. * \ingroup compta
  25. * \brief Show list of customers to add an new invoice from orders
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  31. $action = GETPOST('action', 'aZ09');
  32. // Secrutiy check
  33. if ($user->socid > 0) {
  34. $action = '';
  35. $socid = $user->socid;
  36. }
  37. if (!$user->hasRight('facture', 'creer')) {
  38. accessforbidden();
  39. }
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("companies", "orders"));
  42. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. if (empty($page) || $page == -1) {
  47. $page = 0;
  48. } // If $page is not defined, or '' or -1
  49. $offset = $limit * $page;
  50. $pageprev = $page - 1;
  51. $pagenext = $page + 1;
  52. if (!$sortorder) {
  53. $sortorder = "ASC";
  54. }
  55. if (!$sortfield) {
  56. $sortfield = "nom";
  57. }
  58. /*
  59. * View
  60. */
  61. llxHeader();
  62. $thirdpartystatic = new Societe($db);
  63. /*
  64. * Mode List
  65. */
  66. $sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
  67. $sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
  68. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  69. $sql .= ", sc.fk_soc, sc.fk_user ";
  70. }
  71. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."commande as c";
  72. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  73. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  74. }
  75. $sql .= " WHERE s.fk_stcomm = st.id AND c.fk_soc = s.rowid";
  76. $sql .= " AND s.entity IN (".getEntity('societe').")";
  77. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  78. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  79. }
  80. if (GETPOST("search_nom")) {
  81. $sql .= natural_search("s.nom", GETPOST("search_nom"));
  82. }
  83. if (GETPOST("search_compta")) {
  84. $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
  85. }
  86. if (GETPOST("search_code_client")) {
  87. $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
  88. }
  89. if (dol_strlen($begin)) {
  90. $sql .= " AND s.nom like '".$db->escape($begin)."'";
  91. }
  92. if ($socid > 0) {
  93. $sql .= " AND s.rowid = ".((int) $socid);
  94. }
  95. $sql .= " AND c.fk_statut in (1, 2) AND c.facture = 0";
  96. $sql .= " GROUP BY s.nom";
  97. $sql .= $db->order($sortfield, $sortorder);
  98. // Count total nb of records
  99. $nbtotalofrecords = '';
  100. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  101. $result = $db->query($sql);
  102. $nbtotalofrecords = $db->num_rows($result);
  103. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  104. $page = 0;
  105. $offset = 0;
  106. }
  107. }
  108. $sql .= $db->plimit($limit + 1, $offset);
  109. //print $sql;
  110. $resql = $db->query($sql);
  111. if ($resql) {
  112. $num = $db->num_rows($resql);
  113. $i = 0;
  114. print_barre_liste($langs->trans("MenuOrdersToBill"), $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", "", "", 'align="left"', $sortfield, $sortorder);
  121. print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", 'align="left"', $sortfield, $sortorder);
  122. print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", $addu, "", 'class="right"', $sortfield, $sortorder);
  123. print "</tr>\n";
  124. // Fields title search
  125. print '<tr class="liste_titre">';
  126. print '<td align="left" class="liste_titre">';
  127. print '<input class="flat" type="text" name="search_nom" value="'.dol_escape_htmltag(GETPOST("search_nom")).'"></td>';
  128. print '<td class="liste_titre">&nbsp;</td>';
  129. print '<td align="left" class="liste_titre">';
  130. print '<input class="flat" type="text" size="10" name="search_code_client" value="'.dol_escape_htmltag(GETPOST("search_code_client")).'">';
  131. print '</td>';
  132. print '<td align="left" class="liste_titre">';
  133. print '<input class="flat" type="text" size="10" name="search_compta" value="'.dol_escape_htmltag(GETPOST("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, $limit)) {
  140. $obj = $db->fetch_object($resql);
  141. print '<tr class="oddeven">';
  142. print '<td>';
  143. $result = '';
  144. $link = $linkend = '';
  145. $link = '<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$obj->rowid.'">';
  146. $linkend = '</a>';
  147. $name = $obj->name;
  148. $result .= ($link.img_object($langs->trans("ShowCompany").': '.$name, 'company').$linkend);
  149. $result .= $link.(dol_trunc($name, $maxlen)).$linkend;
  150. print $result;
  151. print '</td>';
  152. print '<td>'.$obj->town.'&nbsp;</td>';
  153. print '<td class="left">'.$obj->code_client.'&nbsp;</td>';
  154. print '<td class="left">'.$obj->code_compta.'&nbsp;</td>';
  155. print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
  156. print "</tr>\n";
  157. $i++;
  158. }
  159. print "</table>";
  160. print '</form>';
  161. $db->free($resql);
  162. } else {
  163. dol_print_error($db);
  164. }
  165. // End of page
  166. llxFooter();
  167. $db->close();