dolibarr/htdocs/don/class/paymentdonation.class.php

702 lines
18 KiB
PHP
Raw Normal View History

2015-03-18 05:07:32 +01:00
<?php
2019-01-28 21:39:22 +01:00
/* Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
2015-03-18 05:07:32 +01:00
*
* 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
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2015-03-18 05:07:32 +01:00
*/
/**
2015-03-25 22:37:14 +01:00
* \file htdocs/don/class/paymentdonation.class.php
2015-03-18 05:07:32 +01:00
* \ingroup Donation
* \brief File of class to manage payment of donations
*/
require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
2016-12-18 13:04:24 +01:00
/**
* Class to manage payments of donations
2015-03-18 05:07:32 +01:00
*/
class PaymentDonation extends CommonObject
{
2018-08-23 18:35:45 +02:00
/**
* @var string ID to identify managed object
*/
public $element = 'payment_donation';
2018-08-28 08:33:02 +02:00
2018-08-22 18:48:53 +02:00
/**
* @var string Name of table without prefix where object is stored
*/
public $table_element = 'payment_donation';
2018-08-28 08:33:02 +02:00
/**
2018-09-05 12:21:13 +02:00
* @var string String with name of icon for myobject. Must be the part after the 'object_' into object_myobject.png
*/
public $picto = 'payment';
2017-06-09 09:25:15 +02:00
2018-09-01 22:55:10 +02:00
/**
* @var int ID
*/
2016-12-18 13:04:24 +01:00
public $rowid;
2018-10-10 09:20:50 +02:00
/**
* @var int ID
*/
2016-12-18 13:04:24 +01:00
public $fk_donation;
2018-10-10 09:20:50 +02:00
public $datec = '';
2020-05-02 15:18:59 +02:00
public $tms = '';
2020-05-02 15:18:59 +02:00
public $datep = '';
2020-05-02 15:18:59 +02:00
public $amount; // Total amount of payment
public $amounts = array(); // Array of amounts
2022-04-08 15:15:55 +02:00
public $fk_typepayment; // Payment mode ID
public $paymenttype; // Payment mode ID
2020-05-02 15:18:59 +02:00
2016-12-18 13:04:24 +01:00
public $num_payment;
2018-10-10 09:20:50 +02:00
/**
* @var int ID
*/
2016-12-18 13:04:24 +01:00
public $fk_bank;
2018-10-10 09:20:50 +02:00
/**
* @var int ID
*/
2016-12-18 13:04:24 +01:00
public $fk_user_creat;
2018-10-10 09:20:50 +02:00
/**
* @var int ID
*/
2016-12-18 13:04:24 +01:00
public $fk_user_modif;
2015-03-18 05:07:32 +01:00
/**
* @deprecated
2019-04-08 16:04:15 +02:00
* @see $amount, $amounts
*/
2016-12-18 13:04:24 +01:00
public $total;
public $type_code;
public $type_label;
/**
* @var string Id of external payment mode
*/
public $ext_payment_id;
/**
* @var string Name of external payment mode
*/
public $ext_payment_site;
2015-03-18 05:07:32 +01:00
/**
* Constructor
*
* @param DoliDB $db Database handler
*/
2019-02-25 20:35:59 +01:00
public function __construct($db)
2015-03-18 05:07:32 +01:00
{
$this->db = $db;
}
/**
* Create payment of donation into database.
* Use this->amounts to have list of lines for the payment
*
2018-01-05 04:31:48 +01:00
* @param User $user User making payment
2018-08-28 08:33:02 +02:00
* @param bool $notrigger false=launch triggers after, true=disable triggers
2018-01-05 04:31:48 +01:00
* @return int <0 if KO, id of payment if OK
2015-03-18 05:07:32 +01:00
*/
2019-02-25 20:35:59 +01:00
public function create($user, $notrigger = false)
2015-03-18 05:07:32 +01:00
{
global $conf, $langs;
$error = 0;
2015-03-18 05:07:32 +01:00
$now = dol_now();
2015-03-18 05:07:32 +01:00
// Validate parameters
2021-02-25 22:18:34 +01:00
if (!$this->datepaid) {
$this->error = 'ErrorBadValueForParameterCreatePaymentDonation';
2015-03-18 05:07:32 +01:00
return -1;
}
// Clean parameters
if (isset($this->chid)) {
$this->chid = (int) $this->chid;
2021-04-22 17:04:35 +02:00
} elseif (isset($this->fk_donation)) {
// NOTE : The property used in INSERT for fk_donation is not fk_donation but chid
// (keep priority to chid property)
$this->chid = (int) $this->fk_donation;
}
2021-02-25 22:18:34 +01:00
if (isset($this->fk_donation)) {
$this->fk_donation = (int) $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_public)) {
$this->note_public = trim($this->note_public);
}
if (isset($this->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
2015-03-18 05:07:32 +01:00
$totalamount = 0;
2021-02-25 22:18:34 +01:00
foreach ($this->amounts as $key => $value) { // How payment is dispatch
$newvalue = price2num($value, 'MT');
$this->amounts[$key] = $newvalue;
$totalamount += $newvalue;
}
$totalamount = price2num($totalamount);
2015-03-18 05:07:32 +01:00
// Check parameters
2021-02-25 22:18:34 +01:00
if ($totalamount == 0) {
return -1; // On accepte les montants negatifs pour les rejets de prelevement mais pas null
}
2015-03-18 05:07:32 +01:00
$this->db->begin();
2021-02-25 22:18:34 +01:00
if ($totalamount != 0) {
2015-03-18 05:07:32 +01:00
$sql = "INSERT INTO ".MAIN_DB_PREFIX."payment_donation (fk_donation, datec, datep, amount,";
$sql .= " fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
$sql .= " fk_user_creat, fk_bank)";
$sql .= " VALUES ($this->chid, '".$this->db->idate($now)."',";
$sql .= " '".$this->db->idate($this->datepaid)."',";
2021-06-14 13:51:09 +02:00
$sql .= " ".price2num($totalamount).",";
$sql .= " ".((int) $this->paymenttype).", '".$this->db->escape($this->num_payment)."', '".$this->db->escape($this->note_public)."', ";
$sql .= " ".($this->ext_payment_id ? "'".$this->db->escape($this->ext_payment_id)."'" : "null").", ".($this->ext_payment_site ? "'".$this->db->escape($this->ext_payment_site)."'" : "null").",";
$sql .= " ".$user->id.", 0)";
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql = $this->db->query($sql);
2021-02-25 22:18:34 +01:00
if ($resql) {
2015-03-18 05:07:32 +01:00
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."payment_donation");
2018-01-05 04:31:48 +01:00
$this->ref = $this->id;
2020-05-21 15:05:19 +02:00
} else {
2015-03-18 05:07:32 +01:00
$error++;
}
2018-01-05 04:31:48 +01:00
}
2015-03-18 05:07:32 +01:00
2021-02-25 22:18:34 +01:00
if (!$error && !$notrigger) {
2018-01-05 04:31:48 +01:00
// Call triggers
$result = $this->call_trigger('DONATION_PAYMENT_CREATE', $user);
2021-02-25 22:18:34 +01:00
if ($result < 0) {
$error++;
}
2018-01-05 04:31:48 +01:00
// End call triggers
2015-03-18 05:07:32 +01:00
}
2021-02-25 22:18:34 +01:00
if ($totalamount != 0 && !$error) {
$this->amount = $totalamount;
$this->total = $totalamount; // deprecated
$this->db->commit();
2015-03-18 05:07:32 +01:00
return $this->id;
2020-05-21 15:05:19 +02:00
} else {
$this->error = $this->db->error();
2015-03-18 05:07:32 +01:00
$this->db->rollback();
return -1;
}
}
/**
* Load object in memory from database
*
* @param int $id Id object
* @return int <0 if KO, >0 if OK
*/
2019-02-25 20:35:59 +01:00
public function fetch($id)
2015-03-18 05:07:32 +01:00
{
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 as note_public,";
$sql .= " t.fk_bank,";
$sql .= " t.fk_user_creat,";
$sql .= " t.fk_user_modif,";
$sql .= " pt.code as type_code, pt.libelle as type_label,";
$sql .= ' b.fk_account';
$sql .= " FROM ".MAIN_DB_PREFIX."payment_donation as t";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pt ON t.fk_typepayment = pt.id";
$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON t.fk_bank = b.rowid';
2021-03-14 11:48:39 +01:00
$sql .= " WHERE t.rowid = ".((int) $id);
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql = $this->db->query($sql);
2021-02-25 22:18:34 +01:00
if ($resql) {
if ($this->db->num_rows($resql)) {
2015-03-18 05:07:32 +01:00
$obj = $this->db->fetch_object($resql);
2020-05-02 15:18:59 +02:00
$this->id = $obj->rowid;
$this->ref = $obj->rowid;
2015-03-18 05:07:32 +01:00
2020-05-02 15:18:59 +02:00
$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;
2022-04-08 15:15:55 +02:00
$this->fk_typepayment = $obj->fk_typepayment; // For backward compatibility
$this->paymenttype = $obj->fk_typepayment;
2020-05-02 15:18:59 +02:00
$this->num_payment = $obj->num_payment;
$this->note_public = $obj->note_public;
$this->fk_bank = $obj->fk_bank;
$this->fk_user_creat = $obj->fk_user_creat;
$this->fk_user_modif = $obj->fk_user_modif;
2015-03-29 09:20:32 +02:00
2020-05-02 15:18:59 +02:00
$this->type_code = $obj->type_code;
$this->type_label = $obj->type_label;
2015-03-29 09:20:32 +02:00
$this->bank_account = $obj->fk_account;
2020-05-02 15:18:59 +02:00
$this->bank_line = $obj->fk_bank;
2015-03-18 05:07:32 +01:00
}
$this->db->free($resql);
return 1;
2020-05-21 15:05:19 +02:00
} else {
$this->error = "Error ".$this->db->lasterror();
2015-03-18 05:07:32 +01:00
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
*/
2019-02-25 20:35:59 +01:00
public function update($user, $notrigger = 0)
2015-03-18 05:07:32 +01:00
{
global $conf, $langs;
$error = 0;
2015-03-18 05:07:32 +01:00
// Clean parameters
2021-02-25 22:18:34 +01:00
if (isset($this->fk_donation)) {
$this->fk_donation = (int) $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_public)) {
$this->note_public = trim($this->note_public);
}
if (isset($this->fk_bank)) {
$this->fk_bank = (int) $this->fk_bank;
}
if (isset($this->fk_user_creat)) {
$this->fk_user_creat = (int) $this->fk_user_creat;
}
if (isset($this->fk_user_modif)) {
$this->fk_user_modif = (int) $this->fk_user_modif;
}
2015-03-18 05:07:32 +01:00
// 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_public) ? "'".$this->db->escape($this->note_public)."'" : "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=".(int) $this->id;
2015-03-18 05:07:32 +01:00
$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();
}
2015-03-18 05:07:32 +01:00
2021-02-25 22:18:34 +01:00
if (!$error) {
if (!$notrigger) {
if (!$error && !$notrigger) {
2018-01-05 04:31:48 +01:00
// Call triggers
$result = $this->call_trigger('DONATION_PAYMENT_MODIFY', $user);
2021-02-25 22:18:34 +01:00
if ($result < 0) {
$error++;
}
2018-01-05 04:31:48 +01:00
// End call triggers
}
2015-03-18 05:07:32 +01:00
}
}
// Commit or rollback
2021-02-25 22:18:34 +01:00
if ($error) {
foreach ($this->errors as $errmsg) {
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2015-03-18 05:07:32 +01:00
}
$this->db->rollback();
return -1 * $error;
2020-05-21 15:05:19 +02:00
} else {
2015-03-18 05:07:32 +01:00
$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
*/
2019-02-25 20:35:59 +01:00
public function delete($user, $notrigger = 0)
2015-03-18 05:07:32 +01:00
{
global $conf, $langs;
$error = 0;
2015-03-18 05:07:32 +01:00
$this->db->begin();
2021-02-25 22:18:34 +01:00
if (!$error) {
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_url";
$sql .= " WHERE type='payment_donation' AND url_id=".(int) $this->id;
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
2021-02-25 22:18:34 +01:00
if (!$resql) {
$error++; $this->errors[] = "Error ".$this->db->lasterror();
}
}
2015-03-18 05:07:32 +01:00
2021-02-25 22:18:34 +01:00
if (!$error) {
2015-03-18 05:07:32 +01:00
$sql = "DELETE FROM ".MAIN_DB_PREFIX."payment_donation";
2021-03-14 12:20:23 +01:00
$sql .= " WHERE rowid=".((int) $this->id);
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
2019-12-07 15:44:13 +01:00
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
2019-12-07 15:44:13 +01:00
}
2015-03-18 05:07:32 +01:00
}
2021-02-25 22:18:34 +01:00
if (!$error) {
if (!$notrigger) {
if (!$error && !$notrigger) {
2018-01-05 04:31:48 +01:00
// Call triggers
$result = $this->call_trigger('DONATION_PAYMENT_DELETE', $user);
2021-02-25 22:18:34 +01:00
if ($result < 0) {
$error++;
}
2018-01-05 04:31:48 +01:00
// End call triggers
}
2015-03-18 05:07:32 +01:00
}
}
// Commit or rollback
2021-02-25 22:18:34 +01:00
if ($error) {
foreach ($this->errors as $errmsg) {
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
2015-03-18 05:07:32 +01:00
}
$this->db->rollback();
return -1 * $error;
2020-05-21 15:05:19 +02:00
} else {
2015-03-18 05:07:32 +01:00
$this->db->commit();
return 1;
}
}
/**
* Load an object from its id and create a new one in database
*
* @param User $user User making the clone
2015-03-18 05:07:32 +01:00
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone(User $user, $fromid)
2015-03-18 05:07:32 +01:00
{
$error = 0;
2015-03-18 05:07:32 +01:00
$object = new PaymentDonation($this->db);
2015-03-18 05:07:32 +01:00
$this->db->begin();
// Load source object
$object->fetch($fromid);
$object->id = 0;
$object->statut = 0;
2015-03-18 05:07:32 +01:00
// Clear fields
// ...
// Create clone
$object->context['createfromclone'] = 'createfromclone';
$result = $object->create($user);
2015-03-18 05:07:32 +01:00
// Other options
2021-02-25 22:18:34 +01:00
if ($result < 0) {
$this->error = $object->error;
2015-03-18 05:07:32 +01:00
$error++;
}
2021-02-25 22:18:34 +01:00
if (!$error) {
2015-03-18 05:07:32 +01:00
}
unset($object->context['createfromclone']);
2015-03-18 05:07:32 +01:00
// End
2021-02-25 22:18:34 +01:00
if (!$error) {
2015-03-18 05:07:32 +01:00
$this->db->commit();
return $object->id;
2020-05-21 15:05:19 +02:00
} else {
2015-03-18 05:07:32 +01:00
$this->db->rollback();
return -1;
}
}
2016-12-18 13:04:24 +01:00
/**
* Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
*
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
* @return string Libelle
*/
2019-02-25 20:35:59 +01:00
public function getLibStatut($mode = 0)
2016-12-18 13:04:24 +01:00
{
return '';
2016-12-18 13:04:24 +01:00
}
2017-06-09 09:25:15 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016-12-18 13:04:24 +01:00
/**
* Renvoi le libelle d'un statut donne
*
2019-11-01 23:58:14 +01:00
* @param int $status Id status
2016-12-18 13:04:24 +01:00
* @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
* @return string Libelle du statut
*/
public function LibStatut($status, $mode = 0)
{
// phpcs:enable
global $langs;
2017-06-09 09:25:15 +02:00
return '';
}
2017-06-09 09:25:15 +02:00
2015-03-18 05:07:32 +01:00
/**
* 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
2015-03-18 05:07:32 +01:00
*/
2019-02-25 20:35:59 +01:00
public function initAsSpecimen()
2015-03-18 05:07:32 +01:00
{
$this->id = 0;
$this->fk_donation = '';
$this->datec = '';
$this->tms = '';
$this->datep = '';
$this->amount = '';
$this->fk_typepayment = '';
2022-04-08 15:15:55 +02:00
$this->paymenttype = '';
$this->num_payment = '';
$this->note_public = '';
$this->fk_bank = '';
$this->fk_user_creat = '';
$this->fk_user_modif = '';
2015-03-18 05:07:32 +01:00
}
/**
* 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_donation'
* @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
*/
public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
{
global $conf;
$error = 0;
2021-02-25 22:18:34 +01:00
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;
2021-02-25 22:18:34 +01:00
if ($mode == 'payment_donation') {
$amount = $total;
}
// Insert payment into llx_bank
$bank_line_id = $acc->addline(
$this->datepaid,
$this->paymenttype, // Payment mode id or code ("CHQ or VIR for example")
$label,
$amount,
$this->num_payment,
'',
$user,
$emetteur_nom,
$emetteur_banque
);
// Update fk_bank in llx_paiement.
// On connait ainsi le paiement qui a genere l'ecriture bancaire
2021-02-25 22:18:34 +01:00
if ($bank_line_id > 0) {
$result = $this->update_fk_bank($bank_line_id);
2021-02-25 22:18:34 +01:00
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
// Add link 'payment', 'payment_supplier', 'payment_donation' in bank_url between payment and bank transaction
$url = '';
2021-02-25 22:18:34 +01:00
if ($mode == 'payment_donation') {
$url = DOL_URL_ROOT.'/don/payment/card.php?rowid=';
}
if ($url) {
$result = $acc->add_url_line($bank_line_id, $this->id, $url, '(paiement)', $mode);
2021-02-25 22:18:34 +01:00
if ($result <= 0) {
$error++;
dol_print_error($this->db);
}
}
} else {
$this->error = $acc->error;
$error++;
}
}
2021-02-25 22:18:34 +01:00
if (!$error) {
return 1;
} else {
return -1;
}
}
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
/**
2015-03-29 09:20:32 +02:00
* Update link between the donation payment and the generated line in llx_bank
2015-03-18 05:07:32 +01:00
*
* @param int $id_bank Id if bank
* @return int >0 if OK, <=0 if KO
*/
2019-02-25 20:35:59 +01:00
public function update_fk_bank($id_bank)
2015-03-18 05:07:32 +01:00
{
// phpcs:enable
2019-12-07 15:44:13 +01:00
$sql = "UPDATE ".MAIN_DB_PREFIX."payment_donation SET fk_bank = ".(int) $id_bank." WHERE rowid = ".(int) $this->id;
2015-03-18 05:07:32 +01:00
dol_syslog(get_class($this)."::update_fk_bank", LOG_DEBUG);
$result = $this->db->query($sql);
2021-02-25 22:18:34 +01:00
if ($result) {
2015-03-18 05:07:32 +01:00
return 1;
2020-05-21 15:05:19 +02:00
} else {
$this->error = $this->db->error();
2015-03-18 05:07:32 +01:00
return 0;
}
}
/**
* Return clicable name (with picto eventually)
*
* @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto
2020-11-03 14:19:54 +01:00
* @param int $maxlen Max length
* @return string String with URL
2015-03-18 05:07:32 +01:00
*/
2019-02-25 20:35:59 +01:00
public function getNomUrl($withpicto = 0, $maxlen = 0)
2015-03-18 05:07:32 +01:00
{
2021-11-22 19:57:26 +01:00
global $langs, $hookmanager;
2015-03-18 05:07:32 +01:00
$result = '';
2015-03-18 05:07:32 +01:00
2020-11-03 14:19:54 +01:00
$label = '<u>'.$langs->trans("DonationPayment").'</u>';
$label .= '<br>';
$label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
2015-03-18 05:07:32 +01:00
2021-02-25 22:18:34 +01:00
if (!empty($this->id)) {
2015-03-29 09:20:32 +02:00
$link = '<a href="'.DOL_URL_ROOT.'/don/payment/card.php?id='.$this->id.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">';
$linkend = '</a>';
2015-03-18 05:07:32 +01:00
2021-02-25 22:18:34 +01:00
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;
}
2015-03-18 05:07:32 +01:00
}
2021-11-22 19:57:26 +01:00
global $action;
2022-02-15 19:04:18 +01:00
$hookmanager->initHooks(array($this->element . 'dao'));
2021-11-22 19:57:26 +01:00
$parameters = array('id'=>$this->id, 'getnomurl' => &$result);
$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
if ($reshook > 0) {
$result = $hookmanager->resPrint;
} else {
$result .= $hookmanager->resPrint;
}
2015-03-18 05:07:32 +01:00
return $result;
}
}