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