diff --git a/htdocs/compta/dons/card.php b/htdocs/compta/dons/card.php
index a4e68fbc4de..0c4c92cecd7 100644
--- a/htdocs/compta/dons/card.php
+++ b/htdocs/compta/dons/card.php
@@ -142,7 +142,6 @@ if ($action == 'add')
$object->societe = GETPOST("societe");
$object->address = GETPOST("address");
$object->amount = price2num(GETPOST("amount"));
- $object->town = GETPOST("town");
$object->zip = GETPOST("zipcode");
$object->town = GETPOST("town");
$object->country_id = GETPOST('country_id', 'int');
@@ -196,7 +195,7 @@ if ($action == 'set_cancel')
}
if ($action == 'set_paid')
{
- if ($object->set_paye($id, $modepaiement) >= 0)
+ if ($object->set_paye($id, $modepayment) >= 0)
{
header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
exit;
@@ -260,7 +259,7 @@ $formcompany = new FormCompany($db);
/* ************************************************************************** */
/* */
-/* Creation */
+/* Donation card in create mode */
/* */
/* ************************************************************************** */
@@ -353,7 +352,7 @@ if ($action == 'create')
/* ************************************************************ */
/* */
-/* Fiche don en mode edition */
+/* Donation card in edit mode */
/* */
/* ************************************************************ */
@@ -417,10 +416,10 @@ if (! empty($id) && $action == 'edit')
print "
';
- print '
';
+ print '
';
if ($object->statut == 0)
{
- print '
';
+ print '
';
}
- if (($object->statut == 0 || $object->statut == 1) && $resteapayer == 0 && $object->paye == 0)
+ if (($object->statut == 0 || $object->statut == 1) && $remaintopay == 0 && $object->paye == 0)
{
- print '
";
+ print '
";
}
- // TODO Gerer action emettre paiement
- if ($object->statut == 1 && $resteapayer > 0)
+ // Create payment
+ if ($object->statut == 1 && $object->paid == 0 && $user->rights->don->creer)
{
- print '
";
+ if ($remaintopay == 0)
+ {
+ print '
' . $langs->trans('DoPayment') . '
';
+ }
+ else
+ {
+ print '
';
+ }
}
- if ($object->statut == 1 && $resteapayer == 0 && $object->paye == 0)
+ /*
+ // Classify paid
+ if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0))
+ || ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $resteapayer == 0 && $user->rights->facture->paiement && empty($discount->id))
+ )
+ {
+ print '
';
+ }
+
+ // Emit payment
+ if ($object->statut == 1 && $object->paid == 0 && ((price2num($object->amount) > 0 && round($remaintopay) > 0)) && $user->rights->don->creer)
{
- print '
";
+ print '
';
}
+ */
+ // Classify 'paid'
+ if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
+ {
+ print '
";
+ }
+
if ($user->rights->don->supprimer)
{
- print '
";
+ print '
";
}
else
{
diff --git a/htdocs/compta/dons/class/don.class.php b/htdocs/compta/dons/class/don.class.php
index 88682b9d738..b677a3afad2 100644
--- a/htdocs/compta/dons/class/don.class.php
+++ b/htdocs/compta/dons/class/don.class.php
@@ -322,7 +322,7 @@ class Don extends CommonObject
$sql.= "datec";
$sql.= ", entity";
$sql.= ", amount";
- $sql.= ", fk_paiement";
+ $sql.= ", fk_payment";
$sql.= ", firstname";
$sql.= ", lastname";
$sql.= ", societe";
@@ -330,7 +330,7 @@ class Don extends CommonObject
$sql.= ", zip";
$sql.= ", town";
// $sql.= ", country"; -- Deprecated
- $sql.= ", fk_pays";
+ $sql.= ", fk_country";
$sql.= ", public";
$sql.= ", fk_don_projet";
$sql.= ", note_private";
@@ -406,14 +406,14 @@ class Don extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET ";
$sql .= "amount = " . price2num($this->amount);
- $sql .= ",fk_paiement = ".($this->modepaiementid?$this->modepaiementid:"null");
+ $sql .= ",fk_payment = ".($this->modepaymentid?$this->modepaymentid:"null");
$sql .= ",firstname = '".$this->db->escape($this->firstname)."'";
$sql .= ",lastname='".$this->db->escape($this->lastname)."'";
$sql .= ",societe='".$this->db->escape($this->societe)."'";
$sql .= ",address='".$this->db->escape($this->address)."'";
$sql .= ",zip='".$this->db->escape($this->zip)."'";
$sql .= ",town='".$this->db->escape($this->town)."'";
- $sql .= ",fk_pays = ".$this->country_id;
+ $sql .= ",fk_country = ".$this->country_id;
$sql .= ",public=".$this->public;
$sql .= ",fk_don_projet=".($this->fk_project>0?$this->fk_project:'null');
$sql .= ",note_private=".(!empty($this->note_private)?("'".$this->db->escape($this->note_private)."'"):"NULL");
@@ -497,14 +497,14 @@ class Don extends CommonObject
$sql = "SELECT d.rowid, d.datec, d.tms as datem, d.datedon,";
$sql.= " d.firstname, d.lastname, d.societe, d.amount, d.fk_statut, d.address, d.zip, d.town, ";
- $sql.= " d.fk_pays, d.public, d.amount, d.fk_paiement, d.note_private, d.note_public, cp.libelle, d.email, d.phone, ";
+ $sql.= " d.fk_country, d.country as country_olddata, d.public, d.amount, d.fk_payment, d.paid, d.note_private, d.note_public, cp.libelle, d.email, d.phone, ";
$sql.= " d.phone_mobile, d.fk_don_projet,";
$sql.= " p.title as project_label,";
$sql.= " c.code as country_code, c.label as country";
$sql.= " FROM ".MAIN_DB_PREFIX."don as d";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet as p ON p.rowid = d.fk_don_projet";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_paiement";
- $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_pays = c.rowid";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON cp.id = d.fk_payment";
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON d.fk_country = c.rowid";
$sql.= " WHERE d.rowid = ".$rowid." AND d.entity = ".$conf->entity;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
@@ -528,17 +528,19 @@ class Don extends CommonObject
$this->town = $obj->town;
$this->zip = $obj->zip;
$this->town = $obj->town;
- $this->country_id = $obj->country_id;
- $this->country_code = $obj->country_code;
- $this->country = $obj->country;
- $this->email = $obj->email;
+ $this->country_id = $obj->country_id;
+ $this->country_code = $obj->country_code;
+ $this->country = $obj->country;
+ $this->country_olddata= $obj->country_olddata;
+ $this->email = $obj->email;
$this->phone = $obj->phone;
$this->phone_mobile = $obj->phone_mobile;
$this->projet = $obj->project_label;
$this->fk_project = $obj->fk_don_projet;
$this->public = $obj->public;
- $this->modepaiementid = $obj->fk_paiement;
- $this->modepaiement = $obj->libelle;
+ $this->modepaymentid = $obj->fk_payment;
+ $this->modepayment = $obj->libelle;
+ $this->paid = $obj->paid;
$this->amount = $obj->amount;
$this->note_private = $obj->note_private;
$this->note_public = $obj->note_public;
@@ -597,7 +599,7 @@ class Don extends CommonObject
$sql = "UPDATE ".MAIN_DB_PREFIX."don SET fk_statut = 2";
if ($modepaiement)
{
- $sql .= ", fk_paiement=$modepaiement";
+ $sql .= ", fk_payment=$modepayment";
}
$sql .= " WHERE rowid = $rowid AND fk_statut = 1";
diff --git a/htdocs/compta/dons/class/paymentdonation.class.php b/htdocs/compta/dons/class/paymentdonation.class.php
new file mode 100644
index 00000000000..65d72fbfb52
--- /dev/null
+++ b/htdocs/compta/dons/class/paymentdonation.class.php
@@ -0,0 +1,607 @@
+
+ *
+ * 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 3 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, see
.
+ */
+
+/**
+ * \file htdocs/compta/dons/class/paymentdonation.class.php
+ * \ingroup Donation
+ * \brief File of class to manage payment of donations
+ */
+
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
+
+
+/** \class PaymentDonation
+ * \brief Class to manage payments of donations
+ */
+class PaymentDonation extends CommonObject
+{
+ public $element='payment_donation'; //!< Id that identify managed objects
+ public $table_element='payment_donation'; //!< Name of table without prefix where object is stored
+
+ var $id;
+ var $ref;
+
+ var $fk_donation;
+ var $datec='';
+ var $tms='';
+ var $datep='';
+ var $amount; // Total amount of payment
+ var $amounts=array(); // Array of amounts
+ var $fk_typepayment;
+ var $num_payment;
+ var $note;
+ var $fk_bank;
+ var $fk_user_creat;
+ var $fk_user_modif;
+
+ /**
+ * Constructor
+ *
+ * @param DoliDB $db Database handler
+ */
+ function __construct($db)
+ {
+ $this->db = $db;
+ }
+
+ /**
+ * Create payment of donation into database.
+ * Use this->amounts to have list of lines for the payment
+ *
+ * @param User $user User making payment
+ * @return int <0 if KO, id of payment if OK
+ */
+ function create($user)
+ {
+ global $conf, $langs;
+
+ $error=0;
+
+ $now=dol_now();
+
+ // Validate parameters
+ if (! $this->datepaye)
+ {
+ $this->error='ErrorBadValueForParameterCreatePaymentDonation';
+ return -1;
+ }
+
+ // Clean parameters
+ if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation);
+ if (isset($this->amount)) $this->amount=trim($this->amount);
+ if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment);
+ if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment);
+ if (isset($this->note)) $this->note=trim($this->note);
+ if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
+ if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
+ if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
+
+ $totalamount = 0;
+ foreach ($this->amounts as $key => $value) // How payment is dispatch
+ {
+ $newvalue = price2num($value,'MT');
+ $this->amounts[$key] = $newvalue;
+ $totalamount += $newvalue;
+ }
+ $totalamount = price2num($totalamount);
+
+ // Check parameters
+ if ($totalamount == 0) return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
+
+
+ $this->db->begin();
+
+ if ($totalamount != 0)
+ {
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_donation (fk_donation, datec, datep, amount,";
+ $sql.= " fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
+ $sql.= " VALUES ($this->chid, '".$this->db->idate($now)."',";
+ $sql.= " '".$this->db->idate($this->datepaye)."',";
+ $sql.= " ".$totalamount.",";
+ $sql.= " ".$this->paymenttype.", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note)."', ".$user->id.",";
+ $sql.= " 0)";
+
+ dol_syslog(get_class($this)."::create", LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_donation");
+ }
+ else
+ {
+ $error++;
+ }
+
+ }
+
+ if ($totalamount != 0 && ! $error)
+ {
+ $this->amount=$totalamount;
+ $this->total=$totalamount; // deprecated
+ $this->db->commit();
+ return $this->id;
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+ /**
+ * Load object in memory from database
+ *
+ * @param int $id Id object
+ * @return int <0 if KO, >0 if OK
+ */
+ function fetch($id)
+ {
+ global $langs;
+ $sql = "SELECT";
+ $sql.= " t.rowid,";
+ $sql.= " t.fk_donation,";
+ $sql.= " t.datec,";
+ $sql.= " t.tms,";
+ $sql.= " t.datep,";
+ $sql.= " t.amount,";
+ $sql.= " t.fk_typepayment,";
+ $sql.= " t.num_payment,";
+ $sql.= " t.note,";
+ $sql.= " t.fk_bank,";
+ $sql.= " t.fk_user_creat,";
+ $sql.= " t.fk_user_modif,";
+ $sql.= " pt.code as type_code, pt.libelle as type_libelle,";
+ $sql.= ' b.fk_account';
+ $sql.= " FROM (".MAIN_DB_PREFIX."c_paiement as pt, ".MAIN_DB_PREFIX."payment_donation as t)";
+ $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
+ $sql.= " WHERE t.rowid = ".$id." AND t.fk_typepayment = pt.id";
+
+ dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ if ($this->db->num_rows($resql))
+ {
+ $obj = $this->db->fetch_object($resql);
+
+ $this->id = $obj->rowid;
+ $this->ref = $obj->rowid;
+
+ $this->fk_donation = $obj->fk_donation;
+ $this->datec = $this->db->jdate($obj->datec);
+ $this->tms = $this->db->jdate($obj->tms);
+ $this->datep = $this->db->jdate($obj->datep);
+ $this->amount = $obj->amount;
+ $this->fk_typepayment = $obj->fk_typepayment;
+ $this->num_payment = $obj->num_payment;
+ $this->note = $obj->note;
+ $this->fk_bank = $obj->fk_bank;
+ $this->fk_user_creat = $obj->fk_user_creat;
+ $this->fk_user_modif = $obj->fk_user_modif;
+
+ $this->type_code = $obj->type_code;
+ $this->type_libelle = $obj->type_libelle;
+
+ $this->bank_account = $obj->fk_account;
+ $this->bank_line = $obj->fk_bank;
+ }
+ $this->db->free($resql);
+
+ return 1;
+ }
+ else
+ {
+ $this->error="Error ".$this->db->lasterror();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Update database
+ *
+ * @param User $user User that modify
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function update($user=null, $notrigger=0)
+ {
+ global $conf, $langs;
+ $error=0;
+
+ // Clean parameters
+
+ if (isset($this->fk_donation)) $this->fk_donation=trim($this->fk_donation);
+ if (isset($this->amount)) $this->amount=trim($this->amount);
+ if (isset($this->fk_typepayment)) $this->fk_typepayment=trim($this->fk_typepayment);
+ if (isset($this->num_payment)) $this->num_payment=trim($this->num_payment);
+ if (isset($this->note)) $this->note=trim($this->note);
+ if (isset($this->fk_bank)) $this->fk_bank=trim($this->fk_bank);
+ if (isset($this->fk_user_creat)) $this->fk_user_creat=trim($this->fk_user_creat);
+ if (isset($this->fk_user_modif)) $this->fk_user_modif=trim($this->fk_user_modif);
+
+
+
+ // Check parameters
+ // Put here code to add control on parameters values
+
+ // Update request
+ $sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET";
+
+ $sql.= " fk_donation=".(isset($this->fk_donation)?$this->fk_donation:"null").",";
+ $sql.= " datec=".(dol_strlen($this->datec)!=0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
+ $sql.= " tms=".(dol_strlen($this->tms)!=0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
+ $sql.= " datep=".(dol_strlen($this->datep)!=0 ? "'".$this->db->idate($this->datep)."'" : 'null').",";
+ $sql.= " amount=".(isset($this->amount)?$this->amount:"null").",";
+ $sql.= " fk_typepayment=".(isset($this->fk_typepayment)?$this->fk_typepayment:"null").",";
+ $sql.= " num_payment=".(isset($this->num_payment)?"'".$this->db->escape($this->num_payment)."'":"null").",";
+ $sql.= " note=".(isset($this->note)?"'".$this->db->escape($this->note)."'":"null").",";
+ $sql.= " fk_bank=".(isset($this->fk_bank)?$this->fk_bank:"null").",";
+ $sql.= " fk_user_creat=".(isset($this->fk_user_creat)?$this->fk_user_creat:"null").",";
+ $sql.= " fk_user_modif=".(isset($this->fk_user_modif)?$this->fk_user_modif:"null")."";
+
+
+ $sql.= " WHERE rowid=".$this->id;
+
+ $this->db->begin();
+
+ dol_syslog(get_class($this)."::update", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Uncomment this and change MYOBJECT to your own tag if you
+ // want this action call a trigger.
+
+ //// Call triggers
+ //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ //$interface=new Interfaces($this->db);
+ //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
+ //if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ //// End call triggers
+ }
+ }
+
+ // Commit or rollback
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+
+ /**
+ * Delete object in database
+ *
+ * @param User $user User that delete
+ * @param int $notrigger 0=launch triggers after, 1=disable triggers
+ * @return int <0 if KO, >0 if OK
+ */
+ function delete($user, $notrigger=0)
+ {
+ global $conf, $langs;
+ $error=0;
+
+ $this->db->begin();
+
+ if (! $error)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
+ $sql.= " WHERE type='payment_sc' AND url_id=".$this->id;
+
+ dol_syslog(get_class($this)."::delete", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ }
+
+ if (! $error)
+ {
+ $sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation";
+ $sql.= " WHERE rowid=".$this->id;
+
+ dol_syslog(get_class($this)."::delete", LOG_DEBUG);
+ $resql = $this->db->query($sql);
+ if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
+ }
+
+ if (! $error)
+ {
+ if (! $notrigger)
+ {
+ // Uncomment this and change MYOBJECT to your own tag if you
+ // want this action call a trigger.
+
+ //// Call triggers
+ //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
+ //$interface=new Interfaces($this->db);
+ //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
+ //if ($result < 0) { $error++; $this->errors=$interface->errors; }
+ //// End call triggers
+ }
+ }
+
+ // Commit or rollback
+ if ($error)
+ {
+ foreach($this->errors as $errmsg)
+ {
+ dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
+ $this->error.=($this->error?', '.$errmsg:$errmsg);
+ }
+ $this->db->rollback();
+ return -1*$error;
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
+ }
+
+
+
+ /**
+ * Load an object from its id and create a new one in database
+ *
+ * @param int $fromid Id of object to clone
+ * @return int New id of clone
+ */
+ function createFromClone($fromid)
+ {
+ global $user,$langs;
+
+ $error=0;
+
+ $object=new PaymentSocialContribution($this->db);
+
+ $object->context['createfromclone'] = 'createfromclone';
+
+ $this->db->begin();
+
+ // Load source object
+ $object->fetch($fromid);
+ $object->id=0;
+ $object->statut=0;
+
+ // Clear fields
+ // ...
+
+ // Create clone
+ $result=$object->create($user);
+
+ // Other options
+ if ($result < 0)
+ {
+ $this->error=$object->error;
+ $error++;
+ }
+
+ if (! $error)
+ {
+
+
+
+ }
+
+ unset($this->context['createfromclone']);
+
+ // End
+ if (! $error)
+ {
+ $this->db->commit();
+ return $object->id;
+ }
+ else
+ {
+ $this->db->rollback();
+ return -1;
+ }
+ }
+
+
+ /**
+ * Initialise an instance with random values.
+ * Used to build previews or test instances.
+ * id must be 0 if object instance is a specimen.
+ *
+ * @return void
+ */
+ function initAsSpecimen()
+ {
+ $this->id=0;
+
+ $this->fk_donation='';
+ $this->datec='';
+ $this->tms='';
+ $this->datep='';
+ $this->amount='';
+ $this->fk_typepayment='';
+ $this->num_payment='';
+ $this->note='';
+ $this->fk_bank='';
+ $this->fk_user_creat='';
+ $this->fk_user_modif='';
+
+
+ }
+
+
+ /**
+ * Add record into bank for payment with links between this bank record and invoices of payment.
+ * All payment properties must have been set first like after a call to create().
+ *
+ * @param User $user Object of user making payment
+ * @param string $mode 'payment_sc'
+ * @param string $label Label to use in bank record
+ * @param int $accountid Id of bank account to do link with
+ * @param string $emetteur_nom Name of transmitter
+ * @param string $emetteur_banque Name of bank
+ * @return int <0 if KO, >0 if OK
+ */
+ function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque)
+ {
+ global $conf;
+
+ $error=0;
+
+ if (! empty($conf->banque->enabled))
+ {
+ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+ $acc = new Account($this->db);
+ $acc->fetch($accountid);
+
+ $total=$this->total;
+ if ($mode == 'payment_sc') $total=-$total;
+
+ // Insert payment into llx_bank
+ $bank_line_id = $acc->addline(
+ $this->datepaye,
+ $this->paymenttype, // Payment mode id or code ("CHQ or VIR for example")
+ $label,
+ $total,
+ $this->num_payment,
+ '',
+ $user,
+ $emetteur_nom,
+ $emetteur_banque
+ );
+
+ // Mise a jour fk_bank dans llx_paiement.
+ // On connait ainsi le paiement qui a genere l'ecriture bancaire
+ if ($bank_line_id > 0)
+ {
+ $result=$this->update_fk_bank($bank_line_id);
+ if ($result <= 0)
+ {
+ $error++;
+ dol_print_error($this->db);
+ }
+
+ // Add link 'payment', 'payment_supplier', 'payment_sc' in bank_url between payment and bank transaction
+ $url='';
+ if ($mode == 'payment_sc') $url=DOL_URL_ROOT.'/compta/payment_sc/card.php?id=';
+ if ($url)
+ {
+ $result=$acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
+ if ($result <= 0)
+ {
+ $error++;
+ dol_print_error($this->db);
+ }
+ }
+
+ // Add link 'company' in bank_url between invoice and bank transaction (for each invoice concerned by payment)
+ $linkaddedforthirdparty=array();
+ foreach ($this->amounts as $key => $value)
+ {
+ if ($mode == 'payment_sc')
+ {
+ $socialcontrib = new ChargeSociales($this->db);
+ $socialcontrib->fetch($key);
+ $result=$acc->add_url_line($bank_line_id, $socialcontrib->id, DOL_URL_ROOT.'/compta/charges.php?id=', $socialcontrib->type_libelle.(($socialcontrib->lib && $socialcontrib->lib!=$socialcontrib->type_libelle)?' ('.$socialcontrib->lib.')':''),'sc');
+ if ($result <= 0) dol_print_error($this->db);
+ }
+ }
+ }
+ else
+ {
+ $this->error=$acc->error;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ return 1;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+
+
+ /**
+ * Mise a jour du lien entre le paiement de charge et la ligne dans llx_bank generee
+ *
+ * @param int $id_bank Id if bank
+ * @return int >0 if OK, <=0 if KO
+ */
+ function update_fk_bank($id_bank)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET fk_bank = ".$id_bank." WHERE rowid = ".$this->id;
+
+ dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ return 1;
+ }
+ else
+ {
+ $this->error=$this->db->error();
+ return 0;
+ }
+ }
+
+ /**
+ * Return clicable name (with picto eventually)
+ *
+ * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
+ * @param int $maxlen Longueur max libelle
+ * @return string Chaine avec URL
+ */
+ function getNomUrl($withpicto=0,$maxlen=0)
+ {
+ global $langs;
+
+ $result='';
+
+ if (empty($this->ref)) $this->ref=$this->lib;
+ $label = $langs->trans("ShowPayment").': '.$this->ref;
+
+ if (!empty($this->id))
+ {
+ $link = '
';
+ $linkend='';
+
+ if ($withpicto) $result.=($link.img_object($label, 'payment', 'class="classfortooltip"').$linkend.' ');
+ if ($withpicto && $withpicto != 2) $result.=' ';
+ if ($withpicto != 2) $result.=$link.($maxlen?dol_trunc($this->ref,$maxlen):$this->ref).$linkend;
+ }
+
+ return $result;
+ }
+}
+
+
diff --git a/htdocs/compta/dons/payment.php b/htdocs/compta/dons/payment.php
new file mode 100644
index 00000000000..12b0296ca5a
--- /dev/null
+++ b/htdocs/compta/dons/payment.php
@@ -0,0 +1,313 @@
+
+ *
+ * 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 3 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, see
.
+ */
+
+/**
+ * \file htdocs/compta/dons/payment.php
+ * \ingroup Donation
+ * \brief Page to add payment of a donation
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/don.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/dons/class/paymentdonation.class.php';
+require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
+
+$langs->load("bills");
+
+$chid=GETPOST("rowid");
+$action=GETPOST('action');
+$amounts = array();
+
+// Security check
+$socid=0;
+if ($user->societe_id > 0)
+{
+ $socid = $user->societe_id;
+}
+
+
+/*
+ * Actions
+ */
+
+if ($action == 'add_payment')
+{
+ $error=0;
+
+ if ($_POST["cancel"])
+ {
+ $loc = DOL_URL_ROOT.'/compta/dons/card.php?rowid='.$chid;
+ header("Location: ".$loc);
+ exit;
+ }
+
+ $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
+
+ if (! $_POST["paymenttype"] > 0)
+ {
+ $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("PaymentMode"));
+ $error++;
+ }
+ if ($datepaye == '')
+ {
+ $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("Date"));
+ $error++;
+ }
+ if (! empty($conf->banque->enabled) && ! $_POST["accountid"] > 0)
+ {
+ $mesg = $langs->trans("ErrorFieldRequired",$langs->transnoentities("AccountToCredit"));
+ $error++;
+ }
+
+ if (! $error)
+ {
+ $paymentid = 0;
+
+ // Read possible payments
+ foreach ($_POST as $key => $value)
+ {
+ if (substr($key,0,7) == 'amount_')
+ {
+ $other_chid = substr($key,7);
+ $amounts[$other_chid] = price2num($_POST[$key]);
+ }
+ }
+
+ if (count($amounts) <= 0)
+ {
+ $error++;
+ $errmsg='ErrorNoPaymentDefined';
+ }
+
+ if (! $error)
+ {
+ $db->begin();
+
+ // Create a line of payments
+ $payment = new PaymentDonation($db);
+ $payment->chid = $chid;
+ $payment->datepaye = $datepaye;
+ $payment->amounts = $amounts; // Tableau de montant
+ $payment->paymenttype = $_POST["paymenttype"];
+ $payment->num_payment = $_POST["num_payment"];
+ $payment->note = $_POST["note"];
+
+ if (! $error)
+ {
+ $paymentid = $payment->create($user);
+ if ($paymentid < 0)
+ {
+ $errmsg=$payment->error;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ $result=$payment->addPaymentToBank($user,'payment_donation','(DonationPayment)',$_POST['accountid'],'','');
+ if (! $result > 0)
+ {
+ $errmsg=$payment->error;
+ $error++;
+ }
+ }
+
+ if (! $error)
+ {
+ $db->commit();
+ $loc = DOL_URL_ROOT.'/compta/dons/card.php?rowid='.$chid;
+ header('Location: '.$loc);
+ exit;
+ }
+ else
+ {
+ $db->rollback();
+ }
+ }
+ }
+
+ $_GET["action"]='create';
+}
+
+
+/*
+ * View
+ */
+
+llxHeader();
+
+$form=new Form($db);
+
+
+// Form to create donation payment
+if (GETPOST("action") == 'create')
+{
+
+ $don = new Don($db);
+ $don->fetch($chid);
+
+ $total = $don->amount;
+
+ print_fiche_titre($langs->trans("DoPayment"));
+ print "
\n";
+
+ if ($mesg)
+ {
+ print "
$mesg
";
+ }
+
+ print '
\n";
+}
+
+
+$db->close();
+
+llxFooter();
diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
index d2520973275..c92c78014cb 100755
--- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
+++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql
@@ -372,4 +372,22 @@ ALTER TABLE llx_societe_extrafields DROP INDEX idx_societe_extrafields;
ALTER TABLE llx_societe_extrafields ADD UNIQUE INDEX uk_societe_extrafields (fk_object);
-- Module Donation
-ALTER TABLE llx_don ADD COLUMN fk_pays integer NOT NULL after country;
+ALTER TABLE llx_don ADD COLUMN fk_country integer NOT NULL after country;
+ALTER TABLE llx_don CHANGE COLUMN fk_paiement fk_payment integer;
+ALTER TABLE llx_don ADD COLUMN paid smallint default 0 NOT NULL after fk_payment;
+
+create table llx_payment_donation
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ fk_donation integer,
+ datec datetime, -- date de creation
+ tms timestamp,
+ datep datetime, -- payment date
+ amount real DEFAULT 0,
+ fk_typepayment integer NOT NULL,
+ num_payment varchar(50),
+ note text,
+ fk_bank integer NOT NULL,
+ fk_user_creat integer, -- creation user
+ fk_user_modif integer -- last modification user
+)ENGINE=innodb;
diff --git a/htdocs/install/mysql/tables/llx_don.sql b/htdocs/install/mysql/tables/llx_don.sql
index bf434e11518..d4e03c55d0c 100644
--- a/htdocs/install/mysql/tables/llx_don.sql
+++ b/htdocs/install/mysql/tables/llx_don.sql
@@ -2,6 +2,7 @@
-- Copyright (C) 2001-2002 Rodolphe Quiedeville
-- Copyright (C) 2009 Regis Houssin
-- Copyright (C) 2011 Laurent Destailleur
+-- Copyright (C) 2015 Alexandre Spangaro
--
-- 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
@@ -29,15 +30,16 @@ create table llx_don
datec datetime, -- date de creation de l'enregistrement
datedon datetime, -- date du don/promesse
amount real DEFAULT 0,
- fk_paiement integer,
+ fk_payment integer,
+ paid smallint default 0 NOT NULL,
firstname varchar(50),
lastname varchar(50),
societe varchar(50),
address text,
zip varchar(30),
town varchar(50),
- country varchar(50), -- Deprecated - Replace with fk_pays
- fk_pays integer NOT NULL,
+ country varchar(50), -- Deprecated - Replace with fk_country
+ fk_country integer NOT NULL,
email varchar(255),
phone varchar(24),
phone_mobile varchar(24),
diff --git a/htdocs/install/mysql/tables/llx_payment_donation.sql b/htdocs/install/mysql/tables/llx_payment_donation.sql
new file mode 100644
index 00000000000..0389a59e06e
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_payment_donation.sql
@@ -0,0 +1,33 @@
+-- ===================================================================
+-- Copyright (C) 2015 Alexandre Spangaro
+--
+-- 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 3 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, see .
+--
+-- ===================================================================
+
+create table llx_payment_donation
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ fk_donation integer,
+ datec datetime, -- date de creation
+ tms timestamp,
+ datep datetime, -- payment date
+ amount real DEFAULT 0,
+ fk_typepayment integer NOT NULL,
+ num_payment varchar(50),
+ note text,
+ fk_bank integer NOT NULL,
+ fk_user_creat integer, -- creation user
+ fk_user_modif integer -- last modification user
+)ENGINE=innodb;