dolibarr  17.0.3
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, $hookmanager;
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 (empty($user->rights->societe->client->voir) && !$user->socid) {
68  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
69  $sql .= " WHERE sc.fk_user = ".((int) $user->id);
70  $clause = "AND";
71  }
72  $sql .= " ".$clause." s.client IN (1,2,3)";
73  $sql .= ' AND s.entity IN ('.getEntity($this->element).')';
74  // Add where from hooks
75  if (is_object($hookmanager)) {
76  $parameters = array();
77  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
78  $sql .= $hookmanager->resPrint;
79  }
80  $sql .= " GROUP BY s.client";
81 
82  $resql = $this->db->query($sql);
83  if ($resql) {
84  while ($obj = $this->db->fetch_object($resql)) {
85  if ($obj->client == 1 || $obj->client == 3) {
86  $this->nb["customers"] += $obj->nb;
87  }
88  if ($obj->client == 2 || $obj->client == 3) {
89  $this->nb["prospects"] += $obj->nb;
90  }
91  }
92  $this->db->free($resql);
93  return 1;
94  } else {
95  dol_print_error($this->db);
96  $this->error = $this->db->lasterror();
97  return -1;
98  }
99  }
100 
107  public function loadCacheOfProspStatus($active = 1)
108  {
109  global $langs;
110 
111  $sql = "SELECT id, code, libelle as label, picto FROM ".MAIN_DB_PREFIX."c_stcomm";
112  if ($active >= 0) {
113  $sql .= " WHERE active = ".((int) $active);
114  }
115  $resql = $this->db->query($sql);
116  $num = $this->db->num_rows($resql);
117  $i = 0;
118  while ($i < $num) {
119  $obj = $this->db->fetch_object($resql);
120  $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);
121  $i++;
122  }
123  return 1;
124  }
125 }
Societe
Class to manage third parties objects (customers, suppliers, prospects...)
Definition: societe.class.php:49
db
$conf db
API class for accounts.
Definition: inc.php:41
Client\__construct
__construct($db)
Constructor.
Definition: client.class.php:43
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4993
Client\load_state_board
load_state_board()
Load indicators into this->nb for board.
Definition: client.class.php:57
Client\loadCacheOfProspStatus
loadCacheOfProspStatus($active=1)
Load array of prospect status.
Definition: client.class.php:107
$resql
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
Client
Class to manage customers or prospects.
Definition: client.class.php:31