dolibarr  9.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 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 <http://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 //Init error
39 $error = false;
40 $message = false;
41 
42 $action = GETPOST('action','alpha');
43 $id = GETPOST('id','int');
44 $offset = GETPOST('offset','int');
45 $coef = GETPOST('coef','int');
46 
47 $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
48 $fk_range = GETPOST('fk_range');
49 
50 if ($action == 'updateik')
51 {
52  $expIk = new ExpenseReportIk($db);
53  if ($id > 0)
54  {
55  $result = $expIk->fetch($id);
56  if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
57  }
58 
59  $expIk->setValues($_POST);
60  $result = $expIk->create($user);
61 
62  if ($result > 0) setEventMessages('SetupSaved', null, 'mesgs');
63 
64  header('Location: '.$_SERVER['PHP_SELF']);
65  exit;
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  * View
87  */
88 
89 llxHeader('',$langs->trans("ExpenseReportsSetup"));
90 
91 $form=new Form($db);
92 
93 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
94 print load_fiche_titre($langs->trans("ExpenseReportsIkSetup"),$linkback,'title_setup');
95 
97 dol_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
98 
99 echo $langs->trans('ExpenseReportIkDesc');
100 
101 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
102 
103 if ($action == 'edit')
104 {
105  echo '<input type="hidden" name="id" value="'.$id.'" />';
106  echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
107  echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
108  echo '<input type="hidden" name="action" value="updateik" />';
109 }
110 
111 echo '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
112 
113 echo '<table class="noborder" width="100%">';
114 
115 foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab)
116 {
117  $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
118  echo '<tr class="liste_titre">';
119  echo '<td>'.$title.'</td>';
120  echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
121  echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
122  echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
123  echo '<td>&nbsp;</td>';
124  echo '</tr>';
125 
126  if ($Tab['active'] == 0) continue;
127 
128  $tranche=1;
129 
130  foreach ($Tab['ranges'] as $k => $range)
131  {
132  if (isset($Tab['ranges'][$k+1])) $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k+1]->range_ik-1));
133  else $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
134 
135  if ($range->range_active == 0) $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
136 
137  echo '<tr class="oddeven">';
138 
139  // Label
140  echo '<td width="20%"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
141 
142  // Offset
143  echo '<td width="20%">';
144  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" name="offset" value="'.$range->ik->offset.'" />';
145  else echo $range->ik->offset;
146  echo '</td>';
147  // Coef
148  echo '<td width="20%">';
149  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" name="coef" value="'.$range->ik->coef.'" />';
150  else echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
151  echo '</td>';
152 
153  // Total for one
154  echo '<td width="30%">'.$langs->trans('expenseReportPrintExample', price($range->ik->offset + 5 * $range->ik->coef)).'</td>';
155 
156  // Action
157  echo '<td align="right">';
158  if ($range->range_active == 1)
159  {
160  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat)
161  {
162  echo '<input id="" class="button" name="save" value="'.$langs->trans('Save').'" type="submit" />';
163  echo '<input class="button" value="'.$langs->trans('Cancel').'" onclick="javascript:history.go(-1)" type="button" />';
164  }
165  else
166  {
167  echo '<a href="'.$_SERVER['PHP_SELF'].'?action=edit&id='.$range->ik->id.'&fk_c_exp_tax_cat='.$range->fk_c_exp_tax_cat.'&fk_range='.$range->rowid.'">'.img_edit().'</a>';
168  if (!empty($range->ik->id)) echo '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&id='.$range->ik->id.'">'.img_delete().'</a>';
169  // TODO add delete link
170  }
171  }
172  echo '</td>';
173 
174  echo '</tr>';
175  }
176 }
177 
178 echo '</table>';
179 echo '</form>';
180 
181 dol_fiche_end();
182 
183 // End of page
184 llxFooter();
185 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print
Draft customers invoices.
Definition: index.php:91
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
static getAllRanges()
Return an array of ranges grouped by category.
img_edit($titlealt='default', $float=0, $other='class="pictoedit"')
Show logo editer/modifier fiche.
Class to manage inventories.
expensereport_admin_prepare_head()
Return array head with list of tabs to view object informations.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
img_delete($titlealt='default', $other='class="pictodelete"')
Show delete logo.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage generation of HTML components Only common components must be here.
dol_fiche_end($notab=0)
Show tab footer of a card.
llxHeader()
Empty header.
Definition: wrapper.php:44
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...
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.