dolibarr  16.0.5
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 require '../main.inc.php';
31 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
32 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
33 
34 $hookmanager = new HookManager($db);
35 
36 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
37 $hookmanager->initHooks(array('thirdpartiesindex'));
38 
39 $langs->load("companies");
40 
41 $socid = GETPOST('socid', 'int');
42 if ($user->socid) {
43  $socid = $user->socid;
44 }
45 
46 // Security check
47 $result = restrictedArea($user, 'societe', 0, '', '', '', '');
48 
49 $thirdparty_static = new Societe($db);
50 
51 if (!isset($form) || !is_object($form)) {
52  $form = new Form($db);
53 }
54 // Load $resultboxes
55 $resultboxes = FormOther::getBoxesArea($user, "3");
56 
57 if (GETPOST('addbox')) {
58  // Add box (when submit is done from a form when ajax disabled)
59  require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
60  $zone = GETPOST('areacode', 'int');
61  $userid = GETPOST('userid', 'int');
62  $boxorder = GETPOST('boxorder', 'aZ09');
63  $boxorder .= GETPOST('boxcombo', 'aZ09');
64  $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
65  if ($result > 0) {
66  setEventMessages($langs->trans("BoxAdded"), null);
67  }
68 }
69 
70 
71 /*
72  * View
73  */
74 
75 $transAreaType = $langs->trans("ThirdPartiesArea");
76 $helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
77 
78 llxHeader("", $langs->trans("ThirdParties"), $helpurl);
79 
80 print load_fiche_titre($transAreaType, $resultboxes['selectboxlist'], 'companies');
81 
82 
83 /*
84  * Statistics area
85  */
86 
87 $third = array(
88  'customer' => 0,
89  'prospect' => 0,
90  'supplier' => 0,
91  'other' =>0
92 );
93 $total = 0;
94 
95 $sql = "SELECT s.rowid, s.client, s.fournisseur";
96 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
97 if (empty($user->rights->societe->client->voir) && !$socid) {
98  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
99 }
100 $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
101 if (empty($user->rights->societe->client->voir) && !$socid) {
102  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
103 }
104 if (empty($user->rights->fournisseur->lire)) {
105  $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
106 }
107 // Add where from hooks
108 $parameters = array('socid' => $socid);
109 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
110 if (empty($reshook)) {
111  if ($socid > 0) {
112  $sql .= " AND s.rowid = ".((int) $socid);
113  }
114 }
115 $sql .= $hookmanager->resPrint;
116 //print $sql;
117 $result = $db->query($sql);
118 if ($result) {
119  while ($objp = $db->fetch_object($result)) {
120  $found = 0;
121  if (isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) {
122  $found = 1; $third['prospect']++;
123  }
124  if (isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) {
125  $found = 1; $third['customer']++;
126  }
127  if (((isModEnabled('fournisseur') && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled('supplier_order') && $user->rights->supplier_order->lire) || (isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) {
128  $found = 1; $third['supplier']++;
129  }
130  if (isModEnabled('societe') && $objp->client == 0 && $objp->fournisseur == 0) {
131  $found = 1; $third['other']++;
132  }
133  if ($found) {
134  $total++;
135  }
136  }
137 } else {
138  dol_print_error($db);
139 }
140 
141 $thirdpartygraph = '<div class="div-table-responsive-no-min">';
142 $thirdpartygraph .= '<table class="noborder nohover centpercent">'."\n";
143 $thirdpartygraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
144 if (!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)) {
145  $thirdpartygraph .= '<tr><td class="center" colspan="2">';
146  $dataseries = array();
147  if (isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) {
148  $dataseries[] = array($langs->trans("Prospects"), round($third['prospect']));
149  }
150  if (isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) {
151  $dataseries[] = array($langs->trans("Customers"), round($third['customer']));
152  }
153  if (((isModEnabled('fournisseur') && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled('supplier_order') && $user->rights->supplier_order->lire) || (isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) {
154  $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier']));
155  }
156  if (isModEnabled('societe')) {
157  $dataseries[] = array($langs->trans("Others"), round($third['other']));
158  }
159  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
160  $dolgraph = new DolGraph();
161  $dolgraph->SetData($dataseries);
162  $dolgraph->setShowLegend(2);
163  $dolgraph->setShowPercent(1);
164  $dolgraph->SetType(array('pie'));
165  $dolgraph->setHeight('200');
166  $dolgraph->draw('idgraphthirdparties');
167  $thirdpartygraph .= $dolgraph->show();
168  $thirdpartygraph .= '</td></tr>'."\n";
169 } else {
170  if (isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) {
171  $statstring = "<tr>";
172  $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
173  $statstring .= "</tr>";
174  }
175  if (isModEnabled('societe') && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) {
176  $statstring .= "<tr>";
177  $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
178  $statstring .= "</tr>";
179  }
180  $statstring2 = '';
181  if (((isModEnabled('fournisseur') && $user->rights->fournisseur->facture->lire && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled('supplier_order') && $user->rights->supplier_order->lire) || (isModEnabled('supplier_invoice') && $user->rights->supplier_invoice->lire)) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) {
182  $statstring2 = "<tr>";
183  $statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
184  $statstring2 .= "</tr>";
185  }
186  $thirdpartygraph .= $statstring;
187  $thirdpartygraph .= $statstring2;
188 }
189 $thirdpartygraph .= '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td class="right">';
190 $thirdpartygraph .= $total;
191 $thirdpartygraph .= '</td></tr>';
192 $thirdpartygraph .= '</table>';
193 $thirdpartygraph .= '</div>';
194 
195 $thirdpartycateggraph = '';
196 if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
197  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
198  $elementtype = 'societe';
199 
200  $thirdpartycateggraph = '<div class="div-table-responsive-no-min">';
201  $thirdpartycateggraph .= '<table class="noborder nohover centpercent">';
202  $thirdpartycateggraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
203  $thirdpartycateggraph .= '<tr><td class="center" colspan="2">';
204  $sql = "SELECT c.label, count(*) as nb";
205  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
206  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
207  $sql .= " WHERE c.type = 2";
208  if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
209  $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
210  }
211  $sql .= " AND c.entity IN (".getEntity('category').")";
212  $sql .= " GROUP BY c.label";
213  $total = 0;
214  $result = $db->query($sql);
215  if ($result) {
216  $num = $db->num_rows($result);
217  $i = 0;
218  if (!empty($conf->use_javascript_ajax)) {
219  $dataseries = array();
220  $rest = 0;
221  $nbmax = 10;
222 
223  while ($i < $num) {
224  $obj = $db->fetch_object($result);
225  if ($i < $nbmax) {
226  $dataseries[] = array($obj->label, round($obj->nb));
227  } else {
228  $rest += $obj->nb;
229  }
230  $total += $obj->nb;
231  $i++;
232  }
233  if ($i > $nbmax) {
234  $dataseries[] = array($langs->trans("Other"), round($rest));
235  }
236  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
237  $dolgraph = new DolGraph();
238  $dolgraph->SetData($dataseries);
239  $dolgraph->setShowLegend(2);
240  $dolgraph->setShowPercent(1);
241  $dolgraph->SetType(array('pie'));
242  $dolgraph->setHeight('200');
243  $dolgraph->draw('idgraphcateg');
244  $thirdpartycateggraph .= $dolgraph->show();
245  } else {
246  while ($i < $num) {
247  $obj = $db->fetch_object($result);
248 
249  $thirdpartycateggraph .= '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
250  $total += $obj->nb;
251  $i++;
252  }
253  }
254  }
255  $thirdpartycateggraph .= '</td></tr>';
256  $thirdpartycateggraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
257  $thirdpartycateggraph .= $total;
258  $thirdpartycateggraph .= '</td></tr>';
259  $thirdpartycateggraph .= '</table>';
260  $thirdpartycateggraph .= '</div>';
261 } else {
262  $thirdpartycateggraph = '';
263 }
264 
265 
266 /*
267  * Latest modified third parties
268  */
269 $max = 15;
270 $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
271 $sql .= ", s.code_client";
272 $sql .= ", s.code_fournisseur";
273 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
274  $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
275  $sql .= ", spe.accountancy_code_customer as code_compta";
276 } else {
277  $sql .= ", s.code_compta_fournisseur";
278  $sql .= ", s.code_compta";
279 }
280 $sql .= ", s.logo";
281 $sql .= ", s.entity";
282 $sql .= ", s.canvas, s.tms as date_modification, s.status as status";
283 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
284 if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
285  $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
286 }
287 if (empty($user->rights->societe->client->voir) && !$socid) {
288  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
289 }
290 $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
291 if (empty($user->rights->societe->client->voir) && !$socid) {
292  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
293 }
294 if (empty($user->rights->fournisseur->lire)) {
295  $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
296 }
297 // Add where from hooks
298 $parameters = array('socid' => $socid);
299 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
300 if (empty($reshook)) {
301  if ($socid > 0) {
302  $sql .= " AND s.rowid = ".((int) $socid);
303  }
304 }
305 $sql .= $hookmanager->resPrint;
306 $sql .= $db->order("s.tms", "DESC");
307 $sql .= $db->plimit($max, 0);
308 
309 //print $sql;
310 $lastmodified="";
311 $result = $db->query($sql);
312 if ($result) {
313  $num = $db->num_rows($result);
314 
315  $i = 0;
316 
317  if ($num > 0) {
318  $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
319 
320  $lastmodified = "\n<!-- last thirdparties modified -->\n";
321  $lastmodified .= '<div class="div-table-responsive-no-min">';
322  $lastmodified .= '<table class="noborder centpercent">';
323 
324  $lastmodified .= '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
325  $lastmodified .= '<th>&nbsp;</th>';
326  $lastmodified .= '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
327  $lastmodified .= '</tr>'."\n";
328 
329  while ($i < $num) {
330  $objp = $db->fetch_object($result);
331 
332  $thirdparty_static->id = $objp->rowid;
333  $thirdparty_static->name = $objp->name;
334  $thirdparty_static->client = $objp->client;
335  $thirdparty_static->fournisseur = $objp->fournisseur;
336  $thirdparty_static->logo = $objp->logo;
337  $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
338  $thirdparty_static->status = $objp->status;
339  $thirdparty_static->code_client = $objp->code_client;
340  $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
341  $thirdparty_static->canvas = $objp->canvas;
342  $thirdparty_static->email = $objp->email;
343  $thirdparty_static->entity = $objp->entity;
344  $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
345  $thirdparty_static->code_compta = $objp->code_compta;
346 
347  $lastmodified .= '<tr class="oddeven">';
348  // Name
349  $lastmodified .= '<td class="nowrap tdoverflowmax200">';
350  $lastmodified .= $thirdparty_static->getNomUrl(1);
351  $lastmodified .= "</td>\n";
352  // Type
353  $lastmodified .= '<td class="center">';
354  $lastmodified .= $thirdparty_static->getTypeUrl();
355  $lastmodified .= '</td>';
356  // Last modified date
357  $lastmodified .= '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").' '.dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')).'">';
358  $lastmodified .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel');
359  $lastmodified .= "</td>";
360  $lastmodified .= '<td class="right nowrap">';
361  $lastmodified .= $thirdparty_static->getLibStatut(3);
362  $lastmodified .= "</td>";
363  $lastmodified .= "</tr>\n";
364  $i++;
365  }
366 
367  $db->free($result);
368 
369  $lastmodified .= "</table>\n";
370  $lastmodified .= '</div>';
371  $lastmodified .= "<!-- End last thirdparties modified -->\n";
372  }
373 } else {
374  dol_print_error($db);
375 }
376 
377 //print '</div></div></div>';
378 
379 // boxes
380 print '<div class="clearboth"></div>';
381 print '<div class="fichecenter fichecenterbis">';
382 
383 $boxlist = '<div class="twocolumns">';
384 
385 $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
386 $boxlist .= $thirdpartygraph;
387 $boxlist .= '<br>';
388 $boxlist .= $thirdpartycateggraph;
389 $boxlist .= '<br>';
390 $boxlist .= $resultboxes['boxlista'];
391 $boxlist .= '</div>'."\n";
392 
393 $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
394 $boxlist .= $lastmodified;
395 $boxlist .= '<br>';
396 $boxlist .= $resultboxes['boxlistb'];
397 $boxlist .= '</div>'."\n";
398 
399 $boxlist .= '</div>';
400 
401 print $boxlist;
402 
403 print '</div>';
404 
405 $parameters = array('user' => $user);
406 $reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
407 
408 // End of page
409 llxFooter();
410 $db->close();
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:48
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5204
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
DolGraph
Class to build graphs.
Definition: dolgraph.class.php:40
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
InfoBox\saveboxorder
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
Definition: infobox.class.php:224
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
llxFooter
llxFooter()
Footer empty.
Definition: index.php:71
llxHeader
if(!defined('NOTOKENRENEWAL')) if(!defined('NOLOGIN')) if(!defined('NOCSRFCHECK')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) if(!defined('NOIPCHECK')) if(!defined('NOBROWSERNOTIF')) llxHeader()
Header empty.
Definition: index.php:63
isModEnabled
isModEnabled($module)
Is Dolibarr module enabled.
Definition: functions.lib.php:105
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
FormOther\getBoxesArea
static getBoxesArea($user, $areacode)
Get array with HTML tabs with boxes of a particular area including personalized choices of user.
Definition: html.formother.class.php:1173
HookManager
Class to manage hooks.
Definition: hookmanager.class.php:30