32require
'../main.inc.php';
40require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/contact/class/contact.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formother.class.php';
45$langs->load(
"companies");
49$hookmanager->initHooks(array(
'thirdpartiesindex'));
54 $socid = $user->socid;
58$result =
restrictedArea($user,
'societe|contact', 0,
'',
'',
'',
'');
60$thirdparty_static =
new Societe($db);
61$contact_static =
new Contact($db);
63if (!isset($form) || !is_object($form)) {
64 $form =
new Form($db);
71include DOL_DOCUMENT_ROOT.
'/core/actions_addbox.inc.php';
80$transAreaType = $langs->trans(
"ThirdPartiesArea");
81$helpurl =
'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Terceros';
83llxHeader(
"", $langs->trans(
"ThirdParties"), $helpurl);
85print
load_fiche_titre($transAreaType, $resultboxes[
'selectboxlist'],
'companies');
99$sql =
"SELECT s.client, s.fournisseur, COUNT(s.rowid) as nb";
100$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
101if (!$user->hasRight(
'societe',
'client',
'voir')) {
102 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
104$sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
105if (!$user->hasRight(
'societe',
'client',
'voir')) {
106 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
108if (!$user->hasRight(
'fournisseur',
'lire')) {
109 $sql .=
" AND (s.fournisseur <> 1 OR s.client <> 0)";
112$parameters = array(
'socid' => $socid);
113$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
114if (empty($reshook)) {
116 $sql .=
" AND s.rowid = ".((int) $socid);
119$sql .= $hookmanager->resPrint;
120$sql .=
" GROUP BY s.client, s.fournisseur";
122$result = $db->query($sql);
124 while ($objp = $db->fetch_object($result)) {
128 $third[
'prospect'] += $objp->nb;
132 $third[
'customer'] += $objp->nb;
134 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 $third[
'supplier'] += $objp->nb;
138 if (
isModEnabled(
'societe') && $objp->client == 0 && $objp->fournisseur == 0) {
140 $third[
'other'] += $objp->nb;
147 dol_print_error($db);
150$thirdpartygraph =
'<div class="div-table-responsive-no-min">';
151$thirdpartygraph .=
'<table class="noborder nohover centpercent">'.
"\n";
152$thirdpartygraph .=
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Statistics").
' - '.$langs->trans(
"NatureOfThirdParty").
'</th></tr>';
153if (!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)) {
154 $thirdpartygraph .=
'<tr><td class="center" colspan="2">';
155 $dataseries = array();
157 $dataseries[] = array($langs->transnoentitiesnoconv(
"Prospects"), round($third[
'prospect']));
160 $dataseries[] = array($langs->transnoentitiesnoconv(
"Customers"), round($third[
'customer']));
163 $dataseries[] = array($langs->transnoentitiesnoconv(
"Suppliers"), round($third[
'supplier']));
166 $dataseries[] = array($langs->transnoentitiesnoconv(
"Others"), round($third[
'other']));
168 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
170 $dolgraph->SetData($dataseries);
171 $dolgraph->setShowLegend(2);
172 $dolgraph->setShowPercent(1);
173 $dolgraph->SetType(array(
'pie'));
174 $dolgraph->setHeight(
'200');
175 $dolgraph->draw(
'idgraphthirdparties');
176 $thirdpartygraph .= $dolgraph->show();
177 $thirdpartygraph .=
'</td></tr>'.
"\n";
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>";
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>";
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>";
196 $thirdpartygraph .= $statstring;
197 $thirdpartygraph .= $statstring2;
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>';
205$thirdpartycateggraph =
'';
207 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
209 $thirdpartycateggraph =
'<div class="div-table-responsive-no-min">';
210 $thirdpartycateggraph .=
'<table class="noborder nohover centpercent">';
211 $thirdpartycateggraph .=
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Categories").
'</th></tr>';
212 $thirdpartycateggraph .=
'<tr><td class="center" colspan="2">';
213 $sql =
"SELECT c.label, count(*) as nb";
214 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_societe as cs";
215 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie as c ON cs.fk_categorie = c.rowid";
216 $sql .=
" WHERE c.type = 2";
218 $sql .=
" AND c.label like '".$db->escape(
getDolGlobalString(
'CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')).
"'";
220 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
221 $sql .=
" GROUP BY c.label";
223 $result = $db->query($sql);
225 $num = $db->num_rows($result);
227 if (!empty(
$conf->use_javascript_ajax)) {
228 $dataseries = array();
233 $obj = $db->fetch_object($result);
235 $dataseries[] = array($obj->label, round($obj->nb));
243 $dataseries[] = array($langs->trans(
"Other"), round($rest));
245 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
247 $dolgraph->SetData($dataseries);
248 $dolgraph->setShowLegend(2);
249 $dolgraph->setShowPercent(1);
250 $dolgraph->SetType(array(
'pie'));
251 $dolgraph->setHeight(
'200');
252 $dolgraph->draw(
'idgraphcateg');
253 $thirdpartycateggraph .= $dolgraph->show();
256 $obj = $db->fetch_object($result);
258 $thirdpartycateggraph .=
'<tr class="oddeven"><td>'.dolPrintHTML($obj->label).
'</td><td>'.$obj->nb.
'</td></tr>';
264 $thirdpartycateggraph .=
'</td></tr>';
265 $thirdpartycateggraph .=
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">';
266 $thirdpartycateggraph .= $total;
267 $thirdpartycateggraph .=
'</td></tr>';
268 $thirdpartycateggraph .=
'</table>';
269 $thirdpartycateggraph .=
'</div>';
271 $thirdpartycateggraph =
'';
279$sql =
"SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
280$sql .=
", s.code_client";
281$sql .=
", s.code_fournisseur";
283 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
284 $sql .=
", spe.accountancy_code_customer as code_compta";
286 $sql .=
", s.code_compta_fournisseur";
287 $sql .=
", s.code_compta";
291$sql .=
", s.canvas, GREATEST(s.tms, COALESCE(sef.tms, s.tms)) as date_modification, s.status as status";
292$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
293$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as sef ON sef.fk_object=s.rowid";
295 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
298if (!$user->hasRight(
'societe',
'client',
'voir')) {
299 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
301$sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
302if (!$user->hasRight(
'societe',
'client',
'voir')) {
303 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
305if (!$user->hasRight(
'fournisseur',
'lire')) {
306 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
309$parameters = array(
'socid' => $socid);
310$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
311if (empty($reshook)) {
313 $sql .=
" AND s.rowid = ".((int) $socid);
316$sql .= $hookmanager->resPrint;
317$sql .= $db->order(
"date_modification",
"DESC");
318$sql .= $db->plimit($max, 0);
322$result = $db->query($sql);
324 $num = $db->num_rows($result);
329 $transRecordedType = $langs->trans(
"LastModifiedThirdParties", $max);
331 $lastmodified =
"\n<!-- last thirdparties modified -->\n";
332 $lastmodified .=
'<div class="div-table-responsive-no-min">';
333 $lastmodified .=
'<table class="noborder centpercent">';
335 $lastmodified .=
'<tr class="liste_titre"><th colspan="2">';
337 $lastmodified .=
'<span class="valignmiddle">'.$transRecordedType.
'</span>';
338 $lastmodified .=
'<a class="marginleftonlyshort" href="'.DOL_URL_ROOT.
'/societe/list.php?sortfield=s.tms&sortorder=DESC" title="'.$langs->trans(
"FullList").
'">';
339 $lastmodified .=
'<span class="badge marginleftonlyshort">...</span>';
340 $lastmodified .=
'</a>';
341 $lastmodified .=
'</th>';
342 $lastmodified .=
'<th> </th>';
343 $lastmodified .=
'<th class="right">';
344 $lastmodified .=
'</th>';
345 $lastmodified .=
'</tr>'.
"\n";
348 $objp = $db->fetch_object($result);
350 $thirdparty_static->id = $objp->rowid;
351 $thirdparty_static->name = $objp->name;
352 $thirdparty_static->client = $objp->client;
353 $thirdparty_static->fournisseur = $objp->fournisseur;
354 $thirdparty_static->logo = $objp->logo;
355 $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
356 $thirdparty_static->status = $objp->status;
357 $thirdparty_static->code_client = $objp->code_client;
358 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
359 $thirdparty_static->canvas = $objp->canvas;
360 $thirdparty_static->email = $objp->email;
361 $thirdparty_static->entity = $objp->entity;
362 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
363 $thirdparty_static->code_compta_client = $objp->code_compta;
365 $lastmodified .=
'<tr class="oddeven">';
367 $lastmodified .=
'<td class="nowrap tdoverflowmax200">';
368 $lastmodified .= $thirdparty_static->getNomUrl(1);
369 $lastmodified .=
"</td>\n";
371 $lastmodified .=
'<td class="center">';
372 $lastmodified .= $thirdparty_static->getTypeUrl();
373 $lastmodified .=
'</td>';
375 $lastmodified .=
'<td class="right tddate" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
' '.
dol_print_date($thirdparty_static->date_modification,
'dayhour',
'tzuserrel')).
'">';
376 $lastmodified .=
dol_print_date($thirdparty_static->date_modification,
'day',
'tzuserrel');
377 $lastmodified .=
"</td>";
378 $lastmodified .=
'<td class="right nowrap">';
379 $lastmodified .= $thirdparty_static->getLibStatut(3);
380 $lastmodified .=
"</td>";
381 $lastmodified .=
"</tr>\n";
387 $lastmodified .=
"</table>\n";
388 $lastmodified .=
'</div>';
389 $lastmodified .=
"<!-- End last thirdparties modified -->\n";
392 dol_print_error($db);
400$sql =
"SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
401$sql .=
", s.code_client";
402$sql .=
", s.code_fournisseur";
404 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
405 $sql .=
", spe.accountancy_code_customer as code_compta";
407 $sql .=
", s.code_compta_fournisseur";
408 $sql .=
", s.code_compta";
413$sql .=
", s.status as status";
414$sql .=
", GREATEST(sp.tms, COALESCE(spef.tms, sp.tms)) as date_modification, sp.statut as cstatus";
415$sql .=
", sp.rowid as cid, sp.canvas as ccanvas, sp.email as cemail, sp.firstname, sp.lastname";
416$sql .=
", sp.address as caddress, sp.phone as cphone";
417$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
418$sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"socpeople as sp ON sp.fk_soc = s.rowid AND ((sp.fk_user_creat = ".((int) $user->id).
" AND sp.priv = 1) OR sp.priv = 0)";
419$sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople_extrafields as spef ON spef.fk_object = sp.rowid";
421 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
424if (!$user->hasRight(
'societe',
'client',
'voir')) {
425 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
427$sql .=
" WHERE s.entity IN (".getEntity(
'societe').
") ";
428if (!$user->hasRight(
'societe',
'client',
'voir')) {
429 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
431if (!$user->hasRight(
'fournisseur',
'lire')) {
432 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
435$parameters = array(
'socid' => $socid);
436$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
437if (empty($reshook)) {
439 $sql .=
" AND s.rowid = ".((int) $socid);
442$sql .= $hookmanager->resPrint;
443$sql .= $db->order(
"date_modification",
"DESC");
444$sql .= $db->plimit($max, 0);
447$lastmodifiedcontact =
'';
448$result = $db->query($sql);
450 $num = $db->num_rows($result);
455 $transRecordedType = $langs->trans(
"LastModifiedContacts", $max);
457 $lastmodifiedcontact =
"\n<!-- last contacts modified -->\n";
458 $lastmodifiedcontact .=
'<div class="div-table-responsive-no-min">';
459 $lastmodifiedcontact .=
'<table class="noborder centpercent">';
461 $lastmodifiedcontact .=
'<tr class="liste_titre"><th colspan="2">';
463 $lastmodifiedcontact .=
'<span class="valignmiddle">'.$transRecordedType.
'</div>';
464 $lastmodifiedcontact .=
'<a class="marginleftonlyshort" href="'.DOL_URL_ROOT.
'/contact/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans(
"FullList").
'">';
466 $lastmodifiedcontact .=
'<span class="badge marginleftonlyshort">...</span>';
467 $lastmodifiedcontact .=
'</th>';
468 $lastmodifiedcontact .=
'<th> </th>';
469 $lastmodifiedcontact .=
'<th class="right">';
471 $lastmodifiedcontact .=
'</th>';
472 $lastmodifiedcontact .=
'</tr>'.
"\n";
475 $objp = $db->fetch_object($result);
477 $thirdparty_static->id = $objp->rowid;
478 $thirdparty_static->name = $objp->name;
479 $thirdparty_static->client = $objp->client;
480 $thirdparty_static->fournisseur = $objp->fournisseur;
481 $thirdparty_static->logo = $objp->logo;
482 $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
483 $thirdparty_static->status = $objp->status;
484 $thirdparty_static->code_client = $objp->code_client;
485 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
486 $thirdparty_static->canvas = $objp->canvas;
487 $thirdparty_static->email = $objp->email;
488 $thirdparty_static->entity = $objp->entity;
489 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
490 $thirdparty_static->code_compta_client = $objp->code_compta;
492 $contact_static->id = $objp->cid;
493 $contact_static->status = $objp->cstatus;
494 $contact_static->firstname = $objp->firstname;
495 $contact_static->lastname = $objp->lastname;
496 $contact_static->email = $objp->cemail;
497 $contact_static->socid = $objp->rowid;
498 $contact_static->canvas = $objp->ccanvas;
499 $contact_static->phone_pro = $objp->cphone;
500 $contact_static->address = $objp->caddress;
502 $lastmodifiedcontact .=
'<tr class="oddeven">';
504 $lastmodifiedcontact .=
'<td class="tdoverflowmax150">';
505 $lastmodifiedcontact .= $contact_static->getNomUrl(1);
506 $lastmodifiedcontact .=
'</td>';
508 $lastmodifiedcontact .=
'<td class="nowrap tdoverflowmax125">';
509 $lastmodifiedcontact .= $thirdparty_static->getNomUrl(1);
510 $lastmodifiedcontact .=
"</td>\n";
512 $lastmodifiedcontact .=
'<td class="right tddate" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
' '.
dol_print_date($thirdparty_static->date_modification,
'dayhour',
'tzuserrel')).
'">';
513 $lastmodifiedcontact .=
dol_print_date($thirdparty_static->date_modification,
'day',
'tzuserrel');
514 $lastmodifiedcontact .=
"</td>";
515 $lastmodifiedcontact .=
'<td class="right nowrap">';
516 $lastmodifiedcontact .= $thirdparty_static->getLibStatut(3);
517 $lastmodifiedcontact .=
"</td>";
518 $lastmodifiedcontact .=
"</tr>\n";
524 $lastmodifiedcontact .=
"</table>\n";
525 $lastmodifiedcontact .=
'</div>';
526 $lastmodifiedcontact .=
"<!-- End last contacts modified -->\n";
529 dol_print_error($db);
534print
'<div class="clearboth"></div>';
535print
'<div class="fichecenter fichecenterbis">';
537$boxlist =
'<div class="twocolumns">';
539$boxlist .=
'<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
540$boxlist .= $thirdpartygraph;
542$boxlist .= $thirdpartycateggraph;
544$boxlist .= $resultboxes[
'boxlista'];
545$boxlist .=
'</div>'.
"\n";
547$boxlist .=
'<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
548$boxlist .= $lastmodified;
550$boxlist .= $lastmodifiedcontact;
552$boxlist .= $resultboxes[
'boxlistb'];
553$boxlist .=
'</div>'.
"\n";
561$parameters = array(
'user' => $user);
562$reshook = $hookmanager->executeHooks(
'dashboardThirdparties', $parameters, $thirdparty_static);
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage third parties objects (customers, suppliers, prospects...)
getDolUserInt($key, $default=0, $tmpuser=null)
Return Dolibarr user constant int value.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.