dolibarr  9.0.0
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 <http://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  var $next_prev_filter="te.fournisseur = 1"; // Used to add a filter in Form::showrefnav method
37 
38 
44  function __construct($db)
45  {
46  $this->db = $db;
47 
48  $this->client = 0;
49  $this->fournisseur = 1;
50  }
51 
52 
58  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  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  }
99  else
100  {
101  return -1;
102  }
103  }
104 
105  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
111  function load_state_board()
112  {
113  // phpcs:enable
114  global $conf, $user;
115 
116  $this->nb=array();
117  $clause = "WHERE";
118 
119  $sql = "SELECT count(s.rowid) as nb";
120  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
121  if (!$user->rights->societe->client->voir && !$user->societe_id)
122  {
123  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
124  $sql.= " WHERE sc.fk_user = " .$user->id;
125  $clause = "AND";
126  }
127  $sql.= " ".$clause." s.fournisseur = 1";
128  $sql.= " AND s.entity IN (".getEntity('societe').")";
129 
130  $resql=$this->db->query($sql);
131  if ($resql)
132  {
133  while ($obj=$this->db->fetch_object($resql))
134  {
135  $this->nb["suppliers"]=$obj->nb;
136  }
137  $this->db->free($resql);
138  return 1;
139  }
140  else
141  {
142  dol_print_error($this->db);
143  $this->error=$this->db->error();
144  return -1;
145  }
146  }
147 
148  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
156  function CreateCategory($user, $name)
157  {
158  // phpcs:enable
159  $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label,visible,type)";
160  $sql.= " VALUES ";
161  $sql.= " ('".$this->db->escape($name)."',1,1)";
162 
163  dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
164  $resql = $this->db->query($sql);
165  if ($resql)
166  {
167  dol_syslog("Fournisseur::CreateCategory : Success");
168  return 0;
169  }
170  else
171  {
172  $this->error=$this->db->lasterror();
173  dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
174  return -1;
175  }
176  }
177 
178  // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
184  function ListArray()
185  {
186  // phpcs:enable
187  global $conf;
188  global $user;
189 
190  $arr = array();
191 
192  $sql = "SELECT s.rowid, s.nom as name";
193  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
194  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
195  $sql.= " WHERE s.fournisseur = 1";
196  $sql.= " AND s.entity IN (".getEntity('societe').")";
197  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
198 
199  $resql=$this->db->query($sql);
200 
201  if ($resql)
202  {
203  while ($obj=$this->db->fetch_object($resql))
204  {
205  $arr[$obj->rowid] = $obj->name;
206  }
207  }
208  else
209  {
210  dol_print_error($this->db);
211  $this->error=$this->db->lasterror();
212  }
213  return $arr;
214  }
215 }
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->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) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
nbOfProductRefs()
Returns number of ref prices (not number of products).
__construct($db)
Constructor.
ListArray()
Return the suppliers list.
load_state_board()
Load statistics indicators.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Class to manage suppliers.
getNbOfOrders()
Return nb of orders.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
CreateCategory($user, $name)
Create a supplier category.