dolibarr 21.0.0-beta
box_fournisseurs.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2006 Destailleur Laurent <eldy@users.sourceforge.net>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2015-2019 Frederic France <frederic.france@free.fr>
5 * Copyright (C) 2020 Pierre Ardoin <mapiolca@me.com>
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
35{
36 public $boxcode = "lastsuppliers";
37 public $boximg = "object_company";
38 public $boxlabel = "BoxLastSuppliers";
39 public $depends = array("fournisseur");
40
47 public function __construct($db, $param)
48 {
49 global $user;
50
51 $this->db = $db;
52
53 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
54 $this->urltoaddentry = DOL_URL_ROOT.'/societe/card.php?action=create&type=f';
55 $this->msgNoRecords = 'NoRecordedSuppliers';
56 }
57
64 public function loadBox($max = 5)
65 {
66 global $user, $langs, $hookmanager;
67 $langs->load("boxes");
68
69 $this->max = $max;
70
71 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
72 $thirdpartystatic = new Fournisseur($this->db);
73
74 $this->info_box_head = array(
75 'text' => $langs->trans("BoxTitleLastModifiedSuppliers", $max).'<a class="paddingleft" href="'.DOL_URL_ROOT.'/societe/list.php?type=f&sortfield=s.tms&sortorder=DESC"><span class="badge">...</span></a>'
76 );
77
78 if ($user->hasRight('societe', 'lire')) {
79 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
80 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
81 $sql .= ", s.logo, s.email, s.entity";
82 $sql .= ", s.datec, s.tms, s.status";
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 .= " WHERE s.fournisseur = 1";
88 $sql .= " AND s.entity IN (".getEntity('societe').")";
89 if (!$user->hasRight('societe', 'client', 'voir')) {
90 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
91 }
92 // Add where from hooks
93 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
94 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
95 if (empty($reshook)) {
96 if ($user->socid > 0) {
97 $sql .= " AND s.rowid = ".((int) $user->socid);
98 }
99 }
100 $sql .= $hookmanager->resPrint;
101 $sql .= " ORDER BY s.tms DESC ";
102 $sql .= $this->db->plimit($max, 0);
103
104 $result = $this->db->query($sql);
105 if ($result) {
106 $num = $this->db->num_rows($result);
107
108 $line = 0;
109 while ($line < $num) {
110 $objp = $this->db->fetch_object($result);
111 $datec = $this->db->jdate($objp->datec);
112 $datem = $this->db->jdate($objp->tms);
113
114 $thirdpartystatic->id = $objp->socid;
115 $thirdpartystatic->name = $objp->name;
116 $thirdpartystatic->name_alias = $objp->name_alias;
117 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
118 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
119 $thirdpartystatic->fournisseur = $objp->fournisseur;
120 $thirdpartystatic->logo = $objp->logo;
121 $thirdpartystatic->email = $objp->email;
122 $thirdpartystatic->entity = $objp->entity;
123
124 $this->info_box_contents[$line][] = array(
125 'td' => '',
126 'text' => $thirdpartystatic->getNomUrl(1, '', 40),
127 'asis' => 1,
128 );
129
130 $this->info_box_contents[$line][] = array(
131 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
132 'text' => dol_print_date($datem, "day", 'tzuserrel'),
133 );
134
135 $this->info_box_contents[$line][] = array(
136 'td' => 'class="right" width="18"',
137 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
138 );
139
140 $line++;
141 }
142
143 // if ($num == 0) {
144 // $langs->load("suppliers");
145 // $this->info_box_contents[$line][0] = array(
146 // 'td' => 'class="center"',
147 // 'text' => '<span class="opacitymedium">'.$langs->trans("NoRecordedSuppliers").'</span>'
148 // );
149 // }
150
151 $this->db->free($result);
152 } else {
153 $this->info_box_contents[0][0] = array(
154 'td' => '',
155 'maxlength' => 500,
156 'text' => ($this->db->error().' sql='.$sql),
157 );
158 }
159 } else {
160 $this->info_box_contents[0][0] = array(
161 'td' => 'class="nohover left"',
162 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
163 );
164 }
165 }
166
167
168
177 public function showBox($head = null, $contents = null, $nooutput = 0)
178 {
179 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
180 }
181}
Class to manage suppliers.
Class ModeleBoxes.
Class to manage the box to show last suppliers.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.
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_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...