dolibarr 18.0.6
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
43 public $db;
44
45 public $param;
46
47 public $info_box_head = array();
48 public $info_box_contents = array();
49
50
57 public function __construct($db, $param)
58 {
59 global $user;
60
61 $this->db = $db;
62
63 $this->hidden = empty($user->rights->bom->read);
64 }
65
72 public function loadBox($max = 5)
73 {
74 global $user, $langs, $conf;
75
76 $this->max = $max;
77
78 include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
79 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
80
81 $mostatic = new Mo($this->db);
82 $productstatic = new Product($this->db);
83 $userstatic = new User($this->db);
84
85 $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedMos", $max));
86
87 if ($user->rights->mrp->read) {
88 $sql = "SELECT p.ref as product_ref";
89 $sql .= ", p.rowid as productid";
90 $sql .= ", p.tosell";
91 $sql .= ", p.tobuy";
92 $sql .= ", p.tobatch";
93 $sql .= ", c.rowid";
94 $sql .= ", c.date_creation";
95 $sql .= ", c.tms";
96 $sql .= ", c.ref";
97 $sql .= ", c.status";
98 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
99 $sql .= ", ".MAIN_DB_PREFIX."mrp_mo as c";
100 $sql .= " WHERE c.fk_product = p.rowid";
101 $sql .= " AND c.entity = ".$conf->entity;
102 $sql .= " ORDER BY c.tms DESC, c.ref DESC";
103 $sql .= $this->db->plimit($max, 0);
104
105 $result = $this->db->query($sql);
106 if ($result) {
107 $num = $this->db->num_rows($result);
108
109 $line = 0;
110
111 while ($line < $num) {
112 $objp = $this->db->fetch_object($result);
113 $datem = $this->db->jdate($objp->tms);
114 $mostatic->id = $objp->rowid;
115 $mostatic->ref = $objp->ref;
116 $mostatic->status = $objp->status;
117 $productstatic->id = $objp->productid;
118 $productstatic->ref = $objp->product_ref;
119 $productstatic->status = $objp->tosell;
120 $productstatic->status_buy = $objp->tobuy;
121 $productstatic->status_batch = $objp->tobatch;
122
123 $this->info_box_contents[$line][] = array(
124 'td' => 'class="nowraponall"',
125 'text' => $mostatic->getNomUrl(1),
126 'asis' => 1,
127 );
128
129 $this->info_box_contents[$line][] = array(
130 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
131 'text' => $productstatic->getNomUrl(1),
132 'asis' => 1,
133 );
134
135 if (!empty($conf->global->MRP_BOX_LAST_MOS_SHOW_VALIDATE_USER)) {
136 if ($objp->fk_user_valid > 0) {
137 $userstatic->fetch($objp->fk_user_valid);
138 }
139 $this->info_box_contents[$line][] = array(
140 'td' => 'class="right"',
141 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
142 'asis' => 1,
143 );
144 }
145
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
148 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
149 );
150
151 $this->info_box_contents[$line][] = array(
152 'td' => 'class="right" width="18"',
153 'text' => $mostatic->LibStatut($objp->status, 3),
154 );
155
156 $line++;
157 }
158
159 if ($num == 0) {
160 $this->info_box_contents[$line][0] = array(
161 'td' => 'class="center"',
162 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedOrders").'</span>'
163 );
164 }
165
166 $this->db->free($result);
167 } else {
168 $this->info_box_contents[0][0] = array(
169 'td' => '',
170 'maxlength'=>500,
171 'text' => ($this->db->error().' sql='.$sql),
172 );
173 }
174 } else {
175 $this->info_box_contents[0][0] = array(
176 'td' => 'class="nohover left"',
177 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
178 );
179 }
180 }
181
190 public function showBox($head = null, $contents = null, $nooutput = 0)
191 {
192 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
193 }
194}
Class for Mo.
Definition mo.class.php:34
Class ModeleBoxes.
Class to manage products or services.
Class to manage Dolibarr users.
Class to manage the box to show last orders.
Definition box_mos.php:34
loadBox($max=5)
Load data for box to show them later.
Definition box_mos.php:72
__construct($db, $param)
Constructor.
Definition box_mos.php:57
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition box_mos.php:190
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_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...