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