AutodialController_28062018.php
4.18 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
<?php namespace App\Http\Controllers;
use Auth;
use Input;
use Response;
use App\Models\Group;
use App\Models\Master;
use App\Models\Record;
use App\Models\CRMCall;
use App\Models\CRMCallArchive;
use App\Models\CRM;
use App\Models\CRMCampaign;
use App\Models\CRMList;
use App\Jobs\KHRMSLib;
use App\Models\Sipid;
use App\Models\Dialline;
use App\Models\UserLog;
use App\Models\User;
use App\Models\Kqueue;
use App\Models\QCFeedback;
use DB;
use Log;
use Session;
$client='';
class AutodialController extends Controller {
public function index()
{
}
public function create()
{
}
public function store()
{
}
public function show($id)
{
if($id=="autodialmode")
{
$campaign=Input::get("client");
$sipip=env('app_ip');
$wakka = new KHRMSLib();
for($i=0;$i<10;$i++)
{
usleep(2000*1000);
//echo "prashant----".Auth::user()->id;
$dialmode = DB::table('users')->where('id','=',Auth::user()->id)->first();
//echo $dialmode->current_dialmode;
if($dialmode->current_dialmode!="Predictive")
{
break;
exit;
}
$autocompany=array();
$companyarr=$wakka->LoadAll("select * from hrms_masters where mtype='company' and mkey='$campaign'");
foreach($companyarr as $tcompany)
{
$mastersdata=$wakka->getCompanyMaster($tcompany['mkey']);
if(!isset($mastersdata["autodialercampaign"]))$mastersdata["autodialercampaign"]=0;
if($mastersdata["autodialercampaign"]>0)
{
$autocompany[$tcompany['mkey']]=$mastersdata;
}
}
foreach($autocompany as $tcompany=>$mastersdata)
{
$asipids=Sipid::where('server','=',$sipip)->where("status","=","1")->where("ready","=","1")->where("clients","like","%$tcompany%")->count();
if($asipids>0)
{
$acalls=($asipids*$mastersdata["autodialercampaign"])-Dialline::where('server','=',$this->sipip)->whereIn("status",array("AutoCall","Auto"))->where("conf","=","")->where("regexstr","=",$tcompany)->count();
if($acalls>0)
{
for($i=0;$i<$acalls;$i++)
{
$callerid="";
if(!empty($mastersdata["DialerDID"]))
$callerid=$mastersdata["DialerDID"];
$calleridarr=explode(":",$callerid);$dspan="1";
if(isset($calleridarr[1]))
{
$callerid=$calleridarr[0];$dspan=$calleridarr[1];
}
$dialline=Dialline::where('server','=', $sipip)->where("status","=","Free")->where("enabled","=","1");
if($dspan!="")$dialline=$dialline->where('dspan','=',$dspan);
$dialline=$dialline->orderBy('updated_at','ASC')->first();
if($dialline)
{
$users=$wakka->getPersons("client='$campaign' and status='New' limit 1");
if(sizeof($users)>=1)
{
$dialline->status="Free";
$dialline->regexstr=$users[0]['client'];
$dialline->save();
$nowts=microtime(true)*1000;
//start the call log
$crmcall=new CRMCall();
$crmcall->number=$users[0]["mobile"];
$crmcall->user_id=0;
$crmcall->sipid_id=0;
$crmcall->crm_id=$users[0]['id'];
$crmcall->lan=$users[0]['lan'];
$crmcall->client=$users[0]['client'];
$crmcall->department=$users[0]['department'];
$crmcall->state='New';
$crmcall->type="AutoCall";
$crmcall->dialline_id=$dialline->id;
$crmcall->setTs('ts_Wait',$nowts);
$crmcall->setTs('ts_Call',$nowts);
$crmcall->did=$callerid;
$tdata=array();
$crmcall->data=json_encode($tdata);
$crmcall->save();
//start actual calls
$newqueue=new Kqueue();
$newqueue->autoCallOut($users[0]["mobile"],$callerid,$crmcall,$dialline);
}
DB::update("update records set status='AutoDial' where id='".$users[0]["id"]."'");
}
else break;
}
}
}
}
}
}
}
}