PageRenderTime 46ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/comm/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 779 lines | 521 code | 97 blank | 161 comment | 134 complexity | 6309c4981b0761578d78af26ba7d1446 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2001-2005 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/comm/index.php
  22. * \ingroup commercial
  23. * \brief Home page of commercial area
  24. */
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php';
  30. if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  31. if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
  32. if (! $user->rights->societe->lire) accessforbidden();
  33. $langs->load("commercial");
  34. $action=GETPOST('action', 'alpha');
  35. $bid=GETPOST('bid', 'int');
  36. // Securite acces client
  37. $socid=GETPOST('socid','int');
  38. if (isset($user->societe_id) && $user->societe_id > 0)
  39. {
  40. $action = '';
  41. $socid = $user->societe_id;
  42. }
  43. $max=5;
  44. $now=dol_now();
  45. /*
  46. * Actions
  47. */
  48. if ($action == 'add_bookmark' && ! empty($socid))
  49. {
  50. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE fk_soc = ".$db->escape($socid)." AND fk_user=".$user->id;
  51. if (! $db->query($sql) )
  52. {
  53. dol_print_error($db);
  54. }
  55. $sql = "INSERT INTO ".MAIN_DB_PREFIX."bookmark (fk_soc, dateb, fk_user) VALUES (".$db->escape($socid).", ".$db->idate($now).",".$user->id.");";
  56. if (! $db->query($sql) )
  57. {
  58. dol_print_error($db);
  59. }
  60. }
  61. if ($action == 'del_bookmark' && ! empty($bid))
  62. {
  63. $sql = "DELETE FROM ".MAIN_DB_PREFIX."bookmark WHERE rowid=".$db->escape($bid);
  64. $result = $db->query($sql);
  65. }
  66. /*
  67. * View
  68. */
  69. $now=dol_now();
  70. $form = new Form($db);
  71. $formfile = new FormFile($db);
  72. $companystatic=new Societe($db);
  73. if (! empty($conf->propal->enabled)) $propalstatic=new Propal($db);
  74. llxHeader();
  75. print_fiche_titre($langs->trans("CustomerArea"));
  76. print '<table border="0" width="100%" class="notopnoleftnoright">';
  77. print '<tr>';
  78. //if ((! empty($conf->propal->enabled) && $user->rights->propale->lire) ||
  79. // (! empty($conf->contrat->enabled) && $user->rights->contrat->lire) ||
  80. // (! empty($conf->commande->enabled) && $user->rights->commande->lire))
  81. //{
  82. print '<td valign="top" width="30%" class="notopnoleft">';
  83. //}
  84. // Recherche Propal
  85. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  86. {
  87. $var=false;
  88. print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/list.php">';
  89. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  90. print '<table class="noborder nohover" width="100%">';
  91. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAProposal").'</td></tr>';
  92. print '<tr '.$bc[$var].'>';
  93. print '<td nowrap>'.$langs->trans("Ref").':</td><td><input type="text" class="flat" name="sf_ref" size="18"></td>';
  94. print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  95. print '<tr '.$bc[$var].'><td nowrap>'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  96. print '</tr>';
  97. print "</table></form>\n";
  98. print "<br>\n";
  99. }
  100. /*
  101. * Recherche Contrat
  102. */
  103. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire)
  104. {
  105. $var=false;
  106. print '<form method="post" action="'.DOL_URL_ROOT.'/contrat/liste.php">';
  107. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  108. print '<table class="noborder nohover" width="100%">';
  109. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchAContract").'</td></tr>';
  110. print '<tr '.$bc[$var].'>';
  111. print '<td nowrap>'.$langs->trans("Ref").':</td><td><input type="text" class="flat" name="search_contract" size="18"></td>';
  112. print '<td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  113. print '<tr '.$bc[$var].'><td nowrap>'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  114. print '</tr>';
  115. print "</table></form>\n";
  116. print "<br>";
  117. }
  118. $NBMAX=3;
  119. $max=3;
  120. /*
  121. * Prospects par status
  122. *
  123. */
  124. if($conf->highcharts->enabled && $user->rights->highcharts->read )
  125. {
  126. dol_include_once("/highCharts/class/highCharts.class.php");
  127. $langs->load("highcharts@highCharts");
  128. $graph=new HighCharts($db);
  129. $graph->width="100%";
  130. $graph->height="300px";
  131. $graph->name="ProspectionStatus";
  132. $graph->label=$langs->trans("ProspectionStatus");
  133. if($user->rights->highcharts->all)
  134. {
  135. $graph->mine=0;
  136. }
  137. $graph->ProspectStatus();
  138. }
  139. //print '<br>';
  140. $prospect=new Prospect($db);
  141. $prospect->ProspectStatus();
  142. /*
  143. * Last modified customers or prospects
  144. */
  145. if ($conf->societe->enabled && $user->rights->societe->lire)
  146. {
  147. $langs->load("boxes");
  148. $sql = "SELECT s.rowid,s.nom,s.client,s.datec,s.tms";
  149. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  150. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  151. $sql.= " WHERE s.client IN (1, 2, 3)";
  152. $sql.= " AND s.entity = ".$conf->entity;
  153. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  154. if ($socid) $sql.= " AND s.rowid = $socid";
  155. $sql .= " ORDER BY s.tms DESC";
  156. $sql .= $db->plimit($max, 0);
  157. $resql = $db->query($sql);
  158. if ($resql)
  159. {
  160. $var=false;
  161. $num = $db->num_rows($resql);
  162. $i = 0;
  163. print '<table class="noborder" width="100%">';
  164. print '<tr class="liste_titre">';
  165. print '<td colspan="2">'.$langs->trans("BoxTitleLastCustomersOrProspects",$max).'</td>';
  166. print '<td align="right">'.$langs->trans("DateModificationShort").'</td>';
  167. print '</tr>';
  168. if ($num)
  169. {
  170. $company=new Societe($db);
  171. while ($i < $num)
  172. {
  173. $objp = $db->fetch_object($resql);
  174. $company->id=$objp->rowid;
  175. $company->nom=$objp->nom;
  176. $company->client=$objp->client;
  177. print '<tr '.$bc[$var].'>';
  178. print '<td nowrap="nowrap">'.$company->getNomUrl(1,'customer',25).'</td>';
  179. print '<td align="right" nowrap>';
  180. if ($objp->client == 2 || $objp->client == 3) print $langs->trans("Prospect");
  181. if ($objp->client == 3) print ' / ';
  182. if ($objp->client == 1 || $objp->client == 3) print $langs->trans("Customer");
  183. print "</td>";
  184. print '<td align="right" nowrap>'.dol_print_date($db->jdate($objp->tms),'day')."</td>";
  185. print '</tr>';
  186. $i++;
  187. $var=!$var;
  188. }
  189. print "</table><br>";
  190. $db->free($resql);
  191. }
  192. else
  193. {
  194. print '<tr '.$bc[$var].'><td colspan="3">'.$langs->trans("None").'</td></tr>';
  195. print "</table><br>";
  196. }
  197. }
  198. }
  199. /*
  200. * Draft proposals
  201. */
  202. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  203. {
  204. $sql = "SELECT p.rowid, p.ref, p.total_ht, s.rowid as socid, s.nom as name, s.client, s.canvas";
  205. $sql.= " FROM ".MAIN_DB_PREFIX."propal as p";
  206. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  207. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  208. $sql.= " WHERE p.fk_statut = 0";
  209. $sql.= " AND p.fk_soc = s.rowid";
  210. $sql.= " AND p.entity = ".$conf->entity;
  211. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  212. if ($socid) $sql.= " AND s.rowid = ".$socid;
  213. $resql=$db->query($sql);
  214. if ($resql)
  215. {
  216. print '<table class="noborder" width="100%">';
  217. print '<tr class="liste_titre">';
  218. print '<td colspan="3">'.$langs->trans("ProposalsDraft").'</td></tr>';
  219. $total = 0;
  220. $num = $db->num_rows($resql);
  221. if ($num > 0)
  222. {
  223. $i = 0;
  224. $var=true;
  225. while ($i < $num)
  226. {
  227. $obj = $db->fetch_object($resql);
  228. $var=!$var;
  229. print '<tr '.$bc[$var].'><td nowrap="nowrap">';
  230. $propalstatic->id=$obj->rowid;
  231. $propalstatic->ref=$obj->ref;
  232. print $propalstatic->getNomUrl(1);
  233. print '</td>';
  234. print '<td nowrap="nowrap">';
  235. $companystatic->id=$obj->socid;
  236. $companystatic->name=$obj->name;
  237. $companystatic->client=$obj->client;
  238. $companystatic->canvas=$obj->canvas;
  239. print $companystatic->getNomUrl(1,'customer',16);
  240. print '</td>';
  241. print '<td align="right" nowrap="nowrap">'.price($obj->total_ht).'</td></tr>';
  242. $i++;
  243. $total += $obj->total_ht;
  244. }
  245. if ($total>0)
  246. {
  247. $var=!$var;
  248. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  249. }
  250. }
  251. print "</table><br>";
  252. $db->free($resql);
  253. }
  254. else
  255. {
  256. dol_print_error($db);
  257. }
  258. }
  259. /*
  260. * Draft orders
  261. */
  262. if (! empty($conf->commande->enabled) && $user->rights->commande->lire)
  263. {
  264. $langs->load("orders");
  265. $sql = "SELECT c.rowid, c.ref, c.total_ttc, s.rowid as socid, s.nom as name, s.client, s.canvas";
  266. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  267. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  268. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  269. $sql.= " WHERE c.fk_soc = s.rowid";
  270. $sql.= " AND c.fk_statut = 0";
  271. $sql.= " AND c.entity = ".$conf->entity;
  272. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  273. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  274. $resql = $db->query($sql);
  275. if ($resql)
  276. {
  277. print '<table class="noborder" width="100%">';
  278. print '<tr class="liste_titre">';
  279. print '<td colspan="3">'.$langs->trans("DraftOrders").'</td></tr>';
  280. $total = 0;
  281. $num = $db->num_rows($resql);
  282. if ($num)
  283. {
  284. $i = 0;
  285. $var = true;
  286. while ($i < $num)
  287. {
  288. $var=!$var;
  289. $obj = $db->fetch_object($resql);
  290. print '<tr '.$bc[$var].'><td nowrap="nowrap"><a href="../commande/fiche.php?id='.$obj->rowid.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.'</a></td>';
  291. print '<td nowrap="nowrap">';
  292. $companystatic->id=$obj->socid;
  293. $companystatic->name=$obj->name;
  294. $companystatic->client=$obj->client;
  295. $companystatic->canvas=$obj->canvas;
  296. print $companystatic->getNomUrl(1,'customer',16);
  297. print '</td>';
  298. print '<td align="right" nowrap="nowrap">'.price($obj->total_ttc).'</td></tr>';
  299. $i++;
  300. $total += $obj->total_ttc;
  301. }
  302. if ($total>0)
  303. {
  304. $var=!$var;
  305. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td colspan="2" align="right">'.price($total)."</td></tr>";
  306. }
  307. }
  308. print "</table><br>";
  309. $db->free($resql);
  310. }
  311. }
  312. if ((! empty($conf->propal->enabled) && $user->rights->propale->lire) ||
  313. (! empty($conf->contrat->enabled) && $user->rights->contrat->lire) ||
  314. (! empty($conf->commande->enabled) && $user->rights->commande->lire))
  315. {
  316. $socstatic=new Societe($db);
  317. $leadstatic=new Lead($db);
  318. if($conf->rights->lead->all)
  319. $mine=1;
  320. else
  321. $mine=0;
  322. $leadsListId = $leadstatic->getLeadsAuthorizedForUser($user,$mine,1);
  323. print_lead_array($db,1,$socid,$leadsListId);
  324. }
  325. $NBMAX=3;
  326. $max=3;
  327. /*
  328. * Last modified proposals
  329. */
  330. /*
  331. if ($conf->propal->enabled && $user->rights->propale->lire)
  332. {
  333. $sql = "SELECT s.nom as name, s.rowid as socid, s.client, s.canvas, p.rowid as propalid, p.total_ht, p.ref, p.fk_statut, p.datep as dp";
  334. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  335. $sql.= ", ".MAIN_DB_PREFIX."propal as p";
  336. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  337. $sql.= " WHERE p.fk_soc = s.rowid";
  338. $sql.= " AND p.entity = ".$conf->entity;
  339. //$sql.= " AND p.fk_statut > 1";
  340. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  341. if ($socid) $sql.= " AND s.rowid = ".$socid;
  342. $sql.= " ORDER BY p.datep DESC";
  343. $sql.= $db->plimit($NBMAX, 0);
  344. $resql=$db->query($sql);
  345. if ($resql)
  346. {
  347. $num = $db->num_rows($resql);
  348. $i = 0;
  349. print '<table class="noborder" width="100%">';
  350. print '<tr class="liste_titre"><td colspan="6">'.$langs->trans("LastModifiedProposals",$NBMAX).'</td></tr>';
  351. $var=False;
  352. while ($i < $num)
  353. {
  354. $objp = $db->fetch_object($resql);
  355. print '<tr '.$bc[$var].'>';
  356. // Ref
  357. print '<td nowrap="nowrap" width="140">';
  358. $propalstatic->id=$objp->propalid;
  359. $propalstatic->ref=$objp->ref;
  360. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  361. print '<td class="nobordernopadding" nowrap="nowrap">';
  362. print $propalstatic->getNomUrl(1);
  363. print '</td>';
  364. print '<td width="18" class="nobordernopadding" nowrap="nowrap">';
  365. // TODO se baser sur datep ou fin_validite ?
  366. if (($objp->fk_statut <= 1) && ($db->jdate($objp->dp) < ($now - $conf->propal->cloture->warning_delay))) print img_warning($langs->trans("Late"));
  367. print '</td>';
  368. print '<td width="16" align="center" class="nobordernopadding">';
  369. $filename=dol_sanitizeFileName($objp->ref);
  370. $filedir=$conf->propale->dir_output . '/' . dol_sanitizeFileName($objp->ref);
  371. $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->propalid;
  372. $formfile->show_documents('propal',$filename,$filedir,$urlsource,'','','',1,'',1);
  373. print '</td></tr></table>';
  374. print '</td>';
  375. print '<td align="left">';
  376. $companystatic->id=$objp->socid;
  377. $companystatic->name=$objp->name;
  378. $companystatic->client=$objp->client;
  379. $companystatic->canvas=$objp->canvas;
  380. print $companystatic->getNomUrl(1,'customer',44);
  381. print '</td>';
  382. print '<td align="right">';
  383. print dol_print_date($db->jdate($objp->dp),'day').'</td>'."\n";
  384. print '<td align="right">'.price($objp->total_ht).'</td>'."\n";
  385. print '<td align="center" width="14">'.$propalstatic->LibStatut($objp->fk_statut,3).'</td>'."\n";
  386. print '</tr>'."\n";
  387. $i++;
  388. $var=!$var;
  389. }
  390. print "</table><br>";
  391. $db->free($resql);
  392. }
  393. else
  394. {
  395. dol_print_error($db,'');
  396. }
  397. }
  398. */
  399. //if (($conf->propal->enabled && $user->rights->propale->lire) ||
  400. // ($conf->contrat->enabled && $user->rights->contrat->lire) ||
  401. // ($conf->commande->enabled && $user->rights->commande->lire))
  402. //{
  403. print '</td>';
  404. print '<td valign="top" width="70%" class="notopnoleftnoright">';
  405. //}
  406. //else
  407. //{
  408. // print '<td valign="top" width="100%" class="notopnoleftnoright">';
  409. //}
  410. /* Print Portefeuille Prospection */
  411. if ($user->rights->agenda->myactions->read && $conf->highcharts->enabled && $user->rights->highcharts->read)
  412. {
  413. $graph->name="graphProspectionState";
  414. $graph->label=$langs->trans("ProspectionStatus");
  415. if($user->rights->highcharts->all && $user->rights->agenda->allactions->read)
  416. $graph->mine=0;
  417. $graph->graphProspectionState();
  418. }
  419. /* Print Activity Graph */
  420. if ($user->rights->agenda->myactions->read && $conf->highcharts->enabled && $user->rights->highcharts->read)
  421. {
  422. $graph->label=$langs->trans("graphMonthTaskDone").' '.(isset($_GET["month"])?$_GET["month"]:strftime("%m",dol_now()))."/".(isset($_GET["year"])?$_GET["year"]:strftime("%Y",dol_now()));
  423. $graph->name="graphMonthTaskDone";
  424. $graph->height="350px";
  425. if($user->rights->highcharts->all && $user->rights->agenda->myactions->all)
  426. $graph->mine=0;
  427. $graph->graphTaskDone(isset($_GET["month"])?$_GET["month"]:strftime("%m",dol_now()),isset($_GET["year"])?$_GET["year"]:strftime("%Y",dol_now()));
  428. }
  429. $NBMAX=3;
  430. $max=3;
  431. /*
  432. * Last modified customers or prospects
  433. */
  434. if (! empty($conf->societe->enabled) && $user->rights->societe->lire)
  435. {
  436. $langs->load("boxes");
  437. $sql = "SELECT s.rowid, s.nom as name, s.client, s.datec, s.tms, s.canvas";
  438. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  439. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  440. $sql.= " WHERE s.client IN (1, 2, 3)";
  441. $sql.= " AND s.entity IN (".getEntity($companystatic->element, 1).")";
  442. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  443. if ($socid) $sql.= " AND s.rowid = $socid";
  444. $sql .= " ORDER BY s.tms DESC";
  445. $sql .= $db->plimit($max, 0);
  446. $resql = $db->query($sql);
  447. if ($resql)
  448. {
  449. $var=false;
  450. $num = $db->num_rows($resql);
  451. $i = 0;
  452. print '<table class="noborder" width="100%">';
  453. print '<tr class="liste_titre">';
  454. print '<td colspan="2">'.$langs->trans("BoxTitleLastCustomersOrProspects",$max).'</td>';
  455. print '<td align="right">'.$langs->trans("DateModificationShort").'</td>';
  456. print '</tr>';
  457. if ($num)
  458. {
  459. while ($i < $num)
  460. {
  461. $objp = $db->fetch_object($resql);
  462. $companystatic->id=$objp->rowid;
  463. $companystatic->name=$objp->name;
  464. $companystatic->client=$objp->client;
  465. $companystatic->canvas=$objp->canvas;
  466. print '<tr '.$bc[$var].'>';
  467. print '<td nowrap="nowrap">'.$companystatic->getNomUrl(1,'customer',48).'</td>';
  468. print '<td align="right" nowrap>';
  469. if ($objp->client == 2 || $objp->client == 3) print $langs->trans("Prospect");
  470. if ($objp->client == 3) print ' / ';
  471. if ($objp->client == 1 || $objp->client == 3) print $langs->trans("Customer");
  472. print "</td>";
  473. print '<td align="right" nowrap>'.dol_print_date($db->jdate($objp->tms),'day')."</td>";
  474. print '</tr>';
  475. $i++;
  476. $var=!$var;
  477. }
  478. $db->free($resql);
  479. }
  480. else
  481. {
  482. print '<tr '.$bc[$var].'><td colspan="3">'.$langs->trans("None").'</td></tr>';
  483. }
  484. print "</table><br>";
  485. }
  486. }
  487. // Last suppliers
  488. if (! empty($conf->fournisseur->enabled) && $user->rights->societe->lire)
  489. {
  490. $langs->load("boxes");
  491. $sql = "SELECT s.nom as name, s.rowid, s.datec as dc, s.canvas, s.tms as dm";
  492. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  493. if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  494. $sql.= " WHERE s.fournisseur = 1";
  495. $sql.= " AND s.entity IN (".getEntity($companystatic->element, 1).")";
  496. if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  497. if ($socid) $sql.= " AND s.rowid = ".$socid;
  498. $sql.= " ORDER BY s.datec DESC";
  499. $sql.= $db->plimit($max, 0);
  500. $result = $db->query($sql);
  501. if ($result)
  502. {
  503. $var=false;
  504. $num = $db->num_rows($result);
  505. $i = 0;
  506. print '<table class="noborder" width="100%">';
  507. print '<tr class="liste_titre"><td>'.$langs->trans("BoxTitleLastModifiedSuppliers",min($max,$num)).'</td>';
  508. print '<td align="right">'.$langs->trans("DateModificationShort").'</td>';
  509. print '</tr>';
  510. if ($num)
  511. {
  512. while ($i < $num && $i < $max)
  513. {
  514. $objp = $db->fetch_object($result);
  515. $companystatic->id=$objp->rowid;
  516. $companystatic->name=$objp->name;
  517. $companystatic->canvas=$objp->canvas;
  518. print '<tr '.$bc[$var].'>';
  519. print '<td nowrap="nowrap">'.$companystatic->getNomUrl(1,'supplier',44).'</td>';
  520. print '<td align="right">'.dol_print_date($db->jdate($objp->dm),'day').'</td>';
  521. print '</tr>';
  522. $var=!$var;
  523. $i++;
  524. }
  525. }
  526. else
  527. {
  528. print '<tr '.$bc[$var].'><td colspan="2">'.$langs->trans("None").'</td></tr>';
  529. }
  530. print '</table><br>';
  531. }
  532. }
  533. /*
  534. * Last actions
  535. */
  536. if ($user->rights->agenda->myactions->read)
  537. {
  538. show_array_last_actions_done($max);
  539. }
  540. /*
  541. * Actions to do
  542. */
  543. if ($user->rights->agenda->myactions->read)
  544. {
  545. show_array_actions_to_do(10);
  546. }
  547. /*
  548. * Last contracts
  549. */
  550. if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire && 0) // TODO A REFAIRE DEPUIS NOUVEAU CONTRAT
  551. {
  552. $langs->load("contracts");
  553. $sql = "SELECT s.nom as name, s.rowid, s.canvas, ";
  554. $sql.= " c.statut, c.rowid as contratid, p.ref, c.mise_en_service as datemes, c.fin_validite as datefin, c.date_cloture as dateclo";
  555. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  556. $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
  557. $sql.= ", ".MAIN_DB_PREFIX."product as p";
  558. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  559. $sql.= " WHERE c.fk_soc = s.rowid";
  560. $sql.= " AND c.entity = ".$conf->entity;
  561. $sql.= " AND c.fk_product = p.rowid";
  562. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  563. if ($socid) $sql.= " AND s.rowid = ".$socid;
  564. $sql.= " ORDER BY c.tms DESC";
  565. $sql.= $db->plimit(5, 0);
  566. $resql=$db->query($sql);
  567. if ($resql)
  568. {
  569. $num = $db->num_rows($resql);
  570. if ($num > 0)
  571. {
  572. print '<table class="noborder" width="100%">';
  573. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("LastContracts",5).'</td></tr>';
  574. $i = 0;
  575. $staticcontrat=new Contrat($db);
  576. $var=false;
  577. while ($i < $num)
  578. {
  579. $obj = $db->fetch_object($resql);
  580. print "<tr ".$bc[$var]."><td><a href=\"../contrat/fiche.php?id=".$obj->contratid."\">".img_object($langs->trans("ShowContract","contract"))." ".$obj->ref."</a></td>";
  581. print '<td>';
  582. $companystatic->id=$objp->rowid;
  583. $companystatic->name=$objp->name;
  584. $companystatic->canvas=$objp->canvas;
  585. print $companystatic->getNomUrl(1,'customer',44);
  586. print '</td>'."\n";
  587. print "<td align=\"right\">".$staticcontrat->LibStatut($obj->statut,3)."</td></tr>\n";
  588. $var=!$var;
  589. $i++;
  590. }
  591. print "</table><br>";
  592. }
  593. }
  594. else
  595. {
  596. dol_print_error($db);
  597. }
  598. }
  599. /*
  600. * Opened proposals
  601. */
  602. if (! empty($conf->propal->enabled) && $user->rights->propal->lire)
  603. {
  604. $langs->load("propal");
  605. $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.total as total_ttc, p.total_ht, p.ref, p.fk_statut, p.datep as dp";
  606. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  607. $sql.= ", ".MAIN_DB_PREFIX."propal as p";
  608. if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  609. $sql.= " WHERE p.fk_soc = s.rowid";
  610. $sql.= " AND p.entity = ".$conf->entity;
  611. $sql.= " AND p.fk_statut = 1";
  612. if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  613. if ($socid) $sql.= " AND s.rowid = ".$socid;
  614. $sql.= " ORDER BY p.rowid DESC";
  615. $result=$db->query($sql);
  616. if ($result)
  617. {
  618. $total = 0;
  619. $num = $db->num_rows($result);
  620. $i = 0;
  621. if ($num > 0)
  622. {
  623. $var=true;
  624. print '<table class="noborder" width="100%">';
  625. print '<tr class="liste_titre"><td colspan="5">'.$langs->trans("ProposalsOpened").'</td></tr>';
  626. while ($i < $num)
  627. {
  628. $obj = $db->fetch_object($result);
  629. $var=!$var;
  630. print '<tr '.$bc[$var].'>';
  631. // Ref
  632. print '<td nowrap="nowrap" width="140">';
  633. $propalstatic->id=$obj->propalid;
  634. $propalstatic->ref=$obj->ref;
  635. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  636. print '<td class="nobordernopadding" nowrap="nowrap">';
  637. print $propalstatic->getNomUrl(1);
  638. print '</td>';
  639. print '<td width="18" class="nobordernopadding" nowrap="nowrap">';
  640. if ($db->jdate($obj->dp) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
  641. print '</td>';
  642. print '<td width="16" align="center" class="nobordernopadding">';
  643. $filename=dol_sanitizeFileName($obj->ref);
  644. $filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  645. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  646. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  647. print '</td></tr></table>';
  648. print "</td>";
  649. print '<td align="left"><a href="fiche.php?socid='.$obj->rowid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,44).'</a></td>'."\n";
  650. print '<td align="right">';
  651. print dol_print_date($db->jdate($obj->dp),'day').'</td>'."\n";
  652. print '<td align="right">'.price($obj->total_ttc).'</td>';
  653. print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut,3).'</td>'."\n";
  654. print '</tr>'."\n";
  655. $i++;
  656. $total += $obj->total_ttc;
  657. }
  658. if ($total>0) {
  659. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td><td>&nbsp;</td></tr>";
  660. }
  661. print "</table><br>";
  662. }
  663. }
  664. else
  665. {
  666. dol_print_error($db);
  667. }
  668. }
  669. print '</td></tr>';
  670. print '</table>';
  671. dol_fiche_end();
  672. llxFooter();
  673. $db->close();
  674. ?>