dolibarr  16.0.5
ajaxik.php
Go to the documentation of this file.
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')) {
26  define('NOTOKENRENEWAL', 1); // Disables token renewal
27 }
28 if (!defined('NOREQUIREMENU')) {
29  define('NOREQUIREMENU', '1');
30 }
31 if (!defined('NOREQUIREHTML')) {
32  define('NOREQUIREHTML', '1');
33 }
34 if (!defined('NOREQUIREAJAX')) {
35  define('NOREQUIREAJAX', '1');
36 }
37 if (!defined('NOREQUIRESOC')) {
38  define('NOREQUIRESOC', '1');
39 }
40 if (!defined('NOCSRFCHECK')) {
41  define('NOCSRFCHECK', '1');
42 }
43 
44 $res = 0;
45 require '../../main.inc.php';
46 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
48 
49 // Load translation files required by the page
50 $langs->loadlangs(array('errors', 'trips'));
51 
52 $fk_expense = GETPOST('fk_expense', 'int');
53 $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int');
54 $vatrate = GETPOST('vatrate', 'int');
55 $qty = GETPOST('qty', 'int');
56 
57 // Security check
58 $result = restrictedArea($user, 'expensereport', $fk_expense, 'expensereport');
59 
60 
61 /*
62  * View
63  */
64 
65 top_httphead();
66 $rep = new stdClass();
67 $rep->response_status = 0;
68 $rep->data = null;
69 $rep->error = '';//@todo deprecated use error_message instead
70 $rep->errorMessage = '';
71 
72 
73 if (empty($fk_expense) || $fk_expense < 0) {
74  $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense');
75 } elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) {
76  $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat');
77 
78  $rep->response_status = 'error';
79 } else {
80  // @see ndfp.class.php:3576 (method: compute_total_km)
81  $expense = new ExpenseReport($db);
82  if ($expense->fetch($fk_expense) <= 0) {
83  $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorRecordNotFound');
84  $rep->response_status = 'error';
85  } else {
86  $userauthor = new User($db);
87  if ($userauthor->fetch($expense->fk_user_author) <= 0) {
88  $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorRecordNotFound');
89  $rep->response_status = 'error';
90  } else {
91  $expense = new ExpenseReport($db);
92  $result = $expense->fetch($fk_expense);
93  if ($result) {
94  $result = $expense->computeTotalKm($fk_c_exp_tax_cat, $qty, $vatrate);
95  if ($result < 0) {
96  $rep->error = $result;
97  $rep->errorMessage = $langs->trans('errorComputeTtcOnMileageExpense');
98  $rep->response_status = 'error';
99  } else {
100  $rep->data = $result;
101  $rep->response_status = 'success';
102  }
103  }
104  }
105  }
106 }
107 echo json_encode($rep);
restrictedArea
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
Definition: security.lib.php:234
GETPOST
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
Definition: functions.lib.php:484
top_httphead
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
Definition: main.inc.php:1407
User
Class to manage Dolibarr users.
Definition: user.class.php:44
ExpenseReport
Class to manage Trips and Expenses.
Definition: expensereport.class.php:36