dolibarr  13.0.2
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 Charles-Fr Benke <charles.fr@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 
33 $hookmanager = new HookManager($db);
34 
35 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
36 $hookmanager->initHooks(array('thirdpartiesindex'));
37 
38 $langs->load("companies");
39 
40 $socid = GETPOST('socid', 'int');
41 if ($user->socid) $socid = $user->socid;
42 
43 // Security check
44 $result = restrictedArea($user, 'societe', 0, '', '', '', '');
45 
46 $thirdparty_static = new Societe($db);
47 
48 
49 /*
50  * View
51  */
52 
53 $transAreaType = $langs->trans("ThirdPartiesArea");
54 $helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
55 
56 llxHeader("", $langs->trans("ThirdParties"), $helpurl);
57 $linkback = '';
58 print load_fiche_titre($transAreaType, $linkback, 'companies');
59 
60 
61 print '<div class="fichecenter"><div class="fichethirdleft">';
62 
63 
64 /*
65  * Statistics area
66  */
67 
68 $third = array(
69  'customer' => 0,
70  'prospect' => 0,
71  'supplier' => 0,
72  'other' =>0
73 );
74 $total = 0;
75 
76 $sql = "SELECT s.rowid, s.client, s.fournisseur";
77 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
78 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
79 $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
80 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
81 if ($socid) $sql .= " AND s.rowid = ".$socid;
82 if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
83 //print $sql;
84 $result = $db->query($sql);
85 if ($result)
86 {
87  while ($objp = $db->fetch_object($result))
88  {
89  $found = 0;
90  if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) { $found = 1; $third['prospect']++; }
91  if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) { $found = 1; $third['customer']++; }
92  if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) { $found = 1; $third['supplier']++; }
93  if (!empty($conf->societe->enabled) && $objp->client == 0 && $objp->fournisseur == 0) { $found = 1; $third['other']++; }
94  if ($found) $total++;
95  }
96 } else dol_print_error($db);
97 
98 print '<div class="div-table-responsive-no-min">';
99 print '<table class="noborder nohover centpercent">'."\n";
100 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
101 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))
102 {
103  print '<tr><td class="center" colspan="2">';
104  $dataseries = array();
105  if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[] = array($langs->trans("Prospects"), round($third['prospect']));
106  if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[] = array($langs->trans("Customers"), round($third['customer']));
107  if (!empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[] = array($langs->trans("Suppliers"), round($third['supplier']));
108  if (!empty($conf->societe->enabled)) $dataseries[] = array($langs->trans("Others"), round($third['other']));
109  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
110  $dolgraph = new DolGraph();
111  $dolgraph->SetData($dataseries);
112  $dolgraph->setShowLegend(2);
113  $dolgraph->setShowPercent(1);
114  $dolgraph->SetType(array('pie'));
115  $dolgraph->setHeight('200');
116  $dolgraph->draw('idgraphthirdparties');
117  print $dolgraph->show();
118  print '</td></tr>'."\n";
119 } else {
120  if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS))
121  {
122  $statstring = "<tr>";
123  $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
124  $statstring .= "</tr>";
125  }
126  if (!empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS))
127  {
128  $statstring .= "<tr>";
129  $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
130  $statstring .= "</tr>";
131  }
132  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $user->rights->fournisseur->lire)
133  {
134  $statstring2 = "<tr>";
135  $statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
136  $statstring2 .= "</tr>";
137  }
138  print $statstring;
139  print $statstring2;
140 }
141 print '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td class="right">';
142 print $total;
143 print '</td></tr>';
144 print '</table>';
145 print '</div>';
146 
147 if (!empty($conf->categorie->enabled) && !empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES))
148 {
149  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
150  $elementtype = 'societe';
151 
152  print '<br>';
153 
154  print '<div class="div-table-responsive-no-min">';
155  print '<table class="noborder nohover centpercent">';
156  print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
157  print '<tr><td class="center" colspan="2">';
158  $sql = "SELECT c.label, count(*) as nb";
159  $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
160  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
161  $sql .= " WHERE c.type = 2";
162  if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
163  $sql .= " AND c.entity IN (".getEntity('category').")";
164  $sql .= " GROUP BY c.label";
165  $total = 0;
166  $result = $db->query($sql);
167  if ($result)
168  {
169  $num = $db->num_rows($result);
170  $i = 0;
171  if (!empty($conf->use_javascript_ajax))
172  {
173  $dataseries = array();
174  $rest = 0;
175  $nbmax = 10;
176 
177  while ($i < $num)
178  {
179  $obj = $db->fetch_object($result);
180  if ($i < $nbmax)
181  {
182  $dataseries[] = array($obj->label, round($obj->nb));
183  } else {
184  $rest += $obj->nb;
185  }
186  $total += $obj->nb;
187  $i++;
188  }
189  if ($i > $nbmax)
190  {
191  $dataseries[] = array($langs->trans("Other"), round($rest));
192  }
193  include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
194  $dolgraph = new DolGraph();
195  $dolgraph->SetData($dataseries);
196  $dolgraph->setShowLegend(2);
197  $dolgraph->setShowPercent(1);
198  $dolgraph->SetType(array('pie'));
199  $dolgraph->setHeight('200');
200  $dolgraph->draw('idgraphcateg');
201  print $dolgraph->show();
202  } else {
203  while ($i < $num)
204  {
205  $obj = $db->fetch_object($result);
206 
207  print '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
208  $total += $obj->nb;
209  $i++;
210  }
211  }
212  }
213  print '</td></tr>';
214  print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
215  print $total;
216  print '</td></tr>';
217  print '</table>';
218  print '</div>';
219 }
220 
221 print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
222 
223 
224 /*
225  * Latest modified third parties
226  */
227 $max = 15;
228 $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
229 $sql .= ", s.code_client";
230 $sql .= ", s.code_fournisseur";
231 $sql .= ", s.code_compta_fournisseur";
232 $sql .= ", s.code_compta";
233 $sql .= ", s.logo";
234 $sql .= ", s.entity";
235 $sql .= ", s.canvas, s.tms as date_modification, s.status as status";
236 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
237 if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
238 $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
239 if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
240 if ($socid) $sql .= " AND s.rowid = ".$socid;
241 if (!$user->rights->fournisseur->lire) $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
242 $sql .= $db->order("s.tms", "DESC");
243 $sql .= $db->plimit($max, 0);
244 
245 //print $sql;
246 $result = $db->query($sql);
247 if ($result)
248 {
249  $num = $db->num_rows($result);
250 
251  $i = 0;
252 
253  if ($num > 0)
254  {
255  $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
256 
257  print "\n<!-- last thirdparties modified -->\n";
258  print '<div class="div-table-responsive-no-min">';
259  print '<table class="noborder centpercent">';
260 
261  print '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
262  print '<th>&nbsp;</th>';
263  print '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
264  print '</tr>'."\n";
265 
266  while ($i < $num)
267  {
268  $objp = $db->fetch_object($result);
269 
270  $thirdparty_static->id = $objp->rowid;
271  $thirdparty_static->name = $objp->name;
272  $thirdparty_static->client = $objp->client;
273  $thirdparty_static->fournisseur = $objp->fournisseur;
274  $thirdparty_static->logo = $objp->logo;
275  $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
276  $thirdparty_static->status = $objp->status;
277  $thirdparty_static->code_client = $objp->code_client;
278  $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
279  $thirdparty_static->canvas = $objp->canvas;
280  $thirdparty_static->email = $objp->email;
281  $thirdparty_static->entity = $objp->entity;
282  $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
283  $thirdparty_static->code_compta = $objp->code_compta;
284 
285  print '<tr class="oddeven">';
286  // Name
287  print '<td class="nowrap tdoverflowmax200">';
288  print $thirdparty_static->getNomUrl(1);
289  print "</td>\n";
290  // Type
291  print '<td class="center">';
292  $obj = $thirdparty_static;
293  $s = '';
294  if (($obj->client == 2 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
295  {
296  $s .= '<a class="customer-back opacitymedium" title="'.$langs->trans("Prospect").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$thirdparty_static->id.'">'.dol_substr($langs->trans("Prospect"), 0, 1).'</a>';
297  }
298  if (($obj->client == 1 || $obj->client == 3) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))
299  {
300  $s .= '<a class="customer-back" title="'.$langs->trans("Customer").'" href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$thirdparty_static->id.'">'.dol_substr($langs->trans("Customer"), 0, 1).'</a>';
301  }
302  if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled)) && $obj->fournisseur)
303  {
304  $s .= '<a class="vendor-back" title="'.$langs->trans("Supplier").'" href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$thirdparty_static->id.'">'.dol_substr($langs->trans("Supplier"), 0, 1).'</a>';
305  }
306  print $s;
307  print '</td>';
308  // Last modified date
309  print '<td class="right tddate">';
310  print dol_print_date($thirdparty_static->date_modification, 'day');
311  print "</td>";
312  print '<td class="right nowrap">';
313  print $thirdparty_static->getLibStatut(3);
314  print "</td>";
315  print "</tr>\n";
316  $i++;
317  }
318 
319  $db->free($result);
320 
321  print "</table>\n";
322  print '</div>';
323  print "<!-- End last thirdparties modified -->\n";
324  }
325 } else {
326  dol_print_error($db);
327 }
328 
329 print '</div></div></div>';
330 
331 $parameters = array('user' => $user);
332 $reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $object); // Note that $action and $object may have been modified by hook
333 
334 // End of page
335 llxFooter();
336 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_substr($string, $start, $length, $stringencoding= '', $trunconbytes=0)
Make a substring.
llxHeader()
Empty header.
Definition: wrapper.php:45
Class to manage hooks.
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.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to build graphs.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
llxFooter()
Empty footer.
Definition: wrapper.php:59