dolibarr  13.0.2
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 = !($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  {
89  $sql = "SELECT p.ref as product_ref, p.tobuy, p.tosell";
90  $sql .= ", c.rowid";
91  $sql .= ", c.date_creation";
92  $sql .= ", c.tms";
93  $sql .= ", c.ref";
94  $sql .= ", c.status";
95  $sql .= ", c.fk_user_valid";
96  $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
97  $sql .= ", ".MAIN_DB_PREFIX."bom_bom as c";
98  $sql .= " WHERE c.fk_product = p.rowid";
99  $sql .= " AND c.entity = ".$conf->entity;
100  $sql .= " ORDER BY c.tms DESC, c.ref DESC";
101  $sql .= " ".$this->db->plimit($max, 0);
102 
103  $result = $this->db->query($sql);
104  if ($result) {
105  $num = $this->db->num_rows($result);
106 
107  $line = 0;
108 
109  while ($line < $num) {
110  $objp = $this->db->fetch_object($result);
111  $datem = $this->db->jdate($objp->tms);
112 
113  $bomstatic->id = $objp->rowid;
114  $bomstatic->ref = $objp->ref;
115  $bomstatic->id = $objp->socid;
116  $bomstatic->status = $objp->status;
117 
118  $productstatic->ref = $objp->product_ref;
119  $productstatic->status = $objp->tobuy;
120  $productstatic->status_buy = $objp->tosell;
121 
122  $this->info_box_contents[$line][] = array(
123  'td' => 'class="nowraponall"',
124  'text' => $bomstatic->getNomUrl(1),
125  'asis' => 1,
126  );
127 
128  $this->info_box_contents[$line][] = array(
129  'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
130  'text' => $productstatic->getNomUrl(1),
131  'asis' => 1,
132  );
133 
134  if (!empty($conf->global->BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER)) {
135  if ($objp->fk_user_valid > 0) $userstatic->fetch($objp->fk_user_valid);
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="right"',
138  'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
139  'asis' => 1,
140  );
141  }
142 
143  $this->info_box_contents[$line][] = array(
144  'td' => 'class="right"',
145  'text' => dol_print_date($datem, 'day'),
146  );
147 
148  $this->info_box_contents[$line][] = array(
149  'td' => 'class="right" width="18"',
150  'text' => $bomstatic->LibStatut($objp->status, 3),
151  );
152 
153  $line++;
154  }
155 
156  if ($num == 0) $this->info_box_contents[$line][0] = array(
157  'td' => 'class="center opacitymedium"',
158  'text'=>$langs->trans("NoRecordedOrders")
159  );
160 
161  $this->db->free($result);
162  } else {
163  $this->info_box_contents[0][0] = array(
164  'td' => '',
165  'maxlength'=>500,
166  'text' => ($this->db->error().' sql='.$sql),
167  );
168  }
169  } else {
170  $this->info_box_contents[0][0] = array(
171  'td' => 'class="nohover opacitymedium left"',
172  'text' => $langs->trans("ReadPermissionNotAllowed")
173  );
174  }
175  }
176 
185  public function showBox($head = null, $contents = null, $nooutput = 0)
186  {
187  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
188  }
189 }
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_boms.php:185
Class to manage products or services.
__construct($db, $param)
Constructor.
Definition: box_boms.php:57
Class to manage Dolibarr users.
Definition: user.class.php:44
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage the box to show last orders.
Definition: box_boms.php:33
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
loadBox($max=5)
Load data for box to show them later.
Definition: box_boms.php:72