dolibarr 23.0.3
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 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2025 MDW <mdeweerd@users.noreply.github.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27if (!defined('NOTOKENRENEWAL')) {
28 define('NOTOKENRENEWAL', 1); // Disables token renewal
29}
30if (!defined('NOREQUIREMENU')) {
31 define('NOREQUIREMENU', '1');
32}
33if (!defined('NOREQUIREHTML')) {
34 define('NOREQUIREHTML', '1');
35}
36if (!defined('NOREQUIREAJAX')) {
37 define('NOREQUIREAJAX', '1');
38}
39if (!defined('NOREQUIRESOC')) {
40 define('NOREQUIRESOC', '1');
41}
42
43require '../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
45require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
46
55// Load translation files required by the page
56$langs->loadlangs(array('errors', 'trips'));
57
58$fk_expense = GETPOSTINT('fk_expense');
59$fk_c_exp_tax_cat = GETPOSTINT('fk_c_exp_tax_cat');
60$vatrate = GETPOSTINT('vatrate');
61$qty = GETPOSTINT('qty');
62
63// Security check
64$result = restrictedArea($user, 'expensereport', $fk_expense, 'expensereport');
65
66
67/*
68 * View
69 */
70
71top_httphead('application/json');
72
73$rep = new stdClass();
74$rep->response_status = 0;
75$rep->data = null;
76$rep->errorMessage = '';
77
78
79if (empty($fk_expense) || $fk_expense < 0) {
80 $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorBadValueForParameter', (string) $fk_expense, 'fk_expense');
81} elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) {
82 $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorBadValueForParameter', (string) $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat');
83
84 $rep->response_status = 'error';
85} else {
86 // @see ndfp.class.php:3576 (method: compute_total_km)
87 $expense = new ExpenseReport($db);
88 if ($expense->fetch($fk_expense) <= 0) {
89 $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorRecordNotFound');
90 $rep->response_status = 'error';
91 } else {
92 $userauthor = new User($db);
93 if ($userauthor->fetch($expense->fk_user_author) <= 0) {
94 $rep->errorMessage = $langs->transnoentitiesnoconv('ErrorRecordNotFound');
95 $rep->response_status = 'error';
96 } else {
97 $expense = new ExpenseReport($db);
98 $result = $expense->fetch($fk_expense);
99 if ($result) {
100 $result = $expense->computeTotalKm($fk_c_exp_tax_cat, $qty, $vatrate);
101 if ($result < 0) {
102 $rep->errorMessage = $langs->trans('errorComputeTtcOnMileageExpense');
103 $rep->response_status = 'error';
104 } else {
105 $rep->data = $result;
106 $rep->response_status = 'success';
107 }
108 }
109 }
110 }
111}
112echo json_encode($rep);
Class to manage Trips and Expenses.
Class to manage Dolibarr users.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.