28 require
'../main.inc.php';
29 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
30 require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
31 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
32 require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
35 $langs->loadLangs(array(
"admin",
"other",
"trips",
"errors",
"dict"));
43 $action =
GETPOST(
'action',
'aZ09');
46 $apply_to =
GETPOST(
'apply_to');
47 $fk_user =
GETPOST(
'fk_user',
'int');
48 $fk_usergroup =
GETPOST(
'fk_usergroup',
'int');
50 $fk_c_type_fees =
GETPOST(
'fk_c_type_fees');
51 $code_expense_rules_type =
GETPOST(
'code_expense_rules_type');
55 $restrictive =
GETPOST(
'restrictive');
60 $result = $object->fetch($id);
65 if ($action ==
'save')
70 if (empty($apply_to)) {
72 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportApplyTo")), null,
'errors');
74 if (empty($fk_c_type_fees)) {
76 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDomain")), null,
'errors');
78 if (empty($code_expense_rules_type)) {
80 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportLimitOn")), null,
'errors');
84 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDateStart")), null,
'errors');
88 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDateEnd")), null,
'errors');
92 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportLimitAmount")), null,
'errors');
97 $object->setValues($_POST);
99 if ($apply_to ==
'U') {
100 $object->fk_user = (int) $fk_user;
101 $object->fk_usergroup = 0;
102 $object->is_for_all = 0;
103 } elseif ($apply_to ==
'G') {
104 $object->fk_usergroup = (int) $fk_usergroup;
105 $object->fk_user = 0;
106 $object->is_for_all = 0;
107 } elseif ($apply_to ==
'A') {
108 $object->is_for_all = 1;
109 $object->fk_user = 0;
110 $object->fk_usergroup = 0;
113 $object->dates = $dates;
114 $object->datee = $datee;
116 $object->entity = $conf->entity;
118 $res = $object->create($user);
119 if ($res > 0)
setEventMessages($langs->trans(
'ExpenseReportRuleSave'), null);
122 header(
'Location: '.
$_SERVER[
'PHP_SELF']);
125 } elseif ($action ==
'delete')
128 $res = $object->delete($user);
132 header(
'Location: '.
$_SERVER[
'PHP_SELF']);
138 $tab_apply = array(
'A' => $langs->trans(
'All'),
'G' => $langs->trans(
'Group'),
'U' => $langs->trans(
'User'));
139 $tab_rules_type = array(
'EX_DAY' => $langs->trans(
'Day'),
'EX_MON' => $langs->trans(
'Month'),
'EX_YEA' => $langs->trans(
'Year'),
'EX_EXP' => $langs->trans(
'OnExpense'));
146 llxHeader(
'', $langs->trans(
"ExpenseReportsSetup"));
148 $form =
new Form($db);
150 $linkback =
'<a href="'.DOL_URL_ROOT.
'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToModuleList").
'</a>';
156 echo
'<span class="opacitymedium">'.$langs->trans(
'ExpenseReportRulesDesc').
'</span>';
159 if ($action !=
'edit')
161 echo
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
162 echo
'<input type="hidden" name="token" value="'.newToken().
'" />';
163 echo
'<input type="hidden" name="action" value="save" />';
165 echo
'<table class="noborder centpercent">';
167 echo
'<tr class="liste_titre">';
168 echo
'<th>'.$langs->trans(
'ExpenseReportApplyTo').
'</th>';
169 echo
'<th>'.$langs->trans(
'Type').
'</th>';
170 echo
'<th>'.$langs->trans(
'ExpenseReportLimitOn').
'</th>';
171 echo
'<th>'.$langs->trans(
'ExpenseReportDateStart').
'</th>';
172 echo
'<th>'.$langs->trans(
'ExpenseReportDateEnd').
'</th>';
173 echo
'<th>'.$langs->trans(
'ExpenseReportLimitAmount').
'</th>';
174 echo
'<th>'.$langs->trans(
'ExpenseReportRestrictive').
'</th>';
175 echo
'<th> </th>';
178 echo
'<tr class="oddeven">';
180 echo
'<div class="float">'.$form->selectarray(
'apply_to', $tab_apply,
'', 0).
'</div>';
181 echo
'<div id="user" class="float">'.$form->select_dolusers(
'',
'fk_user').
'</div>';
182 echo
'<div id="group" class="float">'.$form->select_dolgroups(
'',
'fk_usergroup').
'</div>';
185 echo
'<td>'.$form->selectExpense(
'',
'fk_c_type_fees', 0, 1, 1).
'</td>';
186 echo
'<td>'.$form->selectarray(
'code_expense_rules_type', $tab_rules_type,
'', 0).
'</td>';
187 echo
'<td>'.$form->selectDate(strtotime(date(
'Y-m-01',
dol_now())),
'start',
'',
'', 0,
'', 1, 0).
'</td>';
188 echo
'<td>'.$form->selectDate(strtotime(date(
'Y-m-t',
dol_now())),
'end',
'',
'', 0,
'', 1, 0).
'</td>';
189 echo
'<td><input type="text" value="" class="maxwidth100" name="amount" class="amount" /> '.$conf->currency.
'</td>';
190 echo
'<td>'.$form->selectyesno(
'restrictive', 0, 1).
'</td>';
191 echo
'<td class="right"><input type="submit" class="button" value="'.$langs->trans(
'Add').
'" /></td>';
199 echo
'<form action="'.$_SERVER[
'PHP_SELF'].
'" method="post">';
200 echo
'<input type="hidden" name="token" value="'.newToken().
'" />';
202 if ($action ==
'edit')
204 echo
'<input type="hidden" name="id" value="'.$object->id.
'" />';
205 echo
'<input type="hidden" name="action" value="save" />';
208 echo
'<table class="noborder centpercent">';
210 echo
'<tr class="liste_titre">';
211 echo
'<th>'.$langs->trans(
'ExpenseReportApplyTo').
'</th>';
212 echo
'<th>'.$langs->trans(
'Type').
'</th>';
213 echo
'<th>'.$langs->trans(
'ExpenseReportLimitOn').
'</th>';
214 echo
'<th>'.$langs->trans(
'ExpenseReportDateStart').
'</th>';
215 echo
'<th>'.$langs->trans(
'ExpenseReportDateEnd').
'</th>';
216 echo
'<th>'.$langs->trans(
'ExpenseReportLimitAmount').
'</th>';
217 echo
'<th>'.$langs->trans(
'ExpenseReportRestrictive').
'</th>';
218 echo
'<th> </th>';
221 foreach ($rules as $rule)
223 echo
'<tr class="oddeven">';
226 if ($action ==
'edit' && $object->id == $rule->id)
228 $selected = ($object->is_for_all > 0) ?
'A' : ($object->fk_usergroup > 0 ?
'G' :
'U');
229 echo
'<div class="float">'.$form->selectarray(
'apply_to', $tab_apply, $selected, 0).
'</div>';
230 echo
'<div id="user" class="float">'.$form->select_dolusers($object->fk_user,
'fk_user').
'</div>';
231 echo
'<div id="group" class="float">'.$form->select_dolgroups($object->fk_usergroup,
'fk_usergroup').
'</div>';
233 if ($rule->is_for_all > 0) echo $tab_apply[
'A'];
234 elseif ($rule->fk_usergroup > 0) echo $tab_apply['G'].' ('.$rule->getGroupLabel().')';
235 elseif ($rule->fk_user > 0) echo $tab_apply['U'].' ('.$rule->getUserName().')';
241 if ($action == 'edit' && $object->
id == $rule->
id)
243 echo $form->selectExpense($object->fk_c_type_fees,
'fk_c_type_fees', 0, 1, 1);
245 if ($rule->fk_c_type_fees == -1) echo $langs->trans(
'AllExpenseReport');
247 $key =
getDictvalue(MAIN_DB_PREFIX.
'c_type_fees',
'code', $rule->fk_c_type_fees,
false,
'id');
248 if ($key != $langs->trans($key)) echo $langs->trans($key);
249 else echo $langs->trans(
getDictvalue(MAIN_DB_PREFIX.
'c_type_fees',
'label', $rule->fk_c_type_fees,
false,
'id'));
256 if ($action ==
'edit' && $object->id == $rule->id)
258 echo $form->selectarray(
'code_expense_rules_type', $tab_rules_type, $object->code_expense_rules_type, 0);
260 echo $tab_rules_type[$rule->code_expense_rules_type];
266 if ($action ==
'edit' && $object->id == $rule->id)
268 print $form->selectDate(strtotime(date(
'Y-m-d', $object->dates)),
'start',
'',
'', 0,
'', 1, 0);
276 if ($action ==
'edit' && $object->id == $rule->id)
278 print $form->selectDate(strtotime(date(
'Y-m-d', $object->datee)),
'end',
'',
'', 0,
'', 1, 0);
286 if ($action ==
'edit' && $object->id == $rule->id)
288 echo
'<input type="text" value="'.price2num($object->amount).
'" name="amount" class="amount" />'.$conf->currency;
290 echo
price($rule->amount, 0, $langs, 1, -1, -1, $conf->currency);
296 if ($action ==
'edit' && $object->id == $rule->id)
298 echo $form->selectyesno(
'restrictive', $object->restrictive, 1);
300 echo
yn($rule->restrictive, 1, 1);
305 echo
'<td class="center">';
306 if ($object->id != $rule->id)
308 echo
'<a class="editfielda paddingright paddingleft" href="'.$_SERVER[
'PHP_SELF'].
'?action=edit&token='.
newToken().
'&id='.$rule->id.
'">'.
img_edit().
'</a> ';
309 echo
'<a class="paddingright paddingleft" href="'.$_SERVER[
'PHP_SELF'].
'?action=delete&token='.
newToken().
'&id='.$rule->id.
'">'.
img_delete().
'</a>';
311 echo
'<input type="submit" class="button" value="'.$langs->trans(
'Update').
'" /> ';
312 echo
'<a href="'.$_SERVER[
'PHP_SELF'].
'" class="button button-cancel">'.$langs->trans(
"Cancel").
'</a>';
323 echo
'<script type="text/javascript"> $(function() {
324 $("#apply_to").change(function() {
325 var value = $(this).val();
327 $("#group").hide(); $("#user").hide();
328 } else if (value == "U") {
331 } else if (value == "G") {
337 $("#apply_to").change();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
getDictvalue($tablename, $field, $id, $checkentity=false, $rowidfield= 'rowid')
Return value from dictionary.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
Class to manage inventories.
expensereport_admin_prepare_head()
Return array head with list of tabs to view object informations.
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...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
static getAllRule($fk_c_type_fees= '', $date= '', $fk_user= '')
Return all rules or filtered by something.
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.
if(!defined('CSRFCHECK_WITH_TOKEN')) define('CSRFCHECK_WITH_TOKEN'
Draft customers invoices.