dolibarr  7.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@capnetworks.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 
39  var $db;
40  var $param;
41 
42  var $info_box_head = array();
43  var $info_box_contents = array();
44 
45 
52  function __construct($db,$param)
53  {
54  global $user;
55 
56  $this->db=$db;
57 
58  $this->hidden=! ($user->rights->societe->lire && empty($user->socid));
59  }
60 
67  function loadBox($max=5)
68  {
69  global $conf, $user, $langs, $db;
70  $langs->load("boxes");
71 
72  $this->max=$max;
73 
74  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
75  $thirdpartystatic=new Societe($db);
76  include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
77  $thirdpartytmp=new Fournisseur($db);
78 
79  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedSuppliers",$max));
80 
81  if ($user->rights->societe->lire)
82  {
83  $sql = "SELECT s.nom as name, s.rowid as socid, s.datec, s.tms, s.status,";
84  $sql.= " s.code_fournisseur,";
85  $sql.= " s.logo";
86  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
87  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
88  $sql.= " WHERE s.fournisseur = 1";
89  $sql.= " AND s.entity IN (".getEntity('societe').")";
90  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
91  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
92  $sql.= " ORDER BY s.tms DESC ";
93  $sql.= $db->plimit($max, 0);
94 
95  $result = $db->query($sql);
96  if ($result)
97  {
98  $num = $db->num_rows($result);
99 
100  $line = 0;
101  while ($line < $num)
102  {
103  $objp = $db->fetch_object($result);
104  $datec=$db->jdate($objp->datec);
105  $datem=$db->jdate($objp->tms);
106  $thirdpartytmp->id = $objp->socid;
107  $thirdpartytmp->name = $objp->name;
108  $thirdpartytmp->code_client = $objp->code_client;
109  $thirdpartytmp->logo = $objp->logo;
110 
111  $this->info_box_contents[$line][] = array(
112  'td' => '',
113  'text' => $thirdpartytmp->getNomUrl(1, '', 40),
114  'asis' => 1,
115  );
116 
117  $this->info_box_contents[$line][] = array(
118  'td' => 'class="right"',
119  'text' => dol_print_date($datem, "day"),
120  );
121 
122  $this->info_box_contents[$line][] = array(
123  'td' => 'align="right" width="18"',
124  'text' => $thirdpartystatic->LibStatut($objp->status,3),
125  );
126 
127  $line++;
128  }
129 
130  if ($num==0) $this->info_box_contents[$line][0] = array(
131  'td' => 'align="center"',
132  'text'=>$langs->trans("NoRecordedSuppliers"),
133  );
134 
135  $db->free($result);
136  } else {
137  $this->info_box_contents[0][0] = array(
138  'td' => '',
139  'maxlength'=>500,
140  'text' => ($db->error().' sql='.$sql),
141  );
142  }
143  } else {
144  $this->info_box_contents[0][0] = array(
145  'td' => 'align="left" class="nohover opacitymedium"',
146  'text' => $langs->trans("ReadPermissionNotAllowed")
147  );
148  }
149 
150  }
151 
160  function showBox($head = null, $contents = null, $nooutput=0)
161  {
162  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
163  }
164 
165 }
166 
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.