dolibarr  21.0.0-alpha
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 
26 require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
27 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php';
29 
30 
34 class 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 
71  public function fetch($rowid, $ref = '', $ref_ext = '', $barcode = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '', $is_client = 0, $is_supplier = 1)
72  {
73  return parent::fetch($rowid, $ref, $ref_ext, $barcode, $idprof1, $idprof2, $idprof3, $idprof4, $idprof5, $idprof6, $email, $ref_alias, $is_client, $is_supplier);
74  }
75 
81  public function getNbOfOrders()
82  {
83  $num = 0;
84 
85  $sql = "SELECT rowid";
86  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
87  $sql .= " WHERE cf.fk_soc = ".((int) $this->id);
88 
89  $resql = $this->db->query($sql);
90  if ($resql) {
91  $num = $this->db->num_rows($resql);
92  }
93 
94  return $num;
95  }
96 
102  public function nbOfProductRefs()
103  {
104  global $conf;
105 
106  $sql = "SELECT count(pfp.rowid) as nb";
107  $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
108  $sql .= " WHERE pfp.entity = ".$conf->entity;
109  $sql .= " AND pfp.fk_soc = ".((int) $this->id);
110 
111  $resql = $this->db->query($sql);
112  if ($resql) {
113  $obj = $this->db->fetch_object($resql);
114  return $obj->nb;
115  } else {
116  return -1;
117  }
118  }
119 
125  public function loadStateBoard()
126  {
127  global $conf, $user, $hookmanager;
128 
129  $this->nb = array();
130  $clause = "WHERE";
131 
132  $sql = "SELECT count(s.rowid) as nb";
133  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
134  if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
135  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
136  $sql .= " WHERE sc.fk_user = ".((int) $user->id);
137  $clause = "AND";
138  }
139  $sql .= " ".$clause." s.fournisseur = 1";
140  $sql .= " AND s.entity IN (".getEntity('societe').")";
141  // Add where from hooks
142  if (is_object($hookmanager)) {
143  $parameters = array();
144  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
145  $sql .= $hookmanager->resPrint;
146  }
147 
148  $resql = $this->db->query($sql);
149  if ($resql) {
150  while ($obj = $this->db->fetch_object($resql)) {
151  $this->nb["suppliers"] = $obj->nb;
152  }
153  $this->db->free($resql);
154  return 1;
155  } else {
156  dol_print_error($this->db);
157  $this->error = $this->db->error();
158  return -1;
159  }
160  }
161 
162  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
170  public function CreateCategory($user, $name)
171  {
172  // phpcs:enable
173  $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label,visible,type)";
174  $sql .= " VALUES ";
175  $sql .= " ('".$this->db->escape($name)."',1,1)";
176 
177  dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
178  $resql = $this->db->query($sql);
179  if ($resql) {
180  dol_syslog("Fournisseur::CreateCategory : Success");
181  return 0;
182  } else {
183  $this->error = $this->db->lasterror();
184  dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
185  return -1;
186  }
187  }
188 
189  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
195  public function ListArray()
196  {
197  // phpcs:enable
198  global $conf;
199  global $user;
200 
201  $arr = array();
202 
203  $sql = "SELECT s.rowid, s.nom as name";
204  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
205  if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
206  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
207  }
208  $sql .= " WHERE s.fournisseur = 1";
209  $sql .= " AND s.entity IN (".getEntity('societe').")";
210  if (!$user->hasRight("societe", "client", "voir") && !$user->socid) {
211  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
212  }
213 
214  $resql = $this->db->query($sql);
215 
216  if ($resql) {
217  while ($obj = $this->db->fetch_object($resql)) {
218  $arr[$obj->rowid] = $obj->name;
219  }
220  } else {
221  dol_print_error($this->db);
222  $this->error = $this->db->lasterror();
223  }
224  return $arr;
225  }
226 
235  public static function replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
236  {
237  $tables = array(
238  'facture_fourn'
239  );
240 
241  return CommonObject::commonReplaceThirdparty($dbs, $origin_id, $dest_id, $tables);
242  }
243 }
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('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...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.