[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?php 2 /* Copyright (C) 2002-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: cotisation.class.php,v 1.12 2005/03/18 23:56:41 eldy Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/adherents/cotisation.class.php,v $ 20 * 21 */ 22 23 /*! \file htdocs/adherents/cotisation.class.php 24 \ingroup adherent 25 \brief Fichier de la classe permettant de gèrer les cotisations 26 \author Rodolphe Quiedeville 27 \version $Revision: 1.12 $ 28 */ 29 30 /*! \class Cotisation 31 \brief Classe permettant de gèrer les cotisations 32 */ 33 34 class Cotisation 35 { 36 var $id; 37 var $db; 38 var $date; 39 var $amount; 40 var $prenom; 41 var $nom; 42 var $societe; 43 var $adresse; 44 var $cp; 45 var $ville; 46 var $pays; 47 var $email; 48 var $public; 49 var $projetid; 50 var $modepaiement; 51 var $modepaiementid; 52 var $commentaire; 53 var $statut; 54 55 var $projet; 56 var $errorstr; 57 58 /*! 59 \brief Cotisation 60 \param DB base de données 61 \param soc_idp 62 */ 63 64 function Cotisation($DB, $soc_idp="") 65 { 66 $this->db = $DB ; 67 $this->modepaiementid = 0; 68 } 69 70 71 /* 72 * 73 * 74 */ 75 76 function print_error_list() 77 { 78 $num = sizeof($this->errorstr); 79 for ($i = 0 ; $i < $num ; $i++) 80 { 81 print "<li>" . $this->errorstr[$i]; 82 } 83 } 84 85 /* 86 * 87 * 88 */ 89 90 function check($minimum=0) 91 { 92 $err = 0; 93 94 if (strlen(trim($this->societe)) == 0) 95 { 96 if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0) 97 { 98 $error_string[$err] = "Vous devez saisir vos nom et prénom ou le nom de votre société."; 99 $err++; 100 } 101 } 102 103 if (strlen(trim($this->adresse)) == 0) 104 { 105 $error_string[$err] = "L'adresse saisie est invalide"; 106 $err++; 107 } 108 109 if (strlen(trim($this->cp)) == 0) 110 { 111 $error_string[$err] = "Le code postal saisi est invalide"; 112 $err++; 113 } 114 115 if (strlen(trim($this->ville)) == 0) 116 { 117 $error_string[$err] = "La ville saisie est invalide"; 118 $err++; 119 } 120 121 if (strlen(trim($this->email)) == 0) 122 { 123 $error_string[$err] = "L'email saisi est invalide"; 124 $err++; 125 } 126 127 $this->amount = trim($this->amount); 128 129 $map = range(0,9); 130 for ($i = 0; $i < strlen($this->amount) ; $i++) 131 { 132 if (!isset($map[substr($this->amount, $i, 1)] )) 133 { 134 $error_string[$err] = "Le montant du don contient un/des caractère(s) invalide(s)"; 135 $err++; 136 $amount_invalid = 1; 137 break; 138 } 139 } 140 141 if (! $amount_invalid) 142 { 143 if ($this->amount == 0) 144 { 145 $error_string[$err] = "Le montant du don est null"; 146 $err++; 147 } 148 else 149 { 150 if ($this->amount < $minimum && $minimum > 0) 151 { 152 $error_string[$err] = "Le montant minimum du don est de $minimum"; 153 $err++; 154 } 155 } 156 } 157 158 /* 159 * Return errors 160 * 161 */ 162 163 if ($err) 164 { 165 $this->errorstr = $error_string; 166 return 0; 167 } 168 else 169 { 170 return 1; 171 } 172 173 } 174 175 /*! 176 \brief fonction qui permet de créer le don 177 \param userid userid de l'adhérent 178 */ 179 180 function create($userid) 181 { 182 /* 183 * Insertion dans la base 184 */ 185 186 $this->date = $this->db->idate($this->date); 187 188 $sql = "INSERT INTO ".MAIN_DB_PREFIX."don (datec, amount, fk_paiement,prenom, nom, societe,adresse, cp, ville, pays, public, fk_don_projet, note, fk_user_author, datedon, email)"; 189 $sql .= " VALUES (now(), $this->amount, $this->modepaiementid,'$this->prenom','$this->nom','$this->societe','$this->adresse', '$this->cp','$this->ville','$this->pays',$this->public, $this->projetid, '$this->commentaire', $userid, '$this->date','$this->email')"; 190 191 $result = $this->db->query($sql); 192 193 if ($result) 194 { 195 return $this->db->last_insert_id(MAIN_DB_PREFIX."don"); 196 } 197 else 198 { 199 dolibarr_print_error($this->db); 200 return 0; 201 } 202 } 203 204 /*! 205 \brief fonction qui permet de mettre à jour le don 206 \param userid userid de l'adhérent 207 */ 208 209 function update($userid) 210 { 211 212 $this->date = $this->db->idate($this->date); 213 214 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET "; 215 $sql .= "amount = " . $this->amount; 216 $sql .= ",fk_paiement = ".$this->modepaiementid; 217 $sql .= ",prenom = '".$this->prenom ."'"; 218 $sql .= ",nom='".$this->nom."'"; 219 $sql .= ",societe='".$this->societe."'"; 220 $sql .= ",adresse='".$this->adresse."'"; 221 $sql .= ",cp='".$this->cp."'"; 222 $sql .= ",ville='".$this->ville."'"; 223 $sql .= ",pays='".$this->pays."'"; 224 $sql .= ",public=".$this->public; 225 $sql .= ",fk_don_projet=".$this->projetid; 226 $sql .= ",note='".$this->commentaire."'"; 227 $sql .= ",datedon='".$this->date."'"; 228 $sql .= ",email='".$this->email."'"; 229 $sql .= ",fk_statut=".$this->statut; 230 231 $sql .= " WHERE rowid = $this->id"; 232 233 $result = $this->db->query($sql); 234 235 if ($result) 236 { 237 return 1; 238 } 239 else 240 { 241 dolibarr_print_error($this->db); 242 return 0; 243 } 244 } 245 246 /*! 247 \brief fonction qui permet de supprimer le don 248 \param rowid 249 */ 250 251 function delete($rowid) 252 253 { 254 255 $sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;"; 256 257 if ( $this->db->query( $sql) ) 258 { 259 if ( $this->db->affected_rows() ) 260 { 261 return 1; 262 } 263 else 264 { 265 return 0; 266 } 267 } 268 else 269 { 270 dolibarr_print_error($this->db); 271 return 0; 272 } 273 } 274 275 /*! 276 \brief fonction qui permet de récupèrer le don 277 \param rowid 278 */ 279 280 function fetch($rowid) 281 { 282 $sql = "SELECT d.rowid, ".$this->db->pdate("d.datedon")." as datedon, 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"; 283 $sql .= " FROM ".MAIN_DB_PREFIX."don as d, ".MAIN_DB_PREFIX."don_projet as p, ".MAIN_DB_PREFIX."c_paiement as cp"; 284 285 $sql .= " WHERE p.rowid = d.fk_don_projet AND cp.id = d.fk_paiement AND d.rowid = $rowid"; 286 287 if ( $this->db->query( $sql) ) 288 { 289 if ($this->db->num_rows()) 290 { 291 292 $obj = $this->db->fetch_object(); 293 294 $this->id = $obj->rowid; 295 $this->date = $obj->datedon; 296 $this->prenom = stripslashes($obj->prenom); 297 $this->nom = stripslashes($obj->nom); 298 $this->societe = stripslashes($obj->societe); 299 $this->statut = $obj->fk_statut; 300 $this->adresse = stripslashes($obj->adresse); 301 $this->cp = stripslashes($obj->cp); 302 $this->ville = stripslashes($obj->ville); 303 $this->email = stripslashes($obj->email); 304 $this->pays = stripslashes($obj->pays); 305 $this->projet = $obj->projet; 306 $this->projetid = $obj->fk_don_projet; 307 $this->public = $obj->public; 308 $this->modepaiementid = $obj->fk_paiement; 309 $this->modepaiement = $obj->libelle; 310 $this->amount = $obj->amount; 311 $this->commentaire = stripslashes($obj->note); 312 } 313 } 314 else 315 { 316 print $this->db->error(); 317 } 318 319 } 320 321 /*! 322 \brief fonction qui permet de valider la promesse de don 323 \param rowid 324 \param userid userid de l'adhérent 325 */ 326 327 function valid_promesse($rowid, $userid) 328 { 329 330 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0;"; 331 332 if ( $this->db->query( $sql) ) 333 { 334 if ( $this->db->affected_rows() ) 335 { 336 return 1; 337 } 338 else 339 { 340 return 0; 341 } 342 } 343 else 344 { 345 dolibarr_print_error($this->db); 346 return 0; 347 } 348 } 349 350 /*! 351 \brief fonction qui permet de définir la cotisation comme payée 352 \param rowid rowid de la cotisation 353 \param modepaiement mode de paiement 354 */ 355 356 function set_paye($rowid, $modepaiement='') 357 { 358 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2"; 359 360 if ($modepaiement) 361 { 362 $sql .= ", fk_paiement=$modepaiement"; 363 } 364 $sql .= " WHERE rowid = $rowid AND fk_statut = 1;"; 365 366 if ( $this->db->query( $sql) ) 367 { 368 if ( $this->db->affected_rows() ) 369 { 370 return 1; 371 } 372 else 373 { 374 return 0; 375 } 376 } 377 else 378 { 379 dolibarr_print_error($this->db); 380 return 0; 381 } 382 } 383 384 /*! 385 \brief fonction qui permet de mettre un commentaire sur le don 386 \param rowid 387 \param commentaire 388 */ 389 390 function set_commentaire($rowid, $commentaire='') 391 { 392 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET note = '$commentaire'"; 393 394 $sql .= " WHERE rowid = $rowid ;"; 395 396 if ( $this->db->query( $sql) ) 397 { 398 if ( $this->db->affected_rows() ) 399 { 400 return 1; 401 } 402 else 403 { 404 return 0; 405 } 406 } 407 else 408 { 409 dolibarr_print_error($this->db); 410 return 0; 411 } 412 } 413 414 /*! 415 \brief fonction qui permet de mettre le don comme encaissé 416 \param rowid 417 */ 418 419 function set_encaisse($rowid) 420 { 421 422 $sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2;"; 423 424 if ( $this->db->query( $sql) ) 425 { 426 if ( $this->db->affected_rows() ) 427 { 428 return 1; 429 } 430 else 431 { 432 return 0; 433 } 434 } 435 else 436 { 437 dolibarr_print_error($this->db); 438 return 0; 439 } 440 } 441 442 /* 443 * Somme des dons encaissés 444 */ 445 446 function sum_actual() 447 { 448 $sql = "SELECT sum(amount)"; 449 $sql .= " FROM ".MAIN_DB_PREFIX."don"; 450 $sql .= " WHERE fk_statut = 3"; 451 452 if ( $this->db->query( $sql) ) 453 { 454 $row = $this->db->fetch_row(0); 455 456 return $row[0]; 457 458 } 459 } 460 461 /* Paiement recu en attente d'encaissement 462 * 463 * 464 */ 465 function sum_pending() 466 { 467 $sql = "SELECT sum(amount)"; 468 $sql .= " FROM ".MAIN_DB_PREFIX."don"; 469 $sql .= " WHERE fk_statut = 2"; 470 471 if ( $this->db->query( $sql) ) 472 { 473 $row = $this->db->fetch_row(0); 474 475 return $row[0]; 476 477 } 478 } 479 480 /* 481 * Somme des promesses de dons validées 482 * 483 */ 484 485 function sum_intent() 486 { 487 $sql = "SELECT sum(amount)"; 488 $sql .= " FROM ".MAIN_DB_PREFIX."don"; 489 $sql .= " WHERE fk_statut = 1"; 490 491 if ( $this->db->query( $sql) ) 492 { 493 $row = $this->db->fetch_row(0); 494 495 return $row[0]; 496 497 } 498 } 499 } 500 ?>
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 |
![]() |