26require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'payment_donation';
42 public $table_element =
'payment_donation';
47 public $picto =
'payment';
77 public $amounts = array();
84 public $fk_typepayment;
105 public $fk_user_creat;
110 public $fk_user_modif;
138 public $bank_account;
147 public $ext_payment_id;
152 public $ext_payment_site;
172 public function create($user, $notrigger = 0)
180 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
185 if (isset($this->chid)) {
186 $this->chid = (int) $this->chid;
187 } elseif (isset($this->fk_donation)) {
190 $this->chid = (int) $this->fk_donation;
192 if (isset($this->fk_donation)) {
193 $this->fk_donation = (int) $this->fk_donation;
195 if (isset($this->amount)) {
196 $this->amount = (float)
price2num($this->amount);
198 if (isset($this->fk_typepayment)) {
199 $this->fk_typepayment = (int)
price2num($this->fk_typepayment);
201 if (isset($this->num_payment)) {
202 $this->num_payment = trim($this->num_payment);
204 if (isset($this->note_public)) {
205 $this->note_public = trim($this->note_public);
207 if (isset($this->fk_bank)) {
208 $this->fk_bank = (int) $this->fk_bank;
210 if (isset($this->fk_user_creat)) {
211 $this->fk_user_creat = (int) $this->fk_user_creat;
213 if (isset($this->fk_user_modif)) {
214 $this->fk_user_modif = (int) $this->fk_user_modif;
218 foreach ($this->amounts as $key => $value) {
219 $newvalue = (float)
price2num($value,
'MT');
220 $this->amounts[$key] = $newvalue;
221 $totalamount += $newvalue;
223 $totalamount = (float)
price2num($totalamount);
226 if ($totalamount == 0) {
233 if ($totalamount != 0) {
234 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
235 $sql .=
" fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
236 $sql .=
" fk_user_creat, fk_bank)";
237 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
238 $sql .=
" '".$this->db->idate($this->datep).
"',";
239 $sql .=
" ".((float)
price2num($totalamount)).
",";
240 $sql .=
" ".((int) $this->paymenttype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ";
241 $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").
",";
242 $sql .=
" ".((int) $user->id).
", 0)";
244 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
245 $resql = $this->db->query($sql);
247 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
248 $this->
ref = (string) $this->
id;
254 if (!$error && !$notrigger) {
256 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
263 if ($totalamount != 0 && !$error) {
264 $this->amount = $totalamount;
265 $this->total = $totalamount;
269 $this->error = $this->db->error();
270 $this->db->rollback();
286 $sql .=
" t.fk_donation,";
290 $sql .=
" t.amount,";
291 $sql .=
" t.fk_typepayment,";
292 $sql .=
" t.num_payment,";
293 $sql .=
" t.note as note_public,";
294 $sql .=
" t.fk_bank,";
295 $sql .=
" t.fk_user_creat,";
296 $sql .=
" t.fk_user_modif,";
297 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
298 $sql .=
' b.fk_account';
299 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
300 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
301 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
302 $sql .=
" WHERE t.rowid = ".((int) $id);
304 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
305 $resql = $this->db->query($sql);
307 if ($this->db->num_rows($resql)) {
308 $obj = $this->db->fetch_object($resql);
310 $this->
id = $obj->rowid;
311 $this->
ref = $obj->rowid;
313 $this->fk_donation = $obj->fk_donation;
314 $this->datec = $this->db->jdate($obj->datec);
315 $this->tms = $this->db->jdate($obj->tms);
316 $this->datep = $this->db->jdate($obj->datep);
317 $this->amount = $obj->amount;
318 $this->fk_typepayment = $obj->fk_typepayment;
319 $this->paymenttype = $obj->fk_typepayment;
320 $this->num_payment = $obj->num_payment;
321 $this->note_public = $obj->note_public;
322 $this->fk_bank = $obj->fk_bank;
323 $this->fk_user_creat = $obj->fk_user_creat;
324 $this->fk_user_modif = $obj->fk_user_modif;
326 $this->type_code = $obj->type_code;
327 $this->type_label = $obj->type_label;
329 $this->bank_account = $obj->fk_account;
330 $this->bank_line = $obj->fk_bank;
332 $this->db->free($resql);
336 $this->error =
"Error ".$this->db->lasterror();
349 public function update($user, $notrigger = 0)
351 global
$conf, $langs;
356 if (isset($this->fk_donation)) {
357 $this->fk_donation = (int) $this->fk_donation;
359 if (isset($this->amount)) {
360 $this->amount = (float)
price2num($this->amount);
362 if (isset($this->fk_typepayment)) {
363 $this->fk_typepayment = (int)
price2num($this->fk_typepayment);
365 if (isset($this->num_payment)) {
366 $this->num_payment = trim($this->num_payment);
368 if (isset($this->note_public)) {
369 $this->note_public = trim($this->note_public);
371 if (isset($this->fk_bank)) {
372 $this->fk_bank = (int) $this->fk_bank;
374 if (isset($this->fk_user_creat)) {
375 $this->fk_user_creat = (int) $this->fk_user_creat;
377 if (isset($this->fk_user_modif)) {
378 $this->fk_user_modif = (int) $this->fk_user_modif;
385 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
386 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
387 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
388 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
389 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
390 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
391 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
392 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
393 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
394 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
395 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
396 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
397 $sql .=
" WHERE rowid=".(int) $this->
id;
401 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
402 $resql = $this->db->query($sql);
405 $this->errors[] =
"Error ".$this->db->lasterror();
410 if (!$error && !$notrigger) {
412 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
423 foreach ($this->errors as $errmsg) {
424 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
425 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
427 $this->db->rollback();
443 public function delete($user, $notrigger = 0)
445 global
$conf, $langs;
451 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
452 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
454 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
455 $resql = $this->db->query($sql);
458 $this->errors[] =
"Error ".$this->db->lasterror();
463 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
464 $sql .=
" WHERE rowid=".((int) $this->
id);
466 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
467 $resql = $this->db->query($sql);
470 $this->errors[] =
"Error ".$this->db->lasterror();
476 if (!$error && !$notrigger) {
478 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
489 foreach ($this->errors as $errmsg) {
490 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
491 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
493 $this->db->rollback();
527 $object->context[
'createfromclone'] =
'createfromclone';
528 $result =
$object->create($user);
539 unset(
$object->context[
'createfromclone']);
546 $this->db->rollback();
591 $this->fk_donation = 0;
595 $this->amount = 1000.80;
596 $this->fk_typepayment = 0;
597 $this->paymenttype = 0;
598 $this->num_payment =
'';
599 $this->note_public =
'Public note';
601 $this->fk_user_creat = 1;
602 $this->fk_user_modif = 1;
620 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
627 if (isModEnabled(
"bank")) {
628 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
631 $acc->fetch($accountid);
633 $total = $this->total;
634 if ($mode ==
'payment_donation') {
638 $bank_line_id = $acc->addline(
652 if ($bank_line_id > 0) {
661 if ($mode ==
'payment_donation') {
662 $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
665 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
672 $this->error = $acc->error;
695 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
697 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
698 $result = $this->db->query($sql);
702 $this->error = $this->db->error();
716 global $langs, $hookmanager;
720 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
722 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
724 if (!empty($this->
id)) {
725 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
729 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
731 if ($withpicto && $withpicto != 2) {
734 if ($withpicto != 2) {
735 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
740 $hookmanager->initHooks(array($this->element .
'dao'));
741 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
742 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
744 $result = $hookmanager->resPrint;
746 $result .= $hookmanager->resPrint;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
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.
initAsSpecimen()
Initialise an instance with random values.
create($user, $notrigger=0)
Create payment of donation into database.
LibStatut($status, $mode=0)
Return the label of a given status.
update_fk_bank($id_bank)
Update link between the donation payment and the generated line in llx_bank.
__construct($db)
Constructor.
getLibStatut($mode=0)
Return the label of the status.
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 clickable name (with picto eventually)
Class to manage Dolibarr users.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_now($mode='auto')
Return date for now.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...