29require
'../main.inc.php';
30require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
31require_once DOL_DOCUMENT_ROOT.
'/core/lib/expensereport.lib.php';
32require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
33require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport_rule.class.php';
36$langs->loadLangs(array(
"admin",
"other",
"trips",
"errors",
"dict"));
39$hookmanager->initHooks(array(
'admin',
'dictionaryadmin',
'expensereport_rules'));
53$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
62 $action =
GETPOST(
'action',
'aZ09');
65 $apply_to =
GETPOST(
'apply_to');
69 $fk_c_type_fees =
GETPOSTINT(
'fk_c_type_fees');
70 $code_expense_rules_type =
GETPOST(
'code_expense_rules_type');
82 if ($action ==
'save') {
86 if (empty($apply_to)) {
88 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportApplyTo")),
null,
'errors');
90 if (empty($fk_c_type_fees)) {
92 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDomain")),
null,
'errors');
94 if (empty($code_expense_rules_type)) {
96 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportLimitOn")),
null,
'errors');
100 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDateStart")),
null,
'errors');
104 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportDateEnd")),
null,
'errors');
106 if (empty($amount)) {
108 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ExpenseReportLimitAmount")),
null,
'errors');
112 if ($apply_to ==
'U') {
113 $object->fk_user = (int) $fk_user;
116 } elseif ($apply_to ==
'G') {
117 $object->fk_usergroup = (int) $fk_usergroup;
120 } elseif ($apply_to ==
'A') {
128 $object->restrictive = $restrictive;
129 $object->fk_c_type_fees = $fk_c_type_fees;
130 $object->code_expense_rules_type = $code_expense_rules_type;
132 $object->entity = $conf->entity;
147 header(
'Location: ' . $_SERVER[
'PHP_SELF']);
153 } elseif ($action ==
'delete') {
161 header(
'Location: ' . $_SERVER[
'PHP_SELF']);
165 $rules =
$object->getAllRule();
168 'A' => $langs->trans(
'All'),
169 'G' => $langs->trans(
'UserGroup'),
170 'U' => $langs->trans(
'User')
172 $tab_rules_type = array(
173 'EX_DAY' => $langs->trans(
'Day'),
174 'EX_MON' => $langs->trans(
'Month'),
175 'EX_YEA' => $langs->trans(
'Year'),
176 'EX_EXP' => $langs->trans(
'OnExpense')
185llxHeader(
'', $langs->trans(
"ExpenseReportsSetup"),
'',
'', 0, 0,
'',
'',
'',
'mod-admin page-expensereport_rules');
187$form =
new Form($db);
189$linkback =
'<a href="' . DOL_URL_ROOT .
'/admin/modules.php?restore_lastsearch_values=1">' . $langs->trans(
"BackToModuleList") .
'</a>';
190print
load_fiche_titre($langs->trans(
"ExpenseReportsSetup"), $linkback,
'title_setup');
193print
dol_get_fiche_head($head,
'expenserules', $langs->trans(
"ExpenseReportsRules"), -1,
'trip');
195echo
'<span class="opacitymedium">' . $langs->trans(
'ExpenseReportRulesDesc') .
'</span>';
198if ($action !=
'edit') {
199 echo
'<form action="' . $_SERVER[
'PHP_SELF'] .
'" method="post">';
200 echo
'<input type="hidden" name="token" value="' .
newToken() .
'" />';
201 echo
'<input type="hidden" name="action" value="save" />';
203 echo
'<table class="noborder centpercent">';
205 echo
'<tr class="liste_titre headerexpensereportrules">';
206 echo
'<th class="linecolapplyto">' . $langs->trans(
'ExpenseReportApplyTo') .
'</th>';
207 echo
'<th class="linecoltype">' . $langs->trans(
'Type') .
'</th>';
208 echo
'<th class="linecollimiton">' . $langs->trans(
'ExpenseReportLimitOn') .
'</th>';
209 echo
'<th class="linecoldatestart">' . $langs->trans(
'ExpenseReportDateStart') .
'</th>';
210 echo
'<th class="linecoldateend">' . $langs->trans(
'ExpenseReportDateEnd') .
'</th>';
211 echo
'<th class="linecollimitamount">' . $langs->trans(
'ExpenseReportLimitAmount') .
'</th>';
212 echo
'<th class="linecolrestrictive">' . $langs->trans(
'ExpenseReportRestrictive') .
'</th>';
213 echo
'<th> </th>';
216 echo
'<tr class="oddeven">';
218 echo
'<div class="float linecolapplyto">' . $form->selectarray(
'apply_to', $tab_apply,
'', 0) .
'</div>';
219 echo
'<div id="user" class="float linecoluser">' . $form->select_dolusers(
'',
'fk_user') .
'</div>';
220 echo
'<div id="group" class="float linecolgroup">' . $form->select_dolgroups(
'',
'fk_usergroup') .
'</div>';
223 echo
'<td class="linecoltype">' . $form->selectExpense(
'',
'fk_c_type_fees', 0, 1, 1) .
'</td>';
224 echo
'<td class="linecoltyperule">' . $form->selectarray(
'code_expense_rules_type', $tab_rules_type,
'', 0) .
'</td>';
225 echo
'<td class="linecoldatestart">' . $form->selectDate(strtotime(date(
'Y-m-01',
dol_now())),
'start', 0, 0, 0,
'', 1, 0) .
'</td>';
226 echo
'<td class="linecoldateend">' . $form->selectDate(strtotime(date(
'Y-m-t',
dol_now())),
'end', 0, 0, 0,
'', 1, 0) .
'</td>';
227 echo
'<td class="linecolamount"><input type="text" value="" class="maxwidth100" name="amount" class="amount right" /></td>';
228 echo
'<td class="linecolrestrictive">' . $form->selectyesno(
'restrictive', 0, 1) .
'</td>';
229 echo
'<td class="right linecolbutton"><input type="submit" class="button button-add" value="' . $langs->trans(
'Add') .
'" /></td>';
237echo
'<form action="' . $_SERVER[
'PHP_SELF'] .
'" method="post">';
238echo
'<input type="hidden" name="token" value="' .
newToken() .
'" />';
240if ($action ==
'edit') {
241 echo
'<input type="hidden" name="id" value="' .
$object->id .
'" />';
242 echo
'<input type="hidden" name="action" value="save" />';
248echo
'<table class="noborder centpercent">';
250echo
'<tr class="liste_titre expensereportrules">';
251echo
'<th class="linecolapplyto">' . $langs->trans(
'ExpenseReportApplyTo') .
'</th>';
252echo
'<th class="linecoltype">' . $langs->trans(
'Type') .
'</th>';
253echo
'<th class="linecollimiton">' . $langs->trans(
'ExpenseReportLimitOn') .
'</th>';
254echo
'<th class="linecoldatestart">' . $langs->trans(
'ExpenseReportDateStart') .
'</th>';
255echo
'<th class="linecoldateend">' . $langs->trans(
'ExpenseReportDateEnd') .
'</th>';
256echo
'<th class="linecollimitamount">' . $langs->trans(
'ExpenseReportLimitAmount') .
'</th>';
257echo
'<th class="linecolrestrictive">' . $langs->trans(
'ExpenseReportRestrictive') .
'</th>';
258echo
'<th> </th>';
261foreach ($rules as $rule) {
262 echo
'<tr class="oddeven linetrdata" id="'.$rule->id.
'">';
264 echo
'<td class="linecolusergroup">';
265 if ($action ==
'edit' &&
$object->id == $rule->id) {
266 $selected = (
$object->is_for_all > 0) ?
'A' : (
$object->fk_usergroup > 0 ?
'G' :
'U');
267 echo
'<div class="float">' . $form->selectarray(
'apply_to', $tab_apply, $selected, 0) .
'</div>';
268 echo
'<div id="user" class="float">' . $form->select_dolusers(
$object->fk_user,
'fk_user') .
'</div>';
269 echo
'<div id="group" class="float">' . $form->select_dolgroups(
$object->fk_usergroup,
'fk_usergroup') .
'</div>';
271 if ($rule->is_for_all > 0) {
272 echo $tab_apply[
'A'];
273 } elseif ($rule->fk_usergroup > 0) {
274 echo $tab_apply[
'G'] .
' (' . $rule->getGroupLabel() .
')';
275 } elseif ($rule->fk_user > 0) {
276 echo $tab_apply[
'U'] .
' (' . $rule->getUserName() .
')';
281 echo
'<td class="linecoltype">';
282 if ($action ==
'edit' &&
$object->id == $rule->id) {
283 echo $form->selectExpense(
$object->fk_c_type_fees,
'fk_c_type_fees', 0, 1, 1);
285 if ($rule->fk_c_type_fees == -1) {
286 echo $langs->trans(
'AllExpenseReport');
289 if ($key && $key != $langs->trans($key)) {
290 echo $langs->trans($key);
292 $value =
getDictionaryValue(
'c_type_fees',
'label', $rule->fk_c_type_fees,
false,
'id');
293 echo $langs->trans($value ? $value :
'Undefined');
300 echo
'<td class="linecoltyperule">';
301 if ($action ==
'edit' &&
$object->id == $rule->id) {
302 echo $form->selectarray(
'code_expense_rules_type', $tab_rules_type,
$object->code_expense_rules_type, 0);
304 echo $tab_rules_type[$rule->code_expense_rules_type];
309 echo
'<td class="linecoldatestart">';
310 if ($action ==
'edit' &&
$object->id == $rule->id) {
311 print $form->selectDate(strtotime(date(
'Y-m-d',
$object->dates)),
'start', 0, 0, 0,
'', 1, 0);
318 echo
'<td class="linecoldateend">';
319 if ($action ==
'edit' &&
$object->id == $rule->id) {
320 print $form->selectDate(strtotime(date(
'Y-m-d',
$object->datee)),
'end', 0, 0, 0,
'', 1, 0);
327 echo
'<td class="linecolamount">';
328 if ($action ==
'edit' &&
$object->id == $rule->id) {
329 echo
'<input type="text" value="' .
price2num(
$object->amount) .
'" name="amount" class="amount width50 right" />';
331 echo
price($rule->amount, 0, $langs, 1, -1, -1, $conf->currency);
336 echo
'<td class="linecolrestrictive">';
337 if ($action ==
'edit' &&
$object->id == $rule->id) {
338 echo $form->selectyesno(
'restrictive',
$object->restrictive, 1);
340 echo
yn($rule->restrictive, 1, 1);
345 echo
'<td class="center">';
346 if (
$object->id != $rule->id) {
347 echo
'<a class="editfielda paddingright paddingleft" href="' . $_SERVER[
'PHP_SELF'] .
'?action=edit&token=' .
newToken() .
'&id=' . $rule->id .
'">' .
img_edit() .
'</a> ';
348 echo
'<a class="paddingright paddingleft" href="' . $_SERVER[
'PHP_SELF'] .
'?action=delete&token=' .
newToken() .
'&id=' . $rule->id .
'">' .
img_delete() .
'</a>';
350 echo
'<input type="submit" class="button button-edit" value="' . $langs->trans(
'Update') .
'" /> ';
351 echo
'<a href="' . $_SERVER[
'PHP_SELF'] .
'" class="button button-cancel">' . $langs->trans(
"Cancel") .
'</a>';
358if (count($rules) == 0) {
359 print
'<tr class="none"><td colspan="8"><span class="opacitymedium">'.$langs->trans(
"None").
'</span></td></tr>';
365echo
'<script type="text/javascript"> $(function() {
366 $("#apply_to").change(function() {
367 var value = $(this).val();
369 $("#group").hide(); $("#user").hide();
370 } else if (value == "U") {
373 } else if (value == "G") {
379 $("#apply_to").change();
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage inventories.
expensereport_admin_prepare_head()
Return array head with list of tabs to view object information.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_now($mode='auto')
Return date for now.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
getDictionaryValue($tablename, $field, $id, $checkentity=false, $rowidfield='rowid')
Return the value of a filed into a dictionary for the record $id.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.