dolibarr 21.0.0-alpha
box_ficheinter.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
3 * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
5 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
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
34{
35 public $boxcode = "ficheinter";
36 public $boximg = "object_intervention";
37 public $boxlabel = "BoxFicheInter";
38 public $depends = array("ficheinter"); // conf->contrat->enabled
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !($user->hasRight('ficheinter', 'lire'));
53 }
54
61 public function loadBox($max = 10)
62 {
63 global $user, $langs, $conf;
64
65 $this->max = $max;
66
67 include_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
68 $ficheinterstatic = new Fichinter($this->db);
69 $thirdpartystatic = new Societe($this->db);
70
71 $this->info_box_head = array(
72 'text' => $langs->trans("BoxTitleLastFicheInter", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/fichinter/list.php?sortfield=f.tms&sortorder=DESC"><span class="badge">...</span></a>'
73 );
74
75 if ($user->hasRight('ficheinter', 'lire')) {
76 $sql = "SELECT f.rowid, f.ref, f.fk_soc, f.fk_statut as status";
77 $sql .= ", f.datec";
78 $sql .= ", f.date_valid as datev";
79 $sql .= ", f.tms as datem";
80 $sql .= ", s.rowid as socid, s.nom as name, s.name_alias";
81 $sql .= ", s.code_client, s.code_compta, s.client";
82 $sql .= ", s.logo, s.email, s.entity";
83 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
84 if (!$user->hasRight('societe', 'client', 'voir')) {
85 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
86 }
87 $sql .= ", ".MAIN_DB_PREFIX."fichinter as f";
88 $sql .= " WHERE f.fk_soc = s.rowid ";
89 $sql .= " AND f.entity = ".$conf->entity;
90 if (!$user->hasRight('societe', 'client', 'voir')) {
91 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
92 }
93 if ($user->socid) {
94 $sql .= " AND s.rowid = ".((int) $user->socid);
95 }
96 $sql .= " ORDER BY f.tms DESC";
97 $sql .= $this->db->plimit($max, 0);
98
99 dol_syslog(get_class($this).'::loadBox', LOG_DEBUG);
100 $resql = $this->db->query($sql);
101 if ($resql) {
102 $num = $this->db->num_rows($resql);
103 $now = dol_now();
104
105 $i = 0;
106
107 while ($i < $num) {
108 $objp = $this->db->fetch_object($resql);
109 $datec = $this->db->jdate($objp->datec);
110 $datem = $this->db->jdate($objp->datem);
111
112 $ficheinterstatic->statut = $objp->status;
113 $ficheinterstatic->status = $objp->status;
114 $ficheinterstatic->id = $objp->rowid;
115 $ficheinterstatic->ref = $objp->ref;
116
117 $thirdpartystatic->id = $objp->socid;
118 $thirdpartystatic->name = $objp->name;
119 //$thirdpartystatic->name_alias = $objp->name_alias;
120 $thirdpartystatic->code_client = $objp->code_client;
121 $thirdpartystatic->code_compta = $objp->code_compta;
122 $thirdpartystatic->code_compta_client = $objp->code_compta;
123 $thirdpartystatic->client = $objp->client;
124 $thirdpartystatic->logo = $objp->logo;
125 $thirdpartystatic->email = $objp->email;
126 $thirdpartystatic->entity = $objp->entity;
127
128 $this->info_box_contents[$i][] = array(
129 'td' => 'class="nowraponall"',
130 'text' => $ficheinterstatic->getNomUrl(1),
131 'asis' => 1,
132 );
133
134 $this->info_box_contents[$i][] = array(
135 'td' => 'class="tdoverflowmax150"',
136 'text' => $thirdpartystatic->getNomUrl(1),
137 'asis' => 1,
138 );
139
140 $this->info_box_contents[$i][] = array(
141 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
142 'text' => dol_print_date($datem, 'day', 'tzuserrel'),
143 );
144
145 $this->info_box_contents[$i][] = array(
146 'td' => 'class="nowrap right"',
147 'text' => $ficheinterstatic->getLibStatut(3),
148 'asis' => 1,
149 );
150
151 $i++;
152 }
153
154 if ($num == 0) {
155 $this->info_box_contents[$i][0] = array(
156 'td' => 'class="center"',
157 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedInterventions").'</span>'
158 );
159 }
160
161 $this->db->free($resql);
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
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 to manage interventions.
Class ModeleBoxes.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage the box to show last interventions.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
loadBox($max=10)
Load data for box to show them later.
dol_now($mode='auto')
Return date for now.
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).
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
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...