dolibarr  9.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 Frederic France <frederic.france@free.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
26 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
27 
28 
33 {
34  var $boxcode="lastsuppliers";
35  var $boximg="object_company";
36  var $boxlabel="BoxLastSuppliers";
37  var $depends = array("fournisseur");
38 
42  public $db;
43 
44  var $param;
45 
46  var $info_box_head = array();
47  var $info_box_contents = array();
48 
49 
56  function __construct($db,$param)
57  {
58  global $user;
59 
60  $this->db=$db;
61 
62  $this->hidden=! ($user->rights->societe->lire && empty($user->socid));
63  }
64 
71  function loadBox($max=5)
72  {
73  global $conf, $user, $langs, $db;
74  $langs->load("boxes");
75 
76  $this->max=$max;
77 
78  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
79  $thirdpartystatic=new Societe($db);
80  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
81  $thirdpartytmp=new Fournisseur($db);
82 
83  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedSuppliers",$max));
84 
85  if ($user->rights->societe->lire)
86  {
87  $sql = "SELECT s.nom as name, s.rowid as socid, s.datec, s.tms, s.status,";
88  $sql.= " s.code_fournisseur,";
89  $sql.= " s.logo";
90  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
91  if (!$user->rights->societe->client->voir && !$user->societe_id) $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->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
95  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
96  $sql.= " ORDER BY s.tms DESC ";
97  $sql.= $db->plimit($max, 0);
98 
99  $result = $db->query($sql);
100  if ($result)
101  {
102  $num = $db->num_rows($result);
103 
104  $line = 0;
105  while ($line < $num)
106  {
107  $objp = $db->fetch_object($result);
108  $datec=$db->jdate($objp->datec);
109  $datem=$db->jdate($objp->tms);
110  $thirdpartytmp->id = $objp->socid;
111  $thirdpartytmp->name = $objp->name;
112  $thirdpartytmp->code_client = $objp->code_client;
113  $thirdpartytmp->logo = $objp->logo;
114 
115  $this->info_box_contents[$line][] = array(
116  'td' => '',
117  'text' => $thirdpartytmp->getNomUrl(1, '', 40),
118  'asis' => 1,
119  );
120 
121  $this->info_box_contents[$line][] = array(
122  'td' => 'class="right"',
123  'text' => dol_print_date($datem, "day"),
124  );
125 
126  $this->info_box_contents[$line][] = array(
127  'td' => 'align="right" width="18"',
128  'text' => $thirdpartystatic->LibStatut($objp->status,3),
129  );
130 
131  $line++;
132  }
133 
134  if ($num==0) $this->info_box_contents[$line][0] = array(
135  'td' => 'align="center"',
136  'text'=>$langs->trans("NoRecordedSuppliers"),
137  );
138 
139  $db->free($result);
140  } else {
141  $this->info_box_contents[0][0] = array(
142  'td' => '',
143  'maxlength'=>500,
144  'text' => ($db->error().' sql='.$sql),
145  );
146  }
147  } else {
148  $this->info_box_contents[0][0] = array(
149  'td' => 'align="left" class="nohover opacitymedium"',
150  'text' => $langs->trans("ReadPermissionNotAllowed")
151  );
152  }
153  }
154 
163  function showBox($head = null, $contents = null, $nooutput=0)
164  {
165  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
166  }
167 }
168 
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.
Class to manage suppliers.
Class to manage third parties objects (customers, suppliers, prospects...)
dol_print_date($time, $format='', $tzoutput='tzserver', $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.