index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  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@inodbox.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 .'/supplier_proposal/class/supplier_proposal.class.php';
  27. // Load translation files required by the page
  28. $langs->loadLangs(array('supplier_proposal', '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, 'supplier_proposal');
  37. /*
  38. * View
  39. */
  40. $now=dol_now();
  41. $supplier_proposalstatic=new SupplierProposal($db);
  42. $companystatic=new Societe($db);
  43. $form = new Form($db);
  44. $formfile = new FormFile($db);
  45. $help_url="EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur";
  46. llxHeader("",$langs->trans("SupplierProposalArea"),$help_url);
  47. print load_fiche_titre($langs->trans("SupplierProposalArea"));
  48. print '<div class="fichecenter"><div class="fichethirdleft">';
  49. /*
  50. * Search form
  51. */
  52. if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) // This is useless due to the global search combo
  53. {
  54. print '<form method="post" action="'.DOL_URL_ROOT.'/supplier_proposal/list.php">';
  55. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  56. print '<table class="noborder nohover" width="100%">';
  57. print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
  58. print '<tr class="oddeven"><td>';
  59. print $langs->trans("SupplierProposal").':</td><td><input type="text" class="flat" name="sall" size="18"></td><td><input type="submit" value="'.$langs->trans("Search").'" class="button"></td></tr>';
  60. print '</tr>';
  61. print "</table></form><br>\n";
  62. }
  63. /*
  64. * Statistics
  65. */
  66. $sql = "SELECT count(p.rowid), p.fk_statut";
  67. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  68. $sql.= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
  69. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  70. $sql.= " WHERE p.fk_soc = s.rowid";
  71. $sql.= " AND p.entity IN (".getEntity('supplier_proposal').")";
  72. if ($user->societe_id) $sql.=' AND p.fk_soc = '.$user->societe_id;
  73. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  74. $sql.= " AND p.fk_statut IN (0,1,2,3,4)";
  75. $sql.= " GROUP BY p.fk_statut";
  76. $resql = $db->query($sql);
  77. if ($resql)
  78. {
  79. $num = $db->num_rows($resql);
  80. $i = 0;
  81. $total=0;
  82. $totalinprocess=0;
  83. $dataseries=array();
  84. $vals=array();
  85. // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not)
  86. while ($i < $num)
  87. {
  88. $row = $db->fetch_row($resql);
  89. if ($row)
  90. {
  91. //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
  92. {
  93. $vals[$row[1]]=$row[0];
  94. $totalinprocess+=$row[0];
  95. }
  96. $total+=$row[0];
  97. }
  98. $i++;
  99. }
  100. $db->free($resql);
  101. print '<table class="noborder" width="100%">';
  102. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n";
  103. $listofstatus=array(0,1,2,3,4);
  104. foreach ($listofstatus as $status)
  105. {
  106. $dataseries[]=array($supplier_proposalstatic->LibStatut($status,1), (isset($vals[$status])?(int) $vals[$status]:0));
  107. if (! $conf->use_javascript_ajax)
  108. {
  109. print '<tr class="oddeven">';
  110. print '<td>'.$supplier_proposalstatic->LibStatut($status,0).'</td>';
  111. print '<td align="right"><a href="list.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. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  119. $dolgraph = new DolGraph();
  120. $dolgraph->SetData($dataseries);
  121. $dolgraph->setShowLegend(1);
  122. $dolgraph->setShowPercent(1);
  123. $dolgraph->SetType(array('pie'));
  124. $dolgraph->setWidth('100%');
  125. $dolgraph->draw('idgraphstatus');
  126. print $dolgraph->show($total?0:1);
  127. print '</td></tr>';
  128. }
  129. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td align="right">'.$total.'</td></tr>';
  130. print "</table><br>";
  131. }
  132. else
  133. {
  134. dol_print_error($db);
  135. }
  136. /*
  137. * Draft askprice
  138. */
  139. if (! empty($conf->supplier_proposal->enabled))
  140. {
  141. $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
  142. $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
  143. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  144. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  145. $sql.= " WHERE c.fk_soc = s.rowid";
  146. $sql.= " AND c.entity = ".$conf->entity;
  147. $sql.= " AND c.fk_statut = 0";
  148. if ($socid) $sql.= " AND c.fk_soc = ".$socid;
  149. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  150. $resql=$db->query($sql);
  151. if ($resql)
  152. {
  153. print '<table class="noborder" width="100%">';
  154. print '<tr class="liste_titre">';
  155. print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
  156. $langs->load("supplier_proposal");
  157. $num = $db->num_rows($resql);
  158. if ($num)
  159. {
  160. $i = 0;
  161. while ($i < $num)
  162. {
  163. $obj = $db->fetch_object($resql);
  164. print '<tr class="oddeven">';
  165. $supplier_proposalstatic->id=$obj->rowid;
  166. $supplier_proposalstatic->ref=$obj->ref;
  167. print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
  168. $companystatic->id=$obj->socid;
  169. $companystatic->name=$obj->socname;
  170. $companystatic->client=$obj->client;
  171. $companystatic->canvas=$obj->canvas;
  172. print '<td>'.$companystatic->getNomUrl(1,'customer',24).'</td>';
  173. print '</tr>';
  174. $i++;
  175. }
  176. }
  177. print "</table><br>";
  178. }
  179. }
  180. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  181. $max=5;
  182. /*
  183. * Last modified askprice
  184. */
  185. $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
  186. $sql.= " date_cloture as datec";
  187. $sql.= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
  188. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  189. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  190. $sql.= " WHERE c.fk_soc = s.rowid";
  191. $sql.= " AND c.entity = ".$conf->entity;
  192. //$sql.= " AND c.fk_statut > 2";
  193. if ($socid) $sql .= " AND c.fk_soc = ".$socid;
  194. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  195. $sql.= " ORDER BY c.tms DESC";
  196. $sql.= $db->plimit($max, 0);
  197. $resql=$db->query($sql);
  198. if ($resql)
  199. {
  200. print '<table class="noborder" width="100%">';
  201. print '<tr class="liste_titre">';
  202. print '<th colspan="4">'.$langs->trans("LastModifiedRequests",$max).'</th></tr>';
  203. $num = $db->num_rows($resql);
  204. if ($num)
  205. {
  206. $i = 0;
  207. while ($i < $num)
  208. {
  209. $obj = $db->fetch_object($resql);
  210. print '<tr class="oddeven">';
  211. print '<td width="20%" class="nowrap">';
  212. $supplier_proposalstatic->id=$obj->rowid;
  213. $supplier_proposalstatic->ref=$obj->ref;
  214. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  215. print '<td width="96" class="nobordernopadding nowrap">';
  216. print $supplier_proposalstatic->getNomUrl(1);
  217. print '</td>';
  218. print '<td width="16" class="nobordernopadding nowrap">';
  219. print '&nbsp;';
  220. print '</td>';
  221. print '<td width="16" align="right" class="nobordernopadding">';
  222. $filename=dol_sanitizeFileName($obj->ref);
  223. $filedir=$conf->supplier_proposal->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  224. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  225. print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
  226. print '</td></tr></table>';
  227. print '</td>';
  228. $companystatic->id=$obj->socid;
  229. $companystatic->name=$obj->socname;
  230. $companystatic->client=$obj->client;
  231. $companystatic->canvas=$obj->canvas;
  232. print '<td>'.$companystatic->getNomUrl(1,'customer').'</td>';
  233. print '<td>'.dol_print_date($db->jdate($obj->datec),'day').'</td>';
  234. print '<td align="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut,5).'</td>';
  235. print '</tr>';
  236. $i++;
  237. }
  238. }
  239. print "</table><br>";
  240. }
  241. else dol_print_error($db);
  242. /*
  243. * Opened askprice
  244. */
  245. if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire)
  246. {
  247. $langs->load("supplier_proposal");
  248. $now=dol_now();
  249. $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as supplier_proposalid, p.total as total_ttc, p.total_ht, p.ref, p.fk_statut, p.datec as dp";
  250. $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
  251. $sql.= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
  252. if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  253. $sql.= " WHERE p.fk_soc = s.rowid";
  254. $sql.= " AND p.entity IN (".getEntity('supplier_proposal').")";
  255. $sql.= " AND p.fk_statut = 1";
  256. if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  257. if ($socid) $sql.= " AND s.rowid = ".$socid;
  258. $sql.= " ORDER BY p.rowid DESC";
  259. $result=$db->query($sql);
  260. if ($result)
  261. {
  262. $total = 0;
  263. $num = $db->num_rows($result);
  264. $i = 0;
  265. if ($num > 0)
  266. {
  267. print '<table class="noborder" width="100%">';
  268. print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened").' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?viewstatut=1"><span class="badge">'.$num.'</span></a></th></tr>';
  269. $nbofloop=min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD)?500:$conf->global->MAIN_MAXLIST_OVERLOAD));
  270. while ($i < $nbofloop)
  271. {
  272. $obj = $db->fetch_object($result);
  273. print '<tr class="oddeven">';
  274. // Ref
  275. print '<td class="nowrap" width="140">';
  276. $supplier_proposalstatic->id=$obj->supplier_proposalid;
  277. $supplier_proposalstatic->ref=$obj->ref;
  278. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  279. print '<td class="nobordernopadding nowrap">';
  280. print $supplier_proposalstatic->getNomUrl(1);
  281. print '</td>';
  282. print '<td width="18" class="nobordernopadding nowrap">';
  283. if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->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->supplier_proposal->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  288. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
  289. print $formfile->getDocumentsLink($supplier_proposalstatic->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">'.$supplier_proposalstatic->LibStatut($obj->fk_statut,3).'</td>'."\n";
  301. print '</tr>'."\n";
  302. $i++;
  303. $total += $obj->total_ttc;
  304. }
  305. if ($num > $nbofloop)
  306. {
  307. print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
  308. }
  309. else if ($total>0)
  310. {
  311. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total")."</td><td align=\"right\">".price($total)."</td><td>&nbsp;</td></tr>";
  312. }
  313. print "</table><br>";
  314. }
  315. }
  316. else
  317. {
  318. dol_print_error($db);
  319. }
  320. }
  321. print '</div></div></div>';
  322. // End of page
  323. llxFooter();
  324. $db->close();