dolibarr  9.0.0
box_clients.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Frederic France <frederic.france@free.fr>
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 <http://www.gnu.org/licenses/>.
19  */
20 
27 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
28 
29 
33 class box_clients extends ModeleBoxes
34 {
35  var $boxcode="lastcustomers";
36  var $boximg="object_company";
37  var $boxlabel="BoxLastCustomers";
38  var $depends = array("societe");
39 
43  public $db;
44 
45  var $enabled = 1;
46 
47  var $info_box_head = array();
48  var $info_box_contents = array();
49 
50 
57  function __construct($db,$param='')
58  {
59  global $conf, $user;
60 
61  $this->db = $db;
62 
63  // disable box for such cases
64  if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled=0; // disabled by this option
65 
66  $this->hidden = ! ($user->rights->societe->lire && empty($user->socid));
67  }
68 
75  function loadBox($max=5)
76  {
77  global $user, $langs, $db, $conf;
78  $langs->load("boxes");
79 
80  $this->max=$max;
81 
82  include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
83  $thirdpartystatic=new Societe($db);
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedCustomers",$max));
86 
87  if ($user->rights->societe->lire)
88  {
89  $sql = "SELECT s.nom as name, s.rowid as socid";
90  $sql.= ", s.code_client";
91  $sql.= ", s.client";
92  $sql.= ", s.code_fournisseur";
93  $sql.= ", s.fournisseur";
94  $sql.= ", s.code_compta";
95  $sql.= ", s.code_compta_fournisseur";
96  $sql.= ", s.logo";
97  $sql.= ", s.email";
98  $sql.= ", s.datec, s.tms, s.status";
99  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
100  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
101  $sql.= " WHERE s.client IN (1, 3)";
102  $sql.= " AND s.entity IN (".getEntity('societe').")";
103  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
104  if ($user->societe_id) $sql.= " AND s.rowid = $user->societe_id";
105  $sql.= " ORDER BY s.tms DESC";
106  $sql.= $db->plimit($max, 0);
107 
108  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
109  $result = $db->query($sql);
110  if ($result)
111  {
112  $num = $db->num_rows($result);
113 
114  $line = 0;
115  while ($line < $num)
116  {
117  $objp = $db->fetch_object($result);
118  $datec=$db->jdate($objp->datec);
119  $datem=$db->jdate($objp->tms);
120  $thirdpartystatic->id = $objp->socid;
121  $thirdpartystatic->name = $objp->name;
122  $thirdpartystatic->code_client = $objp->code_client;
123  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
124  $thirdpartystatic->code_compta = $objp->code_compta;
125  $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur;
126  $thirdpartystatic->client = $objp->client;
127  $thirdpartystatic->fournisseur = $objp->fournisseur;
128  $thirdpartystatic->logo = $objp->logo;
129  $thirdpartystatic->email = $objp->email;
130 
131  $this->info_box_contents[$line][] = array(
132  'td' => '',
133  'text' => $thirdpartystatic->getNomUrl(1),
134  'asis' => 1,
135  );
136 
137  $this->info_box_contents[$line][] = array(
138  'td' => 'class="right"',
139  'text' => dol_print_date($datem, "day")
140  );
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => 'align="right" width="18"',
144  'text' => $thirdpartystatic->LibStatut($objp->status,3)
145  );
146 
147  $line++;
148  }
149 
150  if ($num==0) $this->info_box_contents[$line][0] = array('td' => 'align="center"','text'=>$langs->trans("NoRecordedCustomers"));
151 
152  $db->free($result);
153  }
154  else {
155  $this->info_box_contents[0][0] = array( 'td' => '',
156  'maxlength'=>500,
157  'text' => ($db->error().' sql='.$sql));
158  }
159  }
160  else {
161  $this->info_box_contents[0][0] = array(
162  'td' => 'align="left" class="nohover opacitymedium"',
163  'text' => $langs->trans("ReadPermissionNotAllowed")
164  );
165  }
166  }
167 
176  function showBox($head = null, $contents = null, $nooutput=0)
177  {
178  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
179  }
180 }
181 
loadBox($max=5)
Load data for box to show them later.
Definition: box_clients.php:75
Class ModeleBoxes.
__construct($db, $param='')
Constructor.
Definition: box_clients.php:57
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
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.
Class to manage the box to show last thirdparties.
Definition: box_clients.php:33