dolibarr 20.0.0
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
27include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28
29
33class box_boms extends ModeleBoxes
34{
35 public $boxcode = "lastboms";
36 public $boximg = "object_bom";
37 public $boxlabel = "BoxTitleLatestModifiedBoms";
38 public $depends = array("bom");
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.'/bom/class/bom.class.php';
68 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
69
70 $bomstatic = new BOM($this->db);
71 $productstatic = new Product($this->db);
72 $userstatic = new User($this->db);
73
74 $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedBoms", $max));
75
76 if ($user->hasRight('bom', '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 .= ", c.fk_user_valid";
88 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
89 $sql .= ", ".MAIN_DB_PREFIX."bom_bom as c";
90 $sql .= " WHERE c.fk_product = p.rowid";
91 $sql .= " AND c.entity = ".$conf->entity;
92 $sql .= " ORDER BY c.tms DESC, c.ref DESC";
93 $sql .= $this->db->plimit($max, 0);
94
95 $result = $this->db->query($sql);
96 if ($result) {
97 $num = $this->db->num_rows($result);
98
99 $line = 0;
100
101 while ($line < $num) {
102 $objp = $this->db->fetch_object($result);
103 $datem = $this->db->jdate($objp->tms);
104
105 $bomstatic->id = $objp->rowid;
106 $bomstatic->ref = $objp->ref;
107 $bomstatic->status = $objp->status;
108
109 $productstatic->id = $objp->productid;
110 $productstatic->ref = $objp->product_ref;
111 $productstatic->status = $objp->tosell;
112 $productstatic->status_buy = $objp->tobuy;
113 $productstatic->status_batch = $objp->tobatch;
114
115 $this->info_box_contents[$line][] = array(
116 'td' => 'class="nowraponall"',
117 'text' => $bomstatic->getNomUrl(1),
118 'asis' => 1,
119 );
120
121 $this->info_box_contents[$line][] = array(
122 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
123 'text' => $productstatic->getNomUrl(1),
124 'asis' => 1,
125 );
126
127 if (getDolGlobalString('BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER')) {
128 if ($objp->fk_user_valid > 0) {
129 $userstatic->fetch($objp->fk_user_valid);
130 }
131 $this->info_box_contents[$line][] = array(
132 'td' => 'class="right"',
133 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
134 'asis' => 1,
135 );
136 }
137
138 $this->info_box_contents[$line][] = array(
139 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
140 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
141 );
142
143 $this->info_box_contents[$line][] = array(
144 'td' => 'class="right" width="18"',
145 'text' => $bomstatic->LibStatut($objp->status, 3),
146 );
147
148 $line++;
149 }
150
151 if ($num == 0) {
152 $this->info_box_contents[$line][0] = array(
153 'td' => 'class="center"',
154 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedOrders").'</span>'
155 );
156 }
157
158 $this->db->free($result);
159 } else {
160 $this->info_box_contents[0][0] = array(
161 'td' => '',
162 'maxlength'=>500,
163 'text' => ($this->db->error().' sql='.$sql),
164 );
165 }
166 } else {
167 $this->info_box_contents[0][0] = array(
168 'td' => 'class="nohover left"',
169 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
170 );
171 }
172 }
173
182 public function showBox($head = null, $contents = null, $nooutput = 0)
183 {
184 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
185 }
186}
Class for BOM.
Definition bom.class.php:45
Class ModeleBoxes.
Class to manage products or services.
Class to manage Dolibarr users.
Class to manage the box to show last modified BOMs.
Definition box_boms.php:34
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition box_boms.php:182
loadBox($max=5)
Load data for box to show them later.
Definition box_boms.php:61
__construct($db, $param)
Constructor.
Definition box_boms.php:46
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...