index.php 13 KB

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