ajaxik.php 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /* Copyright (C) 2017 ATM Consulting <contact@atm-consulting.fr>
  3. * Copyright (C) 2017 Pierre-Henry Favre <phf@atm-consulting.fr>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/expensereport/ajax/ajaxprojet.php
  20. * \ingroup expensereport
  21. * \brief File to return Ajax response on third parties request
  22. */
  23. if (!defined('NOTOKENRENEWAL')) {
  24. define('NOTOKENRENEWAL', 1); // Disables token renewal
  25. }
  26. if (!defined('NOREQUIREMENU')) {
  27. define('NOREQUIREMENU', '1');
  28. }
  29. if (!defined('NOREQUIREHTML')) {
  30. define('NOREQUIREHTML', '1');
  31. }
  32. if (!defined('NOREQUIREAJAX')) {
  33. define('NOREQUIREAJAX', '1');
  34. }
  35. if (!defined('NOREQUIRESOC')) {
  36. define('NOREQUIRESOC', '1');
  37. }
  38. if (!defined('NOCSRFCHECK')) {
  39. define('NOCSRFCHECK', '1');
  40. }
  41. $res = 0;
  42. require '../../main.inc.php';
  43. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php';
  44. require_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport_ik.class.php';
  45. // Load translation files required by the page
  46. $langs->loadlangs(array('errors', 'trips'));
  47. /*
  48. * View
  49. */
  50. top_httphead();
  51. $fk_expense = GETPOST('fk_expense', 'int');
  52. $fk_c_exp_tax_cat = GETPOST('fk_c_exp_tax_cat', 'int');
  53. if (empty($fk_expense) || $fk_expense < 0) {
  54. echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_expense, 'fk_expense')));
  55. } elseif (empty($fk_c_exp_tax_cat) || $fk_c_exp_tax_cat < 0) {
  56. echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorBadValueForParameter', $fk_c_exp_tax_cat, 'fk_c_exp_tax_cat')));
  57. } else {
  58. // @see ndfp.class.php:3576 (method: compute_total_km)
  59. $expense = new ExpenseReport($db);
  60. if ($expense->fetch($fk_expense) <= 0) {
  61. echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_expense' => $fk_expense));
  62. } else {
  63. $userauthor = new User($db);
  64. if ($userauthor->fetch($expense->fk_user_author) <= 0) {
  65. echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'fk_user_author' => $expense->fk_user_author));
  66. } else {
  67. $range = ExpenseReportIk::getRangeByUser($userauthor, $fk_c_exp_tax_cat);
  68. if (empty($range)) {
  69. echo json_encode(array('error' => $langs->transnoentitiesnoconv('ErrorRecordNotFound'), 'range' => $range));
  70. } else {
  71. $ikoffset = price($range->ikoffset, 0, $langs, 1, -1, -1, $conf->currency);
  72. echo json_encode(array('up' => $range->coef, 'ikoffset' => $range->ikoffset, 'title' => $langs->transnoentitiesnoconv('ExpenseRangeOffset', $ikoffset), 'comment' => 'offset should be applied on addline or updateline'));
  73. }
  74. }
  75. }
  76. }