30require
'../main.inc.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
33require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
34require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
45$langs->loadLangs(array(
"admin",
"other",
"trips",
"errors",
"dict"));
48$hookmanager->initHooks(array(
'admin',
'dictionaryadmin',
'expensereport_rules'));
64$tab_rules_type = array();
65$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
67 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
74 $action =
GETPOST(
'action',
'aZ09');
77 $apply_to =
GETPOST(
'apply_to');
81 $fk_c_type_fees =
GETPOSTINT(
'fk_c_type_fees');
82 $code_expense_rules_type =
GETPOST(
'code_expense_rules_type');
94 if ($action ==
'save') {
98 if (empty($apply_to)) {
100 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportApplyTo")),
null,
'errors');
102 if (empty($fk_c_type_fees)) {
104 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDomain")),
null,
'errors');
106 if (empty($code_expense_rules_type)) {
108 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportLimitOn")),
null,
'errors');
112 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDateStart")),
null,
'errors');
116 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDateEnd")),
null,
'errors');
118 if (empty($amount)) {
120 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportLimitAmount")),
null,
'errors');
124 if ($apply_to ==
'U') {
125 $object->fk_user = (int) $fk_user;
128 } elseif ($apply_to ==
'G') {
129 $object->fk_usergroup = (int) $fk_usergroup;
132 } elseif ($apply_to ==
'A') {
140 $object->restrictive = $restrictive;
141 $object->fk_c_type_fees = $fk_c_type_fees;
142 $object->code_expense_rules_type = $code_expense_rules_type;
152 setEventMessages($langs->trans(
'ExpenseReportRuleSave'),
null);
159 header(
'Location: '.DOL_URL_ROOT.
'/admin/expensereport_rules.php');
165 } elseif ($action ==
'delete') {
174 header(
'Location: ' . DOL_URL_ROOT.
'/admin/expensereport_rules.php');
178 $rules =
$object->getAllRule();
181 'A' => $langs->trans(
'All'),
182 'G' => $langs->trans(
'UserGroup'),
183 'U' => $langs->trans(
'User')
185 $tab_rules_type = array(
186 'EX_DAY' => $langs->trans(
'Day'),
187 'EX_MON' => $langs->trans(
'Month'),
188 'EX_YEA' => $langs->trans(
'Year'),
189 'EX_EXP' => $langs->trans(
'OnExpense')
198llxHeader(
'', $langs->trans(
"ExpenseReportsSetup"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-expensereport_rules');
200$form =
new Form($db);
202$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>';
204print
load_fiche_titre($langs->trans(
"ExpenseReportsSetup"), $linkback,
'title_setup');
207print
dol_get_fiche_head($head,
'expenserules', $langs->trans(
"ExpenseReportsRules"), -1,
'trip');
209echo
'<span class="opacitymedium">' . $langs->trans(
'ExpenseReportRulesDesc') .
'</span>';
212if ($action !=
'edit') {
213 echo
'<form action="' . $_SERVER[
'PHP_SELF'] .
'" method="post" spellcheck="false">';
214 echo
'<input type="hidden" name="token" value="' .
newToken() .
'" />';
215 echo
'<input type="hidden" name="action" value="save" />';
217 echo
'<table class="noborder centpercent">';
219 echo
'<tr class="liste_titre headerexpensereportrules">';
220 echo
'<th class="linecolapplyto">' . $langs->trans(
'ExpenseReportApplyTo') .
'</th>';
221 echo
'<th class="linecoltype">' . $langs->trans(
'Type') .
'</th>';
222 echo
'<th class="linecollimiton">' . $langs->trans(
'ExpenseReportLimitOn') .
'</th>';
223 echo
'<th class="linecoldatestart">' . $langs->trans(
'ExpenseReportDateStart') .
'</th>';
224 echo
'<th class="linecoldateend">' . $langs->trans(
'ExpenseReportDateEnd') .
'</th>';
225 echo
'<th class="linecollimitamount">' . $langs->trans(
'ExpenseReportLimitAmount') .
'</th>';
226 echo
'<th class="linecolrestrictive">' . $langs->trans(
'ExpenseReportRestrictive') .
'</th>';
227 echo
'<th> </th>';
230 echo
'<tr class="oddeven">';
232 echo
'<div class="float linecolapplyto">' . $form->selectarray(
'apply_to', $tab_apply,
'', 0) .
'</div>';
233 echo
'<div id="user" class="float linecoluser">' . $form->select_dolusers(
'',
'fk_user') .
'</div>';
234 echo
'<div id="group" class="float linecolgroup">' . $form->select_dolgroups(0,
'fk_usergroup') .
'</div>';
237 echo
'<td class="linecoltype">' . $form->selectExpenseFees(
'',
'fk_c_type_fees', 0, 1, 1) .
'</td>';
238 echo
'<td class="linecoltyperule">' . $form->selectarray(
'code_expense_rules_type', $tab_rules_type,
'', 0) .
'</td>';
239 echo
'<td class="linecoldatestart">' . $form->selectDate(strtotime(
date(
'Y-m-01',
dol_now())),
'start', 0, 0, 0,
'', 1, 0) .
'</td>';
240 echo
'<td class="linecoldateend">' . $form->selectDate(strtotime(
date(
'Y-m-t',
dol_now())),
'end', 0, 0, 0,
'', 1, 0) .
'</td>';
241 echo
'<td class="linecolamount"><input type="text" value="" class="maxwidth100" name="amount" class="amount right" /></td>';
242 echo
'<td class="linecolrestrictive">' . $form->selectyesno(
'restrictive', 0, 1) .
'</td>';
243 echo
'<td class="right linecolbutton"><input type="submit" class="button button-add" value="' . $langs->trans(
'Add') .
'" /></td>';
251echo
'<form action="' . $_SERVER[
'PHP_SELF'] .
'" method="post" spellcheck="false">';
252echo
'<input type="hidden" name="token" value="' .
newToken() .
'" />';
254if ($action ==
'edit') {
255 echo
'<input type="hidden" name="id" value="' .
$object->id .
'" />';
256 echo
'<input type="hidden" name="action" value="save" />';
262echo
'<table class="noborder centpercent">';
264echo
'<tr class="liste_titre expensereportrules">';
265echo
'<th class="linecolapplyto">' . $langs->trans(
'ExpenseReportApplyTo') .
'</th>';
266echo
'<th class="linecoltype">' . $langs->trans(
'Type') .
'</th>';
267echo
'<th class="linecollimiton">' . $langs->trans(
'ExpenseReportLimitOn') .
'</th>';
268echo
'<th class="linecoldatestart">' . $langs->trans(
'ExpenseReportDateStart') .
'</th>';
269echo
'<th class="linecoldateend">' . $langs->trans(
'ExpenseReportDateEnd') .
'</th>';
270echo
'<th class="linecollimitamount">' . $langs->trans(
'ExpenseReportLimitAmount') .
'</th>';
271echo
'<th class="linecolrestrictive">' . $langs->trans(
'ExpenseReportRestrictive') .
'</th>';
272echo
'<th> </th>';
275foreach ($rules as $rule) {
276 echo
'<tr class="oddeven linetrdata" id="'.$rule->id.
'">';
278 echo
'<td class="linecolusergroup">';
279 if ($action ==
'edit' &&
$object->id == $rule->id) {
280 $selected = (
$object->is_for_all > 0) ?
'A' : (
$object->fk_usergroup > 0 ?
'G' :
'U');
281 echo
'<div class="float">' . $form->selectarray(
'apply_to', $tab_apply, $selected, 0) .
'</div>';
282 echo
'<div id="user" class="float">' . $form->select_dolusers(
$object->fk_user,
'fk_user') .
'</div>';
283 echo
'<div id="group" class="float">' . $form->select_dolgroups(
$object->fk_usergroup,
'fk_usergroup') .
'</div>';
285 if ($rule->is_for_all > 0) {
286 echo $tab_apply[
'A'];
287 } elseif ($rule->fk_usergroup > 0) {
288 echo $tab_apply[
'G'] .
' (' . $rule->getGroupLabel() .
')';
289 } elseif ($rule->fk_user > 0) {
290 echo $tab_apply[
'U'] .
' (' . $rule->getUserName() .
')';
295 echo
'<td class="linecoltype">';
296 if ($action ==
'edit' &&
$object->id == $rule->id) {
297 echo $form->selectExpenseFees((
string)
$object->fk_c_type_fees,
'fk_c_type_fees', 0, 1, 1);
299 if ($rule->fk_c_type_fees == -1) {
300 echo $langs->trans(
'AllExpenseReport');
303 if ($key && $key != $langs->trans($key)) {
304 echo $langs->trans($key);
306 $value =
getDictionaryValue(
'c_type_fees',
'label', $rule->fk_c_type_fees,
false,
'id');
307 echo $langs->trans($value ? $value :
'Undefined');
314 echo
'<td class="linecoltyperule">';
315 if ($action ==
'edit' &&
$object->id == $rule->id) {
316 echo $form->selectarray(
'code_expense_rules_type', $tab_rules_type,
$object->code_expense_rules_type, 0);
318 echo $tab_rules_type[$rule->code_expense_rules_type];
323 echo
'<td class="linecoldatestart">';
324 if ($action ==
'edit' &&
$object->id == $rule->id) {
325 print $form->selectDate(strtotime(
date(
'Y-m-d',
$object->dates)),
'start', 0, 0, 0,
'', 1, 0);
332 echo
'<td class="linecoldateend">';
333 if ($action ==
'edit' &&
$object->id == $rule->id) {
334 print $form->selectDate(strtotime(
date(
'Y-m-d',
$object->datee)),
'end', 0, 0, 0,
'', 1, 0);
341 echo
'<td class="linecolamount">';
342 if ($action ==
'edit' &&
$object->id == $rule->id) {
343 echo
'<input type="text" value="' .
price2num(
$object->amount) .
'" name="amount" class="amount width50 right" />';
350 echo
'<td class="linecolrestrictive">';
351 if ($action ==
'edit' &&
$object->id == $rule->id) {
352 echo $form->selectyesno(
'restrictive',
$object->restrictive, 1);
354 echo yn($rule->restrictive, 1, 1);
359 echo
'<td class="center">';
360 if (
$object->id != $rule->id) {
361 echo
'<a class="editfielda paddingright paddingleft" href="' . $_SERVER[
'PHP_SELF'] .
'?action=edit&token=' .
newToken() .
'&id=' . $rule->id .
'">' . img_edit() .
'</a> ';
362 echo
'<a class="paddingright paddingleft" href="' . $_SERVER[
'PHP_SELF'] .
'?action=delete&token=' .
newToken() .
'&id=' . $rule->id .
'">' . img_delete() .
'</a>';
364 echo
'<input type="submit" class="button button-edit" value="' . $langs->trans(
'Update') .
'" /> ';
365 echo
'<a href="' . $_SERVER[
'PHP_SELF'] .
'" class="button button-cancel">' . $langs->trans(
"Cancel") .
'</a>';
372if (!is_array($rules) || count($rules) == 0) {
373 print
'<tr class="none"><td colspan="8"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
379echo
'<script type="text/javascript"> $(function() {
380 $("#apply_to").change(function() {
381 var value = $(this).val();
383 $("#group").hide(); $("#user").hide();
384 } else if (value == "U") {
387 } else if (value == "G") {
393 $("#apply_to").change();
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
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.
Class to manage inventories.
expensereport_admin_prepare_head()
Return array head with list of tabs to view object information.
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...
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
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.
getDolCurrency()
Return the main currency ('EUR', 'USD', ...)
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).
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
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.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
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
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.