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;
149 public function create($user, $notrigger = 0)
156 $this->error =
'ErrorBadValueForParameterCreatePaymentExpenseReport';
161 if (isset($this->fk_expensereport)) {
162 $this->fk_expensereport = (int) $this->fk_expensereport;
164 if (isset($this->
amount)) {
167 if (isset($this->fk_typepayment)) {
168 $this->fk_typepayment = (int) $this->fk_typepayment;
170 if (isset($this->num_payment)) {
171 $this->num_payment = trim($this->num_payment);
173 if (isset($this->note)) {
174 $this->note = trim($this->note);
176 if (isset($this->note_public)) {
177 $this->note_public = trim($this->note_public);
179 if (isset($this->note_private)) {
180 $this->note_private = trim($this->note_private);
182 if (isset($this->fk_bank)) {
183 $this->fk_bank = ((int) $this->fk_bank);
185 if (isset($this->fk_user_creat)) {
186 $this->fk_user_creat = ((int) $this->fk_user_creat);
188 if (isset($this->fk_user_modif)) {
189 $this->fk_user_modif = ((int) $this->fk_user_modif);
193 foreach ($this->amounts as $key => $value) {
194 $newvalue = (float)
price2num($value,
'MT');
195 $this->amounts[$key] = $newvalue;
196 $totalamount += $newvalue;
201 if ($totalamount == 0) {
208 if ($totalamount != 0) {
209 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"payment_expensereport (fk_expensereport, datec, datep, amount,";
210 $sql .=
" fk_typepayment, num_payment, note, fk_user_creat, fk_bank)";
211 $sql .=
" VALUES (".((int) $this->fk_expensereport).
", '".$this->db->idate($now).
"',";
212 $sql .=
" '".$this->db->idate($this->datep).
"',";
213 $sql .=
" ".price2num($totalamount).
",";
214 $sql .=
" ".((int) $this->fk_typepayment).
", '".$this->db->escape($this->num_payment).
"', '".$this->db->escape($this->note_public).
"', ".((int) $user->id).
",";
217 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
218 $resql = $this->db->query($sql);
220 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"payment_expensereport");
226 if ($totalamount != 0 && !$error && !$notrigger) {
228 $result = $this->call_trigger(
'PAYMENTEXPENSEREPORT_CREATE', $user);
235 if ($totalamount != 0 && !$error) {
236 $this->
amount = $totalamount;
240 $this->error = $this->db->error();
241 $this->db->rollback();
256 $sql .=
" t.fk_expensereport,";
260 $sql .=
" t.amount,";
261 $sql .=
" t.fk_typepayment,";
262 $sql .=
" t.num_payment,";
263 $sql .=
" t.note as note_public,";
264 $sql .=
" t.fk_bank,";
265 $sql .=
" t.fk_user_creat,";
266 $sql .=
" t.fk_user_modif,";
267 $sql .=
" pt.code as type_code, pt.libelle as type_label,";
268 $sql .=
' b.fk_account';
269 $sql .=
" FROM ".MAIN_DB_PREFIX.
"payment_expensereport as t";
270 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as pt ON t.fk_typepayment = pt.id";
271 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'bank as b ON t.fk_bank = b.rowid';
272 $sql .=
" WHERE t.rowid = ".((int) $id);
274 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
275 $resql = $this->db->query($sql);
277 if ($this->db->num_rows($resql)) {
278 $obj = $this->db->fetch_object($resql);
280 $this->
id = $obj->rowid;
281 $this->
ref = $obj->rowid;
283 $this->fk_expensereport = $obj->fk_expensereport;
284 $this->datec = $this->db->jdate($obj->datec);
285 $this->tms = $this->db->jdate($obj->tms);
286 $this->datep = $this->db->jdate($obj->datep);
287 $this->
amount = $obj->amount;
288 $this->fk_typepayment = $obj->fk_typepayment;
289 $this->num_payment = $obj->num_payment;
290 $this->note_public = $obj->note_public;
291 $this->fk_bank = $obj->fk_bank;
292 $this->fk_user_creat = $obj->fk_user_creat;
293 $this->fk_user_modif = $obj->fk_user_modif;
295 $this->type_code = $obj->type_code;
296 $this->type_label = $obj->type_label;
298 $this->bank_account = $obj->fk_account;
299 $this->bank_line = $obj->fk_bank;
301 $this->db->free($resql);
305 $this->error =
"Error ".$this->db->lasterror();
318 public function update($user =
null, $notrigger = 0)
325 if (isset($this->fk_expensereport)) {
326 $this->fk_expensereport = (int) $this->fk_expensereport;
328 if (isset($this->
amount)) {
331 if (isset($this->fk_typepayment)) {
332 $this->fk_typepayment = (int) $this->fk_typepayment;
334 if (isset($this->num_payment)) {
335 $this->num_payment = trim($this->num_payment);
337 if (isset($this->note)) {
338 $this->note = trim($this->note);
340 if (isset($this->fk_bank)) {
341 $this->fk_bank = (int) $this->fk_bank;
343 if (isset($this->fk_user_creat)) {
344 $this->fk_user_creat = (int) $this->fk_user_creat;
346 if (isset($this->fk_user_modif)) {
347 $this->fk_user_modif = (int) $this->fk_user_modif;
351 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET";
352 $sql .=
" fk_expensereport=".(isset($this->fk_expensereport) ? ((int) $this->fk_expensereport) :
"null").
",";
353 $sql .=
" datec=".(dol_strlen($this->datec) != 0 ?
"'".$this->db->idate($this->datec).
"'" :
'null').
",";
354 $sql .=
" tms=".(dol_strlen((
string) $this->tms) != 0 ?
"'".$this->db->idate($this->tms).
"'" :
'null').
",";
355 $sql .=
" datep=".(dol_strlen($this->datep) != 0 ?
"'".$this->db->idate($this->datep).
"'" :
'null').
",";
356 $sql .=
" amount=".(isset($this->
amount) ? ((float) $this->
amount) :
"null").
",";
357 $sql .=
" fk_typepayment=".(isset($this->fk_typepayment) ? ((int) $this->fk_typepayment) :
"null").
",";
358 $sql .=
" num_payment=".(isset($this->num_payment) ?
"'".$this->db->escape($this->num_payment).
"'" :
"null").
",";
359 $sql .=
" note=".(isset($this->note) ?
"'".$this->db->escape($this->note).
"'" :
"null").
",";
360 $sql .=
" fk_bank=".(isset($this->fk_bank) ? ((int) $this->fk_bank) :
"null").
",";
361 $sql .=
" fk_user_creat=".(isset($this->fk_user_creat) ? ((int) $this->fk_user_creat) :
"null").
",";
362 $sql .=
" fk_user_modif=".(isset($this->fk_user_modif) ? ((int) $this->fk_user_modif) :
"null");
363 $sql .=
" WHERE rowid=".((int) $this->
id);
367 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
368 $resql = $this->db->query($sql);
371 $this->errors[] =
"Error ".$this->db->lasterror();
374 if (!$error && $user && !$notrigger) {
376 $result = $this->call_trigger(
'PAYMENTEXPENSEREPORT_MODIFY', $user);
385 foreach ($this->errors as $errmsg) {
386 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
387 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
389 $this->db->rollback();
405 public function delete($user, $notrigger = 0)
412 if ($this->bank_line > 0) {
414 $result = $accline->fetch($this->bank_line);
416 $result = $accline->delete($user);
418 $this->errors[] = $accline->error;
425 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"bank_url";
426 $sql .=
" WHERE type='payment_expensereport' AND url_id=".((int) $this->
id);
428 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
429 $resql = $this->db->query($sql);
432 $this->errors[] =
"Error ".$this->db->lasterror();
437 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"payment_expensereport";
438 $sql .=
" WHERE rowid=".((int) $this->
id);
440 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
441 $resql = $this->db->query($sql);
444 $this->errors[] =
"Error ".$this->db->lasterror();
448 if (!$error && !$notrigger) {
450 $result = $this->call_trigger(
'PAYMENTEXPENSEREPORT_DELETE', $user);
459 foreach ($this->errors as $errmsg) {
460 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
461 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
463 $this->db->rollback();
497 $object->context[
'createfromclone'] =
'createfromclone';
498 $result =
$object->create($user);
506 unset(
$object->context[
'createfromclone']);
513 $this->db->rollback();
558 $this->fk_expensereport = 0;
563 $this->fk_typepayment = 0;
564 $this->num_payment =
'123456';
565 $this->note_public =
'Public note';
566 $this->note_private =
'Private note';
568 $this->fk_user_creat = 0;
569 $this->fk_user_modif = 0;
587 public function addPaymentToBank($user, $mode, $label, $accountid, $emetteur_nom, $emetteur_banque)
594 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/account.class.php';
597 $acc->fetch($accountid);
600 $total = $this->amount;
603 if ($mode ==
'payment_expensereport') {
608 $bank_line_id = $acc->addline(
610 (
string) $this->fk_typepayment,
622 if ($bank_line_id > 0) {
626 dol_print_error($this->db);
631 if ($mode ==
'payment_expensereport') {
632 $url = DOL_URL_ROOT.
'/expensereport/payment/card.php?rowid=';
635 $result = $acc->add_url_line($bank_line_id, $this->
id, $url,
'(paiement)', $mode);
638 dol_print_error($this->db);
644 foreach ($this->amounts as $key => $value) {
645 if ($mode ==
'payment_expensereport') {
646 $fuser =
new User($this->db);
649 $result = $acc->add_url_line(
652 DOL_URL_ROOT.
'/user/card.php?id=',
653 $fuser->getFullName($langs),
657 $this->error = $this->db->lasterror();
658 dol_syslog(get_class($this).
'::addPaymentToBank '.$this->error);
665 $this->error = $acc->error;
666 $this->errors = $acc->errors;
689 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"payment_expensereport SET fk_bank = ".((int) $id_bank).
" WHERE rowid = ".((int) $this->
id);
691 dol_syslog(get_class($this).
"::update_fk_bank", LOG_DEBUG);
692 $result = $this->db->query($sql);
696 $this->error = $this->db->error();
710 global $langs, $hookmanager;
714 if (empty($this->
ref)) {
715 $this->
ref = $this->label;
717 $label = img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Payment").
'</u>';
718 if (isset($this->
status)) {
719 $label .=
' '.$this->getLibStatut(5);
721 if (!empty($this->
ref)) {
722 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
724 if (!empty($this->datep)) {
725 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->datep,
'dayhour');
728 if (!empty($this->
id)) {
729 $link =
'<a href="'.DOL_URL_ROOT.
'/expensereport/payment/card.php?id='.$this->
id.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
733 $result .= ($link.img_object($label,
'payment',
'class="classfortooltip"').$linkend.
' ');
735 if ($withpicto && $withpicto != 2) {
738 if ($withpicto != 2) {
739 $result .= $link.($maxlen ?
dol_trunc($this->
ref, $maxlen) : $this->ref).$linkend;
743 $hookmanager->initHooks(array($this->element .
'dao'));
744 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
745 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
747 $result = $hookmanager->resPrint;
749 $result .= $hookmanager->resPrint;
762 $sql =
'SELECT e.rowid, e.datec, e.fk_user_creat, e.fk_user_modif, e.tms';
763 $sql .=
' FROM '.MAIN_DB_PREFIX.
'payment_expensereport as e';
764 $sql .=
' WHERE e.rowid = '.((int) $id);
766 dol_syslog(get_class($this).
'::info', LOG_DEBUG);
767 $result = $this->db->query($sql);
770 if ($this->db->num_rows($result)) {
771 $obj = $this->db->fetch_object($result);
773 $this->
id = $obj->rowid;
775 $this->user_creation_id = $obj->fk_user_creat;
776 $this->user_modification_id = $obj->fk_user_modif;
777 $this->date_creation = $this->db->jdate($obj->datec);
778 $this->date_modification = $this->db->jdate($obj->tms);
780 $this->db->free($result);
782 dol_print_error($this->db);
797 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
799 $return =
'<div class="box-flex-item box-flex-grow-zero">';
800 $return .=
'<div class="info-box info-box-sm">';
801 $return .=
'<span class="info-box-icon bg-infobox-action">';
802 $return .= img_picto(
'', $this->picto);
803 $return .=
'</span>';
804 $return .=
'<div class="info-box-content">';
805 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl(1) : $this->ref).
'</span>';
806 if ($selected >= 0) {
807 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
809 if (property_exists($this,
'datep')) {
810 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Date").
'</span> : <span class="info-box-label">'.
dol_print_date($this->db->jdate($this->datep),
'dayhour').
'</span>';
812 if (property_exists($this,
'fk_typepayment')) {
813 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Type").
'</span> : <span class="info-box-label">'.$this->fk_typepayment.
'</span>';
815 if (property_exists($this,
'fk_bank') && !is_null($this->fk_bank)) {
816 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"BankAccount").
'</span> : <span class="info-box-label">'.$this->fk_bank.
'</span>';
818 if (property_exists($this,
'amount')) {
819 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Amount").
'</span> : <span class="info-box-label amount">'.
price($this->
amount).
'</span>';
821 if (method_exists($this,
'getLibStatut')) {
822 $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.
create($user, $notrigger=0)
Create payment of expense report into database.
fetch($id)
Load object in memory from 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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
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