ultimatepos/Modules/Crm/Http/Controllers/CallQueueController.php

73 lines
2.5 KiB
PHP

<?php
namespace Modules\Crm\Http\Controllers;
use App\Utils\ModuleUtil;
use Illuminate\Routing\Controller;
use Modules\Crm\Entities\CrmCallQueue;
use Modules\Crm\Services\CallQueueService;
use Modules\Crm\Utils\TelemarketingUtil;
use Yajra\DataTables\Facades\DataTables;
class CallQueueController extends Controller
{
protected $moduleUtil;
protected $callQueueService;
public function __construct(ModuleUtil $moduleUtil, CallQueueService $callQueueService)
{
$this->moduleUtil = $moduleUtil;
$this->callQueueService = $callQueueService;
}
protected function authorizeAccess(): void
{
$business_id = request()->session()->get('user.business_id');
TelemarketingUtil::authorizeTelemarketing($this->moduleUtil, $business_id, 'crm.telemarketing.view_all_queue');
}
public function index()
{
$this->authorizeAccess();
$business_id = request()->session()->get('user.business_id');
if (request()->ajax()) {
$this->callQueueService->syncQueueForBusiness($business_id);
$query = CrmCallQueue::where('crm_call_queues.business_id', $business_id)
->join('crm_phone_follow_ups', 'crm_call_queues.phone_follow_up_id', '=', 'crm_phone_follow_ups.id')
->leftJoin('users', 'crm_call_queues.locked_by', '=', 'users.id')
->select(
'crm_call_queues.*',
'crm_phone_follow_ups.mobile_number',
'crm_phone_follow_ups.company_name',
'crm_phone_follow_ups.contact_name',
\DB::raw("CONCAT(COALESCE(users.first_name, ''), ' ', COALESCE(users.last_name, '')) as locked_user_name")
);
if (! empty(request()->get('status'))) {
$query->where('crm_call_queues.status', request()->get('status'));
}
return Datatables::of($query)
->editColumn('status', function ($row) {
return '<span class="label label-info">'.$row->status.'</span>';
})
->rawColumns(['status'])
->make(true);
}
return view('crm::telemarketing.queue.index');
}
public function sync()
{
$this->authorizeAccess();
$business_id = request()->session()->get('user.business_id');
$this->callQueueService->syncQueueForBusiness($business_id);
return redirect()->back()->with('status', ['success' => 1, 'msg' => __('crm::lang.queue_synced')]);
}
}