24 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 public $element =
'payment_donation';
40 public $table_element =
'payment_donation';
45 public $picto =
'payment';
65 public $amounts = array();
67 public $fk_typepayment;
80 public $fk_user_creat;
85 public $fk_user_modif;
99 public $ext_payment_id;
104 public $ext_payment_site;
124 public function create($user, $notrigger =
false)
126 global $conf, $langs;
133 if (!$this->datepaid) {
134 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
139 if (isset($this->chid)) {
140 $this->chid = (int) $this->chid;
141 } elseif (isset($this->fk_donation)) {
144 $this->chid = (int) $this->fk_donation;
146 if (isset($this->fk_donation)) {
147 $this->fk_donation = (int) $this->fk_donation;
149 if (isset($this->amount)) {
150 $this->amount = trim($this->amount);
152 if (isset($this->fk_typepayment)) {
153 $this->fk_typepayment = trim($this->fk_typepayment);
155 if (isset($this->num_payment)) {
156 $this->num_payment = trim($this->num_payment);
158 if (isset($this->note_public)) {
159 $this->note_public = trim($this->note_public);
161 if (isset($this->fk_bank)) {
162 $this->fk_bank = (int) $this->fk_bank;
164 if (isset($this->fk_user_creat)) {
165 $this->fk_user_creat = (int) $this->fk_user_creat;
167 if (isset($this->fk_user_modif)) {
168 $this->fk_user_modif = (int) $this->fk_user_modif;
172 foreach ($this->amounts as $key => $value) {
174 $this->amounts[$key] = $newvalue;
175 $totalamount += $newvalue;
180 if ($totalamount == 0) {
187 if ($totalamount != 0) {
188 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
189 $sql .=
" fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
190 $sql .=
" fk_user_creat, fk_bank)";
191 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->
db->idate($now).
"',";
192 $sql .=
" '".$this->db->idate($this->datepaid).
"',";
193 $sql .=
" ".((float)
price2num($totalamount)).
",";
194 $sql .=
" ".((int) $this->paymenttype).
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_public).
"', ";
195 $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").
",";
196 $sql .=
" ".((int) $user->id).
", 0)";
198 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
201 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
202 $this->
ref = $this->id;
208 if (!$error && !$notrigger) {
210 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
217 if ($totalamount != 0 && !$error) {
218 $this->amount = $totalamount;
219 $this->total = $totalamount;
223 $this->error = $this->
db->error();
224 $this->
db->rollback();
240 $sql .=
" t.fk_donation,";
244 $sql .=
" t.amount,";
245 $sql .=
" t.fk_typepayment,";
246 $sql .=
" t.num_payment,";
247 $sql .=
" t.note as note_public,";
248 $sql .=
" t.fk_bank,";
249 $sql .=
" t.fk_user_creat,";
250 $sql .=
" t.fk_user_modif,";
251 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
252 $sql .=
' b.fk_account';
253 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
254 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
255 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
256 $sql .=
" WHERE t.rowid = ".((int) $id);
258 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
262 $obj = $this->
db->fetch_object(
$resql);
264 $this->
id = $obj->rowid;
265 $this->
ref = $obj->rowid;
267 $this->fk_donation = $obj->fk_donation;
268 $this->datec = $this->
db->jdate($obj->datec);
269 $this->tms = $this->
db->jdate($obj->tms);
270 $this->datep = $this->
db->jdate($obj->datep);
271 $this->amount = $obj->amount;
272 $this->fk_typepayment = $obj->fk_typepayment;
273 $this->paymenttype = $obj->fk_typepayment;
274 $this->num_payment = $obj->num_payment;
275 $this->note_public = $obj->note_public;
276 $this->fk_bank = $obj->fk_bank;
277 $this->fk_user_creat = $obj->fk_user_creat;
278 $this->fk_user_modif = $obj->fk_user_modif;
280 $this->type_code = $obj->type_code;
281 $this->type_label = $obj->type_label;
283 $this->bank_account = $obj->fk_account;
284 $this->bank_line = $obj->fk_bank;
290 $this->error =
"Error ".$this->db->lasterror();
303 public function update($user, $notrigger = 0)
305 global $conf, $langs;
310 if (isset($this->fk_donation)) {
311 $this->fk_donation = (int) $this->fk_donation;
313 if (isset($this->amount)) {
314 $this->amount = trim($this->amount);
316 if (isset($this->fk_typepayment)) {
317 $this->fk_typepayment = trim($this->fk_typepayment);
319 if (isset($this->num_payment)) {
320 $this->num_payment = trim($this->num_payment);
322 if (isset($this->note_public)) {
323 $this->note_public = trim($this->note_public);
325 if (isset($this->fk_bank)) {
326 $this->fk_bank = (int) $this->fk_bank;
328 if (isset($this->fk_user_creat)) {
329 $this->fk_user_creat = (int) $this->fk_user_creat;
331 if (isset($this->fk_user_modif)) {
332 $this->fk_user_modif = (int) $this->fk_user_modif;
339 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
340 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
341 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
342 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
343 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
344 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
345 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
346 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
347 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
348 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
349 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
350 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
351 $sql .=
" WHERE rowid=".(int) $this->
id;
355 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
359 $this->errors[] =
"Error ".$this->db->lasterror();
364 if (!$error && !$notrigger) {
366 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
377 foreach ($this->errors as $errmsg) {
378 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
379 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
381 $this->
db->rollback();
397 public function delete($user, $notrigger = 0)
399 global $conf, $langs;
405 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
406 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
408 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
411 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
416 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
417 $sql .=
" WHERE rowid=".((int) $this->
id);
419 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
423 $this->errors[] =
"Error ".$this->db->lasterror();
429 if (!$error && !$notrigger) {
431 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
442 foreach ($this->errors as $errmsg) {
443 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
444 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
446 $this->
db->rollback();
472 $object->fetch($fromid);
480 $object->context[
'createfromclone'] =
'createfromclone';
481 $result = $object->create($user);
485 $this->error = $object->error;
492 unset($object->context[
'createfromclone']);
499 $this->
db->rollback();
544 $this->fk_donation =
'';
549 $this->fk_typepayment =
'';
550 $this->paymenttype =
'';
551 $this->num_payment =
'';
552 $this->note_public =
'';
554 $this->fk_user_creat =
'';
555 $this->fk_user_modif =
'';
571 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
578 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
581 $acc->fetch($accountid);
584 if ($mode ==
'payment_donation') {
589 $bank_line_id = $acc->addline(
603 if ($bank_line_id > 0) {
612 if ($mode ==
'payment_donation') {
613 $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
616 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
623 $this->error = $acc->error;
646 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
648 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
649 $result = $this->
db->query($sql);
653 $this->error = $this->
db->error();
667 global $langs, $hookmanager;
671 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
673 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
675 if (!empty($this->
id)) {
676 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
680 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
682 if ($withpicto && $withpicto != 2) {
685 if ($withpicto != 2) {
686 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
691 $hookmanager->initHooks(array($this->element .
'dao'));
692 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
693 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
695 $result = $hookmanager->resPrint;
697 $result .= $hookmanager->resPrint;
Class to manage bank accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage payments of donations.
addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
Add record into bank for payment with links between this bank record and invoices of payment.
create($user, $notrigger=false)
Create payment of donation into database.
initAsSpecimen()
Initialise an instance with random values.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
update_fk_bank($id_bank)
Update link between the donation payment and the generated line in llx_bank.
__construct($db)
Constructor.
getLibStatut($mode=0)
Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
fetch($id)
Load object in memory from database.
update($user, $notrigger=0)
Update database.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_now($mode='auto')
Return date for now.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.