24require_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;
103 public $ext_payment_id;
108 public $ext_payment_site;
128 public function create($user, $notrigger =
false)
130 global $conf, $langs;
138 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
143 if (isset($this->chid)) {
144 $this->chid = (int) $this->chid;
145 } elseif (isset($this->fk_donation)) {
148 $this->chid = (int) $this->fk_donation;
150 if (isset($this->fk_donation)) {
151 $this->fk_donation = (int) $this->fk_donation;
153 if (isset($this->amount)) {
154 $this->amount = trim($this->amount);
156 if (isset($this->fk_typepayment)) {
157 $this->fk_typepayment = trim($this->fk_typepayment);
159 if (isset($this->num_payment)) {
160 $this->num_payment = trim($this->num_payment);
162 if (isset($this->note_public)) {
163 $this->note_public = trim($this->note_public);
165 if (isset($this->fk_bank)) {
166 $this->fk_bank = (int) $this->fk_bank;
168 if (isset($this->fk_user_creat)) {
169 $this->fk_user_creat = (int) $this->fk_user_creat;
171 if (isset($this->fk_user_modif)) {
172 $this->fk_user_modif = (int) $this->fk_user_modif;
176 foreach ($this->amounts as $key => $value) {
178 $this->amounts[$key] = $newvalue;
179 $totalamount += $newvalue;
184 if ($totalamount == 0) {
191 if ($totalamount != 0) {
192 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
193 $sql .=
" fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
194 $sql .=
" fk_user_creat, fk_bank)";
195 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
196 $sql .=
" '".$this->db->idate($this->datep).
"',";
197 $sql .=
" ".((float)
price2num($totalamount)).
",";
198 $sql .=
" ".((int) $this->paymenttype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ";
199 $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").
",";
200 $sql .=
" ".((int) $user->id).
", 0)";
202 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
203 $resql = $this->db->query($sql);
205 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
206 $this->
ref = $this->id;
212 if (!$error && !$notrigger) {
214 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
221 if ($totalamount != 0 && !$error) {
222 $this->amount = $totalamount;
223 $this->total = $totalamount;
227 $this->error = $this->db->error();
228 $this->db->rollback();
244 $sql .=
" t.fk_donation,";
248 $sql .=
" t.amount,";
249 $sql .=
" t.fk_typepayment,";
250 $sql .=
" t.num_payment,";
251 $sql .=
" t.note as note_public,";
252 $sql .=
" t.fk_bank,";
253 $sql .=
" t.fk_user_creat,";
254 $sql .=
" t.fk_user_modif,";
255 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
256 $sql .=
' b.fk_account';
257 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
258 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
259 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
260 $sql .=
" WHERE t.rowid = ".((int) $id);
262 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
263 $resql = $this->db->query($sql);
265 if ($this->db->num_rows($resql)) {
266 $obj = $this->db->fetch_object($resql);
268 $this->
id = $obj->rowid;
269 $this->
ref = $obj->rowid;
271 $this->fk_donation = $obj->fk_donation;
272 $this->datec = $this->db->jdate($obj->datec);
273 $this->tms = $this->db->jdate($obj->tms);
274 $this->datep = $this->db->jdate($obj->datep);
275 $this->amount = $obj->amount;
276 $this->fk_typepayment = $obj->fk_typepayment;
277 $this->paymenttype = $obj->fk_typepayment;
278 $this->num_payment = $obj->num_payment;
279 $this->note_public = $obj->note_public;
280 $this->fk_bank = $obj->fk_bank;
281 $this->fk_user_creat = $obj->fk_user_creat;
282 $this->fk_user_modif = $obj->fk_user_modif;
284 $this->type_code = $obj->type_code;
285 $this->type_label = $obj->type_label;
287 $this->bank_account = $obj->fk_account;
288 $this->bank_line = $obj->fk_bank;
290 $this->db->free($resql);
294 $this->error =
"Error ".$this->db->lasterror();
307 public function update($user, $notrigger = 0)
309 global $conf, $langs;
314 if (isset($this->fk_donation)) {
315 $this->fk_donation = (int) $this->fk_donation;
317 if (isset($this->amount)) {
318 $this->amount = trim($this->amount);
320 if (isset($this->fk_typepayment)) {
321 $this->fk_typepayment = trim($this->fk_typepayment);
323 if (isset($this->num_payment)) {
324 $this->num_payment = trim($this->num_payment);
326 if (isset($this->note_public)) {
327 $this->note_public = trim($this->note_public);
329 if (isset($this->fk_bank)) {
330 $this->fk_bank = (int) $this->fk_bank;
332 if (isset($this->fk_user_creat)) {
333 $this->fk_user_creat = (int) $this->fk_user_creat;
335 if (isset($this->fk_user_modif)) {
336 $this->fk_user_modif = (int) $this->fk_user_modif;
343 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
344 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
345 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
346 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
347 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
348 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
349 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
350 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
351 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
352 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
353 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
354 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
355 $sql .=
" WHERE rowid=".(int) $this->
id;
359 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
360 $resql = $this->db->query($sql);
363 $this->errors[] =
"Error ".$this->db->lasterror();
368 if (!$error && !$notrigger) {
370 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
381 foreach ($this->errors as $errmsg) {
382 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
383 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
385 $this->db->rollback();
401 public function delete($user, $notrigger = 0)
403 global $conf, $langs;
409 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
410 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
412 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
413 $resql = $this->db->query($sql);
415 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
420 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
421 $sql .=
" WHERE rowid=".((int) $this->
id);
423 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
424 $resql = $this->db->query($sql);
427 $this->errors[] =
"Error ".$this->db->lasterror();
433 if (!$error && !$notrigger) {
435 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
446 foreach ($this->errors as $errmsg) {
447 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
448 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
450 $this->db->rollback();
476 $object->fetch($fromid);
484 $object->context[
'createfromclone'] =
'createfromclone';
485 $result = $object->create($user);
489 $this->error = $object->error;
496 unset($object->context[
'createfromclone']);
503 $this->db->rollback();
548 $this->fk_donation =
'';
553 $this->fk_typepayment =
'';
554 $this->paymenttype =
'';
555 $this->num_payment =
'';
556 $this->note_public =
'';
558 $this->fk_user_creat =
'';
559 $this->fk_user_modif =
'';
575 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
581 if (isModEnabled(
"banque")) {
582 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
585 $acc->fetch($accountid);
588 if ($mode ==
'payment_donation') {
592 $bank_line_id = $acc->addline(
606 if ($bank_line_id > 0) {
615 if ($mode ==
'payment_donation') {
616 $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
619 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
626 $this->error = $acc->error;
649 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
651 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
652 $result = $this->db->query($sql);
656 $this->error = $this->db->error();
670 global $langs, $hookmanager;
674 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
676 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
678 if (!empty($this->
id)) {
679 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
683 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
685 if ($withpicto && $withpicto != 2) {
688 if ($withpicto != 2) {
689 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
694 $hookmanager->initHooks(array($this->element .
'dao'));
695 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
696 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
698 $result = $hookmanager->resPrint;
700 $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)
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 clicable 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_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.
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...