26 require
'../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.
'/core/lib/product.lib.php';
28 require_once DOL_DOCUMENT_ROOT.
'/mrp/class/mo.class.php';
29 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
32 $langs->loadLangs(array(
'mrp',
'products',
'companies'));
38 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref :
''));
39 $fieldtype = (!empty($ref) ?
'ref' :
'rowid');
41 $socid = $user->socid;
45 $hookmanager->initHooks(array(
'productstatsmo'));
48 $limit =
GETPOST(
'limit',
'int') ?
GETPOST(
'limit',
'int') : $conf->liste_limit;
49 $sortfield =
GETPOST(
'sortfield',
'aZ09comma');
50 $sortorder =
GETPOST(
'sortorder',
'aZ09comma');
52 if (empty($page) || $page == -1) {
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
62 $sortfield =
"c.date_valid";
65 $result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
72 $staticmo =
new Mo($db);
73 $staticmoligne =
new MoLine($db);
77 if ($id > 0 || !empty($ref)) {
79 $result = $product->fetch($id, $ref);
83 $parameters = array(
'id'=>$id);
84 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
89 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type));
93 $titre = $langs->trans(
"CardProduct".$product->type);
97 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
98 print $hookmanager->resPrint;
103 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
106 if ($user->socid && !in_array(
'product', explode(
',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
112 print
'<div class="fichecenter">';
114 print
'<div class="underbanner clearboth"></div>';
115 print
'<table class="border tableforfield" width="100%">';
122 print
'<div style="clear:both"></div>';
130 $sql .=
" sum(".$db->ifsql(
"cd.role='toconsume'",
"cd.qty", 0).
') as nb_toconsume,';
131 $sql .=
" sum(".$db->ifsql(
"cd.role='consumed'",
"cd.qty", 0).
') as nb_consumed,';
132 $sql .=
" sum(".$db->ifsql(
"cd.role='toproduce'",
"cd.qty", 0).
') as nb_toproduce,';
133 $sql .=
" sum(".$db->ifsql(
"cd.role='produced'",
"cd.qty", 0).
') as nb_produced,';
134 $sql .=
" c.rowid as rowid, c.ref, c.date_valid, c.status";
136 $sql .=
" FROM ".MAIN_DB_PREFIX.
"mrp_mo as c";
137 $sql .=
", ".MAIN_DB_PREFIX.
"mrp_production as cd";
138 $sql .=
" WHERE c.rowid = cd.fk_mo";
139 $sql .=
" AND c.entity IN (".getEntity(
'mo').
")";
140 $sql .=
" AND cd.fk_product = ".((int) $product->id);
142 $sql .=
" AND s.rowid = ".((int) $socid);
144 $sql .=
" GROUP BY c.rowid, c.ref, c.date_valid, c.status";
146 $sql .= $db->order($sortfield, $sortorder);
153 $totalofrecords =
'';
154 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
155 $result = $db->query($sql);
156 $totalofrecords = $db->num_rows($result);
159 $sql .= $db->plimit($limit + 1, $offset);
161 $result = $db->query($sql);
163 $num = $db->num_rows($result);
165 $option .=
'&id='.$product->id;
167 if ($limit > 0 && $limit != $conf->liste_limit) {
168 $option .=
'&limit='.urlencode($limit);
170 if (!empty($search_month)) {
171 $option .=
'&search_month='.urlencode($search_month);
173 if (!empty($search_year)) {
174 $option .=
'&search_year='.urlencode($search_year);
177 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
178 print
'<input type="hidden" name="token" value="'.newToken().
'">';
179 if (!empty($sortfield)) {
180 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
182 if (!empty($sortorder)) {
183 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
186 print_barre_liste($langs->trans(
"MOs"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
189 $option .=
'&page='.urlencode($page);
193 print
'<div class="div-table-responsive">';
194 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
196 print
'<tr class="liste_titre">';
197 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
199 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
201 print_liste_field_titre(
"ToConsume", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
202 print_liste_field_titre(
"QtyAlreadyConsumed", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
203 print_liste_field_titre(
"QtyToProduce", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
204 print_liste_field_titre(
"QtyAlreadyProduced", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
205 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'right ');
208 $motmp =
new Mo($db);
211 while ($i < min($num, $limit)) {
212 $objp = $db->fetch_object($result);
214 $motmp->id = $objp->rowid;
215 $motmp->ref = $objp->ref;
216 $motmp->status = $objp->status;
218 print
'<tr class="oddeven">';
220 print $motmp->getNomUrl(1,
'production');
222 print
"<td align=\"center\">";
223 print
dol_print_date($db->jdate($objp->date_valid),
'dayhour').
"</td>";
226 print
'<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume :
'').
'</td>';
227 print
'<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed :
'').
'</td>';
228 print
'<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce :
'').
'</td>';
229 print
'<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced :
'').
'</td>';
231 print
'<td class="right">'.$motmp->getLibStatut(2).
'</td>';