dolibarr  16.0.5
clients.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  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
26 require '../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
29 
30 $action = GETPOST('action', 'aZ09');
31 
32 // Secrutiy check
33 if ($user->socid > 0) {
34  $action = '';
35  $socid = $user->socid;
36 }
37 
38 if (!$user->rights->facture->lire) {
40 }
41 
42 // Load translation files required by the page
43 $langs->load("companies");
44 
45 $mode = GETPOST("mode");
46 
47 $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
48 $sortfield = GETPOST('sortfield', 'aZ09comma');
49 $sortorder = GETPOST('sortorder', 'aZ09comma');
50 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
51 if (empty($page) || $page == -1) {
52  $page = 0;
53 } // If $page is not defined, or '' or -1
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (!$sortorder) {
58  $sortorder = "ASC";
59 }
60 if (!$sortfield) {
61  $sortfield = "nom";
62 }
63 
64 
65 /*
66  * View
67  */
68 
69 llxHeader();
70 
71 $thirdpartystatic = new Societe($db);
72 
73 if ($action == 'note') {
74  $sql = "UPDATE ".MAIN_DB_PREFIX."societe SET note='".$db->escape($note)."' WHERE rowid=".((int) $socid);
75  $result = $db->query($sql);
76 }
77 
78 if ($mode == 'search') {
79  $resql = $db->query($sql);
80  if ($resql) {
81  if ($db->num_rows($resql) == 1) {
82  $obj = $db->fetch_object($resql);
83  $socid = $obj->rowid;
84  }
85  $db->free($resql);
86  }
87 }
88 
89 
90 
91 /*
92  * Mode List
93  */
94 
95 $sql = "SELECT s.rowid, s.nom as name, s.client, s.town, s.datec, s.datea";
96 $sql .= ", st.libelle as stcomm, s.prefix_comm, s.code_client, s.code_compta ";
97 if (empty($user->rights->societe->client->voir) && !$socid) {
98  $sql .= ", sc.fk_soc, sc.fk_user ";
99 }
100 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st";
101 if (empty($user->rights->societe->client->voir) && !$socid) {
102  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
103 }
104 $sql .= " WHERE s.fk_stcomm = st.id AND s.client in (1, 3)";
105 $sql .= " AND s.entity IN (".getEntity('societe').")";
106 if (empty($user->rights->societe->client->voir) && !$socid) {
107  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
108 }
109 if (dol_strlen($stcomm)) {
110  $sql .= " AND s.fk_stcomm=".((int) $stcomm);
111 }
112 if (GETPOST("search_nom")) {
113  $sql .= natural_search("s.nom", GETPOST("search_nom"));
114 }
115 if (GETPOST("search_compta")) {
116  $sql .= natural_search("s.code_compta", GETPOST("search_compta"));
117 }
118 if (GETPOST("search_code_client")) {
119  $sql .= natural_search("s.code_client", GETPOST("search_code_client"));
120 }
121 if ($socid) {
122  $sql .= " AND s.rowid = ".((int) $socid);
123 }
124 $sql .= " ORDER BY $sortfield $sortorder";
125 $sql .= $db->plimit($conf->liste_limit + 1, $offset);
126 //print $sql;
127 
128 $resql = $db->query($sql);
129 if ($resql) {
130  $num = $db->num_rows($resql);
131  $i = 0;
132 
133  $langs->load('commercial');
134 
135  print_barre_liste($langs->trans("ListOfCustomers"), $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, '', $num);
136 
137  print '<form method="GET" action="'.$_SERVER["PHP_SELF"].'">';
138 
139  print '<table class="liste centpercent">';
140  print '<tr class="liste_titre">';
141 
142  print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder);
143  print_liste_field_titre("Town", $_SERVER["PHP_SELF"], "s.town", "", "", 'valign="center"', $sortfield, $sortorder);
144  print_liste_field_titre("CustomerCode", $_SERVER["PHP_SELF"], "s.code_client", "", "", '', $sortfield, $sortorder, 'left ');
145  print_liste_field_titre("AccountancyCode", $_SERVER["PHP_SELF"], "s.code_compta", "", "", '', $sortfield, $sortorder, 'left ');
146  print_liste_field_titre("DateCreation", $_SERVER["PHP_SELF"], "datec", $addu, "", '', $sortfield, $sortorder, 'right ');
147  print "</tr>\n";
148 
149  // Fields title search
150  print '<tr class="liste_titre">';
151 
152  print '<td class="liste_titre left">';
153  print '<input class="flat" type="text" name="search_nom" value="'.$_GET["search_nom"].'"></td>';
154 
155  print '<td class="liste_titre">&nbsp;</td>';
156 
157  print '<td class="liste_titre left">';
158  print '<input class="flat" type="text" size="10" name="search_code_client" value="'.$_GET["search_code_client"].'">';
159  print '</td>';
160 
161  print '<td class="liste_titre left">';
162  print '<input class="flat" type="text" size="10" name="search_compta" value="'.$_GET["search_compta"].'">';
163  print '</td>';
164 
165  print '<td colspan="2" class="liste_titre right">';
166  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")).'">';
167  print '</td>';
168  print "</tr>\n";
169 
170  while ($i < min($num, $conf->liste_limit)) {
171  $obj = $db->fetch_object($resql);
172 
173  print '<tr class="oddeven">';
174  print '<td>';
175  $thirdpartystatic->id = $obj->rowid;
176  $thirdpartystatic->name = $obj->name;
177  $thirdpartystatic->client = $obj->client;
178  print $thirdpartystatic->getNomUrl(1, 'compta');
179  print '</td>';
180  print '<td>'.$obj->town.'&nbsp;</td>';
181  print '<td class="left">'.$obj->code_client.'&nbsp;</td>';
182  print '<td class="left">'.$obj->code_compta.'&nbsp;</td>';
183  print '<td class="right">'.dol_print_date($db->jdate($obj->datec)).'</td>';
184  print "</tr>\n";
185  $i++;
186  }
187  print "</table>";
188 
189  print '</form>';
190 
191  $db->free($resql);
192 } else {
193  dol_print_error($db);
194 }
195 
196 llxFooter();
197 $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:1468
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:4844
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:5257
dol_strlen
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
Definition: functions.lib.php:3747
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:5026
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:9420
$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