dolibarr  9.0.0
box_prospect.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2011 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 
28 include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php';
29 include_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
30 
31 
36 {
37  var $boxcode="lastprospects";
38  var $boximg="object_company";
39  var $boxlabel="BoxLastProspects";
40  var $depends = array("societe");
41 
45  public $db;
46 
47  var $enabled = 1;
48 
49  var $info_box_head = array();
50  var $info_box_contents = array();
51 
52 
59  function __construct($db,$param='')
60  {
61  global $conf, $user;
62 
63  $this->db = $db;
64 
65  // disable box for such cases
66  if (! empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $this->enabled=0; // disabled by this option
67 
68  $this->hidden=! ($user->rights->societe->lire && empty($user->socid));
69  }
70 
77  function loadBox($max=5)
78  {
79  global $user, $langs, $db, $conf;
80 
81  $this->max=$max;
82 
83  $thirdpartystatic=new Client($db);
84 
85  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedProspects",$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.logo";
95  $sql.= ", s.fk_stcomm, s.datec, s.tms, s.status";
96  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
97  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
98  $sql.= " WHERE s.client IN (2, 3)";
99  $sql.= " AND s.entity IN (".getEntity('societe').")";
100  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
101  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
102  $sql.= " ORDER BY s.tms DESC";
103  $sql.= $db->plimit($max, 0);
104 
105  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
106  $resql = $db->query($sql);
107  if ($resql)
108  {
109  $num = $db->num_rows($resql);
110 
111  $line = 0;
112  while ($line < $num)
113  {
114  $objp = $db->fetch_object($resql);
115  $datec=$db->jdate($objp->datec);
116  $datem=$db->jdate($objp->tms);
117  $thirdpartystatic->id = $objp->socid;
118  $thirdpartystatic->name = $objp->name;
119  $thirdpartystatic->code_client = $objp->code_client;
120  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
121  $thirdpartystatic->client = $objp->client;
122  $thirdpartystatic->fournisseur = $objp->fournisseur;
123  $thirdpartystatic->logo = $objp->logo;
124 
125  $this->info_box_contents[$line][] = array(
126  'td' => '',
127  'text' => $thirdpartystatic->getNomUrl(1),
128  'asis' => 1,
129  );
130 
131  $this->info_box_contents[$line][] = array(
132  'td' => 'class="right"',
133  'text' => dol_print_date($datem, "day"),
134  );
135 
136  $this->info_box_contents[$line][] = array(
137  'td' => 'align="right" width="18"',
138  'text' => str_replace('img ','img height="14" ',$thirdpartystatic->LibProspCommStatut($objp->fk_stcomm,3)),
139  );
140 
141  $this->info_box_contents[$line][] = array(
142  'td' => 'align="right" width="18"',
143  'text' => $thirdpartystatic->LibStatut($objp->status,3),
144  );
145 
146  $line++;
147  }
148 
149  if ($num==0)
150  $this->info_box_contents[$line][0] = array(
151  'td' => 'align="center"',
152  'text'=>$langs->trans("NoRecordedProspects"),
153  );
154 
155  $db->free($resql);
156  } else {
157  $this->info_box_contents[0][0] = array(
158  'td' => '',
159  'maxlength'=>500,
160  'text' => ($db->error().' sql='.$sql),
161  );
162  }
163  } else {
164  $this->info_box_contents[0][0] = array(
165  'td' => 'align="left" class="nohover opacitymedium"',
166  'text' => $langs->trans("ReadPermissionNotAllowed")
167  );
168  }
169  }
170 
179  function showBox($head = null, $contents = null, $nooutput=0)
180  {
181  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
182  }
183 }
184 
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
__construct($db, $param='')
Constructor.
Class to manage customers or prospects.
Class ModeleBoxes.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage the box to show last prospects.
loadBox($max=5)
Load data into info_box_contents array to show array later.
showBox($head=null, $contents=null, $nooutput=0)
Method to show box.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).