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', 'errors', '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 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
123 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
124 }
125} elseif ($action == 'set') {
126 // Activate a model
127 $ret = addDocumentModel($value, $type, $label, $scandir);
128 if ($ret > 0 && !getDolGlobalString('EXPENSEREPORT_ADDON_PDF')) {
129 dolibarr_set_const($db, 'EXPENSEREPORT_ADDON_PDF', $value, 'chaine', 0, '', $conf->entity);
130 }
131} elseif ($action == 'del') {
132 $ret = delDocumentModel($value, $type);
133 if ($ret > 0) {
134 if (getDolGlobalString('EXPENSEREPORT_ADDON_PDF') == "$value") {
135 dolibarr_del_const($db, 'EXPENSEREPORT_ADDON_PDF', $conf->entity);
136 }
137 }
138} elseif ($action == 'setdoc') {
139 // Set default model
140 if (dolibarr_set_const($db, "EXPENSEREPORT_ADDON_PDF", $value, 'chaine', 0, '', $conf->entity)) {
141 // The constant that was read before the new set
142 // so we go through a variable to get a consistent display
143 $conf->global->EXPENSEREPORT_ADDON_PDF = $value;
144 }
145
146 // On active le modele
147 $ret = delDocumentModel($value, $type);
148 if ($ret > 0) {
149 $ret = addDocumentModel($value, $type, $label, $scandir);
150 }
151} elseif ($action == 'setmod') {
152 // TODO Verifier si module numerotation choisi peut etre active
153 // par appel method canBeActivated
154
155 dolibarr_set_const($db, "EXPENSEREPORT_ADDON", $value, 'chaine', 0, '', $conf->entity);
156} elseif ($action == 'setoptions') {
157 $db->begin();
158
159 $freetext = GETPOST('EXPENSEREPORT_FREE_TEXT', 'restricthtml'); // No alpha here, we want exact string
160 $res1 = dolibarr_set_const($db, "EXPENSEREPORT_FREE_TEXT", $freetext, 'chaine', 0, '', $conf->entity);
161
162 $draft = GETPOST('EXPENSEREPORT_DRAFT_WATERMARK', 'alpha');
163 $res2 = dolibarr_set_const($db, "EXPENSEREPORT_DRAFT_WATERMARK", trim($draft), 'chaine', 0, '', $conf->entity);
164
165 $res3 = 0;
166 if (isModEnabled('project') && GETPOSTISSET('EXPENSEREPORT_PROJECT_IS_REQUIRED')) { // Option may not be provided
167 $res3 = dolibarr_set_const($db, 'EXPENSEREPORT_PROJECT_IS_REQUIRED', GETPOSTINT('EXPENSEREPORT_PROJECT_IS_REQUIRED'), 'chaine', 0, '', $conf->entity);
168 }
169
170 $dates = GETPOSTINT('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH');
171 $res4 = dolibarr_set_const($db, 'EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH', intval($dates), 'chaine', 0, '', $conf->entity);
172
173 $amounts = GETPOSTINT('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY');
174 $res5 = dolibarr_set_const($db, 'EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY', intval($amounts), 'chaine', 0, '', $conf->entity);
175
176 $linesblocked = GETPOSTINT('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES');
177 $res6 = dolibarr_set_const($db, 'EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES', intval($linesblocked), 'chaine', 0, '', $conf->entity);
178
179 if (!($res1 > 0) || !($res2 > 0) || !($res3 >= 0) || !($res4 > 0) || !($res5 > 0) || !($res6 > 0)) {
180 $error++;
181 }
182
183 if (!$error) {
184 $db->commit();
185 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
186 } else {
187 $db->rollback();
188 setEventMessages($langs->trans("Error"), null, 'errors');
189 }
190}
191
192
193/*
194 * View
195 */
196
197$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
198
199llxHeader('', $langs->trans("ExpenseReportsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expensereport');
200
201$form = new Form($db);
202
203$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>';
204
205print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
206
207
209
210print dol_get_fiche_head($head, 'expensereport', $langs->trans("ExpenseReports"), -1, 'trip');
211
212/*
213 * Expense report numbering model
214 */
215
216print load_fiche_titre($langs->trans("ExpenseReportNumberingModules"), '', '');
217
218print '<div class="div-table-responsive-no-min">';
219print '<table class="noborder centpercent">';
220print '<tr class="liste_titre">';
221print '<td>'.$langs->trans("Name").'</td>';
222print '<td>'.$langs->trans("Description").'</td>';
223print '<td class="nowrap">'.$langs->trans("Example").'</td>';
224print '<td class="center" width="60">'.$langs->trans("Status").'</td>';
225print '<td class="center" width="16">'.$langs->trans("ShortInfo").'</td>';
226print '</tr>'."\n";
227
228clearstatcache();
229
230foreach ($dirmodels as $reldir) {
231 $dir = dol_buildpath($reldir."core/modules/expensereport/");
232
233 if (is_dir($dir)) {
234 $handle = opendir($dir);
235 if (is_resource($handle)) {
236 while (($file = readdir($handle)) !== false) {
237 if (dol_substr($file, 0, 18) == 'mod_expensereport_' && dol_substr($file, dol_strlen($file) - 3, 3) == 'php') {
238 $file = dol_substr($file, 0, dol_strlen($file) - 4);
239
240 require_once $dir.$file.'.php';
241
242 $module = new $file($db);
243
244 '@phan-var-force ModeleNumRefExpenseReport $module';
245
246 // Show modules according to features level
247 if ($module->version == 'development' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 2) {
248 continue;
249 }
250 if ($module->version == 'experimental' && getDolGlobalInt('MAIN_FEATURES_LEVEL') < 1) {
251 continue;
252 }
253
254 if ($module->isEnabled()) {
255 print '<tr class="oddeven"><td>'.$module->getName($langs)."</td><td>\n";
256 print $module->info($langs);
257 print '</td>';
258
259 // Show example of numbering model
260 print '<td class="nowrap">';
261 $tmp = $module->getExample();
262 if (preg_match('/^Error/', $tmp)) {
263 $langs->load("errors");
264 print '<div class="error">'.$langs->trans($tmp).'</div>';
265 } elseif ($tmp == 'NotConfigured') {
266 print '<span class="opacitymedium">'.$langs->trans($tmp).'</span>';
267 } else {
268 print $tmp;
269 }
270 print '</td>'."\n";
271
272 print '<td class="center">';
273 if (getDolGlobalString('EXPENSEREPORT_ADDON') == $file) {
274 print img_picto($langs->trans("Activated"), 'switch_on');
275 } else {
276 print '<a class="reposition" href="'.$_SERVER["PHP_SELF"].'?action=setmod&token='.newToken().'&value='.urlencode($file).'">';
277 print img_picto($langs->trans("Disabled"), 'switch_off');
278 print '</a>';
279 }
280 print '</td>';
281
282 $exp = new ExpenseReport($db);
283 $exp->initAsSpecimen();
284
285 // Info
286 $htmltooltip = '';
287 $htmltooltip .= ''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
288 $nextval = $module->getNextValue($exp);
289 if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
290 $htmltooltip .= ''.$langs->trans("NextValue").': ';
291 if ($nextval) {
292 if (preg_match('/^Error/', $nextval) || $nextval == 'NotConfigured') {
293 $nextval = $langs->trans($nextval);
294 }
295 $htmltooltip .= $nextval.'<br>';
296 } else {
297 $htmltooltip .= $langs->trans($module->error).'<br>';
298 }
299 }
300
301 print '<td class="center">';
302 print $form->textwithpicto('', $htmltooltip, 1, 'info');
303 print '</td>';
304
305 print "</tr>\n";
306 }
307 }
308 }
309 closedir($handle);
310 }
311 }
312}
313print "</table></div><br>\n";
314
315/*
316 * Documents models for ExpenseReport
317 */
318
319printDocumentModelList('expensereport', 'expensereport', 'EXPENSEREPORT_ADDON_PDF', $langs->trans("TemplatePDFExpenseReports"), array(
320 'Logo' => 'option_logo',
321 'PaymentMode' => 'option_modereg',
322 'PaymentConditions' => 'option_condreg',
323 'MultiLanguage' => 'option_multilang',
324 'WatermarkOnDraftOrders' => 'option_draft_watermark',
325));
326
327print '<br>';
328
329
330
331/*
332 * Other options
333 */
334
335print '<form action="'.$_SERVER["PHP_SELF"].'" method="post" spellcheck="false">';
336print '<input type="hidden" name="token" value="'.newToken().'">';
337print '<input type="hidden" name="action" value="setoptions">';
338
339print load_fiche_titre($langs->trans("OtherOptions"), '', '');
340
341print '<div class="div-table-responsive-no-min">';
342print '<table class="noborder centpercent">';
343print '<tr class="liste_titre">';
344print '<td>'.$langs->trans("Parameter").'</td>';
345print '<td class="center" width="60"></td>';
346print "</tr>\n";
347
348$substitutionarray = pdf_getSubstitutionArray($langs, null, null, 2);
349$substitutionarray['__(AnyTranslationKey)__'] = $langs->trans("Translation");
350$htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
351foreach ($substitutionarray as $key => $val) {
352 $htmltext .= $key.'<br>';
353}
354$htmltext .= '</i>';
355
356print '<tr class="oddeven"><td colspan="2">';
357print $form->textwithpicto($langs->trans("FreeLegalTextOnExpenseReports"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
358$variablename = 'EXPENSEREPORT_FREE_TEXT';
359if (!getDolGlobalString('PDF_ALLOW_HTML_FOR_FREE_TEXT')) {
360 print '<textarea name="'.$variablename.'" class="flat" cols="120">'.getDolGlobalString($variablename).'</textarea>';
361} else {
362 include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
363 $doleditor = new DolEditor($variablename, getDolGlobalString($variablename), '', 80, 'dolibarr_notes');
364 print $doleditor->Create();
365}
366print '</td></tr>'."\n";
367
368// Use draft Watermark
369
370print '<tr class="oddeven"><td colspan="2">';
371print $form->textwithpicto($langs->trans("WatermarkOnDraftExpenseReports"), $htmltext, 1, 'help', '', 0, 2, 'watermarktooltip').'<br>';
372print '<input class="flat minwidth200" type="text" name="EXPENSEREPORT_DRAFT_WATERMARK" value="'.dol_escape_htmltag(getDolGlobalString('EXPENSEREPORT_DRAFT_WATERMARK')).'">';
373print '</td></tr>'."\n";
374
375if (isModEnabled('project')) {
376 print '<tr class="oddeven"><td>';
377 print $langs->trans('ProjectIsRequiredOnExpenseReports');
378 print '</td><td class="right">';
379 print $form->selectyesno('EXPENSEREPORT_PROJECT_IS_REQUIRED', getDolGlobalString('EXPENSEREPORT_PROJECT_IS_REQUIRED') ? 1 : 0, 1);
380 print '</td></tr>';
381}
382
383print '<tr class="oddeven"><td>';
384print $langs->trans('PrefillExpenseReportDatesWithCurrentMonth');
385print '</td><td class="right">';
386print $form->selectyesno('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH', getDolGlobalString('EXPENSEREPORT_PREFILL_DATES_WITH_CURRENT_MONTH') ? 1 : 0, 1);
387print '</td></tr>';
388
389print '<tr class="oddeven"><td>';
390print $langs->trans('ForceExpenseReportsLineAmountsIncludingTaxesOnly');
391print '</td><td class="right">';
392print $form->selectyesno('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY', getDolGlobalString('EXPENSEREPORT_FORCE_LINE_AMOUNTS_INCLUDING_TAXES_ONLY') ? 1 : 0, 1);
393print '</td></tr>';
394
395print '<tr class="oddeven"><td>';
396print $langs->trans('BlockExpenseReportLineCreationIfNotBetweenDates');
397print '</td><td class="right">';
398print $form->selectyesno('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES', getDolGlobalString('EXPENSEREPORT_BLOCK_LINE_CREATION_IF_NOT_BETWEEN_DATES') ? 1 : 0, 1);
399print '</td></tr>';
400
401print '</table>';
402print '</div>';
403
404print $form->buttonsSaveCancel("Save", '');
405
406print '</form>';
407
408print dol_get_fiche_end();
409
410// End of page
411llxFooter();
412$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
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
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
expensereport_admin_prepare_head()
Return array head with list of tabs to view object information.
dol_strlen($string, $stringencoding='UTF-8')
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:540
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:738
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.