price.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /* Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \file htdocs/core/ajax/price.php
  19. * \brief File to get ht and ttc
  20. */
  21. if (!defined('NOTOKENRENEWAL')) {
  22. define('NOTOKENRENEWAL', '1'); // Disables token renewal
  23. }
  24. if (!defined('NOREQUIREMENU')) {
  25. define('NOREQUIREMENU', '1');
  26. }
  27. if (!defined('NOREQUIREAJAX')) {
  28. define('NOREQUIREAJAX', '1');
  29. }
  30. if (!defined('NOREQUIRESOC')) {
  31. define('NOREQUIRESOC', '1');
  32. }
  33. // Load Dolibarr environment
  34. require '../../main.inc.php';
  35. $output = GETPOST('output', 'alpha');
  36. $amount = price2num(GETPOST('amount', 'alpha'));
  37. $tva_tx = str_replace('*', '', GETPOST('tva_tx', 'alpha'));
  38. /*
  39. * View
  40. */
  41. top_httphead();
  42. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  43. // Load original field value
  44. if (!empty($output) && isset($amount) && isset($tva_tx)) {
  45. $return = array();
  46. $price = '';
  47. if (is_numeric($amount) && $amount != '') {
  48. if ($output == 'price_ttc') {
  49. $price = price2num($amount * (1 + ($tva_tx / 100)), 'MU');
  50. $return['price_ht'] = $amount;
  51. $return['price_ttc'] = (isset($price) && $price != '' ? price($price) : '');
  52. } elseif ($output == 'price_ht') {
  53. $price = price2num($amount / (1 + ($tva_tx / 100)), 'MU');
  54. $return['price_ht'] = (isset($price) && $price != '' ? price($price) : '');
  55. $return['price_ttc'] = ($tva_tx == 0 ? $price : $amount);
  56. }
  57. }
  58. echo json_encode($return);
  59. }