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,
'',
'',
'',
'');
63if (!isset($form) || !is_object($form)) {
72 require_once DOL_DOCUMENT_ROOT.
'/core/class/infobox.class.php';
75 $boxorder =
GETPOST(
'boxorder',
'aZ09');
76 $boxorder .=
GETPOST(
'boxcombo',
'aZ09');
90$transAreaType = $langs->trans(
"ThirdPartiesArea");
91$helpurl =
'EN:Module_Third_Parties|FR:Module_Tiers|ES:Módulo_Terceros';
93llxHeader(
"", $langs->trans(
"ThirdParties"), $helpurl);
95print
load_fiche_titre($transAreaType, $resultboxes[
'selectboxlist'],
'companies');
108$sql =
"SELECT s.rowid, s.client, s.fournisseur";
109$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
110if (!$user->hasRight(
'societe',
'client',
'voir')) {
111 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
113$sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
114if (!$user->hasRight(
'societe',
'client',
'voir')) {
115 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
117if (!$user->hasRight(
'fournisseur',
'lire')) {
118 $sql .=
" AND (s.fournisseur <> 1 OR s.client <> 0)";
121$parameters = array(
'socid' => $socid);
122$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
123if (empty($reshook)) {
125 $sql .=
" AND s.rowid = ".((int) $socid);
128$sql .= $hookmanager->resPrint;
130$result =
$db->query($sql);
132 while ($objp =
$db->fetch_object($result)) {
136 $third[
'prospect']++;
140 $third[
'customer']++;
142 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) {
144 $third[
'supplier']++;
146 if (
isModEnabled(
'societe') && $objp->client == 0 && $objp->fournisseur == 0) {
158$thirdpartygraph =
'<div class="div-table-responsive-no-min">';
159$thirdpartygraph .=
'<table class="noborder nohover centpercent">'.
"\n";
160$thirdpartygraph .=
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Statistics").
' - '.$langs->trans(
"NatureOfThirdParty").
'</th></tr>';
161if (!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)) {
162 $thirdpartygraph .=
'<tr><td class="center" colspan="2">';
163 $dataseries = array();
165 $dataseries[] = array($langs->transnoentitiesnoconv(
"Prospects"), round($third[
'prospect']));
168 $dataseries[] = array($langs->transnoentitiesnoconv(
"Customers"), round($third[
'customer']));
171 $dataseries[] = array($langs->transnoentitiesnoconv(
"Suppliers"), round($third[
'supplier']));
174 $dataseries[] = array($langs->transnoentitiesnoconv(
"Others"), round($third[
'other']));
176 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
178 $dolgraph->SetData($dataseries);
179 $dolgraph->setShowLegend(2);
180 $dolgraph->setShowPercent(1);
181 $dolgraph->SetType(array(
'pie'));
182 $dolgraph->setHeight(
'200');
183 $dolgraph->draw(
'idgraphthirdparties');
184 $thirdpartygraph .= $dolgraph->show();
185 $thirdpartygraph .=
'</td></tr>'.
"\n";
189 $statstring .=
"<tr>";
190 $statstring .=
'<td><a href="'.DOL_URL_ROOT.
'/societe/list.php?type=p">'.$langs->trans(
"Prospects").
'</a></td><td class="right">'.round($third[
'prospect']).
'</td>';
191 $statstring .=
"</tr>";
194 $statstring .=
"<tr>";
195 $statstring .=
'<td><a href="'.DOL_URL_ROOT.
'/societe/list.php?type=c">'.$langs->trans(
"Customers").
'</a></td><td class="right">'.round($third[
'customer']).
'</td>';
196 $statstring .=
"</tr>";
200 $statstring2 .=
"<tr>";
201 $statstring2 .=
'<td><a href="'.DOL_URL_ROOT.
'/societe/list.php?type=f">'.$langs->trans(
"Suppliers").
'</a></td><td class="right">'.round($third[
'supplier']).
'</td>';
202 $statstring2 .=
"</tr>";
204 $thirdpartygraph .= $statstring;
205 $thirdpartygraph .= $statstring2;
207$thirdpartygraph .=
'<tr class="liste_total"><td>'.$langs->trans(
"UniqueThirdParties").
'</td><td class="right">';
208$thirdpartygraph .= $total;
209$thirdpartygraph .=
'</td></tr>';
210$thirdpartygraph .=
'</table>';
211$thirdpartygraph .=
'</div>';
213$thirdpartycateggraph =
'';
215 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
217 $thirdpartycateggraph =
'<div class="div-table-responsive-no-min">';
218 $thirdpartycateggraph .=
'<table class="noborder nohover centpercent">';
219 $thirdpartycateggraph .=
'<tr class="liste_titre"><th colspan="2">'.$langs->trans(
"Categories").
'</th></tr>';
220 $thirdpartycateggraph .=
'<tr><td class="center" colspan="2">';
221 $sql =
"SELECT c.label, count(*) as nb";
222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"categorie_societe as cs";
223 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"categorie as c ON cs.fk_categorie = c.rowid";
224 $sql .=
" WHERE c.type = 2";
226 $sql .=
" AND c.label like '".$db->escape(
getDolGlobalString(
'CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')).
"'";
228 $sql .=
" AND c.entity IN (".getEntity(
'category').
")";
229 $sql .=
" GROUP BY c.label";
231 $result =
$db->query($sql);
233 $num =
$db->num_rows($result);
235 if (!empty(
$conf->use_javascript_ajax)) {
236 $dataseries = array();
241 $obj =
$db->fetch_object($result);
243 $dataseries[] = array($obj->label, round($obj->nb));
251 $dataseries[] = array($langs->trans(
"Other"), round($rest));
253 include_once DOL_DOCUMENT_ROOT.
'/core/class/dolgraph.class.php';
255 $dolgraph->SetData($dataseries);
256 $dolgraph->setShowLegend(2);
257 $dolgraph->setShowPercent(1);
258 $dolgraph->SetType(array(
'pie'));
259 $dolgraph->setHeight(
'200');
260 $dolgraph->draw(
'idgraphcateg');
261 $thirdpartycateggraph .= $dolgraph->show();
264 $obj =
$db->fetch_object($result);
266 $thirdpartycateggraph .=
'<tr class="oddeven"><td>'.dolPrintHTML($obj->label).
'</td><td>'.$obj->nb.
'</td></tr>';
272 $thirdpartycateggraph .=
'</td></tr>';
273 $thirdpartycateggraph .=
'<tr class="liste_total"><td>'.$langs->trans(
"Total").
'</td><td class="right">';
274 $thirdpartycateggraph .= $total;
275 $thirdpartycateggraph .=
'</td></tr>';
276 $thirdpartycateggraph .=
'</table>';
277 $thirdpartycateggraph .=
'</div>';
279 $thirdpartycateggraph =
'';
287$sql =
"SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
288$sql .=
", s.code_client";
289$sql .=
", s.code_fournisseur";
291 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
292 $sql .=
", spe.accountancy_code_customer as code_compta";
294 $sql .=
", s.code_compta_fournisseur";
295 $sql .=
", s.code_compta";
299$sql .=
", s.canvas, GREATEST(s.tms, sef.tms) as date_modification, s.status as status";
300$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
301$sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_extrafields as sef ON sef.fk_object=s.rowid";
303 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
306if (!$user->hasRight(
'societe',
'client',
'voir')) {
307 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
309$sql .=
' WHERE s.entity IN ('.getEntity(
'societe').
')';
310if (!$user->hasRight(
'societe',
'client',
'voir')) {
311 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
313if (!$user->hasRight(
'fournisseur',
'lire')) {
314 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
317$parameters = array(
'socid' => $socid);
318$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
319if (empty($reshook)) {
321 $sql .=
" AND s.rowid = ".((int) $socid);
324$sql .= $hookmanager->resPrint;
325$sql .=
$db->order(
"date_modification",
"DESC");
326$sql .=
$db->plimit($max, 0);
330$result =
$db->query($sql);
332 $num =
$db->num_rows($result);
337 $transRecordedType = $langs->trans(
"LastModifiedThirdParties", $max);
339 $lastmodified =
"\n<!-- last thirdparties modified -->\n";
340 $lastmodified .=
'<div class="div-table-responsive-no-min">';
341 $lastmodified .=
'<table class="noborder centpercent">';
343 $lastmodified .=
'<tr class="liste_titre"><th colspan="2">';
345 $lastmodified .=
'<span class="valignmiddle">'.$transRecordedType.
'</span>';
346 $lastmodified .=
'<a class="marginleftonlyshort" href="'.DOL_URL_ROOT.
'/societe/list.php?sortfield=s.tms&sortorder=DESC" title="'.$langs->trans(
"FullList").
'">';
347 $lastmodified .=
'<span class="badge marginleftonlyshort">...</span>';
348 $lastmodified .=
'</a>';
349 $lastmodified .=
'</th>';
350 $lastmodified .=
'<th> </th>';
351 $lastmodified .=
'<th class="right">';
352 $lastmodified .=
'</th>';
353 $lastmodified .=
'</tr>'.
"\n";
356 $objp =
$db->fetch_object($result);
358 $thirdparty_static->id = $objp->rowid;
359 $thirdparty_static->name = $objp->name;
360 $thirdparty_static->client = $objp->client;
361 $thirdparty_static->fournisseur = $objp->fournisseur;
362 $thirdparty_static->logo = $objp->logo;
363 $thirdparty_static->date_modification =
$db->jdate($objp->date_modification);
364 $thirdparty_static->status = $objp->status;
365 $thirdparty_static->code_client = $objp->code_client;
366 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
367 $thirdparty_static->canvas = $objp->canvas;
368 $thirdparty_static->email = $objp->email;
369 $thirdparty_static->entity = $objp->entity;
370 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
371 $thirdparty_static->code_compta_client = $objp->code_compta;
373 $lastmodified .=
'<tr class="oddeven">';
375 $lastmodified .=
'<td class="nowrap tdoverflowmax200">';
376 $lastmodified .= $thirdparty_static->getNomUrl(1);
377 $lastmodified .=
"</td>\n";
379 $lastmodified .=
'<td class="center">';
380 $lastmodified .= $thirdparty_static->getTypeUrl();
381 $lastmodified .=
'</td>';
383 $lastmodified .=
'<td class="right tddate" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
' '.
dol_print_date($thirdparty_static->date_modification,
'dayhour',
'tzuserrel')).
'">';
384 $lastmodified .=
dol_print_date($thirdparty_static->date_modification,
'day',
'tzuserrel');
385 $lastmodified .=
"</td>";
386 $lastmodified .=
'<td class="right nowrap">';
387 $lastmodified .= $thirdparty_static->getLibStatut(3);
388 $lastmodified .=
"</td>";
389 $lastmodified .=
"</tr>\n";
395 $lastmodified .=
"</table>\n";
396 $lastmodified .=
'</div>';
397 $lastmodified .=
"<!-- End last thirdparties modified -->\n";
408$sql =
"SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
409$sql .=
", s.code_client";
410$sql .=
", s.code_fournisseur";
412 $sql .=
", spe.accountancy_code_supplier as code_compta_fournisseur";
413 $sql .=
", spe.accountancy_code_customer as code_compta";
415 $sql .=
", s.code_compta_fournisseur";
416 $sql .=
", s.code_compta";
421$sql .=
", s.status as status";
422$sql .=
", GREATEST(sp.tms, spef.tms) as date_modification, sp.statut as cstatus";
423$sql .=
", sp.rowid as cid, sp.canvas as ccanvas, sp.email as cemail, sp.firstname, sp.lastname";
424$sql .=
", sp.address as caddress, sp.phone as cphone";
425$sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s";
426$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)";
427$sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"socpeople_extrafields as spef ON spef.fk_object = sp.rowid";
429 $sql .=
" LEFT JOIN " . MAIN_DB_PREFIX .
"societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int)
$conf->entity);
432if (!$user->hasRight(
'societe',
'client',
'voir')) {
433 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
435$sql .=
" WHERE s.entity IN (".getEntity(
'societe').
") ";
436if (!$user->hasRight(
'societe',
'client',
'voir')) {
437 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
439if (!$user->hasRight(
'fournisseur',
'lire')) {
440 $sql .=
" AND (s.fournisseur != 1 OR s.client != 0)";
443$parameters = array(
'socid' => $socid);
444$reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $thirdparty_static);
445if (empty($reshook)) {
447 $sql .=
" AND s.rowid = ".((int) $socid);
450$sql .= $hookmanager->resPrint;
451$sql .=
$db->order(
"date_modification",
"DESC");
452$sql .=
$db->plimit($max, 0);
455$lastmodifiedcontact =
'';
456$result =
$db->query($sql);
458 $num =
$db->num_rows($result);
463 $transRecordedType = $langs->trans(
"LastModifiedContacts", $max);
465 $lastmodifiedcontact =
"\n<!-- last contacts modified -->\n";
466 $lastmodifiedcontact .=
'<div class="div-table-responsive-no-min">';
467 $lastmodifiedcontact .=
'<table class="noborder centpercent">';
469 $lastmodifiedcontact .=
'<tr class="liste_titre"><th colspan="2">';
471 $lastmodifiedcontact .=
'<span class="valignmiddle">'.$transRecordedType.
'</div>';
472 $lastmodifiedcontact .=
'<a class="marginleftonlyshort" href="'.DOL_URL_ROOT.
'/contact/list.php?sortfield=p.tms&sortorder=DESC" title="'.$langs->trans(
"FullList").
'">';
474 $lastmodifiedcontact .=
'<span class="badge marginleftonlyshort">...</span>';
475 $lastmodifiedcontact .=
'</th>';
476 $lastmodifiedcontact .=
'<th> </th>';
477 $lastmodifiedcontact .=
'<th class="right">';
479 $lastmodifiedcontact .=
'</th>';
480 $lastmodifiedcontact .=
'</tr>'.
"\n";
483 $objp =
$db->fetch_object($result);
485 $thirdparty_static->id = $objp->rowid;
486 $thirdparty_static->name = $objp->name;
487 $thirdparty_static->client = $objp->client;
488 $thirdparty_static->fournisseur = $objp->fournisseur;
489 $thirdparty_static->logo = $objp->logo;
490 $thirdparty_static->date_modification =
$db->jdate($objp->date_modification);
491 $thirdparty_static->status = $objp->status;
492 $thirdparty_static->code_client = $objp->code_client;
493 $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
494 $thirdparty_static->canvas = $objp->canvas;
495 $thirdparty_static->email = $objp->email;
496 $thirdparty_static->entity = $objp->entity;
497 $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
498 $thirdparty_static->code_compta_client = $objp->code_compta;
500 $contact_static->id = $objp->cid;
501 $contact_static->status = $objp->cstatus;
502 $contact_static->firstname = $objp->firstname;
503 $contact_static->lastname = $objp->lastname;
504 $contact_static->email = $objp->cemail;
505 $contact_static->socid = $objp->rowid;
506 $contact_static->canvas = $objp->ccanvas;
507 $contact_static->phone_pro = $objp->cphone;
508 $contact_static->address = $objp->caddress;
510 $lastmodifiedcontact .=
'<tr class="oddeven">';
512 $lastmodifiedcontact .=
'<td class="tdoverflowmax150">';
513 $lastmodifiedcontact .= $contact_static->getNomUrl(1);
514 $lastmodifiedcontact .=
'</td>';
516 $lastmodifiedcontact .=
'<td class="nowrap tdoverflowmax125">';
517 $lastmodifiedcontact .= $thirdparty_static->getNomUrl(1);
518 $lastmodifiedcontact .=
"</td>\n";
520 $lastmodifiedcontact .=
'<td class="right tddate" title="'.dol_escape_htmltag($langs->trans(
"DateModification").
' '.
dol_print_date($thirdparty_static->date_modification,
'dayhour',
'tzuserrel')).
'">';
521 $lastmodifiedcontact .=
dol_print_date($thirdparty_static->date_modification,
'day',
'tzuserrel');
522 $lastmodifiedcontact .=
"</td>";
523 $lastmodifiedcontact .=
'<td class="right nowrap">';
524 $lastmodifiedcontact .= $thirdparty_static->getLibStatut(3);
525 $lastmodifiedcontact .=
"</td>";
526 $lastmodifiedcontact .=
"</tr>\n";
532 $lastmodifiedcontact .=
"</table>\n";
533 $lastmodifiedcontact .=
'</div>';
534 $lastmodifiedcontact .=
"<!-- End last contacts modified -->\n";
542print
'<div class="clearboth"></div>';
543print
'<div class="fichecenter fichecenterbis">';
545$boxlist =
'<div class="twocolumns">';
547$boxlist .=
'<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
548$boxlist .= $thirdpartygraph;
550$boxlist .= $thirdpartycateggraph;
552$boxlist .= $resultboxes[
'boxlista'];
553$boxlist .=
'</div>'.
"\n";
555$boxlist .=
'<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
556$boxlist .= $lastmodified;
558$boxlist .= $lastmodifiedcontact;
560$boxlist .= $resultboxes[
'boxlistb'];
561$boxlist .=
'</div>'.
"\n";
569$parameters = array(
'user' => $user);
570$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.
static saveboxorder($dbs, $zone, $boxorder, $userid=0)
Save order of boxes for area and user.
Class to manage third parties objects (customers, suppliers, prospects...)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
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.