1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Alkoumi\LaravelArabicTafqeet\Helpers; |
4
|
|
|
|
5
|
|
|
trait Calculators |
6
|
|
|
{ |
7
|
|
|
use Digit; |
8
|
|
|
|
9
|
|
|
public function classA($arr, $len = 1) |
10
|
|
|
{ |
11
|
|
|
return $this->ones[$arr[0]]; |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
public function classB($arr, $len = 2) |
15
|
|
|
{ |
16
|
|
|
if ($this->before_comma_len >= 2) { |
17
|
|
|
$ten_number_index = $this->before_comma_len - 2; |
18
|
|
|
$single_number_index = $this->before_comma_len - 1; |
19
|
|
|
$detecd_array = [ |
20
|
|
|
$this->before_comma_array[$ten_number_index], |
21
|
|
|
$this->before_comma_array[$single_number_index], |
22
|
|
|
]; |
23
|
|
|
if ($arr == $detecd_array) { |
24
|
|
|
if ($arr[0] == 0 and $arr[1] >= 1 and $arr[1] <= 10) { |
25
|
|
|
$this->is_main1_currency = true; |
|
|
|
|
26
|
|
|
} elseif ($arr[0] >= 1 and $arr[1] >= 1 and $arr[1] <= 9) { |
27
|
|
|
$this->is_main1_currency = false; |
28
|
|
|
} elseif ($arr[0] >= 2) { |
29
|
|
|
$this->is_main1_currency = false; |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
if ($arr[0] == 0 and $arr[1] == 0) { |
35
|
|
|
return ''; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
if ($arr[0] == 0) { |
39
|
|
|
return $this->ones[$arr[1]]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
if ($arr[0] == 1 and $arr[1] == 1) { |
43
|
|
|
return $this->ones[11]; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
if ($arr[0] == 1 and $arr[1] == 0) { |
47
|
|
|
return $this->ones[10]; |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
if ($arr[1] == 0) { |
51
|
|
|
return $this->tens[$arr[0]]; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
if ($arr[0] > 1) { |
55
|
|
|
return $this->ones[$arr[1]].$this->config['connection_tool'].$this->tens[$arr[0]]; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
if (in_array($arr[1], [1, 2])) { |
59
|
|
|
return $this->others[$arr[1]].' '.$this->tens[$arr[0]]; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return $this->ones[$arr[1]].' '.$this->tens[$arr[0]]; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function classC($arr, $len = 3) |
66
|
|
|
{ |
67
|
|
|
if ($arr[0] == 0 and $arr[1] == 0 and $arr[2] == 0) { |
68
|
|
|
return ''; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($arr[0] == 0 and $arr[1] == 0) { |
72
|
|
|
return $this->ones[$arr[2]]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if ($arr[0] == 0) { |
76
|
|
|
return $this->classB([$arr[1], $arr[2]]); |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
if ($arr[2] == 0 and $arr[1] == 0) { |
80
|
|
|
return $this->hundreds[$arr[0]]; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
if ($arr[1] != 0) { |
84
|
|
|
return $this->hundreds[$arr[0]].$this->config['connection_tool'].$this->classB([$arr[1], $arr[2]]); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
return $this->hundreds[$arr[0]].$this->config['connection_tool'].$this->classA([$arr[2]]); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function classD($arr, $len = 4) |
91
|
|
|
{ |
92
|
|
|
$classC = [$arr[1], $arr[2], $arr[3]]; |
93
|
|
|
|
94
|
|
|
if ($arr[0] <= 2) { |
95
|
|
|
$thousands = $this->thousands[$arr[0]]; |
96
|
|
|
} else { |
97
|
|
|
$thousands = $this->ones[$arr[0]].' '.$this->thousands['39']; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
if ($arr[1] == 0 and $arr[2] == 0 and $arr[3] == 0) { |
101
|
|
|
return $thousands; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return $thousands.$this->config['connection_tool'].$this->classC($classC); |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
public function classE($arr, $len = 5) |
108
|
|
|
{ |
109
|
|
|
$classC = [$arr[2], $arr[3], $arr[4]]; |
110
|
|
|
|
111
|
|
|
if ($arr[0] != 0) { |
112
|
|
|
$conn = ' '; |
113
|
|
|
|
114
|
|
|
if ($arr[1] >= 2 and $arr[0] > 1) { |
115
|
|
|
$conn = $this->config['connection_tool']; |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
if (in_array($arr[1], [2, 1])) { |
119
|
|
|
$thousands = $this->others[$arr[1]].$conn.$this->tens[$arr[0]]; |
120
|
|
|
} else { |
121
|
|
|
$thousands = $this->ones[$arr[1]].$conn.$this->tens[$arr[0]]; |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
if ($arr[1] == 0) { |
125
|
|
|
if ($arr[0] == 1) { |
126
|
|
|
$thousands = $this->ones[10]; |
127
|
|
|
$thousands .= ' '.$this->thousands[39]; |
128
|
|
|
} else { |
129
|
|
|
$thousands = $this->tens[$arr[0]]; |
130
|
|
|
$thousands .= ' '.$this->thousands[1]; |
131
|
|
|
} |
132
|
|
|
} else { |
133
|
|
|
if ($arr[2] == 0 and $arr[3] == 0 and $arr[4] == 0) { |
134
|
|
|
$thousands .= ' '.$this->thousands[1]; |
135
|
|
|
} else { |
136
|
|
|
$thousands .= ' '.$this->thousands[1199]; |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
} else { |
140
|
|
|
if (in_array($arr[1], [2, 1])) { |
141
|
|
|
$thousands = $this->others[$arr[1]].' '; |
142
|
|
|
} else { |
143
|
|
|
$thousands = $this->ones[$arr[1]].' '; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
if ($arr[1] == 0) { |
147
|
|
|
$thousands = $this->tens[$arr[2]]; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
$thousands .= ' '.$this->thousands[39]; |
151
|
|
|
} |
152
|
|
|
if ($this->classC($classC) != '') { |
153
|
|
|
return $thousands.$this->config['connection_tool'].$this->classC($classC); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
return $thousands; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
public function classF($arr, $len = 6) |
160
|
|
|
{ |
161
|
|
|
$classC = [$arr[3], $arr[4], $arr[5]]; |
162
|
|
|
if ($arr[0] != 0) { |
163
|
|
|
if ($arr[1] == 0 && $arr[2] == 0) { |
164
|
|
|
$thousands = $this->hundreds[$arr[0]].' '.$this->thousands[1]; |
165
|
|
|
} else { |
166
|
|
|
if ($arr[1] == 0) { |
167
|
|
|
$thousands = $this->hundreds[$arr[0]].$this->config['connection_tool']. |
168
|
|
|
$this->ones[$arr[2]].' '.$this->thousands[1]; |
169
|
|
|
} elseif ($arr[2] == 0) { |
170
|
|
|
if ($arr[3] == 0 and $arr[4] == 0 and $arr[5] == 0) { |
171
|
|
|
$thousands = $this->hundreds[$arr[0]].$this->config['connection_tool']. |
172
|
|
|
$this->tens[$arr[1]].' '.$this->thousands[1]; |
173
|
|
|
} else { |
174
|
|
|
$thousands = $this->hundreds[$arr[0]].$this->config['connection_tool']. |
175
|
|
|
$this->tens[$arr[1]].' '.$this->thousands[1199]; |
176
|
|
|
} |
177
|
|
|
} else { |
178
|
|
|
// $thousands_lang = $this->thousands[1199]; |
179
|
|
|
if ($arr[1] == 0 and $arr[2] >= 1 and $arr[1] <= 10) { |
180
|
|
|
$thousands_lang = $this->thousands[1]; |
181
|
|
|
} elseif ($arr[1] >= 1 and $arr[2] >= 1 and $arr[1] <= 9) { |
182
|
|
|
$thousands_lang = $this->thousands[1199]; |
183
|
|
|
} elseif ($arr[1] >= 2) { |
184
|
|
|
$thousands_lang = $this->thousands[1199]; |
185
|
|
|
} |
186
|
|
|
|
187
|
|
|
$thousands = $this->classC([$arr[0], $arr[1], $arr[2]], 3).' '.$thousands_lang; |
|
|
|
|
188
|
|
|
} |
189
|
|
|
} |
190
|
|
|
} else { |
191
|
|
|
return $this->classE([$arr[1], $arr[2], $arr[3], $arr[4], $arr[5]]); |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
if ($this->classC($classC) != '') { |
195
|
|
|
return $thousands.$this->config['connection_tool'].$this->classC($classC); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
return $thousands; |
199
|
|
|
} |
200
|
|
|
|
201
|
|
|
public function classG($arr,$len = 7) |
202
|
|
|
{ |
203
|
|
|
//dd($arr,$len); |
204
|
|
|
//$classC = [$arr[2],$arr[4],$arr[5]]; |
205
|
|
|
$classC = [$arr[1],$arr[2],$arr[3]]; |
206
|
|
|
//$classE = [$arr[1],$arr[2],$arr[3],$arr[4],$arr[5],$arr[6]]; |
207
|
|
|
|
208
|
|
|
if($arr[0]<=2) |
209
|
|
|
$million = $this->millions[$arr[0]] ; |
210
|
|
|
else |
211
|
|
|
$million = $this->ones[$arr[0]] . ' ' . $this->millions['39']; |
212
|
|
|
|
213
|
|
|
if($this->classC($classC)!='') |
214
|
|
|
return $million . $this->config['connection_tool'] . $this->classC($classC); |
215
|
|
|
return $million; |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
|
219
|
|
|
// public function classH($arr,$len = 8) |
220
|
|
|
// { |
221
|
|
|
// $classC = [$arr[2],$arr[4],$arr[5]]; |
222
|
|
|
// //$classC = [$arr[1],$arr[2],$arr[3]]; |
223
|
|
|
// $classE = [$arr[1],$arr[2],$arr[3],$arr[4],$arr[5],$arr[6],$arr[7]]; |
224
|
|
|
// |
225
|
|
|
// if($arr[0]<=2) |
226
|
|
|
// $million = $this->millions[$arr[0]] ; |
227
|
|
|
// else |
228
|
|
|
// $million = $this->ones[$arr[0]] . ' ' . $this->millions['39']; |
229
|
|
|
// |
230
|
|
|
// return $million . $this->config['connection_tool'] . $this->classG($classE); |
231
|
|
|
// |
232
|
|
|
// } |
233
|
|
|
public function classH($arr, $len = 8) |
234
|
|
|
{ |
235
|
|
|
$classF = [$arr[2], $arr[3], $arr[4], $arr[5], $arr[6], $arr[7]]; |
236
|
|
|
|
237
|
|
|
if ($arr[0] != 0) { |
238
|
|
|
$conn = ' '; |
239
|
|
|
|
240
|
|
|
if ($arr[1] >= 2 and $arr[0] > 1) { |
241
|
|
|
$conn = $this->config['connection_tool']; |
242
|
|
|
} |
243
|
|
|
|
244
|
|
|
if (in_array($arr[1], [2, 1])) { |
245
|
|
|
$million = $this->others[$arr[1]].$conn.$this->tens[$arr[0]]; |
246
|
|
|
} else { |
247
|
|
|
$million = $this->ones[$arr[1]].$conn.$this->tens[$arr[0]]; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if ($arr[1] == 0) { |
251
|
|
|
if ($arr[0] == 1) { |
252
|
|
|
$million = $this->ones[10]; |
253
|
|
|
$million .= ' '.$this->millions[39]; |
254
|
|
|
} else { |
255
|
|
|
$million = $this->tens[$arr[0]]; |
256
|
|
|
$million .= ' '.$this->millions[1]; |
257
|
|
|
} |
258
|
|
|
} else { |
259
|
|
|
if ($arr[2] == 0 and $arr[3] == 0 and $arr[4] == 0) { |
260
|
|
|
$million .= ' '.$this->millions[1]; |
261
|
|
|
} else { |
262
|
|
|
$million .= ' '.$this->millions[1199]; |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
} else { |
266
|
|
|
if (in_array($arr[1], [2, 1])) { |
267
|
|
|
$million = $this->others[$arr[1]].' '; |
268
|
|
|
} else { |
269
|
|
|
$million = $this->ones[$arr[1]].' '; |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
if ($arr[1] == 0) { |
273
|
|
|
$million = $this->tens[$arr[2]]; |
274
|
|
|
} |
275
|
|
|
|
276
|
|
|
$million .= ' '.$this->millions[39]; |
277
|
|
|
} |
278
|
|
|
// if(in_array($arr[1],[2])) |
279
|
|
|
// $million = $this->others[$arr[1]] . $this->config['connection_tool'] . $this->tens[$arr[0]] ; |
280
|
|
|
// else |
281
|
|
|
// $million = $this->ones[$arr[1]] . $this->config['connection_tool'] . $this->tens[$arr[0]] ; |
282
|
|
|
|
283
|
|
|
//$million = $this->ones[$arr[1]] . $this->config['connection_tool'] . $this->tens[$arr[0]] ; |
284
|
|
|
|
285
|
|
|
// if($arr[1] == 0) |
286
|
|
|
// { |
287
|
|
|
// $million = $this->tens[$arr[0]] ; |
288
|
|
|
// } |
289
|
|
|
|
290
|
|
|
//$million.=' ' . $this->millions[1199]; |
291
|
|
|
|
292
|
|
|
return $million.$this->config['connection_tool'].$this->classF($classF); |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
public function classI($arr, $len = 9) |
296
|
|
|
{ |
297
|
|
|
$classF = [$arr[3], $arr[4], $arr[5], $arr[6], $arr[7], $arr[8]]; |
298
|
|
|
|
299
|
|
|
if (in_array($arr[1], [2])) { |
300
|
|
|
$million = $this->others[$arr[1]].$this->config['connection_tool'].$this->tens[$arr[0]]; |
301
|
|
|
} else { |
302
|
|
|
$million = $this->ones[$arr[1]].$this->config['connection_tool'].$this->tens[$arr[0]]; |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
if ($arr[1] == 0) { |
306
|
|
|
$million = $this->tens[$arr[0]]; |
307
|
|
|
} |
308
|
|
|
|
309
|
|
|
$million .= ' '.$this->millions[1199]; |
310
|
|
|
|
311
|
|
|
return $million.$this->config['connection_tool'].$this->classF($classF); |
312
|
|
|
} |
313
|
|
|
} |
314
|
|
|
|