dolibarr  7.0.0-beta
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@capnetworks.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 
42  var $db;
43  var $enabled = 1;
44 
45  var $info_box_head = array();
46  var $info_box_contents = array();
47 
48 
55  function __construct($db,$param='')
56  {
57  global $conf, $user;
58 
59  $this->db = $db;
60 
61  // disable box for such cases
62  if (! empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $this->enabled=0; // disabled by this option
63 
64  $this->hidden=! ($user->rights->societe->lire && empty($user->socid));
65  }
66 
73  function loadBox($max=5)
74  {
75  global $user, $langs, $db, $conf;
76 
77  $this->max=$max;
78 
79  $thirdpartystatic=new Client($db);
80 
81  $this->info_box_head = array('text' => $langs->trans("BoxTitleLastModifiedProspects",$max));
82 
83  if ($user->rights->societe->lire)
84  {
85  $sql = "SELECT s.nom as name, s.rowid as socid";
86  $sql.= ", s.code_client";
87  $sql.= ", s.client";
88  $sql.= ", s.code_fournisseur";
89  $sql.= ", s.fournisseur";
90  $sql.= ", s.logo";
91  $sql.= ", s.fk_stcomm, s.datec, s.tms, s.status";
92  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
93  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
94  $sql.= " WHERE s.client IN (2, 3)";
95  $sql.= " AND s.entity IN (".getEntity('societe').")";
96  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
97  if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id;
98  $sql.= " ORDER BY s.tms DESC";
99  $sql.= $db->plimit($max, 0);
100 
101  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
102  $resql = $db->query($sql);
103  if ($resql)
104  {
105  $num = $db->num_rows($resql);
106 
107  $line = 0;
108  while ($line < $num)
109  {
110  $objp = $db->fetch_object($resql);
111  $datec=$db->jdate($objp->datec);
112  $datem=$db->jdate($objp->tms);
113  $thirdpartystatic->id = $objp->socid;
114  $thirdpartystatic->name = $objp->name;
115  $thirdpartystatic->code_client = $objp->code_client;
116  $thirdpartystatic->code_fournisseur = $objp->code_fournisseur;
117  $thirdpartystatic->client = $objp->client;
118  $thirdpartystatic->fournisseur = $objp->fournisseur;
119  $thirdpartystatic->logo = $objp->logo;
120 
121  $this->info_box_contents[$line][] = array(
122  'td' => '',
123  'text' => $thirdpartystatic->getNomUrl(1),
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' => 'align="right" width="18"',
134  'text' => str_replace('img ','img height="14" ',$thirdpartystatic->LibProspCommStatut($objp->fk_stcomm,3)),
135  );
136 
137  $this->info_box_contents[$line][] = array(
138  'td' => 'align="right" width="18"',
139  'text' => $thirdpartystatic->LibStatut($objp->status,3),
140  );
141 
142  $line++;
143  }
144 
145  if ($num==0)
146  $this->info_box_contents[$line][0] = array(
147  'td' => 'align="center"',
148  'text'=>$langs->trans("NoRecordedProspects"),
149  );
150 
151  $db->free($resql);
152  } else {
153  $this->info_box_contents[0][0] = array(
154  'td' => '',
155  'maxlength'=>500,
156  'text' => ($db->error().' sql='.$sql),
157  );
158  }
159  } else {
160  $this->info_box_contents[0][0] = array(
161  'td' => 'align="left" class="nohover opacitymedium"',
162  'text' => $langs->trans("ReadPermissionNotAllowed")
163  );
164  }
165  }
166 
175  function showBox($head = null, $contents = null, $nooutput=0)
176  {
177  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
178  }
179 
180 }
181 
__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).
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:1013