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