dolibarr 24.0.0-beta
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 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
9 * Copyright (C) 2026 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
34require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
35
44$action = GETPOST('action', 'aZ09');
45
46// Secrutiy check
47if ($user->socid > 0) {
48 $action = '';
49 $socid = $user->socid;
50} else {
51 $socid = 0;
52}
53
54if (!$user->hasRight('facture', 'creer')) {
56}
57
58// Load translation files required by the page
59$langs->loadLangs(array("companies", "orders"));
60
61$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
62$sortfield = GETPOST('sortfield', 'aZ09comma');
63$sortorder = GETPOST('sortorder', 'aZ09comma');
64$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
65if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
66 // If $page is not defined, or '' or -1 or if we click on clear filters
67 $page = 0;
68}
69$offset = $limit * $page;
70$pageprev = $page - 1;
71$pagenext = $page + 1;
72if (!$sortorder) {
73 $sortorder = "ASC";
74}
75if (!$sortfield) {
76 $sortfield = "nom";
77}
78
79
80/*
81 * View
82 */
83
84llxHeader('', '', '', '', 0, 0, '', '', '', 'mod-commande page-customer');
85
86// Mode List
87
88$sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec,";
89$sql .= " st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta as code_compta_client";
90$sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."commande as c";
91$sql .= " WHERE s.fk_stcomm = st.id AND c.fk_soc = s.rowid";
92$sql .= " AND s.entity IN (".getEntity('societe').")";
93if (GETPOST("search_nom")) {
94 $sql .= natural_search("s.nom", GETPOST("search_nom"));
95}
96if (GETPOST("search_compta")) {
97 $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
98}
99if (GETPOST("search_code_client")) {
100 $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
101}
102// If the internal user must only see his customers, force searching by him
103$search_sale = 0;
104if (!$user->hasRight('societe', 'client', 'voir')) {
105 $search_sale = $user->id;
106}
107// Search on sale representative
108if ($search_sale && $search_sale != '-1') {
109 if ($search_sale == -2) {
110 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
111 } elseif ($search_sale > 0) {
112 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
113 }
114}
115// Search on socid
116if ($socid) {
117 $sql .= " AND c.fk_soc = ".((int) $socid);
118}
119$sql .= " AND c.fk_statut in (1, 2) AND c.facture = 0";
120$sql .= " GROUP BY s.nom, s.rowid";
121$sql .= $db->order($sortfield, $sortorder);
122
123// Count total nb of records
124$nbtotalofrecords = '';
125if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
126 $result = $db->query($sql);
127 $nbtotalofrecords = $db->num_rows($result);
128
129 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
130 $page = 0;
131 $offset = 0;
132 }
133}
134
135$sql .= $db->plimit($limit + 1, $offset);
136//print $sql;
137
138$resql = $db->query($sql);
139if ($resql) {
140 $num = $db->num_rows($resql);
141 $i = 0;
142
143 print_barre_liste($langs->trans("MenuOrdersToBill"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
144
145 print '<form method="GET" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
146
147 print '<table class="liste centpercent">';
148 print '<tr class="liste_titre">';
149
150 print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
151 print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "s.town", "", "", 'valign="center"', $sortfield, $sortorder);
152 print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "", 'align="left"', $sortfield, $sortorder);
153 print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", 'align="left"', $sortfield, $sortorder);
154 print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", "", "", 'class="right"', $sortfield, $sortorder);
155 print "</tr>\n";
156
157 // Fields title search
158 print '<tr class="liste_titre">';
159
160 print '<td align="left" class="liste_titre">';
161 print '<input class="flat" type="text" name="search_nom" value="'.dol_escape_htmltag(GETPOST("search_nom")).'"></td>';
162
163 print '<td class="liste_titre">&nbsp;</td>';
164
165 print '<td align="left" class="liste_titre">';
166 print '<input class="flat" type="text" size="10" name="search_code_client" value="'.dol_escape_htmltag(GETPOST("search_code_client")).'">';
167 print '</td>';
168
169 print '<td align="left" class="liste_titre">';
170 print '<input class="flat" type="text" size="10" name="search_compta" value="'.dol_escape_htmltag(GETPOST("search_compta")).'">';
171 print '</td>';
172
173 print '<td colspan="2" class="liste_titre right">';
174 print '<input type="image" class="liste_titre" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" name="button_search" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
175 print '</td>';
176
177 print "</tr>\n";
178
179 while ($i < min($num, $limit)) {
180 $obj = $db->fetch_object($resql);
181
182 print '<tr class="oddeven">';
183 print '<td class="tdoverflowmax150">';
184
185 $result = '';
186 $link = $linkend = '';
187 $link = '<a href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$obj->rowid.'">';
188 $linkend = '</a>';
189 $name = $obj->name;
190 $result .= ($link.img_object($langs->trans("ShowCompany").': '.$name, 'company').$linkend);
191 $result .= $link.$name.$linkend;
192
193 print $result;
194 print '</td>';
195 print '<td>'.dolPrintLabel($obj->town).'</td>';
196 print '<td class="left">'.dolPrintLabel($obj->code_client).'</td>';
197 print '<td class="left">'.dolPrintLabel($obj->code_compta_client).'</td>';
198 print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
199 print "</tr>\n";
200 $i++;
201 }
202 print "</table>";
203
204 print '</form>';
205
206 $db->free($resql);
207} else {
209}
210
211// End of page
212llxFooter();
213$db->close();
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.