Add payment on donation

This commit is contained in:
aspangaro 2015-03-18 05:07:32 +01:00
parent 03bf12bdc0
commit 4e83952485
7 changed files with 1041 additions and 41 deletions

View File

@ -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 "<tr><td>".$langs->trans("PaymentMode")."</td><td>\n";
if ($object->modepaiementid) $selected = $object->modepaiementid;
if ($object->modepaymentid) $selected = $object->modepaymentid;
else $selected = '';
$form->select_types_paiements($selected, 'modepaiement', 'CRDT', 0, 1);
$form->select_types_paiements($selected, 'modepayment', 'CRDT', 0, 1);
print "</td></tr>\n";
print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
@ -453,7 +452,7 @@ if (! empty($id) && $action == 'edit')
/* ************************************************************ */
/* */
/* Fiche don en mode visu */
/* Donation card in view mode */
/* */
/* ************************************************************ */
if (! empty($id) && $action != 'edit')
@ -503,8 +502,12 @@ if (! empty($id) && $action != 'edit')
{
$img=picto_from_langcode($object->country_code);
print ($img?$img.' ':'');
print $object->country;
}
print $object->country;
else
{
print $object->country_olddata;
}
print '</td></tr>';
// EMail
@ -512,7 +515,7 @@ if (! empty($id) && $action != 'edit')
// Payment mode
print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
$form->form_modes_reglement(null, $object->modepaiementid,'none');
$form->form_modes_reglement(null, $object->modepaymentid,'none');
print "</td></tr>\n";
print "<tr>".'<td>'.$langs->trans("Status").'</td><td>'.$object->getLibStatut(4).'</td></tr>';
@ -532,41 +535,63 @@ if (! empty($id) && $action != 'edit')
print "</div>";
// TODO Gerer action emettre paiement
$resteapayer = 0;
$remaintopay = $object->amount - $totalpaid;
/**
* Barre d'actions
* Actions buttons
*/
print '<div class="tabsAction">';
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?action=edit&rowid='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
if ($object->statut == 0)
{
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>';
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=valid_promesse">'.$langs->trans("ValidPromess").'</a></div>';
}
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 '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>";
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_cancel">'.$langs->trans("ClassifyCanceled")."</a></div>";
}
// 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 '<div class="inline-block divButAction"><a class="butAction" href="paiement.php?rowid='.$object->id.'&action=create">'.$langs->trans("DoPayment")."</a></div>";
if ($remaintopay == 0)
{
print '<div class="inline-block divButAction"><span class="butActionRefused" title="' . $langs->trans("DisabledBecauseRemainderToPayIsZero") . '">' . $langs->trans('DoPayment') . '</span></div>';
}
else
{
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/dons/payment.php?rowid=' . $object->id . '&amp;action=create">' . $langs->trans('DoPayment') . '</a></div>';
}
}
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 '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?facid='.$object->id.'&amp;action=paid">'.$langs->trans('ClassifyPaid').'</a></div>';
}
// Emit payment
if ($object->statut == 1 && $object->paid == 0 && ((price2num($object->amount) > 0 && round($remaintopay) > 0)) && $user->rights->don->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="card.php?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/dons/payment.php?rowid='.$object->id.'&action=create">'.$langs->trans("DoPayment").'</a></div>';
}
*/
// Classify 'paid'
if ($object->statut == 1 && round($remaintopay) == 0 && $object->paid == 0 && $user->rights->don->creer)
{
print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=set_paid">'.$langs->trans("ClassifyPaid")."</a></div>";
}
if ($user->rights->don->supprimer)
{
print '<div class="inline-block divButAction"><a class="butActionDelete" href="card.php?rowid='.$object->id.'&action=delete">'.$langs->trans("Delete")."</a></div>";
print '<div class="inline-block divButAction"><a class="butActionDelete" href="' . $_SERVER["PHP_SELF"] . '?rowid='.$object->id.'&action=delete">'.$langs->trans("Delete")."</a></div>";
}
else
{

View File

@ -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";

View File

@ -0,0 +1,607 @@
<?php
/* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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 = '<a href="'.DOL_URL_ROOT.'/compta/payment_sc/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend='</a>';
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;
}
}

View File

@ -0,0 +1,313 @@
<?php
/* Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
*
* 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 <http://www.gnu.org/licenses/>.
*/
/**
* \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 "<br>\n";
if ($mesg)
{
print "<div class=\"error\">$mesg</div>";
}
print '<form name="add_payment" action="'.$_SERVER['PHP_SELF'].'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="rowid" value="'.$chid.'">';
print '<input type="hidden" name="chid" value="'.$chid.'">';
print '<input type="hidden" name="action" value="add_payment">';
print '<table cellspacing="0" class="border" width="100%" cellpadding="2">';
print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Donation").'</td>';
print '<tr><td>'.$langs->trans("Ref").'</td><td colspan="2"><a href="'.DOL_URL_ROOT.'/compta/dons/card.php?rowid='.$chid.'">'.$chid.'</a></td></tr>';
print '<tr><td>'.$langs->trans("Date")."</td><td colspan=\"2\">".dol_print_date($don->date,'day')."</td></tr>\n";
print '<tr><td>'.$langs->trans("Amount")."</td><td colspan=\"2\">".price($don->amount,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
$sql = "SELECT sum(p.amount) as total";
$sql.= " FROM ".MAIN_DB_PREFIX."payment_donation as p";
$sql.= " WHERE p.fk_donation = ".$chid;
$resql = $db->query($sql);
if ($resql)
{
$obj=$db->fetch_object($resql);
$sumpaid = $obj->total;
$db->free();
}
print '<tr><td>'.$langs->trans("AlreadyPaid").'</td><td colspan="2">'.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
print '<tr><td valign="top">'.$langs->trans("RemainderToPay").'</td><td colspan="2">'.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'</td></tr>';
print '<tr class="liste_titre">';
print "<td colspan=\"3\">".$langs->trans("Payment").'</td>';
print '</tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("Date").'</td><td colspan="2">';
$datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]);
$datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0;
$form->select_date($datepayment,'','','','',"add_payment",1,1);
print "</td>";
print '</tr>';
print '<tr><td class="fieldrequired">'.$langs->trans("PaymentMode").'</td><td colspan="2">';
$form->select_types_paiements(isset($_POST["paymenttype"])?$_POST["paymenttype"]:$don->paymenttype, "paymenttype");
print "</td>\n";
print '</tr>';
print '<tr>';
print '<td class="fieldrequired">'.$langs->trans('AccountToDebit').'</td>';
print '<td colspan="2">';
$form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$don->accountid, "accountid", 0, '',1); // Show opend bank account list
print '</td></tr>';
// Number
print '<tr><td>'.$langs->trans('Numero');
print ' <em>('.$langs->trans("ChequeOrTransferNumber").')</em>';
print '</td>';
print '<td colspan="2"><input name="num_payment" type="text" value="'.GETPOST('num_payment').'"></td></tr>'."\n";
print '<tr>';
print '<td valign="top">'.$langs->trans("Comments").'</td>';
print '<td valign="top" colspan="2"><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_3.'"></textarea></td>';
print '</tr>';
print '</table>';
print '<br>';
/*
* Autres charges impayees
*/
$num = 1;
$i = 0;
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td align="right">'.$langs->trans("Amount").'</td>';
print '<td align="right">'.$langs->trans("AlreadyPaid").'</td>';
print '<td align="right">'.$langs->trans("RemainderToPay").'</td>';
print '<td align="center">'.$langs->trans("Amount").'</td>';
print "</tr>\n";
$var=true;
$total=0;
$totalrecu=0;
while ($i < $num)
{
$objp = $don;
$var=!$var;
print "<tr ".$bc[$var].">";
print '<td align="right">'.price($objp->amount)."</td>";
print '<td align="right">'.price($sumpaid)."</td>";
print '<td align="right">'.price($objp->amount - $sumpaid)."</td>";
print '<td align="center">';
if ($sumpaid < $objp->amount)
{
$namef = "amount_".$objp->id;
print '<input type="text" size="8" name="'.$namef.'">';
}
else
{
print '-';
}
print "</td>";
print "</tr>\n";
$total+=$objp->total;
$total_ttc+=$objp->total_ttc;
$totalrecu+=$objp->am;
$i++;
}
if ($i > 1)
{
// Print total
print "<tr ".$bc[!$var].">";
print '<td colspan="2" align="left">'.$langs->trans("Total").':</td>';
print "<td align=\"right\"><b>".price($total_ttc)."</b></td>";
print "<td align=\"right\"><b>".price($totalrecu)."</b></td>";
print "<td align=\"right\"><b>".price($total_ttc - $totalrecu)."</b></td>";
print '<td align="center">&nbsp;</td>';
print "</tr>\n";
}
print "</table>";
print '<br><div class="center">';
print '<input type="submit" class="button" name="save" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
print '</div>';
print "</form>\n";
}
$db->close();
llxFooter();

View File

@ -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;

View File

@ -2,6 +2,7 @@
-- Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
-- Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
-- Copyright (C) 2011 Laurent Destailleur <eldy@users.sourceforge.net>
-- Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
--
-- 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),

View File

@ -0,0 +1,33 @@
-- ===================================================================
-- Copyright (C) 2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===================================================================
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;