customer.php 6.8 KB

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