dolibarr  7.0.0-beta
price.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2012 Regis Houssin <regis.houssin@capnetworks.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 <http://www.gnu.org/licenses/>.
16  */
17 
23 if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal
24 if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1');
25 //if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1');
26 if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1');
27 if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1');
28 //if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1');
29 
30 require('../../main.inc.php');
31 
32 $output = GETPOST('output','alpha');
33 $amount = price2num(GETPOST('amount','alpha'));
34 $tva_tx = str_replace('*','',GETPOST('tva_tx','alpha'));
35 
36 /*
37  * View
38  */
39 
40 top_httphead();
41 
42 //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
43 
44 // Load original field value
45 if (! empty($output) && isset($amount) && isset($tva_tx))
46 {
47  $return=array();
48  $price='';
49 
50  if (is_numeric($amount) && $amount != '')
51  {
52  if ($output == 'price_ttc') {
53 
54  $price = price2num($amount * (1 + ($tva_tx/100)), 'MU');
55  $return['price_ht'] = $amount;
56  $return['price_ttc'] = (isset($price) && $price != '' ? price($price) : '');
57 
58  }
59  else if ($output == 'price_ht') {
60 
61  $price = price2num($amount / (1 + ($tva_tx/100)), 'MU');
62  $return['price_ht'] = (isset($price) && $price != '' ? price($price) : '');
63  $return['price_ttc'] = ($tva_tx == 0 ? $price : $amount);
64  }
65  }
66 
67  echo json_encode($return);
68 }
69 
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
if(!defined('NOREQUIREMENU')) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html')
Show HTTP header.
Definition: main.inc.php:1052
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is '...