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;
122 public $bank_account;
128 public $ext_payment_id;
133 public $ext_payment_site;
153 public function create($user, $notrigger = 0)
161 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
166 if (isset($this->chid)) {
167 $this->chid = (int) $this->chid;
168 } elseif (isset($this->fk_donation)) {
171 $this->chid = (int) $this->fk_donation;
173 if (isset($this->fk_donation)) {
174 $this->fk_donation = (int) $this->fk_donation;
176 if (isset($this->amount)) {
177 $this->amount = (float)
price2num($this->amount);
179 if (isset($this->fk_typepayment)) {
180 $this->fk_typepayment = (int)
price2num($this->fk_typepayment);
182 if (isset($this->num_payment)) {
183 $this->num_payment = trim($this->num_payment);
185 if (isset($this->note_public)) {
186 $this->note_public = trim($this->note_public);
188 if (isset($this->fk_bank)) {
189 $this->fk_bank = (int) $this->fk_bank;
191 if (isset($this->fk_user_creat)) {
192 $this->fk_user_creat = (int) $this->fk_user_creat;
194 if (isset($this->fk_user_modif)) {
195 $this->fk_user_modif = (int) $this->fk_user_modif;
199 foreach ($this->amounts as $key => $value) {
200 $newvalue = (float)
price2num($value,
'MT');
201 $this->amounts[$key] = $newvalue;
202 $totalamount += $newvalue;
204 $totalamount = (float)
price2num($totalamount);
207 if ($totalamount == 0) {
214 if ($totalamount != 0) {
215 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
216 $sql .=
" fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
217 $sql .=
" fk_user_creat, fk_bank)";
218 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
219 $sql .=
" '".$this->db->idate($this->datep).
"',";
220 $sql .=
" ".((float)
price2num($totalamount)).
",";
221 $sql .=
" ".((int) $this->paymenttype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ";
222 $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").
",";
223 $sql .=
" ".((int) $user->id).
", 0)";
225 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
226 $resql = $this->db->query($sql);
228 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
229 $this->
ref = (string) $this->
id;
235 if (!$error && !$notrigger) {
237 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
244 if ($totalamount != 0 && !$error) {
245 $this->amount = $totalamount;
246 $this->total = $totalamount;
250 $this->error = $this->db->error();
251 $this->db->rollback();
267 $sql .=
" t.fk_donation,";
271 $sql .=
" t.amount,";
272 $sql .=
" t.fk_typepayment,";
273 $sql .=
" t.num_payment,";
274 $sql .=
" t.note as note_public,";
275 $sql .=
" t.fk_bank,";
276 $sql .=
" t.fk_user_creat,";
277 $sql .=
" t.fk_user_modif,";
278 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
279 $sql .=
' b.fk_account';
280 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
281 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
282 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
283 $sql .=
" WHERE t.rowid = ".((int) $id);
285 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
286 $resql = $this->db->query($sql);
288 if ($this->db->num_rows($resql)) {
289 $obj = $this->db->fetch_object($resql);
291 $this->
id = $obj->rowid;
292 $this->
ref = $obj->rowid;
294 $this->fk_donation = $obj->fk_donation;
295 $this->datec = $this->db->jdate($obj->datec);
296 $this->tms = $this->db->jdate($obj->tms);
297 $this->datep = $this->db->jdate($obj->datep);
298 $this->amount = $obj->amount;
299 $this->fk_typepayment = $obj->fk_typepayment;
300 $this->paymenttype = $obj->fk_typepayment;
301 $this->num_payment = $obj->num_payment;
302 $this->note_public = $obj->note_public;
303 $this->fk_bank = $obj->fk_bank;
304 $this->fk_user_creat = $obj->fk_user_creat;
305 $this->fk_user_modif = $obj->fk_user_modif;
307 $this->type_code = $obj->type_code;
308 $this->type_label = $obj->type_label;
310 $this->bank_account = $obj->fk_account;
311 $this->bank_line = $obj->fk_bank;
313 $this->db->free($resql);
317 $this->error =
"Error ".$this->db->lasterror();
330 public function update($user, $notrigger = 0)
332 global $conf, $langs;
337 if (isset($this->fk_donation)) {
338 $this->fk_donation = (int) $this->fk_donation;
340 if (isset($this->amount)) {
341 $this->amount = (float)
price2num($this->amount);
343 if (isset($this->fk_typepayment)) {
344 $this->fk_typepayment = (int)
price2num($this->fk_typepayment);
346 if (isset($this->num_payment)) {
347 $this->num_payment = trim($this->num_payment);
349 if (isset($this->note_public)) {
350 $this->note_public = trim($this->note_public);
352 if (isset($this->fk_bank)) {
353 $this->fk_bank = (int) $this->fk_bank;
355 if (isset($this->fk_user_creat)) {
356 $this->fk_user_creat = (int) $this->fk_user_creat;
358 if (isset($this->fk_user_modif)) {
359 $this->fk_user_modif = (int) $this->fk_user_modif;
366 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
367 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
368 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
369 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
370 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
371 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
372 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
373 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
374 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
375 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
376 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
377 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
378 $sql .=
" WHERE rowid=".(int) $this->
id;
382 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
383 $resql = $this->db->query($sql);
386 $this->errors[] =
"Error ".$this->db->lasterror();
391 if (!$error && !$notrigger) {
393 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
404 foreach ($this->errors as $errmsg) {
405 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
406 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
408 $this->db->rollback();
424 public function delete($user, $notrigger = 0)
426 global $conf, $langs;
432 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
433 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
435 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
436 $resql = $this->db->query($sql);
439 $this->errors[] =
"Error ".$this->db->lasterror();
444 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
445 $sql .=
" WHERE rowid=".((int) $this->
id);
447 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
448 $resql = $this->db->query($sql);
451 $this->errors[] =
"Error ".$this->db->lasterror();
457 if (!$error && !$notrigger) {
459 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
470 foreach ($this->errors as $errmsg) {
471 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
472 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
474 $this->db->rollback();
508 $object->context[
'createfromclone'] =
'createfromclone';
509 $result =
$object->create($user);
520 unset(
$object->context[
'createfromclone']);
527 $this->db->rollback();
572 $this->fk_donation = 0;
576 $this->amount = 1000.80;
577 $this->fk_typepayment = 0;
578 $this->paymenttype = 0;
579 $this->num_payment =
'';
580 $this->note_public =
'Public note';
582 $this->fk_user_creat = 1;
583 $this->fk_user_modif = 1;
601 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
607 if (isModEnabled(
"bank")) {
608 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
611 $acc->fetch($accountid);
614 if ($mode ==
'payment_donation') {
618 $bank_line_id = $acc->addline(
632 if ($bank_line_id > 0) {
641 if ($mode ==
'payment_donation') {
642 $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
645 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
652 $this->error = $acc->error;
675 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
677 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
678 $result = $this->db->query($sql);
682 $this->error = $this->db->error();
696 global $langs, $hookmanager;
700 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
702 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
704 if (!empty($this->
id)) {
705 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
709 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
711 if ($withpicto && $withpicto != 2) {
714 if ($withpicto != 2) {
715 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
720 $hookmanager->initHooks(array($this->element .
'dao'));
721 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
722 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
724 $result = $hookmanager->resPrint;
726 $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...