PageRenderTime 27ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/propal/index.php

https://bitbucket.org/speedealing/speedealing
PHP | 518 lines | 272 code | 57 blank | 189 comment | 42 complexity | 9310b74d0535822bab55f2ab5f245f01 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  1. <?php
  2. /* Copyright (C) 2003-2004 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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/comm/propal/index.php
  21. * \ingroup propal
  22. * \brief Home page of proposal area
  23. */
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  26. require_once DOL_DOCUMENT_ROOT .'/comm/propal/class/propal.class.php';
  27. $langs->load("propal");
  28. $langs->load("companies");
  29. // Security check
  30. $socid=GETPOST('socid','int');
  31. if (isset($user->societe_id) && $user->societe_id > 0)
  32. {
  33. $action = '';
  34. $socid = $user->societe_id;
  35. }
  36. $result = restrictedArea($user, 'propal');
  37. /*
  38. * View
  39. */
  40. $propalstatic=new Propal($db);
  41. $companystatic=new Societe($db);
  42. $form = new Form($db);
  43. $formfile = new FormFile($db);
  44. llxHeader("",$langs->trans("ProspectionArea"));
  45. print_fiche_titre($langs->trans("ProspectionArea"));
  46. print '<table width="100%" class="notopnoleftnoright">';
  47. print '<tr><td valign="top" width="30%" class="notopnoleft">';
  48. /*
  49. * Search form
  50. */
  51. $var=false;
  52. print '<table class="noborder nohover" width="100%">';
  53. print '<form method="post" action="'.DOL_URL_ROOT.'/comm/propal/list.php">';
  54. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  55. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("SearchPropal").'</td></tr>';
  56. print '<tr '.$bc[$var].'><td>';
  57. print $langs->trans("Ref").':</td><td><input type="text" class="flat" name="sref" size=18></td><td rowspan="2"><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  58. print '<tr '.$bc[$var].'><td nowrap>'.$langs->trans("Other").':</td><td><input type="text" class="flat" name="sall" size="18"></td>';
  59. print '</tr>';
  60. print "</form></table><br>\n";
  61. /*
  62. * Statistics
  63. */
  64. $sql = "SELECT count(p.rowid), p.fk_statut";
  65. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  66. $sql.= ", ".MAIN_DB_PREFIX."propal as p";
  67. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  68. $sql.= " WHERE p.fk_soc = s.rowid";
  69. $sql.= " AND p.entity = ".$conf->entity;
  70. if ($user->societe_id) $sql.=' AND p.fk_soc = '.$user->societe_id;
  71. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  72. $sql.= " AND p.fk_statut IN (0,1,2,3,4)";
  73. $sql.= " GROUP BY p.fk_statut";
  74. $resql = $db->query($sql);
  75. if ($resql)
  76. {
  77. $num = $db->num_rows($resql);
  78. $i = 0;
  79. $total=0;
  80. $totalinprocess=0;
  81. $dataseries=array();
  82. $vals=array();
  83. // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not)
  84. while ($i < $num)
  85. {
  86. $row = $db->fetch_row($resql);
  87. if ($row)
  88. {
  89. //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
  90. {
  91. $vals[$row[1]]=$row[0];
  92. $totalinprocess+=$row[0];
  93. }
  94. $total+=$row[0];
  95. }
  96. $i++;
  97. }
  98. $db->free($resql);
  99. print '<table class="noborder" width="100%">';
  100. print '<tr class="liste_titre"><td colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("Proposals").'</td></tr>'."\n";
  101. $var=true;
  102. $listofstatus=array(0,1,2,3,4);
  103. foreach ($listofstatus as $status)
  104. {
  105. $dataseries[]=array('label'=>$propalstatic->LibStatut($status,1),'data'=>(isset($vals[$status])?(int) $vals[$status]:0));
  106. if (! $conf->use_javascript_ajax)
  107. {
  108. $var=!$var;
  109. print "<tr ".$bc[$var].">";
  110. print '<td>'.$propalstatic->LibStatut($status,0).'</td>';
  111. print '<td align="right"><a href="liste.php?statut='.$status.'">'.(isset($vals[$status])?$vals[$status]:0).'</a></td>';
  112. print "</tr>\n";
  113. }
  114. }
  115. if ($conf->use_javascript_ajax)
  116. {
  117. print '<tr><td align="center" colspan="2">';
  118. $data=array('series'=>$dataseries);
  119. dol_print_graph('stats',300,180,$data,1,'pie',1);
  120. print '</td></tr>';
  121. }
  122. //if ($totalinprocess != $total)
  123. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("CustomersOrdersRunning").')</td><td align="right">'.$totalinprocess.'</td></tr>';
  124. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
  125. print "</table><br>";
  126. }
  127. else
  128. {
  129. dol_print_error($db);
  130. }
  131. /*
  132. * Draft proposals
  133. */
  134. if (! empty($conf->propal->enabled))
  135. {
  136. $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
  137. $sql.= " FROM ".MAIN_DB_PREFIX."propal as c";
  138. $sql.= ", ".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 c.fk_soc = s.rowid";
  141. $sql.= " AND c.entity = ".$conf->entity;
  142. $sql.= " AND c.fk_statut = 0";
  143. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  144. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  145. $resql=$db->query($sql);
  146. if ($resql)
  147. {
  148. print '<table class="noborder" width="100%">';
  149. print '<tr class="liste_titre">';
  150. print '<td colspan="2">'.$langs->trans("DraftPropals").'</td></tr>';
  151. $langs->load("propal");
  152. $num = $db->num_rows($resql);
  153. if ($num)
  154. {
  155. $i = 0;
  156. $var = True;
  157. while ($i < $num)
  158. {
  159. $var=!$var;
  160. $obj = $db->fetch_object($resql);
  161. print "<tr $bc[$var]>";
  162. $propalstatic->id=$obj->rowid;
  163. $propalstatic->ref=$obj->ref;
  164. print '<td nowrap="nowrap">'.$propalstatic->getNomUrl(1).'</td>';
  165. $companystatic->id=$obj->socid;
  166. $companystatic->name=$obj->socname;
  167. $companystatic->client=$obj->client;
  168. $companystatic->canvas=$obj->canvas;
  169. print '<td>'.$companystatic->getNomUrl(1,'customer',24).'</td>';
  170. print '</tr>';
  171. $i++;
  172. }
  173. }
  174. print "</table><br>";
  175. }
  176. }
  177. print '</td><td valign="top" width="70%" class="notopnoleftnoright">';
  178. $max=5;
  179. /*
  180. * Last modified proposals
  181. */
  182. $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
  183. $sql.= " date_cloture as datec";
  184. $sql.= " FROM ".MAIN_DB_PREFIX."propal as c";
  185. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  186. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  187. $sql.= " WHERE c.fk_soc = s.rowid";
  188. $sql.= " AND c.entity = ".$conf->entity;
  189. //$sql.= " AND c.fk_statut > 2";
  190. if ($socid) $sql .= " AND c.fk_soc = ".$socid;
  191. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  192. $sql.= " ORDER BY c.tms DESC";
  193. $sql.= $db->plimit($max, 0);
  194. $resql=$db->query($sql);
  195. if ($resql)
  196. {
  197. print '<table class="noborder" width="100%">';
  198. print '<tr class="liste_titre">';
  199. print '<td colspan="4">'.$langs->trans("LastModifiedProposals",$max).'</td></tr>';
  200. $num = $db->num_rows($resql);
  201. if ($num)
  202. {
  203. $i = 0;
  204. $var = True;
  205. while ($i < $num)
  206. {
  207. $var=!$var;
  208. $obj = $db->fetch_object($resql);
  209. print "<tr $bc[$var]>";
  210. print '<td width="20%" nowrap="nowrap">';
  211. $propalstatic->id=$obj->rowid;
  212. $propalstatic->ref=$obj->ref;
  213. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  214. print '<td width="96" class="nobordernopadding" nowrap="nowrap">';
  215. print $propalstatic->getNomUrl(1);
  216. print '</td>';
  217. print '<td width="16" class="nobordernopadding" nowrap="nowrap">';
  218. print '&nbsp;';
  219. print '</td>';
  220. print '<td width="16" align="right" class="nobordernopadding">';
  221. $filename=dol_sanitizeFileName($obj->ref);
  222. $filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  223. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  224. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  225. print '</td></tr></table>';
  226. print '</td>';
  227. $companystatic->id=$obj->socid;
  228. $companystatic->name=$obj->socname;
  229. $companystatic->client=$obj->client;
  230. $companystatic->canvas=$obj->canvas;
  231. print '<td>'.$companystatic->getNomUrl(1,'customer').'</td>';
  232. print '<td>'.dol_print_date($db->jdate($obj->datec),'day').'</td>';
  233. print '<td align="right">'.$propalstatic->LibStatut($obj->fk_statut,5).'</td>';
  234. print '</tr>';
  235. $i++;
  236. }
  237. }
  238. print "</table><br>";
  239. }
  240. else dol_print_error($db);
  241. /*
  242. * Opened proposals
  243. */
  244. if (! empty($conf->propal->enabled) && $user->rights->propale->lire)
  245. {
  246. $langs->load("propal");
  247. $now=dol_now();
  248. $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as propalid, p.total as total_ttc, p.total_ht, p.ref, p.fk_statut, p.datep as dp";
  249. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  250. $sql.= ", ".MAIN_DB_PREFIX."propal as p";
  251. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  252. $sql.= " WHERE p.fk_soc = s.rowid";
  253. $sql.= " AND p.entity = ".$conf->entity;
  254. $sql.= " AND p.fk_statut = 1";
  255. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  256. if ($socid) $sql.= " AND s.rowid = ".$socid;
  257. $sql.= " ORDER BY p.rowid DESC";
  258. $result=$db->query($sql);
  259. if ($result)
  260. {
  261. $total = 0;
  262. $num = $db->num_rows($result);
  263. $i = 0;
  264. if ($num > 0)
  265. {
  266. $var=true;
  267. print '<table class="noborder" width="100%">';
  268. print '<tr class="liste_titre"><td colspan="5">'.$langs->trans("ProposalsOpened").' <a href="'.DOL_URL_ROOT.'/comm/propal.php?viewstatut=1">('.$num.')</a></td></tr>';
  269. while ($i < $num)
  270. {
  271. $obj = $db->fetch_object($result);
  272. $var=!$var;
  273. print '<tr '.$bc[$var].'>';
  274. // Ref
  275. print '<td nowrap="nowrap" width="140">';
  276. $propalstatic->id=$obj->propalid;
  277. $propalstatic->ref=$obj->ref;
  278. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  279. print '<td class="nobordernopadding" nowrap="nowrap">';
  280. print $propalstatic->getNomUrl(1);
  281. print '</td>';
  282. print '<td width="18" class="nobordernopadding" nowrap="nowrap">';
  283. if ($db->jdate($obj->dp) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
  284. print '</td>';
  285. print '<td width="16" align="center" class="nobordernopadding">';
  286. $filename=dol_sanitizeFileName($obj->ref);
  287. $filedir=$conf->propal->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  288. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->propalid;
  289. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  290. print '</td></tr></table>';
  291. print "</td>";
  292. $companystatic->id=$obj->socid;
  293. $companystatic->name=$obj->socname;
  294. $companystatic->client=$obj->client;
  295. $companystatic->canvas=$obj->canvas;
  296. print '<td align="left">'.$companystatic->getNomUrl(1,'customer',44).'</td>'."\n";
  297. print '<td align="right">';
  298. print dol_print_date($db->jdate($obj->dp),'day').'</td>'."\n";
  299. print '<td align="right">'.price($obj->total_ttc).'</td>';
  300. print '<td align="center" width="14">'.$propalstatic->LibStatut($obj->fk_statut,3).'</td>'."\n";
  301. print '</tr>'."\n";
  302. $i++;
  303. $total += $obj->total_ttc;
  304. }
  305. if ($total>0) {
  306. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td><td>&nbsp;</td></tr>";
  307. }
  308. print "</table><br>";
  309. }
  310. }
  311. else
  312. {
  313. dol_print_error($db);
  314. }
  315. }
  316. /*
  317. * Proposals to process
  318. */
  319. /*
  320. if (! empty($conf->propal->enabled))
  321. {
  322. $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom, s.rowid as socid";
  323. $sql.=" FROM ".MAIN_DB_PREFIX."propal as c";
  324. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  325. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  326. $sql.= " WHERE c.fk_soc = s.rowid";
  327. $sql.= " AND c.entity = ".$conf->entity;
  328. $sql.= " AND c.fk_statut = 1";
  329. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  330. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  331. $sql.= " ORDER BY c.rowid DESC";
  332. $resql=$db->query($sql);
  333. if ($resql)
  334. {
  335. $num = $db->num_rows($resql);
  336. print '<table class="noborder" width="100%">';
  337. print '<tr class="liste_titre">';
  338. print '<td colspan="3">'.$langs->trans("ProposalsToProcess").' <a href="'.DOL_URL_ROOT.'/commande/liste.php?viewstatut=1">('.$num.')</a></td></tr>';
  339. if ($num)
  340. {
  341. $i = 0;
  342. $var = True;
  343. while ($i < $num)
  344. {
  345. $var=!$var;
  346. $obj = $db->fetch_object($resql);
  347. print "<tr $bc[$var]>";
  348. print '<td nowrap="nowrap">';
  349. $propalstatic->id=$obj->rowid;
  350. $propalstatic->ref=$obj->ref;
  351. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  352. print '<td width="96" class="nobordernopadding" nowrap="nowrap">';
  353. print $propalstatic->getNomUrl(1);
  354. print '</td>';
  355. print '<td width="16" class="nobordernopadding" nowrap="nowrap">';
  356. print '&nbsp;';
  357. print '</td>';
  358. print '<td width="16" align="right" class="nobordernopadding">';
  359. $filename=dol_sanitizeFileName($obj->ref);
  360. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  361. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  362. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  363. print '</td></tr></table>';
  364. print '</td>';
  365. print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->nom,24).'</a></td>';
  366. print '<td align="right">'.$propalstatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
  367. print '</tr>';
  368. $i++;
  369. }
  370. }
  371. print "</table><br>";
  372. }
  373. else dol_print_error($db);
  374. }
  375. */
  376. /*
  377. * Proposal that are in a shipping process
  378. */
  379. /*if (! empty($conf->propal->enabled))
  380. {
  381. $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom, s.rowid as socid";
  382. $sql.= " FROM ".MAIN_DB_PREFIX."commande as c";
  383. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  384. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  385. $sql.= " WHERE c.fk_soc = s.rowid";
  386. $sql.= " AND c.entity = ".$conf->entity;
  387. $sql.= " AND c.fk_statut = 2 ";
  388. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  389. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  390. $sql.= " ORDER BY c.rowid DESC";
  391. $resql=$db->query($sql);
  392. if ($resql)
  393. {
  394. $num = $db->num_rows($resql);
  395. print '<table class="noborder" width="100%">';
  396. print '<tr class="liste_titre">';
  397. print '<td colspan="3">'.$langs->trans("OnProcessOrders").' <a href="'.DOL_URL_ROOT.'/commande/liste.php?viewstatut=2">('.$num.')</a></td></tr>';
  398. if ($num)
  399. {
  400. $i = 0;
  401. $var = True;
  402. while ($i < $num)
  403. {
  404. $var=!$var;
  405. $obj = $db->fetch_object($resql);
  406. print "<tr $bc[$var]>";
  407. print '<td width="20%" nowrap="nowrap">';
  408. $propalstatic->id=$obj->rowid;
  409. $propalstatic->ref=$obj->ref;
  410. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  411. print '<td width="96" class="nobordernopadding" nowrap="nowrap">';
  412. print $propalstatic->getNomUrl(1);
  413. print '</td>';
  414. print '<td width="16" class="nobordernopadding" nowrap="nowrap">';
  415. print '&nbsp;';
  416. print '</td>';
  417. print '<td width="16" align="right" class="nobordernopadding">';
  418. $filename=dol_sanitizeFileName($obj->ref);
  419. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  420. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  421. print $formfile->getDocumentsLink($propalstatic->element, $filename, $filedir);
  422. print '</td></tr></table>';
  423. print '</td>';
  424. print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->nom.'</a></td>';
  425. print '<td align="right">'.$propalstatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
  426. print '</tr>';
  427. $i++;
  428. }
  429. }
  430. print "</table><br>";
  431. }
  432. else dol_print_error($db);
  433. }
  434. */
  435. print '</td></tr></table>';
  436. $db->close();
  437. llxFooter();
  438. ?>