dolibarr 22.0.5
index.php
Go to the documentation of this file.
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-2024 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
9 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
33require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
34require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
35
44// Initialize a technical object to manage hooks. Note that conf->hooks_modules contains array
45$hookmanager->initHooks(array('mrpindex'));
46
47// Load translation files required by the page
48$langs->loadLangs(array("companies", "mrp"));
49
50// Security check
51$result = restrictedArea($user, 'bom|mrp');
52
53$max = getDolGlobalInt('MAIN_SIZE_SHORTLIST_LIMIT', 5);
54
55
56/*
57 * View
58 */
59
60$staticbom = new BOM($db);
61$staticmo = new Mo($db);
62
63$title = $langs->trans('MRP');
64$help_url = 'EN:Module_Manufacturing_Orders|FR:Module_Ordres_de_Fabrication|DE:Modul_Fertigungsauftrag';
65
66llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-mrp page-index');
67
68print load_fiche_titre($langs->trans("MRPArea"), '', 'mrp');
69
70
71print '<div class="fichecenter">';
72
73print '<div class="twocolumns">';
74
75print '<div class="firstcolumn fichehalfleft boxhalfleft" id="boxhalfleft">';
76
77
78/*
79 * Statistics
80 */
81
82if (isModEnabled('mrp') && $conf->use_javascript_ajax) {
83 $sql = "SELECT COUNT(t.rowid) as nb, status";
84 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as t";
85 $sql .= " GROUP BY t.status";
86 $sql .= " ORDER BY t.status ASC";
87 $resql = $db->query($sql);
88
89 if ($resql) {
90 $num = $db->num_rows($resql);
91 $i = 0;
92
93 $totalnb = 0;
94 $dataseries = array();
95 $colorseries = array();
96 $vals = array();
97
98 include DOL_DOCUMENT_ROOT.'/theme/'.$conf->theme.'/theme_vars.inc.php';
99
100 while ($i < $num) {
101 $obj = $db->fetch_object($resql);
102 if ($obj) {
103 $vals[$obj->status] = $obj->nb;
104
105 $totalnb += $obj->nb;
106 }
107 $i++;
108 }
109 $db->free($resql);
110
111 print '<div class="div-table-responsive-no-min">';
112 print '<table class="noborder nohover centpercent">';
113 print '<tr class="liste_titre"><th colspan="2">'.$langs->trans("Statistics").' - '.$langs->trans("ManufacturingOrder").'</th>';
114 print '</tr>'."\n";
115 $listofstatus = array(0, 1, 2, 3, 9);
116 foreach ($listofstatus as $status) {
117 $dataseries[] = array($staticmo->LibStatut($status, 1), (isset($vals[$status]) ? (int) $vals[$status] : 0));
118 if ($status == Mo::STATUS_DRAFT) {
119 $colorseries[$status] = '-'.$badgeStatus0;
120 }
121 if ($status == Mo::STATUS_VALIDATED) {
122 $colorseries[$status] = $badgeStatus1;
123 }
124 if ($status == Mo::STATUS_INPROGRESS) {
125 $colorseries[$status] = $badgeStatus4;
126 }
127 if ($status == Mo::STATUS_PRODUCED) {
128 $colorseries[$status] = $badgeStatus6;
129 }
130 if ($status == Mo::STATUS_CANCELED) {
131 $colorseries[$status] = $badgeStatus9;
132 }
133
134 if (empty($conf->use_javascript_ajax)) {
135 print '<tr class="oddeven">';
136 print '<td>'.$staticmo->LibStatut($status, 0).'</td>';
137 print '<td class="right"><a href="list.php?statut='.$status.'">'.(isset($vals[$status]) ? $vals[$status] : 0).'</a></td>';
138 print "</tr>\n";
139 }
140 }
141 if ($conf->use_javascript_ajax) {
142 print '<tr><td class="center" colspan="2">';
143
144 include_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
145 $dolgraph = new DolGraph();
146 $dolgraph->SetData($dataseries);
147 $dolgraph->SetDataColor(array_values($colorseries));
148 $dolgraph->setShowLegend(2);
149 $dolgraph->setShowPercent(1);
150 $dolgraph->SetType(array('pie'));
151 $dolgraph->SetHeight('200');
152 $dolgraph->draw('idgraphstatus');
153 print $dolgraph->show($totalnb ? 0 : 1);
154
155 print '</td></tr>';
156 }
157 print "</table>";
158 print "</div>";
159
160 print "<br>";
161 } else {
162 dol_print_error($db);
163 }
164}
165
166print '<br>';
167
168
169print '</div><div class="secondcolumn fichehalfright boxhalfright" id="boxhalfright">';
170
171
172/*
173 * Last modified BOM
174 */
175
176if (isModEnabled('bom')) {
177 $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status, a.fk_product";
178 $sql .= " FROM ".MAIN_DB_PREFIX."bom_bom as a";
179 $sql .= " WHERE a.entity IN (".getEntity('bom').")";
180 $sql .= $db->order("a.tms", "DESC");
181 $sql .= $db->plimit($max, 0);
182
183 $resql = $db->query($sql);
184 if ($resql) {
185 print '<div class="div-table-responsive-no-min">';
186 print '<table class="noborder centpercent">';
187 print '<tr class="liste_titre">';
188 print '<th colspan="2">'.$langs->trans("LatestBOMModified", $max);
189 $lastmodified = '<a href="'.DOL_URL_ROOT.'/bom/bom_list.php?sortfield=t.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
190 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
191 $lastmodified .= '</a>';
192 print $lastmodified;
193 print '</th>';
194 print '<th class="right">';
195 //print '<a href="'.DOL_URL_ROOT.'/bom/bom_list.php?sortfield=t.tms&sortorder=DESC">'.img_picto($langs->trans("FullList"), 'bom');
196 print '</th>';
197 print '</tr>';
198
199 $num = $db->num_rows($resql);
200 if ($num) {
201 $i = 0;
202 while ($i < $num) {
203 $obj = $db->fetch_object($resql);
204
205 $staticbom->id = $obj->rowid;
206 $staticbom->ref = $obj->ref;
207 $staticbom->fk_product = $obj->fk_product;
208 $staticbom->date_modification = $obj->datem;
209 $staticbom->status = $obj->status;
210
211 print '<tr class="oddeven">';
212 print '<td>'.$staticbom->getNomUrl(1, '32').'</td>';
213 print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
214 print '<td class="right">'.$staticbom->getLibStatut(3).'</td>';
215 print '</tr>';
216 $i++;
217 }
218 } else {
219 print '<tr class="oddeven">';
220 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
221 print '</tr>';
222 }
223 print '</table>';
224 print '</div>';
225 print '<br>';
226 } else {
227 dol_print_error($db);
228 }
229}
230
231
232/*
233 * Last modified MOs
234 */
235
236if (isModEnabled('mrp')) {
237 $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status";
238 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as a";
239 $sql .= " WHERE a.entity IN (".getEntity('mo').")";
240 $sql .= $db->order("a.tms", "DESC");
241 $sql .= $db->plimit($max, 0);
242
243 $sql = "SELECT a.rowid, a.status, a.ref, a.tms as datem, a.status";
244 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as a";
245 $sql .= " WHERE a.entity IN (".getEntity('mo').")";
246 $sql .= $db->order("a.tms", "DESC");
247 $sql .= $db->plimit($max, 0);
248
249 $resql = $db->query($sql);
250 if ($resql) {
251 print '<div class="div-table-responsive-no-min">';
252 print '<table class="noborder centpercent">';
253 print '<tr class="liste_titre">';
254 print '<th colspan="2">'.$langs->trans("LatestMOModified", $max);
255 $lastmodified = '<a href="'.DOL_URL_ROOT.'/mrp/mo_list.php?sortfield=t.tms&sortorder=DESC" title="'.$langs->trans("FullList").'">';
256 $lastmodified .= '<span class="badge marginleftonlyshort">...</span>';
257 $lastmodified .= '</a>';
258 print $lastmodified;
259 print '</th>';
260 print '<th class="right">';
261 //print '<a href="'.DOL_URL_ROOT.'/mrp/mo_list.php?sortfield=t.tms&sortorder=DESC">'.img_picto($langs->trans("FullList"), 'mrp');
262 print '</th>';
263 print '</tr>';
264
265 $num = $db->num_rows($resql);
266 if ($num) {
267 $i = 0;
268 while ($i < $num) {
269 $obj = $db->fetch_object($resql);
270
271 $staticmo->id = $obj->rowid;
272 $staticmo->ref = $obj->ref;
273 $staticmo->date_modification = $obj->datem;
274 $staticmo->status = $obj->status;
275
276 print '<tr class="oddeven">';
277 print '<td>'.$staticmo->getNomUrl(1, '32').'</td>';
278 print '<td>'.dol_print_date($db->jdate($obj->datem), 'dayhour').'</td>';
279 print '<td class="right">'.$staticmo->getLibStatut(3).'</td>';
280 print '</tr>';
281 $i++;
282 }
283 } else {
284 print '<tr class="oddeven">';
285 print '<td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td>';
286 print '</tr>';
287 }
288 print '</table>';
289 print '</div>';
290 print '<br>';
291 } else {
292 dol_print_error($db);
293 }
294}
295
296print '</div></div></div>';
297
298$object = new stdClass();
299$parameters = array(
300 //'type' => $type,
301 'user' => $user,
302);
303$reshook = $hookmanager->executeHooks('dashboardMRP', $parameters, $object);
304
305// End of page
306llxFooter();
307$db->close();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
Class for BOM.
Definition bom.class.php:42
Class to build graphs.
Class for Mo.
Definition mo.class.php:35
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.