dolibarr  13.0.2
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->rights->societe->lire && empty($user->socid));
64  }
65 
72  public function loadBox($max = 5)
73  {
74  global $conf, $user, $langs;
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->rights->societe->lire)
85  {
86  $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias";
87  $sql .= ", s.code_fournisseur, s.code_compta_fournisseur, s.fournisseur";
88  $sql .= ", s.logo, s.email, s.entity";
89  $sql .= ", s.datec, s.tms, s.status";
90  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
91  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
92  $sql .= " WHERE s.fournisseur = 1";
93  $sql .= " AND s.entity IN (".getEntity('societe').")";
94  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
95  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
96  $sql .= " ORDER BY s.tms DESC ";
97  $sql .= $this->db->plimit($max, 0);
98 
99  $result = $this->db->query($sql);
100  if ($result)
101  {
102  $num = $this->db->num_rows($result);
103 
104  $line = 0;
105  while ($line < $num)
106  {
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="right"',
129  'text' => dol_print_date($datem, "day"),
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 opacitymedium"',
144  'text'=>$langs->trans("NoRecordedSuppliers"),
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 opacitymedium left"',
159  'text' => $langs->trans("ReadPermissionNotAllowed")
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 }
loadBox($max=5)
Load data into info_box_contents array to show array later.
Class to manage the box to show last suppliers.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage suppliers.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
__construct($db, $param)
Constructor.