dolibarr  13.0.2
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 = ".$this->id;
63 
64  $resql = $this->db->query($sql);
65  if ($resql)
66  {
67  $num = $this->db->num_rows($resql);
68 
69  if ($num == 1)
70  {
71  $row = $this->db->fetch_row($resql);
72 
73  $this->single_open_commande = $row[0];
74  }
75  }
76  return $num;
77  }
78 
84  public function nbOfProductRefs()
85  {
86  global $conf;
87 
88  $sql = "SELECT count(pfp.rowid) as nb";
89  $sql .= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
90  $sql .= " WHERE pfp.entity = ".$conf->entity;
91  $sql .= " AND pfp.fk_soc = ".$this->id;
92 
93  $resql = $this->db->query($sql);
94  if ($resql)
95  {
96  $obj = $this->db->fetch_object($resql);
97  return $obj->nb;
98  } else {
99  return -1;
100  }
101  }
102 
103  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
109  public function load_state_board()
110  {
111  // phpcs:enable
112  global $conf, $user;
113 
114  $this->nb = array();
115  $clause = "WHERE";
116 
117  $sql = "SELECT count(s.rowid) as nb";
118  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
119  if (!$user->rights->societe->client->voir && !$user->socid)
120  {
121  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
122  $sql .= " WHERE sc.fk_user = ".$user->id;
123  $clause = "AND";
124  }
125  $sql .= " ".$clause." s.fournisseur = 1";
126  $sql .= " AND s.entity IN (".getEntity('societe').")";
127 
128  $resql = $this->db->query($sql);
129  if ($resql)
130  {
131  while ($obj = $this->db->fetch_object($resql))
132  {
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  {
163  dol_syslog("Fournisseur::CreateCategory : Success");
164  return 0;
165  } else {
166  $this->error = $this->db->lasterror();
167  dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
168  return -1;
169  }
170  }
171 
172  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
178  public function ListArray()
179  {
180  // phpcs:enable
181  global $conf;
182  global $user;
183 
184  $arr = array();
185 
186  $sql = "SELECT s.rowid, s.nom as name";
187  $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
188  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
189  $sql .= " WHERE s.fournisseur = 1";
190  $sql .= " AND s.entity IN (".getEntity('societe').")";
191  if (!$user->rights->societe->client->voir && !$user->socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
192 
193  $resql = $this->db->query($sql);
194 
195  if ($resql)
196  {
197  while ($obj = $this->db->fetch_object($resql))
198  {
199  $arr[$obj->rowid] = $obj->name;
200  }
201  } else {
202  dol_print_error($this->db);
203  $this->error = $this->db->lasterror();
204  }
205  return $arr;
206  }
207 
216  public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
217  {
218  $tables = array(
219  'facture_fourn'
220  );
221 
222  return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
223  }
224 }
nbOfProductRefs()
Returns number of ref prices (not number of products).
__construct($db)
Constructor.
Class to manage Dolibarr database access.
ListArray()
Return the suppliers list.
load_state_board()
Load statistics indicators.
$conf db
API class for accounts.
Definition: inc.php:54
Class to manage suppliers.
getNbOfOrders()
Return nb of orders.
Class to manage third parties objects (customers, suppliers, prospects...)
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
CreateCategory($user, $name)
Create a supplier category.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1232
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...