25 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 public $element =
'payment_expensereport';
41 public $table_element =
'payment_expensereport';
46 public $picto =
'payment';
56 public $fk_expensereport;
62 public $amounts = array();
67 public $fk_typepayment;
79 public $fk_user_creat;
84 public $fk_user_modif;
109 global $conf, $langs;
116 if (!$this->datepaid) {
117 $this->error =
'ErrorBadValueForParameterCreatePaymentExpenseReport';
122 if (isset($this->fk_expensereport)) {
123 $this->fk_expensereport = trim($this->fk_expensereport);
125 if (isset($this->amount)) {
126 $this->amount = trim($this->amount);
128 if (isset($this->fk_typepayment)) {
129 $this->fk_typepayment = trim($this->fk_typepayment);
131 if (isset($this->num_payment)) {
132 $this->num_payment = trim($this->num_payment);
134 if (isset($this->note)) {
135 $this->note = trim($this->note);
137 if (isset($this->note_public)) {
138 $this->note_public = trim($this->note_public);
140 if (isset($this->note_private)) {
141 $this->note_private = trim($this->note_private);
143 if (isset($this->fk_bank)) {
144 $this->fk_bank = ((int) $this->fk_bank);
146 if (isset($this->fk_user_creat)) {
147 $this->fk_user_creat = ((int) $this->fk_user_creat);
149 if (isset($this->fk_user_modif)) {
150 $this->fk_user_modif = ((int) $this->fk_user_modif);
154 foreach ($this->amounts as $key => $value) {
156 $this->amounts[$key] = $newvalue;
157 $totalamount += $newvalue;
162 if ($totalamount == 0) {
169 if ($totalamount != 0) {
170 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_expensereport (fk_expensereport, datec, datep, amount,";
171 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
172 $sql .=
" VALUES ($this->fk_expensereport, '".$this->db->idate($now).
"',";
173 $sql .=
" '".$this->db->idate($this->datepaid).
"',";
174 $sql .=
" ".price2num($totalamount).
",";
175 $sql .=
" ".((int) $this->fk_typepayment).
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_public).
"', ".((int) $user->id).
",";
178 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
181 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_expensereport");
187 if ($totalamount != 0 && !$error) {
188 $this->amount = $totalamount;
192 $this->error = $this->
db->error();
193 $this->
db->rollback();
208 $sql .=
" t.fk_expensereport,";
212 $sql .=
" t.amount,";
213 $sql .=
" t.fk_typepayment,";
214 $sql .=
" t.num_payment,";
215 $sql .=
" t.note as note_public,";
216 $sql .=
" t.fk_bank,";
217 $sql .=
" t.fk_user_creat,";
218 $sql .=
" t.fk_user_modif,";
219 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
220 $sql .=
' b.fk_account';
221 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as t";
222 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
223 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
224 $sql .=
" WHERE t.rowid = ".((int) $id);
226 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
230 $obj = $this->
db->fetch_object(
$resql);
232 $this->
id = $obj->rowid;
233 $this->
ref = $obj->rowid;
235 $this->fk_expensereport = $obj->fk_expensereport;
236 $this->datec = $this->
db->jdate($obj->datec);
237 $this->tms = $this->
db->jdate($obj->tms);
238 $this->datep = $this->
db->jdate($obj->datep);
239 $this->amount = $obj->amount;
240 $this->fk_typepayment = $obj->fk_typepayment;
241 $this->num_payment = $obj->num_payment;
242 $this->note_public = $obj->note_public;
243 $this->fk_bank = $obj->fk_bank;
244 $this->fk_user_creat = $obj->fk_user_creat;
245 $this->fk_user_modif = $obj->fk_user_modif;
247 $this->type_code = $obj->type_code;
248 $this->type_label = $obj->type_label;
250 $this->bank_account = $obj->fk_account;
251 $this->bank_line = $obj->fk_bank;
257 $this->error =
"Error ".$this->db->lasterror();
270 public function update($user =
null, $notrigger = 0)
273 global $conf, $langs;
278 if (isset($this->fk_expensereport)) {
279 $this->fk_expensereport = trim($this->fk_expensereport);
281 if (isset($this->amount)) {
282 $this->amount = trim($this->amount);
284 if (isset($this->fk_typepayment)) {
285 $this->fk_typepayment = trim($this->fk_typepayment);
287 if (isset($this->num_payment)) {
288 $this->num_payment = trim($this->num_payment);
290 if (isset($this->note)) {
291 $this->note = trim($this->note);
293 if (isset($this->fk_bank)) {
294 $this->fk_bank = trim($this->fk_bank);
296 if (isset($this->fk_user_creat)) {
297 $this->fk_user_creat = trim($this->fk_user_creat);
299 if (isset($this->fk_user_modif)) {
300 $this->fk_user_modif = trim($this->fk_user_modif);
308 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET";
310 $sql .=
" fk_expensereport=".(isset($this->fk_expensereport) ? $this->fk_expensereport :
"null").
",";
311 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
312 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
313 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
314 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
315 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
316 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
317 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
318 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
319 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
320 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
323 $sql .=
" WHERE rowid=".((int) $this->
id);
327 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
330 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
335 foreach ($this->errors as $errmsg) {
336 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
337 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
339 $this->
db->rollback();
355 public function delete($user, $notrigger = 0)
358 global $conf, $langs;
364 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
365 $sql .=
" WHERE type='payment_expensereport' AND url_id=".((int) $this->
id);
367 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
370 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
375 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_expensereport";
376 $sql .=
" WHERE rowid=".((int) $this->
id);
378 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
382 $this->errors[] =
"Error ".$this->db->lasterror();
388 foreach ($this->errors as $errmsg) {
389 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
390 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
392 $this->
db->rollback();
418 $object->fetch($fromid);
426 $object->context[
'createfromclone'] =
'createfromclone';
427 $result = $object->create($user);
431 $this->error = $object->error;
435 unset($object->context[
'createfromclone']);
442 $this->
db->rollback();
487 $this->fk_expensereport =
'';
492 $this->fk_typepayment =
'';
493 $this->num_payment =
'';
496 $this->fk_user_creat =
'';
497 $this->fk_user_modif =
'';
513 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
515 global $langs, $conf;
520 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
523 $acc->fetch($accountid);
526 $total = $this->amount;
528 if ($mode ==
'payment_expensereport') {
533 $bank_line_id = $acc->addline(
535 $this->fk_typepayment,
547 if ($bank_line_id > 0) {
556 if ($mode ==
'payment_expensereport') {
557 $url = DOL_URL_ROOT.
'/expensereport/payment/card.php?rowid=';
560 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
569 foreach ($this->amounts as $key => $value) {
570 if ($mode ==
'payment_expensereport') {
571 $fuser =
new User($this->
db);
574 $result = $acc->add_url_line(
577 DOL_URL_ROOT.
'/user/card.php?id=',
578 $fuser->getFullName($langs),
582 $this->error = $this->
db->lasterror();
583 dol_syslog(get_class($this).
'::addPaymentToBank '.$this->error);
590 $this->error = $acc->error;
591 $this->errors = $acc->errors;
614 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
616 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
617 $result = $this->
db->query($sql);
621 $this->error = $this->
db->error();
635 global $langs, $hookmanager;
639 if (empty($this->
ref)) {
640 $this->
ref = $this->label;
642 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Payment").
'</u>';
643 if (isset($this->status)) {
644 $label .=
' '.$this->getLibStatut(5);
646 if (!empty($this->
ref)) {
647 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
649 if (!empty($this->datep)) {
650 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'dayhour');
653 if (!empty($this->
id)) {
654 $link =
'<a href="'.DOL_URL_ROOT.
'/expensereport/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
658 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
660 if ($withpicto && $withpicto != 2) {
663 if ($withpicto != 2) {
664 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
668 $hookmanager->initHooks(array($this->element .
'dao'));
669 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
670 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
672 $result = $hookmanager->resPrint;
674 $result .= $hookmanager->resPrint;
687 $sql =
'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
688 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_expensereport as e';
689 $sql .=
' WHERE e.rowid = '.((int) $id);
691 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
692 $result = $this->
db->query($sql);
695 if ($this->
db->num_rows($result)) {
696 $obj = $this->
db->fetch_object($result);
697 $this->
id = $obj->rowid;
698 if ($obj->fk_user_creat) {
699 $cuser =
new User($this->
db);
700 $cuser->fetch($obj->fk_user_creat);
701 $this->user_creation = $cuser;
703 if ($obj->fk_user_modif) {
704 $muser =
new User($this->
db);
705 $muser->fetch($obj->fk_user_modif);
706 $this->user_modification = $muser;
708 $this->date_creation = $this->
db->jdate($obj->datec);
709 $this->date_modification = $this->
db->jdate($obj->tms);
711 $this->
db->free($result);
Class to manage bank accounts.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
Class to manage payments of expense report.
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.
fetch($id)
Load object in memory from database.
create($user)
Create payment of expense report into database.
__construct($db)
Constructor.
info($id)
Tab information on object.
getLibStatut($mode=0)
Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
initAsSpecimen()
Initialise an instance with random values.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update($user=null, $notrigger=0)
Update database.
update_fk_bank($id_bank)
Update link between the expense report payment and the generated line in llx_bank.
Class to manage Dolibarr users.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
$conf db
API class for accounts.