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