customer.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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@capnetworks.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. $langs->load("companies");
  40. $langs->load("orders");
  41. $limit = GETPOST("limit")?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', 1).")";
  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. }
  92. $sql.= $db->plimit($limit + 1, $offset);
  93. //print $sql;
  94. $resql = $db->query($sql);
  95. if ($resql)
  96. {
  97. $num = $db->num_rows($resql);
  98. $i = 0;
  99. print_barre_liste($langs->trans("MenuOrdersToBill"), $page, $_SERVER["PHP_SELF"],"",$sortfield,$sortorder,'',$num);
  100. print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
  101. print '<table class="liste" width="100%">';
  102. print '<tr class="liste_titre">';
  103. print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder);
  104. print_liste_field_titre($langs->trans("Town"),$_SERVER["PHP_SELF"],"s.town","","",'valign="center"',$sortfield,$sortorder);
  105. print_liste_field_titre($langs->trans("CustomerCode"),$_SERVER["PHP_SELF"],"s.code_client","","",'align="left"',$sortfield,$sortorder);
  106. print_liste_field_titre($langs->trans("AccountancyCode"),$_SERVER["PHP_SELF"],"s.code_compta","","",'align="left"',$sortfield,$sortorder);
  107. print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"datec",$addu,"",'align="right"',$sortfield,$sortorder);
  108. print "</tr>\n";
  109. // Lignes des champs de filtre
  110. print '<tr class="liste_titre">';
  111. print '<td align="left" class="liste_titre">';
  112. print '<input class="flat" type="text" name="search_nom" value="'.dol_escape_htmltag(GETPOST("search_nom")).'"></td>';
  113. print '<td class="liste_titre">&nbsp;</td>';
  114. print '<td align="left" class="liste_titre">';
  115. print '<input class="flat" type="text" size="10" name="search_code_client" value="'.dol_escape_htmltag(GETPOST("search_code_client")).'">';
  116. print '</td>';
  117. print '<td align="left" class="liste_titre">';
  118. print '<input class="flat" type="text" size="10" name="search_compta" value="'.dol_escape_htmltag(GETPOST("search_compta")).'">';
  119. print '</td>';
  120. print '<td align="right" colspan="2" class="liste_titre">';
  121. 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")).'">';
  122. print '</td>';
  123. print "</tr>\n";
  124. $var=true;
  125. while ($i < min($num,$limit))
  126. {
  127. $obj = $db->fetch_object($resql);
  128. print '<tr class="oddeven">';
  129. print '<td>';
  130. $result='';
  131. $link=$linkend='';
  132. $link = '<a href="'.dol_buildpath('/commande/orderstoinvoice.php',1).'?socid='.$obj->rowid.'">';
  133. $linkend='</a>';
  134. $name=$obj->name;
  135. $result.=($link.img_object($langs->trans("ShowCompany").': '.$name,'company').$linkend);
  136. $result.=$link.(dol_trunc($name,$maxlen)).$linkend;
  137. print $result;
  138. print '</td>';
  139. print '<td>'.$obj->town.'&nbsp;</td>';
  140. print '<td align="left">'.$obj->code_client.'&nbsp;</td>';
  141. print '<td align="left">'.$obj->code_compta.'&nbsp;</td>';
  142. print '<td align="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
  143. print "</tr>\n";
  144. $i++;
  145. }
  146. print "</table>";
  147. print '</form>';
  148. $db->free($resql);
  149. }
  150. else
  151. {
  152. dol_print_error($db);
  153. }
  154. llxFooter();
  155. $db->close();