dolibarr  18.0.0-alpha
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 // Load Dolibarr environment
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
30 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array('mrp', 'products', 'companies'));
34 
35 $id = GETPOST('id', 'int');
36 $ref = GETPOST('ref', 'alpha');
37 
38 // Security check
39 $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : ''));
40 $fieldtype = (!empty($ref) ? 'ref' : 'rowid');
41 if ($user->socid) {
42  $socid = $user->socid;
43 }
44 
45 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
46 $hookmanager->initHooks(array('productstatsmo'));
47 
48 // Load variable for pagination
49 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
50 $sortfield = GETPOST('sortfield', 'aZ09comma');
51 $sortorder = GETPOST('sortorder', 'aZ09comma');
52 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
53 if (empty($page) || $page == -1) {
54  $page = 0;
55 } // If $page is not defined, or '' or -1
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 if (!$sortorder) {
60  $sortorder = "DESC";
61 }
62 if (!$sortfield) {
63  $sortfield = "c.date_valid";
64 }
65 
66 $result = restrictedArea($user, 'produit|service', $fieldvalue, 'product&product', '', '', $fieldtype);
67 
68 
69 /*
70  * View
71  */
72 
73 $staticmo = new Mo($db);
74 $staticmoligne = new MoLine($db);
75 
76 $form = new Form($db);
77 
78 if ($id > 0 || !empty($ref)) {
79  $product = new Product($db);
80  $result = $product->fetch($id, $ref);
81 
82  $object = $product;
83 
84  $parameters = array('id'=>$id);
85  $reshook = $hookmanager->executeHooks('doActions', $parameters, $product, $action); // Note that $action and $object may have been modified by some hooks
86  if ($reshook < 0) {
87  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
88  }
89 
90  llxHeader("", "", $langs->trans("CardProduct".$product->type));
91 
92  if ($result > 0) {
93  $head = product_prepare_head($product);
94  $titre = $langs->trans("CardProduct".$product->type);
95  $picto = ($product->type == Product::TYPE_SERVICE ? 'service' : 'product');
96  print dol_get_fiche_head($head, 'referers', $titre, -1, $picto);
97 
98  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $product, $action); // Note that $action and $object may have been modified by hook
99  print $hookmanager->resPrint;
100  if ($reshook < 0) {
101  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
102  }
103 
104  $linkback = '<a href="'.DOL_URL_ROOT.'/product/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
105 
106  $shownav = 1;
107  if ($user->socid && !in_array('product', explode(',', $conf->global->MAIN_MODULES_FOR_EXTERNAL))) {
108  $shownav = 0;
109  }
110 
111  dol_banner_tab($object, 'ref', $linkback, $shownav, 'ref');
112 
113  print '<div class="fichecenter">';
114 
115  print '<div class="underbanner clearboth"></div>';
116  print '<table class="border tableforfield" width="100%">';
117 
118  $nboflines = show_stats_for_company($product, $socid);
119 
120  print "</table>";
121 
122  print '</div>';
123  print '<div style="clear:both"></div>';
124 
125  print dol_get_fiche_end();
126 
127 
128  $now = dol_now();
129 
130  $sql = "SELECT";
131  $sql .= " sum(".$db->ifsql("cd.role='toconsume'", "cd.qty", 0).') as nb_toconsume,';
132  $sql .= " sum(".$db->ifsql("cd.role='consumed'", "cd.qty", 0).') as nb_consumed,';
133  $sql .= " sum(".$db->ifsql("cd.role='toproduce'", "cd.qty", 0).') as nb_toproduce,';
134  $sql .= " sum(".$db->ifsql("cd.role='produced'", "cd.qty", 0).') as nb_produced,';
135  $sql .= " c.rowid as rowid, c.ref, c.date_valid, c.status";
136  //$sql .= " s.nom as name, s.rowid as socid, s.code_client";
137  $sql .= " FROM ".MAIN_DB_PREFIX."mrp_mo as c";
138  $sql .= ", ".MAIN_DB_PREFIX."mrp_production as cd";
139  $sql .= " WHERE c.rowid = cd.fk_mo";
140  $sql .= " AND c.entity IN (".getEntity('mo').")";
141  $sql .= " AND cd.fk_product = ".((int) $product->id);
142  if ($socid) {
143  $sql .= " AND s.rowid = ".((int) $socid);
144  }
145  $sql .= " GROUP BY c.rowid, c.ref, c.date_valid, c.status";
146  //$sql .= ", s.nom, s.rowid, s.code_client";
147  $sql .= $db->order($sortfield, $sortorder);
148 
149  //Calcul total qty and amount for global if full scan list
150  $total_ht = 0;
151  $total_qty = 0;
152 
153  // Count total nb of records
154  $totalofrecords = '';
155  if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
156  $result = $db->query($sql);
157  $totalofrecords = $db->num_rows($result);
158  }
159 
160  $sql .= $db->plimit($limit + 1, $offset);
161 
162  $result = $db->query($sql);
163  if ($result) {
164  $num = $db->num_rows($result);
165 
166  $option = '&id='.$product->id;
167 
168  if ($limit > 0 && $limit != $conf->liste_limit) {
169  $option .= '&limit='.urlencode($limit);
170  }
171  if (!empty($search_month)) {
172  $option .= '&search_month='.urlencode($search_month);
173  }
174  if (!empty($search_year)) {
175  $option .= '&search_year='.urlencode($search_year);
176  }
177 
178  print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$product->id.'" name="search_form">'."\n";
179  print '<input type="hidden" name="token" value="'.newToken().'">';
180  if (!empty($sortfield)) {
181  print '<input type="hidden" name="sortfield" value="'.$sortfield.'"/>';
182  }
183  if (!empty($sortorder)) {
184  print '<input type="hidden" name="sortorder" value="'.$sortorder.'"/>';
185  }
186 
187  print_barre_liste($langs->trans("MOs"), $page, $_SERVER["PHP_SELF"], $option, $sortfield, $sortorder, '', $num, $totalofrecords, '', 0, '', '', $limit, 0, 0, 1);
188 
189  if (!empty($page)) {
190  $option .= '&page='.urlencode($page);
191  }
192 
193  $i = 0;
194  print '<div class="div-table-responsive">';
195  print '<table class="tagtable liste listwithfilterbefore" width="100%">';
196 
197  print '<tr class="liste_titre">';
198  print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "c.rowid", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
199  //print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "&amp;id=".$product->id, '', $sortfield, $sortorder);
200  print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "c.date_valid", "", "&amp;id=".$product->id, 'align="center"', $sortfield, $sortorder);
201  //print_liste_field_titre("AmountHT"),$_SERVER["PHP_SELF"],"c.amount","","&amp;id=".$product->id,'align="right"',$sortfield,$sortorder);
202  print_liste_field_titre("ToConsume", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
203  print_liste_field_titre("QtyAlreadyConsumed", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
204  print_liste_field_titre("QtyToProduce", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
205  print_liste_field_titre("QtyAlreadyProduced", $_SERVER["PHP_SELF"], "", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'center ');
206  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "b.status", "", "&amp;id=".$product->id, '', $sortfield, $sortorder, 'right ');
207  print "</tr>\n";
208 
209  $motmp = new Mo($db);
210 
211  if ($num > 0) {
212  while ($i < min($num, $limit)) {
213  $objp = $db->fetch_object($result);
214 
215  $motmp->id = $objp->rowid;
216  $motmp->ref = $objp->ref;
217  $motmp->status = $objp->status;
218 
219  print '<tr class="oddeven">';
220  print '<td>';
221  print $motmp->getNomUrl(1, 'production');
222  print "</td>\n";
223  print "<td align=\"center\">";
224  print dol_print_date($db->jdate($objp->date_valid), 'dayhour')."</td>";
225  //print "<td align=\"right\">".price($objp->total_ht)."</td>\n";
226  //print '<td align="right">';
227  print '<td class="center">'.($objp->nb_toconsume > 0 ? $objp->nb_toconsume : '').'</td>';
228  print '<td class="center">'.($objp->nb_consumed > 0 ? $objp->nb_consumed : '').'</td>';
229  print '<td class="center">'.($objp->nb_toproduce > 0 ? $objp->nb_toproduce : '').'</td>';
230  print '<td class="center">'.($objp->nb_produced > 0 ? $objp->nb_produced : '').'</td>';
231  //$mostatic->LibStatut($objp->statut,5).'</td>';
232  print '<td class="right">'.$motmp->getLibStatut(2).'</td>';
233  print "</tr>\n";
234  $i++;
235  }
236  }
237 
238  print '</table>';
239  print '</div>';
240  print '</form>';
241  } else {
242  dol_print_error($db);
243  }
244  $db->free($result);
245  }
246 } else {
247  dol_print_error();
248 }
249 
250 // End of page
251 llxFooter();
252 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:70
$sql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:745
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:527
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:4980
MoLine
Class MoLine.
Definition: mo.class.php:1598
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:143
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:2083
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:2554
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
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:5400
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:1859
restrictedArea
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.
Definition: security.lib.php:337
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2055
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:428
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:5165
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:419
dol_now
dol_now($mode='auto')
Return date for now.
Definition: functions.lib.php:2935
Product\TYPE_SERVICE
const TYPE_SERVICE
Service.
Definition: product.class.php:546
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8471