31require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobjectline.class.php';
32require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
47 public $table_element =
'expensereport_det';
87 public $fk_c_type_fees;
92 public $fk_c_exp_tax_cat;
102 public $fk_expensereport;
107 public $type_fees_code;
112 public $type_fees_libelle;
117 public $type_fees_accountancy_code;
127 public $projet_title;
142 public $vat_src_code;
152 public $localtax1_tx;
157 public $localtax2_tx;
162 public $localtax1_type;
167 public $localtax2_type;
187 public $total_localtax1;
192 public $total_localtax2;
198 public $fk_multicurrency;
203 public $multicurrency_code;
208 public $multicurrency_tx;
213 public $multicurrency_total_ht;
218 public $multicurrency_total_tva;
223 public $multicurrency_total_ttc;
228 public $fk_ecm_files;
233 public $rule_warning_message;
254 $sql =
'SELECT fde.rowid, fde.fk_expensereport, fde.fk_c_type_fees, fde.fk_c_exp_tax_cat, fde.fk_projet as fk_project, fde.date,';
255 $sql .=
' fde.tva_tx as vatrate, fde.vat_src_code, fde.comments, fde.qty, fde.value_unit, fde.total_ht, fde.total_tva, fde.total_ttc, fde.fk_ecm_files,';
256 $sql .=
' fde.localtax1_tx, fde.localtax2_tx, fde.localtax1_type, fde.localtax2_type, fde.total_localtax1, fde.total_localtax2, fde.rule_warning_message,';
257 $sql .=
' ctf.code as type_fees_code, ctf.label as type_fees_libelle,';
258 $sql .=
' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref';
259 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport_det as fde';
260 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id';
261 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'projet as pjt ON fde.fk_projet=pjt.rowid';
262 $sql .=
' WHERE fde.rowid = '.((int) $rowid);
264 $result = $this->db->query($sql);
267 $objp = $this->db->fetch_object($result);
269 $this->
rowid = $objp->rowid;
270 $this->
id = $objp->rowid;
271 $this->
ref = $objp->ref;
272 $this->fk_expensereport = $objp->fk_expensereport;
273 $this->comments = $objp->comments;
274 $this->qty = $objp->qty;
275 $this->date = $objp->date;
276 $this->dates = $this->db->jdate($objp->date);
277 $this->value_unit = $objp->value_unit;
278 $this->fk_c_type_fees = $objp->fk_c_type_fees;
279 $this->fk_c_exp_tax_cat = $objp->fk_c_exp_tax_cat;
280 $this->fk_projet = $objp->fk_project;
281 $this->fk_project = $objp->fk_project;
282 $this->type_fees_code = $objp->type_fees_code;
283 $this->type_fees_libelle = $objp->type_fees_libelle;
284 $this->projet_ref = $objp->projet_ref;
285 $this->projet_title = $objp->projet_title;
287 $this->
vatrate = $objp->vatrate;
288 $this->vat_src_code = $objp->vat_src_code;
289 $this->localtax1_tx = $objp->localtax1_tx;
290 $this->localtax2_tx = $objp->localtax2_tx;
291 $this->localtax1_type = $objp->localtax1_type;
292 $this->localtax2_type = $objp->localtax2_type;
294 $this->total_ht = $objp->total_ht;
295 $this->total_tva = $objp->total_tva;
296 $this->total_ttc = $objp->total_ttc;
297 $this->total_localtax1 = $objp->total_localtax1;
298 $this->total_localtax2 = $objp->total_localtax2;
300 $this->fk_ecm_files = $objp->fk_ecm_files;
302 $this->rule_warning_message = $objp->rule_warning_message;
304 $this->db->free($result);
320 public function insert($notrigger = 0, $fromaddline =
false)
326 dol_syslog(
"ExpenseReportLine::Insert", LOG_DEBUG);
329 $this->comments = trim($this->comments);
330 if (empty($this->value_unit)) {
331 $this->value_unit = 0;
333 $this->qty = (float)
price2num($this->qty);
335 if (empty($this->fk_c_exp_tax_cat)) {
336 $this->fk_c_exp_tax_cat = 0;
341 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.
'expensereport_det';
342 $sql .=
' (fk_expensereport, fk_c_type_fees, fk_projet,';
343 $sql .=
' tva_tx, vat_src_code,';
344 $sql .=
' localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
345 $sql .=
' comments, qty, value_unit,';
346 $sql .=
' total_ht, total_tva, total_ttc,';
347 $sql .=
' total_localtax1, total_localtax2,';
348 $sql .=
' date, rule_warning_message, fk_c_exp_tax_cat, fk_ecm_files)';
349 $sql .=
" VALUES (".$this->db->escape($this->fk_expensereport).
",";
350 $sql .=
" ".((int) $this->fk_c_type_fees).
",";
351 $sql .=
" ".((int) (!empty($this->fk_project) && $this->fk_project > 0) ? $this->fk_project : ((!empty($this->fk_projet) && $this->fk_projet > 0) ? $this->fk_projet :
'null')).
",";
352 $sql .=
" ".((float) $this->
vatrate).
",";
353 $sql .=
" '".$this->db->escape(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"',";
354 $sql .=
" ".((float)
price2num($this->localtax1_tx)).
",";
355 $sql .=
" ".((float)
price2num($this->localtax2_tx)).
",";
356 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
357 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
358 $sql .=
" '".$this->db->escape($this->comments).
"',";
359 $sql .=
" ".((float) $this->qty).
",";
360 $sql .=
" ".((float) $this->value_unit).
",";
361 $sql .=
" ".((float)
price2num($this->total_ht)).
",";
362 $sql .=
" ".((float)
price2num($this->total_tva)).
",";
363 $sql .=
" ".((float)
price2num($this->total_ttc)).
",";
364 $sql .=
" ".((float)
price2num($this->total_localtax1)).
",";
365 $sql .=
" ".((float)
price2num($this->total_localtax2)).
",";
366 $sql .=
" '".$this->db->idate($this->date).
"',";
367 $sql .=
" ".(empty($this->rule_warning_message) ?
'null' :
"'".$this->db->escape($this->rule_warning_message).
"'").
",";
368 $sql .=
" ".((int) $this->fk_c_exp_tax_cat).
",";
369 $sql .=
" ".($this->fk_ecm_files > 0 ? ((int) $this->fk_ecm_files) :
'null');
372 $resql = $this->db->query($sql);
374 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'expensereport_det');
377 if (!$error && !$notrigger) {
379 $result = $this->
call_trigger(
'EXPENSE_REPORT_DET_CREATE', $user);
389 $tmpparent->fetch($this->fk_expensereport);
390 $result = $tmpparent->update_price(1);
393 $this->error = $tmpparent->error;
394 $this->errors = $tmpparent->errors;
405 $this->error = $this->db->lasterror();
406 dol_syslog(
"ExpenseReportLine::insert Error ".$this->error, LOG_ERR);
407 $this->db->rollback();
424 $sql =
'SELECT SUM(d.total_ttc) as total_amount';
425 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport_det d';
426 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'expensereport e ON (d.fk_expensereport = e.rowid)';
427 $sql .=
' WHERE e.fk_user_author = '.((int) $fk_user);
428 if (!empty($this->
id)) {
429 $sql .=
' AND d.rowid <> '.((int) $this->
id);
431 $sql .=
' AND d.fk_c_type_fees = '.((int) $rule->fk_c_type_fees);
432 if ($mode ==
'day' || $mode ==
'EX_DAY') {
433 $sql .=
" AND d.date = '".dol_print_date($this->date,
'%Y-%m-%d').
"'";
434 } elseif ($mode ==
'mon' || $mode ==
'EX_MON') {
435 $sql .=
" AND DATE_FORMAT(d.date, '%Y-%m') = '".dol_print_date($this->date,
'%Y-%m').
"'";
436 } elseif ($mode ==
'year' || $mode ==
'EX_YEA') {
437 $sql .=
" AND DATE_FORMAT(d.date, '%Y') = '".dol_print_date($this->date,
'%Y').
"'";
440 dol_syslog(
'ExpenseReportLine::getExpAmount');
442 $resql = $this->db->query($sql);
444 $num = $this->db->num_rows($resql);
446 $obj = $this->db->fetch_object($resql);
447 $amount = (float) $obj->total_amount;
453 return $amount + $this->total_ttc;
469 $this->comments = trim($this->comments);
471 $this->value_unit =
price2num($this->value_unit);
472 if (empty($this->fk_c_exp_tax_cat)) {
473 $this->fk_c_exp_tax_cat = 0;
479 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"expensereport_det SET";
480 $sql .=
" comments='".$this->db->escape($this->comments).
"'";
481 $sql .=
", value_unit = ".((float) $this->value_unit);
482 $sql .=
", qty=".((float) $this->qty);
483 $sql .=
", date='".$this->db->idate($this->date).
"'";
484 $sql .=
", total_ht=".((float)
price2num($this->total_ht,
'MT'));
485 $sql .=
", total_tva=".((float)
price2num($this->total_tva,
'MT'));
486 $sql .=
", total_ttc=".((float)
price2num($this->total_ttc,
'MT'));
487 $sql .=
", total_localtax1=".((float)
price2num($this->total_localtax1,
'MT'));
488 $sql .=
", total_localtax2=".((float)
price2num($this->total_localtax2,
'MT'));
489 $sql .=
", tva_tx=".((float) $this->
vatrate);
490 $sql .=
", vat_src_code='".$this->db->escape($this->vat_src_code).
"'";
491 $sql .=
", localtax1_tx=".((float) $this->localtax1_tx);
492 $sql .=
", localtax2_tx=".((float) $this->localtax2_tx);
493 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
494 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
495 $sql .=
", rule_warning_message='".$this->db->escape($this->rule_warning_message).
"'";
496 $sql .=
", fk_c_exp_tax_cat=".$this->db->escape($this->fk_c_exp_tax_cat);
497 $sql .=
", fk_ecm_files=".($this->fk_ecm_files > 0 ? ((int) $this->fk_ecm_files) :
'null');
498 if ($this->fk_c_type_fees) {
499 $sql .=
", fk_c_type_fees = ".((int) $this->fk_c_type_fees);
501 $sql .=
", fk_c_type_fees=null";
503 if ($this->fk_project > 0) {
504 $sql .=
", fk_projet=".((int) $this->fk_project);
506 $sql .=
", fk_projet=null";
508 $sql .=
" WHERE rowid = ".((int) ($this->
rowid ? $this->
rowid : $this->id));
512 $resql = $this->db->query($sql);
515 $result = $tmpparent->fetch($this->fk_expensereport);
517 $result = $tmpparent->update_price(1);
520 $this->error = $tmpparent->error;
521 $this->errors = $tmpparent->errors;
525 $this->error = $tmpparent->error;
526 $this->errors = $tmpparent->errors;
537 $this->error = $this->db->lasterror();
538 dol_syslog(
"ExpenseReportLine::update Error ".$this->error, LOG_ERR);
539 $this->db->rollback();
call_trigger($triggerName, $user)
Call trigger based on this instance.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage Trips and Expenses.
Class of expense report details lines.
fetch($rowid)
Fetch record for expense report detailed line.
update(User $user)
Update line.
getExpAmount(ExpenseReportRule $rule, $fk_user, $mode='day')
Function to get total amount in expense reports for a same rule.
insert($notrigger=0, $fromaddline=false)
Insert a line of expense report.
__construct($db)
Constructor.
Class to manage inventories.
Class to manage Dolibarr users.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid