dolibarr 21.0.0-alpha
box_mos.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 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
33class box_mos extends ModeleBoxes
34{
35 public $boxcode = "lastmos";
36 public $boximg = "object_mrp";
37 public $boxlabel = "BoxTitleLatestModifiedMos";
38 public $depends = array("mrp");
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !$user->hasRight('bom', 'read');
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $user, $langs, $conf;
64
65 $this->max = $max;
66
67 include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
68 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
69
70 $mostatic = new Mo($this->db);
71 $productstatic = new Product($this->db);
72 $userstatic = new User($this->db);
73
74 $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedMos", $max));
75
76 if ($user->hasRight('mrp', 'read')) {
77 $sql = "SELECT p.ref as product_ref";
78 $sql .= ", p.rowid as productid";
79 $sql .= ", p.tosell";
80 $sql .= ", p.tobuy";
81 $sql .= ", p.tobatch";
82 $sql .= ", c.rowid";
83 $sql .= ", c.date_creation";
84 $sql .= ", c.tms";
85 $sql .= ", c.ref";
86 $sql .= ", c.status";
87 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
88 $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as c";
89 $sql .= " WHERE c.fk_product = p.rowid";
90 $sql .= " AND c.entity = ".$conf->entity;
91 $sql .= " ORDER BY c.tms DESC, c.ref DESC";
92 $sql .= $this->db->plimit($max, 0);
93
94 $result = $this->db->query($sql);
95 if ($result) {
96 $num = $this->db->num_rows($result);
97
98 $line = 0;
99
100 while ($line < $num) {
101 $objp = $this->db->fetch_object($result);
102 $datem = $this->db->jdate($objp->tms);
103 $mostatic->id = $objp->rowid;
104 $mostatic->ref = $objp->ref;
105 $mostatic->status = $objp->status;
106 $productstatic->id = $objp->productid;
107 $productstatic->ref = $objp->product_ref;
108 $productstatic->status = $objp->tosell;
109 $productstatic->status_buy = $objp->tobuy;
110 $productstatic->status_batch = $objp->tobatch;
111
112 $this->info_box_contents[$line][] = array(
113 'td' => 'class="nowraponall"',
114 'text' => $mostatic->getNomUrl(1),
115 'asis' => 1,
116 );
117
118 $this->info_box_contents[$line][] = array(
119 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
120 'text' => $productstatic->getNomUrl(1),
121 'asis' => 1,
122 );
123
124 if (getDolGlobalString('MRP_BOX_LAST_MOS_SHOW_VALIDATE_USER')) {
125 if ($objp->fk_user_valid > 0) {
126 $userstatic->fetch($objp->fk_user_valid);
127 }
128 $this->info_box_contents[$line][] = array(
129 'td' => 'class="right"',
130 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
131 'asis' => 1,
132 );
133 }
134
135 $this->info_box_contents[$line][] = array(
136 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
137 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
138 );
139
140 $this->info_box_contents[$line][] = array(
141 'td' => 'class="right" width="18"',
142 'text' => $mostatic->LibStatut($objp->status, 3),
143 );
144
145 $line++;
146 }
147
148 if ($num == 0) {
149 $this->info_box_contents[$line][0] = array(
150 'td' => 'class="center"',
151 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedOrders").'</span>'
152 );
153 }
154
155 $this->db->free($result);
156 } else {
157 $this->info_box_contents[0][0] = array(
158 'td' => '',
159 'maxlength'=>500,
160 'text' => ($this->db->error().' sql='.$sql),
161 );
162 }
163 } else {
164 $this->info_box_contents[0][0] = array(
165 'td' => 'class="nohover left"',
166 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
167 );
168 }
169 }
170
179 public function showBox($head = null, $contents = null, $nooutput = 0)
180 {
181 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
182 }
183}
Class for Mo.
Definition mo.class.php:36
Class ModeleBoxes.
Class to manage products or services.
Class to manage Dolibarr users.
Class to manage the box to show last manufacturing orders (MO)
Definition box_mos.php:34
loadBox($max=5)
Load data for box to show them later.
Definition box_mos.php:61
__construct($db, $param)
Constructor.
Definition box_mos.php:46
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition box_mos.php:179
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalString($key, $default='')
Return 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...