27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
38 public $element =
'payment_expensereport';
43 public $table_element =
'payment_expensereport';
48 public $picto =
'payment';
58 public $fk_expensereport;
76 public $amounts = array();
81 public $fk_typepayment;
97 public $fk_user_creat;
102 public $fk_user_modif;
117 public $bank_account;
154 $this->error =
'ErrorBadValueForParameterCreatePaymentExpenseReport';
159 if (isset($this->fk_expensereport)) {
160 $this->fk_expensereport = (int) $this->fk_expensereport;
162 if (isset($this->amount)) {
163 $this->amount = (float) $this->amount;
165 if (isset($this->fk_typepayment)) {
166 $this->fk_typepayment = (int) $this->fk_typepayment;
168 if (isset($this->num_payment)) {
169 $this->num_payment = trim($this->num_payment);
171 if (isset($this->note)) {
172 $this->note = trim($this->note);
174 if (isset($this->note_public)) {
175 $this->note_public = trim($this->note_public);
177 if (isset($this->note_private)) {
178 $this->note_private = trim($this->note_private);
180 if (isset($this->fk_bank)) {
181 $this->fk_bank = ((int) $this->fk_bank);
183 if (isset($this->fk_user_creat)) {
184 $this->fk_user_creat = ((int) $this->fk_user_creat);
186 if (isset($this->fk_user_modif)) {
187 $this->fk_user_modif = ((int) $this->fk_user_modif);
191 foreach ($this->amounts as $key => $value) {
192 $newvalue = (float)
price2num($value,
'MT');
193 $this->amounts[$key] = $newvalue;
194 $totalamount += $newvalue;
199 if ($totalamount == 0) {
206 if ($totalamount != 0) {
207 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_expensereport (fk_expensereport, datec, datep, amount,";
208 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
209 $sql .=
" VALUES ($this->fk_expensereport, '".$this->db->idate($now).
"',";
210 $sql .=
" '".$this->db->idate($this->datep).
"',";
211 $sql .=
" ".price2num($totalamount).
",";
212 $sql .=
" ".((int) $this->fk_typepayment).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ".((int) $user->id).
",";
215 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
216 $resql = $this->db->query($sql);
218 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_expensereport");
224 if ($totalamount != 0 && !$error) {
225 $this->amount = $totalamount;
229 $this->error = $this->db->error();
230 $this->db->rollback();
245 $sql .=
" t.fk_expensereport,";
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_expensereport 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_expensereport = $obj->fk_expensereport;
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->num_payment = $obj->num_payment;
279 $this->note_public = $obj->note_public;
280 $this->fk_bank = $obj->fk_bank;
281 $this->fk_user_creat = $obj->fk_user_creat;
282 $this->fk_user_modif = $obj->fk_user_modif;
284 $this->type_code = $obj->type_code;
285 $this->type_label = $obj->type_label;
287 $this->bank_account = $obj->fk_account;
288 $this->bank_line = $obj->fk_bank;
290 $this->db->free($resql);
294 $this->error =
"Error ".$this->db->lasterror();
307 public function update($user =
null, $notrigger = 0)
314 if (isset($this->fk_expensereport)) {
315 $this->fk_expensereport = (int) $this->fk_expensereport;
317 if (isset($this->amount)) {
318 $this->amount = (float) $this->amount;
320 if (isset($this->fk_typepayment)) {
321 $this->fk_typepayment = (int) $this->fk_typepayment;
323 if (isset($this->num_payment)) {
324 $this->num_payment = trim($this->num_payment);
326 if (isset($this->note)) {
327 $this->note = trim($this->note);
329 if (isset($this->fk_bank)) {
330 $this->fk_bank = (int) $this->fk_bank;
332 if (isset($this->fk_user_creat)) {
333 $this->fk_user_creat = (int) $this->fk_user_creat;
335 if (isset($this->fk_user_modif)) {
336 $this->fk_user_modif = (int) $this->fk_user_modif;
340 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET";
341 $sql .=
" fk_expensereport=".(isset($this->fk_expensereport) ? $this->fk_expensereport :
"null").
",";
342 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
343 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
344 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
345 $sql .=
" amount=".(isset($this->amount) ? $this->amount :
"null").
",";
346 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? $this->fk_typepayment :
"null").
",";
347 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
348 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
349 $sql .=
" fk_bank=".(isset($this->fk_bank) ? $this->fk_bank :
"null").
",";
350 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? $this->fk_user_creat :
"null").
",";
351 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? $this->fk_user_modif :
"null");
352 $sql .=
" WHERE rowid=".((int) $this->
id);
356 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
357 $resql = $this->db->query($sql);
360 $this->errors[] =
"Error ".$this->db->lasterror();
365 foreach ($this->errors as $errmsg) {
366 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
367 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
369 $this->db->rollback();
385 public function delete($user, $notrigger = 0)
393 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
394 $sql .=
" WHERE type='payment_expensereport' AND url_id=".((int) $this->
id);
396 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
397 $resql = $this->db->query($sql);
400 $this->errors[] =
"Error ".$this->db->lasterror();
405 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_expensereport";
406 $sql .=
" WHERE rowid=".((int) $this->
id);
408 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
409 $resql = $this->db->query($sql);
412 $this->errors[] =
"Error ".$this->db->lasterror();
418 foreach ($this->errors as $errmsg) {
419 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
420 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
422 $this->db->rollback();
456 $object->context[
'createfromclone'] =
'createfromclone';
457 $result =
$object->create($user);
465 unset(
$object->context[
'createfromclone']);
472 $this->db->rollback();
517 $this->fk_expensereport = 0;
522 $this->fk_typepayment = 0;
523 $this->num_payment =
'123456';
524 $this->note_public =
'Public note';
525 $this->note_private =
'Private note';
527 $this->fk_user_creat = 0;
528 $this->fk_user_modif = 0;
546 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
552 if (isModEnabled(
"bank")) {
553 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
556 $acc->fetch($accountid);
559 $total = $this->amount;
562 if ($mode ==
'payment_expensereport') {
567 $bank_line_id = $acc->addline(
569 $this->fk_typepayment,
581 if ($bank_line_id > 0) {
590 if ($mode ==
'payment_expensereport') {
591 $url = DOL_URL_ROOT.
'/expensereport/payment/card.php?rowid=';
594 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
603 foreach ($this->amounts as $key => $value) {
604 if ($mode ==
'payment_expensereport') {
605 $fuser =
new User($this->db);
608 $result = $acc->add_url_line(
611 DOL_URL_ROOT.
'/user/card.php?id=',
612 $fuser->getFullName($langs),
616 $this->error = $this->db->lasterror();
617 dol_syslog(get_class($this).
'::addPaymentToBank '.$this->error);
624 $this->error = $acc->error;
625 $this->errors = $acc->errors;
648 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
650 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
651 $result = $this->db->query($sql);
655 $this->error = $this->db->error();
669 global $langs, $hookmanager;
673 if (empty($this->
ref)) {
674 $this->
ref = $this->label;
676 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Payment").
'</u>';
677 if (isset($this->
status)) {
678 $label .=
' '.$this->getLibStatut(5);
680 if (!empty($this->
ref)) {
681 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
683 if (!empty($this->datep)) {
684 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'dayhour');
687 if (!empty($this->
id)) {
688 $link =
'<a href="'.DOL_URL_ROOT.
'/expensereport/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
692 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
694 if ($withpicto && $withpicto != 2) {
697 if ($withpicto != 2) {
698 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
702 $hookmanager->initHooks(array($this->element .
'dao'));
703 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
704 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
706 $result = $hookmanager->resPrint;
708 $result .= $hookmanager->resPrint;
721 $sql =
'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
722 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_expensereport as e';
723 $sql .=
' WHERE e.rowid = '.((int) $id);
725 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
726 $result = $this->db->query($sql);
729 if ($this->db->num_rows($result)) {
730 $obj = $this->db->fetch_object($result);
732 $this->
id = $obj->rowid;
734 $this->user_creation_id = $obj->fk_user_creat;
735 $this->user_modification_id = $obj->fk_user_modif;
736 $this->date_creation = $this->db->jdate($obj->datec);
737 $this->date_modification = $this->db->jdate($obj->tms);
739 $this->db->free($result);
756 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
758 $return =
'<div class="box-flex-item box-flex-grow-zero">';
759 $return .=
'<div class="info-box info-box-sm">';
760 $return .=
'<span class="info-box-icon bg-infobox-action">';
762 $return .=
'</span>';
763 $return .=
'<div class="info-box-content">';
764 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
765 if ($selected >= 0) {
766 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
768 if (property_exists($this,
'datep')) {
769 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'dayhour').
'</span>';
771 if (property_exists($this,
'fk_typepayment')) {
772 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Type").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
774 if (property_exists($this,
'fk_bank') && !is_null($this->fk_bank)) {
775 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"BankAccount").
'</span> : <span class="info-box-label">'.$this->fk_bank.
'</span>';
777 if (property_exists($this,
'amount')) {
778 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->amount).
'</span>';
780 if (method_exists($this,
'getLibStatut')) {
781 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
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,...
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 clickable link of object (with eventually picto)
getNomUrl($withpicto=0, $maxlen=0)
Return clickable 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.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...