dolibarr  16.0.5
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  *
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) {
41  $socid = $user->socid;
42 }
43 
44 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
45 $hookmanager->initHooks(array('productstatsmo'));
46 
47 // Load variable for pagination
48 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
52 if (empty($page) || $page == -1) {
53  $page = 0;
54 } // If $page is not defined, or '' or -1
55 $offset = $limit * $page;
56 $pageprev = $page - 1;
57 $pagenext = $page + 1;
58 if (!$sortorder) {
59  $sortorder = "DESC";
60 }
61 if (!$sortfield) {
62  $sortfield = "c.date_valid";
63 }
64 
65 $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
66 
67 
68 /*
69  * View
70  */
71 
72 $staticmo = new Mo($db);
73 $staticmoligne = new MoLine($db);
74 
75 $form = new Form($db);
76 
77 if ($id > 0 || !empty($ref)) {
78  $product = new Product($db);
79  $result = $product->fetch($id, $ref);
80 
81  $object = $product;
82 
83  $parameters = array('id'=>$id);
84  $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
85  if ($reshook < 0) {
86  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
87  }
88 
89  llxHeader("", "", $langs->trans("CardProduct".$product->type));
90 
91  if ($result > 0) {
92  $head = product_prepare_head($product);
93  $titre = $langs->trans("CardProduct".$product->type);
94  $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
95  print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
96 
97  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
98  print $hookmanager->resPrint;
99  if ($reshook < 0) {
100  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
101  }
102 
103  $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
104 
105  $shownav = 1;
106  if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
107  $shownav = 0;
108  }
109 
110  dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
111 
112  print '<div class="fichecenter">';
113 
114  print '<div class="underbanner clearboth"></div>';
115  print '<table class="border tableforfield" width="100%">';
116 
117  $nboflines = show_stats_for_company($product, $socid);
118 
119  print "</table>";
120 
121  print '</div>';
122  print '<div style="clear:both"></div>';
123 
124  print dol_get_fiche_end();
125 
126 
127  $now = dol_now();
128 
129  $sql = "SELECT";
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";
135  //$sql .= " s.nom as name, s.rowid as socid, s.code_client";
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);
141  if ($socid) {
142  $sql .= " AND s.rowid = ".((int) $socid);
143  }
144  $sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status";
145  //$sql .= ", s.nom, s.rowid, s.code_client";
146  $sql .= $db->order($sortfield, $sortorder);
147 
148  //Calcul total qty and amount for global if full scan list
149  $total_ht = 0;
150  $total_qty = 0;
151 
152  // Count total nb of records
153  $totalofrecords = '';
154  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
155  $result = $db->query($sql);
156  $totalofrecords = $db->num_rows($result);
157  }
158 
159  $sql .= $db->plimit($limit + 1, $offset);
160 
161  $result = $db->query($sql);
162  if ($result) {
163  $num = $db->num_rows($result);
164 
165  $option .= '&id='.$product->id;
166 
167  if ($limit > 0 && $limit != $conf->liste_limit) {
168  $option .= '&limit='.urlencode($limit);
169  }
170  if (!empty($search_month)) {
171  $option .= '&search_month='.urlencode($search_month);
172  }
173  if (!empty($search_year)) {
174  $option .= '&search_year='.urlencode($search_year);
175  }
176 
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.'"/>';
181  }
182  if (!empty($sortorder)) {
183  print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
184  }
185 
186  print_barre_liste($langs->trans("MOs"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
187 
188  if (!empty($page)) {
189  $option .= '&page='.urlencode($page);
190  }
191 
192  $i = 0;
193  print '<div class="div-table-responsive">';
194  print '<table class="tagtable liste listwithfilterbefore" width="100%">';
195 
196  print '<tr class="liste_titre">';
197  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
198  //print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
199  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", "&amp;id=".$product->id, 'align="center"', $sortfield, $sortorder);
200  //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
201  print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
202  print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
203  print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
204  print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
205  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "b.status", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'right ');
206  print "</tr>\n";
207 
208  $motmp = new Mo($db);
209 
210  if ($num > 0) {
211  while ($i < min($num, $limit)) {
212  $objp = $db->fetch_object($result);
213 
214  $motmp->id = $objp->rowid;
215  $motmp->ref = $objp->ref;
216  $motmp->status = $objp->status;
217 
218  print '<tr class="oddeven">';
219  print '<td>';
220  print $motmp->getNomUrl(1, 'production');
221  print "</td>\n";
222  print "<td align=\"center\">";
223  print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."</td>";
224  //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
225  //print '<td align="right">';
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>';
230  //$mostatic->LibStatut($objp->statut,5).'</td>';
231  print '<td class="right">'.$motmp->getLibStatut(2).'</td>';
232  print "</tr>\n";
233  $i++;
234  }
235  }
236 
237  print '</table>';
238  print '</div>';
239  print '</form>';
240  } else {
241  dol_print_error($db);
242  }
243  $db->free($result);
244  }
245 } else {
246  dol_print_error();
247 }
248 
249 // End of page
250 llxFooter();
251 $db->close();
restrictedArea
restrictedArea($user, $features, $objectid=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.
Definition: security.lib.php:234
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4844
MoLine
Class MoLine.
Definition: mo.class.php:1562
product_prepare_head
product_prepare_head($object)
Prepare array with list of tabs.
Definition: product.lib.php:35
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
Mo
Class for Mo.
Definition: mo.class.php:35
dol_banner_tab
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.
Definition: functions.lib.php:2046
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2514
print_barre_liste
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.
Definition: functions.lib.php:5257
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1822
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2018
GETPOSTISSET
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
Definition: functions.lib.php:386
print_liste_field_titre
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
Definition: functions.lib.php:5026
Product
Class to manage products or services.
Definition: product.class.php:46
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
show_stats_for_company
show_stats_for_company($product, $socid)
Show stats for company.
Definition: product.lib.php:361
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2845
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:504
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8137
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59