dolibarr  13.0.2
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-2009 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
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';
30 
31 // Load translation files required by the page
32 $langs->loadLangs(array('mrp', 'products', 'companies'));
33 
34 $id = GETPOST('id', 'int');
35 $ref = GETPOST('ref', 'alpha');
36 
37 // Security check
38 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
39 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
40 if ($user->socid) $socid = $user->socid;
41 $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
42 
43 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
44 $hookmanager->initHooks(array('productstatscontract'));
45 
46 $mesg = '';
47 
48 // Load variable for pagination
49 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
50 $sortfield = GETPOST("sortfield", 'alpha');
51 $sortorder = GETPOST("sortorder", 'alpha');
52 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
53 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
54 $offset = $limit * $page;
55 $pageprev = $page - 1;
56 $pagenext = $page + 1;
57 if (!$sortorder) $sortorder = "DESC";
58 if (!$sortfield) $sortfield = "c.date_valid";
59 
60 
61 /*
62  * View
63  */
64 
65 $staticmo = new Mo($db);
66 $staticmoligne = new MoLine($db);
67 
68 $form = new Form($db);
69 
70 if ($id > 0 || !empty($ref))
71 {
72  $product = new Product($db);
73  $result = $product->fetch($id, $ref);
74 
75  $object = $product;
76 
77  $parameters = array('id'=>$id);
78  $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
79  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
80 
81  llxHeader("", "", $langs->trans("CardProduct".$product->type));
82 
83  if ($result > 0)
84  {
85  $head = product_prepare_head($product);
86  $titre = $langs->trans("CardProduct".$product->type);
87  $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
88  print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
89 
90  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
91  print $hookmanager->resPrint;
92  if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
93 
94  $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
95 
96  $shownav = 1;
97  if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) $shownav = 0;
98 
99  dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
100 
101  print '<div class="fichecenter">';
102 
103  print '<div class="underbanner clearboth"></div>';
104  print '<table class="border tableforfield" width="100%">';
105 
106  $nboflines = show_stats_for_company($product, $socid);
107 
108  print "</table>";
109 
110  print '</div>';
111  print '<div style="clear:both"></div>';
112 
114 
115 
116  $now = dol_now();
117 
118  $sql = "SELECT";
119  $sql .= ' sum('.$db->ifsql("cd.role='toconsume'", "cd.qty", 0).') as nb_toconsume,';
120  $sql .= ' sum('.$db->ifsql("cd.role='consumed'", "cd.qty", 0).') as nb_consumed,';
121  $sql .= ' sum('.$db->ifsql("cd.role='toproduce'", "cd.qty", 0).') as nb_toproduce,';
122  $sql .= ' sum('.$db->ifsql("cd.role='produced'", "cd.qty", 0).') as nb_produced,';
123  $sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status";
124  //$sql .= " s.nom as name, s.rowid as socid, s.code_client";
125  $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
126  $sql .= ", ".MAIN_DB_PREFIX."mrp_production as cd";
127  $sql .= " WHERE c.rowid = cd.fk_mo";
128  $sql .= " AND c.entity IN (".getEntity('mo').")";
129  $sql .= " AND cd.fk_product =".$product->id;
130  if ($socid) $sql .= " AND s.rowid = ".$socid;
131  $sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status";
132  //$sql .= ", s.nom, s.rowid, s.code_client";
133  $sql .= $db->order($sortfield, $sortorder);
134 
135  //Calcul total qty and amount for global if full scan list
136  $total_ht = 0;
137  $total_qty = 0;
138 
139  // Count total nb of records
140  $totalofrecords = '';
141  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
142  {
143  $result = $db->query($sql);
144  $totalofrecords = $db->num_rows($result);
145  }
146 
147  $sql .= $db->plimit($limit + 1, $offset);
148 
149  $result = $db->query($sql);
150  if ($result)
151  {
152  $num = $db->num_rows($result);
153 
154  if ($limit > 0 && $limit != $conf->liste_limit) $option .= '&limit='.urlencode($limit);
155  if (!empty($id)) $option .= '&id='.$product->id;
156  if (!empty($search_month)) $option .= '&search_month='.urlencode($search_month);
157  if (!empty($search_year)) $option .= '&search_year='.urlencode($search_year);
158 
159  print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$product->id.'" name="search_form">'."\n";
160  if (!empty($sortfield))
161  print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
162  if (!empty($sortorder))
163  print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
164 
165  print_barre_liste($langs->trans("Mos"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
166 
167  if (!empty($page)) $option .= '&page='.urlencode($page);
168 
169  $i = 0;
170  print '<div class="div-table-responsive">';
171  print '<table class="tagtable liste listwithfilterbefore" width="100%">';
172 
173  print '<tr class="liste_titre">';
174  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
175  //print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
176  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", "&amp;id=".$product->id, 'align="center"', $sortfield, $sortorder);
177  //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
178  print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
179  print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
180  print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
181  print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
182  print "</tr>\n";
183 
184  $motmp = new Mo($db);
185 
186  if ($num > 0)
187  {
188  while ($i < min($num, $limit))
189  {
190  $objp = $db->fetch_object($result);
191 
192  $motmp->id = $objp->rowid;
193  $motmp->ref = $objp->ref;
194 
195  print '<tr class="oddeven">';
196  print '<td>';
197  print $motmp->getNomUrl(1, 'production');
198  print "</td>\n";
199  print "<td align=\"center\">";
200  print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."</td>";
201  //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
202  //print '<td align="right">';
203  print '<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume : '').'</td>';
204  print '<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed : '').'</td>';
205  print '<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce : '').'</td>';
206  print '<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced : '').'</td>';
207  //$mostatic->LibStatut($objp->statut,5).'</td>';
208  print "</tr>\n";
209  $i++;
210  }
211  }
212 
213  print '</table>';
214  print '</div>';
215  print '</form>';
216  } else {
217  dol_print_error($db);
218  }
219  $db->free($result);
220  }
221 } else {
222  dol_print_error();
223 }
224 
225 // End of page
226 llxFooter();
227 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage products or services.
dol_now($mode= 'auto')
Return date for now.
Class for Mo.
Definition: mo.class.php:34
const TYPE_SERVICE
Service.
Class MoLine.
Definition: mo.class.php:1364
show_stats_for_company($product, $socid)
Show stats for company.
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
print_barre_liste($titre, $page, $file, $options= '', $sortfield= '', $sortorder= '', $morehtmlcenter= '', $num=-1, $totalnboflines= '', $picto= 'generic', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow= '')
Print a title with navigation controls for pagination.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35