dolibarr 22.0.5
mo.php
1<?php
2/* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2023 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
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
29// Load Dolibarr environment
30require '../../../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
32require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
33require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
34require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
35require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
36
45// Load translation files required by the page
46$langs->loadLangs(array('mrp', 'products', 'companies', 'productbatch'));
47
48$id = GETPOSTINT('id');
49$ref = GETPOST('ref', 'alpha');
50
51// Security check
52$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
53$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
54$socid = 0;
55if ($user->socid) {
56 $socid = $user->socid;
57}
58
59// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
60$hookmanager->initHooks(array('batchproductstatsmo'));
61
62// Load variable for pagination
63$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
64$sortfield = GETPOST('sortfield', 'aZ09comma');
65$sortorder = GETPOST('sortorder', 'aZ09comma');
66$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
67if (empty($page) || $page == -1) {
68 $page = 0;
69} // If $page is not defined, or '' or -1
70$offset = $limit * $page;
71$pageprev = $page - 1;
72$pagenext = $page + 1;
73if (empty($sortorder)) {
74 $sortorder = "DESC";
75}
76if (empty($sortfield)) {
77 $sortfield = "c.date_valid";
78}
79
80$search_month = GETPOSTINT('search_month');
81$search_year = GETPOSTINT('search_year');
82
83if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
84 $search_month = '';
85 $search_year = '';
86}
87
88if (!$user->hasRight('produit', 'lire')) {
90}
91
92
93/*
94 * View
95 */
96
97$staticmo = new Mo($db);
98$staticmoligne = new MoLine($db);
99
100$form = new Form($db);
101$formother = new FormOther($db);
102
103if ($id > 0 || !empty($ref)) {
104 $object = new Productlot($db);
105 $batch = '';
106 $objectid = 0;
107 if ($ref) {
108 $tmp = explode('_', $ref);
109 $objectid = $tmp[0];
110 $batch = $tmp[1];
111 }
112 $result = $object->fetch($id, $objectid, $batch);
113
114 $parameters = array('id' => $id);
115 $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
116 if ($reshook < 0) {
117 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
118 }
119
120 $helpurl = '';
121 $shortlabel = dol_trunc($object->batch, 16);
122 $title = $langs->trans('Batch')." ".$shortlabel." - ".$langs->trans('Referers');
123 $helpurl = 'EN:Module_Products|FR:Module_Produits|ES:M&oacute;dulo_Productos';
124
125 llxHeader('', $title, $helpurl, '', 0, 0, '', '', '', 'mod-product page-stock-stats_mo');
126
127 if ($result > 0) {
129 $titre = $langs->trans("CardProduct".$object->type);
130 $picto = 'lot';
131 $morehtmlref = '';
132 print dol_get_fiche_head($head, 'referers', $langs->trans("Batch"), -1, $object->picto);
133
134 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
135 print $hookmanager->resPrint;
136 if ($reshook < 0) {
137 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
138 }
139
140 $linkback = '<a href="'.DOL_URL_ROOT.'/product/stock/productlot_list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
141
142 $shownav = 1;
143 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
144 $shownav = 0;
145 }
146
147 dol_banner_tab($object, 'id', $linkback, $shownav, 'rowid', 'batch', $morehtmlref);
148
149 print '<div class="fichecenter">';
150
151 print '<div class="underbanner clearboth"></div>';
152 print '<table class="border tableforfield" width="100%">';
153
154 // Product
155 print '<tr><td class="titlefield">'.$langs->trans("Product").'</td><td>';
156 $producttmp = new Product($db);
157 $producttmp->fetch($object->fk_product);
158 print $producttmp->getNomUrl(1, 'stock')." - ".$producttmp->label;
159 print '</td></tr>';
160 print "</table>";
161
162 echo '<br>';
163
164 print '<table class="border centpercent tableforfield" width="100%">';
165
166 $nboflines = show_stats_for_batch($object, $socid);
167
168 print "</table>";
169
170 print '</div>';
171 print '<div class="clearboth"></div>';
172
173 print dol_get_fiche_end();
174
175
176 $now = dol_now();
177
178 $sql = "SELECT";
179 // $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", 0).') as nb_toconsume,';
180 $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", '0').') as nb_consumed,';
181 // $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", 0).') as nb_toproduce,';
182 $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", '0').') as nb_produced,';
183 $sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status";
184 //$sql .= " s.nom as name, s.rowid as socid, s.code_client";
185 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
186 $sql .= ", ".MAIN_DB_PREFIX."mrp_production as cd";
187 $sql .= " WHERE c.rowid = cd.fk_mo";
188 $sql .= " AND c.entity IN (".getEntity('mo').")";
189 $sql .= " AND cd.batch = '".($db->escape($object->batch))."'";
190 if (!empty($search_month)) {
191 $sql .= ' AND MONTH(c.date_valid) IN ('.$db->sanitize((string) $search_month).')';
192 }
193 if (!empty($search_year)) {
194 $sql .= ' AND YEAR(c.date_valid) IN ('.$db->sanitize((string) $search_year).')';
195 }
196 if ($socid > 0) {
197 $sql .= " AND s.rowid = ".((int) $socid);
198 }
199 $sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status";
200 //$sql .= ", s.nom, s.rowid, s.code_client";
201 $sql .= $db->order($sortfield, $sortorder);
202
203 //Calcul total qty and amount for global if full scan list
204 $total_ht = 0;
205 $total_qty = 0;
206
207 // Count total nb of records
208 $totalofrecords = '';
209 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
210 $result = $db->query($sql);
211 $totalofrecords = $db->num_rows($result);
212 }
213
214 $sql .= $db->plimit($limit + 1, $offset);
215
216 $result = $db->query($sql);
217 if ($result) {
218 $num = $db->num_rows($result);
219
220 $option = '&id='.$object->id;
221
222 if ($limit > 0 && $limit != $conf->liste_limit) {
223 $option .= '&limit='.((int) $limit);
224 }
225 if (!empty($search_month)) {
226 $option .= '&search_month='.urlencode((string) ($search_month));
227 }
228 if (!empty($search_year)) {
229 $option .= '&search_year='.urlencode((string) ($search_year));
230 }
231
232 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" name="search_form">'."\n";
233 print '<input type="hidden" name="token" value="'.newToken().'">';
234 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
235 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
236
237 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
238 print_barre_liste($langs->trans("MOs"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
239
240 if (!empty($page)) {
241 $option .= '&page='.urlencode((string) ($page));
242 }
243
244 print '<div class="liste_titre liste_titre_bydiv centpercent">';
245 print '<div class="divsearchfield">';
246 print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
247 print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.$search_month.'"> ';
248 print $langs->trans('Year').':'.$formother->selectyear($search_year ? (string) $search_year : '-1', 'search_year', 1, 20, 5);
249 print '<div style="vertical-align: middle; display: inline-block">';
250 print '<input type="image" class="liste_titre" name="button_search" src="'.img_picto($langs->trans("Search"), 'search.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">';
251 print '<input type="image" class="liste_titre" name="button_removefilter" src="'.img_picto($langs->trans("Search"), 'searchclear.png', '', 0, 1).'" value="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'" title="'.dol_escape_htmltag($langs->trans("RemoveFilter")).'">';
252 print '</div>';
253 print '</div>';
254 print '</div>';
255
256 $i = 0;
257 print '<div class="div-table-responsive">';
258 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
259
260 print '<tr class="liste_titre">';
261
262 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder);
263 //print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$object->id, '', $sortfield, $sortorder);
264 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", $option."&amp;id=".$object->id, 'align="center"', $sortfield, $sortorder);
265 //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$object->id,'align="right"',$sortfield,$sortorder);
266 // print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
267 print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
268 // print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
269 print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder, 'center ');
270 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "c.status", "", $option."&amp;id=".$object->id, '', $sortfield, $sortorder, 'right ');
271 print "</tr>\n";
272
273 $motmp = new Mo($db);
274
275 $total_consumed = $total_produced = 0;
276
277 if ($num > 0) {
278 while ($i < min($num, $limit)) {
279 $objp = $db->fetch_object($result);
280
281 $motmp->id = $objp->rowid;
282 $motmp->ref = $objp->ref;
283 $motmp->status = $objp->status;
284
285 $total_consumed += $objp->nb_consumed;
286 $total_produced += $objp->nb_produced;
287
288 print '<tr class="oddeven">';
289 print '<td>';
290 print $motmp->getNomUrl(1, 'production');
291 print "</td>\n";
292 print "<td align=\"center\">";
293 print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."</td>";
294 //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
295 //print '<td align="right">';
296 // print '<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume : '').'</td>';
297 print '<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed : '').'</td>';
298 // print '<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce : '').'</td>';
299 print '<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced : '').'</td>';
300 //$mostatic->LibStatut($objp->statut,5).'</td>';
301 print '<td class="right">'.$motmp->getLibStatut(2).'</td>';
302 print "</tr>\n";
303 $i++;
304 }
305 }
306 print '<tr class="liste_total">';
307 if ($num < $limit) {
308 print '<td class="left">'.$langs->trans("Total").'</td>';
309 } else {
310 print '<td class="left">'.$langs->trans("Totalforthispage").'</td>';
311 }
312 print '<td></td>';
313 print '<td class="center">'.$total_consumed.'</td>';
314 print '<td class="center">'.$total_produced.'</td>';
315 print '<td></td>';
316 print "</table>";
317 print '</div>';
318 print '</form>';
319
320 print '</table>';
321 print '</div>';
322 print '</form>';
323 } else {
324 dol_print_error($db);
325 }
326 $db->free($result);
327 }
328} else {
330}
331
332// End of page
333llxFooter();
334$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
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 to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class for Mo.
Definition mo.class.php:35
Class MoLine.
Class to manage products or services.
Class with list of lots and properties.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
print_liste_field_titre($name, $file="", $field="", $begin="", $param="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
show_stats_for_batch($batch, $socid)
Show stats for product batch.
productlot_prepare_head($object)
Prepare array with list of tabs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.