PluginProbe
Yatra – Travel Booking & Tour Operator Software / trunk
Yatra – Travel Booking & Tour Operator Software vtrunk
3.0.14 3.0.14.1 3.0.14.2 3.0.12 3.0.13 3.0.11 3.0.10 3.0.9 3.0.8 3.0.7 3.0.6 3.0.5 3.0.5.1 3.0.4 3.0.3 3.0.2.9 3.0.2.7 3.0.2.8 3.0.2.6 trunk 1.0.0 2.0.0 2.0.1 2.0.10 2.0.11 All 82 releases
yatra / app / Helpers / CurrencyHelper.php

CurrencyHelper.php in Yatra – Travel Booking & Tour Operator Software trunk, at app/Helpers/CurrencyHelper.php

335 lines 16.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace Yatra\Helpers;
6
7 /**
8 * Currency Helper
9 *
10 * Centralized currency data for use throughout the application.
11 *
12 * Usage:
13 * CurrencyHelper::getAll()
14 * CurrencyHelper::getSymbol('USD')
15 * CurrencyHelper::getName('USD')
16 *
17 * @package Yatra\Helpers
18 */
19 class CurrencyHelper
20 {
21 /**
22 * Complete list of world currencies with code, name, and symbol
23 */
24 private const CURRENCIES = [
25 // Major Currencies
26 'USD' => ['name' => 'US Dollar', 'symbol' => '$', 'decimal_digits' => 2],
27 'EUR' => ['name' => 'Euro', 'symbol' => '', 'decimal_digits' => 2],
28 'GBP' => ['name' => 'British Pound', 'symbol' => '£', 'decimal_digits' => 2],
29 'JPY' => ['name' => 'Japanese Yen', 'symbol' => '¥', 'decimal_digits' => 0],
30 'CNY' => ['name' => 'Chinese Yuan', 'symbol' => '¥', 'decimal_digits' => 2],
31 'CHF' => ['name' => 'Swiss Franc', 'symbol' => 'CHF', 'decimal_digits' => 2],
32 'CAD' => ['name' => 'Canadian Dollar', 'symbol' => 'C$', 'decimal_digits' => 2],
33 'AUD' => ['name' => 'Australian Dollar', 'symbol' => 'A$', 'decimal_digits' => 2],
34 'NZD' => ['name' => 'New Zealand Dollar', 'symbol' => 'NZ$', 'decimal_digits' => 2],
35
36 // Asian Currencies
37 'INR' => ['name' => 'Indian Rupee', 'symbol' => '', 'decimal_digits' => 2],
38 'NPR' => ['name' => 'Nepalese Rupee', 'symbol' => 'Rs', 'decimal_digits' => 2],
39 'PKR' => ['name' => 'Pakistani Rupee', 'symbol' => '', 'decimal_digits' => 2],
40 'BDT' => ['name' => 'Bangladeshi Taka', 'symbol' => '', 'decimal_digits' => 2],
41 'LKR' => ['name' => 'Sri Lankan Rupee', 'symbol' => 'Rs', 'decimal_digits' => 2],
42 'MMK' => ['name' => 'Myanmar Kyat', 'symbol' => 'K', 'decimal_digits' => 2],
43 'THB' => ['name' => 'Thai Baht', 'symbol' => '฿', 'decimal_digits' => 2],
44 'VND' => ['name' => 'Vietnamese Dong', 'symbol' => '', 'decimal_digits' => 0],
45 'IDR' => ['name' => 'Indonesian Rupiah', 'symbol' => 'Rp', 'decimal_digits' => 2],
46 'MYR' => ['name' => 'Malaysian Ringgit', 'symbol' => 'RM', 'decimal_digits' => 2],
47 'SGD' => ['name' => 'Singapore Dollar', 'symbol' => 'S$', 'decimal_digits' => 2],
48 'PHP' => ['name' => 'Philippine Peso', 'symbol' => '', 'decimal_digits' => 2],
49 'KRW' => ['name' => 'South Korean Won', 'symbol' => '', 'decimal_digits' => 0],
50 'TWD' => ['name' => 'Taiwan Dollar', 'symbol' => 'NT$', 'decimal_digits' => 2],
51 'HKD' => ['name' => 'Hong Kong Dollar', 'symbol' => 'HK$', 'decimal_digits' => 2],
52 'MOP' => ['name' => 'Macanese Pataca', 'symbol' => 'MOP$', 'decimal_digits' => 2],
53 'KHR' => ['name' => 'Cambodian Riel', 'symbol' => '', 'decimal_digits' => 2],
54 'LAK' => ['name' => 'Lao Kip', 'symbol' => '', 'decimal_digits' => 2],
55 'BND' => ['name' => 'Brunei Dollar', 'symbol' => 'B$', 'decimal_digits' => 2],
56 'MNT' => ['name' => 'Mongolian Tugrik', 'symbol' => '', 'decimal_digits' => 2],
57 'KZT' => ['name' => 'Kazakhstani Tenge', 'symbol' => '', 'decimal_digits' => 2],
58 'UZS' => ['name' => 'Uzbekistani Som', 'symbol' => 'сўм', 'decimal_digits' => 2],
59 'KGS' => ['name' => 'Kyrgyzstani Som', 'symbol' => 'сом', 'decimal_digits' => 2],
60 'TJS' => ['name' => 'Tajikistani Somoni', 'symbol' => '�
61 М', 'decimal_digits' => 2],
62 'TMT' => ['name' => 'Turkmenistani Manat', 'symbol' => 'm', 'decimal_digits' => 2],
63 'AFN' => ['name' => 'Afghan Afghani', 'symbol' => '؋', 'decimal_digits' => 2],
64
65 // Middle Eastern Currencies
66 'AED' => ['name' => 'UAE Dirham', 'symbol' => 'د.إ', 'decimal_digits' => 2],
67 'SAR' => ['name' => 'Saudi Riyal', 'symbol' => '', 'decimal_digits' => 2],
68 'QAR' => ['name' => 'Qatari Riyal', 'symbol' => '', 'decimal_digits' => 2],
69 'KWD' => ['name' => 'Kuwaiti Dinar', 'symbol' => 'د.ك', 'decimal_digits' => 3],
70 'BHD' => ['name' => 'Bahraini Dinar', 'symbol' => '.د.ب', 'decimal_digits' => 3],
71 'OMR' => ['name' => 'Omani Rial', 'symbol' => '', 'decimal_digits' => 3],
72 'JOD' => ['name' => 'Jordanian Dinar', 'symbol' => 'د.ا', 'decimal_digits' => 3],
73 'ILS' => ['name' => 'Israeli Shekel', 'symbol' => '', 'decimal_digits' => 2],
74 'LBP' => ['name' => 'Lebanese Pound', 'symbol' => 'ل.ل', 'decimal_digits' => 2],
75 'SYP' => ['name' => 'Syrian Pound', 'symbol' => '£S', 'decimal_digits' => 2],
76 'IQD' => ['name' => 'Iraqi Dinar', 'symbol' => 'ع.د', 'decimal_digits' => 3],
77 'IRR' => ['name' => 'Iranian Rial', 'symbol' => '', 'decimal_digits' => 2],
78 'YER' => ['name' => 'Yemeni Rial', 'symbol' => '', 'decimal_digits' => 2],
79 'EGP' => ['name' => 'Egyptian Pound', 'symbol' => '', 'decimal_digits' => 2],
80 'TRY' => ['name' => 'Turkish Lira', 'symbol' => '', 'decimal_digits' => 2],
81
82 // European Currencies
83 'SEK' => ['name' => 'Swedish Krona', 'symbol' => 'kr', 'decimal_digits' => 2],
84 'NOK' => ['name' => 'Norwegian Krone', 'symbol' => 'kr', 'decimal_digits' => 2],
85 'DKK' => ['name' => 'Danish Krone', 'symbol' => 'kr', 'decimal_digits' => 2],
86 'ISK' => ['name' => 'Icelandic Króna', 'symbol' => 'kr', 'decimal_digits' => 0],
87 'PLN' => ['name' => 'Polish Zloty', 'symbol' => '', 'decimal_digits' => 2],
88 'CZK' => ['name' => 'Czech Koruna', 'symbol' => '', 'decimal_digits' => 2],
89 'HUF' => ['name' => 'Hungarian Forint', 'symbol' => 'Ft', 'decimal_digits' => 2],
90 'RON' => ['name' => 'Romanian Leu', 'symbol' => 'lei', 'decimal_digits' => 2],
91 'BGN' => ['name' => 'Bulgarian Lev', 'symbol' => 'лв', 'decimal_digits' => 2],
92 'HRK' => ['name' => 'Croatian Kuna', 'symbol' => 'kn', 'decimal_digits' => 2],
93 'RSD' => ['name' => 'Serbian Dinar', 'symbol' => 'дин.', 'decimal_digits' => 2],
94 'MKD' => ['name' => 'Macedonian Denar', 'symbol' => 'ден', 'decimal_digits' => 2],
95 'BAM' => ['name' => 'Bosnia-Herzegovina Mark', 'symbol' => 'KM', 'decimal_digits' => 2],
96 'ALL' => ['name' => 'Albanian Lek', 'symbol' => 'L', 'decimal_digits' => 2],
97 'MDL' => ['name' => 'Moldovan Leu', 'symbol' => 'L', 'decimal_digits' => 2],
98 'UAH' => ['name' => 'Ukrainian Hryvnia', 'symbol' => '', 'decimal_digits' => 2],
99 'BYN' => ['name' => 'Belarusian Ruble', 'symbol' => 'Br', 'decimal_digits' => 2],
100 'RUB' => ['name' => 'Russian Ruble', 'symbol' => '', 'decimal_digits' => 2],
101 'GEL' => ['name' => 'Georgian Lari', 'symbol' => '', 'decimal_digits' => 2],
102 'AMD' => ['name' => 'Armenian Dram', 'symbol' => '֏', 'decimal_digits' => 2],
103 'AZN' => ['name' => 'Azerbaijani Manat', 'symbol' => '', 'decimal_digits' => 2],
104
105 // African Currencies
106 'ZAR' => ['name' => 'South African Rand', 'symbol' => 'R', 'decimal_digits' => 2],
107 'NGN' => ['name' => 'Nigerian Naira', 'symbol' => '', 'decimal_digits' => 2],
108 'KES' => ['name' => 'Kenyan Shilling', 'symbol' => 'KSh', 'decimal_digits' => 2],
109 'GHS' => ['name' => 'Ghanaian Cedi', 'symbol' => '', 'decimal_digits' => 2],
110 'TZS' => ['name' => 'Tanzanian Shilling', 'symbol' => 'TSh', 'decimal_digits' => 2],
111 'UGX' => ['name' => 'Ugandan Shilling', 'symbol' => 'USh', 'decimal_digits' => 0],
112 'RWF' => ['name' => 'Rwandan Franc', 'symbol' => 'FRw', 'decimal_digits' => 0],
113 'ETB' => ['name' => 'Ethiopian Birr', 'symbol' => 'Br', 'decimal_digits' => 2],
114 'MAD' => ['name' => 'Moroccan Dirham', 'symbol' => 'د.�
115 .', 'decimal_digits' => 2],
116 'TND' => ['name' => 'Tunisian Dinar', 'symbol' => 'د.ت', 'decimal_digits' => 3],
117 'DZD' => ['name' => 'Algerian Dinar', 'symbol' => 'د.ج', 'decimal_digits' => 2],
118 'LYD' => ['name' => 'Libyan Dinar', 'symbol' => 'ل.د', 'decimal_digits' => 3],
119 'SDG' => ['name' => 'Sudanese Pound', 'symbol' => 'ج.س.', 'decimal_digits' => 2],
120 'XOF' => ['name' => 'West African CFA Franc', 'symbol' => 'CFA', 'decimal_digits' => 0],
121 'XAF' => ['name' => 'Central African CFA Franc', 'symbol' => 'FCFA', 'decimal_digits' => 0],
122 'MUR' => ['name' => 'Mauritian Rupee', 'symbol' => '', 'decimal_digits' => 2],
123 'SCR' => ['name' => 'Seychellois Rupee', 'symbol' => '', 'decimal_digits' => 2],
124 'MGA' => ['name' => 'Malagasy Ariary', 'symbol' => 'Ar', 'decimal_digits' => 2],
125 'MZN' => ['name' => 'Mozambican Metical', 'symbol' => 'MT', 'decimal_digits' => 2],
126 'ZMW' => ['name' => 'Zambian Kwacha', 'symbol' => 'ZK', 'decimal_digits' => 2],
127 'BWP' => ['name' => 'Botswana Pula', 'symbol' => 'P', 'decimal_digits' => 2],
128 'NAD' => ['name' => 'Namibian Dollar', 'symbol' => 'N$', 'decimal_digits' => 2],
129 'AOA' => ['name' => 'Angolan Kwanza', 'symbol' => 'Kz', 'decimal_digits' => 2],
130 'CDF' => ['name' => 'Congolese Franc', 'symbol' => 'FC', 'decimal_digits' => 2],
131
132 // Americas Currencies
133 'BRL' => ['name' => 'Brazilian Real', 'symbol' => 'R$', 'decimal_digits' => 2],
134 'MXN' => ['name' => 'Mexican Peso', 'symbol' => '$', 'decimal_digits' => 2],
135 'ARS' => ['name' => 'Argentine Peso', 'symbol' => '$', 'decimal_digits' => 2],
136 'CLP' => ['name' => 'Chilean Peso', 'symbol' => '$', 'decimal_digits' => 0],
137 'COP' => ['name' => 'Colombian Peso', 'symbol' => '$', 'decimal_digits' => 2],
138 'PEN' => ['name' => 'Peruvian Sol', 'symbol' => 'S/', 'decimal_digits' => 2],
139 'UYU' => ['name' => 'Uruguayan Peso', 'symbol' => '$U', 'decimal_digits' => 2],
140 'PYG' => ['name' => 'Paraguayan Guarani', 'symbol' => '', 'decimal_digits' => 0],
141 'BOB' => ['name' => 'Bolivian Boliviano', 'symbol' => 'Bs.', 'decimal_digits' => 2],
142 'VES' => ['name' => 'Venezuelan Bolívar', 'symbol' => 'Bs.S', 'decimal_digits' => 2],
143 'CRC' => ['name' => 'Costa Rican Colón', 'symbol' => '', 'decimal_digits' => 2],
144 'PAB' => ['name' => 'Panamanian Balboa', 'symbol' => 'B/.', 'decimal_digits' => 2],
145 'GTQ' => ['name' => 'Guatemalan Quetzal', 'symbol' => 'Q', 'decimal_digits' => 2],
146 'HNL' => ['name' => 'Honduran Lempira', 'symbol' => 'L', 'decimal_digits' => 2],
147 'NIO' => ['name' => 'Nicaraguan Córdoba', 'symbol' => 'C$', 'decimal_digits' => 2],
148 'SVC' => ['name' => 'Salvadoran Colón', 'symbol' => '', 'decimal_digits' => 2],
149 'DOP' => ['name' => 'Dominican Peso', 'symbol' => 'RD$', 'decimal_digits' => 2],
150 'CUP' => ['name' => 'Cuban Peso', 'symbol' => '', 'decimal_digits' => 2],
151 'HTG' => ['name' => 'Haitian Gourde', 'symbol' => 'G', 'decimal_digits' => 2],
152 'JMD' => ['name' => 'Jamaican Dollar', 'symbol' => 'J$', 'decimal_digits' => 2],
153 'TTD' => ['name' => 'Trinidad & Tobago Dollar', 'symbol' => 'TT$', 'decimal_digits' => 2],
154 'BBD' => ['name' => 'Barbadian Dollar', 'symbol' => 'Bds$', 'decimal_digits' => 2],
155 'BSD' => ['name' => 'Bahamian Dollar', 'symbol' => 'B$', 'decimal_digits' => 2],
156 'BZD' => ['name' => 'Belize Dollar', 'symbol' => 'BZ$', 'decimal_digits' => 2],
157 'GYD' => ['name' => 'Guyanese Dollar', 'symbol' => 'G$', 'decimal_digits' => 2],
158 'SRD' => ['name' => 'Surinamese Dollar', 'symbol' => '$', 'decimal_digits' => 2],
159 'XCD' => ['name' => 'East Caribbean Dollar', 'symbol' => 'EC$', 'decimal_digits' => 2],
160 'AWG' => ['name' => 'Aruban Florin', 'symbol' => 'ƒ', 'decimal_digits' => 2],
161 'ANG' => ['name' => 'Netherlands Antillean Guilder', 'symbol' => 'ƒ', 'decimal_digits' => 2],
162 'KYD' => ['name' => 'Cayman Islands Dollar', 'symbol' => 'CI$', 'decimal_digits' => 2],
163 'BMD' => ['name' => 'Bermudian Dollar', 'symbol' => '$', 'decimal_digits' => 2],
164
165 // Oceania Currencies
166 'FJD' => ['name' => 'Fijian Dollar', 'symbol' => 'FJ$', 'decimal_digits' => 2],
167 'PGK' => ['name' => 'Papua New Guinean Kina', 'symbol' => 'K', 'decimal_digits' => 2],
168 'SBD' => ['name' => 'Solomon Islands Dollar', 'symbol' => 'SI$', 'decimal_digits' => 2],
169 'VUV' => ['name' => 'Vanuatu Vatu', 'symbol' => 'VT', 'decimal_digits' => 0],
170 'WST' => ['name' => 'Samoan Tala', 'symbol' => 'WS$', 'decimal_digits' => 2],
171 'TOP' => ['name' => 'Tongan Paʻanga', 'symbol' => 'T$', 'decimal_digits' => 2],
172 'XPF' => ['name' => 'CFP Franc', 'symbol' => '', 'decimal_digits' => 0],
173
174 // Crypto (optional, for modern support)
175 'BTC' => ['name' => 'Bitcoin', 'symbol' => '', 'decimal_digits' => 8],
176 'ETH' => ['name' => 'Ethereum', 'symbol' => 'Ξ', 'decimal_digits' => 8],
177 ];
178
179 /**
180 * Get all currencies
181 *
182 * @return array [code => ['name' => ..., 'symbol' => ..., 'decimal_digits' => ...]]
183 */
184 public static function getAll(): array
185 {
186 return self::CURRENCIES;
187 }
188
189 /**
190 * Get currencies as simple options array for dropdowns
191 *
192 * @param bool $includeSymbol Include symbol in label
193 * @return array [code => label]
194 */
195 public static function getOptions(bool $includeSymbol = true): array
196 {
197 $options = [];
198 foreach (self::CURRENCIES as $code => $data) {
199 if ($includeSymbol) {
200 $options[$code] = "{$data['name']} ({$data['symbol']})";
201 } else {
202 $options[$code] = "{$data['name']} ({$code})";
203 }
204 }
205 return $options;
206 }
207
208 /**
209 * Get currency symbol
210 *
211 * @param string $code Currency code
212 * @return string Symbol or code if not found
213 */
214 public static function getSymbol(string $code): string
215 {
216 $code = strtoupper($code);
217 return self::CURRENCIES[$code]['symbol'] ?? $code;
218 }
219
220 /**
221 * Get currency name
222 *
223 * @param string $code Currency code
224 * @return string Name or code if not found
225 */
226 public static function getName(string $code): string
227 {
228 $code = strtoupper($code);
229 return self::CURRENCIES[$code]['name'] ?? $code;
230 }
231
232 /**
233 * Get decimal digits for currency
234 *
235 * @param string $code Currency code
236 * @return int Decimal digits (default 2)
237 */
238 public static function getDecimalDigits(string $code): int
239 {
240 $code = strtoupper($code);
241 return self::CURRENCIES[$code]['decimal_digits'] ?? 2;
242 }
243
244 /**
245 * Get currency data
246 *
247 * @param string $code Currency code
248 * @return array|null Currency data or null if not found
249 */
250 public static function get(string $code): ?array
251 {
252 $code = strtoupper($code);
253 return self::CURRENCIES[$code] ?? null;
254 }
255
256 /**
257 * Check if currency exists
258 *
259 * @param string $code Currency code
260 * @return bool
261 */
262 public static function exists(string $code): bool
263 {
264 return isset(self::CURRENCIES[strtoupper($code)]);
265 }
266
267 /**
268 * Format amount with currency
269 *
270 * @param float $amount Amount to format
271 * @param string $code Currency code
272 * @param bool $showCode Show currency code after amount
273 * @return string Formatted amount
274 */
275 public static function format(float $amount, string $code = 'USD', bool $showCode = false): string
276 {
277 if (function_exists('yatra_format_price')) {
278 $result = yatra_format_price($amount, $code, false);
279 } else {
280 $code = strtoupper($code);
281 $currency = self::CURRENCIES[$code] ?? null;
282
283 if (!$currency) {
284 return number_format($amount, 2) . ' ' . $code;
285 }
286
287 $formatted = number_format($amount, $currency['decimal_digits']);
288 $result = $currency['symbol'] . $formatted;
289 }
290
291 if ($showCode) {
292 $result .= ' ' . strtoupper($code);
293 }
294
295 return $result;
296 }
297
298 /**
299 * Get currencies for JavaScript (to be localized)
300 *
301 * @return array
302 */
303 public static function getForJavaScript(): array
304 {
305 $currencies = [];
306 foreach (self::CURRENCIES as $code => $data) {
307 $currencies[$code] = [
308 'code' => $code,
309 'name' => $data['name'],
310 'symbol' => $data['symbol'],
311 'decimalDigits' => $data['decimal_digits'],
312 'label' => "{$data['name']} ({$data['symbol']})",
313 ];
314 }
315 return $currencies;
316 }
317
318 /**
319 * Get popular/common currencies (for quick selection)
320 *
321 * @return array
322 */
323 public static function getPopular(): array
324 {
325 $popular = ['USD', 'EUR', 'GBP', 'JPY', 'CNY', 'CAD', 'AUD', 'CHF', 'INR', 'NPR'];
326 $result = [];
327 foreach ($popular as $code) {
328 if (isset(self::CURRENCIES[$code])) {
329 $result[$code] = self::CURRENCIES[$code];
330 }
331 }
332 return $result;
333 }
334 }
335