dolibarr 18.0.6
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 (empty($user->rights->societe->client->voir) && !$socid) {
104 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
105}
106$sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
107if (empty($user->rights->societe->client->voir) && !$socid) {
108 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
109}
110if (empty($user->rights->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') && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) {
128 $found = 1; $third['prospect']++;
129 }
130 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) {
131 $found = 1; $third['customer']++;
132 }
133 if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) {
134 $found = 1; $third['supplier']++;
135 }
136 if (isModEnabled('societe') && $objp->client == 0 && $objp->fournisseur == 0) {
137 $found = 1; $third['other']++;
138 }
139 if ($found) {
140 $total++;
141 }
142 }
143} else {
144 dol_print_error($db);
145}
146
147$thirdpartygraph = '<div class="div-table-responsive-no-min">';
148$thirdpartygraph .= '<table class="noborder nohover centpercent">'."\n";
149$thirdpartygraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
150if (!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)) {
151 $thirdpartygraph .= '<tr><td class="center" colspan="2">';
152 $dataseries = array();
153 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) {
154 $dataseries[] = array($langs->transnoentitiesnoconv("Prospects"), round($third['prospect']));
155 }
156 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) {
157 $dataseries[] = array($langs->transnoentitiesnoconv("Customers"), round($third['customer']));
158 }
159 if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) {
160 $dataseries[] = array($langs->transnoentitiesnoconv("Suppliers"), round($third['supplier']));
161 }
162 if (isModEnabled('societe')) {
163 $dataseries[] = array($langs->transnoentitiesnoconv("Others"), round($third['other']));
164 }
165 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
166 $dolgraph = new DolGraph();
167 $dolgraph->SetData($dataseries);
168 $dolgraph->setShowLegend(2);
169 $dolgraph->setShowPercent(1);
170 $dolgraph->SetType(array('pie'));
171 $dolgraph->setHeight('200');
172 $dolgraph->draw('idgraphthirdparties');
173 $thirdpartygraph .= $dolgraph->show();
174 $thirdpartygraph .= '</td></tr>'."\n";
175} else {
176 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) {
177 $statstring = "<tr>";
178 $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
179 $statstring .= "</tr>";
180 }
181 if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) {
182 $statstring .= "<tr>";
183 $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
184 $statstring .= "</tr>";
185 }
186 $statstring2 = '';
187 if (((isModEnabled('fournisseur') && $user->hasRight('fournisseur', 'facture', 'lire') && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || (isModEnabled('supplier_order') && $user->hasRight('supplier_order', 'lire')) || (isModEnabled('supplier_invoice') && $user->hasRight('supplier_invoice', 'lire'))) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) {
188 $statstring2 = "<tr>";
189 $statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
190 $statstring2 .= "</tr>";
191 }
192 $thirdpartygraph .= $statstring;
193 $thirdpartygraph .= $statstring2;
194}
195$thirdpartygraph .= '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td class="right">';
196$thirdpartygraph .= $total;
197$thirdpartygraph .= '</td></tr>';
198$thirdpartygraph .= '</table>';
199$thirdpartygraph .= '</div>';
200
201$thirdpartycateggraph = '';
202if (isModEnabled('categorie') && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
203 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
204 $elementtype = 'societe';
205
206 $thirdpartycateggraph = '<div class="div-table-responsive-no-min">';
207 $thirdpartycateggraph .= '<table class="noborder nohover centpercent">';
208 $thirdpartycateggraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
209 $thirdpartycateggraph .= '<tr><td class="center" colspan="2">';
210 $sql = "SELECT c.label, count(*) as nb";
211 $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
212 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
213 $sql .= " WHERE c.type = 2";
214 if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
215 $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
216 }
217 $sql .= " AND c.entity IN (".getEntity('category').")";
218 $sql .= " GROUP BY c.label";
219 $total = 0;
220 $result = $db->query($sql);
221 if ($result) {
222 $num = $db->num_rows($result);
223 $i = 0;
224 if (!empty($conf->use_javascript_ajax)) {
225 $dataseries = array();
226 $rest = 0;
227 $nbmax = 10;
228
229 while ($i < $num) {
230 $obj = $db->fetch_object($result);
231 if ($i < $nbmax) {
232 $dataseries[] = array($obj->label, round($obj->nb));
233 } else {
234 $rest += $obj->nb;
235 }
236 $total += $obj->nb;
237 $i++;
238 }
239 if ($i > $nbmax) {
240 $dataseries[] = array($langs->trans("Other"), round($rest));
241 }
242 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
243 $dolgraph = new DolGraph();
244 $dolgraph->SetData($dataseries);
245 $dolgraph->setShowLegend(2);
246 $dolgraph->setShowPercent(1);
247 $dolgraph->SetType(array('pie'));
248 $dolgraph->setHeight('200');
249 $dolgraph->draw('idgraphcateg');
250 $thirdpartycateggraph .= $dolgraph->show();
251 } else {
252 while ($i < $num) {
253 $obj = $db->fetch_object($result);
254
255 $thirdpartycateggraph .= '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
256 $total += $obj->nb;
257 $i++;
258 }
259 }
260 }
261 $thirdpartycateggraph .= '</td></tr>';
262 $thirdpartycateggraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
263 $thirdpartycateggraph .= $total;
264 $thirdpartycateggraph .= '</td></tr>';
265 $thirdpartycateggraph .= '</table>';
266 $thirdpartycateggraph .= '</div>';
267} else {
268 $thirdpartycateggraph = '';
269}
270
271
272/*
273 * Latest modified third parties
274 */
275$max = 15;
276$sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
277$sql .= ", s.code_client";
278$sql .= ", s.code_fournisseur";
279if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
280 $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
281 $sql .= ", spe.accountancy_code_customer as code_compta";
282} else {
283 $sql .= ", s.code_compta_fournisseur";
284 $sql .= ", s.code_compta";
285}
286$sql .= ", s.logo";
287$sql .= ", s.entity";
288$sql .= ", s.canvas, s.tms as date_modification, s.status as status";
289$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
290if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) {
291 $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
292}
293if (empty($user->rights->societe->client->voir) && !$socid) {
294 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
295}
296$sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
297if (empty($user->rights->societe->client->voir) && !$socid) {
298 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
299}
300if (empty($user->rights->fournisseur->lire)) {
301 $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
302}
303// Add where from hooks
304$parameters = array('socid' => $socid);
305$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
306if (empty($reshook)) {
307 if ($socid > 0) {
308 $sql .= " AND s.rowid = ".((int) $socid);
309 }
310}
311$sql .= $hookmanager->resPrint;
312$sql .= $db->order("s.tms", "DESC");
313$sql .= $db->plimit($max, 0);
314
315//print $sql;
316$lastmodified="";
317$result = $db->query($sql);
318if ($result) {
319 $num = $db->num_rows($result);
320
321 $i = 0;
322
323 if ($num > 0) {
324 $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
325
326 $lastmodified = "\n<!-- last thirdparties modified -->\n";
327 $lastmodified .= '<div class="div-table-responsive-no-min">';
328 $lastmodified .= '<table class="noborder centpercent">';
329
330 $lastmodified .= '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
331 $lastmodified .= '<th>&nbsp;</th>';
332 $lastmodified .= '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
333 $lastmodified .= '</tr>'."\n";
334
335 while ($i < $num) {
336 $objp = $db->fetch_object($result);
337
338 $thirdparty_static->id = $objp->rowid;
339 $thirdparty_static->name = $objp->name;
340 $thirdparty_static->client = $objp->client;
341 $thirdparty_static->fournisseur = $objp->fournisseur;
342 $thirdparty_static->logo = $objp->logo;
343 $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
344 $thirdparty_static->status = $objp->status;
345 $thirdparty_static->code_client = $objp->code_client;
346 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
347 $thirdparty_static->canvas = $objp->canvas;
348 $thirdparty_static->email = $objp->email;
349 $thirdparty_static->entity = $objp->entity;
350 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
351 $thirdparty_static->code_compta = $objp->code_compta;
352
353 $lastmodified .= '<tr class="oddeven">';
354 // Name
355 $lastmodified .= '<td class="nowrap tdoverflowmax200">';
356 $lastmodified .= $thirdparty_static->getNomUrl(1);
357 $lastmodified .= "</td>\n";
358 // Type
359 $lastmodified .= '<td class="center">';
360 $lastmodified .= $thirdparty_static->getTypeUrl();
361 $lastmodified .= '</td>';
362 // Last modified date
363 $lastmodified .= '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").' '.dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')).'">';
364 $lastmodified .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel');
365 $lastmodified .= "</td>";
366 $lastmodified .= '<td class="right nowrap">';
367 $lastmodified .= $thirdparty_static->getLibStatut(3);
368 $lastmodified .= "</td>";
369 $lastmodified .= "</tr>\n";
370 $i++;
371 }
372
373 $db->free($result);
374
375 $lastmodified .= "</table>\n";
376 $lastmodified .= '</div>';
377 $lastmodified .= "<!-- End last thirdparties modified -->\n";
378 }
379} else {
380 dol_print_error($db);
381}
382
383//print '</div></div></div>';
384
385// boxes
386print '<div class="clearboth"></div>';
387print '<div class="fichecenter fichecenterbis">';
388
389$boxlist = '<div class="twocolumns">';
390
391$boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
392$boxlist .= $thirdpartygraph;
393$boxlist .= '<br>';
394$boxlist .= $thirdpartycateggraph;
395$boxlist .= '<br>';
396$boxlist .= $resultboxes['boxlista'];
397$boxlist .= '</div>'."\n";
398
399$boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
400$boxlist .= $lastmodified;
401$boxlist .= '<br>';
402$boxlist .= $resultboxes['boxlistb'];
403$boxlist .= '</div>'."\n";
404
405$boxlist .= '</div>';
406
407print $boxlist;
408
409print '</div>';
410
411$parameters = array('user' => $user);
412$reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
413
414// End of page
415llxFooter();
416$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:56
llxFooter()
Empty footer.
Definition wrapper.php:70
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.
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.