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