index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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-2021 Charlene Benke <charlene.r@benke.fr>
  6. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  7. * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
  8. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/societe/index.php
  25. * \ingroup societe
  26. * \brief Home page for third parties area
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  32. // Load translation files required by the page
  33. $langs->load("companies");
  34. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  35. $hookmanager = new HookManager($db);
  36. $hookmanager->initHooks(array('thirdpartiesindex'));
  37. $socid = GETPOST('socid', 'int');
  38. if ($user->socid) {
  39. $socid = $user->socid;
  40. }
  41. // Security check
  42. $result = restrictedArea($user, 'societe', 0, '', '', '', '');
  43. $thirdparty_static = new Societe($db);
  44. if (!isset($form) || !is_object($form)) {
  45. $form = new Form($db);
  46. }
  47. // Load $resultboxes
  48. $resultboxes = FormOther::getBoxesArea($user, "3");
  49. if (GETPOST('addbox')) {
  50. // Add box (when submit is done from a form when ajax disabled)
  51. require_once DOL_DOCUMENT_ROOT.'/core/class/infobox.class.php';
  52. $zone = GETPOST('areacode', 'int');
  53. $userid = GETPOST('userid', 'int');
  54. $boxorder = GETPOST('boxorder', 'aZ09');
  55. $boxorder .= GETPOST('boxcombo', 'aZ09');
  56. $result = InfoBox::saveboxorder($db, $zone, $boxorder, $userid);
  57. if ($result > 0) {
  58. setEventMessages($langs->trans("BoxAdded"), null);
  59. }
  60. }
  61. /*
  62. * View
  63. */
  64. $transAreaType = $langs->trans("ThirdPartiesArea");
  65. $helpurl = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
  66. llxHeader("", $langs->trans("ThirdParties"), $helpurl);
  67. print load_fiche_titre($transAreaType, $resultboxes['selectboxlist'], 'companies');
  68. /*
  69. * Statistics area
  70. */
  71. $third = array(
  72. 'customer' => 0,
  73. 'prospect' => 0,
  74. 'supplier' => 0,
  75. 'other' =>0
  76. );
  77. $total = 0;
  78. $sql = "SELECT s.rowid, s.client, s.fournisseur";
  79. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  80. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  81. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  82. }
  83. $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
  84. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  85. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  86. }
  87. if (!$user->hasRight('fournisseur', 'lire')) {
  88. $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
  89. }
  90. // Add where from hooks
  91. $parameters = array('socid' => $socid);
  92. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
  93. if (empty($reshook)) {
  94. if ($socid > 0) {
  95. $sql .= " AND s.rowid = ".((int) $socid);
  96. }
  97. }
  98. $sql .= $hookmanager->resPrint;
  99. //print $sql;
  100. $result = $db->query($sql);
  101. if ($result) {
  102. while ($objp = $db->fetch_object($result)) {
  103. $found = 0;
  104. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS') && ($objp->client == 2 || $objp->client == 3)) {
  105. $found = 1;
  106. $third['prospect']++;
  107. }
  108. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS') && ($objp->client == 1 || $objp->client == 3)) {
  109. $found = 1;
  110. $third['customer']++;
  111. }
  112. 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) {
  113. $found = 1;
  114. $third['supplier']++;
  115. }
  116. if (isModEnabled('societe') && $objp->client == 0 && $objp->fournisseur == 0) {
  117. $found = 1;
  118. $third['other']++;
  119. }
  120. if ($found) {
  121. $total++;
  122. }
  123. }
  124. } else {
  125. dol_print_error($db);
  126. }
  127. $thirdpartygraph = '<div class="div-table-responsive-no-min">';
  128. $thirdpartygraph .= '<table class="noborder nohover centpercent">'."\n";
  129. $thirdpartygraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  130. 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)) {
  131. $thirdpartygraph .= '<tr><td class="center" colspan="2">';
  132. $dataseries = array();
  133. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
  134. $dataseries[] = array($langs->transnoentitiesnoconv("Prospects"), round($third['prospect']));
  135. }
  136. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) {
  137. $dataseries[] = array($langs->transnoentitiesnoconv("Customers"), round($third['customer']));
  138. }
  139. 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')) {
  140. $dataseries[] = array($langs->transnoentitiesnoconv("Suppliers"), round($third['supplier']));
  141. }
  142. if (isModEnabled('societe')) {
  143. $dataseries[] = array($langs->transnoentitiesnoconv("Others"), round($third['other']));
  144. }
  145. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  146. $dolgraph = new DolGraph();
  147. $dolgraph->SetData($dataseries);
  148. $dolgraph->setShowLegend(2);
  149. $dolgraph->setShowPercent(1);
  150. $dolgraph->SetType(array('pie'));
  151. $dolgraph->setHeight('200');
  152. $dolgraph->draw('idgraphthirdparties');
  153. $thirdpartygraph .= $dolgraph->show();
  154. $thirdpartygraph .= '</td></tr>'."\n";
  155. } else {
  156. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
  157. $statstring = "<tr>";
  158. $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
  159. $statstring .= "</tr>";
  160. }
  161. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) {
  162. $statstring .= "<tr>";
  163. $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
  164. $statstring .= "</tr>";
  165. }
  166. $statstring2 = '';
  167. 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')) {
  168. $statstring2 = "<tr>";
  169. $statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
  170. $statstring2 .= "</tr>";
  171. }
  172. $thirdpartygraph .= $statstring;
  173. $thirdpartygraph .= $statstring2;
  174. }
  175. $thirdpartygraph .= '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td class="right">';
  176. $thirdpartygraph .= $total;
  177. $thirdpartygraph .= '</td></tr>';
  178. $thirdpartygraph .= '</table>';
  179. $thirdpartygraph .= '</div>';
  180. $thirdpartycateggraph = '';
  181. if (isModEnabled('categorie') && getDolGlobalString('CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')) {
  182. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  183. $elementtype = 'societe';
  184. $thirdpartycateggraph = '<div class="div-table-responsive-no-min">';
  185. $thirdpartycateggraph .= '<table class="noborder nohover centpercent">';
  186. $thirdpartycateggraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
  187. $thirdpartycateggraph .= '<tr><td class="center" colspan="2">';
  188. $sql = "SELECT c.label, count(*) as nb";
  189. $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
  190. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
  191. $sql .= " WHERE c.type = 2";
  192. if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
  193. $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
  194. }
  195. $sql .= " AND c.entity IN (".getEntity('category').")";
  196. $sql .= " GROUP BY c.label";
  197. $total = 0;
  198. $result = $db->query($sql);
  199. if ($result) {
  200. $num = $db->num_rows($result);
  201. $i = 0;
  202. if (!empty($conf->use_javascript_ajax)) {
  203. $dataseries = array();
  204. $rest = 0;
  205. $nbmax = 10;
  206. while ($i < $num) {
  207. $obj = $db->fetch_object($result);
  208. if ($i < $nbmax) {
  209. $dataseries[] = array($obj->label, round($obj->nb));
  210. } else {
  211. $rest += $obj->nb;
  212. }
  213. $total += $obj->nb;
  214. $i++;
  215. }
  216. if ($i > $nbmax) {
  217. $dataseries[] = array($langs->trans("Other"), round($rest));
  218. }
  219. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  220. $dolgraph = new DolGraph();
  221. $dolgraph->SetData($dataseries);
  222. $dolgraph->setShowLegend(2);
  223. $dolgraph->setShowPercent(1);
  224. $dolgraph->SetType(array('pie'));
  225. $dolgraph->setHeight('200');
  226. $dolgraph->draw('idgraphcateg');
  227. $thirdpartycateggraph .= $dolgraph->show();
  228. } else {
  229. while ($i < $num) {
  230. $obj = $db->fetch_object($result);
  231. $thirdpartycateggraph .= '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
  232. $total += $obj->nb;
  233. $i++;
  234. }
  235. }
  236. }
  237. $thirdpartycateggraph .= '</td></tr>';
  238. $thirdpartycateggraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
  239. $thirdpartycateggraph .= $total;
  240. $thirdpartycateggraph .= '</td></tr>';
  241. $thirdpartycateggraph .= '</table>';
  242. $thirdpartycateggraph .= '</div>';
  243. } else {
  244. $thirdpartycateggraph = '';
  245. }
  246. /*
  247. * Latest modified third parties
  248. */
  249. $max = 15;
  250. $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
  251. $sql .= ", s.code_client";
  252. $sql .= ", s.code_fournisseur";
  253. if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
  254. $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
  255. $sql .= ", spe.accountancy_code_customer as code_compta";
  256. } else {
  257. $sql .= ", s.code_compta_fournisseur";
  258. $sql .= ", s.code_compta";
  259. }
  260. $sql .= ", s.logo";
  261. $sql .= ", s.entity";
  262. $sql .= ", s.canvas, s.tms as date_modification, s.status as status";
  263. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  264. if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
  265. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
  266. }
  267. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  268. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  269. }
  270. $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
  271. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  272. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  273. }
  274. if (!$user->hasRight('fournisseur', 'lire')) {
  275. $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
  276. }
  277. // Add where from hooks
  278. $parameters = array('socid' => $socid);
  279. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
  280. if (empty($reshook)) {
  281. if ($socid > 0) {
  282. $sql .= " AND s.rowid = ".((int) $socid);
  283. }
  284. }
  285. $sql .= $hookmanager->resPrint;
  286. $sql .= $db->order("s.tms", "DESC");
  287. $sql .= $db->plimit($max, 0);
  288. //print $sql;
  289. $lastmodified="";
  290. $result = $db->query($sql);
  291. if ($result) {
  292. $num = $db->num_rows($result);
  293. $i = 0;
  294. if ($num > 0) {
  295. $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
  296. $lastmodified = "\n<!-- last thirdparties modified -->\n";
  297. $lastmodified .= '<div class="div-table-responsive-no-min">';
  298. $lastmodified .= '<table class="noborder centpercent">';
  299. $lastmodified .= '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
  300. $lastmodified .= '<th>&nbsp;</th>';
  301. $lastmodified .= '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  302. $lastmodified .= '</tr>'."\n";
  303. while ($i < $num) {
  304. $objp = $db->fetch_object($result);
  305. $thirdparty_static->id = $objp->rowid;
  306. $thirdparty_static->name = $objp->name;
  307. $thirdparty_static->client = $objp->client;
  308. $thirdparty_static->fournisseur = $objp->fournisseur;
  309. $thirdparty_static->logo = $objp->logo;
  310. $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
  311. $thirdparty_static->status = $objp->status;
  312. $thirdparty_static->code_client = $objp->code_client;
  313. $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
  314. $thirdparty_static->canvas = $objp->canvas;
  315. $thirdparty_static->email = $objp->email;
  316. $thirdparty_static->entity = $objp->entity;
  317. $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
  318. $thirdparty_static->code_compta = $objp->code_compta;
  319. $lastmodified .= '<tr class="oddeven">';
  320. // Name
  321. $lastmodified .= '<td class="nowrap tdoverflowmax200">';
  322. $lastmodified .= $thirdparty_static->getNomUrl(1);
  323. $lastmodified .= "</td>\n";
  324. // Type
  325. $lastmodified .= '<td class="center">';
  326. $lastmodified .= $thirdparty_static->getTypeUrl();
  327. $lastmodified .= '</td>';
  328. // Last modified date
  329. $lastmodified .= '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").' '.dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')).'">';
  330. $lastmodified .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel');
  331. $lastmodified .= "</td>";
  332. $lastmodified .= '<td class="right nowrap">';
  333. $lastmodified .= $thirdparty_static->getLibStatut(3);
  334. $lastmodified .= "</td>";
  335. $lastmodified .= "</tr>\n";
  336. $i++;
  337. }
  338. $db->free($result);
  339. $lastmodified .= "</table>\n";
  340. $lastmodified .= '</div>';
  341. $lastmodified .= "<!-- End last thirdparties modified -->\n";
  342. }
  343. } else {
  344. dol_print_error($db);
  345. }
  346. //print '</div></div></div>';
  347. // boxes
  348. print '<div class="clearboth"></div>';
  349. print '<div class="fichecenter fichecenterbis">';
  350. $boxlist = '<div class="twocolumns">';
  351. $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  352. $boxlist .= $thirdpartygraph;
  353. $boxlist .= '<br>';
  354. $boxlist .= $thirdpartycateggraph;
  355. $boxlist .= '<br>';
  356. $boxlist .= $resultboxes['boxlista'];
  357. $boxlist .= '</div>'."\n";
  358. $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  359. $boxlist .= $lastmodified;
  360. $boxlist .= '<br>';
  361. $boxlist .= $resultboxes['boxlistb'];
  362. $boxlist .= '</div>'."\n";
  363. $boxlist .= '</div>';
  364. print $boxlist;
  365. print '</div>';
  366. $parameters = array('user' => $user);
  367. $reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
  368. // End of page
  369. llxFooter();
  370. $db->close();