ajaxsalaries.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. /**
  21. * \file htdocs/salaries/ajax/ajaxsalaries.php
  22. * \brief File to return Ajax response on salary request
  23. */
  24. if (!defined('NOTOKENRENEWAL')) {
  25. define('NOTOKENRENEWAL', 1); // Disables token renewal
  26. }
  27. if (!defined('NOREQUIREMENU')) {
  28. define('NOREQUIREMENU', '1');
  29. }
  30. if (!defined('NOREQUIREHTML')) {
  31. define('NOREQUIREHTML', '1');
  32. }
  33. if (!defined('NOREQUIREAJAX')) {
  34. define('NOREQUIREAJAX', '1');
  35. }
  36. if (!defined('NOREQUIRESOC')) {
  37. define('NOREQUIRESOC', '1');
  38. }
  39. // Load Dolibarr environment
  40. require '../../main.inc.php';
  41. require_once DOL_DOCUMENT_ROOT.'/salaries/class/salary.class.php';
  42. restrictedArea($user, 'salaries');
  43. /*
  44. * View
  45. */
  46. top_httphead('application/json');
  47. $fk_user = GETPOST('fk_user', 'int');
  48. $return_arr = array();
  49. if (!empty(GETPOST('fk_user', 'int'))) {
  50. $sql = "SELECT s.amount, s.rowid FROM ".MAIN_DB_PREFIX."salary as s";
  51. $sql .= " WHERE s.fk_user = ".((int) $fk_user);
  52. $sql .= " AND s.paye = 1";
  53. $sql .= $db->order("s.dateep", "DESC");
  54. $resql = $db->query($sql);
  55. if ($resql) {
  56. $obj = $db->fetch_object($resql);
  57. $label = "Salary amount";
  58. $row_array['label'] = $label;
  59. $row_array['value'] = price2num($obj->amount, 'MT');
  60. $row_array['key'] = "Amount";
  61. array_push($return_arr, $row_array);
  62. echo json_encode($return_arr);
  63. } else {
  64. echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error'));
  65. }
  66. } else {
  67. echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter'));
  68. }