dolibarr  17.0.4
box_boms.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 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
33 class box_boms extends ModeleBoxes
34 {
35  public $boxcode = "lastboms";
36  public $boximg = "object_bom";
37  public $boxlabel = "BoxTitleLatestModifiedBoms";
38  public $depends = array("bom");
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.'/bom/class/bom.class.php';
79  include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
80 
81  $bomstatic = new Bom($this->db);
82  $productstatic = new Product($this->db);
83  $userstatic = new User($this->db);
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedBoms", $max));
86 
87  if ($user->rights->bom->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 .= ", c.fk_user_valid";
99  $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
100  $sql .= ", ".MAIN_DB_PREFIX."bom_bom as c";
101  $sql .= " WHERE c.fk_product = p.rowid";
102  $sql .= " AND c.entity = ".$conf->entity;
103  $sql .= " ORDER BY c.tms DESC, c.ref DESC";
104  $sql .= $this->db->plimit($max, 0);
105 
106  $result = $this->db->query($sql);
107  if ($result) {
108  $num = $this->db->num_rows($result);
109 
110  $line = 0;
111 
112  while ($line < $num) {
113  $objp = $this->db->fetch_object($result);
114  $datem = $this->db->jdate($objp->tms);
115 
116  $bomstatic->id = $objp->rowid;
117  $bomstatic->ref = $objp->ref;
118  $bomstatic->status = $objp->status;
119 
120  $productstatic->id = $objp->productid;
121  $productstatic->ref = $objp->product_ref;
122  $productstatic->status = $objp->tosell;
123  $productstatic->status_buy = $objp->tobuy;
124  $productstatic->status_batch = $objp->tobatch;
125 
126  $this->info_box_contents[$line][] = array(
127  'td' => 'class="nowraponall"',
128  'text' => $bomstatic->getNomUrl(1),
129  'asis' => 1,
130  );
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
134  'text' => $productstatic->getNomUrl(1),
135  'asis' => 1,
136  );
137 
138  if (!empty($conf->global->BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER)) {
139  if ($objp->fk_user_valid > 0) {
140  $userstatic->fetch($objp->fk_user_valid);
141  }
142  $this->info_box_contents[$line][] = array(
143  'td' => 'class="right"',
144  'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
145  'asis' => 1,
146  );
147  }
148 
149  $this->info_box_contents[$line][] = array(
150  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
151  'text' => dol_print_date($datem, 'day', 'tzuserrel'),
152  );
153 
154  $this->info_box_contents[$line][] = array(
155  'td' => 'class="right" width="18"',
156  'text' => $bomstatic->LibStatut($objp->status, 3),
157  );
158 
159  $line++;
160  }
161 
162  if ($num == 0) {
163  $this->info_box_contents[$line][0] = array(
164  'td' => 'class="center opacitymedium"',
165  'text'=>$langs->trans("NoRecordedOrders")
166  );
167  }
168 
169  $this->db->free($result);
170  } else {
171  $this->info_box_contents[0][0] = array(
172  'td' => '',
173  'maxlength'=>500,
174  'text' => ($this->db->error().' sql='.$sql),
175  );
176  }
177  } else {
178  $this->info_box_contents[0][0] = array(
179  'td' => 'class="nohover opacitymedium left"',
180  'text' => $langs->trans("ReadPermissionNotAllowed")
181  );
182  }
183  }
184 
193  public function showBox($head = null, $contents = null, $nooutput = 0)
194  {
195  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
196  }
197 }
Class ModeleBoxes.
Class to manage products or services.
Class to manage Dolibarr users.
Definition: user.class.php:47
Class to manage the box to show last orders.
Definition: box_boms.php:34
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_boms.php:193
loadBox($max=5)
Load data for box to show them later.
Definition: box_boms.php:72
__construct($db, $param)
Constructor.
Definition: box_boms.php:57
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
$conf db
API class for accounts.
Definition: inc.php:41