dolibarr 21.0.0-beta
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-2024 Frédéric 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 $this->urltoaddentry = DOL_URL_ROOT.'/bom/bom_card.php?action=create';
55 $this->msgNoRecords = 'NoRecordedOrders';
56 }
57
64 public function loadBox($max = 5)
65 {
66 global $user, $langs, $conf;
67
68 $this->max = $max;
69
70 include_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
71 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
72
73 $bomstatic = new BOM($this->db);
74 $productstatic = new Product($this->db);
75 $userstatic = new User($this->db);
76
77 $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedBoms", $max));
78
79 if ($user->hasRight('bom', 'read')) {
80 $sql = "SELECT p.ref as product_ref";
81 $sql .= ", p.rowid as productid";
82 $sql .= ", p.tosell";
83 $sql .= ", p.tobuy";
84 $sql .= ", p.tobatch";
85 $sql .= ", c.rowid";
86 $sql .= ", c.date_creation";
87 $sql .= ", c.tms";
88 $sql .= ", c.ref";
89 $sql .= ", c.status";
90 $sql .= ", c.fk_user_valid";
91 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
92 $sql .= ", ".MAIN_DB_PREFIX."bom_bom as c";
93 $sql .= " WHERE c.fk_product = p.rowid";
94 $sql .= " AND c.entity = ".$conf->entity;
95 $sql .= " ORDER BY c.tms DESC, c.ref DESC";
96 $sql .= $this->db->plimit($max, 0);
97
98 $result = $this->db->query($sql);
99 if ($result) {
100 $num = $this->db->num_rows($result);
101
102 $line = 0;
103
104 while ($line < $num) {
105 $objp = $this->db->fetch_object($result);
106 $datem = $this->db->jdate($objp->tms);
107
108 $bomstatic->id = $objp->rowid;
109 $bomstatic->ref = $objp->ref;
110 $bomstatic->status = $objp->status;
111
112 $productstatic->id = $objp->productid;
113 $productstatic->ref = $objp->product_ref;
114 $productstatic->status = $objp->tosell;
115 $productstatic->status_buy = $objp->tobuy;
116 $productstatic->status_batch = $objp->tobatch;
117
118 $this->info_box_contents[$line][] = array(
119 'td' => 'class="nowraponall"',
120 'text' => $bomstatic->getNomUrl(1),
121 'asis' => 1,
122 );
123
124 $this->info_box_contents[$line][] = array(
125 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"',
126 'text' => $productstatic->getNomUrl(1),
127 'asis' => 1,
128 );
129
130 if (getDolGlobalString('BOM_BOX_LAST_BOMS_SHOW_VALIDATE_USER')) {
131 if ($objp->fk_user_valid > 0) {
132 $userstatic->fetch($objp->fk_user_valid);
133 }
134 $this->info_box_contents[$line][] = array(
135 'td' => 'class="right"',
136 'text' => (($objp->fk_user_valid > 0) ? $userstatic->getNomUrl(1) : ''),
137 'asis' => 1,
138 );
139 }
140
141 $this->info_box_contents[$line][] = array(
142 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
143 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
144 );
145
146 $this->info_box_contents[$line][] = array(
147 'td' => 'class="right" width="18"',
148 'text' => $bomstatic->LibStatut($objp->status, 3),
149 );
150
151 $line++;
152 }
153
154 // if ($num == 0) {
155 // $this->info_box_contents[$line][0] = array(
156 // 'td' => 'class="center"',
157 // 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedOrders").'</span>'
158 // );
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 left"',
172 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
173 );
174 }
175 }
176
177
178
187 public function showBox($head = null, $contents = null, $nooutput = 0)
188 {
189 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
190 }
191}
Class for BOM.
Definition bom.class.php:42
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:187
loadBox($max=5)
Load data for box to show them later.
Definition box_boms.php:64
__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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79