dolibarr  21.0.0-alpha
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  * Copyright (C) 2024 Frédéric 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 <https://www.gnu.org/licenses/>.
19  */
20 
26 include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
27 
28 
32 class Client extends Societe
33 {
37  public $next_prev_filter = "te.client in (1,2,3)";
38 
42  public $cacheprospectstatus = array();
43 
44 
50  public function __construct($db)
51  {
52  $this->db = $db;
53 
54  $this->client = 3;
55  $this->fournisseur = 0;
56  }
57 
58 
78  public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = 1, $is_supplier = 0)
79  {
80  return parent::fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
81  }
82 
83  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
89  public function loadStateBoard()
90  {
91  global $user, $hookmanager;
92 
93  $this->nb = array("prospects" => 0, "customers" => 0);
94  $clause = "WHERE";
95 
96  $sql = "SELECT count(s.rowid) as nb, s.client";
97  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
98  if (!$user->hasRight('societe', 'client', 'voir')) {
99  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
100  $sql .= " WHERE sc.fk_user = ".((int) $user->id);
101  $clause = "AND";
102  }
103  $sql .= " ".$clause." s.client IN (1,2,3)";
104  $sql .= ' AND s.entity IN ('.getEntity($this->element).')';
105  // Add where from hooks
106  if (is_object($hookmanager)) {
107  $parameters = array();
108  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
109  $sql .= $hookmanager->resPrint;
110  }
111  $sql .= " GROUP BY s.client";
112 
113  $resql = $this->db->query($sql);
114  if ($resql) {
115  while ($obj = $this->db->fetch_object($resql)) {
116  if ($obj->client == 1 || $obj->client == 3) {
117  $this->nb["customers"] += $obj->nb;
118  }
119  if ($obj->client == 2 || $obj->client == 3) {
120  $this->nb["prospects"] += $obj->nb;
121  }
122  }
123  $this->db->free($resql);
124  return 1;
125  } else {
126  dol_print_error($this->db);
127  $this->error = $this->db->lasterror();
128  return -1;
129  }
130  }
131 
138  public function loadCacheOfProspStatus($active = 1)
139  {
140  global $langs;
141 
142  $sql = "SELECT id, code, libelle as label, picto, sortorder";
143  $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm";
144  if ($active >= 0) {
145  $sql .= " WHERE active = ".((int) $active);
146  }
147  $sql .= $this->db->order('sortorder,id', 'ASC,ASC');
148 
149  $resql = $this->db->query($sql);
150  $num = $this->db->num_rows($resql);
151  $i = 0;
152  while ($i < $num) {
153  $obj = $this->db->fetch_object($resql);
154  $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);
155  $i++;
156  }
157  return 1;
158  }
159 }
Class to manage customers or prospects.
fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=1, $is_supplier=0)
Load a third party from database into memory.
loadStateBoard()
Load indicators into this->nb for board.
loadCacheOfProspStatus($active=1)
Load array of prospect status.
__construct($db)
Constructor.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:751
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...