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/**
19 *       \file       htdocs/core/ajax/vatrates.php
20 *       \brief      File to load vat rates combobox
21 */
22
23if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1'); // Disables token renewal
24if (!defined('NOREQUIREMENU'))  define('NOREQUIREMENU', '1');
25if (!defined('NOREQUIREAJAX'))  define('NOREQUIREAJAX', '1');
26
27require '../../main.inc.php';
28
29$id = GETPOST('id', 'int');
30$action = GETPOST('action', 'aZ09');
31$htmlname	= GETPOST('htmlname', 'alpha');
32$selected	= (GETPOST('selected') ?GETPOST('selected') : '-1');
33$productid = (GETPOST('productid', 'int') ?GETPOST('productid', 'int') : 0);
34
35/*
36 * View
37 */
38
39top_httphead();
40
41//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
42
43// Load original field value
44if (!empty($id) && !empty($action) && !empty($htmlname))
45{
46	$form = new Form($db);
47	$soc = new Societe($db);
48
49	$soc->fetch($id);
50
51	if ($action == 'getSellerVATRates')
52	{
53		$seller = $mysoc;
54		$buyer = $soc;
55	} else {
56		$buyer = $mysoc;
57		$seller = $soc;
58	}
59
60	$return = array();
61
62	$return['value']	= $form->load_tva('tva_tx', $selected, $seller, $buyer, $productid, 0, '', true);
63	$return['num'] = $form->num;
64	$return['error']	= $form->error;
65
66	echo json_encode($return);
67}
68