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