dolibarr 24.0.1
ajaxsalaries.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
3 * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@inodbox.com>
4 * Copyright (C) 2007-2010 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2010 Cyrille de Lambert <info@auguria.net>
6 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program. If not, see <https://www.gnu.org/licenses/>.
20 */
21
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
43// Load Dolibarr environment
44require '../../main.inc.php';
52require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
53
54
55restrictedArea($user, 'salaries');
56
57
58/*
59 * View
60 */
61
62top_httphead('application/json');
63
64$fk_user = GETPOSTINT('fk_user');
65$return_arr = array();
66
67if (!empty(GETPOSTINT('fk_user'))) {
68 // Check that the caller is allowed to read the salary of the requested user:
69 // salaries/readall = any user, salaries/readchild = self and subordinates,
70 // salaries/read = self only.
71 if (!$user->hasRight('salaries', 'readall')) {
72 if ($user->hasRight('salaries', 'readchild')) {
73 $childids = $user->getAllChildIds(1); // Includes the current user
74 if (!in_array($fk_user, $childids)) {
75 echo json_encode(array('nom' => 'NotAuthorized', 'label' => 'NotAuthorized', 'key' => 'NotAuthorized', 'value' => 'NotAuthorized'));
76 exit;
77 }
78 } else {
79 if ($fk_user != $user->id) {
80 echo json_encode(array('nom' => 'NotAuthorized', 'label' => 'NotAuthorized', 'key' => 'NotAuthorized', 'value' => 'NotAuthorized'));
81 exit;
82 }
83 }
84 }
85
86 $sql = "SELECT s.amount, s.rowid FROM ".MAIN_DB_PREFIX."salary as s";
87 $sql .= " WHERE s.fk_user = ".((int) $fk_user);
88 $sql .= " AND s.paye = 1";
89 $sql .= $db->order("s.dateep", "DESC");
90
91 $resql = $db->query($sql);
92 if ($resql) {
93 $obj = $db->fetch_object($resql);
94 $label = "Salary amount";
95 $row_array = array();
96 $row_array['label'] = $label;
97 $row_array['value'] = price2num($obj->amount, 'MT');
98 $row_array['key'] = "Amount";
99
100 array_push($return_arr, $row_array);
101 echo json_encode($return_arr);
102 } else {
103 echo json_encode(array('nom' => 'Error', 'label' => 'Error', 'key' => 'Error', 'value' => 'Error'));
104 }
105} else {
106 echo json_encode(array('nom' => 'ErrorBadParameter', 'label' => 'ErrorBadParameter', 'key' => 'ErrorBadParameter', 'value' => 'ErrorBadParameter'));
107}
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
GETPOSTINT($paramname, $method=0, $nodefault=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.