dolibarr 24.0.0-beta
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
28require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
29require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
30require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
31
32
36class Fournisseur extends Societe
37{
38 public $next_prev_filter = "(te.fournisseur:=:1)"; // Used to add a filter in Form::showrefnav method
39
40
46 public function __construct($db)
47 {
48 $this->db = $db;
49
50 $this->client = 0;
51 $this->fournisseur = 1;
52 }
53
73 public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = 0, $is_supplier = 1)
74 {
75 return parent::fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
76 }
77
83 public function getNbOfOrders()
84 {
85 $num = 0;
86
87 $sql = "SELECT rowid";
88 $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
89 $sql .= " WHERE cf.fk_soc = ".((int) $this->id);
90
91 $resql = $this->db->query($sql);
92 if ($resql) {
93 $num = $this->db->num_rows($resql);
94 }
95
96 return $num;
97 }
98
104 public function nbOfProductRefs()
105 {
106 global $conf;
107
108 $sql = "SELECT count(pfp.rowid) as nb";
109 $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
110 $sql .= " WHERE pfp.entity = ".$conf->entity;
111 $sql .= " AND pfp.fk_soc = ".((int) $this->id);
112
113 $resql = $this->db->query($sql);
114 if ($resql) {
115 $obj = $this->db->fetch_object($resql);
116 return $obj->nb;
117 } else {
118 return -1;
119 }
120 }
121
127 public function loadStateBoard()
128 {
129 global $conf, $user, $hookmanager;
130
131 $this->nb = array();
132 $clause = "WHERE";
133
134 $sql = "SELECT count(s.rowid) as nb";
135 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
136 if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
137 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
138 $sql .= " WHERE sc.fk_user = ".((int) $user->id);
139 $clause = "AND";
140 }
141 $sql .= " ".$clause." s.fournisseur = 1";
142 $sql .= " AND s.entity IN (".getEntity('societe').")";
143 // Add where from hooks
144 if (is_object($hookmanager)) {
145 $parameters = array();
146 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
147 $sql .= $hookmanager->resPrint;
148 }
149
150 $resql = $this->db->query($sql);
151 if ($resql) {
152 while ($obj = $this->db->fetch_object($resql)) {
153 $this->nb["suppliers"] = $obj->nb;
154 }
155 $this->db->free($resql);
156 return 1;
157 } else {
158 dol_print_error($this->db);
159 $this->error = $this->db->error();
160 return -1;
161 }
162 }
163
164 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
172 public function CreateCategory($user, $name)
173 {
174 // phpcs:enable
175 $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label,visible,type)";
176 $sql .= " VALUES ";
177 $sql .= " ('".$this->db->escape($name)."',1,1)";
178
179 dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
180 $resql = $this->db->query($sql);
181 if ($resql) {
182 dol_syslog("Fournisseur::CreateCategory : Success");
183 return 0;
184 } else {
185 $this->error = $this->db->lasterror();
186 dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
187 return -1;
188 }
189 }
190
191 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
197 public function ListArray()
198 {
199 // phpcs:enable
200 global $conf;
201 global $user;
202
203 $arr = array();
204
205 $sql = "SELECT s.rowid, s.nom as name";
206 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
207 if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
208 $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
209 }
210 $sql .= " WHERE s.fournisseur = 1";
211 $sql .= " AND s.entity IN (".getEntity('societe').")";
212 if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
213 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
214 }
215
216 $resql = $this->db->query($sql);
217
218 if ($resql) {
219 while ($obj = $this->db->fetch_object($resql)) {
220 $arr[$obj->rowid] = $obj->name;
221 }
222 } else {
223 dol_print_error($this->db);
224 $this->error = $this->db->lasterror();
225 }
226 return $arr;
227 }
228
237 public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
238 {
239 $tables = array(
240 'facture_fourn'
241 );
242
243 return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
244 }
245}
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.
getNbOfOrders()
Return nb of orders.
__construct($db)
Constructor.
loadStateBoard()
Load statistics indicators.
fetch($rowid, $ref='', $ref_ext='', $barcode='', $idprof1='', $idprof2='', $idprof3='', $idprof4='', $idprof5='', $idprof6='', $email='', $ref_alias='', $is_client=0, $is_supplier=1)
Load a third party from database into memory.
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...)
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
dol_print_error($db=null, $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.