index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  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; $third['prospect']++;
  106. }
  107. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS') && ($objp->client == 1 || $objp->client == 3)) {
  108. $found = 1; $third['customer']++;
  109. }
  110. 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) {
  111. $found = 1; $third['supplier']++;
  112. }
  113. if (isModEnabled('societe') && $objp->client == 0 && $objp->fournisseur == 0) {
  114. $found = 1; $third['other']++;
  115. }
  116. if ($found) {
  117. $total++;
  118. }
  119. }
  120. } else {
  121. dol_print_error($db);
  122. }
  123. $thirdpartygraph = '<div class="div-table-responsive-no-min">';
  124. $thirdpartygraph .= '<table class="noborder nohover centpercent">'."\n";
  125. $thirdpartygraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  126. 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)) {
  127. $thirdpartygraph .= '<tr><td class="center" colspan="2">';
  128. $dataseries = array();
  129. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
  130. $dataseries[] = array($langs->transnoentitiesnoconv("Prospects"), round($third['prospect']));
  131. }
  132. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) {
  133. $dataseries[] = array($langs->transnoentitiesnoconv("Customers"), round($third['customer']));
  134. }
  135. 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')) {
  136. $dataseries[] = array($langs->transnoentitiesnoconv("Suppliers"), round($third['supplier']));
  137. }
  138. if (isModEnabled('societe')) {
  139. $dataseries[] = array($langs->transnoentitiesnoconv("Others"), round($third['other']));
  140. }
  141. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  142. $dolgraph = new DolGraph();
  143. $dolgraph->SetData($dataseries);
  144. $dolgraph->setShowLegend(2);
  145. $dolgraph->setShowPercent(1);
  146. $dolgraph->SetType(array('pie'));
  147. $dolgraph->setHeight('200');
  148. $dolgraph->draw('idgraphthirdparties');
  149. $thirdpartygraph .= $dolgraph->show();
  150. $thirdpartygraph .= '</td></tr>'."\n";
  151. } else {
  152. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS') && !getDolGlobalString('SOCIETE_DISABLE_PROSPECTS_STATS')) {
  153. $statstring = "<tr>";
  154. $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=p">'.$langs->trans("Prospects").'</a></td><td class="right">'.round($third['prospect']).'</td>';
  155. $statstring .= "</tr>";
  156. }
  157. if (isModEnabled('societe') && $user->hasRight('societe', 'lire') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS') && !getDolGlobalString('SOCIETE_DISABLE_CUSTOMERS_STATS')) {
  158. $statstring .= "<tr>";
  159. $statstring .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=c">'.$langs->trans("Customers").'</a></td><td class="right">'.round($third['customer']).'</td>';
  160. $statstring .= "</tr>";
  161. }
  162. $statstring2 = '';
  163. 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')) {
  164. $statstring2 = "<tr>";
  165. $statstring2 .= '<td><a href="'.DOL_URL_ROOT.'/societe/list.php?type=f">'.$langs->trans("Suppliers").'</a></td><td class="right">'.round($third['supplier']).'</td>';
  166. $statstring2 .= "</tr>";
  167. }
  168. $thirdpartygraph .= $statstring;
  169. $thirdpartygraph .= $statstring2;
  170. }
  171. $thirdpartygraph .= '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td class="right">';
  172. $thirdpartygraph .= $total;
  173. $thirdpartygraph .= '</td></tr>';
  174. $thirdpartygraph .= '</table>';
  175. $thirdpartygraph .= '</div>';
  176. $thirdpartycateggraph = '';
  177. if (isModEnabled('categorie') && getDolGlobalString('CATEGORY_GRAPHSTATS_ON_THIRDPARTIES')) {
  178. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  179. $elementtype = 'societe';
  180. $thirdpartycateggraph = '<div class="div-table-responsive-no-min">';
  181. $thirdpartycateggraph .= '<table class="noborder nohover centpercent">';
  182. $thirdpartycateggraph .= '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Categories").'</th></tr>';
  183. $thirdpartycateggraph .= '<tr><td class="center" colspan="2">';
  184. $sql = "SELECT c.label, count(*) as nb";
  185. $sql .= " FROM ".MAIN_DB_PREFIX."categorie_societe as cs";
  186. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."categorie as c ON cs.fk_categorie = c.rowid";
  187. $sql .= " WHERE c.type = 2";
  188. if (!is_numeric($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)) {
  189. $sql .= " AND c.label like '".$db->escape($conf->global->CATEGORY_GRAPHSTATS_ON_THIRDPARTIES)."'";
  190. }
  191. $sql .= " AND c.entity IN (".getEntity('category').")";
  192. $sql .= " GROUP BY c.label";
  193. $total = 0;
  194. $result = $db->query($sql);
  195. if ($result) {
  196. $num = $db->num_rows($result);
  197. $i = 0;
  198. if (!empty($conf->use_javascript_ajax)) {
  199. $dataseries = array();
  200. $rest = 0;
  201. $nbmax = 10;
  202. while ($i < $num) {
  203. $obj = $db->fetch_object($result);
  204. if ($i < $nbmax) {
  205. $dataseries[] = array($obj->label, round($obj->nb));
  206. } else {
  207. $rest += $obj->nb;
  208. }
  209. $total += $obj->nb;
  210. $i++;
  211. }
  212. if ($i > $nbmax) {
  213. $dataseries[] = array($langs->trans("Other"), round($rest));
  214. }
  215. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  216. $dolgraph = new DolGraph();
  217. $dolgraph->SetData($dataseries);
  218. $dolgraph->setShowLegend(2);
  219. $dolgraph->setShowPercent(1);
  220. $dolgraph->SetType(array('pie'));
  221. $dolgraph->setHeight('200');
  222. $dolgraph->draw('idgraphcateg');
  223. $thirdpartycateggraph .= $dolgraph->show();
  224. } else {
  225. while ($i < $num) {
  226. $obj = $db->fetch_object($result);
  227. $thirdpartycateggraph .= '<tr class="oddeven"><td>'.$obj->label.'</td><td>'.$obj->nb.'</td></tr>';
  228. $total += $obj->nb;
  229. $i++;
  230. }
  231. }
  232. }
  233. $thirdpartycateggraph .= '</td></tr>';
  234. $thirdpartycateggraph .= '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">';
  235. $thirdpartycateggraph .= $total;
  236. $thirdpartycateggraph .= '</td></tr>';
  237. $thirdpartycateggraph .= '</table>';
  238. $thirdpartycateggraph .= '</div>';
  239. } else {
  240. $thirdpartycateggraph = '';
  241. }
  242. /*
  243. * Latest modified third parties
  244. */
  245. $max = 15;
  246. $sql = "SELECT s.rowid, s.nom as name, s.email, s.client, s.fournisseur";
  247. $sql .= ", s.code_client";
  248. $sql .= ", s.code_fournisseur";
  249. if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
  250. $sql .= ", spe.accountancy_code_supplier as code_compta_fournisseur";
  251. $sql .= ", spe.accountancy_code_customer as code_compta";
  252. } else {
  253. $sql .= ", s.code_compta_fournisseur";
  254. $sql .= ", s.code_compta";
  255. }
  256. $sql .= ", s.logo";
  257. $sql .= ", s.entity";
  258. $sql .= ", s.canvas, s.tms as date_modification, s.status as status";
  259. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  260. if (getDolGlobalString('MAIN_COMPANY_PERENTITY_SHARED')) {
  261. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity);
  262. }
  263. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  264. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  265. }
  266. $sql .= ' WHERE s.entity IN ('.getEntity('societe').')';
  267. if (!$user->hasRight('societe', 'client', 'voir') && !$socid) {
  268. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  269. }
  270. if (!$user->hasRight('fournisseur', 'lire')) {
  271. $sql .= " AND (s.fournisseur != 1 OR s.client != 0)";
  272. }
  273. // Add where from hooks
  274. $parameters = array('socid' => $socid);
  275. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
  276. if (empty($reshook)) {
  277. if ($socid > 0) {
  278. $sql .= " AND s.rowid = ".((int) $socid);
  279. }
  280. }
  281. $sql .= $hookmanager->resPrint;
  282. $sql .= $db->order("s.tms", "DESC");
  283. $sql .= $db->plimit($max, 0);
  284. //print $sql;
  285. $lastmodified="";
  286. $result = $db->query($sql);
  287. if ($result) {
  288. $num = $db->num_rows($result);
  289. $i = 0;
  290. if ($num > 0) {
  291. $transRecordedType = $langs->trans("LastModifiedThirdParties", $max);
  292. $lastmodified = "\n<!-- last thirdparties modified -->\n";
  293. $lastmodified .= '<div class="div-table-responsive-no-min">';
  294. $lastmodified .= '<table class="noborder centpercent">';
  295. $lastmodified .= '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</th>';
  296. $lastmodified .= '<th>&nbsp;</th>';
  297. $lastmodified .= '<th class="right"><a href="'.DOL_URL_ROOT.'/societe/list.php?sortfield=s.tms&sortorder=DESC">'.$langs->trans("FullList").'</th>';
  298. $lastmodified .= '</tr>'."\n";
  299. while ($i < $num) {
  300. $objp = $db->fetch_object($result);
  301. $thirdparty_static->id = $objp->rowid;
  302. $thirdparty_static->name = $objp->name;
  303. $thirdparty_static->client = $objp->client;
  304. $thirdparty_static->fournisseur = $objp->fournisseur;
  305. $thirdparty_static->logo = $objp->logo;
  306. $thirdparty_static->date_modification = $db->jdate($objp->date_modification);
  307. $thirdparty_static->status = $objp->status;
  308. $thirdparty_static->code_client = $objp->code_client;
  309. $thirdparty_static->code_fournisseur = $objp->code_fournisseur;
  310. $thirdparty_static->canvas = $objp->canvas;
  311. $thirdparty_static->email = $objp->email;
  312. $thirdparty_static->entity = $objp->entity;
  313. $thirdparty_static->code_compta_fournisseur = $objp->code_compta_fournisseur;
  314. $thirdparty_static->code_compta = $objp->code_compta;
  315. $lastmodified .= '<tr class="oddeven">';
  316. // Name
  317. $lastmodified .= '<td class="nowrap tdoverflowmax200">';
  318. $lastmodified .= $thirdparty_static->getNomUrl(1);
  319. $lastmodified .= "</td>\n";
  320. // Type
  321. $lastmodified .= '<td class="center">';
  322. $lastmodified .= $thirdparty_static->getTypeUrl();
  323. $lastmodified .= '</td>';
  324. // Last modified date
  325. $lastmodified .= '<td class="right tddate" title="'.dol_escape_htmltag($langs->trans("DateModification").' '.dol_print_date($thirdparty_static->date_modification, 'dayhour', 'tzuserrel')).'">';
  326. $lastmodified .= dol_print_date($thirdparty_static->date_modification, 'day', 'tzuserrel');
  327. $lastmodified .= "</td>";
  328. $lastmodified .= '<td class="right nowrap">';
  329. $lastmodified .= $thirdparty_static->getLibStatut(3);
  330. $lastmodified .= "</td>";
  331. $lastmodified .= "</tr>\n";
  332. $i++;
  333. }
  334. $db->free($result);
  335. $lastmodified .= "</table>\n";
  336. $lastmodified .= '</div>';
  337. $lastmodified .= "<!-- End last thirdparties modified -->\n";
  338. }
  339. } else {
  340. dol_print_error($db);
  341. }
  342. //print '</div></div></div>';
  343. // boxes
  344. print '<div class="clearboth"></div>';
  345. print '<div class="fichecenter fichecenterbis">';
  346. $boxlist = '<div class="twocolumns">';
  347. $boxlist .= '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
  348. $boxlist .= $thirdpartygraph;
  349. $boxlist .= '<br>';
  350. $boxlist .= $thirdpartycateggraph;
  351. $boxlist .= '<br>';
  352. $boxlist .= $resultboxes['boxlista'];
  353. $boxlist .= '</div>'."\n";
  354. $boxlist .= '<div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
  355. $boxlist .= $lastmodified;
  356. $boxlist .= '<br>';
  357. $boxlist .= $resultboxes['boxlistb'];
  358. $boxlist .= '</div>'."\n";
  359. $boxlist .= '</div>';
  360. print $boxlist;
  361. print '</div>';
  362. $parameters = array('user' => $user);
  363. $reshook = $hookmanager->executeHooks('dashboardThirdparties', $parameters, $thirdparty_static); // Note that $action and $object may have been modified by hook
  364. // End of page
  365. llxFooter();
  366. $db->close();