dolibarr 21.0.0-alpha
box_mos.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_mos extends ModeleBoxes
35{
36 public $boxcode = "lastmos";
37 public $boximg = "object_mrp";
38 public $boxlabel = "BoxTitleLatestModifiedMos";
39 public $depends = array("mrp");
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 $this->urltoaddentry = DOL_URL_ROOT.'/mrp/mo_card.php?action=create';
56 $this->msgNoRecords = 'NoRecordedOrders';
57 }
58
65 public function loadBox($max = 5)
66 {
67 global $user, $langs, $conf;
68
69 $this->max = $max;
70
71 include_once DOL_DOCUMENT_ROOT.'/mrp/class/mo.class.php';
72 include_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
73
74 $mostatic = new Mo($this->db);
75 $productstatic = new Product($this->db);
76 $userstatic = new User($this->db);
77
78 $this->info_box_head = array('text' => $langs->trans("BoxTitleLatestModifiedMos", $max));
79
80 if ($user->hasRight('mrp', 'read')) {
81 $sql = "SELECT p.ref as product_ref";
82 $sql .= ", p.rowid as productid";
83 $sql .= ", p.tosell";
84 $sql .= ", p.tobuy";
85 $sql .= ", p.tobatch";
86 $sql .= ", c.rowid";
87 $sql .= ", c.date_creation";
88 $sql .= ", c.tms";
89 $sql .= ", c.ref";
90 $sql .= ", c.status";
91 $sql .= " FROM ".MAIN_DB_PREFIX."product as p";
92 $sql .= ", ".MAIN_DB_PREFIX."mrp_mo 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 $mostatic->id = $objp->rowid;
108 $mostatic->ref = $objp->ref;
109 $mostatic->status = $objp->status;
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' => $mostatic->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('MRP_BOX_LAST_MOS_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' => $mostatic->LibStatut($objp->status, 3),
147 );
148
149 $line++;
150 }
151
152
153 $this->db->free($result);
154 } else {
155 $this->info_box_contents[0][0] = array(
156 'td' => '',
157 'maxlength' => 500,
158 'text' => ($this->db->error().' sql='.$sql),
159 );
160 }
161 } else {
162 $this->info_box_contents[0][0] = array(
163 'td' => 'class="nohover left"',
164 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
165 );
166 }
167 }
168
169
170
179 public function showBox($head = null, $contents = null, $nooutput = 0)
180 {
181 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
182 }
183}
Class for Mo.
Definition mo.class.php:34
Class ModeleBoxes.
Class to manage products or services.
Class to manage Dolibarr users.
Class to manage the box to show last manufacturing orders (MO)
Definition box_mos.php:35
loadBox($max=5)
Load data for box to show them later.
Definition box_mos.php:65
__construct($db, $param)
Constructor.
Definition box_mos.php:47
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition box_mos.php:179
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...