dolibarr 19.0.3
fournisseur.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2006 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2011 Juanjo Menent <jmenent@2byte.es>
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
26require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
27require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
28require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
29
30
34class Fournisseur extends Societe
35{
36 public $next_prev_filter = "te.fournisseur = 1"; // Used to add a filter in Form::showrefnav method
37
38
44 public function __construct($db)
45 {
46 $this->db = $db;
47
48 $this->client = 0;
49 $this->fournisseur = 1;
50 }
51
52
58 public function getNbOfOrders()
59 {
60 $num = 0;
61
62 $sql = "SELECT rowid";
63 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
64 $sql .= " WHERE cf.fk_soc = ".((int) $this->id);
65
66 $resql = $this->db->query($sql);
67 if ($resql) {
68 $num = $this->db->num_rows($resql);
69 }
70
71 return $num;
72 }
73
79 public function nbOfProductRefs()
80 {
81 global $conf;
82
83 $sql = "SELECT count(pfp.rowid) as nb";
84 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
85 $sql .= " WHERE pfp.entity = ".$conf->entity;
86 $sql .= " AND pfp.fk_soc = ".((int) $this->id);
87
88 $resql = $this->db->query($sql);
89 if ($resql) {
90 $obj = $this->db->fetch_object($resql);
91 return $obj->nb;
92 } else {
93 return -1;
94 }
95 }
96
97 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
103 public function load_state_board()
104 {
105 // phpcs:enable
106 global $conf, $user, $hookmanager;
107
108 $this->nb = array();
109 $clause = "WHERE";
110
111 $sql = "SELECT count(s.rowid) as nb";
112 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
113 if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
114 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
115 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
116 $clause = "AND";
117 }
118 $sql .= " ".$clause." s.fournisseur = 1";
119 $sql .= " AND s.entity IN (".getEntity('societe').")";
120 // Add where from hooks
121 if (is_object($hookmanager)) {
122 $parameters = array();
123 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
124 $sql .= $hookmanager->resPrint;
125 }
126
127 $resql = $this->db->query($sql);
128 if ($resql) {
129 while ($obj = $this->db->fetch_object($resql)) {
130 $this->nb["suppliers"] = $obj->nb;
131 }
132 $this->db->free($resql);
133 return 1;
134 } else {
135 dol_print_error($this->db);
136 $this->error = $this->db->error();
137 return -1;
138 }
139 }
140
141 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
149 public function CreateCategory($user, $name)
150 {
151 // phpcs:enable
152 $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label,visible,type)";
153 $sql .= " VALUES ";
154 $sql .= " ('".$this->db->escape($name)."',1,1)";
155
156 dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
157 $resql = $this->db->query($sql);
158 if ($resql) {
159 dol_syslog("Fournisseur::CreateCategory : Success");
160 return 0;
161 } else {
162 $this->error = $this->db->lasterror();
163 dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
164 return -1;
165 }
166 }
167
168 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
174 public function ListArray()
175 {
176 // phpcs:enable
177 global $conf;
178 global $user;
179
180 $arr = array();
181
182 $sql = "SELECT s.rowid, s.nom as name";
183 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
184 if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
185 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
186 }
187 $sql .= " WHERE s.fournisseur = 1";
188 $sql .= " AND s.entity IN (".getEntity('societe').")";
189 if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
190 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
191 }
192
193 $resql = $this->db->query($sql);
194
195 if ($resql) {
196 while ($obj = $this->db->fetch_object($resql)) {
197 $arr[$obj->rowid] = $obj->name;
198 }
199 } else {
200 dol_print_error($this->db);
201 $this->error = $this->db->lasterror();
202 }
203 return $arr;
204 }
205
214 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
215 {
216 $tables = array(
217 'facture_fourn'
218 );
219
220 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
221 }
222}
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
Class to manage Dolibarr database access.
Class to manage suppliers.
nbOfProductRefs()
Returns number of ref prices (not number of products) for current supplier.
ListArray()
Return the suppliers list.
load_state_board()
Load statistics indicators.
getNbOfOrders()
Return nb of orders.
__construct($db)
Constructor.
CreateCategory($user, $name)
Create a supplier category.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
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...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.