| 1 |
<?php |
| 2 |
|
| 3 |
/** |
| 4 |
***** DO NOT CALL ANY FUNCTIONS DIRECTLY FROM THIS FILE ****** |
| 5 |
* |
| 6 |
* This file will be loaded even before the framework is loaded |
| 7 |
* so the $app is not available here, only declare functions here. |
| 8 |
*/ |
| 9 |
|
| 10 |
defined( 'ABSPATH' ) || exit; |
| 11 |
|
| 12 |
if ($app->config->get('app.env') == 'dev') { |
| 13 |
|
| 14 |
$globalsDevFile = __DIR__ . '/globals_dev.php'; |
| 15 |
|
| 16 |
is_readable($globalsDevFile) && include $globalsDevFile; |
| 17 |
} |
| 18 |
|
| 19 |
if (!function_exists('dd')) { |
| 20 |
function dd() |
| 21 |
{ |
| 22 |
foreach (func_get_args() as $arg) { |
| 23 |
echo "<pre>"; |
| 24 |
print_r($arg); |
| 25 |
echo "</pre>"; |
| 26 |
} |
| 27 |
die(); |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
function fluentbookingFormattedAmount($amountInCents, $currencySettings) |
| 32 |
{ |
| 33 |
$default = [ |
| 34 |
'currency_sign' => '', |
| 35 |
'currency_position' => 'left', |
| 36 |
'decimal_separator' => '.', |
| 37 |
'thousand_separator' => ',', |
| 38 |
'currency_separator' => 'dot_comma', |
| 39 |
'decimal_points' => 2, |
| 40 |
]; |
| 41 |
|
| 42 |
$currencySettings = array_merge($default, $currencySettings); |
| 43 |
|
| 44 |
$position = $currencySettings['currency_position']; |
| 45 |
$symbol = $currencySettings['currency_sign']; |
| 46 |
$decimalPoints = $currencySettings['decimal_points']; |
| 47 |
$decmalSeparator = $currencySettings['decimal_separator']; |
| 48 |
$thousandSeparator = $currencySettings['thousand_separator']; |
| 49 |
|
| 50 |
if ($currencySettings['currency_separator'] != 'dot_comma') { |
| 51 |
$decmalSeparator = ','; |
| 52 |
$thousandSeparator = '.'; |
| 53 |
} |
| 54 |
if ($amountInCents % 100 == 0 && $currencySettings['decimal_points'] == 0) { |
| 55 |
$decimalPoints = 0; |
| 56 |
} |
| 57 |
|
| 58 |
$amount = number_format($amountInCents / 100, $decimalPoints, $decmalSeparator, $thousandSeparator); |
| 59 |
|
| 60 |
if ('left' === $position) { |
| 61 |
return $symbol . $amount; |
| 62 |
} elseif ('left_space' === $position) { |
| 63 |
return $symbol . ' ' . $amount; |
| 64 |
} elseif ('right' === $position) { |
| 65 |
return $amount . $symbol; |
| 66 |
} elseif ('right_space' === $position) { |
| 67 |
return $amount . ' ' . $symbol; |
| 68 |
} |
| 69 |
return $amount; |
| 70 |
} |
| 71 |
|