vatrates.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/vatrates.php
  19. * \brief File to load vat rates combobox according to thirdparty ID. Values are returned in JSON format.
  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. // Load Dolibarr environment
  31. require '../../main.inc.php';
  32. $id = GETPOST('id', 'int');
  33. $action = GETPOST('action', 'aZ09'); // 'getSellerVATRates' or 'getBuyerVATRates'
  34. $htmlname = GETPOST('htmlname', 'alpha');
  35. $selected = (GETPOST('selected') ? GETPOST('selected') : '-1');
  36. $productid = (GETPOST('productid', 'int') ? GETPOST('productid', 'int') : 0);
  37. // Security check
  38. $result = restrictedArea($user, 'societe', $id, '&societe', '', 'fk_soc', 'rowid', 0);
  39. /*
  40. * View
  41. */
  42. top_httphead('application/json');
  43. //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
  44. // Load original field value
  45. if (!empty($id) && !empty($action) && !empty($htmlname)) {
  46. $form = new Form($db);
  47. $soc = new Societe($db);
  48. $soc->fetch($id);
  49. if ($action == 'getSellerVATRates') {
  50. $seller = $mysoc;
  51. $buyer = $soc;
  52. } else {
  53. $buyer = $mysoc;
  54. $seller = $soc;
  55. }
  56. $return = array();
  57. $return['value'] = $form->load_tva('tva_tx', $selected, $seller, $buyer, $productid, 0, '', true);
  58. $return['num'] = $form->num;
  59. $return['error'] = $form->error;
  60. echo json_encode($return);
  61. }