index.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
  30. $hookmanager = new HookManager($db);
  31. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  32. $hookmanager->initHooks(array('mrpindex'));
  33. // Load translation files required by the page
  34. $langs->loadLangs(array("companies", "mrp"));
  35. // Security check
  36. $result = restrictedArea($user, 'bom|mrp');
  37. /*
  38. * View
  39. */
  40. $staticbom = new BOM($db);
  41. $staticmo = new Mo($db);
  42. llxHeader('', $langs->trans("MRP"), '');
  43. print load_fiche_titre($langs->trans("MRPArea"), '', 'mrp');
  44. print '<div class="fichecenter"><div class="fichethirdleft">';
  45. /*
  46. * Statistics
  47. */
  48. if ($conf->use_javascript_ajax) {
  49. $sql = "SELECT COUNT(t.rowid) as nb, status";
  50. $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as t";
  51. $sql .= " GROUP BY t.status";
  52. $sql .= " ORDER BY t.status ASC";
  53. $resql = $db->query($sql);
  54. if ($resql) {
  55. $num = $db->num_rows($resql);
  56. $i = 0;
  57. $totalnb = 0;
  58. $dataseries = array();
  59. $colorseries = array();
  60. $vals = array();
  61. include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
  62. while ($i < $num) {
  63. $obj = $db->fetch_object($resql);
  64. if ($obj) {
  65. $vals[$obj->status] = $obj->nb;
  66. $totalnb += $obj->nb;
  67. }
  68. $i++;
  69. }
  70. $db->free($resql);
  71. print '<div class="div-table-responsive-no-min">';
  72. print '<table class="noborder nohover centpercent">';
  73. print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("ManufacturingOrder").'</th></tr>'."\n";
  74. $listofstatus = array(0, 1, 2, 3, 9);
  75. foreach ($listofstatus as $status) {
  76. $dataseries[] = array($staticmo->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
  77. if ($status == Mo::STATUS_DRAFT) {
  78. $colorseries[$status] = '-'.$badgeStatus0;
  79. }
  80. if ($status == Mo::STATUS_VALIDATED) {
  81. $colorseries[$status] = $badgeStatus1;
  82. }
  83. if ($status == Mo::STATUS_INPROGRESS) {
  84. $colorseries[$status] = $badgeStatus4;
  85. }
  86. if ($status == Mo::STATUS_PRODUCED) {
  87. $colorseries[$status] = $badgeStatus6;
  88. }
  89. if ($status == Mo::STATUS_CANCELED) {
  90. $colorseries[$status] = $badgeStatus9;
  91. }
  92. if (empty($conf->use_javascript_ajax)) {
  93. print '<tr class="oddeven">';
  94. print '<td>'.$staticmo->LibStatut($status, 0).'</td>';
  95. print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
  96. print "</tr>\n";
  97. }
  98. }
  99. if ($conf->use_javascript_ajax) {
  100. print '<tr><td class="center" colspan="2">';
  101. include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
  102. $dolgraph = new DolGraph();
  103. $dolgraph->SetData($dataseries);
  104. $dolgraph->SetDataColor(array_values($colorseries));
  105. $dolgraph->setShowLegend(2);
  106. $dolgraph->setShowPercent(1);
  107. $dolgraph->SetType(array('pie'));
  108. $dolgraph->SetHeight('200');
  109. $dolgraph->draw('idgraphstatus');
  110. print $dolgraph->show($totalnb ? 0 : 1);
  111. print '</td></tr>';
  112. }
  113. print "</table>";
  114. print "</div>";
  115. print "<br>";
  116. } else {
  117. dol_print_error($db);
  118. }
  119. }
  120. print '<br>';
  121. print '</div><div class="fichetwothirdright">';
  122. /*
  123. * Last modified BOM
  124. */
  125. $max = 5;
  126. $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status, a.fk_product";
  127. $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as a";
  128. $sql .= " WHERE a.entity IN (".getEntity('bom').")";
  129. $sql .= $db->order("a.tms", "DESC");
  130. $sql .= $db->plimit($max, 0);
  131. $resql = $db->query($sql);
  132. if ($resql) {
  133. print '<div class="div-table-responsive-no-min">';
  134. print '<table class="noborder centpercent">';
  135. print '<tr class="liste_titre">';
  136. print '<th colspan="4">'.$langs->trans("LatestBOMModified", $max).'</th></tr>';
  137. $num = $db->num_rows($resql);
  138. if ($num) {
  139. $i = 0;
  140. while ($i < $num) {
  141. $obj = $db->fetch_object($resql);
  142. $staticbom->id = $obj->rowid;
  143. $staticbom->ref = $obj->ref;
  144. $staticbom->fk_product = $obj->fk_product;
  145. $staticbom->date_modification = $obj->datem;
  146. $staticbom->status = $obj->status;
  147. print '<tr class="oddeven">';
  148. print '<td>'.$staticbom->getNomUrl(1, 32).'</td>';
  149. print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
  150. print '<td class="right">'.$staticbom->getLibStatut(3).'</td>';
  151. print '</tr>';
  152. $i++;
  153. }
  154. } else {
  155. print '<tr class="oddeven">';
  156. print '<td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  157. print '</tr>';
  158. }
  159. print "</table></div>";
  160. print "<br>";
  161. } else {
  162. dol_print_error($db);
  163. }
  164. /*
  165. * Last modified MOs
  166. */
  167. $max = 5;
  168. $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status";
  169. $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as a";
  170. $sql .= " WHERE a.entity IN (".getEntity('mo').")";
  171. $sql .= $db->order("a.tms", "DESC");
  172. $sql .= $db->plimit($max, 0);
  173. $resql = $db->query($sql);
  174. if ($resql) {
  175. print '<div class="div-table-responsive-no-min">';
  176. print '<table class="noborder centpercent">';
  177. print '<tr class="liste_titre">';
  178. print '<th colspan="4">'.$langs->trans("LatestMOModified", $max).'</th></tr>';
  179. $num = $db->num_rows($resql);
  180. if ($num) {
  181. $i = 0;
  182. while ($i < $num) {
  183. $obj = $db->fetch_object($resql);
  184. $staticmo->id = $obj->rowid;
  185. $staticmo->ref = $obj->ref;
  186. $staticmo->date_modification = $obj->datem;
  187. $staticmo->status = $obj->status;
  188. print '<tr class="oddeven">';
  189. print '<td>'.$staticmo->getNomUrl(1, 32).'</td>';
  190. print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
  191. print '<td class="right">'.$staticmo->getLibStatut(3).'</td>';
  192. print '</tr>';
  193. $i++;
  194. }
  195. } else {
  196. print '<tr class="oddeven">';
  197. print '<td><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
  198. print '</tr>';
  199. }
  200. print "</table></div>";
  201. print "<br>";
  202. } else {
  203. dol_print_error($db);
  204. }
  205. print '</div></div>';
  206. $parameters = array(
  207. //'type' => $type,
  208. 'user' => $user,
  209. );
  210. $reshook = $hookmanager->executeHooks('dashboardMRP', $parameters);
  211. // End of page
  212. llxFooter();
  213. $db->close();