dolibarr  13.0.2
client.class.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
4  * Copyright (C) 2020 Open-Dsi <support@open-dsi.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 <https://www.gnu.org/licenses/>.
18  */
19 
25 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
26 
27 
31 class Client extends Societe
32 {
33  public $next_prev_filter = "te.client in (1,2,3)"; // Used to add a filter in Form::showrefnav method
34 
35  public $cacheprospectstatus = array();
36 
37 
43  public function __construct($db)
44  {
45  $this->db = $db;
46 
47  $this->client = 3;
48  $this->fournisseur = 0;
49  }
50 
51  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
57  public function load_state_board()
58  {
59  // phpcs:enable
60  global $user;
61 
62  $this->nb = array("prospects" => 0, "customers" => 0);
63  $clause = "WHERE";
64 
65  $sql = "SELECT count(s.rowid) as nb, s.client";
66  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
67  if (!$user->rights->societe->client->voir && !$user->socid)
68  {
69  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
70  $sql .= " WHERE sc.fk_user = ".$user->id;
71  $clause = "AND";
72  }
73  $sql .= " ".$clause." s.client IN (1,2,3)";
74  $sql .= ' AND s.entity IN ('.getEntity($this->element).')';
75  $sql .= " GROUP BY s.client";
76 
77  $resql = $this->db->query($sql);
78  if ($resql)
79  {
80  while ($obj = $this->db->fetch_object($resql))
81  {
82  if ($obj->client == 1 || $obj->client == 3) $this->nb["customers"] += $obj->nb;
83  if ($obj->client == 2 || $obj->client == 3) $this->nb["prospects"] += $obj->nb;
84  }
85  $this->db->free($resql);
86  return 1;
87  } else {
88  dol_print_error($this->db);
89  $this->error = $this->db->lasterror();
90  return -1;
91  }
92  }
93 
100  public function loadCacheOfProspStatus($active = 1)
101  {
102  global $langs;
103 
104  $sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcomm";
105  if ($active >= 0) $sql .= " WHERE active = ".$active;
106  $resql = $this->db->query($sql);
107  $num = $this->db->num_rows($resql);
108  $i = 0;
109  while ($i < $num) {
110  $obj = $this->db->fetch_object($resql);
111  $this->cacheprospectstatus[$obj->id] = array('id'=>$obj->id, 'code'=>$obj->code, 'label'=>($langs->trans("ST_".strtoupper($obj->code)) == "ST_".strtoupper($obj->code)) ? $obj->label : $langs->trans("ST_".strtoupper($obj->code)), 'picto'=>$obj->picto);
112  $i++;
113  }
114  return 1;
115  }
116 }
loadCacheOfProspStatus($active=1)
Load array of prospect status.
load_state_board()
Load indicators into this-&gt;nb for board.
Class to manage customers or prospects.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage third parties objects (customers, suppliers, prospects...)
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
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
__construct($db)
Constructor.