dolibarr  13.0.2
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-2019 Frederic France <frederic.france@netlogic.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 <https://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  public $boxcode = "lastprospects";
38  public $boximg = "object_company";
39  public $boxlabel = "BoxLastProspects";
40  public $depends = array("societe");
41 
45  public $db;
46 
47  public $enabled = 1;
48 
49  public $info_box_head = array();
50  public $info_box_contents = array();
51 
52 
59  public 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  public function loadBox($max = 5)
78  {
79  global $user, $langs, $conf;
80 
81  $this->max = $max;
82 
83  $thirdpartystatic = new Client($this->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.rowid as socid, s.nom as name, s.name_alias";
90  $sql .= ", s.code_client, s.code_compta, s.client";
91  $sql .= ", s.logo, s.email, s.entity";
92  $sql .= ", s.fk_stcomm";
93  $sql .= ", s.datec, s.tms, s.status";
94  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
95  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
96  $sql .= " WHERE s.client IN (2, 3)";
97  $sql .= " AND s.entity IN (".getEntity('societe').")";
98  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
99  if ($user->socid) $sql .= " AND s.rowid = ".$user->socid;
100  $sql .= " ORDER BY s.tms DESC";
101  $sql .= $this->db->plimit($max, 0);
102 
103  dol_syslog(get_class($this)."::loadBox", LOG_DEBUG);
104  $resql = $this->db->query($sql);
105  if ($resql)
106  {
107  $num = $this->db->num_rows($resql);
108 
109  $line = 0;
110  while ($line < $num)
111  {
112  $objp = $this->db->fetch_object($resql);
113  $datec = $this->db->jdate($objp->datec);
114  $datem = $this->db->jdate($objp->tms);
115 
116  $thirdpartystatic->id = $objp->socid;
117  $thirdpartystatic->name = $objp->name;
118  $thirdpartystatic->name_alias = $objp->name_alias;
119  $thirdpartystatic->code_client = $objp->code_client;
120  $thirdpartystatic->code_compta = $objp->code_compta;
121  $thirdpartystatic->client = $objp->client;
122  $thirdpartystatic->logo = $objp->logo;
123  $thirdpartystatic->email = $objp->email;
124  $thirdpartystatic->entity = $objp->entity;
125 
126  $this->info_box_contents[$line][] = array(
127  'td' => '',
128  'text' => $thirdpartystatic->getNomUrl(1),
129  'asis' => 1,
130  );
131 
132  $this->info_box_contents[$line][] = array(
133  'td' => 'class="right"',
134  'text' => dol_print_date($datem, "day"),
135  );
136 
137  $this->info_box_contents[$line][] = array(
138  'td' => 'class="right" width="18"',
139  'text' => str_replace('img ', 'img height="14" ', $thirdpartystatic->LibProspCommStatut($objp->fk_stcomm, 3)),
140  );
141 
142  $this->info_box_contents[$line][] = array(
143  'td' => 'class="right" width="18"',
144  'text' => $thirdpartystatic->LibStatut($objp->status, 3),
145  );
146 
147  $line++;
148  }
149 
150  if ($num == 0) {
151  $this->info_box_contents[$line][0] = array(
152  'td' => 'class="center opacitymedium"',
153  'text'=> $langs->trans("NoRecordedProspects"),
154  );
155  }
156 
157  $this->db->free($resql);
158  } else {
159  $this->info_box_contents[0][0] = array(
160  'td' => '',
161  'maxlength' => 500,
162  'text' => ($this->db->error().' sql='.$sql),
163  );
164  }
165  } else {
166  $this->info_box_contents[0][0] = array(
167  'td' => 'class="nohover opacitymedium left"',
168  'text' => $langs->trans("ReadPermissionNotAllowed")
169  );
170  }
171  }
172 
181  public function showBox($head = null, $contents = null, $nooutput = 0)
182  {
183  return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput);
184  }
185 }
Class to manage customers or prospects.
__construct($db, $param= '')
Constructor.
Class ModeleBoxes.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage the box to show last prospects.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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= 'auto', $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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->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)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232