AutodialController.php
6.13 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
<?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");
$user_id = Auth::user()->id;
$callsToDialled = $this->getCallsToBeDialled($campaign);
if($callsToDialled>0)
{
$this->createCall($campaign, $callsToDialled, $user_id);
}
}
}
public function getCallsToBeDialled($campaign)
{
$wakka = new KHRMSLib();
$mastersdata=$wakka->getCompanyMaster($campaign);
$ratio = $mastersdata["autodialercampaign"];
$availableUsers = $this->getFreeUserCnt($campaign);
$dialedCalls = $this->getDialedCallCount($campaign);
return $availableUsers*$ratio-$dialedCalls;
}
//To Get Number Of Free User which will be multiplied with Defined Ratio For Generating Number Of Calls
public function getFreeUserCnt($campaign)
{
$count=0;
$loggedInSips = Sipid::where('server','=',env('app_ip'))->where("user", "!=", 0)->where("status","=","1")->where("prepare_call","=","1")->where("clients","like","%$campaign%")->groupBy('user')->get();
if(count($loggedInSips))
foreach ($loggedInSips as $key => $loggedInSip)
{
$loggedInUsers[] = $loggedInSip->user;
}
$freeDials = Dialline::whereIn("user_id",$loggedInUsers)->where("status","=","Blocked")->count();
return count($loggedInSips)-$freeDials;
}
public function getDialedCallCount($campaign)
{
$wakka = new KHRMSLib();
$mastersdata=$wakka->getCompanyMaster($campaign);
if($mastersdata["blendedCalling"] == 1)
{
$cnt = Dialline::whereIn("status", ["Auto","AutoCall","Inbound"])->where("conf","=","")->where("regexstr","=",$campaign)->count();
}
else
{
$cnt = Dialline::whereIn("status", ["Auto","AutoCall"])->where("conf","=","")->where("regexstr","=",$campaign)->count();
}
return $cnt;
}
public function getAvailCallInPool($campaign)
{
//$cnt = CRMCall::where("client", "=", $campaign)->where("state","=","DialEnd")->where("type", "=", "Auto")->where("substatus","!=","")->count();
$cnt = Dialline::where("status","=","Auto")->where("conf","=","")->where("regexstr","=",$campaign)->count();
return $cnt;
}
public function getAvgTimeArray($user)
{
$avgdisposecObj = CRMCall::select(DB::Raw('(avg(disposec))/1000 as avgdisposec'))->where("user_id", "=", $user)->orderby("id","desc")->limit(50)->where("type","!=","Inbound")->first();
$avgcallsecObj = CRMCall::select(DB::Raw('(avg(callsec))/1000 as avgcallsec'))->where("user_id", "=", $user)->orderby("id","desc")->limit(50)->where("type","!=","Inbound")->first();
$returnArray['avgdisposec'] = round($avgdisposecObj->avgdisposec);
$returnArray['avgcallsec'] = round($avgdisposecObj->avgcallsec);
return $returnArray;
}
public function createCall($campaign, $acalls, $user_id)
{
$wakka = new KHRMSLib();
$mastersdata=$wakka->getCompanyMaster($campaign);
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','=', env('app_ip'))->where("status","=","Free")->where("enabled","=","1");
if($dspan!="")$dialline=$dialline->where('dspan','=',$dspan)->where('id','<=','30');
$dialline=$dialline->orderBy('updated_at','ASC')->first();
if(empty($dialline))
{
$dialline=Dialline::where('server','=', env('app_ip'))->where("status","=","Free")->where("enabled","=","1");
if($dspan!="")$dialline=$dialline->where('dspan','=', "2")->where('id','>','30');
$dialline=$dialline->orderBy('id','ASC')->first();
}
if($dialline)
{
//$users=$wakka->getPersons("client='$campaign' and status='New' and currentstatus = 'Active' and mobile!='' limit 1");
//Code for DNC check
// $users=$wakka->getPersons("client='$campaign' and status='New' and mobile!='' and mobile NOT IN (select phone_number from flexydial_dnc) AND mobile NOT IN (select phone_number from flexydial_campaign_dnc where campaign='$client') limit 1");
$users=app('App\Http\Controllers\DialerController')->getCallSequencing(1);
if(sizeof($users)>=1)
{
$record=$wakka->getPerson($users[0]['id']);
if($record)
{
$record["peopledata"]["status"]="AutoCall";
$wakka->setPerson($users[0]['id'],$record);
}
$dialline->user_id=$user_id;
$dialline->status="AutoCall";
$dialline->regexstr=$users[0]['client'];
$dialline->number=$users[0]["mobile"];
$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->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);
}
}
else break;
}
}
//return 1;
}
}