dolibarr  19.0.0-dev
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 
27 include_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 
43  public $db;
44 
45  public $param;
46 
47  public $info_box_head = array();
48  public $info_box_contents = array();
49 
50 
57  public function __construct($db, $param)
58  {
59  global $user;
60 
61  $this->db = $db;
62 
63  $this->hidden = !($user->hasRight('societe', 'read') && empty($user->socid));
64  }
65 
72  public function loadBox($max = 5)
73  {
74  global $conf, $user, $langs, $hookmanager;
75  $langs->load("boxes");
76 
77  $this->max = $max;
78 
79  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
80  $thirdpartystatic = new Fournisseur($this->db);
81 
82  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedSuppliers", $max));
83 
84  if ($user->hasRight('societe', 'lire')) {
85  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
86  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
87  $sql .= ", s.logo, s.email, s.entity";
88  $sql .= ", s.datec, s.tms, s.status";
89  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
90  if (empty($user->rights->societe->client->voir) && !$user->socid) {
91  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
92  }
93  $sql .= " WHERE s.fournisseur = 1";
94  $sql .= " AND s.entity IN (".getEntity('societe').")";
95  if (empty($user->rights->societe->client->voir) && !$user->socid) {
96  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
97  }
98  // Add where from hooks
99  $parameters = array('socid' => $user->socid, 'boxcode' => $this->boxcode);
100  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $thirdpartystatic); // Note that $action and $object may have been modified by hook
101  if (empty($reshook)) {
102  if ($user->socid > 0) {
103  $sql .= " AND s.rowid = ".((int) $user->socid);
104  }
105  }
106  $sql .= $hookmanager->resPrint;
107  $sql .= " ORDER BY s.tms DESC ";
108  $sql .= $this->db->plimit($max, 0);
109 
110  $result = $this->db->query($sql);
111  if ($result) {
112  $num = $this->db->num_rows($result);
113 
114  $line = 0;
115  while ($line < $num) {
116  $objp = $this->db->fetch_object($result);
117  $datec = $this->db->jdate($objp->datec);
118  $datem = $this->db->jdate($objp->tms);
119 
120  $thirdpartystatic->id = $objp->socid;
121  $thirdpartystatic->name = $objp->name;
122  $thirdpartystatic->name_alias = $objp->name_alias;
123  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
124  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
125  $thirdpartystatic->fournisseur = $objp->fournisseur;
126  $thirdpartystatic->logo = $objp->logo;
127  $thirdpartystatic->email = $objp->email;
128  $thirdpartystatic->entity = $objp->entity;
129 
130  $this->info_box_contents[$line][] = array(
131  'td' => '',
132  'text' => $thirdpartystatic->getNomUrl(1, '', 40),
133  'asis' => 1,
134  );
135 
136  $this->info_box_contents[$line][] = array(
137  'td' => 'class="center nowraponall" title="'.dol_escape_htmltag($langs->trans("DateModification").': '.dol_print_date($datem, 'dayhour', 'tzuserrel')).'"',
138  'text' => dol_print_date($datem, "day", 'tzuserrel'),
139  );
140 
141  $this->info_box_contents[$line][] = array(
142  'td' => 'class="right" width="18"',
143  'text' => $thirdpartystatic->LibStatut($objp->status, 3),
144  );
145 
146  $line++;
147  }
148 
149  if ($num == 0) {
150  $langs->load("suppliers");
151  $this->info_box_contents[$line][0] = array(
152  'td' => 'class="center opacitymedium"',
153  'text'=>$langs->trans("NoRecordedSuppliers"),
154  );
155  }
156 
157  $this->db->free($result);
158  } else {
159  $this->info_box_contents[0][0] = array(
160  'td' => '',
161  'maxlength'=>500,
162  'text' => ($this->db->error().' sql='.$sql),
163  );
164  }
165  } else {
166  $this->info_box_contents[0][0] = array(
167  'td' => 'class="nohover opacitymedium left"',
168  'text' => $langs->trans("ReadPermissionNotAllowed")
169  );
170  }
171  }
172 
181  public function showBox($head = null, $contents = null, $nooutput = 0)
182  {
183  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
184  }
185 }
dol_escape_htmltag
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...
Definition: functions.lib.php:1600
box_fournisseurs\loadBox
loadBox($max=5)
Load data into info_box_contents array to show array later.
Definition: box_fournisseurs.php:72
dol_print_date
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Definition: functions.lib.php:2675
box_fournisseurs
Class to manage the box to show last suppliers.
Definition: box_fournisseurs.php:33
Fournisseur
Class to manage suppliers.
Definition: fournisseur.class.php:34
box_fournisseurs\__construct
__construct($db, $param)
Constructor.
Definition: box_fournisseurs.php:57
box_fournisseurs\showBox
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
Definition: box_fournisseurs.php:181
$sql
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
Definition: index.php:746
ModeleBoxes
Class ModeleBoxes.
Definition: modules_boxes.php:34