| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2005 Laurent Destailleur <eldy@users.sourceforge.net> 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software 17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * 19 * $Id: entrepot.class.php,v 1.14 2005/03/28 18:50:47 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/product/stock/entrepot.class.php,v $ 21 * 22 */ 23 24 /** 25 \file htdocs/product/stock/entrepot.class.php 26 \ingroup stock 27 \brief Fichier de la classe de gestion des entrepots 28 \version $Revision: 1.14 $ 29 */ 30 31 32 /** \class Entrepot 33 \brief Classe permettant la gestion des entrepots 34 */ 35 36 class Entrepot 37 { 38 var $db; 39 var $error; 40 41 var $id; 42 var $libelle; 43 var $description; 44 var $statut; 45 var $lieu; 46 var $address; 47 var $cp; 48 var $ville; 49 var $pays_id; 50 51 /* 52 * \brief Constructeur de l'objet entrepot 53 * \param DB Handler d'accès à la base de donnée 54 */ 55 function Entrepot($DB) 56 { 57 global $langs; 58 $this->db = $DB; 59 60 $this->statuts[0] = $langs->trans("Closed"); 61 $this->statuts[1] = $langs->trans("Opened"); 62 } 63 64 /* 65 * \brief Creation d'un entrepot en base 66 * \param Objet user qui crée l'entrepot 67 */ 68 function create($user) 69 { 70 // Si libelle non defini, erreur 71 if ($this->libelle == '') { 72 $this->error = "Libellé obligatoire"; 73 return 0; 74 } 75 76 $this->db->begin(); 77 78 $sql = "INSERT INTO ".MAIN_DB_PREFIX."entrepot (datec, fk_user_author)"; 79 $sql .= " VALUES (now(),".$user->id.")"; 80 81 $result=$this->db->query($sql); 82 if ($result) 83 { 84 $id = $this->db->last_insert_id(MAIN_DB_PREFIX."entrepot"); 85 if ($id > 0) 86 { 87 $this->id = $id; 88 89 if ( $this->update($id, $user) > 0) 90 { 91 $this->db->commit(); 92 return $id; 93 } 94 else 95 { 96 $this->db->rollback(); 97 return -3; 98 } 99 } 100 else { 101 $this->error="Failed to get insert id"; 102 return -2; 103 } 104 } 105 else 106 { 107 $this->error="Failed to insert warehouse"; 108 $this->db->rollback(); 109 return -1; 110 } 111 112 } 113 114 /* 115 * \brief Mise a jour des information d'un entrepot 116 * \param id id de l'entrepot à modifier 117 * \param user 118 */ 119 function update($id, $user) 120 { 121 $this->libelle=trim($this->libelle); 122 $this->description=trim($this->description); 123 124 $this->lieu=trim($this->lieu); 125 $this->address=trim($this->address); 126 $this->cp=trim($this->cp); 127 $this->ville=trim($this->ville); 128 $this->pays_id=trim($this->pays_id); 129 130 $sql = "UPDATE ".MAIN_DB_PREFIX."entrepot "; 131 $sql .= " SET label = '" . $this->libelle ."'"; 132 $sql .= ",description = '" . $this->description ."'"; 133 $sql .= ",statut = " . $this->statut ; 134 $sql .= ",description = '" . $this->description ."'"; 135 $sql .= ",lieu = '" . $this->lieu ."'"; 136 $sql .= ",address = '" . $this->address ."'"; 137 $sql .= ",cp = '" . $this->cp ."'"; 138 $sql .= ",ville = '" . $this->ville ."'"; 139 $sql .= ",fk_pays = " . $this->pays_id?$this->pays_id:'0' ; 140 $sql .= " WHERE rowid = " . $id; 141 142 if ( $this->db->query($sql) ) 143 { 144 return 1; 145 } 146 else 147 { 148 $this->error=$this->db->error()." sql=$sql";; 149 return -1; 150 } 151 } 152 153 154 /** 155 * \brief Recupéeration de la base d'un entrepot 156 * \param id id de l'entrepot a récupérer 157 */ 158 function fetch ($id) 159 { 160 $sql = "SELECT rowid, label, description, statut, lieu, address, cp, ville, fk_pays"; 161 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot"; 162 $sql .= " WHERE rowid = $id"; 163 164 $result = $this->db->query($sql); 165 if ($result) 166 { 167 $obj=$this->db->fetch_object($result); 168 169 $this->id = $obj->rowid; 170 $this->ref = $obj->rowid; 171 $this->libelle = $obj->label; 172 $this->description = $obj->description; 173 $this->statut = $obj->statut; 174 $this->lieu = $obj->lieu; 175 $this->address = $obj->address; 176 $this->cp = $obj->cp; 177 $this->ville = $obj->ville; 178 $this->pays_id = $obj->pays_id; 179 180 $this->db->free($result); 181 return 1; 182 } 183 else 184 { 185 $this->error=$this->db->error(); 186 return -1; 187 } 188 } 189 190 191 /* 192 * \brief Charge les informations d'ordre info dans l'objet entrepot 193 * \param id id de l'entrepot a charger 194 */ 195 function info($id) 196 { 197 $sql = "SELECT e.rowid, ".$this->db->pdate("datec")." as datec,"; 198 $sql .= " ".$this->db->pdate("tms")." as datem,"; 199 $sql .= " fk_user_author"; 200 $sql .= " FROM ".MAIN_DB_PREFIX."entrepot as e"; 201 $sql .= " WHERE e.rowid = ".$id; 202 203 $result=$this->db->query($sql); 204 if ($result) 205 { 206 if ($this->db->num_rows($result)) 207 { 208 $obj = $this->db->fetch_object($result); 209 210 $this->id = $obj->rowid; 211 212 if ($obj->fk_user_author) { 213 $cuser = new User($this->db, $obj->fk_user_author); 214 $cuser->fetch(); 215 $this->user_creation = $cuser; 216 } 217 218 if ($obj->fk_user_valid) { 219 $vuser = new User($this->db, $obj->fk_user_valid); 220 $vuser->fetch(); 221 $this->user_validation = $vuser; 222 } 223 224 $this->date_creation = $obj->datec; 225 $this->date_modification = $obj->datem; 226 227 } 228 229 $this->db->free($result); 230 231 } 232 else 233 { 234 dolibarr_print_error($this->db); 235 } 236 } 237 238 239 /** 240 * \brief Renvoie la liste des entrepôts ouverts 241 */ 242 function list_array() 243 { 244 $liste = array(); 245 246 $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."entrepot WHERE statut = 1"; 247 248 $result = $this->db->query($sql) ; 249 $i = 0; 250 $num = $this->db->num_rows(); 251 252 if ( $result ) 253 { 254 while ($i < $num) 255 { 256 $row = $this->db->fetch_row($i); 257 $liste[$row[0]] = $row[1]; 258 $i++; 259 } 260 $this->db->free(); 261 } 262 return $liste; 263 } 264 265 /** 266 * \brief Renvoie le stock (nombre de produits) de l'entrepot 267 */ 268 function nb_products() 269 { 270 $sql = "SELECT sum(reel) FROM llx_product_stock WHERE fk_entrepot = ".$this->id; 271 272 $result = $this->db->query($sql) ; 273 274 if ( $result ) 275 { 276 $row = $this->db->fetch_row(0); 277 return $row[0]; 278 279 $this->db->free(); 280 } 281 else 282 { 283 return 0; 284 } 285 } 286 287 288 /** 289 * \brief Retourne le libellé du statut d'un entrepot (ouvert, fermé) 290 * \return string Libellé 291 */ 292 function getLibStatut() 293 { 294 return $this->LibStatut($this->statut); 295 } 296 297 /** 298 * \brief Renvoi le libellé d'un statut donné 299 * \param statut id statut 300 * \return string Libellé 301 */ 302 function LibStatut($statut) 303 { 304 return $this->statuts[$statut]; 305 } 306 307 } 308 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
|