customer.php 6.7 KB

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