index.php 14 KB

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