dolibarr/htdocs/don.class.php

470 lines
9.6 KiB
PHP
Raw Normal View History

2002-12-17 20:40:02 +01:00
<?PHP
/* Copyright (C) 2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
* $Source$
*
*/
class Don
{
var $id;
var $db;
2002-12-22 16:11:07 +01:00
var $date;
2002-12-17 20:40:02 +01:00
var $amount;
2002-12-22 16:11:07 +01:00
var $prenom;
2002-12-19 19:55:38 +01:00
var $nom;
2002-12-22 16:11:07 +01:00
var $societe;
2002-12-19 19:55:38 +01:00
var $adresse;
var $cp;
var $ville;
var $pays;
2002-12-22 16:11:07 +01:00
var $email;
2002-12-19 19:55:38 +01:00
var $public;
var $projetid;
var $modepaiement;
2002-12-21 18:35:17 +01:00
var $modepaiementid;
var $commentaire;
2002-12-19 19:55:38 +01:00
var $statut;
var $projet;
2002-12-20 19:07:49 +01:00
var $errorstr;
2002-12-17 20:40:02 +01:00
/*
2002-12-19 19:55:38 +01:00
* Statut du don
* 0 : promesse non valid<EFBFBD>e
* 1 : promesse valid<EFBFBD>e
* 2 : don valid<EFBFBD>
* 3 : don pay<EFBFBD>
2002-12-17 20:40:02 +01:00
*
*
*/
Function Don($DB, $soc_idp="")
{
$this->db = $DB ;
2002-12-21 18:35:17 +01:00
$this->modepaiementid = 0;
2002-12-20 19:07:49 +01:00
}
/*
*
*
*
*/
Function print_error_list()
{
$num = sizeof($this->errorstr);
for ($i = 0 ; $i < $num ; $i++)
{
print "<li>" . $this->errorstr[$i];
}
}
2002-12-22 21:04:24 +01:00
/*
*
*
*/
2002-12-22 19:37:53 +01:00
Function check($minimum=0)
2002-12-20 19:07:49 +01:00
{
$err = 0;
2002-12-22 16:11:07 +01:00
if (strlen(trim($this->societe)) == 0)
2002-12-20 19:07:49 +01:00
{
2002-12-22 16:11:07 +01:00
if ((strlen(trim($this->nom)) + strlen(trim($this->prenom))) == 0)
{
$error_string[$err] = "Vous devez saisir vos nom et pr<70>nom ou le nom de votre soci<63>t<EFBFBD>.";
$err++;
}
2002-12-20 19:07:49 +01:00
}
if (strlen(trim($this->adresse)) == 0)
{
$error_string[$err] = "L'adresse saisie est invalide";
$err++;
}
if (strlen(trim($this->cp)) == 0)
{
$error_string[$err] = "Le code postal saisi est invalide";
$err++;
}
if (strlen(trim($this->ville)) == 0)
{
$error_string[$err] = "La ville saisie est invalide";
$err++;
}
2002-12-22 16:11:07 +01:00
if (strlen(trim($this->email)) == 0)
2002-12-20 19:07:49 +01:00
{
2002-12-22 16:11:07 +01:00
$error_string[$err] = "L'email saisi est invalide";
2002-12-20 19:07:49 +01:00
$err++;
}
2002-12-22 16:11:07 +01:00
$this->amount = trim($this->amount);
$map = range(0,9);
for ($i = 0; $i < strlen($this->amount) ; $i++)
{
if (!isset($map[substr($this->amount, $i, 1)] ))
{
$error_string[$err] = "Le montant du don contient un/des caract<63>re(s) invalide(s)";
$err++;
2002-12-22 19:46:40 +01:00
$amount_invalid = 1;
2002-12-22 16:11:07 +01:00
break;
}
}
2002-12-22 19:46:40 +01:00
if (! $amount_invalid)
2002-12-22 16:11:07 +01:00
{
2002-12-22 19:46:40 +01:00
if ($this->amount == 0)
2002-12-22 19:37:53 +01:00
{
2002-12-22 19:46:40 +01:00
$error_string[$err] = "Le montant du don est null";
2002-12-22 19:37:53 +01:00
$err++;
}
2002-12-22 19:46:40 +01:00
else
{
if ($this->amount < $minimum && $minimum > 0)
{
$error_string[$err] = "Le montant minimum du don est de $minimum";
$err++;
}
}
2002-12-22 19:37:53 +01:00
}
2002-12-22 19:46:40 +01:00
/*
* Return errors
*
*/
2002-12-20 19:07:49 +01:00
if ($err)
{
$this->errorstr = $error_string;
return 0;
}
else
{
return 1;
}
2002-12-17 20:40:02 +01:00
}
/*
2002-12-27 22:54:03 +01:00
* Cr<EFBFBD>ation
2002-12-17 20:40:02 +01:00
*
*
*/
2002-12-19 19:55:38 +01:00
Function create($userid)
2002-12-17 20:40:02 +01:00
{
/*
* Insertion dans la base
*/
2002-12-20 19:07:49 +01:00
$this->date = $this->db->idate($this->date);
$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)";
2002-12-22 16:11:07 +01:00
$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')";
2002-12-17 20:40:02 +01:00
$result = $this->db->query($sql);
if ($result)
{
2002-12-30 16:13:28 +01:00
return $this->db->last_insert_id();
2002-12-17 20:40:02 +01:00
}
else
{
2002-12-19 19:55:38 +01:00
print $this->db->error();
print "<h2><br>$sql<br></h2>";
return 0;
2002-12-17 20:40:02 +01:00
}
}
2002-12-27 22:54:03 +01:00
/*
* Mise <EFBFBD> jour
*
*
*/
Function update($userid)
{
$this->date = $this->db->idate($this->date);
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
2002-12-27 22:54:03 +01:00
$sql .= "amount = " . $this->amount;
$sql .= ",fk_paiement = ".$this->modepaiementid;
$sql .= ",prenom = '".$this->prenom ."'";
$sql .= ",nom='".$this->nom."'";
$sql .= ",societe='".$this->societe."'";
$sql .= ",adresse='".$this->adresse."'";
$sql .= ",cp='".$this->cp."'";
$sql .= ",ville='".$this->ville."'";
$sql .= ",pays='".$this->pays."'";
$sql .= ",public=".$this->public;
$sql .= ",fk_don_projet=".$this->projetid;
$sql .= ",note='".$this->commentaire."'";
$sql .= ",datedon='".$this->date."'";
$sql .= ",email='".$this->email."'";
2002-12-28 01:13:44 +01:00
$sql .= ",fk_statut=".$this->statut;
2002-12-27 22:54:03 +01:00
$sql .= " WHERE rowid = $this->id";
$result = $this->db->query($sql);
if ($result)
{
return 1;
}
else
{
print $this->db->error();
print "<h2><br>$sql<br></h2>";
return 0;
}
}
2002-12-19 19:55:38 +01:00
/*
* Suppression du don
*
*/
Function delete($rowid)
2002-12-20 19:07:49 +01:00
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."don WHERE rowid = $rowid AND fk_statut = 0;";
2002-12-19 19:55:38 +01:00
if ( $this->db->query( $sql) )
{
if ( $this->db->affected_rows() )
{
return 1;
}
else
{
return 0;
}
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
/*
* Fetch
*
*
*/
Function fetch($rowid)
{
2002-12-27 22:54:03 +01:00
$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";
$sql .= " FROM ".MAIN_DB_PREFIX."don as d, ".MAIN_DB_PREFIX."don_projet as p, ".MAIN_DB_PREFIX."c_paiement as cp";
2002-12-21 18:35:17 +01:00
$sql .= " WHERE p.rowid = d.fk_don_projet AND cp.id = d.fk_paiement AND d.rowid = $rowid";
2002-12-19 19:55:38 +01:00
if ( $this->db->query( $sql) )
{
if ($this->db->num_rows())
{
$obj = $this->db->fetch_object(0);
2002-12-27 21:21:44 +01:00
$this->id = $obj->rowid;
2002-12-21 18:35:17 +01:00
$this->date = $obj->datedon;
2002-12-22 16:11:07 +01:00
$this->prenom = stripslashes($obj->prenom);
2002-12-21 18:35:17 +01:00
$this->nom = stripslashes($obj->nom);
2002-12-22 16:11:07 +01:00
$this->societe = stripslashes($obj->societe);
2002-12-21 18:35:17 +01:00
$this->statut = $obj->fk_statut;
$this->adresse = stripslashes($obj->adresse);
$this->cp = stripslashes($obj->cp);
$this->ville = stripslashes($obj->ville);
2002-12-22 16:11:07 +01:00
$this->email = stripslashes($obj->email);
$this->pays = stripslashes($obj->pays);
2002-12-21 18:35:17 +01:00
$this->projet = $obj->projet;
2002-12-27 22:54:03 +01:00
$this->projetid = $obj->fk_don_projet;
2002-12-21 18:35:17 +01:00
$this->public = $obj->public;
$this->modepaiementid = $obj->fk_paiement;
$this->modepaiement = $obj->libelle;
$this->amount = $obj->amount;
$this->commentaire = stripslashes($obj->note);
2002-12-19 19:55:38 +01:00
}
}
else
{
print $this->db->error();
}
}
/*
* Suppression du don
*
*/
Function valid_promesse($rowid, $userid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 1, fk_user_valid = $userid WHERE rowid = $rowid AND fk_statut = 0;";
2002-12-19 19:55:38 +01:00
if ( $this->db->query( $sql) )
{
if ( $this->db->affected_rows() )
{
return 1;
}
else
{
return 0;
}
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
/*
* Class<EFBFBD> comme pay<EFBFBD>, le don a <EFBFBD>t<EFBFBD> recu
*
*/
2002-12-21 18:35:17 +01:00
Function set_paye($rowid, $modepaiement='')
2002-12-19 19:55:38 +01:00
{
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
2002-12-19 19:55:38 +01:00
2002-12-21 18:35:17 +01:00
if ($modepaiement)
{
$sql .= ", fk_paiement=$modepaiement";
}
$sql .= " WHERE rowid = $rowid AND fk_statut = 1;";
2002-12-19 19:55:38 +01:00
if ( $this->db->query( $sql) )
{
if ( $this->db->affected_rows() )
{
return 1;
}
else
{
return 0;
}
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
2002-12-26 11:21:15 +01:00
/*
2003-02-03 12:56:05 +01:00
*
2002-12-26 11:21:15 +01:00
*
*/
Function set_commentaire($rowid, $commentaire='')
{
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET note = '$commentaire'";
2002-12-26 11:21:15 +01:00
$sql .= " WHERE rowid = $rowid ;";
if ( $this->db->query( $sql) )
{
if ( $this->db->affected_rows() )
{
return 1;
}
else
{
return 0;
}
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
2002-12-19 19:55:38 +01:00
/*
* Class<EFBFBD> comme encaiss<EFBFBD>
*
*/
Function set_encaisse($rowid)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 3 WHERE rowid = $rowid AND fk_statut = 2;";
2002-12-19 19:55:38 +01:00
if ( $this->db->query( $sql) )
{
if ( $this->db->affected_rows() )
{
return 1;
}
else
{
return 0;
}
}
else
{
print "Err : ".$this->db->error();
return 0;
}
}
2002-12-21 19:39:38 +01:00
/*
2002-12-21 19:41:57 +01:00
* Somme des dons encaiss<EFBFBD>s
2002-12-21 19:39:38 +01:00
*/
Function sum_actual()
{
$sql = "SELECT sum(amount)";
$sql .= " FROM ".MAIN_DB_PREFIX."don";
2002-12-21 19:39:38 +01:00
$sql .= " WHERE fk_statut = 3";
if ( $this->db->query( $sql) )
{
$row = $this->db->fetch_row(0);
return $row[0];
}
}
2002-12-21 19:41:57 +01:00
/* Paiement recu en attente d'encaissement
*
2002-12-21 19:39:38 +01:00
*
*/
Function sum_pending()
{
$sql = "SELECT sum(amount)";
$sql .= " FROM ".MAIN_DB_PREFIX."don";
2002-12-21 19:39:38 +01:00
$sql .= " WHERE fk_statut = 2";
if ( $this->db->query( $sql) )
{
$row = $this->db->fetch_row(0);
return $row[0];
}
}
/*
* Somme des promesses de dons valid<EFBFBD>es
*
*/
Function sum_intent()
{
$sql = "SELECT sum(amount)";
$sql .= " FROM ".MAIN_DB_PREFIX."don";
2002-12-21 19:39:38 +01:00
$sql .= " WHERE fk_statut = 1";
if ( $this->db->query( $sql) )
{
$row = $this->db->fetch_row(0);
return $row[0];
}
}
2002-12-17 20:40:02 +01:00
}
?>