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