dolibarr 20.0.0
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// Load Dolibarr environment
28require '../main.inc.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/expensereport.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
32require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
33
34// Load translation files required by the page
35$langs->loadLangs(array("admin", "trips", "errors", "other", "dict"));
36
37$error = 0;
38
39$action = GETPOST('action', 'aZ09');
40
41$id = GETPOSTINT('id');
42$ikoffset = (float) price2num(GETPOST('ikoffset', 'alpha'));
43$coef = (float) price2num(GETPOST('coef', 'alpha'));
44$fk_c_exp_tax_cat = GETPOSTINT('fk_c_exp_tax_cat');
45$fk_range = GETPOSTINT('fk_range');
46
47$expIk = new ExpenseReportIk($db);
48
49if (!$user->admin) {
51}
52
53
54/*
55 * Actions
56 */
57
58if ($action == 'updateik') {
59 if ($id > 0) {
60 $result = $expIk->fetch($id);
61 if ($result < 0) {
62 dol_print_error(null, $expIk->error, $expIk->errors);
63 }
64 }
65
66 $expIk->coef = $coef;
67 $expIk->ikoffset = $ikoffset;
68 $expIk->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
69 $expIk->fk_range = $fk_range;
70
71 if ($expIk->id > 0) {
72 $result = $expIk->update($user);
73 } else {
74 $result = $expIk->create($user);
75 }
76 if ($result > 0) {
77 setEventMessages('SetupSaved', null, 'mesgs');
78
79 header('Location: '.$_SERVER['PHP_SELF']);
80 exit;
81 } else {
82 setEventMessages($expIk->error, $expIk->errors, 'errors');
83 }
84} elseif ($action == 'delete') { // TODO add confirm
85 if ($id > 0) {
86 $result = $expIk->fetch($id);
87 if ($result < 0) {
88 dol_print_error(null, $expIk->error, $expIk->errors);
89 }
90
91 $expIk->delete($user);
92 }
93
94 header('Location: '.$_SERVER['PHP_SELF']);
95 exit;
96}
97
98$rangesbycateg = $expIk->getAllRanges();
99
100
101/*
102 * View
103 */
104
105llxHeader('', $langs->trans("ExpenseReportsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expensereport_ik');
106
107$form = new Form($db);
108
109$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
110print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
111
113print dol_get_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
114
115echo '<span class="opacitymedium">'.$langs->trans('ExpenseReportIkDesc').'</span>';
116print '<br><br>';
117
118echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
119echo '<input type="hidden" name="token" value="'.newToken().'" />';
120
121if ($action == 'edit') {
122 echo '<input type="hidden" name="id" value="'.$id.'" />';
123 echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
124 echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
125 echo '<input type="hidden" name="action" value="updateik" />';
126}
127
128echo '<table class="noborder centpercent">';
129
130foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab) {
131 $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
132 echo '<tr class="liste_titre">';
133 echo '<td>'.$title.'</td>';
134 echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
135 echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
136 echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
137 echo '<td>&nbsp;</td>';
138 echo '</tr>';
139
140 if ($Tab['active'] == 0) {
141 continue;
142 }
143
144 $tranche = 1;
145
146 foreach ($Tab['ranges'] as $k => $range) {
147 if (isset($Tab['ranges'][$k + 1])) {
148 $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k + 1]->range_ik - 1));
149 } else {
150 $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
151 }
152
153 if ($range->range_active == 0) {
154 $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
155 }
156
157 echo '<tr class="oddeven">';
158
159 // Label
160 echo '<td class="nowraponall"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
161
162 // Offset
163 echo '<td class="nowraponall">';
164 if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
165 echo '<input type="text" class="maxwidth100" name="ikoffset" value="'.$range->ik->ikoffset.'" />';
166 } else {
167 echo $range->ik->ikoffset;
168 }
169 echo '</td>';
170
171 // Coef
172 echo '<td class="nowraponall">';
173 if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
174 echo '<input type="text" class="maxwidth100" name="coef" value="'.$range->ik->coef.'" />';
175 } else {
176 echo($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
177 }
178 echo '</td>';
179
180 // Total for one
181 echo '<td class="nowraponall">'.$langs->trans('expenseReportPrintExample', price($range->ik->ikoffset + 5 * $range->ik->coef)).'</td>';
182
183 // Action
184 echo '<td class="right">';
185 if ($range->range_active == 1) {
186 if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
187 echo '<input id="" class="button button-save" name="save" value="'.$langs->trans("Save").'" type="submit" />';
188 echo '<input class="button button-cancel" value="'.$langs->trans("Cancel").'" onclick="history.go(-1)" type="button" />';
189 } else {
190 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>';
191 if (!empty($range->ik->id)) {
192 echo '<a class="paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$range->ik->id.'">'.img_delete().'</a>';
193 }
194 // TODO add delete link
195 }
196 }
197 echo '</td>';
198
199 echo '</tr>';
200 }
201}
202
203echo '</table>';
204echo '</form>';
205
206print dol_get_fiche_end();
207
208// End of page
209llxFooter();
210$db->close();
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
Class to manage inventories.
Class to manage generation of HTML components Only common components must be here.
expensereport_admin_prepare_head()
Return array head with list of tabs to view object information.
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.
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.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.