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');
98$sql =
"SELECT s.rowid, s.client, s.fournisseur";
99$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
100if (!$user->hasRight(
'societe',
'client',
'voir')) {
101 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
103$sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
104if (!$user->hasRight(
'societe',
'client',
'voir')) {
105 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
107if (!$user->hasRight(
'fournisseur',
'lire')) {
108 $sql .=
" AND (s.fournisseur <> 1 OR s.client <> 0)";
111$parameters = array(
'socid' => $socid);
112$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
113if (empty($reshook)) {
115 $sql .=
" AND s.rowid = ".((int) $socid);
118$sql .= $hookmanager->resPrint;
120$result = $db->query($sql);
122 while ($objp = $db->fetch_object($result)) {
126 $third[
'prospect']++;
130 $third[
'customer']++;
132 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) {
134 $third[
'supplier']++;
136 if (
isModEnabled(
'societe') && $objp->client == 0 && $objp->fournisseur == 0) {
145 dol_print_error($db);
148$thirdpartygraph =
'<div class="div-table-responsive-no-min">';
149$thirdpartygraph .=
'<table class="noborder nohover centpercent">'.
"\n";
150$thirdpartygraph .=
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Statistics").
' - '.$langs->trans(
"NatureOfThirdParty").
'</th></tr>';
151if (!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)) {
152 $thirdpartygraph .=
'<tr><td class="center" colspan="2">';
153 $dataseries = array();
155 $dataseries[] = array($langs->transnoentitiesnoconv(
"Prospects"), round($third[
'prospect']));
158 $dataseries[] = array($langs->transnoentitiesnoconv(
"Customers"), round($third[
'customer']));
161 $dataseries[] = array($langs->transnoentitiesnoconv(
"Suppliers"), round($third[
'supplier']));
164 $dataseries[] = array($langs->transnoentitiesnoconv(
"Others"), round($third[
'other']));
166 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
168 $dolgraph->SetData($dataseries);
169 $dolgraph->setShowLegend(2);
170 $dolgraph->setShowPercent(1);
171 $dolgraph->SetType(array(
'pie'));
172 $dolgraph->setHeight(
'200');
173 $dolgraph->draw(
'idgraphthirdparties');
174 $thirdpartygraph .= $dolgraph->show();
175 $thirdpartygraph .=
'</td></tr>'.
"\n";
179 $statstring .=
"<tr>";
180 $statstring .=
'<td><a href="'.DOL_URL_ROOT.
'/societe/list.php?type=p">'.$langs->trans(
"Prospects").
'</a></td><td class="right">'.round($third[
'prospect']).
'</td>';
181 $statstring .=
"</tr>";
184 $statstring .=
"<tr>";
185 $statstring .=
'<td><a href="'.DOL_URL_ROOT.
'/societe/list.php?type=c">'.$langs->trans(
"Customers").
'</a></td><td class="right">'.round($third[
'customer']).
'</td>';
186 $statstring .=
"</tr>";
190 $statstring2 .=
"<tr>";
191 $statstring2 .=
'<td><a href="'.DOL_URL_ROOT.
'/societe/list.php?type=f">'.$langs->trans(
"Suppliers").
'</a></td><td class="right">'.round($third[
'supplier']).
'</td>';
192 $statstring2 .=
"</tr>";
194 $thirdpartygraph .= $statstring;
195 $thirdpartygraph .= $statstring2;
197$thirdpartygraph .=
'<tr class="liste_total"><td>'.$langs->trans(
"UniqueThirdParties").
'</td><td class="right">';
198$thirdpartygraph .= $total;
199$thirdpartygraph .=
'</td></tr>';
200$thirdpartygraph .=
'</table>';
201$thirdpartygraph .=
'</div>';
203$thirdpartycateggraph =
'';
205 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
207 $thirdpartycateggraph =
'<div class="div-table-responsive-no-min">';
208 $thirdpartycateggraph .=
'<table class="noborder nohover centpercent">';
209 $thirdpartycateggraph .=
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Categories").
'</th></tr>';
210 $thirdpartycateggraph .=
'<tr><td class="center" colspan="2">';
211 $sql =
"SELECT c.label, count(*) as nb";
212 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_societe as cs";
213 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie as c ON cs.fk_categorie = c.rowid";
214 $sql .=
" WHERE c.type = 2";
216 $sql .=
" AND c.label like '".$db->escape(
getDolGlobalString(
'CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')).
"'";
218 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
219 $sql .=
" GROUP BY c.label";
221 $result = $db->query($sql);
223 $num = $db->num_rows($result);
225 if (!empty(
$conf->use_javascript_ajax)) {
226 $dataseries = array();
231 $obj = $db->fetch_object($result);
233 $dataseries[] = array($obj->label, round($obj->nb));
241 $dataseries[] = array($langs->trans(
"Other"), round($rest));
243 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
245 $dolgraph->SetData($dataseries);
246 $dolgraph->setShowLegend(2);
247 $dolgraph->setShowPercent(1);
248 $dolgraph->SetType(array(
'pie'));
249 $dolgraph->setHeight(
'200');
250 $dolgraph->draw(
'idgraphcateg');
251 $thirdpartycateggraph .= $dolgraph->show();
254 $obj = $db->fetch_object($result);
256 $thirdpartycateggraph .=
'<tr class="oddeven"><td>'.dolPrintHTML($obj->label).
'</td><td>'.$obj->nb.
'</td></tr>';
262 $thirdpartycateggraph .=
'</td></tr>';
263 $thirdpartycateggraph .=
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">';
264 $thirdpartycateggraph .= $total;
265 $thirdpartycateggraph .=
'</td></tr>';
266 $thirdpartycateggraph .=
'</table>';
267 $thirdpartycateggraph .=
'</div>';
269 $thirdpartycateggraph =
'';
277$sql =
"SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
278$sql .=
", s.code_client";
279$sql .=
", s.code_fournisseur";
281 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
282 $sql .=
", spe.accountancy_code_customer as code_compta";
284 $sql .=
", s.code_compta_fournisseur";
285 $sql .=
", s.code_compta";
289$sql .=
", s.canvas, GREATEST(s.tms, sef.tms) as date_modification, s.status as status";
290$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
291$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as sef ON sef.fk_object=s.rowid";
293 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
296if (!$user->hasRight(
'societe',
'client',
'voir')) {
297 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
299$sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
300if (!$user->hasRight(
'societe',
'client',
'voir')) {
301 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
303if (!$user->hasRight(
'fournisseur',
'lire')) {
304 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
307$parameters = array(
'socid' => $socid);
308$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
309if (empty($reshook)) {
311 $sql .=
" AND s.rowid = ".((int) $socid);
314$sql .= $hookmanager->resPrint;
315$sql .= $db->order(
"date_modification",
"DESC");
316$sql .= $db->plimit($max, 0);
320$result = $db->query($sql);
322 $num = $db->num_rows($result);
327 $transRecordedType = $langs->trans(
"LastModifiedThirdParties", $max);
329 $lastmodified =
"\n<!-- last thirdparties modified -->\n";
330 $lastmodified .=
'<div class="div-table-responsive-no-min">';
331 $lastmodified .=
'<table class="noborder centpercent">';
333 $lastmodified .=
'<tr class="liste_titre"><th colspan="2">';
335 $lastmodified .=
'<span class="valignmiddle">'.$transRecordedType.
'</span>';
336 $lastmodified .=
'<a class="marginleftonlyshort" href="'.DOL_URL_ROOT.
'/societe/list.php?sortfield=s.tms&sortorder=DESC" title="'.$langs->trans(
"FullList").
'">';
337 $lastmodified .=
'<span class="badge marginleftonlyshort">...</span>';
338 $lastmodified .=
'</a>';
339 $lastmodified .=
'</th>';
340 $lastmodified .=
'<th> </th>';
341 $lastmodified .=
'<th class="right">';
342 $lastmodified .=
'</th>';
343 $lastmodified .=
'</tr>'.
"\n";
346 $objp = $db->fetch_object($result);
348 $thirdparty_static->id = $objp->rowid;
349 $thirdparty_static->name = $objp->name;
350 $thirdparty_static->client = $objp->client;
351 $thirdparty_static->fournisseur = $objp->fournisseur;
352 $thirdparty_static->logo = $objp->logo;
353 $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
354 $thirdparty_static->status = $objp->status;
355 $thirdparty_static->code_client = $objp->code_client;
356 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
357 $thirdparty_static->canvas = $objp->canvas;
358 $thirdparty_static->email = $objp->email;
359 $thirdparty_static->entity = $objp->entity;
360 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
361 $thirdparty_static->code_compta_client = $objp->code_compta;
363 $lastmodified .=
'<tr class="oddeven">';
365 $lastmodified .=
'<td class="nowrap tdoverflowmax200">';
366 $lastmodified .= $thirdparty_static->getNomUrl(1);
367 $lastmodified .=
"</td>\n";
369 $lastmodified .=
'<td class="center">';
370 $lastmodified .= $thirdparty_static->getTypeUrl();
371 $lastmodified .=
'</td>';
373 $lastmodified .=
'<td class="right tddate" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
' '.
dol_print_date($thirdparty_static->date_modification,
'dayhour',
'tzuserrel')).
'">';
374 $lastmodified .=
dol_print_date($thirdparty_static->date_modification,
'day',
'tzuserrel');
375 $lastmodified .=
"</td>";
376 $lastmodified .=
'<td class="right nowrap">';
377 $lastmodified .= $thirdparty_static->getLibStatut(3);
378 $lastmodified .=
"</td>";
379 $lastmodified .=
"</tr>\n";
385 $lastmodified .=
"</table>\n";
386 $lastmodified .=
'</div>';
387 $lastmodified .=
"<!-- End last thirdparties modified -->\n";
390 dol_print_error($db);
398$sql =
"SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
399$sql .=
", s.code_client";
400$sql .=
", s.code_fournisseur";
402 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
403 $sql .=
", spe.accountancy_code_customer as code_compta";
405 $sql .=
", s.code_compta_fournisseur";
406 $sql .=
", s.code_compta";
411$sql .=
", s.status as status";
412$sql .=
", GREATEST(sp.tms, spef.tms) as date_modification, sp.statut as cstatus";
413$sql .=
", sp.rowid as cid, sp.canvas as ccanvas, sp.email as cemail, sp.firstname, sp.lastname";
414$sql .=
", sp.address as caddress, sp.phone as cphone";
415$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
416$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)";
417$sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople_extrafields as spef ON spef.fk_object = sp.rowid";
419 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
422if (!$user->hasRight(
'societe',
'client',
'voir')) {
423 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
425$sql .=
" WHERE s.entity IN (".getEntity(
'societe').
") ";
426if (!$user->hasRight(
'societe',
'client',
'voir')) {
427 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
429if (!$user->hasRight(
'fournisseur',
'lire')) {
430 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
433$parameters = array(
'socid' => $socid);
434$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
435if (empty($reshook)) {
437 $sql .=
" AND s.rowid = ".((int) $socid);
440$sql .= $hookmanager->resPrint;
441$sql .= $db->order(
"date_modification",
"DESC");
442$sql .= $db->plimit($max, 0);
445$lastmodifiedcontact =
'';
446$result = $db->query($sql);
448 $num = $db->num_rows($result);
453 $transRecordedType = $langs->trans(
"LastModifiedContacts", $max);
455 $lastmodifiedcontact =
"\n<!-- last contacts modified -->\n";
456 $lastmodifiedcontact .=
'<div class="div-table-responsive-no-min">';
457 $lastmodifiedcontact .=
'<table class="noborder centpercent">';
459 $lastmodifiedcontact .=
'<tr class="liste_titre"><th colspan="2">';
461 $lastmodifiedcontact .=
'<span class="valignmiddle">'.$transRecordedType.
'</div>';
462 $lastmodifiedcontact .=
'<a class="marginleftonlyshort" href="'.DOL_URL_ROOT.
'/contact/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans(
"FullList").
'">';
464 $lastmodifiedcontact .=
'<span class="badge marginleftonlyshort">...</span>';
465 $lastmodifiedcontact .=
'</th>';
466 $lastmodifiedcontact .=
'<th> </th>';
467 $lastmodifiedcontact .=
'<th class="right">';
469 $lastmodifiedcontact .=
'</th>';
470 $lastmodifiedcontact .=
'</tr>'.
"\n";
473 $objp = $db->fetch_object($result);
475 $thirdparty_static->id = $objp->rowid;
476 $thirdparty_static->name = $objp->name;
477 $thirdparty_static->client = $objp->client;
478 $thirdparty_static->fournisseur = $objp->fournisseur;
479 $thirdparty_static->logo = $objp->logo;
480 $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
481 $thirdparty_static->status = $objp->status;
482 $thirdparty_static->code_client = $objp->code_client;
483 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
484 $thirdparty_static->canvas = $objp->canvas;
485 $thirdparty_static->email = $objp->email;
486 $thirdparty_static->entity = $objp->entity;
487 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
488 $thirdparty_static->code_compta_client = $objp->code_compta;
490 $contact_static->id = $objp->cid;
491 $contact_static->status = $objp->cstatus;
492 $contact_static->firstname = $objp->firstname;
493 $contact_static->lastname = $objp->lastname;
494 $contact_static->email = $objp->cemail;
495 $contact_static->socid = $objp->rowid;
496 $contact_static->canvas = $objp->ccanvas;
497 $contact_static->phone_pro = $objp->cphone;
498 $contact_static->address = $objp->caddress;
500 $lastmodifiedcontact .=
'<tr class="oddeven">';
502 $lastmodifiedcontact .=
'<td class="tdoverflowmax150">';
503 $lastmodifiedcontact .= $contact_static->getNomUrl(1);
504 $lastmodifiedcontact .=
'</td>';
506 $lastmodifiedcontact .=
'<td class="nowrap tdoverflowmax125">';
507 $lastmodifiedcontact .= $thirdparty_static->getNomUrl(1);
508 $lastmodifiedcontact .=
"</td>\n";
510 $lastmodifiedcontact .=
'<td class="right tddate" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
' '.
dol_print_date($thirdparty_static->date_modification,
'dayhour',
'tzuserrel')).
'">';
511 $lastmodifiedcontact .=
dol_print_date($thirdparty_static->date_modification,
'day',
'tzuserrel');
512 $lastmodifiedcontact .=
"</td>";
513 $lastmodifiedcontact .=
'<td class="right nowrap">';
514 $lastmodifiedcontact .= $thirdparty_static->getLibStatut(3);
515 $lastmodifiedcontact .=
"</td>";
516 $lastmodifiedcontact .=
"</tr>\n";
522 $lastmodifiedcontact .=
"</table>\n";
523 $lastmodifiedcontact .=
'</div>';
524 $lastmodifiedcontact .=
"<!-- End last contacts modified -->\n";
527 dol_print_error($db);
532print
'<div class="clearboth"></div>';
533print
'<div class="fichecenter fichecenterbis">';
535$boxlist =
'<div class="twocolumns">';
537$boxlist .=
'<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
538$boxlist .= $thirdpartygraph;
540$boxlist .= $thirdpartycateggraph;
542$boxlist .= $resultboxes[
'boxlista'];
543$boxlist .=
'</div>'.
"\n";
545$boxlist .=
'<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
546$boxlist .= $lastmodified;
548$boxlist .= $lastmodifiedcontact;
550$boxlist .= $resultboxes[
'boxlistb'];
551$boxlist .=
'</div>'.
"\n";
559$parameters = array(
'user' => $user);
560$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.
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.