dolibarr 19.0.3
index.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2014-2021 Charlene Benke <charlene.r@benke.fr>
6 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
7 * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
8 * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31require '../main.inc.php';
32require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
33require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34
35
36// Load translation files required by the page
37$langs->load("companies");
38
39
40// Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
41$hookmanager = new HookManager($db);
42$hookmanager->initHooks(array('thirdpartiesindex'));
43
44
45
46$socid = GETPOST('socid', 'int');
47if ($user->socid) {
48 $socid = $user->socid;
49}
50
51// Security check
52$result = restrictedArea($user, 'societe', 0, '', '', '', '');
53
54$thirdparty_static = new Societe($db);
55
56if (!isset($form) || !is_object($form)) {
57 $form = new Form($db);
58}
59
60// Load $resultboxes
61$resultboxes = FormOther::getBoxesArea($user, "3");
62
63if (GETPOST('addbox')) {
64 // Add box (when submit is done from a form when ajax disabled)
65 require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
66 $zone = GETPOST('areacode', 'int');
67 $userid = GETPOST('userid', 'int');
68 $boxorder = GETPOST('boxorder', 'aZ09');
69 $boxorder .= GETPOST('boxcombo', 'aZ09');
70 $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
71 if ($result > 0) {
72 setEventMessages($langs->trans("BoxAdded"), null);
73 }
74}
75
76
77/*
78 * View
79 */
80
81$transAreaType = $langs->trans("ThirdPartiesArea");
82$helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
83
84llxHeader("", $langs->trans("ThirdParties"), $helpurl);
85
86print load_fiche_titre($transAreaType, $resultboxes['selectboxlist'], 'companies');
87
88
89/*
90 * Statistics area
91 */
92
93$third = array(
94 'customer' => 0,
95 'prospect' => 0,
96 'supplier' => 0,
97 'other' =>0
98);
99$total = 0;
100
101$sql = "SELECT s.rowid, s.client, s.fournisseur";
102$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
103if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
104 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
105}
106$sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
107if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
108 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
109}
110if (!$user->hasRight('fournisseur', 'lire')) {
111 $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
112}
113// Add where from hooks
114$parameters = array('socid' => $socid);
115$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
116if (empty($reshook)) {
117 if ($socid > 0) {
118 $sql .= " AND s.rowid = ".((int) $socid);
119 }
120}
121$sql .= $hookmanager->resPrint;
122//print $sql;
123$result = $db->query($sql);
124if ($result) {
125 while ($objp = $db->fetch_object($result)) {
126 $found = 0;
127 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS') && ($objp->client == 2 || $objp->client == 3)) {
128 $found = 1;
129 $third['prospect']++;
130 }
131 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS') && ($objp->client == 1 || $objp->client == 3)) {
132 $found = 1;
133 $third['customer']++;
134 }
135 if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS') && $objp->fournisseur) {
136 $found = 1;
137 $third['supplier']++;
138 }
139 if (isModEnabled('societe') && $objp->client == 0 && $objp->fournisseur == 0) {
140 $found = 1;
141 $third['other']++;
142 }
143 if ($found) {
144 $total++;
145 }
146 }
147} else {
148 dol_print_error($db);
149}
150
151$thirdpartygraph = '<div class="div-table-responsive-no-min">';
152$thirdpartygraph .= '<table class="noborder nohover centpercent">'."\n";
153$thirdpartygraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
154if (!empty($conf->use_javascript_ajax) && ((round($third['prospect']) ? 1 : 0) + (round($third['customer']) ? 1 : 0) + (round($third['supplier']) ? 1 : 0) + (round($third['other']) ? 1 : 0) >= 2)) {
155 $thirdpartygraph .= '<tr><td class="center" colspan="2">';
156 $dataseries = array();
157 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
158 $dataseries[] = array($langs->transnoentitiesnoconv("Prospects"), round($third['prospect']));
159 }
160 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) {
161 $dataseries[] = array($langs->transnoentitiesnoconv("Customers"), round($third['customer']));
162 }
163 if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS')) {
164 $dataseries[] = array($langs->transnoentitiesnoconv("Suppliers"), round($third['supplier']));
165 }
166 if (isModEnabled('societe')) {
167 $dataseries[] = array($langs->transnoentitiesnoconv("Others"), round($third['other']));
168 }
169 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
170 $dolgraph = new DolGraph();
171 $dolgraph->SetData($dataseries);
172 $dolgraph->setShowLegend(2);
173 $dolgraph->setShowPercent(1);
174 $dolgraph->SetType(array('pie'));
175 $dolgraph->setHeight('200');
176 $dolgraph->draw('idgraphthirdparties');
177 $thirdpartygraph .= $dolgraph->show();
178 $thirdpartygraph .= '</td></tr>'."\n";
179} else {
180 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
181 $statstring = "<tr>";
182 $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
183 $statstring .= "</tr>";
184 }
185 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) {
186 $statstring .= "<tr>";
187 $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
188 $statstring .= "</tr>";
189 }
190 $statstring2 = '';
191 if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'lire') && !getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD')) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && !getDolGlobalString('SOCIETE_DISABLE_SUPPLIERS_STATS')) {
192 $statstring2 = "<tr>";
193 $statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
194 $statstring2 .= "</tr>";
195 }
196 $thirdpartygraph .= $statstring;
197 $thirdpartygraph .= $statstring2;
198}
199$thirdpartygraph .= '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td class="right">';
200$thirdpartygraph .= $total;
201$thirdpartygraph .= '</td></tr>';
202$thirdpartygraph .= '</table>';
203$thirdpartygraph .= '</div>';
204
205$thirdpartycateggraph = '';
206if (isModEnabled('categorie') && getDolGlobalString('CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')) {
207 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
208 $elementtype = 'societe';
209
210 $thirdpartycateggraph = '<div class="div-table-responsive-no-min">';
211 $thirdpartycateggraph .= '<table class="noborder nohover centpercent">';
212 $thirdpartycateggraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
213 $thirdpartycateggraph .= '<tr><td class="center" colspan="2">';
214 $sql = "SELECT c.label, count(*) as nb";
215 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
216 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
217 $sql .= " WHERE c.type = 2";
218 if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
219 $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
220 }
221 $sql .= " AND c.entity IN (".getEntity('category').")";
222 $sql .= " GROUP BY c.label";
223 $total = 0;
224 $result = $db->query($sql);
225 if ($result) {
226 $num = $db->num_rows($result);
227 $i = 0;
228 if (!empty($conf->use_javascript_ajax)) {
229 $dataseries = array();
230 $rest = 0;
231 $nbmax = 10;
232
233 while ($i < $num) {
234 $obj = $db->fetch_object($result);
235 if ($i < $nbmax) {
236 $dataseries[] = array($obj->label, round($obj->nb));
237 } else {
238 $rest += $obj->nb;
239 }
240 $total += $obj->nb;
241 $i++;
242 }
243 if ($i > $nbmax) {
244 $dataseries[] = array($langs->trans("Other"), round($rest));
245 }
246 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
247 $dolgraph = new DolGraph();
248 $dolgraph->SetData($dataseries);
249 $dolgraph->setShowLegend(2);
250 $dolgraph->setShowPercent(1);
251 $dolgraph->SetType(array('pie'));
252 $dolgraph->setHeight('200');
253 $dolgraph->draw('idgraphcateg');
254 $thirdpartycateggraph .= $dolgraph->show();
255 } else {
256 while ($i < $num) {
257 $obj = $db->fetch_object($result);
258
259 $thirdpartycateggraph .= '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
260 $total += $obj->nb;
261 $i++;
262 }
263 }
264 }
265 $thirdpartycateggraph .= '</td></tr>';
266 $thirdpartycateggraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
267 $thirdpartycateggraph .= $total;
268 $thirdpartycateggraph .= '</td></tr>';
269 $thirdpartycateggraph .= '</table>';
270 $thirdpartycateggraph .= '</div>';
271} else {
272 $thirdpartycateggraph = '';
273}
274
275
276/*
277 * Latest modified third parties
278 */
279$max = 15;
280$sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
281$sql .= ", s.code_client";
282$sql .= ", s.code_fournisseur";
283if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
284 $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
285 $sql .= ", spe.accountancy_code_customer as code_compta";
286} else {
287 $sql .= ", s.code_compta_fournisseur";
288 $sql .= ", s.code_compta";
289}
290$sql .= ", s.logo";
291$sql .= ", s.entity";
292$sql .= ", s.canvas, s.tms as date_modification, s.status as status";
293$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
294if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
295 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
296}
297if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
298 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
299}
300$sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
301if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
302 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
303}
304if (!$user->hasRight('fournisseur', 'lire')) {
305 $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
306}
307// Add where from hooks
308$parameters = array('socid' => $socid);
309$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
310if (empty($reshook)) {
311 if ($socid > 0) {
312 $sql .= " AND s.rowid = ".((int) $socid);
313 }
314}
315$sql .= $hookmanager->resPrint;
316$sql .= $db->order("s.tms", "DESC");
317$sql .= $db->plimit($max, 0);
318
319//print $sql;
320$lastmodified="";
321$result = $db->query($sql);
322if ($result) {
323 $num = $db->num_rows($result);
324
325 $i = 0;
326
327 if ($num > 0) {
328 $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
329
330 $lastmodified = "\n<!-- last thirdparties modified -->\n";
331 $lastmodified .= '<div class="div-table-responsive-no-min">';
332 $lastmodified .= '<table class="noborder centpercent">';
333
334 $lastmodified .= '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
335 $lastmodified .= '<th>&nbsp;</th>';
336 $lastmodified .= '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
337 $lastmodified .= '</tr>'."\n";
338
339 while ($i < $num) {
340 $objp = $db->fetch_object($result);
341
342 $thirdparty_static->id = $objp->rowid;
343 $thirdparty_static->name = $objp->name;
344 $thirdparty_static->client = $objp->client;
345 $thirdparty_static->fournisseur = $objp->fournisseur;
346 $thirdparty_static->logo = $objp->logo;
347 $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
348 $thirdparty_static->status = $objp->status;
349 $thirdparty_static->code_client = $objp->code_client;
350 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
351 $thirdparty_static->canvas = $objp->canvas;
352 $thirdparty_static->email = $objp->email;
353 $thirdparty_static->entity = $objp->entity;
354 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
355 $thirdparty_static->code_compta = $objp->code_compta;
356
357 $lastmodified .= '<tr class="oddeven">';
358 // Name
359 $lastmodified .= '<td class="nowrap tdoverflowmax200">';
360 $lastmodified .= $thirdparty_static->getNomUrl(1);
361 $lastmodified .= "</td>\n";
362 // Type
363 $lastmodified .= '<td class="center">';
364 $lastmodified .= $thirdparty_static->getTypeUrl();
365 $lastmodified .= '</td>';
366 // Last modified date
367 $lastmodified .= '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").' '.dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')).'">';
368 $lastmodified .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel');
369 $lastmodified .= "</td>";
370 $lastmodified .= '<td class="right nowrap">';
371 $lastmodified .= $thirdparty_static->getLibStatut(3);
372 $lastmodified .= "</td>";
373 $lastmodified .= "</tr>\n";
374 $i++;
375 }
376
377 $db->free($result);
378
379 $lastmodified .= "</table>\n";
380 $lastmodified .= '</div>';
381 $lastmodified .= "<!-- End last thirdparties modified -->\n";
382 }
383} else {
384 dol_print_error($db);
385}
386
387//print '</div></div></div>';
388
389// boxes
390print '<div class="clearboth"></div>';
391print '<div class="fichecenter fichecenterbis">';
392
393$boxlist = '<div class="twocolumns">';
394
395$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
396$boxlist .= $thirdpartygraph;
397$boxlist .= '<br>';
398$boxlist .= $thirdpartycateggraph;
399$boxlist .= '<br>';
400$boxlist .= $resultboxes['boxlista'];
401$boxlist .= '</div>'."\n";
402
403$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
404$boxlist .= $lastmodified;
405$boxlist .= '<br>';
406$boxlist .= $resultboxes['boxlistb'];
407$boxlist .= '</div>'."\n";
408
409$boxlist .= '</div>';
410
411print $boxlist;
412
413print '</div>';
414
415$parameters = array('user' => $user);
416$reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
417
418// End of page
419llxFooter();
420$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to build graphs.
Class to manage generation of HTML components Only common components must be here.
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user.
Class to manage hooks.
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
Class to manage third parties objects (customers, suppliers, prospects...)
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.