25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'payment_donation';
41 public $table_element =
'payment_donation';
46 public $picto =
'payment';
64 public $amounts = array();
66 public $fk_typepayment;
83 public $fk_user_creat;
88 public $fk_user_modif;
100 public $bank_account;
106 public $ext_payment_id;
111 public $ext_payment_site;
131 public function create($user, $notrigger = 0)
139 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
144 if (isset($this->chid)) {
145 $this->chid = (int) $this->chid;
146 } elseif (isset($this->fk_donation)) {
149 $this->chid = (int) $this->fk_donation;
151 if (isset($this->fk_donation)) {
152 $this->fk_donation = (int) $this->fk_donation;
154 if (isset($this->amount)) {
155 $this->amount = trim($this->amount);
157 if (isset($this->fk_typepayment)) {
158 $this->fk_typepayment = trim($this->fk_typepayment);
160 if (isset($this->num_payment)) {
161 $this->num_payment = trim($this->num_payment);
163 if (isset($this->note_public)) {
164 $this->note_public = trim($this->note_public);
166 if (isset($this->fk_bank)) {
167 $this->fk_bank = (int) $this->fk_bank;
169 if (isset($this->fk_user_creat)) {
170 $this->fk_user_creat = (int) $this->fk_user_creat;
172 if (isset($this->fk_user_modif)) {
173 $this->fk_user_modif = (int) $this->fk_user_modif;
177 foreach ($this->amounts as $key => $value) {
179 $this->amounts[$key] = $newvalue;
180 $totalamount += $newvalue;
185 if ($totalamount == 0) {
192 if ($totalamount != 0) {
193 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
194 $sql .=
" fk_typepayment, num_payment, note, ext_payment_id, ext_payment_site,";
195 $sql .=
" fk_user_creat, fk_bank)";
196 $sql .=
" VALUES (".((int) $this->chid).
", '".$this->db->idate($now).
"',";
197 $sql .=
" '".$this->db->idate($this->datep).
"',";
198 $sql .=
" ".((float)
price2num($totalamount)).
",";
199 $sql .=
" ".((int) $this->paymenttype).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ";
200 $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").
",";
201 $sql .=
" ".((int) $user->id).
", 0)";
203 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
204 $resql = $this->db->query($sql);
206 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
207 $this->
ref = (string) $this->
id;
213 if (!$error && !$notrigger) {
215 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
222 if ($totalamount != 0 && !$error) {
223 $this->amount = $totalamount;
224 $this->total = $totalamount;
228 $this->error = $this->db->error();
229 $this->db->rollback();
245 $sql .=
" t.fk_donation,";
249 $sql .=
" t.amount,";
250 $sql .=
" t.fk_typepayment,";
251 $sql .=
" t.num_payment,";
252 $sql .=
" t.note as note_public,";
253 $sql .=
" t.fk_bank,";
254 $sql .=
" t.fk_user_creat,";
255 $sql .=
" t.fk_user_modif,";
256 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
257 $sql .=
' b.fk_account';
258 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
259 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
260 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
261 $sql .=
" WHERE t.rowid = ".((int) $id);
263 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
264 $resql = $this->db->query($sql);
266 if ($this->db->num_rows($resql)) {
267 $obj = $this->db->fetch_object($resql);
269 $this->
id = $obj->rowid;
270 $this->
ref = $obj->rowid;
272 $this->fk_donation = $obj->fk_donation;
273 $this->datec = $this->db->jdate($obj->datec);
274 $this->tms = $this->db->jdate($obj->tms);
275 $this->datep = $this->db->jdate($obj->datep);
276 $this->amount = $obj->amount;
277 $this->fk_typepayment = $obj->fk_typepayment;
278 $this->paymenttype = $obj->fk_typepayment;
279 $this->num_payment = $obj->num_payment;
280 $this->note_public = $obj->note_public;
281 $this->fk_bank = $obj->fk_bank;
282 $this->fk_user_creat = $obj->fk_user_creat;
283 $this->fk_user_modif = $obj->fk_user_modif;
285 $this->type_code = $obj->type_code;
286 $this->type_label = $obj->type_label;
288 $this->bank_account = $obj->fk_account;
289 $this->bank_line = $obj->fk_bank;
291 $this->db->free($resql);
295 $this->error =
"Error ".$this->db->lasterror();
308 public function update($user, $notrigger = 0)
310 global $conf, $langs;
315 if (isset($this->fk_donation)) {
316 $this->fk_donation = (int) $this->fk_donation;
318 if (isset($this->amount)) {
319 $this->amount = trim($this->amount);
321 if (isset($this->fk_typepayment)) {
322 $this->fk_typepayment = trim($this->fk_typepayment);
324 if (isset($this->num_payment)) {
325 $this->num_payment = trim($this->num_payment);
327 if (isset($this->note_public)) {
328 $this->note_public = trim($this->note_public);
330 if (isset($this->fk_bank)) {
331 $this->fk_bank = (int) $this->fk_bank;
333 if (isset($this->fk_user_creat)) {
334 $this->fk_user_creat = (int) $this->fk_user_creat;
336 if (isset($this->fk_user_modif)) {
337 $this->fk_user_modif = (int) $this->fk_user_modif;
344 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
345 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
346 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
347 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
348 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
349 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
350 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
351 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
352 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
353 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
354 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
355 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
356 $sql .=
" WHERE rowid=".(int) $this->
id;
360 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
361 $resql = $this->db->query($sql);
364 $this->errors[] =
"Error ".$this->db->lasterror();
369 if (!$error && !$notrigger) {
371 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
382 foreach ($this->errors as $errmsg) {
383 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
384 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
386 $this->db->rollback();
402 public function delete($user, $notrigger = 0)
404 global $conf, $langs;
410 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
411 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
413 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
414 $resql = $this->db->query($sql);
417 $this->errors[] =
"Error ".$this->db->lasterror();
422 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
423 $sql .=
" WHERE rowid=".((int) $this->
id);
425 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
426 $resql = $this->db->query($sql);
429 $this->errors[] =
"Error ".$this->db->lasterror();
435 if (!$error && !$notrigger) {
437 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
448 foreach ($this->errors as $errmsg) {
449 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
450 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
452 $this->db->rollback();
486 $object->context[
'createfromclone'] =
'createfromclone';
487 $result =
$object->create($user);
498 unset(
$object->context[
'createfromclone']);
505 $this->db->rollback();
550 $this->fk_donation = 0;
555 $this->fk_typepayment =
'';
556 $this->paymenttype =
'';
557 $this->num_payment =
'';
558 $this->note_public =
'';
560 $this->fk_user_creat =
dol_now();
561 $this->fk_user_modif =
dol_now();
579 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
585 if (isModEnabled(
"bank")) {
586 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
589 $acc->fetch($accountid);
592 if ($mode ==
'payment_donation') {
596 $bank_line_id = $acc->addline(
610 if ($bank_line_id > 0) {
619 if ($mode ==
'payment_donation') {
620 $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
623 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
630 $this->error = $acc->error;
653 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
655 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
656 $result = $this->db->query($sql);
660 $this->error = $this->db->error();
674 global $langs, $hookmanager;
678 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
680 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
682 if (!empty($this->
id)) {
683 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
687 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
689 if ($withpicto && $withpicto != 2) {
692 if ($withpicto != 2) {
693 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
698 $hookmanager->initHooks(array($this->element .
'dao'));
699 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
700 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
702 $result = $hookmanager->resPrint;
704 $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 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_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...