forked from BackCheck/backcheck.io.verify
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_status.php
More file actions
501 lines (348 loc) · 19.8 KB
/
client_status.php
File metadata and controls
501 lines (348 loc) · 19.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
<?php include("include/config.php");
if($_GET['upd']==1){
$bccEmails = "cfo@backcheckgroup.com,ceo@backcheckgroup.com,erum@backcheckgroup.com";
$before_3_days='before_3_days';
$on_due_date='on_due_date';
$next_3_days='next_3_days';
$after_7_days='after_7_days';
$after_8_days='after_8_days';
$general='general';
$selInvoice = $db->select("ver_checks","DISTINCT(invoice_number)"," invoice_number <> '' AND invoiced=1 ORDER BY invoiced_date DESC ");
if(mysql_num_rows($selInvoice)>0){
$index = 0;
while($re = mysql_fetch_array($selInvoice)) {
$cols = " co.name as com_name , co.email as com_email , co.pname as com_person_name, co.disabled_id as com_status, co.id as com_id, co.pymterm, invoiced_date,invoice_number, vc.paid as paid_status";
$tbls = "ver_checks vc INNER JOIN ver_data vd ON vc.v_id=vd.v_id INNER JOIN company co ON vd.com_id=co.id";
$whre = " invoice_number='".$re['invoice_number']."' ";
$sel = $db->select($tbls,$cols,"$whre");
$rs = mysql_fetch_assoc($sel);
$invoiced_date = date("Y-M-d",strtotime($rs['invoiced_date']));
preg_match('/(\d+)/', $rs['pymterm'], $m);
$pymterm = ($m[1]!="")?(int)$m[1]:30;
$dueDate = date("Y-M-d",strtotime($rs['invoiced_date'] . "+$pymterm day"));
$now = strtotime(date("Y-M-d")); // or your date as well
$your_date = strtotime($dueDate);
$datediff = $your_date-$now;
$datediff = floor($datediff/(60*60*24));
// 3 days reminder
if($datediff==3 && $rs['paid_status']==0){
$inv_num = $rs['invoice_number'];
$inv_amount = getInvoiceAmount($rs['invoice_number']);
$email_subject = "The Invoice # $inv_num about to overdue soon";
$email_Heading = "3 days remaining to settle your invoice # $inv_num";
$com_name = $rs['com_name'];
$userCols = "email, CONCAT(first_name ,' ', last_name) as full_name";
$userWhr = "com_id=$rs[com_id] AND level_id=4 AND is_active=1";
$selUsers = $db->select("users",$userCols,$userWhr);
if(mysql_num_rows($selUsers)>0){
while($rsUsers = mysql_fetch_assoc($selUsers)){
$fullName = ($rsUsers['full_name']!="")?$rsUsers['full_name']:getUsernameFromEmail($rsUsers['email']);
$UserEmail = strtolower($rsUsers['email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>3 Days before overdue.</h2> com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}else{
$fullName = ($rs['com_person_name']!="")?$rs['com_person_name']:getUsernameFromEmail($rs['com_email']);
$UserEmail = strtolower($rs['com_email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>10 Days before overdue.</h2> com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}
// On Due Date
if($datediff==0 && $rs['paid_status']==0){
$inv_num = $rs['invoice_number'];
$inv_amount = getInvoiceAmount($rs['invoice_number']);
$email_subject = "The Invoice # $inv_num is overdue today";
$email_Heading = "Today is the last day to pay your invoice # $inv_num";
$com_name = $rs['com_name'];
$userCols = "email, CONCAT(first_name ,' ', last_name) as full_name";
$userWhr = "com_id=$rs[com_id] AND level_id=4 AND is_active=1";
$selUsers = $db->select("users",$userCols,$userWhr);
if(mysql_num_rows($selUsers)>0){
while($rsUsers = mysql_fetch_assoc($selUsers)){
$fullName = ($rsUsers['full_name']!="")?$rsUsers['full_name']:getUsernameFromEmail($rsUsers['email']);
$UserEmail = strtolower($rsUsers['email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>On Due Day overdue.</h2>com_id=: '.$rs[com_id].' com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}else{
$fullName = ($rs['com_person_name']!="")?$rs['com_person_name']:getUsernameFromEmail($rs['com_email']);
$UserEmail = strtolower($rs['com_email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>On Due day overdue.</h2>com_id=: '.$rs[com_id].' com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}
// Next 3 days
if($datediff > 0 && $datediff <= 3 && $rs['paid_status']==0){
$inv_num = $rs['invoice_number'];
$inv_amount = getInvoiceAmount($rs['invoice_number']);
$email_subject = "The Invoice # $inv_num is overdue";
$email_Heading = "Your Invoice is overdue please pay the invoice # $inv_num to continue using our services ";
$com_name = $rs['com_name'];
$userCols = "email, CONCAT(first_name ,' ', last_name) as full_name";
$userWhr = "com_id=$rs[com_id] AND level_id=4 AND is_active=1";
$selUsers = $db->select("users",$userCols,$userWhr);
if(mysql_num_rows($selUsers)>0){
while($rsUsers = mysql_fetch_assoc($selUsers)){
$fullName = ($rsUsers['full_name']!="")?$rsUsers['full_name']:getUsernameFromEmail($rsUsers['email']);
$UserEmail = strtolower($rsUsers['email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>Next 3 days.</h2>com_id=: '.$rs[com_id].' com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}else{
$fullName = ($rs['com_person_name']!="")?$rs['com_person_name']:getUsernameFromEmail($rs['com_email']);
$UserEmail = strtolower($rs['com_email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>1 Day before overdue.</h2>com_id=: '.$rs[com_id].' com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}
// 7th day System Suspension Notice
if($datediff=='-7' && $rs['paid_status']==0 && $rs['com_status']==0){
$suspendDate = date("Y-M-d",strtotime(date("Y-M-d") . "+1 day"));
$inv_num = $rs['invoice_number'];
$inv_amount = getInvoiceAmount($rs['invoice_number']);
$email_subject = "Require your attention for invoice # $inv_num ";
$email_Heading = "<span style='color:#ff0000;'>Your account will be suspended due to non payment on $suspendDate</span>";
$com_name = $rs['com_name'];
$userCols = "email, CONCAT(first_name ,' ', last_name) as full_name";
$userWhr = "com_id=$rs[com_id] AND level_id=4 AND is_active=1";
$selUsers = $db->select("users",$userCols,$userWhr);
if(mysql_num_rows($selUsers)>0){
while($rsUsers = mysql_fetch_assoc($selUsers)){
$fullName = ($rsUsers['full_name']!="")?$rsUsers['full_name']:getUsernameFromEmail($rsUsers['email']);
$UserEmail = $rsUsers['email'];
$dueDate = "<span style='color:#ff0000;'>".$dueDate."</span>";
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>7th day</h2> com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}else{
$fullName = ($rs['com_person_name']!="")?$rs['com_person_name']:getUsernameFromEmail($rs['com_email']);
$UserEmail = strtolower($rs['com_email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>7th day</h2> com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
// disable the client
}
// 8th day System Suspension Notice
if($datediff=='-8' && $rs['paid_status']==0 && $rs['com_status']==0){
$inv_num = $rs['invoice_number'];
$inv_amount = getInvoiceAmount($rs['invoice_number']);
$email_subject = "Account suspended due to non payment invoice";
$email_Heading = "<span style='color:#ff0000;'>Sorry to inform you that your account has been suspended due to non payment. <br> Please pay your pending invoice to continue using Background Check Services.</span>";
$com_name = $rs['com_name'];
$userCols = "email, CONCAT(first_name ,' ', last_name) as full_name";
$userWhr = "com_id=$rs[com_id] AND level_id=4 AND is_active=1";
$selUsers = $db->select("users",$userCols,$userWhr);
if(mysql_num_rows($selUsers)>0){
while($rsUsers = mysql_fetch_assoc($selUsers)){
$fullName = ($rsUsers['full_name']!="")?$rsUsers['full_name']:getUsernameFromEmail($rsUsers['email']);
$UserEmail = $rsUsers['email'];
$dueDate = "<span style='color:#ff0000;'>".$dueDate."</span>";
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>8th day</h2> com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
}else{
$fullName = ($rs['com_person_name']!="")?$rs['com_person_name']:getUsernameFromEmail($rs['com_email']);
$UserEmail = strtolower($rs['com_email']);
$emailTxt = getRemindingContent($fullName,$inv_num,$invoiced_date,$dueDate,$inv_amount,$general);
$data_table = getInvoiceEmailTemplate($com_name,$emailTxt);
echo '<h2>8th day </h2> com_name: '.$com_name.' fullName: '.$fullName.' UserEmail:'.$UserEmail.'<br><br> emailTxt: '.$emailTxt.' <br><br><br>';
emailTmp( $data_table, $email_subject,'khalique@xcluesiv.com','',$bccEmails,'','','no',$email_Heading);
//emailTmp( $data_table, $email_subject,'ceo@backcheckgroup.com','',$bccEmails,'','','no',$email_Heading);
}
// disable the client
//enableDisableClient($rs['com_id'],1);
}
echo "<br><br>";
$index = $index+1;
//sleep(5);
}
}
}
function getInvoiceEmailTemplate($com_name,$emailTxt){
$body ='<table width="100%" border="1" style="border-collapse: collapse; border:1px solid #cccccc; border-color: #cccccc;">
<tr>
<td align="center" width="100%" colspan="7" style="border:none;"> </td>
</tr>
<tr>
<td align="center" width="100%" colspan="7" style="border:none;"><h2 style="color:#465059; padding:20px 0 0 0; margin:0;">'.$com_name.'</h2></td>
</tr>
<tr>
<td align="center" width="100%" colspan="7" style="border:none;"> </td>
</tr>
<tr>
<td align="left" width="100%" colspan="7" style="border:none;padding:10px;">'.$emailTxt.'</td>
</tr>
<tr>
<td align="center" width="100%" colspan="7" style="border:none;"> </td>
</tr>
<tr>
<td align="center" width="100%" colspan="7" style="border:none;"> </td>
</tr>
</table>';
return $body;
}
function getRemindingContent($ClientName,$inv_num,$inv_date,$inv_due_date,$inv_amount=0,$days=""){
$Content="";
if($days=='before_3_days'){
$Content = '<table width="100%" border="0" cellpadding="10" style="">
<tr>
<td align="" width="100%" colspan="" >Dear '.$ClientName.',</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >We thank and appreciate for doing business with us.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >This is a friendly reminder to let you know that the following invoice number will be due for payment on <strong>'.$inv_due_date.'</strong>. Should you have any query about this invoice, please contact us as soon as possible.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Number : '.$inv_num.'
</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Date : '.$inv_date.'
</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Due Date : '.$inv_due_date.'</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" >We would appreciate receiving of our payment within due date. Hope to continue our services and further strengthen of our congenial business relationship in future.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >
<br />Best Regards
<br />Client Relations
<br />Background Check Group
</td>
</tr>
</table>';
}
if($days=='after_7_days'){
$Content = '<table width="100%" border="0" cellpadding="10" style="">
<tr>
<td align="" width="100%" colspan="" >Dear '.$ClientName.',</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >We write to inform you that we have not yet received payment against the following invoice(s). We realize you must have been busy and therefore overlooked it.By sending this email may we ask you to expedite this matter and clearance of our payment at the earliest. If you have already sent the payment, please ignore this message. </td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Number : '.$inv_num.'
</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Date : '.$inv_date.'</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" >We remind you again and again just to make our services available to you 24/7, which will be difficult for us to continue if your invoice(s) remain unpaid after 10 days of due date, because your portal access will automatically blocked due to the policy implemented by the invoicing system. </td>
</tr>
<tr>
<td align="" width="100%" colspan="" >Thank you for your support and doing business with us . We assure you our best services at all times.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><br />Best Regards</td>
</tr>
</table>';
}
if($days=='on_due_date'){
$Content = '<table width="100%" border="0" cellpadding="10" style="">
<tr>
<td align="" width="100%" colspan="" >Dear '.$ClientName.',</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >This is a friendly reminder to let you know that following invoice is due today for payment. If you have already sent the payment, please ignore this message. If not, we would appreciate your prompt attention to this matter.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Number : '.$inv_num.'</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Date : '.$inv_date.'</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" >Thank you for doing business with us.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><br />Best Regards</td>
</tr>
</table>';
}
if($days=='general'){
$Content = '<table width="100%" border="0" cellpadding="10" style="">
<tr>
<td align="" width="100%" colspan="" >Dear '.$ClientName.',</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >This is a friendly reminder to let you know that following invoice is due for payment. If you have already sent the payment, please ignore this message. If not, we would appreciate your prompt attention to this matter.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Number : '.$inv_num.'
</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Date : '.$inv_date.'
</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" ><strong>Invoice Due Date : '.$inv_due_date.'</strong></td>
</tr>
<tr>
<td align="" width="100%" colspan="" >Thank you for doing business with us.</td>
</tr>
<tr>
<td align="" width="100%" colspan="" >
<br />Best Regards,
<br /><br />Client Relations
<br />Background Check Group
</td>
</tr>
</table>';
}
return $Content;
}
function getInvoiceAmount($inv_num){
global $db;
$selAmount = $db->select("invoice_total_amount","total_amount"," invoice_number ='$inv_num' ");
if(mysql_num_rows($selAmount)>0){
$rsAmount = mysql_fetch_assoc($selAmount);
return $rsAmount['total_amount'];
}else{
return 0;
}
}
function getUsernameFromEmail($email=""){
if($email!=""){
$parts = explode("@", $email);
$username = ucfirst($parts[0]);
return $username;
}else{
return "Client";
}
}
?>