dolibarr  17.0.4
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 
52 
58  public function getNbOfOrders()
59  {
60  $sql = "SELECT rowid";
61  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
62  $sql .= " WHERE cf.fk_soc = ".((int) $this->id);
63 
64  $resql = $this->db->query($sql);
65  if ($resql) {
66  $num = $this->db->num_rows($resql);
67 
68  if ($num == 1) {
69  $row = $this->db->fetch_row($resql);
70 
71  $this->single_open_commande = $row[0];
72  }
73  }
74  return $num;
75  }
76 
82  public function nbOfProductRefs()
83  {
84  global $conf;
85 
86  $sql = "SELECT count(pfp.rowid) as nb";
87  $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
88  $sql .= " WHERE pfp.entity = ".$conf->entity;
89  $sql .= " AND pfp.fk_soc = ".((int) $this->id);
90 
91  $resql = $this->db->query($sql);
92  if ($resql) {
93  $obj = $this->db->fetch_object($resql);
94  return $obj->nb;
95  } else {
96  return -1;
97  }
98  }
99 
100  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
106  public function load_state_board()
107  {
108  // phpcs:enable
109  global $conf, $user, $hookmanager;
110 
111  $this->nb = array();
112  $clause = "WHERE";
113 
114  $sql = "SELECT count(s.rowid) as nb";
115  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
116  if (empty($user->rights->societe->client->voir) && !$user->socid) {
117  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
118  $sql .= " WHERE sc.fk_user = ".((int) $user->id);
119  $clause = "AND";
120  }
121  $sql .= " ".$clause." s.fournisseur = 1";
122  $sql .= " AND s.entity IN (".getEntity('societe').")";
123  // Add where from hooks
124  if (is_object($hookmanager)) {
125  $parameters = array();
126  $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $this); // Note that $action and $object may have been modified by hook
127  $sql .= $hookmanager->resPrint;
128  }
129 
130  $resql = $this->db->query($sql);
131  if ($resql) {
132  while ($obj = $this->db->fetch_object($resql)) {
133  $this->nb["suppliers"] = $obj->nb;
134  }
135  $this->db->free($resql);
136  return 1;
137  } else {
138  dol_print_error($this->db);
139  $this->error = $this->db->error();
140  return -1;
141  }
142  }
143 
144  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
152  public function CreateCategory($user, $name)
153  {
154  // phpcs:enable
155  $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label,visible,type)";
156  $sql .= " VALUES ";
157  $sql .= " ('".$this->db->escape($name)."',1,1)";
158 
159  dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
160  $resql = $this->db->query($sql);
161  if ($resql) {
162  dol_syslog("Fournisseur::CreateCategory : Success");
163  return 0;
164  } else {
165  $this->error = $this->db->lasterror();
166  dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
167  return -1;
168  }
169  }
170 
171  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
177  public function ListArray()
178  {
179  // phpcs:enable
180  global $conf;
181  global $user;
182 
183  $arr = array();
184 
185  $sql = "SELECT s.rowid, s.nom as name";
186  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
187  if (empty($user->rights->societe->client->voir) && !$user->socid) {
188  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
189  }
190  $sql .= " WHERE s.fournisseur = 1";
191  $sql .= " AND s.entity IN (".getEntity('societe').")";
192  if (empty($user->rights->societe->client->voir) && !$user->socid) {
193  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
194  }
195 
196  $resql = $this->db->query($sql);
197 
198  if ($resql) {
199  while ($obj = $this->db->fetch_object($resql)) {
200  $arr[$obj->rowid] = $obj->name;
201  }
202  } else {
203  dol_print_error($this->db);
204  $this->error = $this->db->lasterror();
205  }
206  return $arr;
207  }
208 
217  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
218  {
219  $tables = array(
220  'facture_fourn'
221  );
222 
223  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
224  }
225 }
static commonReplaceThirdparty(DoliDB $db, $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.
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
nbOfProductRefs()
Returns number of ref prices (not number of products).
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.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
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.
$conf db
API class for accounts.
Definition: inc.php:41