PageRenderTime 23ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/htdocs/fourn/commande/index.php

https://github.com/hregis/dolibarr
PHP | 427 lines | 255 code | 55 blank | 117 comment | 60 complexity | b8f2b8bcf15cb49b91d2184802ef6670 MD5 | raw file
  1. <?php
  2. /* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012 Vinicius Nogueira <viniciusvgn@gmail.com>
  6. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/fourn/commande/index.php
  23. * \ingroup commande fournisseur
  24. * \brief Home page of supplier's orders area
  25. */
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  30. // Security check
  31. $orderid = GETPOST('orderid');
  32. if ($user->socid) {
  33. $socid = $user->socid;
  34. }
  35. $result = restrictedArea($user, 'fournisseur', $orderid, '', 'commande');
  36. $hookmanager = new HookManager($db);
  37. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  38. $hookmanager->initHooks(array('orderssuppliersindex'));
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("suppliers", "orders"));
  41. /*
  42. * View
  43. */
  44. llxHeader('', $langs->trans("SuppliersOrdersArea"));
  45. $commandestatic = new CommandeFournisseur($db);
  46. $userstatic = new User($db);
  47. $formfile = new FormFile($db);
  48. print load_fiche_titre($langs->trans("SuppliersOrdersArea"), '', 'supplier_order');
  49. print '<div class="fichecenter"><div class="fichethirdleft">';
  50. /*
  51. * Statistics
  52. */
  53. $sql = "SELECT count(cf.rowid) as nb, fk_statut as status";
  54. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  55. $sql .= ", ".MAIN_DB_PREFIX."commande_fournisseur as cf";
  56. if (empty($user->rights->societe->client->voir) && !$socid) {
  57. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  58. }
  59. $sql .= " WHERE cf.fk_soc = s.rowid";
  60. $sql .= " AND cf.entity IN (".getEntity('supplier_order').")";
  61. if ($user->socid) {
  62. $sql .= ' AND cf.fk_soc = '.((int) $user->socid);
  63. }
  64. if (empty($user->rights->societe->client->voir) && !$socid) {
  65. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  66. }
  67. $sql .= " GROUP BY cf.fk_statut";
  68. $resql = $db->query($sql);
  69. if ($resql) {
  70. $num = $db->num_rows($resql);
  71. $i = 0;
  72. $total = 0;
  73. $dataseries = array();
  74. $vals = array();
  75. // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially
  76. // -> 7=Canceled/Never received -> (reopen) 3=Process runing
  77. // -> 6=Canceled -> (reopen) 2=Approved
  78. while ($i < $num) {
  79. $obj = $db->fetch_object($resql);
  80. if ($obj) {
  81. $vals[($obj->status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER ? CommandeFournisseur::STATUS_CANCELED : $obj->status)] = $obj->nb;
  82. $total += $obj->nb;
  83. }
  84. $i++;
  85. }
  86. $db->free($resql);
  87. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  88. print '<div class="div-table-responsive-no-min">';
  89. print '<table class="noborder nohover centpercent">';
  90. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("SuppliersOrders").'</th></tr>';
  91. print "</tr>\n";
  92. $listofstatus = array(0, 1, 2, 3, 4, 5, 6, 9);
  93. foreach ($listofstatus as $status) {
  94. $dataseries[] = array($commandestatic->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
  95. if ($status == CommandeFournisseur::STATUS_DRAFT) {
  96. $colorseries[$status] = '-'.$badgeStatus0;
  97. }
  98. if ($status == CommandeFournisseur::STATUS_VALIDATED) {
  99. $colorseries[$status] = '-'.$badgeStatus1;
  100. }
  101. if ($status == CommandeFournisseur::STATUS_ACCEPTED) {
  102. $colorseries[$status] = $badgeStatus1;
  103. }
  104. if ($status == CommandeFournisseur::STATUS_REFUSED) {
  105. $colorseries[$status] = $badgeStatus9;
  106. }
  107. if ($status == CommandeFournisseur::STATUS_ORDERSENT) {
  108. $colorseries[$status] = $badgeStatus4;
  109. }
  110. if ($status == CommandeFournisseur::STATUS_RECEIVED_PARTIALLY) {
  111. $colorseries[$status] = '-'.$badgeStatus4;
  112. }
  113. if ($status == CommandeFournisseur::STATUS_RECEIVED_COMPLETELY) {
  114. $colorseries[$status] = $badgeStatus6;
  115. }
  116. if ($status == CommandeFournisseur::STATUS_CANCELED || $status == CommandeFournisseur::STATUS_CANCELED_AFTER_ORDER) {
  117. $colorseries[$status] = $badgeStatus9;
  118. }
  119. if (!$conf->use_javascript_ajax) {
  120. print '<tr class="oddeven">';
  121. print '<td>'.$commandestatic->LibStatut($status, 0).'</td>';
  122. print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
  123. print "</tr>\n";
  124. }
  125. }
  126. if ($conf->use_javascript_ajax) {
  127. print '<tr class="impair"><td class="center" colspan="2">';
  128. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  129. $dolgraph = new DolGraph();
  130. $dolgraph->SetData($dataseries);
  131. $dolgraph->SetDataColor(array_values($colorseries));
  132. $dolgraph->setShowLegend(2);
  133. $dolgraph->setShowPercent(1);
  134. $dolgraph->SetType(array('pie'));
  135. $dolgraph->setHeight('200');
  136. $dolgraph->draw('idgraphstatus');
  137. print $dolgraph->show($total ? 0 : 1);
  138. print '</td></tr>';
  139. }
  140. //if ($totalinprocess != $total)
  141. //print '<tr class="liste_total"><td>'.$langs->trans("Total").' ('.$langs->trans("SuppliersOrdersRunning").')</td><td class="right">'.$totalinprocess.'</td></tr>';
  142. print '<tr class="liste_total"><td>'.$langs->trans("Total").'</td><td class="right">'.$total.'</td></tr>';
  143. print "</table></div><br>";
  144. } else {
  145. dol_print_error($db);
  146. }
  147. /*
  148. * Draft orders
  149. */
  150. if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
  151. $sql = "SELECT c.rowid, c.ref, s.nom as name, s.rowid as socid";
  152. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
  153. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  154. if (empty($user->rights->societe->client->voir) && !$socid) {
  155. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  156. }
  157. $sql .= " WHERE c.fk_soc = s.rowid";
  158. $sql .= " AND c.entity IN (".getEntity("supplier_order").")"; // Thirdparty sharing is mandatory with supplier order sharing
  159. $sql .= " AND c.fk_statut = 0";
  160. if (!empty($socid)) {
  161. $sql .= " AND c.fk_soc = ".((int) $socid);
  162. }
  163. if (empty($user->rights->societe->client->voir) && !$socid) {
  164. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  165. }
  166. $resql = $db->query($sql);
  167. if ($resql) {
  168. print '<div class="div-table-responsive-no-min">';
  169. print '<table class="noborder centpercent">';
  170. print '<tr class="liste_titre">';
  171. print '<th colspan="2">'.$langs->trans("DraftOrders").'</th></tr>';
  172. $langs->load("orders");
  173. $num = $db->num_rows($resql);
  174. if ($num) {
  175. $i = 0;
  176. while ($i < $num) {
  177. $obj = $db->fetch_object($resql);
  178. print '<tr class="oddeven">';
  179. print '<td class="nowrap">';
  180. print "<a href=\"card.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"), "order").' '.$obj->ref."</a></td>";
  181. print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.dol_trunc($obj->name, 24).'</a></td></tr>';
  182. $i++;
  183. }
  184. }
  185. print "</table></div><br>";
  186. }
  187. }
  188. /*
  189. * List of users allowed
  190. */
  191. $sql = "SELECT";
  192. if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  193. $sql .= " DISTINCT";
  194. }
  195. $sql .= " u.rowid, u.lastname, u.firstname, u.email, u.statut";
  196. $sql .= " FROM ".MAIN_DB_PREFIX."user as u";
  197. if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  198. $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug";
  199. $sql .= " WHERE ((ug.fk_user = u.rowid";
  200. $sql .= " AND ug.entity IN (".getEntity('usergroup')."))";
  201. $sql .= " OR u.entity = 0)"; // Show always superadmin
  202. } else {
  203. $sql .= " WHERE (u.entity IN (".getEntity('user')."))";
  204. }
  205. $sql .= " AND u.fk_soc IS NULL"; // An external user can not approved
  206. $resql = $db->query($sql);
  207. if ($resql) {
  208. $num = $db->num_rows($resql);
  209. $i = 0;
  210. print '<div class="div-table-responsive-no-min">';
  211. print '<table class="liste centpercent">';
  212. print '<tr class="liste_titre"><th>'.$langs->trans("UserWithApproveOrderGrant").'</th>';
  213. print "</tr>\n";
  214. while ($i < $num) {
  215. $obj = $db->fetch_object($resql);
  216. $userstatic = new User($db);
  217. $userstatic->id = $obj->rowid;
  218. $userstatic->getrights('fournisseur');
  219. if (!empty($userstatic->rights->fournisseur->commande->approuver)) {
  220. print '<tr class="oddeven">';
  221. print '<td>';
  222. $userstatic->lastname = $obj->lastname;
  223. $userstatic->firstname = $obj->firstname;
  224. $userstatic->email = $obj->email;
  225. $userstatic->statut = $obj->statut;
  226. print $userstatic->getNomUrl(1);
  227. print '</td>';
  228. print "</tr>\n";
  229. }
  230. $i++;
  231. }
  232. print "</table></div><br>";
  233. $db->free($resql);
  234. } else {
  235. dol_print_error($db);
  236. }
  237. print '</div><div class="fichetwothirdright">';
  238. /*
  239. * Last modified orders
  240. */
  241. $max = 5;
  242. $sql = "SELECT c.rowid, c.ref, c.fk_statut as status, c.tms, c.billed, s.nom as name, s.rowid as socid";
  243. $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
  244. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  245. if (empty($user->rights->societe->client->voir) && !$socid) {
  246. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  247. }
  248. $sql .= " WHERE c.fk_soc = s.rowid";
  249. $sql .= " AND c.entity IN (".getEntity('supplier_order').")";
  250. //$sql.= " AND c.fk_statut > 2";
  251. if (!empty($socid)) {
  252. $sql .= " AND c.fk_soc = ".((int) $socid);
  253. }
  254. if (empty($user->rights->societe->client->voir) && !$socid) {
  255. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  256. }
  257. $sql .= " ORDER BY c.tms DESC";
  258. $sql .= $db->plimit($max, 0);
  259. $resql = $db->query($sql);
  260. if ($resql) {
  261. print '<div class="div-table-responsive-no-min">';
  262. print '<table class="noborder centpercent">';
  263. print '<tr class="liste_titre">';
  264. print '<th colspan="4">'.$langs->trans("LastModifiedOrders", $max).'</th></tr>';
  265. $num = $db->num_rows($resql);
  266. if ($num) {
  267. $i = 0;
  268. while ($i < $num) {
  269. $obj = $db->fetch_object($resql);
  270. print '<tr class="oddeven">';
  271. print '<td width="20%" class="nowrap">';
  272. $commandestatic->id = $obj->rowid;
  273. $commandestatic->ref = $obj->ref;
  274. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  275. print '<td width="96" class="nobordernopadding nowrap">';
  276. print $commandestatic->getNomUrl(1);
  277. print '</td>';
  278. print '<td width="16" class="nobordernopadding nowrap">';
  279. print '&nbsp;';
  280. print '</td>';
  281. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  282. $filename = dol_sanitizeFileName($obj->ref);
  283. $filedir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  284. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  285. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  286. print '</td></tr></table>';
  287. print '</td>';
  288. print '<td><a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
  289. print '<td>'.dol_print_date($db->jdate($obj->tms), 'day').'</td>';
  290. print '<td class="right">'.$commandestatic->LibStatut($obj->status, 3, $obj->billed).'</td>';
  291. print '</tr>';
  292. $i++;
  293. }
  294. }
  295. print "</table></div><br>";
  296. } else {
  297. dol_print_error($db);
  298. }
  299. /*
  300. * Orders to process
  301. */
  302. /*
  303. $sql = "SELECT c.rowid, c.ref, c.fk_statut, s.nom as name, s.rowid as socid";
  304. $sql.=" FROM ".MAIN_DB_PREFIX."commande_fournisseur as c";
  305. $sql.= ", ".MAIN_DB_PREFIX."societe as s";
  306. if (empty($user->rights->societe->client->voir) && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  307. $sql.= " WHERE c.fk_soc = s.rowid";
  308. $sql.= " AND c.entity IN (".getEntity("supplier_order").")";
  309. $sql.= " AND c.fk_statut = 1";
  310. if ($socid) $sql.= " AND c.fk_soc = ".((int) $socid);
  311. if (empty($user->rights->societe->client->voir) && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .((int) $user->id);
  312. $sql.= " ORDER BY c.rowid DESC";
  313. $resql=$db->query($sql);
  314. if ($resql)
  315. {
  316. $num = $db->num_rows($resql);
  317. print '<div class="div-table-responsive-no-min">';
  318. print '<table class="noborder centpercent">';
  319. print '<tr class="liste_titre">';
  320. print '<th colspan="3">'.$langs->trans("OrdersToProcess").' <a href="'.DOL_URL_ROOT.'/commande/list.php?search_status=1">('.$num.')</a></th></tr>';
  321. if ($num)
  322. {
  323. $i = 0;
  324. while ($i < $num)
  325. {
  326. $obj = $db->fetch_object($resql);
  327. print '<tr class="oddeven">';
  328. print '<td class="nowrap">';
  329. $commandestatic->id=$obj->rowid;
  330. $commandestatic->ref=$obj->ref;
  331. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  332. print '<td width="96" class="nobordernopadding nowrap">';
  333. print $commandestatic->getNomUrl(1);
  334. print '</td>';
  335. print '<td width="16" class="nobordernopadding nowrap">';
  336. print '&nbsp;';
  337. print '</td>';
  338. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  339. $filename=dol_sanitizeFileName($obj->ref);
  340. $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref);
  341. $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  342. print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir);
  343. print '</td></tr></table>';
  344. print '</td>';
  345. print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.dol_trunc($obj->name,24).'</a></td>';
  346. print '<td class="right">'.$commandestatic->LibStatut($obj->fk_statut,$obj->facture,5).'</td>';
  347. print '</tr>';
  348. $i++;
  349. }
  350. }
  351. print "</table></div><br>";
  352. }
  353. */
  354. print '</div></div>';
  355. $parameters = array('user' => $user);
  356. $reshook = $hookmanager->executeHooks('dashboardOrdersSuppliers', $parameters, $object); // Note that $action and $object may have been modified by hook
  357. // End of page
  358. llxFooter();
  359. $db->close();