dolibarr 19.0.3
price.php
Go to the documentation of this file.
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
23if (!defined('NOTOKENRENEWAL')) {
24 define('NOTOKENRENEWAL', '1'); // Disables token renewal
25}
26if (!defined('NOREQUIREMENU')) {
27 define('NOREQUIREMENU', '1');
28}
29if (!defined('NOREQUIREAJAX')) {
30 define('NOREQUIREAJAX', '1');
31}
32if (!defined('NOREQUIRESOC')) {
33 define('NOREQUIRESOC', '1');
34}
35
36// Load Dolibarr environment
37require '../../main.inc.php';
38
39$output = GETPOST('output', 'alpha');
40$amount = price2num(GETPOST('amount', 'alpha'));
41$tva_tx = str_replace('*', '', GETPOST('tva_tx', 'alpha'));
42
43// Security check
44// None. This is a formatting only component.
45
46
47/*
48 * View
49 */
50
52
53//print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n";
54
55// Load original field value
56if (!empty($output) && isset($amount) && isset($tva_tx)) {
57 $return = array();
58 $price = '';
59
60 if (is_numeric($amount) && $amount != '') {
61 if ($output == 'price_ttc') {
62 $price = price2num($amount * (1 + ($tva_tx / 100)), 'MU');
63 $return['price_ht'] = $amount;
64 $return['price_ttc'] = (isset($price) && $price != '' ? price($price) : '');
65 } elseif ($output == 'price_ht') {
66 $price = price2num($amount / (1 + ($tva_tx / 100)), 'MU');
67 $return['price_ht'] = (isset($price) && $price != '' ? price($price) : '');
68 $return['price_ttc'] = ($tva_tx == 0 ? $price : $amount);
69 }
70 }
71
72 echo json_encode($return);
73}
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.