1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use App\Plan; |
4
|
|
|
use App\Member; |
5
|
|
|
use App\Setting; |
6
|
|
|
use App\Sms_log; |
7
|
|
|
use Carbon\Carbon; |
8
|
|
|
use App\Subscription; |
9
|
|
|
use Illuminate\Http\Request; |
|
|
|
|
10
|
|
|
|
11
|
|
|
class Utilities |
12
|
|
|
{ |
13
|
|
|
public static function setActiveMenu($uri, $isParent = false) |
14
|
|
|
{ |
15
|
|
|
$class = ($isParent) ? 'active open' : 'active'; |
16
|
|
|
|
17
|
|
|
return \Request::is($uri) ? $class : ''; |
18
|
|
|
//return \Request::is($uri); |
19
|
|
|
} |
20
|
|
|
|
21
|
|
|
// Get Setting |
22
|
|
|
public static function getSetting($key) |
23
|
|
|
{ |
24
|
|
|
$settingValue = Setting::where('key', '=', $key)->pluck('value'); |
25
|
|
|
|
26
|
|
|
return $settingValue; |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
//get Settings |
30
|
|
|
public static function getSettings() |
31
|
|
|
{ |
32
|
|
|
$settings = Setting::all(); |
33
|
|
|
$settings_array = []; |
34
|
|
|
|
35
|
|
|
foreach ($settings as $setting) { |
36
|
|
|
$settings_array[$setting->key] = $setting->value; |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $settings_array; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
//Follow up Status |
43
|
|
|
public static function getFollowUpStatus($status) |
44
|
|
|
{ |
45
|
|
|
switch ($status) { |
46
|
|
|
case '1': |
47
|
|
|
return 'Done'; |
48
|
|
|
break; |
|
|
|
|
49
|
|
|
|
50
|
|
|
default: |
51
|
|
|
return 'Pending'; |
52
|
|
|
break; |
53
|
|
|
} |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
//Follow up by |
57
|
|
|
public static function getFollowupBy($followUpBy) |
58
|
|
|
{ |
59
|
|
|
switch ($followUpBy) { |
60
|
|
|
case '1': |
61
|
|
|
return 'SMS'; |
62
|
|
|
break; |
|
|
|
|
63
|
|
|
|
64
|
|
|
case '2': |
65
|
|
|
return 'Personal'; |
66
|
|
|
break; |
67
|
|
|
|
68
|
|
|
default: |
69
|
|
|
return 'Call'; |
70
|
|
|
break; |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
//FollowUp Status Icon bg |
75
|
|
|
public static function getIconBg($status) |
76
|
|
|
{ |
77
|
|
|
switch ($status) { |
78
|
|
|
case '1': |
79
|
|
|
return 'bg-blue-400 border-blue-700'; |
80
|
|
|
break; |
|
|
|
|
81
|
|
|
|
82
|
|
|
default: |
83
|
|
|
return 'bg-orange-400 border-orange-700'; |
84
|
|
|
break; |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
//Followup Status Icon |
89
|
|
|
public static function getStatusIcon($status) |
90
|
|
|
{ |
91
|
|
|
switch ($status) { |
92
|
|
|
case '1': |
93
|
|
|
return 'fa fa-thumbs-up'; |
94
|
|
|
break; |
|
|
|
|
95
|
|
|
|
96
|
|
|
default: |
97
|
|
|
return 'fa fa-refresh'; |
98
|
|
|
break; |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
// Aim for member & enquiry creation |
103
|
|
|
public static function getAim($aim) |
104
|
|
|
{ |
105
|
|
|
switch ($aim) { |
106
|
|
|
case '1': |
107
|
|
|
return 'Networking'; |
108
|
|
|
break; |
|
|
|
|
109
|
|
|
|
110
|
|
|
case '2': |
111
|
|
|
return 'Body Building'; |
112
|
|
|
break; |
113
|
|
|
|
114
|
|
|
case '3': |
115
|
|
|
return 'Fatloss'; |
116
|
|
|
break; |
117
|
|
|
|
118
|
|
|
case '4': |
119
|
|
|
return 'Weightgain'; |
120
|
|
|
break; |
121
|
|
|
|
122
|
|
|
case '5': |
123
|
|
|
return 'Others'; |
124
|
|
|
break; |
125
|
|
|
|
126
|
|
|
default: |
127
|
|
|
return 'Fitness'; |
128
|
|
|
break; |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
// Invoice Labels |
133
|
|
|
public static function getInvoiceLabel($status) |
134
|
|
|
{ |
135
|
|
|
switch ($status) { |
136
|
|
|
case '0': |
137
|
|
|
return 'label label-danger'; |
138
|
|
|
break; |
|
|
|
|
139
|
|
|
|
140
|
|
|
case '1': |
141
|
|
|
return 'label label-success'; |
142
|
|
|
break; |
143
|
|
|
|
144
|
|
|
case '3': |
145
|
|
|
return 'label label-default'; |
146
|
|
|
break; |
147
|
|
|
|
148
|
|
|
default: |
149
|
|
|
return 'label label-primary'; |
150
|
|
|
break; |
151
|
|
|
} |
152
|
|
|
} |
153
|
|
|
|
154
|
|
|
// Expense alert repeat |
155
|
|
|
public static function expenseRepeatIntervel($repeat) |
156
|
|
|
{ |
157
|
|
|
switch ($repeat) { |
158
|
|
|
case '0': |
159
|
|
|
return 'Never Repeat'; |
160
|
|
|
break; |
|
|
|
|
161
|
|
|
|
162
|
|
|
case '1': |
163
|
|
|
return 'Every Day'; |
164
|
|
|
break; |
165
|
|
|
|
166
|
|
|
case '2': |
167
|
|
|
return 'Every Week'; |
168
|
|
|
break; |
169
|
|
|
|
170
|
|
|
case '3': |
171
|
|
|
return 'Every Month'; |
172
|
|
|
break; |
173
|
|
|
|
174
|
|
|
default: |
175
|
|
|
return 'Every Year'; |
176
|
|
|
break; |
177
|
|
|
} |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
//Paid Unpaid Labels |
181
|
|
|
public static function getPaidUnpaid($status) |
182
|
|
|
{ |
183
|
|
|
switch ($status) { |
184
|
|
|
case '0': |
185
|
|
|
return 'label label-danger'; |
186
|
|
|
break; |
|
|
|
|
187
|
|
|
|
188
|
|
|
default: |
189
|
|
|
return 'label label-primary'; |
190
|
|
|
break; |
191
|
|
|
} |
192
|
|
|
} |
193
|
|
|
|
194
|
|
|
//Active-Inactive Labels |
195
|
|
|
public static function getActiveInactive($status) |
196
|
|
|
{ |
197
|
|
|
switch ($status) { |
198
|
|
|
case '0': |
199
|
|
|
return 'label label-danger'; |
200
|
|
|
break; |
|
|
|
|
201
|
|
|
|
202
|
|
|
default: |
203
|
|
|
return 'label label-primary'; |
204
|
|
|
break; |
205
|
|
|
} |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
// Occupation of members |
209
|
|
|
public static function getOccupation($occupation) |
210
|
|
|
{ |
211
|
|
|
switch ($occupation) { |
212
|
|
|
case '1': |
213
|
|
|
return 'Housewife'; |
214
|
|
|
break; |
|
|
|
|
215
|
|
|
|
216
|
|
|
case '2': |
217
|
|
|
return 'Self Employed'; |
218
|
|
|
break; |
219
|
|
|
|
220
|
|
|
case '3': |
221
|
|
|
return 'Professional'; |
222
|
|
|
break; |
223
|
|
|
|
224
|
|
|
case '4': |
225
|
|
|
return 'Freelancer'; |
226
|
|
|
break; |
227
|
|
|
|
228
|
|
|
case '5': |
229
|
|
|
return 'Others'; |
230
|
|
|
break; |
231
|
|
|
|
232
|
|
|
default: |
233
|
|
|
return 'Student'; |
234
|
|
|
break; |
235
|
|
|
} |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
// Source for member & enquiry creation |
239
|
|
|
public static function getSource($source) |
240
|
|
|
{ |
241
|
|
|
switch ($source) { |
242
|
|
|
case '1': |
243
|
|
|
return 'Word of mouth'; |
244
|
|
|
break; |
|
|
|
|
245
|
|
|
|
246
|
|
|
case '2': |
247
|
|
|
return 'Others'; |
248
|
|
|
break; |
249
|
|
|
|
250
|
|
|
default: |
251
|
|
|
return 'Promotions'; |
252
|
|
|
break; |
253
|
|
|
} |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
// Member Status |
257
|
|
|
public static function getStatusValue($status) |
258
|
|
|
{ |
259
|
|
|
switch ($status) { |
260
|
|
|
case '0': |
261
|
|
|
return 'Inactive'; |
262
|
|
|
break; |
|
|
|
|
263
|
|
|
|
264
|
|
|
case '2': |
265
|
|
|
return 'Archived'; |
266
|
|
|
break; |
267
|
|
|
|
268
|
|
|
default: |
269
|
|
|
return 'Active'; |
270
|
|
|
break; |
271
|
|
|
} |
272
|
|
|
} |
273
|
|
|
|
274
|
|
|
// Enquiry Status |
275
|
|
|
public static function getEnquiryStatus($status) |
276
|
|
|
{ |
277
|
|
|
switch ($status) { |
278
|
|
|
case '0': |
279
|
|
|
return 'Lost'; |
280
|
|
|
break; |
|
|
|
|
281
|
|
|
|
282
|
|
|
case '2': |
283
|
|
|
return 'Member'; |
284
|
|
|
break; |
285
|
|
|
|
286
|
|
|
default: |
287
|
|
|
return 'Lead'; |
288
|
|
|
break; |
289
|
|
|
} |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
// Enquiry Label |
293
|
|
|
public static function getEnquiryLabel($status) |
294
|
|
|
{ |
295
|
|
|
switch ($status) { |
296
|
|
|
case '0': |
297
|
|
|
return 'label label-danger'; |
298
|
|
|
break; |
|
|
|
|
299
|
|
|
|
300
|
|
|
case '2': |
301
|
|
|
return 'label label-success'; |
302
|
|
|
break; |
303
|
|
|
|
304
|
|
|
default: |
305
|
|
|
return 'label label-primary'; |
306
|
|
|
break; |
307
|
|
|
} |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
// Set invoice status |
311
|
|
|
public static function setInvoiceStatus($amount_due, $invoice_total) |
312
|
|
|
{ |
313
|
|
|
if ($amount_due == 0) { |
314
|
|
|
$paymentStatus = \constPaymentStatus::Paid; |
315
|
|
|
} elseif ($amount_due > 0 && $amount_due < $invoice_total) { |
316
|
|
|
$paymentStatus = \constPaymentStatus::Partial; |
317
|
|
|
} elseif ($amount_due == $invoice_total) { |
318
|
|
|
$paymentStatus = \constPaymentStatus::Unpaid; |
319
|
|
|
} else { |
320
|
|
|
$paymentStatus = \constPaymentStatus::Overpaid; |
321
|
|
|
} |
322
|
|
|
|
323
|
|
|
return $paymentStatus; |
324
|
|
|
} |
325
|
|
|
|
326
|
|
|
// Invoice Status |
327
|
|
|
public static function getInvoiceStatus($status) |
328
|
|
|
{ |
329
|
|
|
switch ($status) { |
330
|
|
|
case '1': |
331
|
|
|
return 'Paid'; |
332
|
|
|
break; |
|
|
|
|
333
|
|
|
|
334
|
|
|
case '2': |
335
|
|
|
return 'Partial'; |
336
|
|
|
break; |
337
|
|
|
|
338
|
|
|
case '3': |
339
|
|
|
return 'Overpaid'; |
340
|
|
|
break; |
341
|
|
|
|
342
|
|
|
default: |
343
|
|
|
return 'Unpaid'; |
344
|
|
|
break; |
345
|
|
|
} |
346
|
|
|
} |
347
|
|
|
|
348
|
|
|
// Subcription Status |
349
|
|
|
public static function getSubscriptionStatus($status) |
350
|
|
|
{ |
351
|
|
|
switch ($status) { |
352
|
|
|
case '0': |
353
|
|
|
return 'Expired'; |
354
|
|
|
break; |
|
|
|
|
355
|
|
|
|
356
|
|
|
case '2': |
357
|
|
|
return 'Renewed'; |
358
|
|
|
break; |
359
|
|
|
|
360
|
|
|
case '3': |
361
|
|
|
return 'Cancelled'; |
362
|
|
|
break; |
363
|
|
|
|
364
|
|
|
default: |
365
|
|
|
return 'OnGoing'; |
366
|
|
|
break; |
367
|
|
|
} |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
// Subcription Label |
371
|
|
|
public static function getSubscriptionLabel($status) |
372
|
|
|
{ |
373
|
|
|
switch ($status) { |
374
|
|
|
case '0': |
375
|
|
|
return 'label label-danger'; |
376
|
|
|
break; |
|
|
|
|
377
|
|
|
|
378
|
|
|
case '2': |
379
|
|
|
return 'label label-success'; |
380
|
|
|
break; |
381
|
|
|
|
382
|
|
|
case '3': |
383
|
|
|
return 'label label-default'; |
384
|
|
|
break; |
385
|
|
|
|
386
|
|
|
default: |
387
|
|
|
return 'label label-primary'; |
388
|
|
|
break; |
389
|
|
|
} |
390
|
|
|
} |
391
|
|
|
|
392
|
|
|
// Payment Mode |
393
|
|
|
public static function getPaymentMode($status) |
394
|
|
|
{ |
395
|
|
|
switch ($status) { |
396
|
|
|
case '0': |
397
|
|
|
return 'Cheque'; |
398
|
|
|
break; |
|
|
|
|
399
|
|
|
|
400
|
|
|
default: |
401
|
|
|
return 'Cash'; |
402
|
|
|
break; |
403
|
|
|
} |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
// Cheque status |
407
|
|
|
public static function getChequeStatus($status) |
408
|
|
|
{ |
409
|
|
|
switch ($status) { |
410
|
|
|
case '1': |
411
|
|
|
return 'Deposited'; |
412
|
|
|
break; |
|
|
|
|
413
|
|
|
|
414
|
|
|
case '2': |
415
|
|
|
return 'Cleared'; |
416
|
|
|
break; |
417
|
|
|
|
418
|
|
|
case '3': |
419
|
|
|
return 'Bounced'; |
420
|
|
|
break; |
421
|
|
|
|
422
|
|
|
case '4': |
423
|
|
|
return 'Reissued'; |
424
|
|
|
break; |
425
|
|
|
|
426
|
|
|
default: |
427
|
|
|
return 'Recieved'; |
428
|
|
|
break; |
429
|
|
|
} |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
// Get Gender |
433
|
|
|
public static function getGender($gender) |
434
|
|
|
{ |
435
|
|
|
switch ($gender) { |
436
|
|
|
case 'm': |
437
|
|
|
return 'Male'; |
438
|
|
|
break; |
|
|
|
|
439
|
|
|
|
440
|
|
|
case 'f': |
441
|
|
|
return 'Female'; |
442
|
|
|
break; |
443
|
|
|
} |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
//Get invoice display name type |
447
|
|
|
public static function getDisplay($display) |
448
|
|
|
{ |
449
|
|
|
switch ($display) { |
450
|
|
|
case 'gym_logo': |
451
|
|
|
return 'Gym Logo'; |
452
|
|
|
break; |
|
|
|
|
453
|
|
|
|
454
|
|
|
default: |
455
|
|
|
return 'Gym Name'; |
456
|
|
|
break; |
457
|
|
|
} |
458
|
|
|
} |
459
|
|
|
|
460
|
|
|
// Get Numbering mode |
461
|
|
|
public static function getMode($mode) |
462
|
|
|
{ |
463
|
|
|
switch ($mode) { |
464
|
|
|
case '0': |
465
|
|
|
return 'Manual'; |
466
|
|
|
break; |
|
|
|
|
467
|
|
|
|
468
|
|
|
default: |
469
|
|
|
return 'Automatic'; |
470
|
|
|
break; |
471
|
|
|
} |
472
|
|
|
} |
473
|
|
|
|
474
|
|
|
public static function getGreeting() |
475
|
|
|
{ |
476
|
|
|
//$time = date("H"); |
477
|
|
|
$time = Carbon::now()->hour; |
478
|
|
|
/* If the time is less than 1200 hours, show good morning */ |
479
|
|
|
if ($time < '12') { |
480
|
|
|
echo 'Good morning'; |
481
|
|
|
} elseif /* If the time is grater than or equal to 1200 hours, but less than 1700 hours, so good afternoon */ |
482
|
|
|
($time >= '12' && $time < '17') { |
483
|
|
|
echo 'Good afternoon'; |
484
|
|
|
} elseif /* Should the time be between or equal to 1700 and 1900 hours, show good evening */ |
485
|
|
|
($time >= '17' && $time < '22') { |
486
|
|
|
echo 'Good evening'; |
487
|
|
|
} elseif /* Finally, show good night if the time is greater than or equal to 2200 hours */ |
488
|
|
|
($time >= '22') { |
489
|
|
|
echo 'Good night'; |
490
|
|
|
} |
491
|
|
|
} |
492
|
|
|
|
493
|
|
|
/** |
494
|
|
|
*File Upload. |
495
|
|
|
**/ |
496
|
|
|
public static function uploadFile(Request $request, $prefix, $recordId, $upload_field, $upload_path) |
|
|
|
|
497
|
|
|
{ |
498
|
|
|
if ($request->hasFile($upload_field)) { |
499
|
|
|
$file = $request->file($upload_field); |
500
|
|
|
|
501
|
|
|
if ($file->isValid()) { |
502
|
|
|
File::delete(public_path('assets/img/gym/gym_logo.jpg')); |
503
|
|
|
$fileName = 'gym_logo.jpg'; |
504
|
|
|
$destinationPath = public_path($upload_path); |
505
|
|
|
$request->file($upload_field)->move($destinationPath, $fileName); |
506
|
|
|
Image::make($destinationPath.'/'.$fileName)->resize(600, null, function ($constraint) { |
507
|
|
|
$constraint->aspectRatio(); |
508
|
|
|
})->save(); |
509
|
|
|
} |
510
|
|
|
} |
511
|
|
|
} |
512
|
|
|
|
513
|
|
|
public static function registrationsTrend() |
514
|
|
|
{ |
515
|
|
|
// Get Financial date |
516
|
|
|
$startDate = new Carbon(Setting::where('key', '=', 'financial_start')->pluck('value')); |
517
|
|
|
$data = []; |
518
|
|
|
|
519
|
|
|
for ($i = 1; $i <= 12; $i++) { |
520
|
|
|
//$members = member::registrations($startDate->month,$startDate->year); // Laravel Scoped Query Issue: Workaroud Needed |
521
|
|
|
$members = Member::whereMonth('created_at', '=', $startDate->month)->whereYear('created_at', '=', $startDate->year)->count(); |
522
|
|
|
$data[] = ['month' => $startDate->format('Y-m'), 'registrations' => $members]; |
523
|
|
|
$startDate->addMonth(); |
524
|
|
|
} |
525
|
|
|
|
526
|
|
|
return json_encode($data); |
527
|
|
|
} |
528
|
|
|
|
529
|
|
|
public static function membersPerPlan() |
530
|
|
|
{ |
531
|
|
|
$data = []; |
532
|
|
|
|
533
|
|
|
$plans = Plan::onlyActive()->get(); |
534
|
|
|
|
535
|
|
|
foreach ($plans as $plan) { |
536
|
|
|
$subscriptions = Subscription::where('status', '=', \constSubscription::onGoing)->where('plan_id', '=', $plan->id)->count(); |
537
|
|
|
$data[] = ['label' =>$plan->plan_name, 'value'=>$subscriptions]; |
538
|
|
|
} |
539
|
|
|
|
540
|
|
|
return json_encode($data); |
541
|
|
|
} |
542
|
|
|
|
543
|
|
|
// Checking logonutility gateway status |
544
|
|
|
public static function smsGatewayStatus() |
545
|
|
|
{ |
546
|
|
|
try { |
547
|
|
|
$api_key = self::getSetting('sms_api_key'); |
548
|
|
|
|
549
|
|
|
$api_url = 'http://logonutility.in/app/miscapi/'.$api_key.'/getBalance/true/'; |
550
|
|
|
|
551
|
|
|
if (self::isDomainAvailible($api_url)) { |
552
|
|
|
return true; |
553
|
|
|
} else { |
554
|
|
|
return false; |
555
|
|
|
} |
556
|
|
|
} catch (Exception $e) { |
557
|
|
|
return false; |
558
|
|
|
} |
559
|
|
|
} |
560
|
|
|
|
561
|
|
|
// returns true, if domain is availible, false if not |
562
|
|
|
public static function isDomainAvailible($domain) |
563
|
|
|
{ |
564
|
|
|
//check, if a valid url is provided |
565
|
|
|
if (! filter_var($domain, FILTER_VALIDATE_URL)) { |
566
|
|
|
return false; |
567
|
|
|
} |
568
|
|
|
|
569
|
|
|
//initialize curl |
570
|
|
|
$curlInit = curl_init($domain); |
571
|
|
|
curl_setopt($curlInit, CURLOPT_CONNECTTIMEOUT, 10); |
572
|
|
|
curl_setopt($curlInit, CURLOPT_HEADER, true); |
573
|
|
|
curl_setopt($curlInit, CURLOPT_NOBODY, true); |
574
|
|
|
curl_setopt($curlInit, CURLOPT_RETURNTRANSFER, true); |
575
|
|
|
|
576
|
|
|
//get answer |
577
|
|
|
$response = curl_exec($curlInit); |
578
|
|
|
|
579
|
|
|
curl_close($curlInit); |
580
|
|
|
|
581
|
|
|
if ($response) { |
582
|
|
|
return true; |
583
|
|
|
} |
584
|
|
|
|
585
|
|
|
return false; |
586
|
|
|
} |
587
|
|
|
|
588
|
|
|
public static function Sms($sender_id, $member_contact, $sms_text, $sms_status) |
589
|
|
|
{ |
590
|
|
|
$sms = self::getSetting('sms'); |
591
|
|
|
$gatewayStatus = self::smsGatewayStatus(); |
592
|
|
|
|
593
|
|
|
if ($sms && $sms_status) { |
594
|
|
|
if ($gatewayStatus) { |
|
|
|
|
595
|
|
|
$api_key = self::getSetting('sms_api_key'); |
596
|
|
|
$contacts = $member_contact; |
597
|
|
|
$from = $sender_id; |
598
|
|
|
$send_sms_text = urlencode($sms_text); |
599
|
|
|
|
600
|
|
|
//Transactional = 20 , Promo with sender id = 21 , only promotional = 18 |
601
|
|
|
$api_url = 'http://www.logonutility.in/app/smsapi/index.php?key='.$api_key.'&campaign=1&routeid=20&type=text&contacts='.$contacts.'&senderid='.$from.'&msg='.$send_sms_text; |
602
|
|
|
|
603
|
|
|
//Submit to server |
604
|
|
|
$response = file_get_contents($api_url); |
605
|
|
|
|
606
|
|
|
if (str_contains($response, 'SMS-SHOOT-ID')) { |
607
|
|
|
//Log entry for SMS_log table |
608
|
|
|
$SmsLogData = ['shoot_id' => substr($response, strpos($response, 'SMS-SHOOT-ID/') + 13), |
609
|
|
|
'number' => $member_contact, |
610
|
|
|
'message' => $sms_text, |
611
|
|
|
'sender_id' => $sender_id, |
612
|
|
|
'send_time' => Carbon::now(), |
613
|
|
|
'status' => 'NA', ]; |
614
|
|
|
|
615
|
|
|
$SmsLog = new Sms_log($SmsLogData); |
616
|
|
|
$SmsLog->save(); |
617
|
|
|
} |
618
|
|
|
//Update SMS balance |
619
|
|
|
self::smsBalance(); |
620
|
|
|
} else { |
621
|
|
|
$SmsLogData = ['shoot_id' => '', |
622
|
|
|
'number' => $member_contact, |
623
|
|
|
'message' => $sms_text, |
624
|
|
|
'sender_id' => $sender_id, |
625
|
|
|
'send_time' => Carbon::now(), |
626
|
|
|
'status' => 'offline', ]; |
627
|
|
|
|
628
|
|
|
$SmsLog = new Sms_log($SmsLogData); |
629
|
|
|
$SmsLog->save(); |
630
|
|
|
} |
631
|
|
|
} |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
public static function retrySms($sender_id, $member_contact, $sms_text, $log) |
635
|
|
|
{ |
636
|
|
|
$gatewayStatus = self::smsGatewayStatus(); |
637
|
|
|
|
638
|
|
|
if ($gatewayStatus) { |
|
|
|
|
639
|
|
|
$api_key = self::getSetting('sms_api_key'); |
640
|
|
|
$contacts = $member_contact; |
641
|
|
|
$from = $sender_id; |
642
|
|
|
$send_sms_text = urlencode($sms_text); |
643
|
|
|
|
644
|
|
|
//Transactional = 20 , Promo with sender id = 21 , only promotional = 18 |
645
|
|
|
$api_url = 'http://www.logonutility.in/app/smsapi/index.php?key='.$api_key.'&campaign=1&routeid=21&type=text&contacts='.$contacts.'&senderid='.$from.'&msg='.$send_sms_text; |
646
|
|
|
|
647
|
|
|
//Submit to server |
648
|
|
|
$response = file_get_contents($api_url); |
649
|
|
|
|
650
|
|
|
if (str_contains($response, 'SMS-SHOOT-ID')) { |
651
|
|
|
//Log entry for SMS_log table |
652
|
|
|
$log->update(['shoot_id' => substr($response, strpos($response, 'SMS-SHOOT-ID/') + 13), |
653
|
|
|
'number' => $member_contact, |
654
|
|
|
'message' => $sms_text, |
655
|
|
|
'sender_id' => $sender_id, |
656
|
|
|
'send_time' => Carbon::now(), |
657
|
|
|
'status' => 'NA', ]); |
658
|
|
|
$log->save(); |
659
|
|
|
} |
660
|
|
|
//Update SMS balance |
661
|
|
|
self::smsBalance(); |
662
|
|
|
} |
663
|
|
|
} |
664
|
|
|
|
665
|
|
|
public static function smsBalance() |
666
|
|
|
{ |
667
|
|
|
$sms = self::getSetting('sms'); |
668
|
|
|
$gatewayStatus = self::smsGatewayStatus(); |
669
|
|
|
|
670
|
|
|
if ($sms && $gatewayStatus) { |
|
|
|
|
671
|
|
|
$api_key = self::getSetting('sms_api_key'); |
672
|
|
|
|
673
|
|
|
$api_url = 'http://logonutility.in/app/miscapi/'.$api_key.'/getBalance/true/'; |
674
|
|
|
|
675
|
|
|
//Submit to server |
676
|
|
|
|
677
|
|
|
$credit_balance = file_get_contents($api_url); |
678
|
|
|
$balance = json_decode($credit_balance); |
679
|
|
|
Setting::where('key', '=', 'sms_balance')->update(['value' => $balance[0]->BALANCE]); |
680
|
|
|
|
681
|
|
|
// If balance turns zero turn off SMS |
682
|
|
|
if ($balance[0]->BALANCE == 0) { |
683
|
|
|
Setting::where('key', '=', 'sms')->update(['value' => 0]); |
684
|
|
|
} |
685
|
|
|
} |
686
|
|
|
} |
687
|
|
|
|
688
|
|
|
public static function smsStatusUpdate() |
689
|
|
|
{ |
690
|
|
|
$sms = self::getSetting('sms'); |
691
|
|
|
$gatewayStatus = self::smsGatewayStatus(); |
692
|
|
|
|
693
|
|
|
if ($sms && $gatewayStatus) { |
|
|
|
|
694
|
|
|
$api_key = self::getSetting('sms_api_key'); |
695
|
|
|
|
696
|
|
|
// Retry Offline Msg |
697
|
|
|
$messages = Sms_log::where('status', 'offline')->get(); |
698
|
|
|
|
699
|
|
|
foreach ($messages as $message) { |
700
|
|
|
self::retrySms($message->sender_id, $message->number, $message->message, $message); |
701
|
|
|
} |
702
|
|
|
|
703
|
|
|
// Update Status |
704
|
|
|
$messages = Sms_log::whereNotIn('status', ['Delivered', 'Failed', 'offline'])->get(); |
705
|
|
|
|
706
|
|
|
foreach ($messages as $message) { |
707
|
|
|
$sms_shoot_id = $message->shoot_id; |
708
|
|
|
$api_url = 'http://logonutility.in/app/miscapi/'.$api_key.'/getDLR/'.$sms_shoot_id; |
709
|
|
|
|
710
|
|
|
//Submit to server |
711
|
|
|
$response = file_get_contents($api_url); |
712
|
|
|
|
713
|
|
|
$dlr_array = json_decode($response); |
714
|
|
|
|
715
|
|
|
//Update Status |
716
|
|
|
$message->status = $dlr_array[0]->DLR; |
717
|
|
|
$message->save(); |
718
|
|
|
} |
719
|
|
|
} |
720
|
|
|
} |
721
|
|
|
} |
722
|
|
|
|
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: