index.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395
  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. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.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 <https://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/supplier_proposal/index.php
  22. * \ingroup supplier_proposal
  23. * \brief Home page of vendor proposal 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.'/supplier_proposal/class/supplier_proposal.class.php';
  28. $hookmanager = new HookManager($db);
  29. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  30. $hookmanager->initHooks(array('suppliersproposalsindex'));
  31. // Load translation files required by the page
  32. $langs->loadLangs(array('supplier_proposal', 'companies'));
  33. // Security check
  34. $socid = GETPOST('socid', 'int');
  35. if (isset($user->socid) && $user->socid > 0) {
  36. $action = '';
  37. $socid = $user->socid;
  38. }
  39. $result = restrictedArea($user, 'supplier_proposal');
  40. /*
  41. * View
  42. */
  43. $now = dol_now();
  44. $supplier_proposalstatic = new SupplierProposal($db);
  45. $companystatic = new Societe($db);
  46. $form = new Form($db);
  47. $formfile = new FormFile($db);
  48. $help_url = "EN:Module_Ask_Price_Supplier|FR:Module_Demande_de_prix_fournisseur";
  49. llxHeader("", $langs->trans("SupplierProposalArea"), $help_url);
  50. print load_fiche_titre($langs->trans("SupplierProposalArea"), '', 'supplier_proposal');
  51. print '<div class="fichecenter"><div class="fichethirdleft">';
  52. // Statistics
  53. $sql = "SELECT count(p.rowid), p.fk_statut";
  54. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  55. $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
  56. if (!$user->rights->societe->client->voir && !$socid) {
  57. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  58. }
  59. $sql .= " WHERE p.fk_soc = s.rowid";
  60. $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
  61. if ($user->socid) {
  62. $sql .= ' AND p.fk_soc = '.((int) $user->socid);
  63. }
  64. if (!$user->rights->societe->client->voir && !$socid) {
  65. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  66. }
  67. $sql .= " AND p.fk_statut IN (0,1,2,3,4)";
  68. $sql .= " GROUP BY p.fk_statut";
  69. $resql = $db->query($sql);
  70. if ($resql) {
  71. $num = $db->num_rows($resql);
  72. $i = 0;
  73. $total = 0;
  74. $totalinprocess = 0;
  75. $dataseries = array();
  76. $colorseries = array();
  77. $vals = array();
  78. // -1=Canceled, 0=Draft, 1=Validated, (2=Accepted/On process not managed for customer orders), 3=Closed (Sent/Received, billed or not)
  79. while ($i < $num) {
  80. $row = $db->fetch_row($resql);
  81. if ($row) {
  82. //if ($row[1]!=-1 && ($row[1]!=3 || $row[2]!=1))
  83. {
  84. $vals[$row[1]] = $row[0];
  85. $totalinprocess += $row[0];
  86. }
  87. $total += $row[0];
  88. }
  89. $i++;
  90. }
  91. $db->free($resql);
  92. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  93. print '<div class="div-table-responsive-no-min">';
  94. print '<table class="noborder centpercent">';
  95. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("CommRequests").'</th></tr>'."\n";
  96. $listofstatus = array(0, 1, 2, 3, 4);
  97. foreach ($listofstatus as $status) {
  98. $dataseries[] = array($supplier_proposalstatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
  99. if ($status == SupplierProposal::STATUS_DRAFT) {
  100. $colorseries[$status] = '-'.$badgeStatus0;
  101. }
  102. if ($status == SupplierProposal::STATUS_VALIDATED) {
  103. $colorseries[$status] = $badgeStatus1;
  104. }
  105. if ($status == SupplierProposal::STATUS_SIGNED) {
  106. $colorseries[$status] = $badgeStatus4;
  107. }
  108. if ($status == SupplierProposal::STATUS_NOTSIGNED) {
  109. $colorseries[$status] = $badgeStatus9;
  110. }
  111. if ($status == SupplierProposal::STATUS_CLOSE) {
  112. $colorseries[$status] = $badgeStatus6;
  113. }
  114. if (empty($conf->use_javascript_ajax)) {
  115. print '<tr class="oddeven">';
  116. print '<td>'.$supplier_proposalstatic->LibStatut($status, 0).'</td>';
  117. print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
  118. print "</tr>\n";
  119. }
  120. }
  121. if ($conf->use_javascript_ajax) {
  122. print '<tr><td class="center" colspan="2">';
  123. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  124. $dolgraph = new DolGraph();
  125. $dolgraph->SetData($dataseries);
  126. $dolgraph->SetDataColor(array_values($colorseries));
  127. $dolgraph->setShowLegend(2);
  128. $dolgraph->setShowPercent(1);
  129. $dolgraph->SetType(array('pie'));
  130. $dolgraph->setHeight('200');
  131. $dolgraph->draw('idgraphstatus');
  132. print $dolgraph->show($total ? 0 : 1);
  133. print '</td></tr>';
  134. }
  135. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
  136. print "</table></div><br>";
  137. } else {
  138. dol_print_error($db);
  139. }
  140. /*
  141. * Draft askprice
  142. */
  143. if (!empty($conf->supplier_proposal->enabled)) {
  144. $sql = "SELECT c.rowid, c.ref, s.nom as socname, s.rowid as socid, s.canvas, s.client";
  145. $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
  146. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  147. if (!$user->rights->societe->client->voir && !$socid) {
  148. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  149. }
  150. $sql .= " WHERE c.fk_soc = s.rowid";
  151. $sql .= " AND c.entity = ".$conf->entity;
  152. $sql .= " AND c.fk_statut = 0";
  153. if ($socid) {
  154. $sql .= " AND c.fk_soc = ".((int) $socid);
  155. }
  156. if (!$user->rights->societe->client->voir && !$socid) {
  157. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  158. }
  159. $resql = $db->query($sql);
  160. if ($resql) {
  161. print '<div class="div-table-responsive-no-min">';
  162. print '<table class="noborder centpercent">';
  163. print '<tr class="liste_titre">';
  164. print '<th colspan="2">'.$langs->trans("DraftRequests").'</th></tr>';
  165. $langs->load("supplier_proposal");
  166. $num = $db->num_rows($resql);
  167. if ($num) {
  168. $i = 0;
  169. while ($i < $num) {
  170. $obj = $db->fetch_object($resql);
  171. print '<tr class="oddeven">';
  172. $supplier_proposalstatic->id = $obj->rowid;
  173. $supplier_proposalstatic->ref = $obj->ref;
  174. print '<td class="nowrap">'.$supplier_proposalstatic->getNomUrl(1).'</td>';
  175. $companystatic->id = $obj->socid;
  176. $companystatic->name = $obj->socname;
  177. $companystatic->client = $obj->client;
  178. $companystatic->canvas = $obj->canvas;
  179. print '<td>'.$companystatic->getNomUrl(1, 'customer', 24).'</td>';
  180. print '</tr>';
  181. $i++;
  182. }
  183. }
  184. print "</table></div><br>";
  185. }
  186. }
  187. print '</div><div class="fichetwothirdright"><div class="ficheaddleft">';
  188. $max = 5;
  189. /*
  190. * Last modified askprice
  191. */
  192. $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as socname, s.rowid as socid, s.canvas, s.client,";
  193. $sql .= " date_cloture as datec";
  194. $sql .= " FROM ".MAIN_DB_PREFIX."supplier_proposal as c";
  195. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  196. if (!$user->rights->societe->client->voir && !$socid) {
  197. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  198. }
  199. $sql .= " WHERE c.fk_soc = s.rowid";
  200. $sql .= " AND c.entity = ".$conf->entity;
  201. //$sql.= " AND c.fk_statut > 2";
  202. if ($socid) {
  203. $sql .= " AND c.fk_soc = ".((int) $socid);
  204. }
  205. if (!$user->rights->societe->client->voir && !$socid) {
  206. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  207. }
  208. $sql .= " ORDER BY c.tms DESC";
  209. $sql .= $db->plimit($max, 0);
  210. $resql = $db->query($sql);
  211. if ($resql) {
  212. print '<div class="div-table-responsive-no-min">';
  213. print '<table class="noborder centpercent">';
  214. print '<tr class="liste_titre">';
  215. print '<th colspan="4">'.$langs->trans("LastModifiedRequests", $max).'</th></tr>';
  216. $num = $db->num_rows($resql);
  217. if ($num) {
  218. $i = 0;
  219. while ($i < $num) {
  220. $obj = $db->fetch_object($resql);
  221. print '<tr class="oddeven">';
  222. print '<td width="20%" class="nowrap">';
  223. $supplier_proposalstatic->id = $obj->rowid;
  224. $supplier_proposalstatic->ref = $obj->ref;
  225. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  226. print '<td width="96" class="nobordernopadding nowrap">';
  227. print $supplier_proposalstatic->getNomUrl(1);
  228. print '</td>';
  229. print '<td width="16" class="nobordernopadding nowrap">';
  230. print '&nbsp;';
  231. print '</td>';
  232. print '<td width="16" class="right nobordernopadding">';
  233. $filename = dol_sanitizeFileName($obj->ref);
  234. $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  235. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  236. print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
  237. print '</td></tr></table>';
  238. print '</td>';
  239. $companystatic->id = $obj->socid;
  240. $companystatic->name = $obj->socname;
  241. $companystatic->client = $obj->client;
  242. $companystatic->canvas = $obj->canvas;
  243. print '<td>'.$companystatic->getNomUrl(1, 'customer').'</td>';
  244. print '<td>'.dol_print_date($db->jdate($obj->datec), 'day').'</td>';
  245. print '<td class="right">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>';
  246. print '</tr>';
  247. $i++;
  248. }
  249. }
  250. print "</table></div><br>";
  251. } else {
  252. dol_print_error($db);
  253. }
  254. /*
  255. * Opened askprice
  256. */
  257. if (!empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) {
  258. $langs->load("supplier_proposal");
  259. $now = dol_now();
  260. $sql = "SELECT s.nom as socname, s.rowid as socid, s.canvas, s.client, p.rowid as supplier_proposalid, p.total_ttc, p.total_tva, p.total_ht, p.ref, p.fk_statut, p.datec as dp";
  261. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  262. $sql .= ", ".MAIN_DB_PREFIX."supplier_proposal as p";
  263. if (!$user->rights->societe->client->voir && !$socid) {
  264. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  265. }
  266. $sql .= " WHERE p.fk_soc = s.rowid";
  267. $sql .= " AND p.entity IN (".getEntity('supplier_proposal').")";
  268. $sql .= " AND p.fk_statut = 1";
  269. if (!$user->rights->societe->client->voir && !$socid) {
  270. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  271. }
  272. if ($socid) {
  273. $sql .= " AND s.rowid = ".((int) $socid);
  274. }
  275. $sql .= " ORDER BY p.rowid DESC";
  276. $result = $db->query($sql);
  277. if ($result) {
  278. $total = 0;
  279. $num = $db->num_rows($result);
  280. $i = 0;
  281. if ($num > 0) {
  282. print '<div class="div-table-responsive-no-min">';
  283. print '<table class="noborder centpercent">';
  284. print '<tr class="liste_titre"><th colspan="5">'.$langs->trans("RequestsOpened").' <a href="'.DOL_URL_ROOT.'/supplier_proposal/list.php?search_status=1"><span class="badge">'.$num.'</span></a></th></tr>';
  285. $nbofloop = min($num, (empty($conf->global->MAIN_MAXLIST_OVERLOAD) ? 500 : $conf->global->MAIN_MAXLIST_OVERLOAD));
  286. while ($i < $nbofloop) {
  287. $obj = $db->fetch_object($result);
  288. print '<tr class="oddeven">';
  289. // Ref
  290. print '<td class="nowrap" width="140">';
  291. $supplier_proposalstatic->id = $obj->supplier_proposalid;
  292. $supplier_proposalstatic->ref = $obj->ref;
  293. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  294. print '<td class="nobordernopadding nowrap">';
  295. print $supplier_proposalstatic->getNomUrl(1);
  296. print '</td>';
  297. print '<td width="18" class="nobordernopadding nowrap">';
  298. if ($db->jdate($obj->dfv) < ($now - $conf->supplier_proposal->cloture->warning_delay)) {
  299. print img_warning($langs->trans("Late"));
  300. }
  301. print '</td>';
  302. print '<td width="16" class="center nobordernopadding">';
  303. $filename = dol_sanitizeFileName($obj->ref);
  304. $filedir = $conf->supplier_proposal->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  305. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->supplier_proposalid;
  306. print $formfile->getDocumentsLink($supplier_proposalstatic->element, $filename, $filedir);
  307. print '</td></tr></table>';
  308. print "</td>";
  309. $companystatic->id = $obj->socid;
  310. $companystatic->name = $obj->socname;
  311. $companystatic->client = $obj->client;
  312. $companystatic->canvas = $obj->canvas;
  313. print '<td class="left">'.$companystatic->getNomUrl(1, 'customer', 44).'</td>'."\n";
  314. print '<td class="right">';
  315. print dol_print_date($db->jdate($obj->dp), 'day').'</td>'."\n";
  316. print '<td class="right">'.price($obj->total_ttc).'</td>';
  317. print '<td class="center" width="14">'.$supplier_proposalstatic->LibStatut($obj->fk_statut, 3).'</td>'."\n";
  318. print '</tr>'."\n";
  319. $i++;
  320. $total += $obj->total_ttc;
  321. }
  322. if ($num > $nbofloop) {
  323. print '<tr class="liste_total"><td colspan="5">'.$langs->trans("XMoreLines", ($num - $nbofloop))."</td></tr>";
  324. } elseif ($total > 0) {
  325. print '<tr class="liste_total"><td colspan="3">'.$langs->trans("Total").'</td><td class="right">'.price($total)."</td><td>&nbsp;</td></tr>";
  326. }
  327. print "</table></div><br>";
  328. }
  329. } else {
  330. dol_print_error($db);
  331. }
  332. }
  333. print '</div></div></div>';
  334. $parameters = array('user' => $user);
  335. $reshook = $hookmanager->executeHooks('dashboardSupplierProposal', $parameters, $object); // Note that $action and $object may have been modified by hook
  336. // End of page
  337. llxFooter();
  338. $db->close();