dolibarr 23.0.3
mo.php
Go to the documentation of this file.
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.'/core/class/html.formother.class.php';
35
44// Load translation files required by the page
45$langs->loadLangs(array('mrp', 'products', 'companies'));
46
47$id = GETPOSTINT('id');
48;
49$ref = GETPOST('ref', 'alpha');
50
51// Security check
52$fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
53$fieldtype = (!empty($ref) ? 'ref' : 'rowid');
54
55$socid = 0;
56if ($user->socid) {
57 $socid = $user->socid;
58}
59
60// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
61$hookmanager->initHooks(array('productstatsmo'));
62
63// Load variable for pagination
64$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
65$sortfield = GETPOST('sortfield', 'aZ09comma');
66$sortorder = GETPOST('sortorder', 'aZ09comma');
67if (empty($sortorder)) {
68 $sortorder = "DESC";
69}
70if (empty($sortfield)) {
71 $sortfield = "c.date_valid";
72}
73$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
74if (empty($page) || $page == -1) {
75 $page = 0;
76} // If $page is not defined, or '' or -1
77$offset = $limit * $page;
78$pageprev = $page - 1;
79$pagenext = $page + 1;
80
81$search_month = GETPOSTINT('search_month');
82$search_year = GETPOSTINT('search_year');
83
84if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
85 $search_month = '';
86 $search_year = '';
87}
88
89$result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
90
91
92/*
93 * View
94 */
95
96$staticmo = new Mo($db);
97$staticmoligne = new MoLine($db);
98
99$form = new Form($db);
100$formother = new FormOther($db);
101
102if ($id > 0 || !empty($ref)) {
103 $product = new Product($db);
104 $result = $product->fetch($id, $ref);
105
106 $object = $product;
107
108 $parameters = array('id' => $id);
109 $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
110 if ($reshook < 0) {
111 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
112 }
113
114 llxHeader("", "", $langs->trans("CardProduct".$product->type), '', 0, 0, '', '', 'mod-product page-stats_mo');
115
116 if ($result > 0) {
117 $head = product_prepare_head($product);
118 $titre = $langs->trans("CardProduct".$product->type);
119 $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
120 print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
121
122 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
123 print $hookmanager->resPrint;
124 if ($reshook < 0) {
125 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126 }
127
128 $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
129
130 $shownav = 1;
131 if ($user->socid && !in_array('product', explode(',', getDolGlobalString('MAIN_MODULES_FOR_EXTERNAL')))) {
132 $shownav = 0;
133 }
134
135 dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
136
137 print '<div class="fichecenter">';
138
139 print '<div class="underbanner clearboth"></div>';
140 print '<table class="border tableforfield centpercent">';
141
142 $nboflines = show_stats_for_company($product, $socid);
143
144 print "</table>";
145
146 print '</div>';
147 print '<div class="clearboth"></div>';
148
149 print dol_get_fiche_end();
150
151
152 $now = dol_now();
153
154 $sql = "SELECT";
155 $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", '0').') as nb_toconsume,';
156 $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", '0').') as nb_consumed,';
157 $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", '0').') as nb_toproduce,';
158 $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", '0').') as nb_produced,';
159 $sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status";
160 //$sql .= " s.nom as name, s.rowid as socid, s.code_client";
161 $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
162 $sql .= ", ".MAIN_DB_PREFIX."mrp_production as cd";
163 $sql .= " WHERE c.rowid = cd.fk_mo";
164 $sql .= " AND c.entity IN (".getEntity('mo').")";
165 $sql .= " AND cd.fk_product = ".((int) $product->id);
166 if (!empty($search_month)) {
167 $sql .= ' AND MONTH(c.date_valid) = '.((int) $search_month);
168 }
169 if (!empty($search_year)) {
170 $sql .= ' AND YEAR(c.date_valid) = '.((int) $search_year);
171 }
172 if ($socid > 0) {
173 $sql .= " AND s.rowid = ".((int) $socid);
174 }
175 $sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status";
176 //$sql .= ", s.nom, s.rowid, s.code_client";
177 $sql .= $db->order($sortfield, $sortorder);
178
179 //Calcul total qty and amount for global if full scan list
180 $total_ht = 0;
181 $total_qty = 0;
182
183 // Count total nb of records
184 $totalofrecords = '';
185 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
186 $result = $db->query($sql);
187 $totalofrecords = $db->num_rows($result);
188 }
189
190 $sql .= $db->plimit($limit + 1, $offset);
191
192 $result = $db->query($sql);
193 if ($result) {
194 $num = $db->num_rows($result);
195
196 $option = '&id='.$product->id;
197
198 if ($limit > 0 && $limit != $conf->liste_limit) {
199 $option .= '&limit='.((int) $limit);
200 }
201 if (!empty($search_month)) {
202 $option .= '&search_month='.urlencode((string) ($search_month));
203 }
204 if (!empty($search_year)) {
205 $option .= '&search_year='.urlencode((string) ($search_year));
206 }
207
208 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$product->id.'" name="search_form">'."\n";
209 print '<input type="hidden" name="token" value="'.newToken().'">';
210 print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
211 print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
212
213 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
214 print_barre_liste($langs->trans("MOs"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
215
216 if (!empty($page)) {
217 $option .= '&page='.urlencode((string) ($page));
218 }
219
220 print '<div class="liste_titre liste_titre_bydiv centpercent">';
221 print '<div class="divsearchfield">';
222 print $langs->trans('Period').' ('.$langs->trans("DateCreation").') - ';
223 print $langs->trans('Month').':<input class="flat" type="text" size="4" name="search_month" value="'.($search_month > 0 ? $search_month : '').'"> ';
224 print $langs->trans('Year').':'.$formother->selectyear(($search_year ? (string) $search_year : '-1'), 'search_year', 1, 20, 5);
225 print '<div style="vertical-align: middle; display: inline-block">';
226 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")).'">';
227 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")).'">';
228 print '</div>';
229 print '</div>';
230 print '</div>';
231
232 $i = 0;
233 print '<div class="div-table-responsive">';
234 print '<table class="tagtable liste listwithfilterbefore" width="100%">';
235
236 print '<tr class="liste_titre">';
237 print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
238 //print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
239 print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", "&amp;id=".$product->id, 'align="center"', $sortfield, $sortorder);
240 //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
241 print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
242 print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
243 print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
244 print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
245 print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "b.status", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'right ');
246 print "</tr>\n";
247
248 $motmp = new Mo($db);
249
250 if ($num > 0) {
251 while ($i < min($num, $limit)) {
252 $objp = $db->fetch_object($result);
253
254 $motmp->id = $objp->rowid;
255 $motmp->ref = $objp->ref;
256 $motmp->status = $objp->status;
257
258 print '<tr class="oddeven">';
259 print '<td>';
260 print $motmp->getNomUrl(1, 'production');
261 print "</td>\n";
262 print "<td align=\"center\">";
263 print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."</td>";
264 //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
265 //print '<td align="right">';
266 print '<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume : '').'</td>';
267 print '<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed : '').'</td>';
268 print '<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce : '').'</td>';
269 print '<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced : '').'</td>';
270 //$mostatic->LibStatut($objp->statut,5).'</td>';
271 print '<td class="right">'.$motmp->getLibStatut(2).'</td>';
272 print "</tr>\n";
273 $i++;
274 }
275 }
276
277 print '</table>';
278 print '</div>';
279 print '</form>';
280 } else {
281 dol_print_error($db);
282 }
283 $db->free($result);
284 }
285} else {
287}
288
289// End of page
290llxFooter();
291$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
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.
const TYPE_SERVICE
Service.
dol_now($mode='gmt')
Return date for now.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
product_prepare_head($object)
Prepare array with list of tabs.
show_stats_for_company($product, $socid)
Show stats for a product.
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.