dolibarr  7.0.0-beta
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 $langs->load('admin');
34 $langs->load('other');
35 $langs->load('trips');
36 $langs->load('errors');
37 $langs->load('dict');
38 
39 if (!$user->admin) accessforbidden();
40 
41 //Init error
42 $error = false;
43 $message = false;
44 
45 $action = GETPOST('action','alpha');
46 $id = GETPOST('id','int');
47 $offset = GETPOST('offset','int');
48 $coef = GETPOST('coef','int');
49 
50 $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
51 $fk_range = GETPOST('fk_range');
52 
53 if ($action == 'updateik')
54 {
55  $expIk = new ExpenseReportIk($db);
56  if ($id > 0)
57  {
58  $result = $expIk->fetch($id);
59  if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
60  }
61 
62  $expIk->setValues($_POST);
63  $result = $expIk->create($user);
64 
65  if ($result > 0) setEventMessages('SetupSaved', null, 'mesgs');
66 
67  header('Location: '.$_SERVER['PHP_SELF']);
68  exit;
69 }
70 elseif ($action == 'delete') // TODO add confirm
71 {
72  $expIk = new ExpenseReportIk($db);
73  if ($id > 0)
74  {
75  $result = $expIk->fetch($id);
76  if ($result < 0) dol_print_error('', $expIk->error, $expIk->errors);
77 
78  $expIk->delete($user);
79  }
80 
81 
82  header('Location: '.$_SERVER['PHP_SELF']);
83  exit;
84 }
85 
86 $rangesbycateg = ExpenseReportIk::getAllRanges();
87 
88 /*
89  * View
90  */
91 
92 llxHeader();
93 
94 $form=new Form($db);
95 
96 $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
97 print load_fiche_titre($langs->trans("ExpenseReportsIkSetup"),$linkback,'title_setup');
98 
100 dol_fiche_head($head, 'expenseik', $langs->trans("ExpenseReportsIk"), -1, 'trip');
101 
102 echo $langs->trans('ExpenseReportIkDesc');
103 
104 echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
105 
106 if ($action == 'edit')
107 {
108  echo '<input type="hidden" name="id" value="'.$id.'" />';
109  echo '<input type="hidden" name="fk_c_exp_tax_cat" value="'.$fk_c_exp_tax_cat.'" />';
110  echo '<input type="hidden" name="fk_range" value="'.$fk_range.'" />';
111  echo '<input type="hidden" name="action" value="updateik" />';
112 }
113 
114 echo '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
115 
116 echo '<table class="noborder" width="100%">';
117 
118 foreach ($rangesbycateg as $fk_c_exp_tax_cat => $Tab)
119 {
120  $title = ($Tab['active'] == 1) ? $langs->trans($Tab['label']) : $form->textwithpicto($langs->trans($Tab['label']), $langs->trans('expenseReportCatDisabled'), 1, 'help', '', 0, 3);
121  echo '<tr class="liste_titre">';
122  echo '<td>'.$title.'</td>';
123  echo '<td>'.$langs->trans('expenseReportOffset').'</td>';
124  echo '<td>'.$langs->trans('expenseReportCoef').'</td>';
125  echo '<td>'.$langs->trans('expenseReportTotalForFive').'</td>';
126  echo '<td>&nbsp;</td>';
127  echo '</tr>';
128 
129  if ($Tab['active'] == 0) continue;
130 
131  $tranche=1;
132  $var = true;
133  foreach ($Tab['ranges'] as $k => $range)
134  {
135  if (isset($Tab['ranges'][$k+1])) $label = $langs->trans('expenseReportRangeFromTo', $range->range_ik, ($Tab['ranges'][$k+1]->range_ik-1));
136  else $label = $langs->trans('expenseReportRangeMoreThan', $range->range_ik);
137 
138  if ($range->range_active == 0) $label = $form->textwithpicto($label, $langs->trans('expenseReportRangeDisabled'), 1, 'help', '', 0, 3);
139 
140  echo '<tr '.$bc[$var].'>';
141 
142  // Label
143  echo '<td width="20%"><b>['.$langs->trans('RangeNum', $tranche++).']</b> - '.$label.'</td>';
144 
145  // Offset
146  echo '<td width="20%">';
147  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.'" />';
148  else echo $range->ik->offset;
149  echo '</td>';
150  // Coef
151  echo '<td width="20%">';
152  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.'" />';
153  else echo ($range->ik->id > 0 ? $range->ik->coef : $langs->trans('expenseReportCoefUndefined'));
154  echo '</td>';
155 
156  // Total for one
157  echo '<td width="30%">'.$langs->trans('expenseReportPrintExample', price($range->ik->offset + 5 * $range->ik->coef)).'</td>';
158 
159  // Action
160  echo '<td align="right">';
161  if ($range->range_active == 1)
162  {
163  if ($action == 'edit' && $range->ik->id == $id && $range->rowid == $fk_range && $range->fk_c_exp_tax_cat == $fk_c_exp_tax_cat)
164  {
165  echo '<input id="" class="button" name="save" value="'.$langs->trans('Save').'" type="submit" />';
166  echo '<input class="button" value="'.$langs->trans('Cancel').'" onclick="javascript:history.go(-1)" type="button" />';
167  }
168  else
169  {
170  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>';
171  if (!empty($range->ik->id)) echo '<a href="'.$_SERVER['PHP_SELF'].'?action=delete&id='.$range->ik->id.'">'.img_delete().'</a>';
172  // TODO add delete link
173  }
174  }
175  echo '</td>';
176 
177  echo '</tr>';
178  $var=!$var;
179  }
180 }
181 
182 echo '</table>';
183 echo '</form>';
184 
185 dol_fiche_end();
186 llxFooter();
187 
188 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
static getAllRanges()
Return an array of ranges grouped by category.
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='')
Show tab header of a card.
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...
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
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.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
dol_fiche_end($notab=0)
Show tab footer of a card.
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id=0, $morecssontable='', $morehtmlcenter='')
Load a title with picto.
llxHeader()
Empty header.
Definition: wrapper.php:46
img_delete($titlealt= 'default', $other= 'class="pictodelete"')
Show delete logo.
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...
print
Draft customers invoices.
Definition: index.php:91
img_edit($titlealt= 'default', $float=0, $other= 'class="pictoedit"')
Show logo editer/modifier fiche.