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';
65 public $amounts = array();
67 public $fk_typepayment;
84 public $fk_user_creat;
89 public $fk_user_modif;
101 public $bank_account;
107 public $ext_payment_id;
112 public $ext_payment_site;
132 public function create($user, $notrigger = 0)
140 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
145 if (isset($this->chid)) {
146 $this->chid = (int) $this->chid;
147 } elseif (isset($this->fk_donation)) {
150 $this->chid = (int) $this->fk_donation;
152 if (isset($this->fk_donation)) {
153 $this->fk_donation = (int) $this->fk_donation;
155 if (isset($this->amount)) {
156 $this->amount = trim($this->amount);
158 if (isset($this->fk_typepayment)) {
159 $this->fk_typepayment = trim($this->fk_typepayment);
161 if (isset($this->num_payment)) {
162 $this->num_payment = trim($this->num_payment);
164 if (isset($this->note_public)) {
165 $this->note_public = trim($this->note_public);
167 if (isset($this->fk_bank)) {
168 $this->fk_bank = (int) $this->fk_bank;
170 if (isset($this->fk_user_creat)) {
171 $this->fk_user_creat = (int) $this->fk_user_creat;
173 if (isset($this->fk_user_modif)) {
174 $this->fk_user_modif = (int) $this->fk_user_modif;
178 foreach ($this->amounts as $key => $value) {
180 $this->amounts[$key] = $newvalue;
181 $totalamount += $newvalue;
186 if ($totalamount == 0) {
193 if ($totalamount != 0) {
194 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
195 $sql .=
" fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
196 $sql .=
" fk_user_creat, fk_bank)";
197 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
198 $sql .=
" '".$this->db->idate($this->datep).
"',";
199 $sql .=
" ".((float)
price2num($totalamount)).
",";
200 $sql .=
" ".((int) $this->paymenttype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ";
201 $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").
",";
202 $sql .=
" ".((int) $user->id).
", 0)";
204 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
205 $resql = $this->db->query($sql);
207 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
208 $this->
ref = (string) $this->
id;
214 if (!$error && !$notrigger) {
216 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
223 if ($totalamount != 0 && !$error) {
224 $this->amount = $totalamount;
225 $this->total = $totalamount;
229 $this->error = $this->db->error();
230 $this->db->rollback();
246 $sql .=
" t.fk_donation,";
250 $sql .=
" t.amount,";
251 $sql .=
" t.fk_typepayment,";
252 $sql .=
" t.num_payment,";
253 $sql .=
" t.note as note_public,";
254 $sql .=
" t.fk_bank,";
255 $sql .=
" t.fk_user_creat,";
256 $sql .=
" t.fk_user_modif,";
257 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
258 $sql .=
' b.fk_account';
259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
260 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
261 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
262 $sql .=
" WHERE t.rowid = ".((int) $id);
264 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
265 $resql = $this->db->query($sql);
267 if ($this->db->num_rows($resql)) {
268 $obj = $this->db->fetch_object($resql);
270 $this->
id = $obj->rowid;
271 $this->
ref = $obj->rowid;
273 $this->fk_donation = $obj->fk_donation;
274 $this->datec = $this->db->jdate($obj->datec);
275 $this->tms = $this->db->jdate($obj->tms);
276 $this->datep = $this->db->jdate($obj->datep);
277 $this->amount = $obj->amount;
278 $this->fk_typepayment = $obj->fk_typepayment;
279 $this->paymenttype = $obj->fk_typepayment;
280 $this->num_payment = $obj->num_payment;
281 $this->note_public = $obj->note_public;
282 $this->fk_bank = $obj->fk_bank;
283 $this->fk_user_creat = $obj->fk_user_creat;
284 $this->fk_user_modif = $obj->fk_user_modif;
286 $this->type_code = $obj->type_code;
287 $this->type_label = $obj->type_label;
289 $this->bank_account = $obj->fk_account;
290 $this->bank_line = $obj->fk_bank;
292 $this->db->free($resql);
296 $this->error =
"Error ".$this->db->lasterror();
309 public function update($user, $notrigger = 0)
311 global $conf, $langs;
316 if (isset($this->fk_donation)) {
317 $this->fk_donation = (int) $this->fk_donation;
319 if (isset($this->amount)) {
320 $this->amount = trim($this->amount);
322 if (isset($this->fk_typepayment)) {
323 $this->fk_typepayment = trim($this->fk_typepayment);
325 if (isset($this->num_payment)) {
326 $this->num_payment = trim($this->num_payment);
328 if (isset($this->note_public)) {
329 $this->note_public = trim($this->note_public);
331 if (isset($this->fk_bank)) {
332 $this->fk_bank = (int) $this->fk_bank;
334 if (isset($this->fk_user_creat)) {
335 $this->fk_user_creat = (int) $this->fk_user_creat;
337 if (isset($this->fk_user_modif)) {
338 $this->fk_user_modif = (int) $this->fk_user_modif;
345 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
346 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
347 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
348 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
349 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
350 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
351 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
352 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
353 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
354 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
355 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
356 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
357 $sql .=
" WHERE rowid=".(int) $this->
id;
361 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
362 $resql = $this->db->query($sql);
365 $this->errors[] =
"Error ".$this->db->lasterror();
370 if (!$error && !$notrigger) {
372 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
383 foreach ($this->errors as $errmsg) {
384 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
385 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
387 $this->db->rollback();
403 public function delete($user, $notrigger = 0)
405 global $conf, $langs;
411 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
412 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
414 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
415 $resql = $this->db->query($sql);
418 $this->errors[] =
"Error ".$this->db->lasterror();
423 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
424 $sql .=
" WHERE rowid=".((int) $this->
id);
426 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
427 $resql = $this->db->query($sql);
430 $this->errors[] =
"Error ".$this->db->lasterror();
436 if (!$error && !$notrigger) {
438 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
449 foreach ($this->errors as $errmsg) {
450 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
451 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
453 $this->db->rollback();
487 $object->context[
'createfromclone'] =
'createfromclone';
488 $result =
$object->create($user);
499 unset(
$object->context[
'createfromclone']);
506 $this->db->rollback();
551 $this->fk_donation = 0;
556 $this->fk_typepayment =
'';
557 $this->paymenttype =
'';
558 $this->num_payment =
'';
559 $this->note_public =
'';
561 $this->fk_user_creat =
dol_now();
562 $this->fk_user_modif =
dol_now();
580 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
586 if (isModEnabled(
"bank")) {
587 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
590 $acc->fetch($accountid);
593 if ($mode ==
'payment_donation') {
597 $bank_line_id = $acc->addline(
611 if ($bank_line_id > 0) {
620 if ($mode ==
'payment_donation') {
621 $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
624 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
631 $this->error = $acc->error;
654 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
656 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
657 $result = $this->db->query($sql);
661 $this->error = $this->db->error();
675 global $langs, $hookmanager;
679 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
681 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
683 if (!empty($this->
id)) {
684 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
688 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
690 if ($withpicto && $withpicto != 2) {
693 if ($withpicto != 2) {
694 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
699 $hookmanager->initHooks(array($this->element .
'dao'));
700 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
701 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
703 $result = $hookmanager->resPrint;
705 $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...