dolibarr  13.0.2
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 <https://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 // Load translation files required by the page
38 $langs->loadlangs(array('errors', '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  // @see ndfp.class.php:3576 (method: compute_total_km)
57  $expense = new ExpenseReport($db);
58  if ($expense->fetch($fk_expense) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense));
59  else {
60  $userauthor = new User($db);
61  if ($userauthor->fetch($expense->fk_user_author) <= 0) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author));
62  else {
63  $range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat);
64 
65  if (empty($range)) echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
66  else {
67  $ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency);
68  echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $offset), 'comment' => 'offset should be apply on addline or updateline'));
69  }
70  }
71  }
72 }
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
static getRangeByUser(User $userauthor, $fk_c_exp_tax_cat)
Return an array of ranges for a user.
Class to manage Dolibarr users.
Definition: user.class.php:44
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype= 'text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1214
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_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
if(!GETPOST('transkey', 'alphanohtml')&&!GETPOST('transphrase', 'alphanohtml')) else
View.
Definition: notice.php:44
Class to manage Trips and Expenses.