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