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';
37 $hookmanager->initHooks(array(
'thirdpartiesindex'));
39 $langs->load(
"companies");
41 $socid =
GETPOST(
'socid',
'int');
43 $socid = $user->socid;
49 $thirdparty_static =
new Societe($db);
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');
75 $transAreaType = $langs->trans(
"ThirdPartiesArea");
76 $helpurl =
'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Terceros';
78 llxHeader(
"", $langs->trans(
"ThirdParties"), $helpurl);
80 print
load_fiche_titre($transAreaType, $resultboxes[
'selectboxlist'],
'companies');
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";
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);
104 if (empty($user->rights->fournisseur->lire)) {
105 $sql .=
" AND (s.fournisseur <> 1 OR s.client <> 0)";
108 $parameters = array(
'socid' => $socid);
109 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
110 if (empty($reshook)) {
112 $sql .=
" AND s.rowid = ".((int) $socid);
115 $sql .= $hookmanager->resPrint;
117 $result = $db->query($sql);
119 while ($objp = $db->fetch_object($result)) {
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']++;
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']++;
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']++;
130 if (
isModEnabled(
'societe') && $objp->client == 0 && $objp->fournisseur == 0) {
131 $found = 1; $third[
'other']++;
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']));
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']));
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']));
157 $dataseries[] = array($langs->trans(
"Others"), round($third[
'other']));
159 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
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";
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>";
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>";
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>";
186 $thirdpartygraph .= $statstring;
187 $thirdpartygraph .= $statstring2;
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>';
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';
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).
"'";
211 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
212 $sql .=
" GROUP BY c.label";
214 $result = $db->query($sql);
216 $num = $db->num_rows($result);
218 if (!empty($conf->use_javascript_ajax)) {
219 $dataseries = array();
224 $obj = $db->fetch_object($result);
226 $dataseries[] = array($obj->label, round($obj->nb));
234 $dataseries[] = array($langs->trans(
"Other"), round($rest));
236 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
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();
247 $obj = $db->fetch_object($result);
249 $thirdpartycateggraph .=
'<tr class="oddeven"><td>'.$obj->label.
'</td><td>'.$obj->nb.
'</td></tr>';
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>';
262 $thirdpartycateggraph =
'';
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";
277 $sql .=
", s.code_compta_fournisseur";
278 $sql .=
", s.code_compta";
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);
287 if (empty($user->rights->societe->client->voir) && !$socid) {
288 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
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);
294 if (empty($user->rights->fournisseur->lire)) {
295 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
298 $parameters = array(
'socid' => $socid);
299 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
300 if (empty($reshook)) {
302 $sql .=
" AND s.rowid = ".((int) $socid);
305 $sql .= $hookmanager->resPrint;
306 $sql .= $db->order(
"s.tms",
"DESC");
307 $sql .= $db->plimit($max, 0);
311 $result = $db->query($sql);
313 $num = $db->num_rows($result);
318 $transRecordedType = $langs->trans(
"LastModifiedThirdParties", $max);
320 $lastmodified =
"\n<!-- last thirdparties modified -->\n";
321 $lastmodified .=
'<div class="div-table-responsive-no-min">';
322 $lastmodified .=
'<table class="noborder centpercent">';
324 $lastmodified .=
'<tr class="liste_titre"><th colspan="2">'.$transRecordedType.
'</th>';
325 $lastmodified .=
'<th> </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";
330 $objp = $db->fetch_object($result);
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;
347 $lastmodified .=
'<tr class="oddeven">';
349 $lastmodified .=
'<td class="nowrap tdoverflowmax200">';
350 $lastmodified .= $thirdparty_static->getNomUrl(1);
351 $lastmodified .=
"</td>\n";
353 $lastmodified .=
'<td class="center">';
354 $lastmodified .= $thirdparty_static->getTypeUrl();
355 $lastmodified .=
'</td>';
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";
369 $lastmodified .=
"</table>\n";
370 $lastmodified .=
'</div>';
371 $lastmodified .=
"<!-- End last thirdparties modified -->\n";
380 print
'<div class="clearboth"></div>';
381 print
'<div class="fichecenter fichecenterbis">';
383 $boxlist =
'<div class="twocolumns">';
385 $boxlist .=
'<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
386 $boxlist .= $thirdpartygraph;
388 $boxlist .= $thirdpartycateggraph;
390 $boxlist .= $resultboxes[
'boxlista'];
391 $boxlist .=
'</div>'.
"\n";
393 $boxlist .=
'<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
394 $boxlist .= $lastmodified;
396 $boxlist .= $resultboxes[
'boxlistb'];
397 $boxlist .=
'</div>'.
"\n";
399 $boxlist .=
'</div>';
405 $parameters = array(
'user' => $user);
406 $reshook = $hookmanager->executeHooks(
'dashboardThirdparties', $parameters, $thirdparty_static);