dolibarr 19.0.4
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
25include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
26
27
31class 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 (!$user->hasRight('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, sortorder";
112 $sql .= " FROM ".MAIN_DB_PREFIX."c_stcomm";
113 if ($active >= 0) {
114 $sql .= " WHERE active = ".((int) $active);
115 }
116 $sql .= $this->db->order('sortorder,id', 'ASC,ASC');
117
118 $resql = $this->db->query($sql);
119 $num = $this->db->num_rows($resql);
120 $i = 0;
121 while ($i < $num) {
122 $obj = $this->db->fetch_object($resql);
123 $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);
124 $i++;
125 }
126 return 1;
127 }
128}
Class to manage customers or prospects.
load_state_board()
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...)
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...