dolibarr 25.0.0-alpha
expensereport.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
5 * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
6 * Copyright (C) 2005-2014 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
8 * Copyright (C) 2011-2013 Juanjo Menent <jmenent@2byte.es>
9 * Copyright (C) 2011-2022 Philippe Grand <philippe.grand@atoo-net.com>
10 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
11 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 3 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <https://www.gnu.org/licenses/>.
25 */
26
33// Load Dolibarr environment
34require '../main.inc.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
44require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
45require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
46
47// Load translation files required by the page
48$langs->loadLangs(array('admin', 'trips', 'other'));
49
50if (!$user->admin) {
52}
53
54$action = GETPOST('action', 'aZ09');
55$value = GETPOST('value', 'alpha');
56$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
57
58$label = GETPOST('label', 'alpha');
59$scandir = GETPOST('scan_dir', 'alpha');
60$type = 'expensereport';
61
62
63/*
64 * Actions
65 */
66$error = 0;
67
68include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
69
70if ($action == 'updateMask') {
71 $maskconst = GETPOST('maskconst', 'aZ09');
72 $maskvalue = GETPOST('maskvalue', 'alpha');
73
74 $res = 0;
75
76 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
77 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
78 }
79
80 if (!($res > 0)) {
81 $error++;
82 }
83
84 if (!$error) {
85 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
86 } else {
87 setEventMessages($langs->trans("Error"), null, 'errors');
88 }
89} elseif ($action == 'specimen') { // For fiche expensereport
90 $modele = GETPOST('module', 'alpha');
91
92 $expensespecimen = new ExpenseReport($db);
93 $expensespecimen->initAsSpecimen();
94 $expensespecimen->status = 0; // Force statut draft to show watermark
95
96 // Search template files
97 $file = '';
98 $classname = '';
99 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
100 foreach ($dirmodels as $reldir) {
101 $file = dol_buildpath($reldir."core/modules/expensereport/doc/pdf_".$modele.".modules.php", 0);
102 if (file_exists($file)) {
103 $classname = "pdf_".$modele;
104 break;
105 }
106 }
107
108 if ($classname !== '') {
109 require_once $file;
110
111 $module = new $classname($db);
112 '@phan-var-force ModeleExpenseReport $module';
113
114 if ($module->write_file($expensespecimen, $langs) > 0) {
115 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=expensereport&file=SPECIMEN.pdf");
116 return;
117 } else {
118 setEventMessages($module->error, $module->errors, 'errors');
119 dol_syslog($module->error, LOG_ERR);
120 }
121 } else {
122 $langs->load('errors');
123 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
124 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
125 }
126} elseif ($action == 'set') {
127 // Activate a model
128 $ret = addDocumentModel($value, $type, $label, $scandir);
129 if ($ret > 0 && !getDolGlobalString('EXPENSEREPORT_ADDON_PDF')) {
130 dolibarr_set_const($db, 'EXPENSEREPORT_ADDON_PDF', $value, 'chaine', 0, '', $conf->entity);
131 }
132} elseif ($action == 'del') {
133 $ret = delDocumentModel($value, $type);
134 if ($ret > 0) {
135 if (getDolGlobalString('EXPENSEREPORT_ADDON_PDF') == "$value") {
136 dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF', $conf->entity);
137 }
138 }
139} elseif ($action == 'setdoc') {
140 // Set default model
141 if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
142 // The constant that was read before the new set
143 // so we go through a variable to get a consistent display
144 $conf->global->EXPENSEREPORT_ADDON_PDF = $value;
145 }
146
147 // On active le modele
148 $ret = delDocumentModel($value, $type);
149 if ($ret > 0) {
150 $ret = addDocumentModel($value, $type, $label, $scandir);
151 }
152} elseif ($action == 'setmod') {
153 // TODO Verifier si module numerotation choisi peut etre active
154 // par appel method canBeActivated
155
156 dolibarr_set_const($db, "EXPENSEREPORT_ADDON", $value, 'chaine', 0, '', $conf->entity);
157} elseif ($action == 'setoptions') {
158 $db->begin();
159
160 $freetext = GETPOST('EXPENSEREPORT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
161 $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
162
163 $draft = GETPOST('EXPENSEREPORT_DRAFT_WATERMARK', 'alpha');
164 $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
165
166 $res3 = 0;
167 if (isModEnabled('project') && GETPOSTISSET('EXPENSEREPORT_PROJECT_IS_REQUIRED')) { // Option may not be provided
168 $res3 = dolibarr_set_const($db, 'EXPENSEREPORT_PROJECT_IS_REQUIRED', GETPOSTINT('EXPENSEREPORT_PROJECT_IS_REQUIRED'), 'chaine', 0, '', $conf->entity);
169 }
170
171 $dates = GETPOSTINT('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH');
172 $res4 = dolibarr_set_const($db, 'EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH', intval($dates), 'chaine', 0, '', $conf->entity);
173
174 $amounts = GETPOSTINT('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY');
175 $res5 = dolibarr_set_const($db, 'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY', intval($amounts), 'chaine', 0, '', $conf->entity);
176
177 $linesblocked = GETPOSTINT('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES');
178 $res6 = dolibarr_set_const($db, 'EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES', intval($linesblocked), 'chaine', 0, '', $conf->entity);
179
180 if (!($res1 > 0) || !($res2 > 0) || !($res3 >= 0) || !($res4 > 0) || !($res5 > 0) || !($res6 > 0)) {
181 $error++;
182 }
183
184 if (!$error) {
185 $db->commit();
186 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
187 } else {
188 $db->rollback();
189 setEventMessages($langs->trans("Error"), null, 'errors');
190 }
191}
192
193
194/*
195 * View
196 */
197
198$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
199
200llxHeader('', $langs->trans("ExpenseReportsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expensereport');
201
202$form = new Form($db);
203
204$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
205
206print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
207
208
210
211print dol_get_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), -1, 'trip');
212
213/*
214 * Expense report numbering model
215 */
216
217print load_fiche_titre($langs->trans("ExpenseReportNumberingModules"), '', '');
218
219print '<div class="div-table-responsive-no-min">';
220print '<table class="noborder centpercent">';
221print '<tr class="liste_titre">';
222print '<td>'.$langs->trans("Name").'</td>';
223print '<td>'.$langs->trans("Description").'</td>';
224print '<td class="nowrap">'.$langs->trans("Example").'</td>';
225print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
226print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
227print '</tr>'."\n";
228
229clearstatcache();
230
231foreach ($dirmodels as $reldir) {
232 $dir = dol_buildpath($reldir."core/modules/expensereport/");
233
234 if (is_dir($dir)) {
235 $handle = opendir($dir);
236 if (is_resource($handle)) {
237 while (($file = readdir($handle)) !== false) {
238 if (dol_substr($file, 0, 18) == 'mod_expensereport_' && dol_substr($file, dol_strlen($file) - 3, 3) == 'php') {
239 $file = dol_substr($file, 0, dol_strlen($file) - 4);
240
241 require_once $dir.$file.'.php';
242
243 $module = new $file($db);
244
245 '@phan-var-force ModeleNumRefExpenseReport $module';
246
247 // Show modules according to features level
248 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
249 continue;
250 }
251 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
252 continue;
253 }
254
255 if ($module->isEnabled()) {
256 print '<tr class="oddeven"><td>'.$module->getName($langs)."</td><td>\n";
257 print $module->info($langs);
258 print '</td>';
259
260 // Show example of numbering model
261 print '<td class="nowrap">';
262 $tmp = $module->getExample();
263 if (preg_match('/^Error/', $tmp)) {
264 $langs->load("errors");
265 print '<div class="error">'.$langs->trans($tmp).'</div>';
266 } elseif ($tmp == 'NotConfigured') {
267 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
268 } else {
269 print $tmp;
270 }
271 print '</td>'."\n";
272
273 print '<td class="center">';
274 if (getDolGlobalString('EXPENSEREPORT_ADDON') == $file) {
275 print img_picto($langs->trans("Activated"), 'switch_on');
276 } else {
277 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'">';
278 print img_picto($langs->trans("Disabled"), 'switch_off');
279 print '</a>';
280 }
281 print '</td>';
282
283 $exp = new ExpenseReport($db);
284 $exp->initAsSpecimen();
285
286 // Info
287 $htmltooltip = '';
288 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
289 $nextval = $module->getNextValue($exp);
290 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
291 $htmltooltip .= ''.$langs->trans("NextValue").': ';
292 if ($nextval) {
293 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
294 $langs->load('errors');
295 $nextval = $langs->trans($nextval);
296 }
297 $htmltooltip .= $nextval.'<br>';
298 } else {
299 $langs->load('errors');
300 $htmltooltip .= $langs->trans($module->error).'<br>';
301 }
302 }
303
304 print '<td class="center">';
305 print $form->textwithpicto('', $htmltooltip, 1, 'info');
306 print '</td>';
307
308 print "</tr>\n";
309 }
310 }
311 }
312 closedir($handle);
313 }
314 }
315}
316print "</table></div><br>\n";
317
318/*
319 * Documents models for ExpenseReport
320 */
321
322printDocumentModelList('expensereport', 'expensereport', 'EXPENSEREPORT_ADDON_PDF', $langs->trans("TemplatePDFExpenseReports"), array(
323 'Logo' => 'option_logo',
324 'PaymentMode' => 'option_modereg',
325 'PaymentConditions' => 'option_condreg',
326 'MultiLanguage' => 'option_multilang',
327 'WatermarkOnDraftOrders' => 'option_draft_watermark',
328));
329
330print '<br>';
331
332
333
334/*
335 * Other options
336 */
337
338print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
339print '<input type="hidden" name="token" value="'.newToken().'">';
340print '<input type="hidden" name="action" value="setoptions">';
341
342print load_fiche_titre($langs->trans("OtherOptions"), '', '');
343
344print '<div class="div-table-responsive-no-min">';
345print '<table class="noborder centpercent">';
346print '<tr class="liste_titre">';
347print '<td>'.$langs->trans("Parameter").'</td>';
348print '<td class="center" width="60"></td>';
349print "</tr>\n";
350
351$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
352$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
353$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
354foreach ($substitutionarray as $key => $val) {
355 $htmltext .= $key.'<br>';
356}
357$htmltext .= '</i>';
358
359print '<tr class="oddeven"><td colspan="2">';
360print $form->textwithpicto($langs->trans("FreeLegalTextOnExpenseReports"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
361$variablename = 'EXPENSEREPORT_FREE_TEXT';
362if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
363 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
364} else {
365 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
366 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
367 print $doleditor->Create();
368}
369print '</td></tr>'."\n";
370
371// Use draft Watermark
372
373print '<tr class="oddeven"><td colspan="2">';
374print $form->textwithpicto($langs->trans("WatermarkOnDraftExpenseReports"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
375print '<input class="flat minwidth200" type="text" name="EXPENSEREPORT_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('EXPENSEREPORT_DRAFT_WATERMARK')).'">';
376print '</td></tr>'."\n";
377
378if (isModEnabled('project')) {
379 print '<tr class="oddeven"><td>';
380 print $langs->trans('ProjectIsRequiredOnExpenseReports');
381 print '</td><td class="right">';
382 print $form->selectyesno('EXPENSEREPORT_PROJECT_IS_REQUIRED', getDolGlobalString('EXPENSEREPORT_PROJECT_IS_REQUIRED') ? 1 : 0, 1);
383 print '</td></tr>';
384}
385
386print '<tr class="oddeven"><td>';
387print $langs->trans('PrefillExpenseReportDatesWithCurrentMonth');
388print '</td><td class="right">';
389print $form->selectyesno('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH', getDolGlobalString('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH') ? 1 : 0, 1);
390print '</td></tr>';
391
392print '<tr class="oddeven"><td>';
393print $langs->trans('ForceExpenseReportsLineAmountsIncludingTaxesOnly');
394print '</td><td class="right">';
395print $form->selectyesno('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY', getDolGlobalString('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ? 1 : 0, 1);
396print '</td></tr>';
397
398print '<tr class="oddeven"><td>';
399print $langs->trans('BlockExpenseReportLineCreationIfNotBetweenDates');
400print '</td><td class="right">';
401print $form->selectyesno('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES', getDolGlobalString('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES') ? 1 : 0, 1);
402print '</td></tr>';
403
404print '</table>';
405print '</div>';
406
407print $form->buttonsSaveCancel("Save", '');
408
409print '</form>';
410
411print dol_get_fiche_end();
412
413// End of page
414llxFooter();
415$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage a WYSIWYG editor.
Class to manage Trips and Expenses.
Class to manage generation of HTML components Only common components must be here.
if(! $sortfield) if(! $sortorder) $module
Definition list.php:193
expensereport_admin_prepare_head()
Return array head with list of tabs to view object information.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
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.
dol_substr($string, $start, $length=null, $stringencoding='', $trunconbytes=0)
Make a substring.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null, $onlykey=0, $include=null)
Return array of possible substitutions for PDF content (without external module substitutions).
Definition pdf.lib.php:1180
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.