dolibarr 18.0.6
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 *
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
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
42// Load Dolibarr environment
43require '../../main.inc.php';
44require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
45
46restrictedArea($user, 'salaries');
47
48
49/*
50 * View
51 */
52
53top_httphead('application/json');
54
55$fk_user = GETPOST('fk_user', 'int');
56$return_arr = array();
57
58if (!empty(GETPOST('fk_user', 'int'))) {
59 $sql = "SELECT s.amount, s.rowid FROM ".MAIN_DB_PREFIX."salary as s";
60 $sql .= " WHERE s.fk_user = ".((int) $fk_user);
61 $sql .= " AND s.paye = 1";
62 $sql .= $db->order("s.dateep", "DESC");
63
64 $resql = $db->query($sql);
65 if ($resql) {
66 $obj = $db->fetch_object($resql);
67 $label = "Salary amount";
68 $row_array['label'] = $label;
69 $row_array['value'] = price2num($obj->amount, 'MT');
70 $row_array['key'] = "Amount";
71
72 array_push($return_arr, $row_array);
73 echo json_encode($return_arr);
74 } else {
75 echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
76 }
77} else {
78 echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
79}
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.