dolibarr  7.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@capnetworks.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  $this->client = 0;
48  $this->fournisseur = 0;
49  $this->effectif_id = 0;
50  $this->forme_juridique_code = 0;
51  }
52 
53 
59  function getNbOfOrders()
60  {
61  $sql = "SELECT rowid";
62  $sql .= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as cf";
63  $sql .= " WHERE cf.fk_soc = ".$this->id;
64 
65  $resql = $this->db->query($sql);
66  if ($resql)
67  {
68  $num = $this->db->num_rows($resql);
69 
70  if ($num == 1)
71  {
72  $row = $this->db->fetch_row($resql);
73 
74  $this->single_open_commande = $row[0];
75  }
76  }
77  return $num;
78  }
79 
85  function nbOfProductRefs()
86  {
87  global $conf;
88 
89  $sql = "SELECT count(pfp.rowid) as nb";
90  $sql.= " FROM ".MAIN_DB_PREFIX."product_fournisseur_price as pfp";
91  $sql.= " WHERE pfp.entity = ".$conf->entity;
92  $sql.= " AND pfp.fk_soc = ".$this->id;
93 
94  $resql = $this->db->query($sql);
95  if ( $resql )
96  {
97  $obj = $this->db->fetch_object($resql);
98  return $obj->nb;
99  }
100  else
101  {
102  return -1;
103  }
104  }
105 
111  function load_state_board()
112  {
113  global $conf, $user;
114 
115  $this->nb=array();
116  $clause = "WHERE";
117 
118  $sql = "SELECT count(s.rowid) as nb";
119  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
120  if (!$user->rights->societe->client->voir && !$user->societe_id)
121  {
122  $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
123  $sql.= " WHERE sc.fk_user = " .$user->id;
124  $clause = "AND";
125  }
126  $sql.= " ".$clause." s.fournisseur = 1";
127  $sql.= " AND s.entity IN (".getEntity('societe').")";
128 
129  $resql=$this->db->query($sql);
130  if ($resql)
131  {
132  while ($obj=$this->db->fetch_object($resql))
133  {
134  $this->nb["suppliers"]=$obj->nb;
135  }
136  $this->db->free($resql);
137  return 1;
138  }
139  else
140  {
141  dol_print_error($this->db);
142  $this->error=$this->db->error();
143  return -1;
144  }
145 
146  }
147 
155  function CreateCategory($user, $name)
156  {
157  $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie (label,visible,type)";
158  $sql.= " VALUES ";
159  $sql.= " ('".$this->db->escape($name)."',1,1)";
160 
161  dol_syslog("Fournisseur::CreateCategory", LOG_DEBUG);
162  $resql = $this->db->query($sql);
163  if ($resql)
164  {
165  dol_syslog("Fournisseur::CreateCategory : Success");
166  return 0;
167  }
168  else
169  {
170  $this->error=$this->db->lasterror();
171  dol_syslog("Fournisseur::CreateCategory : Failed (".$this->error.")");
172  return -1;
173  }
174  }
175 
181  function ListArray()
182  {
183  global $conf;
184  global $user;
185 
186  $arr = array();
187 
188  $sql = "SELECT s.rowid, s.nom as name";
189  $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
190  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
191  $sql.= " WHERE s.fournisseur = 1";
192  $sql.= " AND s.entity IN (".getEntity('societe').")";
193  if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
194 
195  $resql=$this->db->query($sql);
196 
197  if ($resql)
198  {
199  while ($obj=$this->db->fetch_object($resql))
200  {
201  $arr[$obj->rowid] = $obj->name;
202  }
203  }
204  else
205  {
206  dol_print_error($this->db);
207  $this->error=$this->db->lasterror();
208  }
209  return $arr;
210  }
211 
212 }
213 
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.
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:1013