24 require_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();
79 public $fk_user_creat;
84 public $fk_user_modif;
114 public function create($user, $notrigger =
false)
116 global $conf, $langs;
123 if (!$this->datepaid)
125 $this->error =
'ErrorBadValueForParameterCreatePaymentDonation';
130 if (isset($this->fk_donation)) $this->fk_donation = (int) $this->fk_donation;
131 if (isset($this->amount)) $this->amount = trim($this->amount);
132 if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
133 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
134 if (isset($this->note_public)) $this->note_public = trim($this->note_public);
135 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
136 if (isset($this->fk_user_creat)) $this->fk_user_creat = (
int) $this->fk_user_creat;
137 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
140 foreach ($this->amounts as $key => $value)
143 $this->amounts[$key] = $newvalue;
144 $totalamount += $newvalue;
149 if ($totalamount == 0)
return -1;
154 if ($totalamount != 0)
156 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_donation (fk_donation, datec, datep, amount,";
157 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
158 $sql .=
" VALUES ($this->chid, '".$this->db->idate($now).
"',";
159 $sql .=
" '".$this->db->idate($this->datepaid).
"',";
160 $sql .=
" ".$totalamount.
",";
161 $sql .=
" ".$this->paymenttype.
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_public).
"', ".$user->id.
",";
164 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
168 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_donation");
169 $this->ref = $this->id;
175 if (!$error && !$notrigger)
178 $result = $this->
call_trigger(
'DONATION_PAYMENT_CREATE', $user);
179 if ($result < 0) { $error++; }
183 if ($totalamount != 0 && !$error)
185 $this->amount = $totalamount;
186 $this->total = $totalamount;
190 $this->error = $this->
db->error();
191 $this->
db->rollback();
207 $sql .=
" t.fk_donation,";
211 $sql .=
" t.amount,";
212 $sql .=
" t.fk_typepayment,";
213 $sql .=
" t.num_payment,";
214 $sql .=
" t.note as note_public,";
215 $sql .=
" t.fk_bank,";
216 $sql .=
" t.fk_user_creat,";
217 $sql .=
" t.fk_user_modif,";
218 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
219 $sql .=
' b.fk_account';
220 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_donation as t";
221 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
222 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
223 $sql .=
" WHERE t.rowid = ".$id;
225 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
231 $obj = $this->
db->fetch_object(
$resql);
233 $this->
id = $obj->rowid;
234 $this->ref = $obj->rowid;
236 $this->fk_donation = $obj->fk_donation;
237 $this->datec = $this->
db->jdate($obj->datec);
238 $this->tms = $this->
db->jdate($obj->tms);
239 $this->datep = $this->
db->jdate($obj->datep);
240 $this->amount = $obj->amount;
241 $this->fk_typepayment = $obj->fk_typepayment;
242 $this->num_payment = $obj->num_payment;
243 $this->note_public = $obj->note_public;
244 $this->fk_bank = $obj->fk_bank;
245 $this->fk_user_creat = $obj->fk_user_creat;
246 $this->fk_user_modif = $obj->fk_user_modif;
248 $this->type_code = $obj->type_code;
249 $this->type_label = $obj->type_label;
251 $this->bank_account = $obj->fk_account;
252 $this->bank_line = $obj->fk_bank;
258 $this->error =
"Error ".$this->db->lasterror();
271 public function update($user, $notrigger = 0)
273 global $conf, $langs;
278 if (isset($this->fk_donation)) $this->fk_donation = (int) $this->fk_donation;
279 if (isset($this->amount)) $this->amount = trim($this->amount);
280 if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
281 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
282 if (isset($this->note_public)) $this->note_public = trim($this->note_public);
283 if (isset($this->fk_bank)) $this->fk_bank = (
int) $this->fk_bank;
284 if (isset($this->fk_user_creat)) $this->fk_user_creat = (
int) $this->fk_user_creat;
285 if (isset($this->fk_user_modif)) $this->fk_user_modif = (
int) $this->fk_user_modif;
291 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET";
292 $sql .=
" fk_donation=".(isset($this->fk_donation) ? $this->fk_donation :
"null").
",";
293 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
294 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
295 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
296 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
297 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
298 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
299 $sql .=
" note=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
300 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
301 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
302 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
"";
303 $sql .=
" WHERE rowid=".(int) $this->
id;
307 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
311 $this->errors[] =
"Error ".$this->db->lasterror();
318 if (!$error && !$notrigger)
321 $result = $this->
call_trigger(
'DONATION_PAYMENT_MODIFY', $user);
322 if ($result < 0) { $error++; }
331 foreach ($this->errors as $errmsg)
333 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
334 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
336 $this->
db->rollback();
352 public function delete($user, $notrigger = 0)
354 global $conf, $langs;
361 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
362 $sql .=
" WHERE type='payment_donation' AND url_id=".(int) $this->
id;
364 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
366 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
371 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_donation";
372 $sql .=
" WHERE rowid=".$this->id;
374 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
378 $this->errors[] =
"Error ".$this->db->lasterror();
386 if (!$error && !$notrigger)
389 $result = $this->
call_trigger(
'DONATION_PAYMENT_DELETE', $user);
390 if ($result < 0) { $error++; }
399 foreach ($this->errors as $errmsg)
401 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
402 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
404 $this->
db->rollback();
430 $object->fetch($fromid);
438 $object->context[
'createfromclone'] =
'createfromclone';
439 $result = $object->create($user);
444 $this->error = $object->error;
452 unset($object->context[
'createfromclone']);
460 $this->
db->rollback();
505 $this->fk_donation =
'';
510 $this->fk_typepayment =
'';
511 $this->num_payment =
'';
512 $this->note_public =
'';
514 $this->fk_user_creat =
'';
515 $this->fk_user_modif =
'';
531 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
537 if (!empty($conf->banque->enabled))
539 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
542 $acc->fetch($accountid);
545 if ($mode ==
'payment_donation') $amount =
$total;
548 $bank_line_id = $acc->addline(
562 if ($bank_line_id > 0)
573 if ($mode ==
'payment_donation') $url = DOL_URL_ROOT.
'/don/payment/card.php?rowid=';
576 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
584 $this->error = $acc->error;
608 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_donation SET fk_bank = ".(int) $id_bank.
" WHERE rowid = ".(
int) $this->id;
610 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
611 $result = $this->
db->query($sql);
616 $this->error = $this->
db->error();
634 $label =
'<u>'.$langs->trans(
"DonationPayment").
'</u>';
636 $label .=
'<b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
638 if (!empty($this->
id))
640 $link =
'<a href="'.DOL_URL_ROOT.
'/don/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
643 if ($withpicto) $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
644 if ($withpicto && $withpicto != 2) $result .=
' ';
645 if ($withpicto != 2) $result .= $link.($maxlen ?
dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
create($user, $notrigger=false)
Create payment of donation into database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
$conf db
API class for accounts.
Class to manage bank accounts.
update($user, $notrigger=0)
Update database.
fetch($id)
Load object in memory from database.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
Class to manage payments of donations.
update_fk_bank($id_bank)
Update link between the donation payment and the generated line in llx_bank.
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...
call_trigger($triggerName, $user)
Call trigger based on this instance.
initAsSpecimen()
Initialise an instance with random values.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $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.
getLibStatut($mode=0)
Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
__construct($db)
Constructor.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...