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)) $this->fk_expensereport = trim($this->fk_expensereport);
123 if (isset($this->amount)) $this->amount = trim($this->amount);
124 if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
125 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
126 if (isset($this->
note)) $this->
note = trim($this->
note);
127 if (isset($this->note_public)) $this->note_public = trim($this->note_public);
128 if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank);
129 if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat);
130 if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif);
133 foreach ($this->amounts as $key => $value)
136 $this->amounts[$key] = $newvalue;
137 $totalamount += $newvalue;
142 if ($totalamount == 0)
return -1;
147 if ($totalamount != 0)
149 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_expensereport (fk_expensereport, datec, datep, amount,";
150 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
151 $sql .=
" VALUES ($this->fk_expensereport, '".$this->db->idate($now).
"',";
152 $sql .=
" '".$this->db->idate($this->datepaid).
"',";
153 $sql .=
" ".$totalamount.
",";
154 $sql .=
" ".$this->fk_typepayment.
", '".$this->
db->escape($this->num_payment).
"', '".$this->
db->escape($this->note_public).
"', ".$user->id.
",";
157 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
161 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"payment_expensereport");
167 if ($totalamount != 0 && !$error)
169 $this->amount = $totalamount;
173 $this->error = $this->
db->error();
174 $this->
db->rollback();
189 $sql .=
" t.fk_expensereport,";
193 $sql .=
" t.amount,";
194 $sql .=
" t.fk_typepayment,";
195 $sql .=
" t.num_payment,";
196 $sql .=
" t.note as note_public,";
197 $sql .=
" t.fk_bank,";
198 $sql .=
" t.fk_user_creat,";
199 $sql .=
" t.fk_user_modif,";
200 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
201 $sql .=
' b.fk_account';
202 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as t";
203 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
204 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
205 $sql .=
" WHERE t.rowid = ".$id;
207 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
213 $obj = $this->
db->fetch_object(
$resql);
215 $this->
id = $obj->rowid;
216 $this->ref = $obj->rowid;
218 $this->fk_expensereport = $obj->fk_expensereport;
219 $this->datec = $this->
db->jdate($obj->datec);
220 $this->tms = $this->
db->jdate($obj->tms);
221 $this->datep = $this->
db->jdate($obj->datep);
222 $this->amount = $obj->amount;
223 $this->fk_typepayment = $obj->fk_typepayment;
224 $this->num_payment = $obj->num_payment;
225 $this->note_public = $obj->note_public;
226 $this->fk_bank = $obj->fk_bank;
227 $this->fk_user_creat = $obj->fk_user_creat;
228 $this->fk_user_modif = $obj->fk_user_modif;
230 $this->type_code = $obj->type_code;
231 $this->type_label = $obj->type_label;
233 $this->bank_account = $obj->fk_account;
234 $this->bank_line = $obj->fk_bank;
240 $this->error =
"Error ".$this->db->lasterror();
253 public function update($user = null, $notrigger = 0)
256 global $conf, $langs;
261 if (isset($this->fk_expensereport)) $this->fk_expensereport = trim($this->fk_expensereport);
262 if (isset($this->amount)) $this->amount = trim($this->amount);
263 if (isset($this->fk_typepayment)) $this->fk_typepayment = trim($this->fk_typepayment);
264 if (isset($this->num_payment)) $this->num_payment = trim($this->num_payment);
265 if (isset($this->
note)) $this->
note = trim($this->
note);
266 if (isset($this->fk_bank)) $this->fk_bank = trim($this->fk_bank);
267 if (isset($this->fk_user_creat)) $this->fk_user_creat = trim($this->fk_user_creat);
268 if (isset($this->fk_user_modif)) $this->fk_user_modif = trim($this->fk_user_modif);
275 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET";
277 $sql .=
" fk_expensereport=".(isset($this->fk_expensereport) ? $this->fk_expensereport :
"null").
",";
278 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
279 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
280 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
281 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
282 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
283 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
284 $sql .=
" note=".(isset($this->
note) ?
"'".$this->db->escape($this->
note).
"'" :
"null").
",";
285 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
286 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
287 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null").
"";
290 $sql .=
" WHERE rowid=".$this->id;
294 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
296 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
301 foreach ($this->errors as $errmsg)
303 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
304 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
306 $this->
db->rollback();
322 public function delete($user, $notrigger = 0)
325 global $conf, $langs;
332 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
333 $sql .=
" WHERE type='payment_expensereport' AND url_id=".$this->id;
335 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
337 if (!
$resql) { $error++; $this->errors[] =
"Error ".$this->db->lasterror(); }
342 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_expensereport";
343 $sql .=
" WHERE rowid=".$this->id;
345 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
349 $this->errors[] =
"Error ".$this->db->lasterror();
356 foreach ($this->errors as $errmsg)
358 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
359 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
361 $this->
db->rollback();
387 $object->fetch($fromid);
395 $object->context[
'createfromclone'] =
'createfromclone';
396 $result = $object->create($user);
401 $this->error = $object->error;
405 unset($object->context[
'createfromclone']);
413 $this->
db->rollback();
458 $this->fk_expensereport =
'';
463 $this->fk_typepayment =
'';
464 $this->num_payment =
'';
467 $this->fk_user_creat =
'';
468 $this->fk_user_modif =
'';
484 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
486 global $langs, $conf;
490 if (!empty($conf->banque->enabled))
492 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
495 $acc->fetch($accountid);
498 $total = $this->amount;
500 if ($mode ==
'payment_expensereport') $amount = $total;
503 $bank_line_id = $acc->addline(
505 $this->fk_typepayment,
517 if ($bank_line_id > 0)
528 if ($mode ==
'payment_expensereport') $url = DOL_URL_ROOT.
'/expensereport/payment/card.php?rowid=';
531 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
542 foreach ($this->amounts as $key => $value)
544 if ($mode ==
'payment_expensereport')
546 $fuser =
new User($this->
db);
549 $result = $acc->add_url_line(
552 DOL_URL_ROOT.
'/user/card.php?id=',
553 $fuser->getFullName($langs),
558 $this->error = $this->
db->lasterror();
559 dol_syslog(get_class($this).
'::addPaymentToBank '.$this->error);
566 $this->error = $acc->error;
590 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET fk_bank = ".$id_bank.
" WHERE rowid = ".$this->id;
592 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
593 $result = $this->
db->query($sql);
598 $this->error = $this->
db->error();
616 if (empty($this->ref)) $this->ref = $this->label;
617 $label = $langs->trans(
"ShowPayment").
': '.$this->ref;
619 if (!empty($this->
id))
621 $link =
'<a href="'.DOL_URL_ROOT.
'/expensereport/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
624 if ($withpicto) $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
625 if ($withpicto && $withpicto != 2) $result .=
' ';
626 if ($withpicto != 2) $result .= $link.($maxlen ?
dol_trunc($this->ref, $maxlen) : $this->ref).$linkend;
640 $sql =
'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
641 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_expensereport as e';
642 $sql .=
' WHERE e.rowid = '.$id;
644 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
645 $result = $this->
db->query($sql);
649 if ($this->
db->num_rows($result))
651 $obj = $this->
db->fetch_object($result);
652 $this->
id = $obj->rowid;
653 if ($obj->fk_user_creat)
655 $cuser =
new User($this->
db);
656 $cuser->fetch($obj->fk_user_creat);
657 $this->user_creation = $cuser;
659 if ($obj->fk_user_modif)
661 $muser =
new User($this->
db);
662 $muser->fetch($obj->fk_user_modif);
663 $this->user_modification = $muser;
665 $this->date_creation = $this->
db->jdate($obj->datec);
666 $this->date_modification = $this->
db->jdate($obj->tms);
668 $this->
db->free($result);
initAsSpecimen()
Initialise an instance with random values.
fetch($id)
Load object in memory from database.
update_fk_bank($id_bank)
Update link between the expense report payment and the generated line in llx_bank.
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update($user=null, $notrigger=0)
Update database.
$conf db
API class for accounts.
Class to manage bank accounts.
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
info($id)
Tab information on object.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
LibStatut($status, $mode=0)
Renvoi le libelle d'un statut donne.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
getLibStatut($mode=0)
Retourne le libelle du statut d'un don (brouillon, validee, abandonnee, payee)
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...
create($user)
Create payment of expense report into database.
Class to manage payments of expense report.
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.
__construct($db)
Constructor.
Parent class of all other business classes (invoices, contracts, proposals, orders, ...)
if(!empty($search_group)) natural_search(array("g.nom"g note
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...