| [ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002 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: don.class.php,v 1.27 2005/11/11 22:55:34 eldy Exp $ 20 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/don.class.php,v $ 21 */ 22 23 /** 24 \file htdocs/don.class.php 25 \ingroup don 26 \brief Fichier de la classe des dons 27 \version $Revision: 1.27 $ 28 */ 29 30 31 /** 32 \class Don 33 \brief Classe permettant la gestion des dons 34 */ 35 36 class Don 37 { 38 var $id; 39 var $db; 40 var $date; 41 var $amount; 42 var $prenom; 43 var $nom; 44 var $societe; 45 var $adresse; 46 var $cp; 47 var $ville; 48 var $pays; 49 var $email; 50 var $public; 51 var $projetid; 52 var $modepaiement; 53 var $modepaiementid; 54 var $commentaire; 55 var $statut; 56 57 var $projet; 58 var $errorstr; 59 60 /** 61 * \brief Constructeur 62 * \param DB handler d'accès base 63 * \param soc_idp id sociét 64 */ 65 function Don($DB, $soc_idp="") 66 { 67 global $langs; 68 69 $this->db = $DB ; 70 $this->modepaiementid = 0; 71 72 $langs->load("donations"); 73 $this->labelstatut[0]=$langs->trans("DonationStatusPromessNotValidated"); 74 $this->labelstatut[1]=$langs->trans("DonationStatusPromessValidated"); 75 $this->labelstatut[2]=$langs->trans("DonationStatusPayed"); 76 } 77 78 /** 79 * \brief Retourne le libellé du statut d'une propale (brouillon, validée, ...) 80 * \return string Libellé 81 */ 82 function getLibStatut() 83 { 84 return $this->labelstatut[$this->statut]; 85 } 86 87 /* 88 * 89 */ 90 function print_error_list() 91 { 92 $num = sizeof($this->errorstr); 93 for ($i = 0 ; $i < $num ; $i++) 94 { 95 print "<li>" . $this->errorstr[$i]; 96 } 97 } 98 99 /* 100 * 101 * 102 */ 103 function check($minimum=0) 104 { 105 $err = 0; 106 107 if (strlen(trim($this->societe)) == 0) 108 { 109 if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) 110 { 111 $error_string[$err] = "Vous devez saisir vos nom et prénom ou le nom de votre société."; 112 $err++; 113 } 114 } 115 116 if (strlen(trim($this->adresse)) == 0) 117 { 118 $error_string[$err] = "L'adresse saisie est invalide"; 119 $err++; 120 } 121 122 if (strlen(trim($this->cp)) == 0) 123 { 124 $error_string[$err] = "Le code postal saisi est invalide"; 125 $err++; 126 } 127 128 if (strlen(trim($this->ville)) == 0) 129 { 130 $error_string[$err] = "La ville saisie est invalide"; 131 $err++; 132 } 133 134 if (strlen(trim($this->email)) == 0) 135 { 136 $error_string[$err] = "L'email saisi est invalide"; 137 $err++; 138 } 139 140 $this->amount = trim($this->amount); 141 142 $map = range(0,9); 143 for ($i = 0; $i < strlen($this->amount) ; $i++) 144 { 145 if (!isset($map[substr($this->amount, $i, 1)] )) 146 { 147 $error_string[$err] = "Le montant du don contient un/des caractère(s) invalide(s)"; 148 $err++; 149 $amount_invalid = 1; 150 break; 151 } 152 } 153 154 if (! $amount_invalid) 155 { 156 if ($this->amount == 0) 157 { 158 $error_string[$err] = "Le montant du don est null"; 159 $err++; 160 } 161 else 162 { 163 if ($this->amount < $minimum && $minimum > 0) 164 { 165 $error_string[$err] = "Le montant minimum du don est de $minimum"; 166 $err++; 167 } 168 } 169 } 170 171 if ($err) 172 { 173 $this->errorstr = $error_string; 174 return 0; 175 } 176 else 177 { 178 return 1; 179 } 180 181 } 182 183 /** 184 * \brief Création du don en base 185 * \param user Objet utilisateur qui crée le don 186 * \return int Id don crée si ok, <0 si ko 187 */ 188 function create($user) 189 { 190 $this->date = $this->db->idate($this->date); 191 192 $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public,"; 193 if ($this->projetid) 194 { 195 $sql .= " fk_don_projet,"; 196 } 197 $sql .= " note, fk_user_author, datedon, email)"; 198 $sql .= " VALUES (now(),".ereg_replace(",",".", $this->amount).", $this->modepaiementid,'$this->prenom','$this->nom','$this->societe','$this->adresse', '$this->cp','$this->ville','$this->pays',$this->public, "; 199 if ($this->projetid) 200 { 201 $sql .= " $this->projetid,"; 202 } 203 $sql .= " '$this->commentaire', ".$user->id.", '$this->date','$this->email')"; 204 205 $result = $this->db->query($sql); 206 if ($result) 207 { 208 return $this->db->last_insert_id(MAIN_DB_PREFIX."don"); 209 } 210 else 211 { 212 dolibarr_print_error($this->db); 213 return -1; 214 } 215 } 216 217 /** 218 * \brief Mise à jour du don 219 * \param user Objet utilisateur qui met à jour le don 220 * \return int >0 si ok, <0 si ko 221 */ 222 function update($user) 223 { 224 225 $this->date = $this->db->idate($this->date); 226 227 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET "; 228 $sql .= "amount = " . $this->amount; 229 $sql .= ",fk_paiement = ".$this->modepaiementid; 230 $sql .= ",prenom = '".$this->prenom ."'"; 231 $sql .= ",nom='".$this->nom."'"; 232 $sql .= ",societe='".$this->societe."'"; 233 $sql .= ",adresse='".$this->adresse."'"; 234 $sql .= ",cp='".$this->cp."'"; 235 $sql .= ",ville='".$this->ville."'"; 236 $sql .= ",pays='".$this->pays."'"; 237 $sql .= ",public=".$this->public; 238 if ($this->projetid) { $sql .= ",fk_don_projet=".$this->projetid; } 239 $sql .= ",note='".$this->commentaire."'"; 240 $sql .= ",datedon='".$this->date."'"; 241 $sql .= ",email='".$this->email."'"; 242 $sql .= ",fk_statut=".$this->statut; 243 244 $sql .= " WHERE rowid = $this->id"; 245 246 $result = $this->db->query($sql); 247 if ($result) 248 { 249 return 1; 250 } 251 else 252 { 253 dolibarr_print_error($this->db); 254 return -1; 255 } 256 } 257 258 /* 259 * \brief Suppression du don de la base 260 * \param rowid id du don à supprimer 261 */ 262 function delete($rowid) 263 { 264 265 $sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;"; 266 267 if ( $this->db->query( $sql) ) 268 { 269 if ( $this->db->affected_rows() ) 270 { 271 return 1; 272 } 273 else 274 { 275 return -1; 276 } 277 } 278 else 279 { 280 dolibarr_print_error($this->db); 281 return -1; 282 } 283 } 284 285 /* 286 * \brief Charge l'objet don en mémoire depuis la base de donnée 287 * \param rowid Id du don à charger 288 * \return int <0 si ko, >0 si ok 289 */ 290 function fetch($rowid) 291 { 292 $sql = "SELECT d.rowid, ".$this->db->pdate("d.datec")." as datec,"; 293 $sql.= " ".$this->db->pdate("d.datedon")." as datedon,"; 294 $sql.= " d.prenom, d.nom, d.societe, d.amount, p.libelle as projet, d.fk_statut, d.adresse, d.cp, d.ville, d.pays, d.public, d.amount, d.fk_paiement, d.note, cp.libelle, d.email, d.fk_don_projet"; 295 $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement as cp, ".MAIN_DB_PREFIX."don as d"; 296 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."don_projet as p"; 297 $sql.= " ON p.rowid = d.fk_don_projet"; 298 $sql.= " WHERE cp.id = d.fk_paiement AND d.rowid = ".$rowid; 299 300 if ( $this->db->query( $sql) ) 301 { 302 if ($this->db->num_rows()) 303 { 304 305 $obj = $this->db->fetch_object(); 306 307 $this->id = $obj->rowid; 308 $this->datec = $obj->datec; 309 $this->date = $obj->datedon; 310 $this->prenom = stripslashes($obj->prenom); 311 $this->nom = stripslashes($obj->nom); 312 $this->societe = stripslashes($obj->societe); 313 $this->statut = $obj->fk_statut; 314 $this->adresse = stripslashes($obj->adresse); 315 $this->cp = stripslashes($obj->cp); 316 $this->ville = stripslashes($obj->ville); 317 $this->email = stripslashes($obj->email); 318 $this->pays = stripslashes($obj->pays); 319 $this->projet = $obj->projet; 320 $this->projetid = $obj->fk_don_projet; 321 $this->public = $obj->public; 322 $this->modepaiementid = $obj->fk_paiement; 323 $this->modepaiement = $obj->libelle; 324 $this->amount = $obj->amount; 325 $this->commentaire = stripslashes($obj->note); 326 } 327 return 1; 328 } 329 else 330 { 331 dolibarr_print_error($this->db); 332 return -1; 333 } 334 335 } 336 337 /* 338 * \brief Valide une promesse de don 339 * \param rowid id du don à modifier 340 * \param userid utilisateur qui valide la promesse 341 * 342 */ 343 function valid_promesse($rowid, $userid) 344 { 345 346 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0;"; 347 348 if ( $this->db->query( $sql) ) 349 { 350 if ( $this->db->affected_rows() ) 351 { 352 return 1; 353 } 354 else 355 { 356 return 0; 357 } 358 } 359 else 360 { 361 dolibarr_print_error($this->db); 362 return 0; 363 } 364 } 365 366 /* 367 * \brief Classe le don comme payé, le don a été recu 368 * \param rowid id du don à modifier 369 * \param modepaiementd mode de paiement 370 */ 371 function set_paye($rowid, $modepaiement='') 372 { 373 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2"; 374 375 if ($modepaiement) 376 { 377 $sql .= ", fk_paiement=$modepaiement"; 378 } 379 $sql .= " WHERE rowid = $rowid AND fk_statut = 1;"; 380 381 if ( $this->db->query( $sql) ) 382 { 383 if ( $this->db->affected_rows() ) 384 { 385 return 1; 386 } 387 else 388 { 389 return 0; 390 } 391 } 392 else 393 { 394 dolibarr_print_error($this->db); 395 return 0; 396 } 397 } 398 399 /* 400 * \brief Défini le commentaire 401 * \param rowid id du don à modifier 402 * \param commentaire commentaire à définir ('' par défaut) 403 * 404 */ 405 function set_commentaire($rowid, $commentaire='') 406 { 407 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET note = '$commentaire'"; 408 409 $sql .= " WHERE rowid = $rowid ;"; 410 411 if ( $this->db->query( $sql) ) 412 { 413 if ( $this->db->affected_rows() ) 414 { 415 return 1; 416 } 417 else 418 { 419 return 0; 420 } 421 } 422 else 423 { 424 dolibarr_print_error($this->db); 425 return 0; 426 } 427 } 428 429 /* 430 * \brief Classe le don comme encaissé 431 * \param rowid id du don à modifier 432 * 433 */ 434 function set_encaisse($rowid) 435 { 436 437 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2;"; 438 439 if ( $this->db->query( $sql) ) 440 { 441 if ( $this->db->affected_rows() ) 442 { 443 return 1; 444 } 445 else 446 { 447 return 0; 448 } 449 } 450 else 451 { 452 dolibarr_print_error($this->db); 453 return 0; 454 } 455 } 456 457 /* 458 * \brief Somme des dons encaissés 459 */ 460 function sum_actual() 461 { 462 $sql = "SELECT sum(amount)"; 463 $sql .= " FROM ".MAIN_DB_PREFIX."don"; 464 $sql .= " WHERE fk_statut = 3"; 465 466 if ( $this->db->query( $sql) ) 467 { 468 $row = $this->db->fetch_row(0); 469 470 return $row[0]; 471 472 } 473 } 474 475 /* 476 * \brief Paiement recu en attente d'encaissement 477 * 478 */ 479 function sum_pending() 480 { 481 $sql = "SELECT sum(amount)"; 482 $sql .= " FROM ".MAIN_DB_PREFIX."don"; 483 $sql .= " WHERE fk_statut = 2"; 484 485 if ( $this->db->query( $sql) ) 486 { 487 $row = $this->db->fetch_row(0); 488 489 return $row[0]; 490 491 } 492 } 493 494 /* 495 * \brief Somme des promesses de dons validées 496 * 497 */ 498 function sum_intent() 499 { 500 $sql = "SELECT sum(amount)"; 501 $sql .= " FROM ".MAIN_DB_PREFIX."don"; 502 $sql .= " WHERE fk_statut = 1"; 503 504 if ( $this->db->query( $sql) ) 505 { 506 $row = $this->db->fetch_row(0); 507 508 return $row[0]; 509 510 } 511 } 512 } 513 ?>
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 |
|