index.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/societe/index.php
  24. * \ingroup societe
  25. * \brief Home page for third parties area
  26. */
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  29. $langs->load("companies");
  30. $socid = GETPOST('socid','int');
  31. if ($user->societe_id) $socid=$user->societe_id;
  32. // Security check
  33. $result=restrictedArea($user,'societe',0,'','','','');
  34. $thirdparty_static = new Societe($db);
  35. /*
  36. * View
  37. */
  38. $transAreaType = $langs->trans("ThirdPartiesArea");
  39. $helpurl='EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
  40. llxHeader("",$langs->trans("ThirdParties"),$helpurl);
  41. $linkback='';
  42. print load_fiche_titre($transAreaType,$linkback,'title_companies.png');
  43. //print '<table border="0" width="100%" class="notopnoleftnoright">';
  44. //print '<tr><td valign="top" width="30%" class="notopnoleft">';
  45. print '<div class="fichecenter"><div class="fichethirdleft">';
  46. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  47. {
  48. // Search thirdparty
  49. if (! empty($conf->societe->enabled) && $user->rights->societe->lire)
  50. {
  51. $listofsearchfields['search_thirdparty']=array('text'=>'ThirdParty');
  52. }
  53. // Search contact/address
  54. if (! empty($conf->societe->enabled) && $user->rights->societe->lire)
  55. {
  56. $listofsearchfields['search_contact']=array('text'=>'Contact');
  57. }
  58. if (count($listofsearchfields))
  59. {
  60. print '<form method="post" action="'.DOL_URL_ROOT.'/core/search.php">';
  61. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  62. print '<table class="noborder nohover centpercent">';
  63. $i=0;
  64. foreach($listofsearchfields as $key => $value)
  65. {
  66. if ($i == 0) print '<tr class="liste_titre"><th colspan="3">'.$langs->trans("Search").'</th></tr>';
  67. print '<tr '.$bc[false].'>';
  68. print '<td class="nowrap"><label for="'.$key.'">'.$langs->trans($value["text"]).'</label></td><td><input type="text" class="flat inputsearch" name="'.$key.'" id="'.$key.'" size="18"></td>';
  69. if ($i == 0) print '<td rowspan="'.count($listofsearchfields).'"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td>';
  70. print '</tr>';
  71. $i++;
  72. }
  73. print '</table>';
  74. print '</form>';
  75. print '<br>';
  76. }
  77. }
  78. /*
  79. * Statistics area
  80. */
  81. $third = array(
  82. 'customer' => 0,
  83. 'prospect' => 0,
  84. 'supplier' => 0,
  85. 'other' =>0
  86. );
  87. $total=0;
  88. $sql = "SELECT s.rowid, s.client, s.fournisseur";
  89. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  90. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  91. $sql.= ' WHERE s.entity IN ('.getEntity('societe').')';
  92. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  93. if ($socid) $sql.= " AND s.rowid = ".$socid;
  94. if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
  95. //print $sql;
  96. $result = $db->query($sql);
  97. if ($result)
  98. {
  99. while ($objp = $db->fetch_object($result))
  100. {
  101. $found=0;
  102. 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']++; }
  103. 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']++; }
  104. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) { $found=1; $third['supplier']++; }
  105. if (! empty($conf->societe->enabled) && $objp->client == 0 && $objp->fournisseur == 0) { $found=1; $third['other']++; }
  106. if ($found) $total++;
  107. }
  108. }
  109. else dol_print_error($db);
  110. print '<div class="div-table-responsive-no-min">';
  111. print '<table class="noborder nohover" width="100%">'."\n";
  112. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  113. 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))
  114. {
  115. print '<tr><td align="center" colspan="2">';
  116. $dataseries=array();
  117. 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']));
  118. 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']));
  119. if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->lire && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array($langs->trans("Suppliers"), round($third['supplier']));
  120. if (! empty($conf->societe->enabled)) $dataseries[]=array($langs->trans("Others"), round($third['other']));
  121. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  122. $dolgraph = new DolGraph();
  123. $dolgraph->SetData($dataseries);
  124. $dolgraph->setShowLegend(1);
  125. $dolgraph->setShowPercent(1);
  126. $dolgraph->SetType(array('pie'));
  127. $dolgraph->setWidth('100%');
  128. $dolgraph->draw('idgraphthirdparties');
  129. print $dolgraph->show();
  130. print '</td></tr>'."\n";
  131. }
  132. else
  133. {
  134. if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS))
  135. {
  136. $statstring = "<tr>";
  137. $statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td align="right">'.round($third['prospect']).'</td>';
  138. $statstring.= "</tr>";
  139. }
  140. if (! empty($conf->societe->enabled) && $user->rights->societe->lire && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS))
  141. {
  142. $statstring.= "<tr>";
  143. $statstring.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td align="right">'.round($third['customer']).'</td>';
  144. $statstring.= "</tr>";
  145. }
  146. if (! empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $user->rights->fournisseur->lire)
  147. {
  148. $statstring2 = "<tr>";
  149. $statstring2.= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td align="right">'.round($third['supplier']).'</td>';
  150. $statstring2.= "</tr>";
  151. }
  152. print $statstring;
  153. print $statstring2;
  154. }
  155. print '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td align="right">';
  156. print $total;
  157. print '</td></tr>';
  158. print '</table>';
  159. print '</div>';
  160. if (! empty($conf->categorie->enabled) && ! empty($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES))
  161. {
  162. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  163. $elementtype = 'societe';
  164. print '<br>';
  165. print '<div class="div-table-responsive-no-min">';
  166. print '<table class="noborder nohover" width="100%">';
  167. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
  168. print '<tr '.$bc[0].'><td align="center" colspan="2">';
  169. $sql = "SELECT c.label, count(*) as nb";
  170. $sql.= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
  171. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
  172. $sql.= " WHERE c.type = 2";
  173. if (! is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) $sql.= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
  174. $sql.= " AND c.entity IN (".getEntity('category').")";
  175. $sql.= " GROUP BY c.label";
  176. $total=0;
  177. $result = $db->query($sql);
  178. if ($result)
  179. {
  180. $num = $db->num_rows($result);
  181. $i=0;
  182. if (! empty($conf->use_javascript_ajax) )
  183. {
  184. $dataseries=array();
  185. $rest=0;
  186. $nbmax=10;
  187. while ($i < $num)
  188. {
  189. $obj = $db->fetch_object($result);
  190. if ($i < $nbmax)
  191. {
  192. $dataseries[]=array($obj->label, round($obj->nb));
  193. }
  194. else
  195. {
  196. $rest+=$obj->nb;
  197. }
  198. $total+=$obj->nb;
  199. $i++;
  200. }
  201. if ($i > $nbmax)
  202. {
  203. $dataseries[]=array($langs->trans("Other"), round($rest));
  204. }
  205. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  206. $dolgraph = new DolGraph();
  207. $dolgraph->SetData($dataseries);
  208. $dolgraph->setShowLegend(1);
  209. $dolgraph->setShowPercent(1);
  210. $dolgraph->SetType(array('pie'));
  211. $dolgraph->setWidth('100%');
  212. $dolgraph->draw('idgraphcateg');
  213. print $dolgraph->show();
  214. }
  215. else
  216. {
  217. while ($i < $num)
  218. {
  219. $obj = $db->fetch_object($result);
  220. print '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
  221. $total+=$obj->nb;
  222. $i++;
  223. }
  224. }
  225. }
  226. print '</td></tr>';
  227. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">';
  228. print $total;
  229. print '</td></tr>';
  230. print '</table>';
  231. print '</div>';
  232. }
  233. //print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
  234. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  235. /*
  236. * Last third parties modified
  237. */
  238. $max=15;
  239. $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
  240. $sql.= ", s.code_client";
  241. $sql.= ", s.code_fournisseur";
  242. $sql.= ", s.logo";
  243. $sql.= ", s.canvas, s.tms as datem, s.status as status";
  244. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  245. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  246. $sql.= ' WHERE s.entity IN ('.getEntity('societe').')';
  247. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  248. if ($socid) $sql.= " AND s.rowid = ".$socid;
  249. if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur != 1 OR s.client != 0)";
  250. $sql.= $db->order("s.tms","DESC");
  251. $sql.= $db->plimit($max,0);
  252. //print $sql;
  253. $result = $db->query($sql);
  254. if ($result)
  255. {
  256. $num = $db->num_rows($result);
  257. $i = 0;
  258. if ($num > 0)
  259. {
  260. $transRecordedType = $langs->trans("LastModifiedThirdParties",$max);
  261. print "\n<!-- last thirdparties modified -->\n";
  262. print '<div class="div-table-responsive-no-min">';
  263. print '<table class="noborder" width="100%">';
  264. print '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
  265. print '<th>&nbsp;</th>';
  266. print '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  267. print '</tr>'."\n";
  268. while ($i < $num)
  269. {
  270. $objp = $db->fetch_object($result);
  271. $thirdparty_static->id=$objp->rowid;
  272. $thirdparty_static->name=$objp->name;
  273. $thirdparty_static->client=$objp->client;
  274. $thirdparty_static->fournisseur=$objp->fournisseur;
  275. $thirdparty_static->logo = $objp->logo;
  276. $thirdparty_static->datem=$db->jdate($objp->datem);
  277. $thirdparty_static->status=$objp->status;
  278. $thirdparty_static->code_client = $objp->code_client;
  279. $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
  280. $thirdparty_static->canvas=$objp->canvas;
  281. $thirdparty_static->email = $objp->email;
  282. print '<tr class="oddeven">';
  283. // Name
  284. print '<td class="nowrap">';
  285. print $thirdparty_static->getNomUrl(1);
  286. print "</td>\n";
  287. // Type
  288. print '<td align="center">';
  289. if ($thirdparty_static->client==1 || $thirdparty_static->client==3)
  290. {
  291. $thirdparty_static->name=$langs->trans("Customer");
  292. print $thirdparty_static->getNomUrl(0,'customer',0,1);
  293. }
  294. if ($thirdparty_static->client == 3 && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print " / ";
  295. if (($thirdparty_static->client==2 || $thirdparty_static->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  296. {
  297. $thirdparty_static->name=$langs->trans("Prospect");
  298. print $thirdparty_static->getNomUrl(0,'prospect',0,1);
  299. }
  300. if (! empty($conf->fournisseur->enabled) && $thirdparty_static->fournisseur)
  301. {
  302. if ($thirdparty_static->client) print " / ";
  303. $thirdparty_static->name=$langs->trans("Supplier");
  304. print $thirdparty_static->getNomUrl(0,'supplier',0,1);
  305. }
  306. print '</td>';
  307. // Last modified date
  308. print '<td align="right">';
  309. print dol_print_date($thirdparty_static->datem,'day');
  310. print "</td>";
  311. print '<td align="right" class="nowrap">';
  312. print $thirdparty_static->getLibStatut(3);
  313. print "</td>";
  314. print "</tr>\n";
  315. $i++;
  316. }
  317. $db->free($result);
  318. print "</table>\n";
  319. print '</div>';
  320. print "<!-- End last thirdparties modified -->\n";
  321. }
  322. }
  323. else
  324. {
  325. dol_print_error($db);
  326. }
  327. //print '</td></tr></table>';
  328. print '</div></div></div>';
  329. // End of page
  330. llxFooter();
  331. $db->close();