dolibarr 20.0.0
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 *
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 = "lastsuppliers";
36 public $boximg = "object_company";
37 public $boxlabel = "BoxLastSuppliers";
38 public $depends = array("fournisseur");
39
46 public function __construct($db, $param)
47 {
48 global $user;
49
50 $this->db = $db;
51
52 $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
53 }
54
61 public function loadBox($max = 5)
62 {
63 global $user, $langs, $hookmanager;
64 $langs->load("boxes");
65
66 $this->max = $max;
67
68 include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
69 $thirdpartystatic = new Fournisseur($this->db);
70
71 $this->info_box_head = array(
72 '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>'
73 );
74
75 if ($user->hasRight('societe', 'lire')) {
76 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
77 $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
78 $sql .= ", s.logo, s.email, s.entity";
79 $sql .= ", s.datec, s.tms, s.status";
80 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
81 if (!$user->hasRight('societe', 'client', 'voir')) {
82 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
83 }
84 $sql .= " WHERE s.fournisseur = 1";
85 $sql .= " AND s.entity IN (".getEntity('societe').")";
86 if (!$user->hasRight('societe', 'client', 'voir')) {
87 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
88 }
89 // Add where from hooks
90 $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
91 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
92 if (empty($reshook)) {
93 if ($user->socid > 0) {
94 $sql .= " AND s.rowid = ".((int) $user->socid);
95 }
96 }
97 $sql .= $hookmanager->resPrint;
98 $sql .= " ORDER BY s.tms DESC ";
99 $sql .= $this->db->plimit($max, 0);
100
101 $result = $this->db->query($sql);
102 if ($result) {
103 $num = $this->db->num_rows($result);
104
105 $line = 0;
106 while ($line < $num) {
107 $objp = $this->db->fetch_object($result);
108 $datec = $this->db->jdate($objp->datec);
109 $datem = $this->db->jdate($objp->tms);
110
111 $thirdpartystatic->id = $objp->socid;
112 $thirdpartystatic->name = $objp->name;
113 $thirdpartystatic->name_alias = $objp->name_alias;
114 $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
115 $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
116 $thirdpartystatic->fournisseur = $objp->fournisseur;
117 $thirdpartystatic->logo = $objp->logo;
118 $thirdpartystatic->email = $objp->email;
119 $thirdpartystatic->entity = $objp->entity;
120
121 $this->info_box_contents[$line][] = array(
122 'td' => '',
123 'text' => $thirdpartystatic->getNomUrl(1, '', 40),
124 'asis' => 1,
125 );
126
127 $this->info_box_contents[$line][] = array(
128 'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
129 'text' => dol_print_date($datem, "day", 'tzuserrel'),
130 );
131
132 $this->info_box_contents[$line][] = array(
133 'td' => 'class="right" width="18"',
134 'text' => $thirdpartystatic->LibStatut($objp->status, 3),
135 );
136
137 $line++;
138 }
139
140 if ($num == 0) {
141 $langs->load("suppliers");
142 $this->info_box_contents[$line][0] = array(
143 'td' => 'class="center"',
144 'text'=> '<span class="opacitymedium">'.$langs->trans("NoRecordedSuppliers").'</span>'
145 );
146 }
147
148 $this->db->free($result);
149 } else {
150 $this->info_box_contents[0][0] = array(
151 'td' => '',
152 'maxlength'=>500,
153 'text' => ($this->db->error().' sql='.$sql),
154 );
155 }
156 } else {
157 $this->info_box_contents[0][0] = array(
158 'td' => 'class="nohover left"',
159 'text' => '<span class="opacitymedium">'.$langs->trans("ReadPermissionNotAllowed").'</span>'
160 );
161 }
162 }
163
172 public function showBox($head = null, $contents = null, $nooutput = 0)
173 {
174 return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
175 }
176}
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...