dolibarr 25.0.0-alpha
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2015-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
6 * Copyright (C) 2017 Ferran Marcet <fmarcet@2byte.es>
7 * Copyright (C) 2018-2026 Frédéric France <frederic.france@free.fr>
8 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
9 * Copyright (C) 2025 Charlene Benke <charlene@patas-monkey.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
31// Load Dolibarr environment
32require '../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formexpensereport.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
46require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
47require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
49require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
50require_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
51require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
52require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
53require_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php';
54require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
55require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
56require_once DOL_DOCUMENT_ROOT.'/core/modules/expensereport/modules_expensereport.php';
57require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
58require_once DOL_DOCUMENT_ROOT.'/expensereport/class/paymentexpensereport.class.php';
59require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
60if (isModEnabled('accounting')) {
61 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
62}
63
64// Load translation files required by the page
65$langs->loadLangs(array("trips", "bills", "mails"));
66
67$action = GETPOST('action', 'aZ09');
68$cancel = GETPOST('cancel', 'alpha');
69$confirm = GETPOST('confirm', 'alpha');
70$backtopage = GETPOST('backtopage', 'alpha');
71
72$id = GETPOSTINT('id');
73$date_start = dol_mktime(0, 0, 0, GETPOSTINT('date_debutmonth'), GETPOSTINT('date_debutday'), GETPOSTINT('date_debutyear'));
74$date_end = dol_mktime(0, 0, 0, GETPOSTINT('date_finmonth'), GETPOSTINT('date_finday'), GETPOSTINT('date_finyear'));
75$date = dol_mktime(0, 0, 0, GETPOSTINT('datemonth'), GETPOSTINT('dateday'), GETPOSTINT('dateyear'));
76$fk_project = GETPOSTINT('fk_project');
77$vatrate = GETPOST('vatrate', 'alpha');
78$ref = GETPOST("ref", 'alpha');
79$comments = GETPOST('comments', 'restricthtml');
80$fk_c_type_fees = GETPOSTINT('fk_c_type_fees');
81$socid = GETPOSTINT('socid') ? GETPOSTINT('socid') : GETPOSTINT('socid_id');
82
84$childids = $user->getAllChildIds(1);
85
86if (getDolGlobalString('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH')) {
87 if (empty($date_start)) {
88 $date_start = dol_mktime(0, 0, 0, (int) dol_print_date(dol_now(), '%m'), 1, (int) dol_print_date(dol_now(), '%Y'));
89 }
90
91 if (empty($date_end)) {
92 // date('t') => number of days in the month, so last day of the month too
93 $date_end = dol_mktime(0, 0, 0, (int) dol_print_date(dol_now(), '%m'), (int) date('t'), (int) dol_print_date(dol_now(), '%Y'));
94 }
95}
96
97// Hack to use expensereport dir
98$rootfordata = DOL_DATA_ROOT;
99$rootforuser = DOL_DATA_ROOT;
100// If multicompany module is enabled, we redefine the root of data
101if (isModEnabled('multicompany') && !empty($conf->entity) && $conf->entity > 1) {
102 $rootfordata .= '/'.$conf->entity;
103}
104$conf->expensereport->dir_output = $rootfordata.'/expensereport';
105
106// Define $urlwithroot
107$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root));
108$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file
109//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current
110
111// PDF
112$hidedetails = (GETPOSTINT('hidedetails') ? GETPOSTINT('hidedetails') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0));
113$hidedesc = (GETPOSTINT('hidedesc') ? GETPOSTINT('hidedesc') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0));
114$hideref = (GETPOSTINT('hideref') ? GETPOSTINT('hideref') : (getDolGlobalString('MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0));
115
116
117$object = new ExpenseReport($db);
118
119// fetch optionals attributes and labels
120$extrafields->fetch_name_optionals_label($object->table_element);
121
122// Load object
123include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be 'include', not 'include_once'
124
125// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
126$hookmanager->initHooks(array('expensereportcard', 'globalcard'));
127
128
129// An existing expense report can be modified only if it is for the user or one of his subordinates, or with the permission to write the expense reports of everybody
130$caneditreport = (empty($object->id) || in_array($object->fk_user_author, $childids) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expensereport', 'writeall_advance')));
131
132$permissionnote = $user->hasRight('expensereport', 'creer') && $caneditreport; // Used by the include of actions_setnotes.inc.php
133$permissiondellink = $user->hasRight('expensereport', 'creer') && $caneditreport; // Used by the include of actions_dellink.inc.php
134$permissiontoadd = $user->hasRight('expensereport', 'creer') && $caneditreport; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
135$permissiontoeditextra = $permissiontoadd;
136if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
137 // For action 'update_extras', is there a specific permission set for the attribute to update
138 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
139}
140
141$upload_dir = $conf->expensereport->dir_output.'/'.dol_sanitizeFileName($object->ref);
142
143$projectRequired = isModEnabled('project') && getDolGlobalString('EXPENSEREPORT_PROJECT_IS_REQUIRED');
144$fileRequired = getDolGlobalString('EXPENSEREPORT_FILE_IS_REQUIRED');
145
146if ($object->id > 0) {
147 // Check current user can read this expense report
148 $canread = 0;
149 if ($user->hasRight('expensereport', 'readall')) {
150 $canread = 1;
151 }
152 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expensereport', 'writeall_advance')) {
153 $canread = 1; // Can create an expense report for everybody, so can also read it
154 }
155 if ($user->hasRight('expensereport', 'lire') && in_array($object->fk_user_author, $childids)) {
156 $canread = 1;
157 }
158 if ($user->hasRight('expensereport', 'approve') && $object->fk_user_validator == $user->id) {
159 $canread = 1; // The user designated to approve this expense report
160 }
161 if (!$canread) {
163 }
164}
165
166$candelete = 0;
167if ($user->hasRight('expensereport', 'supprimer')) {
168 $candelete = 1;
169}
170if ($object->status == ExpenseReport::STATUS_DRAFT && $user->hasRight('expensereport', 'write') && in_array($object->fk_user_author, $childids)) {
171 $candelete = 1;
172}
173
174// Security check
175if ($user->socid) {
176 $socid = $user->socid;
177}
178$result = restrictedArea($user, 'expensereport', $object->id, 'expensereport');
179
180$permissiontoadd = $user->hasRight('expensereport', 'creer') && $caneditreport; // Used by the include of actions_dellink.inc.php
181
182
183/*
184 * Actions
185 */
186
187$error = 0;
188
189$value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU');
190$value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU');
191$qty = price2num(GETPOST('qty', 'alpha'));
192
193$parameters = array('socid' => $socid);
194$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
195if ($reshook < 0) {
196 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
197}
198
199if (empty($reshook)) {
200 $backurlforlist = DOL_URL_ROOT.'/expensereport/list.php';
201
202 if (empty($backtopage) || ($cancel && empty($id))) {
203 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
204 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
205 $backtopage = $backurlforlist;
206 } else {
207 $backtopage = DOL_URL_ROOT.'/expensereport/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
208 }
209 }
210 }
211
212 if ($cancel) {
213 if (!empty($backtopageforcancel)) {
214 header("Location: ".$backtopageforcancel);
215 exit;
216 } elseif (!empty($backtopage)) {
217 header("Location: ".$backtopage);
218 exit;
219 }
220 $action = '';
221
222 $fk_project = '';
223 $date_start = '';
224 $date_end = '';
225 $date = '';
226 $comments = '';
227 $vatrate = '';
228 $value_unit_ht = '';
229 $value_unit = '';
230 $qty = 1;
231 $fk_c_type_fees = -1;
232 }
233
234 // Refuse a status change that the buttons of this page do not offer for the current status of the report
235 $allowedstatusforaction = array(
236 'confirm_validate' => array(ExpenseReport::STATUS_DRAFT),
237 'confirm_save_from_refuse' => array(ExpenseReport::STATUS_REFUSED),
238 'confirm_approve' => array(ExpenseReport::STATUS_VALIDATED),
241 'confirm_setdraft' => array(ExpenseReport::STATUS_VALIDATED),
242 );
243 if ($user->hasRight('expensereport', 'approve') || $user->hasRight('expensereport', 'to_paid')) {
244 $allowedstatusforaction['confirm_cancel'][] = ExpenseReport::STATUS_CLOSED;
245 }
246 if ($user->hasRight('expensereport', 'to_paid')) {
247 $allowedstatusforaction['confirm_setdraft'][] = ExpenseReport::STATUS_APPROVED;
248 }
249 if (array_key_exists($action, $allowedstatusforaction) && $object->id > 0 && !in_array($object->status, $allowedstatusforaction[$action])) {
250 $labelsofallowedstatus = array();
251 foreach ($allowedstatusforaction[$action] as $allowedstatus) {
252 $labelsofallowedstatus[] = $object->LibStatut($allowedstatus, 0);
253 }
254 setEventMessages($langs->trans("StatusOfRefMustBe", $object->ref, implode(' / ', $labelsofallowedstatus)), null, 'errors');
255 $action = '';
256 }
257
258 include DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
259
260 if (!empty(GETPOST('sendit', 'alpha'))) { // If we just submit a file
261 if ($action == 'updateline') { // Test on permission not required here
262 $action = 'editline'; // To avoid to make the updateline now
263 } else {
264 $action = ''; // To avoid to make the addline now
265 }
266 }
267
268 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
269
270 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
271
272 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
273
274 // Action clone object
275 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
276 if (GETPOSTINT('fk_user_author') <= 0) {
277 setEventMessages($langs->trans("NoCloneOptionsSpecified"), null, 'errors');
278 } else {
279 // Check that the new expense report is for a user inside the hierarchy, or that advanced permission for all is set (same rule as for action 'add')
280 $fk_user_author_clone = (GETPOSTINT('fk_user_author') > 0 ? GETPOSTINT('fk_user_author') : $user->id);
281 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance')) && !in_array($fk_user_author_clone, $childids)) {
282 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
283 $action = '';
284 } elseif ($object->id > 0) {
285 // Because createFromClone modifies the object, we must clone it so that we can restore it later if it fails
286 $orig = clone $object;
287
288 $result = $object->createFromClone($user, GETPOSTINT('fk_user_author'));
289 if ($result > 0) {
290 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
291 exit;
292 } else {
293 setEventMessages($object->error, $object->errors, 'errors');
294 $object = $orig;
295 $action = '';
296 }
297 }
298 }
299 }
300
301 if ($action == 'confirm_delete' && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $candelete) {
302 $object = new ExpenseReport($db);
303 $result = $object->fetch($id);
304 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
305 $result = $object->delete($user);
306 if ($result >= 0) {
307 header("Location: index.php");
308 exit;
309 } else {
310 setEventMessages($object->error, $object->errors, 'errors');
311 }
312 }
313
314 if ($action == 'add' && $permissiontoadd) {
315 $object = new ExpenseReport($db);
316
317 $object->date_debut = $date_start;
318 $object->date_fin = $date_end;
319
320 $object->fk_user_author = GETPOSTINT('fk_user_author');
321 if (!($object->fk_user_author > 0)) {
322 $object->fk_user_author = $user->id;
323 }
324
325 // Check that expense report is for a user inside the hierarchy, or that advanced permission for all is set
326 if ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('expensereport', 'creer'))
327 || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('expensereport', 'creer') && !$user->hasRight('expensereport', 'writeall_advance'))) {
328 $error++;
329 setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors');
330 }
331 if (!$error) {
332 if (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance')) {
333 if (!in_array($object->fk_user_author, $childids)) {
334 $error++;
335 setEventMessages($langs->trans("UserNotInHierachy"), null, 'errors');
336 }
337 }
338 }
339
340 $fuser = new User($db);
341 $fuser->fetch($object->fk_user_author);
342
343 $object->status = 1;
344 $object->fk_c_paiement = GETPOSTINT('fk_c_paiement');
345 $object->fk_user_validator = GETPOSTINT('fk_user_validator');
346 $object->note_public = GETPOST('note_public', 'restricthtml');
347 $object->note_private = GETPOST('note_private', 'restricthtml');
348 // Fill array 'array_options' with data from add form
349 if (!$error) {
350 $ret = $extrafields->setOptionalsFromPost(null, $object);
351 if ($ret < 0) {
352 $error++;
353 }
354 }
355
356 if (!$error && !getDolGlobalString('EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS')) {
357 $overlappingExpenseReportID = $object->periodExists($fuser, $object->date_debut, $object->date_fin);
358
359 if ($overlappingExpenseReportID > 0) {
360 $error++;
361 setEventMessages($langs->trans("ErrorDoubleDeclaration").' <a href="'.$_SERVER['PHP_SELF'].'?id='.$overlappingExpenseReportID.'">'. $langs->trans('ShowTrip').'</a>', null, 'errors');
362 $action = 'create';
363 }
364 }
365
366 if (!$error) {
367 $db->begin();
368
369 $id = $object->create($user);
370 if ($id <= 0) {
371 $error++;
372 }
373
374 if (!$error) {
375 $db->commit();
376 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
377 exit;
378 } else {
379 setEventMessages($object->error, $object->errors, 'errors');
380 $db->rollback();
381 $action = 'create';
382 }
383 }
384 }
385
386 if (($action == 'update' || $action == 'updateFromRefuse') && $permissiontoadd) {
387 $object = new ExpenseReport($db);
388 $object->fetch($id);
389
390 $object->date_debut = $date_start;
391 $object->date_fin = $date_end;
392
393 if ($object->status < 3) {
394 $object->fk_user_validator = GETPOSTINT('fk_user_validator');
395 }
396
397 $object->fk_c_paiement = GETPOSTINT('fk_c_paiement');
398 $object->note_public = GETPOST('note_public', 'restricthtml');
399 $object->note_private = GETPOST('note_private', 'restricthtml');
400 $object->fk_user_modif = $user->id;
401
402 $result = $object->update($user);
403 if ($result > 0) {
404 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
405 exit;
406 } else {
407 setEventMessages($object->error, $object->errors, 'errors');
408 }
409 }
410
411 if ($action == 'update_extras' && $permissiontoeditextra) {
412 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
413
414 $attribute_name = GETPOST('attribute', 'aZ09');
415
416 // Fill array 'array_options' with data from update form
417 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
418 if ($ret < 0) {
419 $error++;
420 }
421
422 if (!$error) {
423 $result = $object->updateExtraField($attribute_name, 'EXPENSEREPORT_MODIFY');
424 if ($result < 0) {
425 setEventMessages($object->error, $object->errors, 'errors');
426 $error++;
427 }
428 }
429
430 if ($error) {
431 $action = 'edit_extras';
432 }
433 }
434
435 if ($action == "confirm_validate" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $permissiontoadd) {
436 $db->begin();
437
438 $object = new ExpenseReport($db);
439 $object->fetch($id);
440
441 $result = $object->setValidate($user);
442
443 if ($result >= 0) {
444 // Define output language
445 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
446 $outputlangs = $langs;
447 $newlang = '';
448 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
449 $newlang = GETPOST('lang_id', 'aZ09');
450 }
451 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
452 $tmpuser = new User($db);
453 $tmpuser->fetch($object->fk_user_author);
454 $newlang = $tmpuser->lang;
455 }
456 if (!empty($newlang)) {
457 $outputlangs = new Translate("", $conf);
458 $outputlangs->setDefaultLang($newlang);
459 }
460 $model = $object->model_pdf;
461 $ret = $object->fetch($id); // Reload to get new records
462
463 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
464 }
465 } else {
466 setEventMessages($object->error, $object->errors, 'errors');
467 $error++;
468 }
469
470 if (!$error && $result > 0 && $object->fk_user_validator > 0) {
471 $langs->load("mails");
472
473 // TO
474 $destinataire = new User($db);
475 $destinataire->fetch($object->fk_user_validator);
476 $emailTo = $destinataire->email;
477
478 // FROM
479 $expediteur = new User($db);
480 $expediteur->fetch($object->fk_user_author);
481 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
482
483 if ($emailTo && $emailFrom) {
484 $filename = array();
485 $filedir = array();
486 $mimetype = array();
487
488 // SUBJECT
489 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
490 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
491 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
492 }
493
494 $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForApproval");
495
496 // CONTENT
497 $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
498 $link = '<a href="'.$link.'">'.$link.'</a>';
499 $summary = $object->getSummary();
500 $message = '';
501 if ($summary !== '') {
502 $message .= $langs->transnoentities("Summary").': '.dol_escape_htmltag($summary).'<br>';
503 }
504 $message .= $langs->transnoentities("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut, $object->date_fin, '', $langs), $link);
505
506 // Rebuild pdf
507 /*
508 $object->setDocModel($user,"");
509 $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs);
510
511 if($resultPDF):
512 // ATTACHMENT
513 array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
514 array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf");
515 array_push($mimetype,"application/pdf");
516 */
517
518 // PREPARE SEND
519 $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
520
521 if (empty($mailfile->error)) {
522 // SEND
523 $result = $mailfile->sendfile();
524 if ($result) {
525 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
526 setEventMessages($mesg, null, 'mesgs');
527 } else {
528 $langs->load("other");
529 if (!empty($mailfile->error) || !empty($mailfile->errors)) {
530 $mesg = '';
531 $mesg .= $langs->transnoentities('ErrorFailedToSendMail', dol_escape_htmltag($emailFrom), dol_escape_htmltag($emailTo));
532 if (!empty($mailfile->error)) {
533 $mesg .= '<br>' . $mailfile->error;
534 }
535 if (!empty($mailfile->errors) && is_array($mailfile->errors)) {
536 $mesg .= '<br>' . implode('<br>', $mailfile->errors);
537 }
538 setEventMessages($mesg, null, 'errors');
539 } else {
540 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
541 }
542 }
543 } else {
544 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
545 $action = '';
546 }
547 } else {
548 setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
549 $action = '';
550 }
551 }
552
553 if (!$error) {
554 $db->commit();
555 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
556 exit;
557 } else {
558 $db->rollback();
559 }
560 }
561
562 if ($action == "confirm_save_from_refuse" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $permissiontoadd) {
563 $object = new ExpenseReport($db);
564 $object->fetch($id);
565 $result = $object->set_save_from_refuse($user);
566
567 if ($result > 0) {
568 // Define output language
569 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
570 $outputlangs = $langs;
571 $newlang = '';
572 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
573 $newlang = GETPOST('lang_id', 'aZ09');
574 }
575 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
576 $tmpuser = new User($db);
577 $tmpuser->fetch($object->fk_user_author);
578 $newlang = $tmpuser->lang;
579 }
580 if (!empty($newlang)) {
581 $outputlangs = new Translate("", $conf);
582 $outputlangs->setDefaultLang($newlang);
583 }
584 $model = $object->model_pdf;
585 $ret = $object->fetch($id); // Reload to get new records
586
587 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
588 }
589 }
590
591 if ($result > 0) {
592 // Send mail
593
594 // TO
595 $destinataire = new User($db);
596 $destinataire->fetch($object->fk_user_validator);
597 $emailTo = $destinataire->email;
598
599 // FROM
600 $expediteur = new User($db);
601 $expediteur->fetch($object->fk_user_author);
602 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
603
604 if ($emailFrom && $emailTo) {
605 $filename = array();
606 $filedir = array();
607 $mimetype = array();
608
609 // SUBJECT
610 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
611 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
612 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
613 }
614
615 $subject = $societeName." - ".$langs->transnoentities("ExpenseReportWaitingForReApproval");
616
617 // CONTENT
618 $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
619 $link = '<a href="'.$link.'">'.$link.'</a>';
620 $message = $langs->transnoentities("ExpenseReportWaitingForReApprovalMessage", dol_print_date($object->date_refuse, 'day'), $object->detail_refuse, $expediteur->getFullName($langs), get_date_range($object->date_debut, $object->date_fin, '', $langs));
621 $message .= '<br>'.$langs->transnoentities("ExpenseReportWaitingForReApprovalMessage2", $link);
622
623 // Rebuild pdf
624 /*
625 $object->setDocModel($user,"");
626 $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
627
628 if($resultPDF)
629 {
630 // ATTACHMENT
631 $filename=array(); $filedir=array(); $mimetype=array();
632 array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
633 array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf");
634 array_push($mimetype,"application/pdf");
635 }
636 */
637
638
639 // PREPARE SEND
640 $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
641
642 if (empty($mailfile->error)) {
643 // SEND
644 $result = $mailfile->sendfile();
645 if ($result) {
646 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
647 setEventMessages($mesg, null, 'mesgs');
648 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
649 exit;
650 } else {
651 $langs->load("other");
652 if ($mailfile->error) {
653 $mesg = '';
654 $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
655 $mesg .= '<br>'.$mailfile->error;
656 setEventMessages($mesg, null, 'errors');
657 } else {
658 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
659 }
660 }
661 } else {
662 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
663 $action = '';
664 }
665 } else {
666 setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
667 $action = '';
668 }
669 } else {
670 setEventMessages($object->error, $object->errors, 'errors');
671 }
672 }
673
674 // Approve
675 if ($action == "confirm_approve" && GETPOST("confirm", 'alpha') == "yes" && $id > 0 && $user->hasRight('expensereport', 'approve')) {
676 $object = new ExpenseReport($db);
677 $object->fetch($id);
678
679 $result = $object->setApproved($user);
680
681 if ($result > 0) {
682 // Define output language
683 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
684 $outputlangs = $langs;
685 $newlang = '';
686 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
687 $newlang = GETPOST('lang_id', 'aZ09');
688 }
689 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
690 $tmpuser = new User($db);
691 $tmpuser->fetch($object->fk_user_author);
692 $newlang = $tmpuser->lang;
693 }
694 if (!empty($newlang)) {
695 $outputlangs = new Translate("", $conf);
696 $outputlangs->setDefaultLang($newlang);
697 }
698 $model = $object->model_pdf;
699 $ret = $object->fetch($id); // Reload to get new records
700
701 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
702 }
703 }
704
705 if ($result > 0) {
706 // Send mail
707
708 // TO
709 $destinataire = new User($db);
710 $destinataire->fetch($object->fk_user_author);
711 $emailTo = $destinataire->email;
712
713 // CC
714 $emailCC = getDolGlobalString('NDF_CC_EMAILS');
715 if (empty($emailTo)) {
716 $emailTo = $emailCC;
717 }
718
719 // FROM
720 $expediteur = new User($db);
721 $expediteur->fetch($object->fk_user_approve > 0 ? $object->fk_user_approve : $object->fk_user_validator);
722 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
723
724 if ($emailFrom && $emailTo) {
725 $filename = array();
726 $filedir = array();
727 $mimetype = array();
728
729 // SUBJECT
730 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
731 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
732 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
733 }
734
735 $subject = $societeName." - ".$langs->transnoentities("ExpenseReportApproved");
736
737 // CONTENT
738 $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
739 $link = '<a href="'.$link.'">'.$link.'</a>';
740 $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
741
742 // Rebuilt pdf
743 /*
744 $object->setDocModel($user,"");
745 $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
746
747 if($resultPDF
748 {
749 // ATTACHMENT
750 $filename=array(); $filedir=array(); $mimetype=array();
751 array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
752 array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
753 array_push($mimetype,"application/pdf");
754 }
755 */
756
757 $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, $emailCC, '', 0, -1);
758
759 if (empty($mailfile->error)) {
760 // SEND
761 $result = $mailfile->sendfile();
762 if ($result) {
763 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
764 setEventMessages($mesg, null, 'mesgs');
765 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
766 exit;
767 } else {
768 $langs->load("other");
769 if ($mailfile->error) {
770 $mesg = '';
771 $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
772 $mesg .= '<br>'.$mailfile->error;
773 setEventMessages($mesg, null, 'errors');
774 } else {
775 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
776 }
777 }
778 } else {
779 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
780 $action = '';
781 }
782 } else {
783 setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
784 $action = '';
785 }
786 } else {
787 setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings');
788 $action = '';
789 }
790 }
791
792 if ($action == "confirm_refuse" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->hasRight('expensereport', 'approve')) {
793 $object = new ExpenseReport($db);
794 $object->fetch($id);
795
796 $detailRefuse = GETPOST('detail_refuse', 'alpha');
797 $result = $object->setDeny($user, $detailRefuse);
798
799 if ($result > 0) {
800 // Define output language
801 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
802 $outputlangs = $langs;
803 $newlang = '';
804 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
805 $newlang = GETPOST('lang_id', 'aZ09');
806 }
807 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
808 $tmpuser = new User($db);
809 $tmpuser->fetch($object->fk_user_author);
810 $newlang = $tmpuser->lang;
811 }
812 if (!empty($newlang)) {
813 $outputlangs = new Translate("", $conf);
814 $outputlangs->setDefaultLang($newlang);
815 }
816 $model = $object->model_pdf;
817 $ret = $object->fetch($id); // Reload to get new records
818
819 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
820 }
821 }
822
823 if ($result > 0) {
824 // Send mail
825
826 // TO
827 $destinataire = new User($db);
828 $destinataire->fetch($object->fk_user_author);
829 $emailTo = $destinataire->email;
830
831 // FROM
832 $expediteur = new User($db);
833 $expediteur->fetch($object->fk_user_refuse);
834 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
835
836 if ($emailFrom && $emailTo) {
837 $filename = array();
838 $filedir = array();
839 $mimetype = array();
840
841 // SUBJECT
842 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
843 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
844 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
845 }
846
847 $subject = $societeName." - ".$langs->transnoentities("ExpenseReportRefused");
848
849 // CONTENT
850 $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
851 $link = '<a href="'.$link.'">'.$link.'</a>';
852 $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailRefuse, $link);
853
854 // Rebuilt pdf
855 /*
856 $object->setDocModel($user,"");
857 $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
858
859 if($resultPDF
860 {
861 // ATTACHMENT
862 $filename=array(); $filedir=array(); $mimetype=array();
863 array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
864 array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
865 array_push($mimetype,"application/pdf");
866 }
867 */
868
869 // PREPARE SEND
870 $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
871
872 if (empty($mailfile->error)) {
873 // SEND
874 $result = $mailfile->sendfile();
875 if ($result) {
876 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
877 setEventMessages($mesg, null, 'mesgs');
878 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
879 exit;
880 } else {
881 $langs->load("other");
882 if ($mailfile->error) {
883 $mesg = '';
884 $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
885 $mesg .= '<br>'.$mailfile->error;
886 setEventMessages($mesg, null, 'errors');
887 } else {
888 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
889 }
890 }
891 } else {
892 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
893 $action = '';
894 }
895 } else {
896 setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
897 $action = '';
898 }
899 } else {
900 setEventMessages($langs->trans("FailedtoSetToDeny"), null, 'warnings');
901 $action = '';
902 }
903 }
904
905 //var_dump($user->id == $object->fk_user_validator);exit;
906 if ($action == "confirm_cancel" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->hasRight('expensereport', 'creer')) {
907 if (!GETPOST('detail_cancel', 'alpha')) {
908 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors');
909 } else {
910 $object = new ExpenseReport($db);
911 $object->fetch($id);
912
913 if ($user->id == $object->fk_user_valid || $user->id == $object->fk_user_author) {
914 $detailCancel = GETPOST('detail_cancel', 'alpha');
915 $result = $object->set_cancel($user, $detailCancel);
916
917 if ($result > 0) {
918 // Define output language
919 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
920 $outputlangs = $langs;
921 $newlang = '';
922 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
923 $newlang = GETPOST('lang_id', 'aZ09');
924 }
925 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
926 $tmpuser = new User($db);
927 $tmpuser->fetch($object->fk_user_author);
928 $newlang = $tmpuser->lang;
929 }
930 if (!empty($newlang)) {
931 $outputlangs = new Translate("", $conf);
932 $outputlangs->setDefaultLang($newlang);
933 }
934 $model = $object->model_pdf;
935 $ret = $object->fetch($id); // Reload to get new records
936
937 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
938 }
939 }
940
941 if ($result > 0) {
942 // Send mail
943
944 // TO
945 $destinataire = new User($db);
946 $destinataire->fetch($object->fk_user_author);
947 $emailTo = $destinataire->email;
948
949 // FROM
950 $expediteur = new User($db);
951 $expediteur->fetch($object->fk_user_cancel);
952 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
953
954 if ($emailFrom && $emailTo) {
955 $filename = array();
956 $filedir = array();
957 $mimetype = array();
958
959 // SUBJECT
960 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
961 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
962 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
963 }
964
965 $subject = $societeName." - ".$langs->transnoentities("ExpenseReportCanceled");
966
967 // CONTENT
968 $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
969 $link = '<a href="'.$link.'">'.$link.'</a>';
970 $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $detailCancel, $link);
971
972 // Rebuilt pdf
973 /*
974 $object->setDocModel($user,"");
975 $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs);
976
977 if($resultPDF
978 {
979 // ATTACHMENT
980 $filename=array(); $filedir=array(); $mimetype=array();
981 array_push($filename,dol_sanitizeFileName($object->ref).".pdf");
982 array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf");
983 array_push($mimetype,"application/pdf");
984 }
985 */
986
987 // PREPARE SEND
988 $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
989
990 if (empty($mailfile->error)) {
991 // SEND
992 $result = $mailfile->sendfile();
993 if ($result) {
994 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
995 setEventMessages($mesg, null, 'mesgs');
996 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
997 exit;
998 } else {
999 $langs->load("other");
1000 if ($mailfile->error) {
1001 $mesg = '';
1002 $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
1003 $mesg .= '<br>'.$mailfile->error;
1004 setEventMessages($mesg, null, 'errors');
1005 } else {
1006 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
1007 }
1008 }
1009 } else {
1010 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
1011 $action = '';
1012 }
1013 } else {
1014 setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
1015 $action = '';
1016 }
1017 } else {
1018 setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings');
1019 $action = '';
1020 }
1021 } else {
1022 setEventMessages($object->error, $object->errors, 'errors');
1023 }
1024 }
1025 }
1026
1027 if ($action == "confirm_setdraft" && GETPOST('confirm', 'alpha') == "yes" && $id > 0 && $user->hasRight('expensereport', 'creer')) {
1028 $object = new ExpenseReport($db);
1029 $object->fetch($id);
1030 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid || in_array($object->fk_user_author, $childids)) {
1031 $result = $object->setStatut(ExpenseReport::STATUS_DRAFT);
1032
1033 if ($result > 0) {
1034 // Define output language
1035 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1036 $outputlangs = $langs;
1037 $newlang = '';
1038 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1039 $newlang = GETPOST('lang_id', 'aZ09');
1040 }
1041 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1042 $tmpuser = new User($db);
1043 $tmpuser->fetch($object->fk_user_author);
1044 $newlang = $tmpuser->lang;
1045 }
1046 if (!empty($newlang)) {
1047 $outputlangs = new Translate("", $conf);
1048 $outputlangs->setDefaultLang($newlang);
1049 }
1050 $model = $object->model_pdf;
1051 $ret = $object->fetch($id); // Reload to get new records
1052
1053 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1054 }
1055 }
1056
1057 if ($result > 0) {
1058 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1059 exit;
1060 } else {
1061 setEventMessages($object->error, $object->errors, 'errors');
1062 }
1063 } else {
1064 setEventMessages("NOT_AUTHOR", null, 'errors');
1065 }
1066 }
1067
1068 if ($action == 'set_unpaid' && $id > 0 && $user->hasRight('expensereport', 'to_paid')) {
1069 $object = new ExpenseReport($db);
1070 $object->fetch($id);
1071
1072 $result = $object->setUnpaid($user);
1073
1074 if ($result > 0) {
1075 // Define output language
1076 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1077 $outputlangs = $langs;
1078 $newlang = '';
1079 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1080 $newlang = GETPOST('lang_id', 'aZ09');
1081 }
1082 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1083 $tmpuser = new User($db);
1084 $tmpuser->fetch($object->fk_user_author);
1085 $newlang = $tmpuser->lang;
1086 }
1087 if (!empty($newlang)) {
1088 $outputlangs = new Translate("", $conf);
1089 $outputlangs->setDefaultLang($newlang);
1090 }
1091 $model = $object->model_pdf;
1092 $ret = $object->fetch($id); // Reload to get new records
1093
1094 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1095 }
1096
1097 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1098 exit;
1099 }
1100 }
1101
1102
1103 if ($action == 'set_paid' && $id > 0 && $user->hasRight('expensereport', 'to_paid')) {
1104 $object = new ExpenseReport($db);
1105 $object->fetch($id);
1106
1107 $result = $object->setPaid($id, $user);
1108
1109 if ($result > 0) {
1110 // Define output language
1111 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1112 $outputlangs = $langs;
1113 $newlang = '';
1114 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1115 $newlang = GETPOST('lang_id', 'aZ09');
1116 }
1117 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1118 $tmpuser = new User($db);
1119 $tmpuser->fetch($object->fk_user_author);
1120 $newlang = $tmpuser->lang;
1121 }
1122 if (!empty($newlang)) {
1123 $outputlangs = new Translate("", $conf);
1124 $outputlangs->setDefaultLang($newlang);
1125 }
1126 $model = $object->model_pdf;
1127 $ret = $object->fetch($id); // Reload to get new records
1128
1129 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1130 }
1131 }
1132
1133 if ($result > 0) {
1134 // TODO We must never send an email without a setup or confirm option to choose if email is
1135 // sent or not. So we add a hidden constant to avoid this for the moment.
1136 if (getDolGlobalString('EXPENSEREPORT_SEND_EMAIL_ON_STATUS_PAID')) {
1137 // Send mail
1138
1139 // TO
1140 $destinataire = new User($db);
1141 $destinataire->fetch($object->fk_user_author);
1142 $emailTo = $destinataire->email;
1143
1144 // FROM
1145 $expediteur = new User($db);
1146 $expediteur->fetch($user->id);
1147 $emailFrom = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
1148
1149 if ($emailFrom && $emailTo) {
1150 $filename = array();
1151 $filedir = array();
1152 $mimetype = array();
1153
1154 // SUBJECT
1155 $societeName = getDolGlobalString('MAIN_INFO_SOCIETE_NOM');
1156 if (getDolGlobalString('MAIN_APPLICATION_TITLE')) {
1157 $societeName = getDolGlobalString('MAIN_APPLICATION_TITLE');
1158 }
1159
1160 $subject = $societeName." - ".$langs->transnoentities("ExpenseReportPaid");
1161
1162 // CONTENT
1163 $link = $urlwithroot.'/expensereport/card.php?id='.$object->id;
1164 $link = '<a href="'.$link.'">'.$link.'</a>';
1165 $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link);
1166
1167 // Generate pdf before attachment
1168 $object->setDocModel($user, "");
1169 $resultPDF = expensereport_pdf_create($db, $object, '', "", $langs);
1170
1171 // PREPARE SEND
1172 $mailfile = new CMailFile($subject, $emailTo, $emailFrom, $message, $filedir, $mimetype, $filename, '', '', 0, -1);
1173
1174 if (empty($mailfile->error)) {
1175 // SEND
1176 $result = $mailfile->sendfile();
1177 if ($result) {
1178 $mesg = $langs->trans('MailSuccessfulySent', $mailfile->getValidAddress($emailFrom, 2), $mailfile->getValidAddress($emailTo, 2));
1179 setEventMessages($mesg, null, 'mesgs');
1180
1181 header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id);
1182 exit;
1183 } else {
1184 $langs->load("other");
1185 if ($mailfile->error) {
1186 $mesg = '';
1187 $mesg .= $langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo);
1188 $mesg .= '<br>'.$mailfile->error;
1189 setEventMessages($mesg, null, 'errors');
1190 } else {
1191 setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings');
1192 }
1193 }
1194 } else {
1195 setEventMessages($mailfile->error, $mailfile->errors, 'errors');
1196 }
1197 } else {
1198 setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings');
1199 }
1200 }
1201 } else {
1202 setEventMessages($langs->trans("FailedToSetPaid"), null, 'warnings');
1203 }
1204
1205 $action = '';
1206 }
1207
1208 if ($action == "addline" && $permissiontoadd) {
1209 // First save uploaded file
1210 $fk_ecm_files = 0;
1211 if (GETPOSTISSET('attachfile')) {
1212 $arrayoffiles = GETPOST('attachfile', 'array');
1213 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1214 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1215 $entityprefix = ($conf->entity != '1') ? $conf->entity.'/' : '';
1216 $relativepath = $entityprefix.'expensereport/'.$object->ref.'/'.$arrayoffiles[0];
1217 $ecmfiles = new EcmFiles($db);
1218 $ecmfiles->fetch(0, '', $relativepath);
1219 $fk_ecm_files = $ecmfiles->id;
1220 }
1221 }
1222
1223 // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
1224 if (empty($vatrate)) {
1225 $vatrate = "0.000";
1226 }
1227 $tmpvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', $vatrate));
1228
1229 $value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU');
1230 $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU');
1231 if (empty($value_unit)) {
1232 $value_unit = price2num((float) $value_unit_ht + ((float) $value_unit_ht * (float) $tmpvat / 100), 'MU');
1233 }
1234
1235 $fk_c_exp_tax_cat = GETPOSTINT('fk_c_exp_tax_cat');
1236
1237 $qty = price2num(GETPOST('qty', 'alpha'));
1238 if (empty($qty)) {
1239 $qty = 1;
1240 }
1241
1242 if (!($fk_c_type_fees > 0)) {
1243 $error++;
1244 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1245 $action = '';
1246 }
1247
1248 if ((float) $tmpvat < 0 || $tmpvat === '') {
1249 $error++;
1250 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("VAT")), null, 'errors');
1251 $action = '';
1252 }
1253
1254 // If no date entered
1255 if (empty($date) || $date == "--") {
1256 $error++;
1257 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
1258 } elseif ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) {
1259 // Warning if date out of range or error if this conf is ON
1260 if (getDolGlobalString('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES')) {
1261 $error++;
1262 }
1263
1264 $langs->load("errors");
1265 $type = $error > 0 ? 'errors' : 'warnings';
1266 setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, $type);
1267 }
1268
1269 // If no price entered
1270 if ($value_unit == 0) {
1271 $error++;
1272 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("PriceUTTC")), null, 'errors');
1273 }
1274
1275 // If no project entered
1276 if ($projectRequired && $fk_project <= 0) {
1277 $error++;
1278 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
1279 }
1280
1281 // If no file associated
1282 if ($fileRequired && $fk_ecm_files == 0) {
1283 $error++;
1284 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("File")), null, 'errors');
1285 }
1286
1287 if (!$error) {
1288 $type = 0; // TODO What if service ? We should take the type product/service from the type of expense report llx_c_type_fees
1289
1290 // Insert line
1291 $result = $object->addline($qty, $value_unit, $fk_c_type_fees, $vatrate, $date, $comments, $fk_project, $fk_c_exp_tax_cat, $type, $fk_ecm_files);
1292 if ($result > 0) {
1293 $ret = $object->fetch($object->id); // Reload to get new records
1294
1295 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1296 // Define output language
1297 $outputlangs = $langs;
1298 $newlang = GETPOST('lang_id', 'alpha');
1299 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1300 $tmpuser = new User($db);
1301 $tmpuser->fetch($object->fk_user_author);
1302 $newlang = $tmpuser->lang;
1303 }
1304 if (!empty($newlang)) {
1305 $outputlangs = new Translate("", $conf);
1306 $outputlangs->setDefaultLang($newlang);
1307 }
1308
1309 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1310 }
1311
1312 unset($qty);
1313 unset($value_unit_ht);
1314 unset($value_unit);
1315 unset($vatrate);
1316 unset($comments);
1317 unset($fk_c_type_fees);
1318 $fk_project = 0;
1319
1320 $date = false;
1321 } else {
1322 $error++;
1323 setEventMessages($object->error, $object->errors, 'errors');
1324 }
1325 }
1326
1327 if (!$error) {
1328 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
1329 exit;
1330 } else {
1331 $action = '';
1332 }
1333 }
1334
1335 // A line can be deleted only when lines can be added or modified: report in draft or refused
1336 if ($action == 'confirm_delete_line' && (empty($object->id) || ($object->status != ExpenseReport::STATUS_DRAFT && $object->status != ExpenseReport::STATUS_REFUSED)) && $permissiontoadd) {
1337 setEventMessages($langs->trans("ErrorDeleteLineNotAllowedByObjectStatus"), null, 'errors');
1338 $action = '';
1339 }
1340
1341 if ($action == 'confirm_delete_line' && GETPOST("confirm", 'alpha') == "yes" && $permissiontoadd) {
1342 $object = new ExpenseReport($db);
1343 $object->fetch($id);
1344
1345 $object_ligne = new ExpenseReportLine($db);
1346 $object_ligne->fetch(GETPOSTINT("rowid"));
1347 $total_ht = $object_ligne->total_ht;
1348 $total_tva = $object_ligne->total_tva;
1349
1350 $result = $object->deleteLine(GETPOSTINT("rowid"), $user);
1351 if ($result >= 0) {
1352 if ($result > 0) {
1353 // Define output language
1354 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1355 $outputlangs = $langs;
1356 $newlang = '';
1357 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1358 $newlang = GETPOST('lang_id', 'aZ09');
1359 }
1360 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1361 $tmpuser = new User($db);
1362 $tmpuser->fetch($object->fk_user_author);
1363 $newlang = $tmpuser->lang;
1364 }
1365 if (!empty($newlang)) {
1366 $outputlangs = new Translate("", $conf);
1367 $outputlangs->setDefaultLang($newlang);
1368 }
1369 $model = $object->model_pdf;
1370 $ret = $object->fetch($id); // Reload to get new records
1371
1372 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1373 }
1374 }
1375
1376 header("Location: ".$_SERVER["PHP_SELF"]."?id=".GETPOSTINT('id'));
1377 exit;
1378 } else {
1379 setEventMessages($object->error, $object->errors, 'errors');
1380 }
1381 }
1382
1383 if ($action == "updateline" && $permissiontoadd) {
1384 $object = new ExpenseReport($db);
1385 $object->fetch($id);
1386
1387 // First save uploaded file
1388 $fk_ecm_files = 0;
1389 if (GETPOSTISSET('attachfile')) {
1390 $arrayoffiles = GETPOST('attachfile', 'array');
1391 if (is_array($arrayoffiles) && !empty($arrayoffiles[0])) {
1392 include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php';
1393 $entityprefix = ($conf->entity != '1') ? $conf->entity.'/' : '';
1394 $relativepath = $entityprefix.'expensereport/'.$object->ref.'/'.$arrayoffiles[0];
1395 $ecmfiles = new EcmFiles($db);
1396 $ecmfiles->fetch(0, '', $relativepath);
1397 $fk_ecm_files = $ecmfiles->id;
1398 }
1399 }
1400
1401 $rowid = GETPOSTINT('rowid');
1402 $type_fees_id = GETPOSTINT('fk_c_type_fees');
1403 $fk_c_exp_tax_cat = GETPOSTINT('fk_c_exp_tax_cat');
1404 $projet_id = $fk_project;
1405 $comments = GETPOST('comments', 'restricthtml');
1406 $qty = price2num(GETPOST('qty', 'alpha'));
1407 $vatrate = GETPOST('vatrate', 'alpha');
1408
1409 // if VAT is not used in Dolibarr, set VAT rate to 0 because VAT rate is necessary.
1410 if (empty($vatrate)) {
1411 $vatrate = "0.000";
1412 }
1413 $tmpvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', $vatrate));
1414
1415 $value_unit_ht = price2num(GETPOST('value_unit_ht', 'alpha'), 'MU');
1416 $value_unit = price2num(GETPOST('value_unit', 'alpha'), 'MU');
1417 if (empty($value_unit)) {
1418 $value_unit = price2num((float) $value_unit_ht + ((float) $value_unit_ht * (float) $tmpvat / 100), 'MU');
1419 }
1420
1421 if (!GETPOSTINT('fk_c_type_fees') > 0) {
1422 $error++;
1423 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1424 $action = '';
1425 }
1426 if ((float) $tmpvat < 0 || $tmpvat == '') {
1427 $error++;
1428 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Vat")), null, 'errors');
1429 $action = '';
1430 }
1431 // Warning if date out of range
1432 if ($date < $object->date_debut || $date > ($object->date_fin + (24 * 3600 - 1))) {
1433 if (getDolGlobalString('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES')) {
1434 $error++;
1435 }
1436
1437 $langs->load("errors");
1438 $type = $error > 0 ? 'errors' : 'warnings';
1439 setEventMessages($langs->trans("WarningDateOfLineMustBeInExpenseReportRange"), null, $type);
1440 }
1441
1442 // If no project entered
1443 if ($projectRequired && $projet_id <= 0) {
1444 $error++;
1445 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Project")), null, 'errors');
1446 }
1447
1448 if (!$error) {
1449 // TODO Use update method of ExpenseReportLine
1450 $result = $object->updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, (float) $qty, (float) $value_unit, $date, $id, $fk_c_exp_tax_cat, $fk_ecm_files);
1451 if ($result >= 0) {
1452 if ($result > 0) {
1453 // Define output language
1454 if (!getDolGlobalString('MAIN_DISABLE_PDF_AUTOUPDATE')) {
1455 $outputlangs = $langs;
1456 $newlang = '';
1457 if (getDolGlobalInt('MAIN_MULTILANGS') /* && empty($newlang) */ && GETPOST('lang_id', 'aZ09')) {
1458 $newlang = GETPOST('lang_id', 'aZ09');
1459 }
1460 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1461 $tmpuser = new User($db);
1462 $tmpuser->fetch($object->fk_user_author);
1463 $newlang = $tmpuser->lang;
1464 }
1465 if (!empty($newlang)) {
1466 $outputlangs = new Translate("", $conf);
1467 $outputlangs->setDefaultLang($newlang);
1468 }
1469 $model = $object->model_pdf;
1470 $ret = $object->fetch($id); // Reload to get new records
1471
1472 $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1473 }
1474
1475 unset($qty);
1476 unset($value_unit_ht);
1477 unset($value_unit);
1478 unset($vatrate);
1479 unset($comments);
1480 unset($fk_c_type_fees);
1481 unset($fk_project);
1482 unset($date);
1483 }
1484
1485 $action = '';
1486 } else {
1487 setEventMessages($object->error, $object->errors, 'errors');
1488 }
1489 }
1490 }
1491
1492 // Actions when printing a doc from card
1493 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1494
1495 // Actions to send emails
1496 $triggersendname = 'EXPENSEREPORT_SENTBYMAIL';
1497 $autocopy = 'MAIN_MAIL_AUTOCOPY_EXPENSEREPORT_TO';
1498 $trackid = 'exp'.$object->id;
1499 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1500
1501 // Actions to build doc
1502 $upload_dir = $conf->expensereport->dir_output;
1503 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1504}
1505
1506
1507/*
1508 * View
1509 */
1510
1511$title = $langs->trans("ExpenseReport")." - ".$langs->trans("Card");
1512$help_url = "EN:Module_Expense_Reports|FR:Module_Notes_de_frais";
1513
1514llxHeader("", $title, $help_url);
1515
1516$form = new Form($db);
1517$formfile = new FormFile($db);
1518$formproject = new FormProjets($db);
1519$projecttmp = new Project($db);
1520$paymentexpensereportstatic = new PaymentExpenseReport($db);
1521$bankaccountstatic = new Account($db);
1522$ecmfilesstatic = new EcmFiles($db);
1523$formexpensereport = new FormExpenseReport($db);
1524$remaintopay = 0;
1525
1526// Create
1527if ($action == 'create') {
1528 print load_fiche_titre($langs->trans("NewTrip"), '', 'trip');
1529
1530 print '<form action="'.$_SERVER['PHP_SELF'].'" method="post" name="create">';
1531 print '<input type="hidden" name="token" value="'.newToken().'">';
1532 print '<input type="hidden" name="action" value="add">';
1533 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1534
1535 print dol_get_fiche_head([]);
1536
1537 print '<table class="border centpercent">';
1538 print '<tbody>';
1539
1540 // User for expense report
1541 print '<tr>';
1542 print '<td class="fieldrequired">'.$langs->trans("User").'</td>';
1543 print '<td>';
1544 $defaultselectuser = $user->id;
1545 if (GETPOSTINT('fk_user_author') > 0) {
1546 $defaultselectuser = GETPOSTINT('fk_user_author');
1547 }
1548 $include_users = 'hierarchyme';
1549 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expensereport', 'writeall_advance')) {
1550 $include_users = array();
1551 }
1552 print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($defaultselectuser, 'fk_user_author', 0, null, 0, $include_users, '', '0,'.$conf->entity, 0, 0, '', 0, '', 'minwidth200 maxwidth500 inline-block');
1553 print '</td>';
1554 print '</tr>';
1555
1556 // Date start
1557 print '<tr>';
1558 print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("DateStart").'</td>';
1559 print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1560 print $form->selectDate($date_start ? $date_start : -1, 'date_debut', 0, 0, 0, '', 1, 1);
1561 print '</td>';
1562 print '</tr>';
1563
1564 // Date end
1565 print '<tr>';
1566 print '<td class="fieldrequired">'.$langs->trans("DateEnd").'</td>';
1567 print '<td>'.img_picto('', 'action', 'class="pictofixedwidth"');
1568 print $form->selectDate($date_end ? $date_end : -1, 'date_fin', 0, 0, 0, '', 1, 1);
1569 print '</td>';
1570 print '</tr>';
1571
1572
1573 // Approver
1574 print '<tr>';
1575 print '<td>'.$langs->trans("ReviewedByCP").'</td>';
1576 print '<td>';
1577 $object = new ExpenseReport($db);
1578 $include_users = $object->fetch_users_approver_expensereport();
1579 if (empty($include_users)) {
1580 print img_warning().' '.$langs->trans("NobodyHasPermissionToValidateExpenseReport");
1581 } else {
1582 $defaultselectuser = (empty($user->fk_user_expense_validator) ? $user->fk_user : $user->fk_user_expense_validator); // Will work only if supervisor has permission to approve so is inside include_users
1583 if (getDolGlobalString('EXPENSEREPORT_DEFAULT_VALIDATOR')) {
1584 $defaultselectuser = getDolGlobalString('EXPENSEREPORT_DEFAULT_VALIDATOR'); // Can force default approver
1585 }
1586 if (GETPOSTINT('fk_user_validator') > 0) {
1587 $defaultselectuser = GETPOSTINT('fk_user_validator');
1588 }
1589 $s = $form->select_dolusers($defaultselectuser, "fk_user_validator", 1, null, ((empty($defaultselectuser) || !getDolGlobalString('EXPENSEREPORT_DEFAULT_VALIDATOR_UNCHANGEABLE')) ? 0 : 1), $include_users);
1590 print img_picto('', 'user', 'class="pictofixedwidth"').$form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1591 }
1592 print '</td>';
1593 print '</tr>';
1594
1595 // Payment mode
1596 if (getDolGlobalString('EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION')) {
1597 print '<tr>';
1598 print '<td>'.$langs->trans("ModePaiement").'</td>';
1599 print '<td>';
1600 $form->select_types_paiements('', 'fk_c_paiement');
1601 print '</td>';
1602 print '</tr>';
1603 }
1604
1605 // Public note
1606 $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : '';
1607
1608 print '<tr>';
1609 print '<td class="tdtop">'.$langs->trans('NotePublic').'</td>';
1610 print '<td>';
1611
1612 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1613 print $doleditor->Create(1);
1614 print '</td></tr>';
1615
1616 // Private note
1617 $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : '';
1618
1619 if (empty($user->socid)) {
1620 print '<tr>';
1621 print '<td class="tdtop">'.$langs->trans('NotePrivate').'</td>';
1622 print '<td>';
1623
1624 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1625 print $doleditor->Create(1);
1626 print '</td></tr>';
1627 }
1628
1629 // Other attributes
1630 $parameters = array('colspan' => ' colspan="3"', 'cols' => 3);
1631 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by
1632 print $hookmanager->resPrint;
1633 if (empty($reshook)) {
1634 print $object->showOptionals($extrafields, 'create', $parameters);
1635 }
1636
1637 print '<tbody>';
1638 print '</table>';
1639
1640 print dol_get_fiche_end();
1641
1642 print $form->buttonsSaveCancel("AddTrip");
1643
1644 print '</form>';
1645} elseif ($object->id > 0) {
1646 $userauthor = null;
1647 $result = $object->fetch($id, $ref);
1648
1649 if ($result > 0) {
1650 if (!in_array($object->fk_user_author, $childids)) {
1651 if (!$user->hasRight('expensereport', 'readall') && !$user->hasRight('expensereport', 'lire_tous')
1652 && (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || !$user->hasRight('expensereport', 'writeall_advance'))) {
1653 print load_fiche_titre($langs->trans('TripCard'), '', 'trip');
1654
1655 print '<div class="tabBar">';
1656 print $langs->trans('NotUserRightToView');
1657 print '</div>';
1658
1659 // End of page
1660 llxFooter();
1661
1662 $db->close();
1663
1664 exit;
1665 }
1666 }
1667
1668 $head = expensereport_prepare_head($object);
1669
1670 if ($action == 'edit' && ($object->status <= ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED)) {
1671 print "<form name='update' action=\"".$_SERVER['PHP_SELF']."\" method=\"post\">\n";
1672 print '<input type="hidden" name="token" value="'.newToken().'">';
1673 print '<input type="hidden" name="id" value="'.$id.'">';
1674 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1675
1676 print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), 0, 'trip', 0, '', '', 0, '', 0); // No drag and drop on the edit form, dropping a file reloads the page and discards it
1677
1678 if ($object->status == ExpenseReport::STATUS_REFUSED) {
1679 print '<input type="hidden" name="action" value="updateFromRefuse">';
1680 } else {
1681 print '<input type="hidden" name="action" value="update">';
1682 }
1683
1684 $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1685
1686 print '<table class="border centpercent">';
1687
1688 print '<tr>';
1689 print '<td>'.$langs->trans("User").'</td>';
1690 print '<td>';
1691 $userfee = new User($db);
1692 if ($object->fk_user_author > 0) {
1693 $userfee->fetch($object->fk_user_author);
1694 print $userfee->getNomUrl(-1);
1695 }
1696 print '</td></tr>';
1697
1698 // Ref
1699 print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td><td>';
1700 print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
1701 print '</td></tr>';
1702
1703 print '<tr>';
1704 print '<td>'.$langs->trans("DateStart").'</td>';
1705 print '<td>';
1706 print $form->selectDate($object->date_debut, 'date_debut');
1707 print '</td>';
1708 print '</tr>';
1709 print '<tr>';
1710 print '<td>'.$langs->trans("DateEnd").'</td>';
1711 print '<td>';
1712 print $form->selectDate($object->date_fin, 'date_fin');
1713 print '</td>';
1714 print '</tr>';
1715
1716 if (getDolGlobalString('EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION')) {
1717 print '<tr>';
1718 print '<td>'.$langs->trans("ModePaiement").'</td>';
1719 print '<td>';
1720 $form->select_types_paiements((string) $object->fk_c_paiement, 'fk_c_paiement');
1721 print '</td>';
1722 print '</tr>';
1723 }
1724
1725 if ($object->status < 3) {
1726 print '<tr>';
1727 print '<td>'.$langs->trans("VALIDATOR").'</td>'; // Approbator
1728 print '<td>';
1729 $include_users = $object->fetch_users_approver_expensereport();
1730 $s = $form->select_dolusers($object->fk_user_validator, "fk_user_validator", 1, null, 0, $include_users);
1731 print $form->textwithpicto($s, $langs->trans("AnyOtherInThisListCanValidate"));
1732 print '</td>';
1733 print '</tr>';
1734 } else {
1735 print '<tr>';
1736 print '<td>'.$langs->trans("VALIDOR").'</td>';
1737 print '<td>';
1738 $userfee = new User($db);
1739 $userfee->fetch($object->fk_user_valid);
1740 print $userfee->getNomUrl(-1);
1741 print '</td></tr>';
1742 }
1743
1744 if ($object->status == ExpenseReport::STATUS_CLOSED) {
1745 print '<tr>';
1746 print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
1747 print '<td>';
1748 $userfee = new User($db);
1749 $userfee->fetch($user->id);
1750 print $userfee->getNomUrl(-1);
1751 print '</td></tr>';
1752 }
1753
1754 // Other attributes
1755 //$cols = 3;
1756 //include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_edit.tpl.php';
1757
1758 print '</table>';
1759
1760 print dol_get_fiche_end();
1761
1762 print $form->buttonsSaveCancel("Modify");
1763
1764 print '</form>';
1765 } else {
1766 $taxlessUnitPriceDisabled = getDolGlobalString('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ? ' disabled' : '';
1767
1768 print dol_get_fiche_head($head, 'card', $langs->trans("ExpenseReport"), -1, 'trip', 0, '', '', 0, '', 1);
1769
1770 $formconfirm = '';
1771
1772 // Clone confirmation
1773 if ($action == 'clone') {
1774 // Create an array for form
1775 $criteriaforfilter = 'hierarchyme';
1776 if (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('expensereport', 'writeall_advance')) {
1777 $criteriaforfilter = '';
1778 }
1779 $formquestion = array(
1780 'text' => '',
1781 0 => array('type' => 'other', 'name' => 'fk_user_author', 'label' => $langs->trans("SelectTargetUser"), 'value' => $form->select_dolusers((GETPOSTINT('fk_user_author') > 0 ? GETPOSTINT('fk_user_author') : $user->id), 'fk_user_author', 0, null, 0, $criteriaforfilter, '', '0', 0, 0, '', 0, '', 'maxwidth150'))
1782 );
1783 // Paiement incomplet. On demande si motif = escompte ou autre
1784 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneExpenseReport', $object->ref), 'confirm_clone', $formquestion, 'yes', 1);
1785 }
1786
1787 if ($action == 'save') {
1788 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("SaveTrip"), $langs->trans("ConfirmSaveTrip"), "confirm_validate", "", "", 1);
1789 }
1790
1791 if ($action == 'save_from_refuse') {
1792 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("SaveTrip"), $langs->trans("ConfirmSaveTrip"), "confirm_save_from_refuse", "", "", 1);
1793 }
1794
1795 if ($action == 'delete') {
1796 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("DeleteTrip"), $langs->trans("ConfirmDeleteTrip"), "confirm_delete", "", "", 1);
1797 }
1798
1799 if ($action == 'validate') {
1800 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("ValideTrip"), $langs->trans("ConfirmValideTrip"), "confirm_approve", "", "", 1);
1801 }
1802
1803 if ($action == 'paid') {
1804 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("PaidTrip"), $langs->trans("ConfirmPaidTrip"), "confirm_paid", "", "", 1);
1805 }
1806
1807 if ($action == 'cancel') {
1808 $array_input = array('text' => $langs->trans("ConfirmCancelTrip"), 0 => array('type' => "text", 'label' => '<strong>'.$langs->trans("Comment").'</strong>', 'name' => "detail_cancel", 'value' => ""));
1809 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("Cancel"), "", "confirm_cancel", $array_input, "", 1);
1810 }
1811
1812 if ($action == 'setdraft') {
1813 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("BrouillonnerTrip"), $langs->trans("ConfirmBrouillonnerTrip"), "confirm_setdraft", "", "", 1);
1814 }
1815
1816 if ($action == 'refuse') { // Deny
1817 $array_input = array('text' => $langs->trans("ConfirmRefuseTrip"), 0 => array('type' => "text", 'label' => $langs->trans("Comment"), 'name' => "detail_refuse", 'value' => ""));
1818 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id, $langs->trans("Deny"), '', "confirm_refuse", $array_input, "yes", 1);
1819 }
1820
1821 if ($action == 'delete_line') {
1822 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$id."&rowid=".GETPOSTINT('rowid'), $langs->trans("DeleteLine"), $langs->trans("ConfirmDeleteLine"), "confirm_delete_line", '', 'yes', 1);
1823 }
1824
1825 // Call Hook formConfirm
1826 $parameters = array('formConfirm' => $formconfirm);
1827 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1828 if (empty($reshook)) {
1829 $formconfirm .= $hookmanager->resPrint;
1830 } elseif ($reshook > 0) {
1831 $formconfirm = $hookmanager->resPrint;
1832 }
1833
1834 // Print form confirm
1835 print $formconfirm;
1836
1837 // Expense report card
1838 $linkback = '<a href="'.DOL_URL_ROOT.'/expensereport/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1839
1840 $morehtmlref = '<div class="refidno">';
1841 $summary = $object->getSummary();
1842 if ($summary !== '') {
1843 $morehtmlref .= $langs->trans('Summary').': '.dol_escape_htmltag($summary);
1844 }
1845 $morehtmlref .= '</div>';
1846
1847 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
1848
1849 print '<div class="fichecenter">';
1850 print '<div class="fichehalfleft">';
1851 print '<div class="underbanner clearboth"></div>';
1852
1853 print '<table class="border tableforfield centpercent">';
1854
1855 // Author
1856 print '<tr>';
1857 print '<td class="titlefield">'.$langs->trans("User").'</td>';
1858 print '<td>';
1859 if ($object->fk_user_author > 0) {
1860 $userauthor = new User($db);
1861 $result = $userauthor->fetch($object->fk_user_author);
1862 if ($result < 0) {
1863 dol_print_error(null, $userauthor->error);
1864 } elseif ($result > 0) {
1865 print $userauthor->getNomUrl(-1);
1866 }
1867 }
1868 print '</td></tr>';
1869
1870 // Period
1871 print '<tr>';
1872 print '<td class="titlefield">'.$langs->trans("Period").'</td>';
1873 print '<td>';
1874 print get_date_range($object->date_debut, $object->date_fin, 'day', $langs, 0);
1875 print '</td>';
1876 print '</tr>';
1877 if (getDolGlobalString('EXPENSEREPORT_ASK_PAYMENTMODE_ON_CREATION')) {
1878 print '<tr>';
1879 print '<td>'.$langs->trans("ModePaiement").'</td>';
1880 print '<td>'.$object->fk_c_paiement.'</td>';
1881 print '</tr>';
1882 }
1883
1884 // Validation date
1885 print '<tr>';
1886 print '<td>'.$langs->trans("DATE_SAVE").'</td>';
1887 print '<td>'.dol_print_date($object->date_valid, 'dayhour', 'tzuser');
1888 if ($object->status == ExpenseReport::STATUS_VALIDATED && $object->hasDelay('toapprove')) {
1889 print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToApprove"));
1890 }
1891 if ($object->status == ExpenseReport::STATUS_APPROVED && $object->hasDelay('topay')) {
1892 print ' '.img_warning($langs->trans("Late").' - '.$langs->trans("ToPay"));
1893 }
1894 print '</td></tr>';
1895 print '</tr>';
1896
1897 // User to inform for approval
1898 if ($object->status <= ExpenseReport::STATUS_VALIDATED) { // informed
1899 print '<tr>';
1900 print '<td>'.$langs->trans("VALIDATOR").'</td>'; // approver
1901 print '<td>';
1902 if ($object->fk_user_validator > 0) {
1903 $userfee = new User($db);
1904 $result = $userfee->fetch($object->fk_user_validator);
1905 if ($result > 0) {
1906 print $userfee->getNomUrl(-1);
1907 }
1908 if (empty($userfee->email) || !isValidEmail($userfee->email)) {
1909 $langs->load("errors");
1910 print img_warning($langs->trans("ErrorBadEMail", $userfee->email));
1911 }
1912 }
1913 print '</td></tr>';
1914 } elseif ($object->status == ExpenseReport::STATUS_CANCELED) {
1915 print '<tr>';
1916 print '<td>'.$langs->trans("CANCEL_USER").'</span></td>';
1917 print '<td>';
1918 if ($object->fk_user_cancel > 0) {
1919 $userfee = new User($db);
1920 $result = $userfee->fetch($object->fk_user_cancel);
1921 if ($result > 0) {
1922 print $userfee->getNomUrl(-1);
1923 }
1924 }
1925 print '</td></tr>';
1926
1927 print '<tr>';
1928 print '<td>'.$langs->trans("MOTIF_CANCEL").'</td>';
1929 print '<td>'.$object->detail_cancel.'</td></tr>';
1930 print '</tr>';
1931 print '<tr>';
1932 print '<td>'.$langs->trans("DATE_CANCEL").'</td>';
1933 print '<td>'.dol_print_date($object->date_cancel, 'dayhour', 'tzuser').'</td></tr>';
1934 print '</tr>';
1935 } else {
1936 print '<tr>';
1937 print '<td>'.$langs->trans("ApprovedBy").'</td>';
1938 print '<td>';
1939 if ($object->fk_user_approve > 0) {
1940 $userapp = new User($db);
1941 $result = $userapp->fetch($object->fk_user_approve);
1942 if ($result > 0) {
1943 print $userapp->getNomUrl(-1);
1944 }
1945 }
1946 print '</td></tr>';
1947
1948 print '<tr>';
1949 print '<td>'.$langs->trans("DateApprove").'</td>';
1950 print '<td>'.dol_print_date($object->date_approve, 'dayhour', 'tzuser').'</td></tr>';
1951 print '</tr>';
1952 }
1953
1954 if ($object->status == ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) {
1955 print '<tr>';
1956 print '<td>'.$langs->trans("REFUSEUR").'</td>';
1957 print '<td>';
1958 $userfee = new User($db);
1959 $result = $userfee->fetch($object->fk_user_refuse);
1960 if ($result > 0) {
1961 print $userfee->getNomUrl(-1);
1962 }
1963 print '</td></tr>';
1964
1965 print '<tr>';
1966 print '<td>'.$langs->trans("DATE_REFUS").'</td>';
1967 print '<td>'.dol_print_date($object->date_refuse, 'dayhour', 'tzuser');
1968 if ($object->detail_refuse) {
1969 print ' - '.$object->detail_refuse;
1970 }
1971 print '</td>';
1972 print '</tr>';
1973 }
1974
1975 if ($object->status == ExpenseReport::STATUS_CLOSED) {
1976 /* TODO this fields are not yet filled
1977 print '<tr>';
1978 print '<td>'.$langs->trans("AUTHORPAIEMENT").'</td>';
1979 print '<td>';
1980 $userfee=new User($db);
1981 $userfee->fetch($object->fk_user_paid);
1982 print $userfee->getNomUrl(-1);
1983 print '</td></tr>';
1984 print '<tr>';
1985 print '<td>'.$langs->trans("DATE_PAIEMENT").'</td>';
1986 print '<td>'.$object->date_paiement.'</td></tr>';
1987 print '</tr>';
1988 */
1989 }
1990
1991 // Other attributes
1992 $cols = 2;
1993 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1994
1995 print '</table>';
1996
1997 print '</div>';
1998 print '<div class="fichehalfright">';
1999 print '<div class="underbanner clearboth"></div>';
2000
2001 print '<table class="border tableforfield centpercent">';
2002
2003 // Amount
2004 print '<tr>';
2005 print '<td class="titlefieldmiddle">'.$langs->trans("AmountHT").'</td>';
2006 print '<td class="nowrap amountcard">'.price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency).'</td>';
2007 $rowspan = 5;
2009 $rowspan++;
2010 } else {
2011 $rowspan += 2;
2012 }
2013 if ($object->status == ExpenseReport::STATUS_REFUSED || !empty($object->detail_refuse)) {
2014 $rowspan += 2;
2015 }
2016 if ($object->status == ExpenseReport::STATUS_CLOSED) {
2017 $rowspan += 2;
2018 }
2019 print "</td>";
2020 print '</tr>';
2021
2022 print '<tr>';
2023 print '<td>'.$langs->trans("AmountVAT").'</td>';
2024 print '<td class="nowrap amountcard">'.price($object->total_tva, 1, '', 1, -1, -1, $conf->currency).'</td>';
2025 print '</tr>';
2026
2027 // Amount Local Taxes
2028 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { // Localtax1
2029 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
2030 print '<td class="valuefield">'.price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency).'</td></tr>';
2031 }
2032 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { // Localtax2 IRPF
2033 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
2034 print '<td class="valuefield">'.price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency).'</td></tr>';
2035 }
2036
2037 print '<tr>';
2038 print '<td>'.$langs->trans("AmountTTC").'</td>';
2039 print '<td class="nowrap amountcard">'.price($object->total_ttc, 1, '', 1, -1, -1, $conf->currency).'</td>';
2040 print '</tr>';
2041
2042 // List of payments already done
2043 $canSeeBankAccount = isModEnabled('bank') && $user->hasRight('banque', 'lire');
2044 $nbcols = 3;
2045 $nbrows = 0;
2046 if ($canSeeBankAccount) {
2047 $nbrows++;
2048 $nbcols++;
2049 }
2050
2051 print '<div class="div-table-responsive-no-min">';
2052 print '<table class="noborder paymenttable centpercent">';
2053
2054 print '<tr class="liste_titre">';
2055 print '<td class="liste_titre">'.$langs->trans('Payments').'</td>';
2056 print '<td class="liste_titre">'.$langs->trans('Date').'</td>';
2057 print '<td class="liste_titre">'.$langs->trans('Type').'</td>';
2058 if ($canSeeBankAccount) {
2059 print '<td class="liste_titre right">'.$langs->trans('BankAccount').'</td>';
2060 }
2061 print '<td class="liste_titre" width="18">&nbsp;</td>';
2062 print '<td class="liste_titre right">'.$langs->trans('Amount').'</td>';
2063 print '</tr>';
2064
2065 // Payments already done (from payment on this expensereport)
2066 $sql = "SELECT p.rowid, p.num_payment, p.datep as dp, p.amount, p.fk_bank,";
2067 $sql .= "c.code as payment_code, c.libelle as payment_type,";
2068 $sql .= "ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal";
2069 $sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e, ".MAIN_DB_PREFIX."payment_expensereport as p";
2070 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as c ON p.fk_typepayment = c.id";
2071 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
2072 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
2073 $sql .= " WHERE e.rowid = ".((int) $id);
2074 $sql .= " AND p.fk_expensereport = e.rowid";
2075 $sql .= ' AND e.entity IN ('.getEntity('expensereport').')';
2076 $sql .= " ORDER BY dp";
2077
2078 $resql = $db->query($sql);
2079 if ($resql) {
2080 $num = $db->num_rows($resql);
2081 $i = 0;
2082 $totalpaid = 0;
2083 while ($i < $num) {
2084 $objp = $db->fetch_object($resql);
2085
2086 $paymentexpensereportstatic->id = $objp->rowid;
2087 $paymentexpensereportstatic->datep = $db->jdate($objp->dp);
2088 $paymentexpensereportstatic->ref = $objp->rowid;
2089 $paymentexpensereportstatic->num_payment = $objp->num_payment;
2090 $paymentexpensereportstatic->type_code = $objp->payment_code;
2091 $paymentexpensereportstatic->type_label = $objp->payment_type;
2092
2093 print '<tr class="oddeven">';
2094 print '<td>';
2095 print $paymentexpensereportstatic->getNomUrl(1);
2096 print '</td>';
2097 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
2098 $labeltype = $langs->trans("PaymentType".$objp->payment_code) != "PaymentType".$objp->payment_code ? $langs->trans("PaymentType".$objp->payment_code) : $objp->payment_type;
2099 print "<td>".$labeltype.' '.$objp->num_payment."</td>\n";
2100 // Bank account
2101 if ($canSeeBankAccount) {
2102 $bankaccountstatic->id = $objp->baid;
2103 $bankaccountstatic->ref = $objp->baref;
2104 $bankaccountstatic->label = $objp->baref;
2105 $bankaccountstatic->number = $objp->banumber;
2106
2107 if (isModEnabled('accounting')) {
2108 $bankaccountstatic->account_number = $objp->account_number;
2109
2110 $accountingjournal = new AccountingJournal($db);
2111 $accountingjournal->fetch($objp->fk_accountancy_journal);
2112 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
2113 }
2114
2115 print '<td class="right">';
2116 if ($bankaccountstatic->id) {
2117 print $bankaccountstatic->getNomUrl(1, 'transactions');
2118 }
2119 print '</td>';
2120 }
2121 print '<td></td>';
2122 print '<td class="right">'.price($objp->amount)."</td>";
2123 print "</tr>";
2124 $totalpaid += $objp->amount;
2125 $i++;
2126 }
2127 $totalpaid = price2num($totalpaid); // Round $totalpaid to fix floating problem after addition into loop
2128
2129 $remaintopay = price2num($object->total_ttc - (float) $totalpaid);
2130 $resteapayeraffiche = $remaintopay;
2131
2132 if ($remaintopay > 0) {
2133 $cssforamountpaymentcomplete = 'amountremaintopay';
2134 } else {
2135 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
2136 }
2137
2138 if ($object->status == ExpenseReport::STATUS_REFUSED) {
2139 $cssforamountpaymentcomplete = 'amountpaymentneutral strikefordisabled';
2140 } elseif ($object->paid == 1 && $remaintopay > 0) {
2141 $cssforamountpaymentcomplete = 'amountpaymentneutral strikefordisabled';
2142 }
2143 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AlreadyPaid").':</td>';
2144 print '<td></td>';
2145 print '<td class="right">'.price($totalpaid).'</td></tr>';
2146
2147 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("AmountExpected").':</td>';
2148 print '<td></td>';
2149 print '<td class="right">'.price($object->total_ttc).'</td></tr>';
2150
2151 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("RemainderToPay").':</td>';
2152 print '<td></td>';
2153 print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayeraffiche).'</td></tr>';
2154
2155 $db->free($resql);
2156 } else {
2157 dol_print_error($db);
2158 }
2159 print "</table>";
2160 print '</div>';
2161
2162 print '<div class="clearboth"></div>';
2163 print '</div>';
2164
2165
2166 print '<br><br>';
2167
2168 print '<div style="clear: both;"></div>';
2169
2170 $actiontouse = 'updateline';
2171 if (($object->status == ExpenseReport::STATUS_DRAFT || $object->status == ExpenseReport::STATUS_REFUSED) && $action != 'editline') {
2172 $actiontouse = 'addline';
2173 }
2174
2175 print '<form name="expensereport" action="'.$_SERVER["PHP_SELF"].'" enctype="multipart/form-data" method="post" >';
2176 print '<input type="hidden" name="token" value="'.newToken().'">';
2177 print '<input type="hidden" name="action" value="'.$actiontouse.'">';
2178 print '<input type="hidden" name="id" value="'.$object->id.'">';
2179 print '<input type="hidden" name="fk_expensereport" value="'.$object->id.'" />';
2180 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2181 print '<input type="hidden" name="page_y" value="">';
2182
2183 print '<div class="div-table-responsive-no-min">';
2184 print '<table id="tablelines" class="noborder centpercent">';
2185
2186 if (!empty($object->lines)) {
2187 $i = 0;
2188 $total = 0;
2189
2190 print '<tr class="liste_titre headerexpensereportdet">';
2191 print '<td class="center linecollinenb">'.$langs->trans('LineNb').'</td>';
2192 //print '<td class="center">'.$langs->trans('Piece').'</td>';
2193 print '<td class="center linecoldate">'.$langs->trans('Date').'</td>';
2194 if (isModEnabled('project')) {
2195 print '<td class="minwidth100imp linecolproject">'.$langs->trans('Project').'</td>';
2196 }
2197 print '<td class="center linecoltype">'.$langs->trans('Type').'</td>';
2198 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2199 print '<td class="center linecolcarcategory">'.$langs->trans('CarCategory').'</td>';
2200 }
2201 print '<td class="linecoldescription">'.$langs->trans('Description').'</td>';
2202 print '<td class="right linecolvat">'.$langs->trans('VAT').'</td>';
2203 print '<td class="right linecolpriceuht">'.$langs->trans('PriceUHT').'</td>';
2204 print '<td class="right linecolpriceuttc">'.$langs->trans('PriceUTTC').'</td>';
2205 print '<td class="right linecolqty">'.$langs->trans('Qty').'</td>';
2206 if ($action != 'editline') {
2207 print '<td class="right linecolamountht">'.$langs->trans('AmountHT').'</td>';
2208 print '<td class="right linecolamountttc">'.$langs->trans('AmountTTC').'</td>';
2209 }
2210 // Picture
2211 print '<td>';
2212 print '</td>';
2213
2214 // Information if there's a rule restriction
2215 print '<td>';
2216 print '</td>';
2217
2218 // Ajout des boutons de modification/suppression
2219 if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $user->hasRight('expensereport', 'creer')) {
2220 print '<td class="right"></td>';
2221 }
2222 print '</tr>';
2223
2224 foreach ($object->lines as &$line) {
2225 $numline = $i + 1;
2226
2227 if ($action != 'editline' || $line->id != GETPOSTINT('rowid')) {
2228 print '<tr class="oddeven linetr" data-id="'.$line->id.'">';
2229
2230 // Num
2231 print '<td class="center linecollinenb">';
2232 print $numline;
2233 print '</td>';
2234
2235 // Date
2236 print '<td class="center linecoldate">'.dol_print_date($db->jdate($line->date), 'day').'</td>';
2237
2238 // Project
2239 if (isModEnabled('project')) {
2240 print '<td class="lineproject">';
2241 if ($line->fk_project > 0) {
2242 $projecttmp->id = $line->fk_project;
2243 $projecttmp->ref = $line->projet_ref;
2244 $projecttmp->title = $line->projet_title;
2245 print $projecttmp->getNomUrl(1);
2246 }
2247 print '</td>';
2248 }
2249
2250 $titlealt = '';
2251 if (isModEnabled('accounting')) {
2252 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingaccount.class.php';
2253 $accountingaccount = new AccountingAccount($db);
2254 $resaccountingaccount = $accountingaccount->fetch(0, $line->type_fees_accountancy_code, 1);
2255 //$titlealt .= '<span class="opacitymedium">';
2256 $titlealt .= $langs->trans("AccountancyCode").': ';
2257 if ($resaccountingaccount > 0) {
2258 $titlealt .= $accountingaccount->account_number;
2259 } else {
2260 $titlealt .= $langs->trans("NotFound");
2261 }
2262 //$titlealt .= '</span>';
2263 }
2264
2265 // Type of fee
2266 print '<td class="center linecoltype" title="'.dol_escape_htmltag($titlealt).'">';
2267 $labeltype = ($langs->trans(($line->type_fees_code)) == $line->type_fees_code ? $line->type_fees_libelle : $langs->trans($line->type_fees_code));
2268 print $labeltype;
2269 print '</td>';
2270
2271 // IK
2272 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2273 print '<td class="fk_c_exp_tax_cat linecoltaxcat">';
2274 $exp_tax_cat_label = dol_getIdFromCode($db, $line->fk_c_exp_tax_cat, 'c_exp_tax_cat', 'rowid', 'label');
2275 print $langs->trans($exp_tax_cat_label);
2276 print '</td>';
2277 }
2278
2279 // Comment
2280 print '<td class="left linecolcomment minwidth100">'.dol_nl2br($line->comments).'</td>';
2281
2282 // VAT rate
2283 $senderissupplier = 0;
2284 $tooltiponprice = '';
2285 $tooltiponpriceend = '';
2286 if (!getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
2287 $tooltiponprice = $langs->transcountry("TotalHT", $mysoc->country_code).'='.price($line->total_ht);
2288 $tooltiponprice .= '<br>'.$langs->transcountry("TotalVAT", ($senderissupplier ? $object->thirdparty->country_code : $mysoc->country_code)).'='.price($line->total_tva);
2289 if (is_object($object->thirdparty)) {
2290 if ($senderissupplier) {
2291 $seller = $object->thirdparty;
2292 $buyer = $mysoc;
2293 } else {
2294 $seller = $mysoc;
2295 $buyer = $object->thirdparty;
2296 }
2297
2298 if ($mysoc->useLocalTax(1)) {
2299 if (($seller->country_code == $buyer->country_code) || $line->total_localtax1 || $seller->useLocalTax(1)) {
2300 $tooltiponprice .= '<br>'.$langs->transcountry("TotalLT1", $seller->country_code).'='.price($line->total_localtax1);
2301 } else {
2302 $tooltiponprice .= '<br>'.$langs->transcountry("TotalLT1", $seller->country_code).'=<span class="opacitymedium">'.$langs->trans($senderissupplier ? "NotUsedForThisVendor" : "NotUsedForThisCustomer").'</span>';
2303 }
2304 }
2305 if ($mysoc->useLocalTax(2)) {
2306 if ((isset($seller->country_code) && isset($buyer->thirdparty->country_code) && $seller->country_code == $buyer->thirdparty->country_code) || $line->total_localtax2 || $seller->useLocalTax(2)) {
2307 $tooltiponprice .= '<br>'.$langs->transcountry("TotalLT2", $seller->country_code).'='.price($line->total_localtax2);
2308 } else {
2309 $tooltiponprice .= '<br>'.$langs->transcountry("TotalLT2", $seller->country_code).'=<span class="opacitymedium">'.$langs->trans($senderissupplier ? "NotUsedForThisVendor" : "NotUsedForThisCustomer").'</span>';
2310 }
2311 }
2312 }
2313 $tooltiponprice .= '<br>'.$langs->transcountry("TotalTTC", $mysoc->country_code).'='.price($line->total_ttc);
2314
2315 $tooltiponprice = '<span class="classfortooltip" title="'.dol_escape_htmltag($tooltiponprice).'">';
2316 $tooltiponpriceend = '</span>';
2317 }
2318
2319 print '<td class="right linecolvatrate">';
2320 print $tooltiponprice;
2321 print vatrate($line->vatrate.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : ''), true);
2322 print $tooltiponpriceend;
2323 print '</td>';
2324
2325 // Unit price HT
2326 print '<td class="right linecolunitht">';
2327 $tmpvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', $line->vatrate));
2328 $pricenettoshow = price2num((float) $line->value_unit / (1 + (float) $tmpvat / 100), 'MU');
2329 print price($pricenettoshow);
2330 print '</td>';
2331
2332 print '<td class="right linecolunitttc">'.price($line->value_unit).'</td>';
2333
2334 print '<td class="right linecolqty">'.dol_escape_htmltag((string) $line->qty).'</td>';
2335
2336 if ($action != 'editline') {
2337 print '<td class="right linecoltotalht">'.price($line->total_ht).'</td>';
2338 print '<td class="right linecoltotalttc">'.price($line->total_ttc).'</td>';
2339 }
2340
2341 // Column with preview
2342 print '<td class="center linecolpreview">';
2343 if ($line->fk_ecm_files > 0) {
2344 $modulepart = 'expensereport';
2345 $maxheightmini = 32;
2346
2347 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2348 if ($result > 0) {
2349 $relativepath = preg_replace('/^([0-9]+\/)?expensereport\//', '', $ecmfilesstatic->filepath);
2350 $fileinfo = pathinfo($ecmfilesstatic->filepath.'/'.$ecmfilesstatic->filename);
2351 if (image_format_supported($fileinfo['basename']) > 0) {
2352 $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini'); // For new thumbs using same ext (in lower case however) than original
2353 if (!dol_is_file($conf->expensereport->dir_output.'/'.$relativepath.'/'.$minifile)) {
2354 $minifile = getImageFileNameForSize($fileinfo['basename'], '_mini', '.png'); // For backward compatibility of old thumbs that were created with filename in lower case and with .png extension
2355 }
2356 //print $file['path'].'/'.$minifile.'<br>';
2357 $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.'/'.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
2358 if (empty($urlforhref)) {
2359 $urlforhref = DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($relativepath.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']));
2360 print '<a href="'.$urlforhref.'" class="aphoto" target="_blank" rel="noopener noreferrer">';
2361 } else {
2362 print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
2363 }
2364 print '<img class="photo" height="'.$maxheightmini.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart='.$modulepart.'&entity='.(empty($object->entity) ? $conf->entity : $object->entity).'&file='.urlencode($relativepath.'/'.$minifile).'" title="">';
2365 print '</a>';
2366 } else {
2367 if (preg_match('/\.pdf$/i', $ecmfilesstatic->filename)) {
2368 $filepdf = $conf->expensereport->dir_output.'/'.$relativepath.'/'.$ecmfilesstatic->filename;
2369 $fileimage = $conf->expensereport->dir_output.'/'.$relativepath.'/'.$ecmfilesstatic->filename.'_preview.png';
2370 $relativepathimage = $relativepath.'/'.$ecmfilesstatic->filename.'_preview.png';
2371
2372 $pdfexists = file_exists($filepdf);
2373 if ($pdfexists) {
2374 // Conversion du PDF en image png si fichier png non existent
2375 if (!file_exists($fileimage) || (filemtime($fileimage) < filemtime($filepdf))) {
2376 if (!getDolGlobalString('MAIN_DISABLE_PDF_THUMBS')) { // If you experience trouble with pdf thumb generation and imagick, you can disable here.
2377 include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2378 $ret = dol_convert_file($filepdf, 'png', $fileimage, '0'); // Convert first page of PDF into a file _preview.png
2379 if ($ret < 0) {
2380 $error++;
2381 }
2382 }
2383 }
2384 }
2385
2386 if ($pdfexists && !$error) {
2387 $heightforphotref = 70;
2388 if (!empty($conf->dol_optimize_smallscreen)) {
2389 $heightforphotref = 60;
2390 }
2391 $urlforhref = getAdvancedPreviewUrl($modulepart, $relativepath.'/'.$fileinfo['filename'].'.'.strtolower($fileinfo['extension']), 1, '&entity='.(empty($object->entity) ? $conf->entity : $object->entity));
2392 print '<a href="'.$urlforhref['url'].'" class="'.$urlforhref['css'].'" target="'.$urlforhref['target'].'" mime="'.$urlforhref['mime'].'">';
2393 // If the preview file is found we display the thumb
2394 if (file_exists($fileimage)) {
2395 print '<img height="'.$heightforphotref.'" class="photo photowithmargin photowithborder" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=apercu'.$modulepart.'&amp;file='.urlencode($relativepathimage).'">';
2396 } else {
2397 // Else, we display an icon
2398 print img_mime($ecmfilesstatic->filename);
2399 }
2400 print '</a>';
2401 }
2402 }
2403 }
2404 }
2405 }
2406 print '</td>';
2407
2408 print '<td class="nowrap right linecolwarning">';
2409 print !empty($line->rule_warning_message) ? img_warning($line->rule_warning_message) : '&nbsp;';
2410 print '</td>';
2411
2412 // Ajout des boutons de modification/suppression
2413 if (($object->status < ExpenseReport::STATUS_VALIDATED || $object->status == ExpenseReport::STATUS_REFUSED) && $permissiontoadd) {
2414 print '<td class="nowrap right linecolaction">';
2415
2416 print '<a class="editfielda reposition paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=editline&token='.newToken().'&rowid='.$line->rowid.'">';
2417 print img_edit();
2418 print '</a> &nbsp; ';
2419 print '<a class="paddingrightonly" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete_line&token='.newToken().'&rowid='.$line->rowid.'">';
2420 print img_delete();
2421 print '</a>';
2422
2423 print '</td>';
2424 }
2425
2426 print '</tr>';
2427 }
2428
2429 if ($action == 'editline' && $line->id == GETPOSTINT('rowid')) {
2430 // Add line with link to add new file or attach line to an existing file
2431 $colspan = 11;
2432 if (isModEnabled('project')) {
2433 $colspan++;
2434 }
2435 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2436 $colspan++;
2437 }
2438
2439 if (!getDolGlobalString('EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES')) {
2440 print '<!-- line of expense report -->'."\n";
2441 print '<tr class="tredited">';
2442
2443 print '<td class="center">';
2444 print $numline;
2445 print '</td>';
2446
2447 print '<td colspan="'.($colspan - 1).'" class="liste_titre"> ';
2448 print '<a href="" class="commonlink aattachtodoc reposition">'.$langs->trans("LinkTheLineToADocument");
2449 print img_picto($langs->trans("LinkTheLineToADocument"), 'chevron-down', '', 0, 0, 0, '', 'marginleftonly');
2450 print '</a>';
2451
2452 print '<!-- Code to open/close section to submit or link files in edit mode -->'."\n";
2453 print '<script type="text/javascript">'."\n";
2454 print '$(document).ready(function() {
2455 $( ".aattachtodoc" ).click(function() {
2456 /* Show both sections (existing files and upload form) if one of them is hidden, else hide both */
2457 var showsection = (jQuery(".trattachnewfilenow, .truploadnewfilenow").filter(":hidden").length > 0);
2458 jQuery(".trattachnewfilenow, .truploadnewfilenow").toggle(showsection);
2459 return false;
2460 });';
2461 if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array'))) {
2462 print 'jQuery(".trattachnewfilenow, .truploadnewfilenow").show();'."\n";
2463 }
2464 print '
2465 jQuery("form[name=\"expensereport\"]").submit(function() {
2466 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2467 jQuery("input[name=\"sendit\"]").val("");
2468 }
2469 });
2470 ';
2471 print '
2472 });
2473 ';
2474 print '</script>'."\n";
2475 print '</td></tr>';
2476
2477 $filenamelinked = '';
2478 if ($line->fk_ecm_files > 0) {
2479 $result = $ecmfilesstatic->fetch($line->fk_ecm_files);
2480 if ($result > 0) {
2481 $filenamelinked = $ecmfilesstatic->filename;
2482 }
2483 }
2484
2485 $tredited = 'tredited'; // Case the addfile and linkto file is used for edit (used by following tpl)
2486 include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php';
2487 include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php';
2488 }
2489
2490 print '<tr class="oddeven tredited">';
2491
2492 print '<td></td>';
2493
2494 // Select date
2495 print '<td class="center">';
2496 print $form->selectDate($line->date, 'date');
2497 print '</td>';
2498
2499 // Select project
2500 if (isModEnabled('project')) {
2501 print '<td class="nowraponall">';
2502 print $formproject->select_projects(-1, (string) $line->fk_project, 'fk_project', 0, 0, $projectRequired ? 0 : 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth300');
2503 print '</td>';
2504 }
2505
2506 // Select type
2507 print '<td class="center">';
2508 print $formexpensereport->selectTypeExpenseReport($line->fk_c_type_fees, 'fk_c_type_fees');
2509 print '</td>';
2510
2511 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2512 print '<td class="fk_c_exp_tax_cat">';
2513 $params = array('fk_expense' => $object->id, 'fk_expense_det' => $line->id, 'date' => $line->date);
2514 print $form->selectExpenseCategories((string) $line->fk_c_exp_tax_cat, 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', (int) $userauthor->default_c_exp_tax_cat, $params);
2515 print '</td>';
2516 }
2517
2518 // Add comments
2519 print '<td>';
2520 print '<textarea name="comments" class="flat_ndf centpercent">'.dol_escape_htmltag($line->comments, 0, 1).'</textarea>';
2521 print '</td>';
2522
2523 // VAT
2524 $selectedvat = price2num($line->vatrate).(!empty($line->vat_src_code) ? ' ('.$line->vat_src_code.')' : '');
2525 print '<td class="right">';
2526 // We must use null, null for seller and buyer as we don't know them for expense report.
2527 print $form->load_tva('vatrate', (GETPOSTISSET("vatrate") ? GETPOST("vatrate") : $selectedvat), null, null, 0, 0, '', false, 1, 2);
2528 print '</td>';
2529
2530 // Unit price
2531 print '<td class="right">';
2532 print '<input type="text" min="0" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value=""'.$taxlessUnitPriceDisabled.' />';
2533 print '</td>';
2534
2535 // Unit price with tax
2536 print '<td class="right">';
2537 print '<input type="text" min="0" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag(price2num($line->value_unit)).'" />';
2538 print '</td>';
2539
2540 // Quantity
2541 print '<td class="right">';
2542 print '<input type="text" min="0" class="input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag((string) $line->qty).'" />'; // We must be able to enter decimal qty
2543 print '</td>';
2544
2545 //print '<td class="right">'.$langs->trans('AmountHT').'</td>';
2546 //print '<td class="right">'.$langs->trans('AmountTTC').'</td>';
2547
2548 // Picture
2549 print '<td class="center">';
2550 //print $line->fk_ecm_files;
2551 print '</td>';
2552 // Information if there's a rule restriction
2553 print '<td class="center">';
2554 print '</td>';
2555
2556 print '<td>';
2557 print '<input type="hidden" name="rowid" value="'.$line->rowid.'">';
2558 print $form->buttonsSaveCancel('Save', 'Cancel', array(), false, 'small');
2559 print '</td>';
2560
2561 print '</tr>';
2562 }
2563
2564 $i++;
2565 }
2566 }
2567
2568 // Add a new line
2569 if (($object->status == ExpenseReport::STATUS_DRAFT || $object->status == ExpenseReport::STATUS_REFUSED) && $action != 'editline' && $permissiontoadd) {
2570 $colspan = 12;
2571 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2572 $colspan++;
2573 }
2574 if (isModEnabled('project')) {
2575 $colspan++;
2576 }
2577 if ($action != 'editline') {
2578 $colspan++;
2579 }
2580
2581 $nbFiles = $nbLinks = 0;
2582 $arrayoffiles = array();
2583 if (!getDolGlobalString('EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES')) {
2584 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
2585 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
2586 require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
2587 $upload_dir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
2588 $arrayoffiles = dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png|'.preg_quote(dol_sanitizeFileName($object->ref.'.pdf'), '/').')$');
2589 $nbFiles = count($arrayoffiles);
2590 $nbLinks = Link::count($db, $object->element, $object->id);
2591 }
2592
2593 if (!getDolGlobalString('EXPENSEREPORT_DISABLE_ATTACHMENT_ON_LINES')) {
2594 // Add line with link to add new file or attach to an existing file
2595 print '<tr class="liste_titre">';
2596 print '<td colspan="'.$colspan.'" class="liste_titre expensereportautoload">';
2597 print '<a href="" class="commonlink aattachtodoc reposition">'.$langs->trans("LinkTheLineToADocument");
2598 print img_picto($langs->trans("LinkTheLineToADocument"), 'chevron-down', '', 0, 0, 0, '', 'marginleftonly');
2599 print '</a>';
2600
2601 print '<!-- Code to open/close section to submit or link files in the form to add new line -->'."\n";
2602 print '<script type="text/javascript">'."\n";
2603 print '$(document).ready(function() {
2604 $( ".aattachtodoc" ).click(function() {
2605 console.log("We click on toggle of aattachtodoc");
2606 /* Show both sections (existing files and upload form) if one of them is hidden, else hide both */
2607 var showsection = (jQuery(".trattachnewfilenow, .truploadnewfilenow").filter(":hidden").length > 0);
2608 jQuery(".trattachnewfilenow, .truploadnewfilenow").toggle(showsection);
2609 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2610 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2611 } else {
2612 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2613 }
2614 // TODO Switch css fa-chevron-dow and add fa-chevron-up
2615 return false;
2616 });'."\n";
2617 if (is_array(GETPOST('attachfile', 'array')) && count(GETPOST('attachfile', 'array')) && $action != 'updateline') {
2618 print 'jQuery(".trattachnewfilenow, .truploadnewfilenow").show();'."\n";
2619 }
2620 if (GETPOSTISSET('sendit')) {
2621 // After an upload, the section of existing files is already visible, so we also show the upload form
2622 print 'jQuery(".truploadnewfilenow").show();'."\n";
2623 }
2624 print '
2625 jQuery("form[name=\"expensereport\"]").submit(function() {
2626 if (jQuery(".truploadnewfilenow").is(":hidden")) {
2627 /* When section to send file is not expanded, we disable the button sendit that submit form to add a new file, so button to submit line will work. */
2628 jQuery("input[name=\"sendit\"]").val("");
2629 jQuery("input[name=\"sendit\"]").prop("name", "senditdisabled");
2630 } else {
2631 jQuery("input[name=\"senditdisabled\"]").prop("name", "sendit");
2632 }
2633 });
2634 ';
2635 print '
2636 });
2637 ';
2638 print '</script>'."\n";
2639 print '</td></tr>';
2640
2641 $tredited = ''; // Case the addfile and linkto file is used for edit (used by following tpl)
2642 include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_linktofile.tpl.php';
2643 include DOL_DOCUMENT_ROOT.'/expensereport/tpl/expensereport_addfile.tpl.php';
2644 }
2645
2646 print '<tr class="liste_titre expensereportcreate">';
2647 print '<td></td>';
2648 print '<td class="center expensereportcreatedate">'.$langs->trans('Date').'</td>';
2649 if (isModEnabled('project')) {
2650 print '<td class="minwidth100imp">'.$form->textwithpicto($langs->trans('Project'), $langs->trans("ClosedProjectsAreHidden")).'</td>';
2651 }
2652 print '<td class="center expensereportcreatetype">'.$langs->trans('Type').'</td>';
2653 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2654 print '<td>'.$langs->trans('CarCategory').'</td>';
2655 }
2656 print '<td class="expensereportcreatedescription">'.$langs->trans('Description').'</td>';
2657 print '<td class="right expensereportcreatevat">'.$langs->trans('VAT').'</td>';
2658 print '<td class="right expensereportcreatepriceuth">'.$langs->trans('PriceUHT').'</td>';
2659 print '<td class="right expensereportcreatepricettc">'.$langs->trans('PriceUTTC').'</td>';
2660 print '<td class="right expensereportcreateqty">'.$langs->trans('Qty').'</td>';
2661 print '<td></td>';
2662 print '<td></td>';
2663 print '<td></td>';
2664 print '<td></td>';
2665 print '<td></td>';
2666 print '</tr>';
2667 print '<tr class="oddeven nohover">';
2668
2669 // Line number
2670 print '<td></td>';
2671
2672 // Select date
2673 print '<td class="center inputdate">';
2674 print $form->selectDate(!empty($date) ? $date : -1, 'date', 0, 0, 0, '', 1, 1);
2675 print '</td>';
2676
2677 // Select project
2678 if (isModEnabled('project')) {
2679 print '<td class="inputproject">';
2680 $formproject->select_projects(-1, !empty($fk_project) ? (string) $fk_project : '0', 'fk_project', 0, 0, $projectRequired ? 0 : 1, -1, 0, 0, 0, '', 0, 0, 'maxwidth300');
2681 print '</td>';
2682 }
2683
2684 // Select type
2685 print '<td class="center inputtype">';
2686 print $formexpensereport->selectTypeExpenseReport(!empty($fk_c_type_fees) ? $fk_c_type_fees : "", 'fk_c_type_fees', 1);
2687 print '</td>';
2688
2689 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2690 print '<td class="fk_c_exp_tax_cat">';
2691 $params = array('fk_expense' => $object->id);
2692 print $form->selectExpenseCategories('', 'fk_c_exp_tax_cat', 1, array(), 'fk_c_type_fees', $userauthor->default_c_exp_tax_cat, $params, 0);
2693 print '</td>';
2694 }
2695
2696 // Add comments
2697 print '<td class="inputcomment">';
2698 print '<textarea class="flat_ndf centpercent" name="comments" rows="'.ROWS_2.'">'.dol_escape_htmltag(!empty($comments) ? $comments : "", 0, 1).'</textarea>';
2699 print '</td>';
2700
2701 // Select VAT
2702 print '<td class="right inputvat">';
2703 $defaultvat = '';
2704 if (getDolGlobalString('EXPENSEREPORT_NO_DEFAULT_VAT')) {
2705 // If option to have no default VAT on expense report is on, we force MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS
2706 $conf->global->MAIN_VAT_DEFAULT_IF_AUTODETECT_FAILS = 'none';
2707 }
2708 // We must use null, null for seller and buyer as we don't know them for expense report.
2709 print $form->load_tva('vatrate', (!empty($vatrate) ? $vatrate : $defaultvat), null, null, 0, 0, '', false, 1);
2710 print '</td>';
2711
2712 // Unit price net
2713 print '<td class="right inputpricenet">';
2714 print '<input type="text" class="right maxwidth50" id="value_unit_ht" name="value_unit_ht" value="'.dol_escape_htmltag((!empty($value_unit_ht) ? $value_unit_ht : "")).'"'.$taxlessUnitPriceDisabled.' />';
2715 print '</td>';
2716
2717 // Unit price with tax
2718 print '<td class="right inputtax">';
2719 print '<input type="text" class="right maxwidth50" id="value_unit" name="value_unit" value="'.dol_escape_htmltag((!empty($value_unit) ? $value_unit : "")).'">';
2720 print '</td>';
2721
2722 // Quantity
2723 print '<td class="right inputqty">';
2724 print '<input type="text" min="0" class=" input_qty right maxwidth50" name="qty" value="'.dol_escape_htmltag(!empty($qty) ? $qty : 1).'">'; // We must be able to enter decimal qty
2725 print '</td>';
2726
2727 // Picture
2728 print '<td></td>';
2729
2730 if ($action != 'editline') {
2731 print '<td class="right"></td>';
2732 print '<td class="right"></td>';
2733 print '<td></td>';
2734 }
2735
2736 print '<td class="center inputbuttons">';
2737 print $form->buttonsSaveCancel("Add", '', array(), true, 'reposition');
2738 print '</td>';
2739
2740 print '</tr>';
2741 } // End if paid/validated
2742
2743 print '</table>';
2744 print '</div>';
2745
2746 print '<script>
2747
2748 /* JQuery for product free or predefined select */
2749 jQuery(document).ready(function() {
2750 jQuery("#value_unit_ht").keyup(function(event) {
2751 console.log(event.which); // discard event tag and arrows
2752 if (event.which != 9 && (event.which < 37 ||event.which > 40) && jQuery("#value_unit_ht").val() != "") {
2753 jQuery("#value_unit").val("");
2754 }
2755 });
2756 jQuery("#value_unit").keyup(function(event) {
2757 console.log(event.which); // discard event tag and arrows
2758 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2759 jQuery("#value_unit_ht").val("");
2760 }
2761 });
2762 ';
2763
2764 if (getDolGlobalString('MAIN_USE_EXPENSE_IK')) {
2765 print '
2766
2767 /* unit price coef calculation */
2768 jQuery(".input_qty, #fk_c_type_fees, #select_fk_c_exp_tax_cat, #vatrate ").change(function(event) {
2769 console.log("We change a parameter");
2770
2771 let type_fee = jQuery("#fk_c_type_fees").find(":selected").val();
2772 let tax_cat = jQuery("#select_fk_c_exp_tax_cat").find(":selected").val();
2773 let tva = jQuery("#vatrate").find(":selected").val();
2774 let qty = jQuery(".input_qty").val();
2775
2776 let path = "'.DOL_URL_ROOT.'/expensereport/ajax/ajaxik.php";
2777 path += "?fk_c_exp_tax_cat="+tax_cat;
2778 path += "&fk_expense="+'.((int) $object->id).';
2779 path += "&vatrate="+tva;
2780 path += "&qty="+qty;
2781
2782 if (type_fee == 4) { // mileage expenses
2783 if (tax_cat == "" || parseInt(tax_cat) <= 0){
2784 return ;
2785 }
2786
2787 jQuery.ajax({
2788 url: path,
2789 async: true,
2790 dataType: "json",
2791 success: function(response) {
2792 if (response.response_status == "success"){';
2793
2794 if (getDolGlobalString('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY')) {
2795 print '
2796 jQuery("#value_unit").val(parseFloat(response.data) * (100 + parseFloat(tva)) / 100);
2797 jQuery("#value_unit").trigger("change");
2798 ';
2799 } else {
2800 print '
2801 jQuery("#value_unit_ht").val(response.data);
2802 jQuery("#value_unit_ht").trigger("change");
2803 jQuery("#value_unit").val("");
2804 ';
2805 }
2806
2807 print '
2808 } else if(response.response_status == "error" && response.errorMessage != undefined && response.errorMessage.length > 0 ) {
2809 console.log("We get an error result");
2810 $.jnotify(response.errorMessage, "error", {timeout: 0, type: "error"},{ remove: function (){} } );
2811 }
2812 }
2813 });
2814 }
2815
2816 /*console.log(event.which); // discard event tag and arrows
2817 if (event.which != 9 && (event.which < 37 || event.which > 40) && jQuery("#value_unit").val() != "") {
2818 jQuery("#value_unit_ht").val("");
2819 }*/
2820 });
2821 ';
2822 }
2823
2824 print '
2825
2826 });
2827
2828 </script>';
2829
2830 print '</form>';
2831
2832 print dol_get_fiche_end();
2833 }
2834 } else {
2835 dol_print_error($db);
2836 }
2837} else {
2838 print 'Record not found';
2839
2840 llxFooter();
2841 exit(1);
2842}
2843
2844
2845/*
2846 * Action bar
2847 */
2848
2849print '<div class="tabsAction">';
2850
2851if ($action != 'create' && $action != 'edit' && $action != 'editline') {
2852 $object = new ExpenseReport($db);
2853 $object->fetch($id, $ref);
2854
2855 // Send
2856 if (empty($user->socid)) {
2857 if ($object->status > ExpenseReport::STATUS_DRAFT) {
2858 print dolGetButtonAction('', $langs->trans('SendMail'), 'email', dolBuildUrl($_SERVER["PHP_SELF"], ['id' => $object->id, 'action' => 'presend', 'mode' => 'init'], true).'#formmailbeforetitle', '');
2859 }
2860 }
2861
2862 /* If status is "Draft"
2863 * AND user has "create/delete" right
2864 * AND fk_user_author == current user
2865 * Show: "Save" / "Modify" / "Delete"
2866 */
2867 if ($user->hasRight('expensereport', 'creer') && $object->status == ExpenseReport::STATUS_DRAFT) {
2868 if (in_array($object->fk_user_author, $childids) || $user->hasRight('expensereport', 'writeall_advance')) {
2869 // Modify
2870 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2871
2872 // Validate
2873 if (count($object->lines) > 0) {
2874 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save&token='.newToken().'&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
2875 }
2876 }
2877 }
2878
2879 /* If status is "Refused"
2880 * AND user has "create/delete" right
2881 * AND fk_user_author == current user
2882 * Show: "Save" / "Modify" / "Delete"
2883 */
2884 if ($user->hasRight('expensereport', 'creer') && $object->status == ExpenseReport::STATUS_REFUSED) {
2885 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2886 // Modify
2887 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Modify').'</a></div>';
2888
2889 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=save_from_refuse&token='.newToken().'&id='.$object->id.'">'.$langs->trans('ValidateAndSubmit').'</a></div>';
2890 }
2891 }
2892
2893 if ($user->hasRight('expensereport', 'to_paid') && $object->status == ExpenseReport::STATUS_APPROVED) {
2894 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2895 // setdraft
2896 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
2897 }
2898 }
2899
2900 /* If status is "Pending approval"
2901 * AND user has "approve" right
2902 * AND fk_user_validator == current user
2903 * Show: "Validate" / "Refuse" / "Delete"
2904 */
2906 if (in_array($object->fk_user_author, $childids)) {
2907 // set draft
2908 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=setdraft&token='.newToken().'&id='.$object->id.'">'.$langs->trans('SetToDraft').'</a></div>';
2909 }
2910 }
2911
2912 if ($user->hasRight('expensereport', 'approve') && $object->status == ExpenseReport::STATUS_VALIDATED) {
2913 //if($object->fk_user_validator==$user->id)
2914 //{
2915 // Validate
2916 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=validate&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Approve').'</a></div>';
2917 // Deny
2918 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
2919 //}
2920
2921 if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) {
2922 // Cancel
2923 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Cancel").'</a></div>';
2924 }
2925 }
2926
2927
2928 // If status is Approved
2929 // ---------------------
2930
2931 if ($user->hasRight('expensereport', 'approve') && $object->status == ExpenseReport::STATUS_APPROVED) {
2932 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=refuse&token='.newToken().'&id='.$object->id.'">'.$langs->trans('Deny').'</a></div>';
2933 }
2934
2935 // If bank module is used
2936 if ($user->hasRight('expensereport', 'to_paid') && isModEnabled("bank") && $object->status == ExpenseReport::STATUS_APPROVED) {
2937 // Pay
2938 if ($remaintopay == 0) {
2939 print '<div class="inline-block divButAction"><span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseRemainderToPayIsZero").'">'.$langs->trans('DoPayment').'</span></div>';
2940 } else {
2941 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/expensereport/payment/payment.php?id='.$object->id.'&action=create">'.$langs->trans('DoPayment').'</a></div>';
2942 }
2943 }
2944
2945 // If bank module is not used
2946 if (($user->hasRight('expensereport', 'to_paid') || empty(isModEnabled("bank"))) && $object->status == ExpenseReport::STATUS_APPROVED) {
2947 //if ((round($remaintopay) == 0 || !isModEnabled("bank")) && $object->paid == 0)
2948 if ($object->paid == 0) {
2949 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=set_paid&token='.newToken().'">'.$langs->trans("ClassifyPaid")."</a></div>";
2950 }
2951 }
2952
2953 if ($user->hasRight('expensereport', 'creer') && ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) && $object->status == ExpenseReport::STATUS_APPROVED) {
2954 // Cancel
2955 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Cancel").'</a></div>';
2956 }
2957
2958 // If status is Closed
2959 // ---------------------
2960
2961 // TODO Replace this. It should be SetUnpaid and should go back to status unpaid not canceled.
2962 if (($user->hasRight('expensereport', 'approve') || $user->hasRight('expensereport', 'to_paid')) && $object->status == ExpenseReport::STATUS_CLOSED) {
2963 // Cancel
2964 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=cancel&token='.newToken().'&id='.$object->id.'">'.$langs->trans("Cancel").'</a></div>';
2965 }
2966
2967 if ($user->hasRight('expensereport', 'to_paid') && $object->paid && $object->status == ExpenseReport::STATUS_CLOSED) {
2968 // Set unpaid
2969 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=set_unpaid&token='.newToken().'&id='.$object->id.'">'.$langs->trans('ClassifyUnPaid').'</a></div>';
2970 }
2971
2972 // Clone
2973 if ($user->hasRight('expensereport', 'creer')) {
2974 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans("ToClone"), $langs->trans("ToClone"), 'clone', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=clone&token='.newToken(), '', true, array('attr' => array('class' => 'reposition'))).'</div>';
2975 }
2976
2977 /* If draft, validated, cancel, and user can create, he can always delete its card before it is approved */
2978 if ($user->hasRight('expensereport', 'creer') && $user->id == $object->fk_user_author && $object->status < ExpenseReport::STATUS_APPROVED) {
2979 // Delete
2980 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans('Delete'), $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '', true, array('attr' => array('class' => 'reposition'))).'</div>'."\n";
2981 } elseif ($candelete && $object->status != ExpenseReport::STATUS_CLOSED) {
2982 // Delete
2983 print '<div class="inline-block divButAction">'.dolGetButtonAction($langs->trans('Delete'), $langs->trans('Delete'), 'delete', $_SERVER["PHP_SELF"].'?action=delete&token='.newToken().'&id='.$object->id, '', true, array('attr' => array('class' => 'reposition'))).'</div>'."\n";
2984 }
2985
2986 $parameters = array();
2987 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
2988}
2989
2990print '</div>';
2991
2992
2993// Select mail models is same action as presend
2994if (GETPOST('modelselected', 'alpha')) {
2995 $action = 'presend';
2996}
2997
2998if ($action != 'presend') {
2999 /*
3000 * Generate documents
3001 */
3002
3003 print '<div class="fichecenter"><div class="fichehalfleft">';
3004 print '<a name="builddoc"></a>'; // ancre
3005
3006 if ($user->hasRight('expensereport', 'creer') && $action != 'create' && $action != 'edit') {
3007 $filename = dol_sanitizeFileName($object->ref);
3008 $filedir = $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref);
3009 $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
3010 $genallowed = $user->hasRight('expensereport', 'creer');
3011 $delallowed = $user->hasRight('expensereport', 'creer');
3012 $var = true;
3013 print $formfile->showdocuments('expensereport', $filename, $filedir, $urlsource, $genallowed, $delallowed);
3014 $somethingshown = $formfile->numoffiles;
3015 }
3016
3017 // Disabled for expensereport, there is no thirdparty on expensereport, so nothing to define the list of other object we can suggest to link to
3018 /*
3019 if ($action != 'create' && $action != 'edit' && ($id || $ref))
3020 {
3021 $tmparray = $form->showLinkToObjectBlock($object, array(), array('expensereport'), 1);
3022 $linktoelem = $tmparray['linktoelem'];
3023 $htmltoenteralink = $tmparray['htmltoenteralink'];
3024 print $htmltoenteralink;
3025
3026 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
3027 }
3028 */
3029
3030 print '</div><div class="fichehalfright">';
3031 // List of actions on element
3032 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
3033 $formactions = new FormActions($db);
3034 $somethingshown = $formactions->showactions($object, 'expensereport', 0);
3035
3036 print '</div></div>';
3037}
3038
3039// Presend form
3040$modelmail = 'expensereport_send';
3041$defaulttopic = 'SendExpenseReportRef';
3042$diroutput = $conf->expensereport->dir_output;
3043$trackid = 'exp'.$object->id;
3044
3045include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
3046
3047
3048llxFooter();
3049
3050$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
global $dolibarr_main_url_root
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage bank accounts.
Class to manage accounting accounts.
Class to manage accounting journals.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage a WYSIWYG editor.
Class to manage ECM files.
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
const STATUS_APPROVED
Classified approved.
const STATUS_CANCELED
Classified canceled.
const STATUS_CLOSED
Classified paid.
const STATUS_REFUSED
Classified refused.
const STATUS_VALIDATED
Validated (need to be paid)
Class of expense report details lines.
Class to manage building of HTML components.
Class to manage generation of HTML components for contract module.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage building of HTML components.
Class to manage payments of expense report.
Class to manage projects.
Class to manage translations.
Class to manage Dolibarr users.
global $mysoc
expensereport_prepare_head($object)
Prepare array with list of tabs.
dol_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert a PDF file into another image format.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
Definition files.lib.php:66
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
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, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
getImageFileNameForSize($file, $extName, $extImgTarget='')
Return the filename of file to get the thumbs.
get_date_range($date_start, $date_end, $format='', $outputlangs=null, $withparenthesis=1)
Format output for start and end date.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
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).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isValidEmail($address, $acceptsupervisorkey=0, $acceptuserkey=0)
Return true if email syntax is ok.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
img_mime($file, $titlealt='', $morecss='')
Show MIME img of a file.
getAdvancedPreviewUrl($modulepart, $relativepath, $alldata=0, $param='')
Return URL we can use for advanced preview links.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
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 date
Definition receipt.php:492
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.