|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace IproSync\Ipro; |
|
4
|
|
|
|
|
5
|
|
|
use Illuminate\Support\Str; |
|
6
|
|
|
|
|
7
|
|
|
class CustomRateAmountHelper |
|
8
|
|
|
{ |
|
9
|
|
|
public static function convertListToHumanReadable(array $amountList, string $currency = '$'): array |
|
10
|
|
|
{ |
|
11
|
|
|
$formattedAmountList = []; |
|
12
|
|
|
foreach ($amountList as $key => $item) { |
|
13
|
|
|
$formattedAmountList[$key] = static::convertToHumanReadable((string) $item, $currency); |
|
14
|
|
|
} |
|
15
|
|
|
|
|
16
|
|
|
return $formattedAmountList; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public static function convertToHumanReadable(string $amount, string $currency = '$'): array |
|
20
|
|
|
{ |
|
21
|
|
|
$amount = trim($amount); |
|
22
|
|
|
|
|
23
|
|
|
$offer = ''; |
|
24
|
|
|
$useFrom = false; |
|
25
|
|
|
|
|
26
|
|
|
if ($amount === '-2') { |
|
27
|
|
|
return [ |
|
28
|
|
|
'text' => trans('ipro-sync::prices.hide'), |
|
29
|
|
|
'hint' => trans('ipro-sync::prices.hints.hide'), |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
if ($amount === '-1') { |
|
34
|
|
|
return [ |
|
35
|
|
|
'text' => trans('ipro-sync::prices.no_price'), |
|
36
|
|
|
'hint' => trans('ipro-sync::prices.hints.no_price'), |
|
37
|
|
|
]; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
if ($amount === '0') { |
|
41
|
|
|
return [ |
|
42
|
|
|
'text' => trans('ipro-sync::prices.previous_week'), |
|
43
|
|
|
'hint' => trans('ipro-sync::prices.hints.previous_week'), |
|
44
|
|
|
]; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
if (Str::startsWith($amount, '+')) { |
|
48
|
|
|
$useFrom = true; |
|
49
|
|
|
$amount = Str::after($amount, '+'); |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
if (Str::endsWith($amount, '*')) { |
|
53
|
|
|
$offer = Str::after($amount, '*').'*'; |
|
54
|
|
|
$amount = trim(Str::before($amount, '*')); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
$priceText = Price::format((float)$amount, $currency); |
|
58
|
|
|
|
|
59
|
|
|
if ($useFrom) { |
|
60
|
|
|
$priceText = trans('ipro-sync::prices.additional.from', ['price' => $priceText]); |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
if ($offer) { |
|
64
|
|
|
$priceText = trans('ipro-sync::prices.additional.offer.'.$offer, ['price' => $priceText]); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
return [ |
|
68
|
|
|
'text' => $priceText, |
|
69
|
|
|
'hint' => trans('ipro-sync::prices.hints.price'), |
|
70
|
|
|
]; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|