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';
45$langs->loadLangs(array(
'mrp',
'products',
'companies'));
52$fieldvalue = (!empty($id) ?
$id : (!empty($ref) ? $ref :
''));
53$fieldtype = (!empty($ref) ?
'ref' :
'rowid');
57 $socid = $user->socid;
61$hookmanager->initHooks(array(
'productstatsmo'));
65$sortfield =
GETPOST(
'sortfield',
'aZ09comma');
66$sortorder =
GETPOST(
'sortorder',
'aZ09comma');
67if (empty($sortorder)) {
70if (empty($sortfield)) {
71 $sortfield =
"c.date_valid";
74if (empty($page) || $page == -1) {
77$offset = $limit * $page;
84if (
GETPOST(
'button_removefilter_x',
'alpha') ||
GETPOST(
'button_removefilter',
'alpha')) {
89$result =
restrictedArea($user,
'produit|service', $fieldvalue,
'product&product',
'',
'', $fieldtype);
96$staticmo =
new Mo(
$db);
102if ($id > 0 || !empty($ref)) {
104 $result = $product->fetch($id, $ref);
108 $parameters = array(
'id' => $id);
109 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $product, $action);
114 llxHeader(
"",
"", $langs->trans(
"CardProduct".$product->type),
'', 0, 0,
'',
'',
'mod-product page-stats_mo');
118 $titre = $langs->trans(
"CardProduct".$product->type);
122 $reshook = $hookmanager->executeHooks(
'formObjectOptions', $parameters, $product, $action);
123 print $hookmanager->resPrint;
128 $linkback =
'<a href="'.DOL_URL_ROOT.
'/product/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
131 if ($user->socid && !in_array(
'product', explode(
',',
getDolGlobalString(
'MAIN_MODULES_FOR_EXTERNAL')))) {
135 dol_banner_tab(
$object,
'ref', $linkback, $shownav,
'ref');
137 print
'<div class="fichecenter">';
139 print
'<div class="clearboth"></div>';
140 print
'<table class="noborder tableforfield centpercent">';
147 print
'<div class="clearboth"></div>';
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";
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);
169 if (!empty($search_year)) {
170 $sql .=
' AND YEAR(c.date_valid) = '.((int) $search_year);
173 $sql .=
" AND s.rowid = ".((int) $socid);
175 $sql .=
" GROUP BY c.rowid, c.ref, c.date_valid, c.status";
177 $sql .=
$db->order($sortfield, $sortorder);
184 $totalofrecords =
'';
186 $result =
$db->query($sql);
187 $totalofrecords =
$db->num_rows($result);
190 $sql .=
$db->plimit($limit + 1, $offset);
192 $result =
$db->query($sql);
194 $num =
$db->num_rows($result);
196 $option =
'&id='.$product->id;
198 if ($limit > 0 && $limit !=
$conf->liste_limit) {
199 $option .=
'&limit='.((int) $limit);
201 if (!empty($search_month)) {
202 $option .=
'&search_month='.urlencode((
string) ($search_month));
204 if (!empty($search_year)) {
205 $option .=
'&search_year='.urlencode((
string) ($search_year));
208 print
'<span id="anchorundermenu" class="anchorundermenu"></span>';
209 print
'<form method="post" action="'.$_SERVER[
'PHP_SELF'].
'?id='.$product->id.
'" name="search_form">'.
"\n";
210 print
'<input type="hidden" name="token" value="'.newToken().
'">';
211 print
'<input type="hidden" name="page_y" value="">';
212 print
'<input type="hidden" name="sortfield" value="'.$sortfield.
'"/>';
213 print
'<input type="hidden" name="sortorder" value="'.$sortorder.
'"/>';
216 print_barre_liste($langs->trans(
"MOs"), $page, $_SERVER[
"PHP_SELF"], $option, $sortfield, $sortorder,
'', $num, $totalofrecords,
'', 0,
'',
'', $limit, 0, 0, 1);
219 $option .=
'&page='.urlencode((
string) ($page));
222 print
'<div class="liste_titre liste_titre_bydiv centpercent">';
223 print
'<div class="divsearchfield">';
224 print $langs->trans(
'Period').
' ('.$langs->trans(
"DateCreation").
') - ';
225 print $langs->trans(
'Month').
':<input class="flat" type="text" size="4" name="search_month" value="'.($search_month > 0 ? $search_month :
'').
'"> ';
226 print $langs->trans(
'Year').
':'.$formother->selectyear(($search_year ? (
string) $search_year :
'-1'),
'search_year', 1, 20, 5);
227 print
'<div style="vertical-align: middle; display: inline-block">';
228 print
'<input type="image" class="liste_titre reposition" 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")).
'">';
229 print
'<input type="image" class="liste_titre reposition" 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")).
'">';
235 print
'<div class="div-table-responsive">';
236 print
'<table class="tagtable liste listwithfilterbefore" width="100%">';
238 print
'<tr class="liste_titre">';
239 print_liste_field_titre(
"Ref", $_SERVER[
"PHP_SELF"],
"c.rowid",
"",
"&id=".$product->id,
'', $sortfield, $sortorder);
241 print_liste_field_titre(
"Date", $_SERVER[
"PHP_SELF"],
"c.date_valid",
"",
"&id=".$product->id,
'align="center"', $sortfield, $sortorder);
243 print_liste_field_titre(
"ToConsume", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
244 print_liste_field_titre(
"QtyAlreadyConsumed", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
245 print_liste_field_titre(
"QtyToProduce", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
246 print_liste_field_titre(
"QtyAlreadyProduced", $_SERVER[
"PHP_SELF"],
"",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'center ');
247 print_liste_field_titre(
"Status", $_SERVER[
"PHP_SELF"],
"b.status",
"",
"&id=".$product->id,
'', $sortfield, $sortorder,
'right ');
250 $motmp =
new Mo(
$db);
253 while ($i < min($num, $limit)) {
254 $objp =
$db->fetch_object($result);
256 $motmp->id = $objp->rowid;
257 $motmp->ref = $objp->ref;
258 $motmp->status = $objp->status;
260 print
'<tr class="oddeven">';
262 print $motmp->getNomUrl(1,
'production');
264 print
"<td align=\"center\">";
268 print
'<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume :
'').
'</td>';
269 print
'<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed :
'').
'</td>';
270 print
'<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce :
'').
'</td>';
271 print
'<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced :
'').
'</td>';
273 print
'<td class="right">'.$motmp->getLibStatut(2).
'</td>';
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
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.