'calls.subject',
// 'label' => trans('calls::calls.form.subject'),
// 'type' => 'string',
// ],
[
'id' => 'calls.phone_number',
'label' => trans('calls::calls.form.phone_number'),
'type' => 'string',
],
[
'id' => 'accounts.name',
'label' => trans('calls::calls.form.account_name'),
'type' => 'string',
],
[
'id' => 'deals.name',
'label' => trans('calls::calls.form.deal_name'),
'type' => 'string',
],
[
'id' => 'contacts.full_name',
'label' => trans('calls::calls.form.contact_name'),
'type' => 'string',
],
[
'id' => 'leads.full_name',
'label' => trans('calls::calls.form.lead_name'),
'type' => 'string',
],
[
'id' => 'calls.duration',
'label' => trans('calls::calls.form.duration'),
'type' => 'string',
],
[
'id' => 'calls.talktime',
'label' => trans('calls::calls.form.talktime'),
'type' => 'string',
],
[
'id' => 'calls.notes',
'label' => trans('calls::calls.form.notes'),
'type' => 'string',
],
[
'id' => 'calls.call_date',
'label' => trans('calls::calls.form.call_date'),
'type' => 'date',
'input_event' => 'dp.change',
'plugin' => 'datetimepicker',
'plugin_config' => [
'locale' => app()->getLocale(),
'calendarWeeks' => true,
'showClear' => true,
'showTodayButton' => true,
'showClose' => true,
'format' => \Modules\Platform\Core\Helper\UserHelper::userJsDateFormat()
]
],
[
'id' => 'calls.direction_id',
'label' => trans('calls::calls.form.direction_id'),
'type' => 'integer',
'input' => 'select',
'multiple' => true,
'plugin' => 'select2',
'plugin_config' => [
'multiple' => 'multiple',
'width' => '300px',
],
'values' => DirectionType::pluck('name', 'id'),
'operators' => [
'in',
'not_in',
'is_null',
'is_not_null'
]
],
[
'id' => 'calls.status_id',
'label' => trans('calls::calls.form.status_id'),
'type' => 'integer',
'input' => 'select',
'multiple' => true,
'plugin' => 'select2',
'plugin_config' => [
'multiple' => 'multiple',
'width' => '300px',
],
'values' => CallStatus::pluck('name', 'id'),
'operators' => [
'in',
'not_in',
'is_null',
'is_not_null'
]
],
];
}
public static function availableColumns()
{
return [
// 'subject' => [
// 'data' => 'subject',
// 'title' => trans('calls::calls.form.subject'),
// 'data_type' => 'text',
// 'filter_type' => 'text'
// ],
'direction' => [
'name' => 'calls_dict_direction.name',
'data' => 'direction',
'title' => trans('calls::calls.form.direction'),
'data_type' => 'text',
'filter_type' => 'text'
],
'status' => [
'name' => 'calls_dict_status.name',
'data' => 'status',
'title' => trans('calls::calls.form.status'),
'data_type' => 'text',
'filter_type' => 'text'
],
'call_type' => [
'data' => 'call_type',
'title' => trans('calls::calls.form.call_type'),
'data_type' => 'text',
'filter_type' => 'text'
],
'phone_number' => [
'data' => 'phone_number',
'title' => trans('calls::calls.form.phone_number'),
'data_type' => 'text',
'filter_type' => 'text'
],
'duration' => [
'data' => 'duration',
'title' => trans('calls::calls.form.duration'),
'data_type' => 'text',
'filter_type' => 'text'
],
'talktime' => [
'data' => 'talktime',
'title' => trans('calls::calls.form.talktime'),
'data_type' => 'text',
'filter_type' => 'text'
],
'call_date' => [
'data' => 'call_date',
'title' => trans('calls::calls.form.call_date'),
'data_type' => 'datetime',
'filter_type' => 'bap_date_range_picker'
],
'owner' => [
'data' => 'owner',
'title' => trans('core::core.table.assigned_to'),
'data_type' => 'assigned_to',
'orderable' => false,
'filter_type' => 'select',
'select_type' => 'select2',
'select_type_options' => [
'theme' => "bootstrap",
'width' => '100%'
],
'filter_data' => DataTableHelper::filterOwnerDropdown()
],
'lead_name' => [
'name' => 'leads.full_name',
'data' => 'lead_name',
'title' => trans('calls::calls.form.lead_name'),
'data_type' => 'text',
'filter_type' => 'text'
],
'account_name' => [
'name' => 'accounts.name',
'data' => 'account_name',
'title' => trans('calls::calls.form.account_name'),
'data_type' => 'text',
'filter_type' => 'text'
],
'deal_name' => [
'name' => 'deals.name',
'data' => 'deal_name',
'title' => trans('calls::calls.form.deal_name'),
'data_type' => 'text',
'filter_type' => 'text'
],
'contact_name' => [
'name' => 'contacts.full_name',
'data' => 'contact_name',
'title' => trans('calls::calls.form.contact_name'),
'data_type' => 'text',
'filter_type' => 'text'
],
'linkedid' => [
'name' => 'calls.linkedid',
'data' => 'linkedid',
'title' => trans('calls::calls.form.download'),
'data_type' => 'text',
'orderable' => false
]
];
}
protected function setFilterDefinition()
{
$this->filterDefinition = self::availableQueryFilters();
}
/**
* Build DataTable class.
*
* @param mixed $query Results from query() method.
* @return \Yajra\DataTables\DataTableAbstract
*/
public function dataTable($query)
{
$dataTable = new EloquentDataTable($query);
$this->applyLinks($dataTable, self::SHOW_URL_ROUTE);
$dataTable->filterColumn('owner', function ($query, $keyword) {
DataTableHelper::queryOwner($query, $keyword, 'calls');
});
$dataTable->filterColumn('created_at', function ($query, $keyword) {
$dates = DataTableHelper::getDatesForFilter($keyword);
if ($dates != null) {
$query->whereBetween('calls.created_at', array($dates[0], $dates[1]));
}
});
$dataTable->filterColumn('call_date', function ($query, $keyword) {
$dates = DataTableHelper::getDatesForFilter($keyword);
if ($dates != null) {
$query->whereBetween('calls.call_date', array($dates[0], $dates[1]));
}
});
$dataTable->filterColumn('updated_at', function ($query, $keyword) {
$dates = DataTableHelper::getDatesForFilter($keyword);
if ($dates != null) {
$query->whereBetween('calls.updated_at', array($dates[0], $dates[1]));
}
});
$dataTable->editColumn('linkedid', function($record){
$record_name = \DB::table('asteriskcdrdb.cdr')
->select('recordingfile')
->where('linkedid',$record->linkedid)
->orderBy('uniqueid','DESC')
->first();
$record_name = $record_name->recordingfile ?? null;
if(is_null($record_name) || ($record->status != 'Up - ANSWERED')){
$btn = 'block';
}else{
$display_url = route('reporting.listen.page', ['id' => $record->linkedid]);
$btn = 'Listen';
}
return $btn;
});
return $dataTable;
}
/**
* Get query source of dataTable.
*
*
* @return \Illuminate\Database\Eloquent\Builder
*/
public function query(Call $model)
{
$query = $model->newQuery()
->with('owner')
->leftJoin('calls_dict_direction', 'calls.direction_id', '=', 'calls_dict_direction.id')
->leftJoin('calls_dict_status', 'calls.status_id', '=', 'calls_dict_status.id')
->leftJoin('accounts', 'calls.account_id', '=', 'accounts.id')
->leftJoin('deals', 'calls.deal_id', '=', 'deals.id')
->leftJoin('contacts', 'calls.contact_id', '=', 'contacts.id')
->leftJoin('leads', 'calls.lead_id', '=', 'leads.id')
->select(
'calls.*',
'calls_dict_direction.name as direction',
'calls_dict_status.name as status',
'deals.name as deal_name',
'accounts.name as account_name',
'contacts.full_name as contact_name',
'leads.full_name as lead_name'
)
->orderBy('calls.created_at', 'DESC');
$user = auth()->user();
if($user->hasRole('admin')){
}elseif($user->hasRole('company_manager') || $user->access_to_all_entity == true){
$query->where(['calls.company_id' => $user->company_id]);
}else{
$query->where(['calls.owned_by_type' =>'Modules\Platform\User\Entities\User','calls.owned_by_id' => $user->id]);
}
if (!empty($this->filterRules)) {
$queryBuilderParser = new QueryBuilderParser();
$queryBuilder = $queryBuilderParser->parse($this->filterRules, $query);
return $queryBuilder;
}
return $query;
}
/**
* Optional method if you want to use html builder.
*
* @return \Yajra\DataTables\Html\Builder
*/
public function html()
{
return $this->builder()
->columns($this->getColumns())
->setTableAttribute('class', 'table table-hover')
->parameters([
'dom' => 'lBfrtip',
'responsive' => false,
'stateSave' => true,
'filterDefinitions' => $this->getFilterDefinition(),
'filterRules' => $this->filterRules,
'headerFilters' => true,
'buttons' => DataTableHelper::buttons(),
'regexp' => true
]);
}
/**
* @return array
*/
protected function getColumns()
{
if (!empty($this->advancedView)) {
$result = [];
if ($this->allowSelect) {
$result = $this->btnCheck_selection;
}
return $result + $this->advancedView;
}
$columns = self::availableColumns();
$result = [];
if ($this->allowSelect) {
$result = $this->btnCheck_selection;
}
if ($this->allowUnlink) {
$result = $this->btnUnlink;
}
if ($this->allowQuickEdit) {
$result = $result + $this->btnQuick_edit;;
}
$result = $result + $columns;
return $result;
}
}