dolibarr  16.0.5
customer.php
Go to the documentation of this file.
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 
29 require '../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
32 
33 $action = GETPOST('action', 'aZ09');
34 
35 // Secrutiy check
36 if ($user->socid > 0) {
37  $action = '';
38  $socid = $user->socid;
39 }
40 
41 if (!$user->rights->facture->creer) {
43 }
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array("companies", "orders"));
47 
48 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) {
59  $sortorder = "ASC";
60 }
61 if (!$sortfield) {
62  $sortfield = "nom";
63 }
64 
65 
66 /*
67  * View
68  */
69 
70 llxHeader();
71 
72 $thirdpartystatic = new Societe($db);
73 
74 /*
75  * Mode List
76  */
77 
78 $sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
79 $sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
80 if (empty($user->rights->societe->client->voir) && !$socid) {
81  $sql .= ", sc.fk_soc, sc.fk_user ";
82 }
83 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."commande as c";
84 if (empty($user->rights->societe->client->voir) && !$socid) {
85  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
86 }
87 $sql .= " WHERE s.fk_stcomm = st.id AND c.fk_soc = s.rowid";
88 $sql .= " AND s.entity IN (".getEntity('societe').")";
89 if (empty($user->rights->societe->client->voir) && !$socid) {
90  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
91 }
92 if (GETPOST("search_nom")) {
93  $sql .= natural_search("s.nom", GETPOST("search_nom"));
94 }
95 if (GETPOST("search_compta")) {
96  $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
97 }
98 if (GETPOST("search_code_client")) {
99  $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
100 }
101 if (dol_strlen($begin)) {
102  $sql .= " AND s.nom like '".$db->escape($begin)."'";
103 }
104 if ($socid > 0) {
105  $sql .= " AND s.rowid = ".((int) $socid);
106 }
107 $sql .= " AND c.fk_statut in (1, 2) AND c.facture = 0";
108 $sql .= " GROUP BY s.nom";
109 $sql .= $db->order($sortfield, $sortorder);
110 
111 // Count total nb of records
112 $nbtotalofrecords = '';
113 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
114  $result = $db->query($sql);
115  $nbtotalofrecords = $db->num_rows($result);
116 
117  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
118  $page = 0;
119  $offset = 0;
120  }
121 }
122 
123 $sql .= $db->plimit($limit + 1, $offset);
124 //print $sql;
125 
126 $resql = $db->query($sql);
127 if ($resql) {
128  $num = $db->num_rows($resql);
129  $i = 0;
130 
131  print_barre_liste($langs->trans("MenuOrdersToBill"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
132 
133  print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
134 
135  print '<table class="liste centpercent">';
136  print '<tr class="liste_titre">';
137 
138  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
139  print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "s.town", "", "", 'valign="center"', $sortfield, $sortorder);
140  print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "", 'align="left"', $sortfield, $sortorder);
141  print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", 'align="left"', $sortfield, $sortorder);
142  print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", $addu, "", 'class="right"', $sortfield, $sortorder);
143  print "</tr>\n";
144 
145  // Fields title search
146  print '<tr class="liste_titre">';
147 
148  print '<td align="left" class="liste_titre">';
149  print '<input class="flat" type="text" name="search_nom" value="'.dol_escape_htmltag(GETPOST("search_nom")).'"></td>';
150 
151  print '<td class="liste_titre">&nbsp;</td>';
152 
153  print '<td align="left" class="liste_titre">';
154  print '<input class="flat" type="text" size="10" name="search_code_client" value="'.dol_escape_htmltag(GETPOST("search_code_client")).'">';
155  print '</td>';
156 
157  print '<td align="left" class="liste_titre">';
158  print '<input class="flat" type="text" size="10" name="search_compta" value="'.dol_escape_htmltag(GETPOST("search_compta")).'">';
159  print '</td>';
160 
161  print '<td colspan="2" class="liste_titre right">';
162  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")).'">';
163  print '</td>';
164 
165  print "</tr>\n";
166 
167  while ($i < min($num, $limit)) {
168  $obj = $db->fetch_object($resql);
169 
170  print '<tr class="oddeven">';
171  print '<td>';
172 
173  $result = '';
174  $link = $linkend = '';
175  $link = '<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$obj->rowid.'">';
176  $linkend = '</a>';
177  $name = $obj->name;
178  $result .= ($link.img_object($langs->trans("ShowCompany").': '.$name, 'company').$linkend);
179  $result .= $link.(dol_trunc($name, $maxlen)).$linkend;
180 
181  print $result;
182  print '</td>';
183  print '<td>'.$obj->town.'&nbsp;</td>';
184  print '<td class="left">'.$obj->code_client.'&nbsp;</td>';
185  print '<td class="left">'.$obj->code_compta.'&nbsp;</td>';
186  print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
187  print "</tr>\n";
188  $i++;
189  }
190  print "</table>";
191 
192  print '</form>';
193 
194  $db->free($resql);
195 } else {
196  dol_print_error($db);
197 }
198 
199 // End of page
200 llxFooter();
201 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
dol_escape_htmltag
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
Definition: functions.lib.php:1454
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4830
print_barre_liste
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
Definition: functions.lib.php:5243
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3733
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5012
natural_search
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
Definition: functions.lib.php:9406
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:742
accessforbidden
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59