PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/societe/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 270 lines | 189 code | 38 blank | 43 comment | 74 complexity | be4d5acbb798753f0516ef4805d89df8 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2010-2011 Herve Prot <herve.prot@symeos.com>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/societe/index.php
  22. * \ingroup societe
  23. * \brief Home page for third parties area
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
  27. $langs->load("companies");
  28. $socid = GETPOST('socid','int');
  29. if ($user->societe_id) $socid=$user->societe_id;
  30. // Security check
  31. $result=restrictedArea($user,'societe',0,'','','','');
  32. $thirdparty_static = new Societe($db);
  33. /*
  34. * View
  35. */
  36. $transAreaType = $langs->trans("ThirdPartiesArea");
  37. $helpurl='EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Terceros';
  38. llxHeader("",$langs->trans("ThirdParties"),$helpurl);
  39. print_fiche_titre($transAreaType);
  40. print '<table border="0" width="100%" class="notopnoleftnoright">';
  41. print '<tr><td valign="top" width="30%" class="notopnoleft">';
  42. /*
  43. * Search area
  44. */
  45. $rowspan=2;
  46. print '<form method="post" action="'.DOL_URL_ROOT.'/societe/societe.php">';
  47. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  48. print '<table class="noborder nohover" width="100%">';
  49. print '<tr class="liste_titre">';
  50. print '<td colspan="3">'.$langs->trans("Search").'</td></tr>';
  51. print "<tr ".$bc[false]."><td>";
  52. print $langs->trans("Name").':</td><td><input class="flat" type="text" size="14" name="search_nom_only"></td>';
  53. print '<td rowspan="'.$rowspan.'"><input type="submit" class="button" value="'.$langs->trans("Search").'"></td></tr>';
  54. print "<tr ".$bc[false]."><td>";
  55. print $langs->trans("Other").':</td><td><input class="flat" type="text" size="14" name="search_all"></td>';
  56. //print '<td><input type="submit" class="button" value="'.$langs->trans("Search").'"></td>';
  57. print '</tr>';
  58. print "</table></form><br>";
  59. /*
  60. * Statistics area
  61. */
  62. $third = array(
  63. 'customer' => 0,
  64. 'prospect' => 0,
  65. 'supplier' => 0,
  66. 'other' =>0
  67. );
  68. $total=0;
  69. $sql = "SELECT s.rowid, s.client, s.fournisseur";
  70. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  71. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  72. $sql.= ' WHERE s.entity IN ('.getEntity('societe', 1).')';
  73. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  74. if ($socid) $sql.= " AND s.rowid = ".$socid;
  75. if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
  76. //print $sql;
  77. $result = $db->query($sql);
  78. if ($result)
  79. {
  80. while ($objp = $db->fetch_object($result))
  81. {
  82. $found=0;
  83. if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS) && ($objp->client == 1 || $objp->client == 3)) { $found=1; $third['customer']++; }
  84. if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS) && ($objp->client == 2 || $objp->client == 3)) { $found=1; $third['prospect']++; }
  85. if (! empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS) && $objp->fournisseur) { $found=1; $third['supplier']++; }
  86. if (! empty($conf->societe->enabled) && $objp->client == 0 && $objp->fournisseur == 0) { $found=1; $third['other']++; }
  87. if ($found) $total++;
  88. }
  89. }
  90. else dol_print_error($db);
  91. print '<table class="noborder" width="100%">';
  92. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").'</th></tr>';
  93. 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))
  94. {
  95. print '<tr><td align="center">';
  96. $dataseries=array();
  97. if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS)) $dataseries[]=array('label'=>$langs->trans("Prospects"),'data'=>round($third['prospect']));
  98. if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Customers"),'data'=>round($third['customer']));
  99. if (! empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS)) $dataseries[]=array('label'=>$langs->trans("Suppliers"),'data'=>round($third['supplier']));
  100. if (! empty($conf->societe->enabled)) $dataseries[]=array('label'=>$langs->trans("Others"),'data'=>round($third['other']));
  101. $data=array('series'=>$dataseries);
  102. dol_print_graph('stats',300,180,$data,1,'pie',0);
  103. print '</td></tr>';
  104. }
  105. else
  106. {
  107. if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS_STATS))
  108. {
  109. $statstring = "<tr $bc[0]>";
  110. $statstring.= '<td><a href="'.DOL_URL_ROOT.'/comm/prospect/list.php">'.$langs->trans("Prospects").'</a></td><td align="right">'.round($third['prospect']).'</td>';
  111. $statstring.= "</tr>";
  112. }
  113. if (! empty($conf->societe->enabled) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS_STATS))
  114. {
  115. $statstring.= "<tr $bc[1]>";
  116. $statstring.= '<td><a href="'.DOL_URL_ROOT.'/comm/list.php">'.$langs->trans("Customers").'</a></td><td align="right">'.round($third['customer']).'</td>';
  117. $statstring.= "</tr>";
  118. }
  119. if (! empty($conf->fournisseur->enabled) && empty($conf->global->SOCIETE_DISABLE_SUPPLIERS_STATS))
  120. {
  121. $statstring2 = "<tr $bc[0]>";
  122. $statstring2.= '<td><a href="'.DOL_URL_ROOT.'/fourn/liste.php">'.$langs->trans("Suppliers").'</a></td><td align="right">'.round($third['supplier']).'</td>';
  123. $statstring2.= "</tr>";
  124. }
  125. print $statstring;
  126. print $statstring2;
  127. }
  128. print '<tr class="liste_total"><td>'.$langs->trans("UniqueThirdParties").'</td><td align="right">';
  129. print $total;
  130. print '</td></tr>';
  131. print '</table>';
  132. print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
  133. /*
  134. * Last third parties modified
  135. */
  136. $max=15;
  137. $sql = "SELECT s.rowid, s.nom as name, s.client, s.fournisseur, s.canvas, s.tms as datem, s.status as status";
  138. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  139. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  140. $sql.= ' WHERE s.entity IN ('.getEntity('societe', 1).')';
  141. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  142. if ($socid) $sql.= " AND s.rowid = ".$socid;
  143. if (! $user->rights->fournisseur->lire) $sql.=" AND (s.fournisseur != 1 OR s.client != 0)";
  144. $sql.= $db->order("s.tms","DESC");
  145. $sql.= $db->plimit($max,0);
  146. //print $sql;
  147. $result = $db->query($sql);
  148. if ($result)
  149. {
  150. $num = $db->num_rows($result);
  151. $i = 0;
  152. if ($num > 0)
  153. {
  154. $transRecordedType = $langs->trans("LastModifiedThirdParties",$max);
  155. print '<table class="noborder" width="100%">';
  156. print '<tr class="liste_titre"><th colspan="2">'.$transRecordedType.'</td>';
  157. print '<th>&nbsp;</td>';
  158. print '<th align="right">'.$langs->trans('Status').'</td>';
  159. print '</tr>';
  160. $var=True;
  161. while ($i < $num)
  162. {
  163. $objp = $db->fetch_object($result);
  164. $var=!$var;
  165. print "<tr $bc[$var]>";
  166. // Name
  167. print '<td nowrap="nowrap">';
  168. $thirdparty_static->id=$objp->rowid;
  169. $thirdparty_static->name=$objp->name;
  170. $thirdparty_static->client=$objp->client;
  171. $thirdparty_static->fournisseur=$objp->fournisseur;
  172. $thirdparty_static->datem=$db->jdate($objp->datem);
  173. $thirdparty_static->status=$objp->status;
  174. $thirdparty_static->canvas=$objp->canvas;
  175. print $thirdparty_static->getNomUrl(1);
  176. print "</td>\n";
  177. // Type
  178. print '<td align="center">';
  179. if ($thirdparty_static->client==1 || $thirdparty_static->client==3)
  180. {
  181. $thirdparty_static->name=$langs->trans("Customer");
  182. print $thirdparty_static->getNomUrl(0,'customer');
  183. }
  184. if ($thirdparty_static->client == 3 && empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print " / ";
  185. if (($thirdparty_static->client==2 || $thirdparty_static->client==3) && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
  186. {
  187. $thirdparty_static->name=$langs->trans("Prospect");
  188. print $thirdparty_static->getNomUrl(0,'prospect');
  189. }
  190. if ($conf->fournisseur->enabled && $thirdparty_static->fournisseur)
  191. {
  192. if ($thirdparty_static->client) print " / ";
  193. $thirdparty_static->name=$langs->trans("Supplier");
  194. print $thirdparty_static->getNomUrl(0,'supplier');
  195. }
  196. print '</td>';
  197. // Last modified date
  198. print '<td align="right">';
  199. print dol_print_date($thirdparty_static->datem,'day');
  200. print "</td>";
  201. print '<td align="right" nowrap="nowrap">';
  202. print $thirdparty_static->getLibStatut(3);
  203. print "</td>";
  204. print "</tr>\n";
  205. $i++;
  206. }
  207. $db->free();
  208. print "</table><br>";
  209. /* Print Graph */
  210. if($conf->highcharts->enabled && $user->rights->highcharts->read && $conf->societe->enabled && $conf->categorie->enabled)
  211. {
  212. dol_include_once("/highCharts/class/highCharts.class.php");
  213. $langs->load("highcharts@highCharts");
  214. $graph=new HighCharts($db);
  215. $graph->width="100%";
  216. $graph->height="300px";
  217. $graph->name="graphPriority";
  218. $graph->label=$langs->trans("graphPriorityTiers");
  219. if($user->rights->highcharts->all && $user->rights->societe->client->voir)
  220. $graph->mine=0;
  221. $graph->graphPriorityTiers();
  222. }
  223. }
  224. }
  225. else
  226. {
  227. dol_print_error($db);
  228. }
  229. print '</td></tr></table>';
  230. llxFooter();
  231. $db->close();
  232. ?>