27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
28require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
39 public $element =
'payment_expensereport';
44 public $table_element =
'payment_expensereport';
49 public $picto =
'payment';
59 public $fk_expensereport;
77 public $amounts = array();
82 public $fk_typepayment;
98 public $fk_user_creat;
103 public $fk_user_modif;
118 public $bank_account;
155 $this->error =
'ErrorBadValueForParameterCreatePaymentExpenseReport';
160 if (isset($this->fk_expensereport)) {
161 $this->fk_expensereport = (int) $this->fk_expensereport;
163 if (isset($this->
amount)) {
166 if (isset($this->fk_typepayment)) {
167 $this->fk_typepayment = (int) $this->fk_typepayment;
169 if (isset($this->num_payment)) {
170 $this->num_payment = trim($this->num_payment);
172 if (isset($this->note)) {
173 $this->note = trim($this->note);
175 if (isset($this->note_public)) {
176 $this->note_public = trim($this->note_public);
178 if (isset($this->note_private)) {
179 $this->note_private = trim($this->note_private);
181 if (isset($this->fk_bank)) {
182 $this->fk_bank = ((int) $this->fk_bank);
184 if (isset($this->fk_user_creat)) {
185 $this->fk_user_creat = ((int) $this->fk_user_creat);
187 if (isset($this->fk_user_modif)) {
188 $this->fk_user_modif = ((int) $this->fk_user_modif);
192 foreach ($this->amounts as $key => $value) {
193 $newvalue = (float)
price2num($value,
'MT');
194 $this->amounts[$key] = $newvalue;
195 $totalamount += $newvalue;
200 if ($totalamount == 0) {
207 if ($totalamount != 0) {
208 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_expensereport (fk_expensereport, datec, datep, amount,";
209 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
210 $sql .=
" VALUES (".((int) $this->fk_expensereport).
", '".$this->db->idate($now).
"',";
211 $sql .=
" '".$this->db->idate($this->datep).
"',";
212 $sql .=
" ".price2num($totalamount).
",";
213 $sql .=
" ".((int) $this->fk_typepayment).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ".((int) $user->id).
",";
216 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
217 $resql = $this->db->query($sql);
219 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_expensereport");
225 if ($totalamount != 0 && !$error) {
226 $this->
amount = $totalamount;
230 $this->error = $this->db->error();
231 $this->db->rollback();
246 $sql .=
" t.fk_expensereport,";
250 $sql .=
" t.amount,";
251 $sql .=
" t.fk_typepayment,";
252 $sql .=
" t.num_payment,";
253 $sql .=
" t.note as note_public,";
254 $sql .=
" t.fk_bank,";
255 $sql .=
" t.fk_user_creat,";
256 $sql .=
" t.fk_user_modif,";
257 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
258 $sql .=
' b.fk_account';
259 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as t";
260 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
261 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
262 $sql .=
" WHERE t.rowid = ".((int) $id);
264 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
265 $resql = $this->db->query($sql);
267 if ($this->db->num_rows($resql)) {
268 $obj = $this->db->fetch_object($resql);
270 $this->
id = $obj->rowid;
271 $this->
ref = $obj->rowid;
273 $this->fk_expensereport = $obj->fk_expensereport;
274 $this->datec = $this->db->jdate($obj->datec);
275 $this->tms = $this->db->jdate($obj->tms);
276 $this->datep = $this->db->jdate($obj->datep);
277 $this->
amount = $obj->amount;
278 $this->fk_typepayment = $obj->fk_typepayment;
279 $this->num_payment = $obj->num_payment;
280 $this->note_public = $obj->note_public;
281 $this->fk_bank = $obj->fk_bank;
282 $this->fk_user_creat = $obj->fk_user_creat;
283 $this->fk_user_modif = $obj->fk_user_modif;
285 $this->type_code = $obj->type_code;
286 $this->type_label = $obj->type_label;
288 $this->bank_account = $obj->fk_account;
289 $this->bank_line = $obj->fk_bank;
291 $this->db->free($resql);
295 $this->error =
"Error ".$this->db->lasterror();
308 public function update($user =
null, $notrigger = 0)
315 if (isset($this->fk_expensereport)) {
316 $this->fk_expensereport = (int) $this->fk_expensereport;
318 if (isset($this->
amount)) {
321 if (isset($this->fk_typepayment)) {
322 $this->fk_typepayment = (int) $this->fk_typepayment;
324 if (isset($this->num_payment)) {
325 $this->num_payment = trim($this->num_payment);
327 if (isset($this->note)) {
328 $this->note = trim($this->note);
330 if (isset($this->fk_bank)) {
331 $this->fk_bank = (int) $this->fk_bank;
333 if (isset($this->fk_user_creat)) {
334 $this->fk_user_creat = (int) $this->fk_user_creat;
336 if (isset($this->fk_user_modif)) {
337 $this->fk_user_modif = (int) $this->fk_user_modif;
341 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET";
342 $sql .=
" fk_expensereport=".(isset($this->fk_expensereport) ? ((int) $this->fk_expensereport) :
"null").
",";
343 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
344 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
345 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
346 $sql .=
" amount=".(isset($this->
amount) ? ((float) $this->
amount) :
"null").
",";
347 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? ((int) $this->fk_typepayment) :
"null").
",";
348 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
349 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
350 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
351 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
352 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
353 $sql .=
" WHERE rowid=".((int) $this->
id);
357 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
358 $resql = $this->db->query($sql);
361 $this->errors[] =
"Error ".$this->db->lasterror();
366 foreach ($this->errors as $errmsg) {
367 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
368 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
370 $this->db->rollback();
386 public function delete($user, $notrigger = 0)
393 if ($this->bank_line > 0) {
395 $result = $accline->fetch($this->bank_line);
397 $result = $accline->delete($user);
399 $this->errors[] = $accline->error;
406 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
407 $sql .=
" WHERE type='payment_expensereport' AND url_id=".((int) $this->
id);
409 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
410 $resql = $this->db->query($sql);
413 $this->errors[] =
"Error ".$this->db->lasterror();
418 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_expensereport";
419 $sql .=
" WHERE rowid=".((int) $this->
id);
421 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
422 $resql = $this->db->query($sql);
425 $this->errors[] =
"Error ".$this->db->lasterror();
431 foreach ($this->errors as $errmsg) {
432 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
433 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
435 $this->db->rollback();
469 $object->context[
'createfromclone'] =
'createfromclone';
470 $result =
$object->create($user);
478 unset(
$object->context[
'createfromclone']);
485 $this->db->rollback();
530 $this->fk_expensereport = 0;
535 $this->fk_typepayment = 0;
536 $this->num_payment =
'123456';
537 $this->note_public =
'Public note';
538 $this->note_private =
'Private note';
540 $this->fk_user_creat = 0;
541 $this->fk_user_modif = 0;
559 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
566 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
569 $acc->fetch($accountid);
572 $total = $this->amount;
575 if ($mode ==
'payment_expensereport') {
580 $bank_line_id = $acc->addline(
582 (
string) $this->fk_typepayment,
594 if ($bank_line_id > 0) {
603 if ($mode ==
'payment_expensereport') {
604 $url = DOL_URL_ROOT.
'/expensereport/payment/card.php?rowid=';
607 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
616 foreach ($this->amounts as $key => $value) {
617 if ($mode ==
'payment_expensereport') {
618 $fuser =
new User($this->db);
621 $result = $acc->add_url_line(
624 DOL_URL_ROOT.
'/user/card.php?id=',
625 $fuser->getFullName($langs),
629 $this->error = $this->db->lasterror();
630 dol_syslog(get_class($this).
'::addPaymentToBank '.$this->error);
637 $this->error = $acc->error;
638 $this->errors = $acc->errors;
661 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
663 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
664 $result = $this->db->query($sql);
668 $this->error = $this->db->error();
682 global $langs, $hookmanager;
686 if (empty($this->
ref)) {
687 $this->
ref = $this->label;
689 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Payment").
'</u>';
690 if (isset($this->
status)) {
691 $label .=
' '.$this->getLibStatut(5);
693 if (!empty($this->
ref)) {
694 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
696 if (!empty($this->datep)) {
697 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'dayhour');
700 if (!empty($this->
id)) {
701 $link =
'<a href="'.DOL_URL_ROOT.
'/expensereport/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
705 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
707 if ($withpicto && $withpicto != 2) {
710 if ($withpicto != 2) {
711 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
715 $hookmanager->initHooks(array($this->element .
'dao'));
716 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
717 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
719 $result = $hookmanager->resPrint;
721 $result .= $hookmanager->resPrint;
734 $sql =
'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
735 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_expensereport as e';
736 $sql .=
' WHERE e.rowid = '.((int) $id);
738 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
739 $result = $this->db->query($sql);
742 if ($this->db->num_rows($result)) {
743 $obj = $this->db->fetch_object($result);
745 $this->
id = $obj->rowid;
747 $this->user_creation_id = $obj->fk_user_creat;
748 $this->user_modification_id = $obj->fk_user_modif;
749 $this->date_creation = $this->db->jdate($obj->datec);
750 $this->date_modification = $this->db->jdate($obj->tms);
752 $this->db->free($result);
769 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
771 $return =
'<div class="box-flex-item box-flex-grow-zero">';
772 $return .=
'<div class="info-box info-box-sm">';
773 $return .=
'<span class="info-box-icon bg-infobox-action">';
775 $return .=
'</span>';
776 $return .=
'<div class="info-box-content">';
777 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
778 if ($selected >= 0) {
779 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
781 if (property_exists($this,
'datep')) {
782 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'dayhour').
'</span>';
784 if (property_exists($this,
'fk_typepayment')) {
785 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Type").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
787 if (property_exists($this,
'fk_bank') && !is_null($this->fk_bank)) {
788 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"BankAccount").
'</span> : <span class="info-box-label">'.$this->fk_bank.
'</span>';
790 if (property_exists($this,
'amount')) {
791 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
793 if (method_exists($this,
'getLibStatut')) {
794 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
if(! $sortfield) if(! $sortorder) $object
Class to manage bank accounts.
Class to manage bank transaction lines.
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...
dol_now($mode='gmt')
Return date for now.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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...
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as p p num_paiement as f pf amount as amount