dolibarr  7.0.0-beta
ajaxik.php
1 <?php
2 /* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
3  * Copyright (C) 2017 Pierre-Henry Favre <phf@atm-consulting.fr>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
25 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal
26 if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
27 if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
28 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
29 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
30 if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1');
31 
32 $res=0;
33 require '../../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
36 
37 $langs->load('errors');
38 $langs->load('trips');
39 
40 /*
41  * View
42  */
43 
44 top_httphead();
45 
46 
47 dol_syslog(join(',',$_POST));
48 
49 $fk_expense = GETPOST('fk_expense');
50 $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat');
51 
52 
53 if (empty($fk_expense) || $fk_expense < 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense')));
54 elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat')));
55 else
56 {
57  // @see ndfp.class.php:3576 (method: compute_total_km)
58  $expense = new ExpenseReport($db);
59  if ($expense->fetch($fk_expense) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense));
60  else
61  {
62  $userauthor = new User($db);
63  if ($userauthor->fetch($expense->fk_user_author) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author));
64  else
65  {
66  $range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat);
67 
68  if (empty($range)) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
69  else
70  {
71  $ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency);
72  echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline'));
73  }
74  }
75  }
76 }
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
Class to manage Dolibarr users.
Definition: user.class.php:39
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage Trips and Expenses.
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...
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html')
Show HTTP header.
Definition: main.inc.php:1052