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