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