dolibarr 21.0.0-alpha
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 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21
28// Load Dolibarr environment
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_ik.class.php';
34
35// Load translation files required by the page
36$langs->loadLangs(array("admin", "trips", "errors", "other", "dict"));
37
38$error = 0;
39
40$action = GETPOST('action', 'aZ09');
41
42$id = GETPOSTINT('id');
43$ikoffset = (float) price2num(GETPOST('ikoffset', 'alpha'));
44$coef = (float) price2num(GETPOST('coef', 'alpha'));
45$fk_c_exp_tax_cat = GETPOSTINT('fk_c_exp_tax_cat');
46$fk_range = GETPOSTINT('fk_range');
47
48$expIk = new ExpenseReportIk($db);
49
50if (!$user->admin) {
52}
53
54
55/*
56 * Actions
57 */
58
59if ($action == 'updateik') {
60 if ($id > 0) {
61 $result = $expIk->fetch($id);
62 if ($result < 0) {
63 dol_print_error(null, $expIk->error, $expIk->errors);
64 }
65 }
66
67 $expIk->coef = $coef;
68 $expIk->ikoffset = $ikoffset;
69 $expIk->fk_c_exp_tax_cat = $fk_c_exp_tax_cat;
70 $expIk->fk_range = $fk_range;
71
72 if ($expIk->id > 0) {
73 $result = $expIk->update($user);
74 } else {
75 $result = $expIk->create($user);
76 }
77 if ($result > 0) {
78 setEventMessages('SetupSaved', null, 'mesgs');
79
80 header('Location: '.$_SERVER['PHP_SELF']);
81 exit;
82 } else {
83 setEventMessages($expIk->error, $expIk->errors, 'errors');
84 }
85} elseif ($action == 'delete') { // TODO add confirm
86 if ($id > 0) {
87 $result = $expIk->fetch($id);
88 if ($result < 0) {
89 dol_print_error(null, $expIk->error, $expIk->errors);
90 }
91
92 $expIk->delete($user);
93 }
94
95 header('Location: '.$_SERVER['PHP_SELF']);
96 exit;
97}
98
99$rangesbycateg = $expIk->getAllRanges();
100
101
102/*
103 * View
104 */
105
106llxHeader('', $langs->trans("ExpenseReportsSetup"), '', '', 0, 0, '', '', '', 'mod-admin page-expensereport_ik');
107
108$form = new Form($db);
109
110$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
111print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
112
114print dol_get_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
115
116echo '<span class="opacitymedium">'.$langs->trans('ExpenseReportIkDesc').'</span>';
117print '<br><br>';
118
119echo '<form action="'.$_SERVER['PHP_SELF'].'" method="POST">';
120echo '<input type="hidden" name="token" value="'.newToken().'" />';
121
122if ($action == 'edit') {
123 echo '<input type="hidden" name="id" value="'.$id.'" />';
124 echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
125 echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
126 echo '<input type="hidden" name="action" value="updateik" />';
127}
128
129echo '<table class="noborder centpercent">';
130
131foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab) {
132 $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
133 echo '<tr class="liste_titre">';
134 echo '<td>'.$title.'</td>';
135 echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
136 echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
137 echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
138 echo '<td>&nbsp;</td>';
139 echo '</tr>';
140
141 if ($Tab['active'] == 0) {
142 continue;
143 }
144
145 $tranche = 1;
146
147 foreach ($Tab['ranges'] as $k => $range) {
148 $ik = $range->ik;
149 '@phan-var-force ExpenseReportIk $ik';
150 if (isset($Tab['ranges'][$k + 1])) {
151 $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k + 1]->range_ik - 1));
152 } else {
153 $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
154 }
155
156 if ($range->range_active == 0) {
157 $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
158 }
159
160 echo '<tr class="oddeven">';
161
162 // Label
163 echo '<td class="nowraponall"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
164
165 // Offset
166 echo '<td class="nowraponall">';
167 if ($action == 'edit' && $ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
168 echo '<input type="text" class="maxwidth100" name="ikoffset" value="'.$ik->ikoffset.'" />';
169 } else {
170 echo $ik->ikoffset;
171 }
172 echo '</td>';
173
174 // Coef
175 echo '<td class="nowraponall">';
176 if ($action == 'edit' && $ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
177 echo '<input type="text" class="maxwidth100" name="coef" value="'.$ik->coef.'" />';
178 } else {
179 echo($ik->id > 0 ? $ik->coef : $langs->trans('expenseReportCoefUndefined'));
180 }
181 echo '</td>';
182
183 // Total for one
184 echo '<td class="nowraponall">'.$langs->trans('expenseReportPrintExample', price($ik->ikoffset + 5 * $ik->coef)).'</td>';
185
186 // Action
187 echo '<td class="right">';
188 if ($range->range_active == 1) {
189 if ($action == 'edit' && $ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) {
190 echo '<input id="" class="button button-save" name="save" value="'.$langs->trans("Save").'" type="submit" />';
191 echo '<input class="button button-cancel" value="'.$langs->trans("Cancel").'" onclick="history.go(-1)" type="button" />';
192 } else {
193 echo '<a class="editfielda marginrightonly paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=edit&token='.newToken().'&id='.$ik->id.'&fk_c_exp_tax_cat='.$range->fk_c_exp_tax_cat.'&fk_range='.$range->rowid.'">'.img_edit().'</a>';
194 if (!empty($ik->id)) {
195 echo '<a class="paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$ik->id.'">'.img_delete().'</a>';
196 }
197 // TODO add delete link
198 }
199 }
200 echo '</td>';
201
202 echo '</tr>';
203 }
204}
205
206echo '</table>';
207echo '</form>';
208
209print dol_get_fiche_end();
210
211// End of page
212llxFooter();
213$db->close();
$id
Definition account.php:39
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.
Definition wrapper.php:70
Class to manage inventories.
Class to manage generation of HTML components Only common components must be here.
llxFooter()
Footer empty.
Definition document.php:107
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
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.