dolibarr  16.0.5
expensereport_ik.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Mikael Carlavan <contact@mika-carl.fr>
3  * Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
4  * Copyright (C) 2017 Pierre-Henry Favre <phf@atm-consulting.fr>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <https://www.gnu.org/licenses/>.
18  */
19 
20 
27 require '../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
31 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
32 
33 // Load translation files required by the page
34 $langs->loadLangs(array("admin", "trips", "errors", "other", "dict"));
35 
36 $error = 0;
37 
38 $action = GETPOST('action', 'aZ09');
39 
40 $id = GETPOST('id', 'int');
41 $ikoffset = GETPOST('ikoffset', 'int');
42 $coef = GETPOST('coef', 'int');
43 $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
44 $fk_range = GETPOST('fk_range', 'int');
45 
46 $expIk = new ExpenseReportIk($db);
47 
48 if (!$user->admin) {
50 }
51 
52 
53 /*
54  * Actions
55  */
56 
57 if ($action == 'updateik') {
58  if ($id > 0) {
59  $result = $expIk->fetch($id);
60  if ($result < 0) {
61  dol_print_error('', $expIk->error, $expIk->errors);
62  }
63  }
64 
65  $expIk->coef = $coef;
66  $expIk->ikoffset = $ikoffset;
67  $expIk->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
68  $expIk->fk_range = $fk_range;
69 
70  if ($expIk->id > 0) {
71  $result = $expIk->update($user);
72  } else {
73  $result = $expIk->create($user);
74  }
75  if ($result > 0) {
76  setEventMessages('SetupSaved', null, 'mesgs');
77 
78  header('Location: '.$_SERVER['PHP_SELF']);
79  exit;
80  } else {
81  setEventMessages($expIk->error, $expIk->errors, 'errors');
82  }
83 } elseif ($action == 'delete') { // TODO add confirm
84  if ($id > 0) {
85  $result = $expIk->fetch($id);
86  if ($result < 0) {
87  dol_print_error('', $expIk->error, $expIk->errors);
88  }
89 
90  $expIk->delete($user);
91  }
92 
93  header('Location: '.$_SERVER['PHP_SELF']);
94  exit;
95 }
96 
97 $rangesbycateg = $expIk->getAllRanges();
98 
99 
100 /*
101  * View
102  */
103 
104 llxHeader('', $langs->trans("ExpenseReportsSetup"));
105 
106 $form = new Form($db);
107 
108 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
109 print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
110 
112 print dol_get_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
113 
114 echo '<span class="opacitymedium">'.$langs->trans('ExpenseReportIkDesc').'</span>';
115 print '<br><br>';
116 
117 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
118 echo '<input type="hidden" name="token" value="'.newToken().'" />';
119 
120 if ($action == 'edit') {
121  echo '<input type="hidden" name="id" value="'.$id.'" />';
122  echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
123  echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
124  echo '<input type="hidden" name="action" value="updateik" />';
125 }
126 
127 echo '<table class="noborder centpercent">';
128 
129 foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab) {
130  $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
131  echo '<tr class="liste_titre">';
132  echo '<td>'.$title.'</td>';
133  echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
134  echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
135  echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
136  echo '<td>&nbsp;</td>';
137  echo '</tr>';
138 
139  if ($Tab['active'] == 0) {
140  continue;
141  }
142 
143  $tranche = 1;
144 
145  foreach ($Tab['ranges'] as $k => $range) {
146  if (isset($Tab['ranges'][$k + 1])) {
147  $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k + 1]->range_ik - 1));
148  } else {
149  $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
150  }
151 
152  if ($range->range_active == 0) {
153  $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
154  }
155 
156  echo '<tr class="oddeven">';
157 
158  // Label
159  echo '<td class="nowraponall"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
160 
161  // Offset
162  echo '<td class="nowraponall">';
163  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
164  echo '<input type="text" class="maxwidth100" name="ikoffset" value="'.$range->ik->ikoffset.'" />';
165  } else {
166  echo $range->ik->ikoffset;
167  }
168  echo '</td>';
169  // Coef
170  echo '<td class="nowraponall">';
171  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
172  echo '<input type="text" class="maxwidth100" name="coef" value="'.$range->ik->coef.'" />';
173  } else {
174  echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
175  }
176  echo '</td>';
177 
178  // Total for one
179  echo '<td class="nowraponall">'.$langs->trans('expenseReportPrintExample', price($range->ik->ikoffset + 5 * $range->ik->coef)).'</td>';
180 
181  // Action
182  echo '<td class="right">';
183  if ($range->range_active == 1) {
184  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
185  echo '<input id="" class="button button-save" name="save" value="'.$langs->trans("Save").'" type="submit" />';
186  echo '<input class="button button-cancel" value="'.$langs->trans("Cancel").'" onclick="javascript:history.go(-1)" type="button" />';
187  } else {
188  echo '<a class="editfielda marginrightonly paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$range->ik->id.'&fk_c_exp_tax_cat='.$range->fk_c_exp_tax_cat.'&fk_range='.$range->rowid.'">'.img_edit().'</a>';
189  if (!empty($range->ik->id)) {
190  echo '<a class="paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$range->ik->id.'">'.img_delete().'</a>';
191  }
192  // TODO add delete link
193  }
194  }
195  echo '</td>';
196 
197  echo '</tr>';
198  }
199 }
200 
201 echo '</table>';
202 echo '</form>';
203 
204 print dol_get_fiche_end();
205 
206 // End of page
207 llxFooter();
208 $db->close();
llxFooter
llxFooter()
Empty footer.
Definition: wrapper.php:73
load_fiche_titre
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
Definition: functions.lib.php:5190
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
dol_print_error
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Definition: functions.lib.php:4830
ExpenseReportIk
Class to manage inventories.
Definition: expensereport_ik.class.php:30
$form
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:142
img_edit
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier fiche.
Definition: functions.lib.php:4375
img_delete
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
Definition: functions.lib.php:4415
expensereport_admin_prepare_head
expensereport_admin_prepare_head()
Return array head with list of tabs to view object informations.
Definition: expensereport.lib.php:129
dol_get_fiche_head
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='')
Show tabs of a record.
Definition: functions.lib.php:1808
newToken
newToken()
Return the value of token currently saved into session with name 'newtoken'.
Definition: functions.lib.php:10864
dol_get_fiche_end
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition: functions.lib.php:2004
Form
Class to manage generation of HTML components Only common components must be here.
Definition: html.form.class.php:52
price
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.
Definition: functions.lib.php:5527
setEventMessages
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
Definition: functions.lib.php:8123
accessforbidden
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 ...
Definition: security.lib.php:933
llxHeader
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:59