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