@php
$contador = 0 ;
@endphp
@foreach($resultado as $res)
@php
// Informando nome para o Status da Chamada
$dispotition = "";
if($res->dstchannel == ""){
$disposition = "Abandonada";
}else{
if($res->disposition == "ANSWERED"){
$disposition = "Atendida";
}elseif($res->disposition == "NO ANSWER"){
$disposition = "Não atendida";
}elseif($res->disposition == "BUSY" && $res->lastdata == 5){
$disposition = "Não Atendida";
} elseif($res->disposition == "BUSY" && $res->lastdata != 5){
$disposition = "Ocupada";
}elseif($res->disposition == "CONGESTION"){
$disposition = "Congestionado";
}else{
$disposition = "Falha";
}
}
// Informando nome para o Tipo de Chamada
if($res->tipo == "OUT"){
$tipo = "Saída";
} elseif($res->tipo == "IN"){
$tipo = "Entrada";
} elseif($res->tipo == "INTRA"){
$tipo = "Interna";
}
// Verificando se existe gravação e informando o nome da mesma
$pabx = "";
$file = "";
$gravacao = "";
if($res->lastapp == "Queue" || $res->lastapp == "Transferred Call"){
$arquivo = $res->userfield;
} else {
$arquivo = $res->gravacao;
}
if(substr($arquivo, 0, 1) == ";"){
$arquivo = substr($arquivo, 1);
}
if($res->servidor == "pabxvirtual02"){
$arquivo = str_replace("monitor", "monitor2", $arquivo);
}
if($res->gravext == "gsm"){
if(file_exists($arquivo.".gsm")){
$file = $arquivo."gsm";
$gravacao = $pabx.$file;
}
} else {
if(file_exists($arquivo.".WAV")){
$file = $arquivo.".WAV";
$gravacao = $pabx.$file;
}
}
// Verificações para exibição do destino
if($res->disposition == "ANSWERED"){
$tarifa = "";
}
if(isset($tarifa)){
$totalmin = $res->billsec;
}
if(substr($res->dstchannel, 0, 5) == "PJSIP" OR substr($res->dstchannel, 0, 5) == "Local"){
$dsp = explode("/", $res->dstchannel);
if($res->tipo == "OUT"){
// dd($res);
$dstchan = $res->dst;
} else {
// dd($res);
if(substr($dsp[1], 0, 5) == "saida"){
if(substr($res->channel, 0, 5) == "PJSIP"){
$ramalstring = explode("/", $res->channel);
$ramalstring2 = explode("-", $ramalstring[1]);
if($ramalstring2[0] == "ws2falemaisnouser"){
$last = explode("/", $res->lastdata);
$last2 = explode("/", $last[2]);
$dstchan = $last2[0];
} else {
$ramal2 = DB::table('pabxvirtual_sip_devices')->where('name', '=', $ramalstring2[0])->first();
$dstchan = $ramal2->alias_name . " <". $ramal2->alias.">";
}
}else {
$dstchan = $res->dst;
}
} else {
$dsp2 = explode("-", $dsp[1]);
$ramal = DB::table('pabxvirtual_sip_devices')->where('name', '=', $dsp2[0])->first();
if($ramal){
$dstchan = $ramal->alias_name . " <".$ramal->alias. ">";
}
}
}
} elseif($res->lastapp == "Read"){
$dstchan = "";
} else {
// $dstchan = $res->dstchannel;
$dstchan = $res->dst;
}
$dstchan = "";
// Calculando o tempo da chamada
if($res->billsec >= 3600){
$hr = str_pad(floor(($res->billsec/60)/60),2, "0", STR_PAD_LEFT);
$min = str_pad(floor(($res->billsec-(3600*$hr))/60),2, "0", STR_PAD_LEFT);
$sec = str_pad(floor(($res->billsec-(3600*$hr))%60),2, "0", STR_PAD_LEFT);
} else {
$hr = "00";
if($res->billsec >= 60){
$min = str_pad(floor($res->billsec/60),2, "0", STR_PAD_LEFT);
$sec = str_pad(floor($res->billsec%60),2, "0", STR_PAD_LEFT);
} else {
$min = "00";
$sec = str_pad($res->billsec,2, "0", STR_PAD_LEFT);
}
}
$tempo = $hr.":". $min. ":" . $sec;
//Verificando a Origem
$ramalchannel = explode("/", $res->channel);
if($ramalchannel[0] == "Local"){
$ramalchannel1 = explode('@', $ramalchannel[1]);
$ramalcerto = $ramalchannel1[0];
} elseif($ramalchannel[0] == "PJSIP") {
$ramalchannel1 = explode('-', $ramalchannel[1]);
$ramalcerto = $ramalchannel1[0];
} else {
$ramalcerto = substr($ramalchannel[0], 4);
}
$ramal3 = DB::table('pabxvirtual_sip_devices')->where('name', '=', $ramalcerto)->select('alias_name', 'name', 'alias')->first();
if($res->tipo == "IN"){
$src2 = $res->src;
} elseif($res->tipo == "OUT") {
if(isset($ramal3->alias_name)){
$src2 = $ramal3->alias_name . " <".$ramal3->alias. ">";;
} else {
$src1 = explode("-", $res->channel);
$src1_1 = substr($src1[0], 4);
$id = auth()->user()->id;
$count = strlen($id);
$src2 = substr($src1_1, $count);
}
} else {
$ramal4 = DB::table('pabxvirtual_sip_devices')->where('name', '=', $res->src)->select('alias_name', 'name', 'alias')->first();
if(isset($ramal4->alias_name)){
$src2 = $ramal4->alias_name . " <".$ramal4->alias. ">";;
} else {
$ramal5 = DB::table('pabxvirtual_sip_devices')->where('alias', '=', $res->src)->select('alias_name', 'name', 'alias')->first();
if(isset($ramal5->alias_name)){
$src2 = $ramal5->alias_name . " <".$ramal5->alias. ">";;
} else {
$src2 = $res->src;
}
}
}
@endphp
@php
$dados[$contador] = [
'data' => date('d-m-Y H:i:s', strtotime($res->calldate)) ,
'bina' => $src2 ,
'origem' => $src2 ,
'did' => $res->did,
'destino' => $dstchan,
'duracao' => $tempo,
'status' => $disposition,
'file' => $file,
'pincode' => $gravacao,
];
$contador ++;
@endphp
@endforeach
Data / Hora |
Bina |
Origem |
DID |
Destino |
Duração |
Status |
Tipo |
Gravação |
Pincode |
{{ date('d-m-Y H:i:s', strtotime($res->calldate))}} |
{{ $src2 }} |
{{ $src2}} |
{{ $res->did }} |
{{ $dstchan }} |
{{ $tempo }} |
{{ $disposition }}
|
@if(isset($tipo))
{{ $tipo }}
@endif
|
@if($gravacao != "")
@endif
|
{{ $res->pinDesc }} |