SettingsHelper = new SettingsHelper();
}
public function index(Request $request){
$conds = $this->SettingsHelper->defaultConds();
if($request->has('daterange')){
$range = explode(' - ',$request->daterange);
$filter_from = new Carbon($range[0]);
$conds['from'] = $filter_from->format('Y-m-d 00:00:00');
$filter_to = new Carbon($range[1]);
$conds['to'] = $filter_to->format('Y-m-d 23:59:59');
}
if ($request->ajax()) {
$data = DB::table(config('database.connections.mysql.database').'.voicemails')
->select('id','phone_number',
'call_date',
'source',
'duration',
'record', 'isDone','done_by'
)->whereNull('deleted_at')
->whereBetween('call_date',[$conds['from'],$conds['to']]);
return Datatables::of($data)
->addIndexColumn()
->addColumn('action', function($record){
$display_url = route('reporting.voicemail.listen.page', ['id' => $record->id]);
if($record->isDone){
$btn = 'Listen';
}else{
$btn = 'Listen';
}
return $btn;
})
->editColumn('call_date', function($row) {
return date('Y-m-d h:i:s A',strtotime($row->call_date));
})
->addColumn('done', function($row){
if ($row->done_by === null) {
$btn = 'Done';
} else {
$user = User::find($row->done_by);
if ($user) {
$btn = 'Done by '.$user->name.'';
} else {
$btn = 'Done';
}
}
return $btn;
})
->rawColumns(['action','done'])
->make(true);
}
$view = view('reporting::voiceMail');
$filter_area = view('reporting::widgets.filter_area');
$filter_area->with('conds',$conds);
$filter_area->with('submit_route',route('reporting.voiceMail'));
$view->with('filter_area',$filter_area);
$view->with('conds',$conds);
return $view;
}
public function listenVoicemail($id) {
$record = DB::table('voicemails')->where('id', $id)->first();
if (!$record) {
abort(404);
}
$file_path = '/var/spool/asterisk/voicemail/default/1000/processed/' . $record->record;
if (!file_exists($file_path)) {
abort(404);
}
return response()->file($file_path);
}
public function listenPageVoicemail($id) {
$record = DB::table('voicemails')->where('id', $id)->first();
if (!$record) {
abort(404);
}
$file_path = '/var/spool/asterisk/voicemail/default/1000/processed/' . $record->record;
if (!file_exists($file_path)) {
abort(404);
}
$view = view('reporting::playVoicemail');
$view->with('record_id', $id);
$view->with('record_name', $record->record);
return $view;
}
function voiceMailDone($id) {
try {
DB::update("update voicemails set isDone = 1 where id = $id");
return true;
} catch (\Throwable $th) {
throw $th;
}
}
function Done($id) {
try {
$userId = Auth::id();
DB::update("update voicemails set done_by = ? where id = ?", [$userId, $id]);
return true;
} catch (\Throwable $th) {
throw $th;
}
}
}