dolibarr  13.0.2
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 2 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 if (!$user->admin) accessforbidden();
37 
38 $error = 0;
39 
40 $action = GETPOST('action', 'aZ09');
41 $id = GETPOST('id', 'int');
42 $ikoffset = GETPOST('ikoffset', 'int');
43 $coef = GETPOST('coef', 'int');
44 
45 $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
46 $fk_range = GETPOST('fk_range');
47 
48 if ($action == 'updateik')
49 {
50  $expIk = new ExpenseReportIk($db);
51  if ($id > 0)
52  {
53  $result = $expIk->fetch($id);
54  if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
55  }
56 
57  $expIk->setValues($_POST);
58  $result = $expIk->create($user);
59 
60  if ($result > 0) {
61  setEventMessages('SetupSaved', null, 'mesgs');
62  header('Location: '.$_SERVER['PHP_SELF']);
63  exit;
64  } else {
65  setEventMessages($expIk->error, $expIk->errors, 'errors');
66  }
67 } elseif ($action == 'delete') // TODO add confirm
68 {
69  $expIk = new ExpenseReportIk($db);
70  if ($id > 0)
71  {
72  $result = $expIk->fetch($id);
73  if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
74 
75  $expIk->delete($user);
76  }
77 
78 
79  header('Location: '.$_SERVER['PHP_SELF']);
80  exit;
81 }
82 
83 $rangesbycateg = ExpenseReportIk::getAllRanges();
84 
85 
86 /*
87  * View
88  */
89 
90 llxHeader('', $langs->trans("ExpenseReportsSetup"));
91 
92 $form = new Form($db);
93 
94 $linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
95 print load_fiche_titre($langs->trans("ExpenseReportsSetup"), $linkback, 'title_setup');
96 
98 print dol_get_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
99 
100 echo '<span class="opacitymedium">'.$langs->trans('ExpenseReportIkDesc').'</span>';
101 print '<br><br>';
102 
103 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
104 
105 if ($action == 'edit')
106 {
107  echo '<input type="hidden" name="id" value="'.$id.'" />';
108  echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
109  echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
110  echo '<input type="hidden" name="action" value="updateik" />';
111 }
112 
113 echo '<input type="hidden" name="token" value="'.newToken().'" />';
114 
115 echo '<table class="noborder centpercent">';
116 
117 foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab)
118 {
119  $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
120  echo '<tr class="liste_titre">';
121  echo '<td>'.$title.'</td>';
122  echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
123  echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
124  echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
125  echo '<td>&nbsp;</td>';
126  echo '</tr>';
127 
128  if ($Tab['active'] == 0) continue;
129 
130  $tranche = 1;
131 
132  foreach ($Tab['ranges'] as $k => $range)
133  {
134  if (isset($Tab['ranges'][$k + 1])) $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k + 1]->range_ik - 1));
135  else $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
136 
137  if ($range->range_active == 0) $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
138 
139  echo '<tr class="oddeven">';
140 
141  // Label
142  echo '<td class="nowraponall"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
143 
144  // Offset
145  echo '<td class="nowraponall">';
146  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) echo '<input type="text" class="maxwidth100" name="ikoffset" value="'.$range->ik->ikoffset.'" />';
147  else {
148  echo $range->ik->ikoffset;
149  }
150  echo '</td>';
151  // Coef
152  echo '<td class="nowraponall">';
153  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat) echo '<input type="text" class="maxwidth100" name="coef" value="'.$range->ik->coef.'" />';
154  else echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
155  echo '</td>';
156 
157  // Total for one
158  echo '<td class="nowraponall">'.$langs->trans('expenseReportPrintExample', price($range->ik->ikoffset + 5 * $range->ik->coef)).'</td>';
159 
160  // Action
161  echo '<td class="right">';
162  if ($range->range_active == 1)
163  {
164  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat)
165  {
166  echo '<input id="" class="button button-save" name="save" value="'.$langs->trans("Save").'" type="submit" />';
167  echo '<input class="button button-cancel" value="'.$langs->trans("Cancel").'" onclick="javascript:history.go(-1)" type="button" />';
168  } else {
169  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>';
170  if (!empty($range->ik->id)) echo '<a class="paddingleft paddingright" href="'.$_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$range->ik->id.'">'.img_delete().'</a>';
171  // TODO add delete link
172  }
173  }
174  echo '</td>';
175 
176  echo '</tr>';
177  }
178 }
179 
180 echo '</table>';
181 echo '</form>';
182 
184 
185 // End of page
186 llxFooter();
187 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
img_edit($titlealt= 'default', $float=0, $other= '')
Show logo editer/modifier fiche.
static getAllRanges()
Return an array of ranges grouped by category.
Class to manage inventories.
expensereport_admin_prepare_head()
Return array head with list of tabs to view object informations.
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...
llxHeader()
Empty header.
Definition: wrapper.php:45
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage generation of HTML components Only common components must be here.
load_fiche_titre($titre, $morehtmlright= '', $picto= 'generic', $pictoisfullpath=0, $id= '', $morecssontable= '', $morehtmlcenter= '')
Load a title with picto.
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
Definition: index.php:89
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
llxFooter()
Empty footer.
Definition: wrapper.php:59
img_delete($titlealt= 'default', $other= 'class="pictodelete"', $morecss= '')
Show delete logo.