25require_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;
124 global $conf, $langs;
131 $this->error =
'ErrorBadValueForParameterCreatePaymentExpenseReport';
136 if (isset($this->fk_expensereport)) {
137 $this->fk_expensereport = trim($this->fk_expensereport);
139 if (isset($this->amount)) {
140 $this->amount = trim($this->amount);
142 if (isset($this->fk_typepayment)) {
143 $this->fk_typepayment = trim($this->fk_typepayment);
145 if (isset($this->num_payment)) {
146 $this->num_payment = trim($this->num_payment);
148 if (isset($this->note)) {
149 $this->note = trim($this->note);
151 if (isset($this->note_public)) {
152 $this->note_public = trim($this->note_public);
154 if (isset($this->note_private)) {
155 $this->note_private = trim($this->note_private);
157 if (isset($this->fk_bank)) {
158 $this->fk_bank = ((int) $this->fk_bank);
160 if (isset($this->fk_user_creat)) {
161 $this->fk_user_creat = ((int) $this->fk_user_creat);
163 if (isset($this->fk_user_modif)) {
164 $this->fk_user_modif = ((int) $this->fk_user_modif);
168 foreach ($this->amounts as $key => $value) {
170 $this->amounts[$key] = $newvalue;
171 $totalamount += $newvalue;
176 if ($totalamount == 0) {
183 if ($totalamount != 0) {
184 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_expensereport (fk_expensereport, datec, datep, amount,";
185 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
186 $sql .=
" VALUES ($this->fk_expensereport, '".$this->db->idate($now).
"',";
187 $sql .=
" '".$this->db->idate($this->datep).
"',";
188 $sql .=
" ".price2num($totalamount).
",";
189 $sql .=
" ".((int) $this->fk_typepayment).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ".((int) $user->id).
",";
192 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
193 $resql = $this->db->query($sql);
195 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_expensereport");
201 if ($totalamount != 0 && !$error) {
202 $this->amount = $totalamount;
206 $this->error = $this->db->error();
207 $this->db->rollback();
222 $sql .=
" t.fk_expensereport,";
226 $sql .=
" t.amount,";
227 $sql .=
" t.fk_typepayment,";
228 $sql .=
" t.num_payment,";
229 $sql .=
" t.note as note_public,";
230 $sql .=
" t.fk_bank,";
231 $sql .=
" t.fk_user_creat,";
232 $sql .=
" t.fk_user_modif,";
233 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
234 $sql .=
' b.fk_account';
235 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as t";
236 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
237 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
238 $sql .=
" WHERE t.rowid = ".((int) $id);
240 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
241 $resql = $this->db->query($sql);
243 if ($this->db->num_rows($resql)) {
244 $obj = $this->db->fetch_object($resql);
246 $this->
id = $obj->rowid;
247 $this->
ref = $obj->rowid;
249 $this->fk_expensereport = $obj->fk_expensereport;
250 $this->datec = $this->db->jdate($obj->datec);
251 $this->tms = $this->db->jdate($obj->tms);
252 $this->datep = $this->db->jdate($obj->datep);
253 $this->amount = $obj->amount;
254 $this->fk_typepayment = $obj->fk_typepayment;
255 $this->num_payment = $obj->num_payment;
256 $this->note_public = $obj->note_public;
257 $this->fk_bank = $obj->fk_bank;
258 $this->fk_user_creat = $obj->fk_user_creat;
259 $this->fk_user_modif = $obj->fk_user_modif;
261 $this->type_code = $obj->type_code;
262 $this->type_label = $obj->type_label;
264 $this->bank_account = $obj->fk_account;
265 $this->bank_line = $obj->fk_bank;
267 $this->db->free($resql);
271 $this->error =
"Error ".$this->db->lasterror();
284 public function update($user =
null, $notrigger = 0)
287 global $conf, $langs;
292 if (isset($this->fk_expensereport)) {
293 $this->fk_expensereport = trim($this->fk_expensereport);
295 if (isset($this->amount)) {
296 $this->amount = trim($this->amount);
298 if (isset($this->fk_typepayment)) {
299 $this->fk_typepayment = trim($this->fk_typepayment);
301 if (isset($this->num_payment)) {
302 $this->num_payment = trim($this->num_payment);
304 if (isset($this->note)) {
305 $this->note = trim($this->note);
307 if (isset($this->fk_bank)) {
308 $this->fk_bank = trim($this->fk_bank);
310 if (isset($this->fk_user_creat)) {
311 $this->fk_user_creat = trim($this->fk_user_creat);
313 if (isset($this->fk_user_modif)) {
314 $this->fk_user_modif = trim($this->fk_user_modif);
322 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET";
324 $sql .=
" fk_expensereport=".(isset($this->fk_expensereport) ? $this->fk_expensereport :
"null").
",";
325 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
326 $sql .=
" tms=".(dol_strlen($this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
327 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
328 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
329 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
330 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
331 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
332 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
333 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
334 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
337 $sql .=
" WHERE rowid=".((int) $this->
id);
341 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
342 $resql = $this->db->query($sql);
345 $this->errors[] =
"Error ".$this->db->lasterror();
350 foreach ($this->errors as $errmsg) {
351 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
352 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
354 $this->db->rollback();
370 public function delete($user, $notrigger = 0)
373 global $conf, $langs;
379 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
380 $sql .=
" WHERE type='payment_expensereport' AND url_id=".((int) $this->
id);
382 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
383 $resql = $this->db->query($sql);
386 $this->errors[] =
"Error ".$this->db->lasterror();
391 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_expensereport";
392 $sql .=
" WHERE rowid=".((int) $this->
id);
394 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
395 $resql = $this->db->query($sql);
398 $this->errors[] =
"Error ".$this->db->lasterror();
404 foreach ($this->errors as $errmsg) {
405 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
406 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
408 $this->db->rollback();
434 $object->fetch($fromid);
442 $object->context[
'createfromclone'] =
'createfromclone';
443 $result = $object->create($user);
447 $this->error = $object->error;
451 unset($object->context[
'createfromclone']);
458 $this->db->rollback();
503 $this->fk_expensereport =
'';
508 $this->fk_typepayment =
'';
509 $this->num_payment =
'';
512 $this->fk_user_creat =
'';
513 $this->fk_user_modif =
'';
529 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
531 global $langs, $conf;
535 if (isModEnabled(
"banque")) {
536 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
539 $acc->fetch($accountid);
542 $total = $this->amount;
544 if ($mode ==
'payment_expensereport') {
549 $bank_line_id = $acc->addline(
551 $this->fk_typepayment,
563 if ($bank_line_id > 0) {
572 if ($mode ==
'payment_expensereport') {
573 $url = DOL_URL_ROOT.
'/expensereport/payment/card.php?rowid=';
576 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
585 foreach ($this->amounts as $key => $value) {
586 if ($mode ==
'payment_expensereport') {
587 $fuser =
new User($this->db);
590 $result = $acc->add_url_line(
593 DOL_URL_ROOT.
'/user/card.php?id=',
594 $fuser->getFullName($langs),
598 $this->error = $this->db->lasterror();
599 dol_syslog(get_class($this).
'::addPaymentToBank '.$this->error);
606 $this->error = $acc->error;
607 $this->errors = $acc->errors;
630 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
632 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
633 $result = $this->db->query($sql);
637 $this->error = $this->db->error();
651 global $langs, $hookmanager;
655 if (empty($this->
ref)) {
656 $this->
ref = $this->label;
658 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Payment").
'</u>';
659 if (isset($this->
status)) {
660 $label .=
' '.$this->getLibStatut(5);
662 if (!empty($this->
ref)) {
663 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
665 if (!empty($this->datep)) {
666 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'dayhour');
669 if (!empty($this->
id)) {
670 $link =
'<a href="'.DOL_URL_ROOT.
'/expensereport/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
674 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
676 if ($withpicto && $withpicto != 2) {
679 if ($withpicto != 2) {
680 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
684 $hookmanager->initHooks(array($this->element .
'dao'));
685 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
686 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
688 $result = $hookmanager->resPrint;
690 $result .= $hookmanager->resPrint;
703 $sql =
'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
704 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_expensereport as e';
705 $sql .=
' WHERE e.rowid = '.((int) $id);
707 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
708 $result = $this->db->query($sql);
711 if ($this->db->num_rows($result)) {
712 $obj = $this->db->fetch_object($result);
714 $this->
id = $obj->rowid;
716 $this->user_creation_id = $obj->fk_user_creat;
717 $this->user_modification_id = $obj->fk_user_modif;
718 $this->date_creation = $this->db->jdate($obj->datec);
719 $this->date_modification = $this->db->jdate($obj->tms);
721 $this->db->free($result);
738 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
740 $return =
'<div class="box-flex-item box-flex-grow-zero">';
741 $return .=
'<div class="info-box info-box-sm">';
742 $return .=
'<span class="info-box-icon bg-infobox-action">';
744 $return .=
'</span>';
745 $return .=
'<div class="info-box-content">';
746 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
747 if ($selected >= 0) {
748 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
750 if (property_exists($this,
'datep')) {
751 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'dayhour').
'</span>';
753 if (property_exists($this,
'fk_typepayment')) {
754 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Type").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
756 if (property_exists($this,
'fk_bank') && !is_null($this->fk_bank)) {
757 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Account").
'</span> : <span class="info-box-label">'.$this->fk_bank.
'</span>';
759 if (property_exists($this,
'amount')) {
760 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
762 if (method_exists($this,
'getLibStatut')) {
763 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
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)
Return the label of the status.
initAsSpecimen()
Initialise an instance with random values.
getKanbanView($option='', $arraydata=null)
Return clicable link of object (with eventually picto)
getNomUrl($withpicto=0, $maxlen=0)
Return clicable name (with picto eventually)
LibStatut($status, $mode=0)
Return the label of a given status.
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.
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...
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
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.
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...