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