index.php 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. <?php
  2. /* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2019 Nicolas ZABOURI <info@inovea-conseil.com>
  7. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/mrp/index.php
  24. * \ingroup bom, mrp
  25. * \brief Home page for BOM and MRP modules
  26. */
  27. // Load Dolibarr environment
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
  31. $hookmanager = new HookManager($db);
  32. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  33. $hookmanager->initHooks(array('mrpindex'));
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("companies", "mrp"));
  36. // Security check
  37. $result = restrictedArea($user, 'bom|mrp');
  38. /*
  39. * View
  40. */
  41. $staticbom = new BOM($db);
  42. $staticmo = new Mo($db);
  43. llxHeader('', $langs->trans("MRP"), '');
  44. print load_fiche_titre($langs->trans("MRPArea"), '', 'mrp');
  45. print '<div class="fichecenter"><div class="fichethirdleft">';
  46. /*
  47. * Statistics
  48. */
  49. if ($conf->use_javascript_ajax) {
  50. $sql = "SELECT COUNT(t.rowid) as nb, status";
  51. $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as t";
  52. $sql .= " GROUP BY t.status";
  53. $sql .= " ORDER BY t.status ASC";
  54. $resql = $db->query($sql);
  55. if ($resql) {
  56. $num = $db->num_rows($resql);
  57. $i = 0;
  58. $totalnb = 0;
  59. $dataseries = array();
  60. $colorseries = array();
  61. $vals = array();
  62. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  63. while ($i < $num) {
  64. $obj = $db->fetch_object($resql);
  65. if ($obj) {
  66. $vals[$obj->status] = $obj->nb;
  67. $totalnb += $obj->nb;
  68. }
  69. $i++;
  70. }
  71. $db->free($resql);
  72. print '<div class="div-table-responsive-no-min">';
  73. print '<table class="noborder nohover centpercent">';
  74. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("ManufacturingOrder").'</th></tr>'."\n";
  75. $listofstatus = array(0, 1, 2, 3, 9);
  76. foreach ($listofstatus as $status) {
  77. $dataseries[] = array($staticmo->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
  78. if ($status == Mo::STATUS_DRAFT) {
  79. $colorseries[$status] = '-'.$badgeStatus0;
  80. }
  81. if ($status == Mo::STATUS_VALIDATED) {
  82. $colorseries[$status] = $badgeStatus1;
  83. }
  84. if ($status == Mo::STATUS_INPROGRESS) {
  85. $colorseries[$status] = $badgeStatus4;
  86. }
  87. if ($status == Mo::STATUS_PRODUCED) {
  88. $colorseries[$status] = $badgeStatus6;
  89. }
  90. if ($status == Mo::STATUS_CANCELED) {
  91. $colorseries[$status] = $badgeStatus9;
  92. }
  93. if (empty($conf->use_javascript_ajax)) {
  94. print '<tr class="oddeven">';
  95. print '<td>'.$staticmo->LibStatut($status, 0).'</td>';
  96. print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
  97. print "</tr>\n";
  98. }
  99. }
  100. if ($conf->use_javascript_ajax) {
  101. print '<tr><td class="center" colspan="2">';
  102. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  103. $dolgraph = new DolGraph();
  104. $dolgraph->SetData($dataseries);
  105. $dolgraph->SetDataColor(array_values($colorseries));
  106. $dolgraph->setShowLegend(2);
  107. $dolgraph->setShowPercent(1);
  108. $dolgraph->SetType(array('pie'));
  109. $dolgraph->SetHeight('200');
  110. $dolgraph->draw('idgraphstatus');
  111. print $dolgraph->show($totalnb ? 0 : 1);
  112. print '</td></tr>';
  113. }
  114. print "</table>";
  115. print "</div>";
  116. print "<br>";
  117. } else {
  118. dol_print_error($db);
  119. }
  120. }
  121. print '<br>';
  122. print '</div><div class="fichetwothirdright">';
  123. /*
  124. * Last modified BOM
  125. */
  126. $max = 5;
  127. $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status, a.fk_product";
  128. $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as a";
  129. $sql .= " WHERE a.entity IN (".getEntity('bom').")";
  130. $sql .= $db->order("a.tms", "DESC");
  131. $sql .= $db->plimit($max, 0);
  132. $resql = $db->query($sql);
  133. if ($resql) {
  134. print '<div class="div-table-responsive-no-min">';
  135. print '<table class="noborder centpercent">';
  136. print '<tr class="liste_titre">';
  137. print '<th colspan="4">'.$langs->trans("LatestBOMModified", $max).'</th></tr>';
  138. $num = $db->num_rows($resql);
  139. if ($num) {
  140. $i = 0;
  141. while ($i < $num) {
  142. $obj = $db->fetch_object($resql);
  143. $staticbom->id = $obj->rowid;
  144. $staticbom->ref = $obj->ref;
  145. $staticbom->fk_product = $obj->fk_product;
  146. $staticbom->date_modification = $obj->datem;
  147. $staticbom->status = $obj->status;
  148. print '<tr class="oddeven">';
  149. print '<td>'.$staticbom->getNomUrl(1, 32).'</td>';
  150. print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
  151. print '<td class="right">'.$staticbom->getLibStatut(3).'</td>';
  152. print '</tr>';
  153. $i++;
  154. }
  155. } else {
  156. print '<tr class="oddeven">';
  157. print '<td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  158. print '</tr>';
  159. }
  160. print "</table></div>";
  161. print "<br>";
  162. } else {
  163. dol_print_error($db);
  164. }
  165. /*
  166. * Last modified MOs
  167. */
  168. $max = 5;
  169. $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status";
  170. $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as a";
  171. $sql .= " WHERE a.entity IN (".getEntity('mo').")";
  172. $sql .= $db->order("a.tms", "DESC");
  173. $sql .= $db->plimit($max, 0);
  174. $resql = $db->query($sql);
  175. if ($resql) {
  176. print '<div class="div-table-responsive-no-min">';
  177. print '<table class="noborder centpercent">';
  178. print '<tr class="liste_titre">';
  179. print '<th colspan="4">'.$langs->trans("LatestMOModified", $max).'</th></tr>';
  180. $num = $db->num_rows($resql);
  181. if ($num) {
  182. $i = 0;
  183. while ($i < $num) {
  184. $obj = $db->fetch_object($resql);
  185. $staticmo->id = $obj->rowid;
  186. $staticmo->ref = $obj->ref;
  187. $staticmo->date_modification = $obj->datem;
  188. $staticmo->status = $obj->status;
  189. print '<tr class="oddeven">';
  190. print '<td>'.$staticmo->getNomUrl(1, 32).'</td>';
  191. print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
  192. print '<td class="right">'.$staticmo->getLibStatut(3).'</td>';
  193. print '</tr>';
  194. $i++;
  195. }
  196. } else {
  197. print '<tr class="oddeven">';
  198. print '<td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  199. print '</tr>';
  200. }
  201. print "</table></div>";
  202. print "<br>";
  203. } else {
  204. dol_print_error($db);
  205. }
  206. print '</div></div>';
  207. $object = new stdClass();
  208. $parameters = array(
  209. //'type' => $type,
  210. 'user' => $user,
  211. );
  212. $reshook = $hookmanager->executeHooks('dashboardMRP', $parameters, $object);
  213. // End of page
  214. llxFooter();
  215. $db->close();