Rev 20117 | Blame | Compare with Previous | Last modification | View Log | RSS feed
<?phpApp::uses('AppController', 'Controller');/*** Callhistories Controller** @property Callhistory $Callhistory* @property PaginatorComponent $Paginator*/class CallhistoriesController extends AppController {/*** Components** @var array*/public $components = array('Paginator');/*** admin_index method** @return void*/public function admin_index() {if ($this->request->is('post')) {alert('Clicked');}$this->Callhistory->recursive = 0;$this->Paginator->settings = array('order' => array('id'=>'desc'));$this->set('callhistories', $this->Paginator->paginate());}/*** admin_view method** @throws NotFoundException* @param string $id* @return void*/public function admin_view($id = null) {if (!$this->Callhistory->exists($id)) {throw new NotFoundException(__('Invalid callhistory'));}$options = array('conditions' => array('Callhistory.' . $this->Callhistory->primaryKey => $id));$this->set('callhistory', $this->Callhistory->find('first', $options));}/*** admin_add method** @return void*/public function admin_add() {if ($this->request->is('post')) {$this->Callhistory->create();if ($this->Callhistory->save($this->request->data)) {$this->Session->setFlash(__('The callhistory has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The callhistory could not be saved. Please, try again.'));}}$retailers = $this->Callhistory->Retailer->find('list');$agents = $this->Callhistory->Agent->find('list');$this->set(compact('retailers', 'agents'));}/*** admin_edit method** @throws NotFoundException* @param string $id* @return void*/public function admin_edit($id = null) {if (!$this->Callhistory->exists($id)) {throw new NotFoundException(__('Invalid callhistory'));}if ($this->request->is(array('post', 'put'))) {if ($this->Callhistory->save($this->request->data)) {$this->Session->setFlash(__('The callhistory has been saved.'));return $this->redirect(array('action' => 'index'));} else {$this->Session->setFlash(__('The callhistory could not be saved. Please, try again.'));}} else {$options = array('conditions' => array('Callhistory.' . $this->Callhistory->primaryKey => $id));$this->request->data = $this->Callhistory->find('first', $options);}$retailers = $this->Callhistory->Retailer->find('list');$agents = $this->Callhistory->Agent->find('list');$this->set(compact('retailers', 'agents'));}/*** admin_delete method** @throws NotFoundException* @param string $id* @return void*/public function admin_delete($id = null) {$this->Callhistory->id = $id;if (!$this->Callhistory->exists()) {throw new NotFoundException(__('Invalid callhistory'));}$this->request->onlyAllow('post', 'delete');if ($this->Callhistory->delete()) {$this->Session->setFlash(__('The callhistory has been deleted.'));} else {$this->Session->setFlash(__('The callhistory could not be deleted. Please, try again.'));}return $this->redirect(array('action' => 'index'));}public function admin_search(){$type=$this->request->query('type');$date_from = $this->request->query('date_from');$date_to = $this->request->query('date_to');$searchTerm = $this->request->query('search');if(empty($searchTerm)){if(!empty($date_from) && !empty($date_to)){if(strtotime($date_from) > strtotime($date_to)){$userActions = array();$resul=$userActions;echo "Wrong date selected";}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}else{$userActions = array();$resul=$userActions;}}else if($type=='agent_name'){if(!empty($date_from) && !empty($date_to)){if(strtotime($date_from) > strtotime($date_to)){$userActions = array();$resul=$userActions;echo "Wrong date selected";}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' and a.name like lower('%$searchTerm%')order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where a.name like lower('%$searchTerm%')order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}else if($type=='agent_id'){if(!empty($date_from) && !empty($date_to)){if(strtotime($date_from) > strtotime($date_to)){$userActions = array();$resul=$userActions;echo "Wrong date selected";}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' and c.agent_id = '$searchTerm' order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where c.agent_id ='$searchTerm' order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}else if($type=='agent_role'){if(!empty($date_from) && !empty($date_to)){if(strtotime($date_from) > strtotime($date_to)){$userActions = array();$resul=$userActions;echo "Wrong date selected";}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where date(call_time) between '$date_from' and '$date_to' and c.call_type = '$searchTerm' order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}else{$sqlQuery = "SELECT c.id,c.retailer_id,c.agent_id,c.mobile_number,c.call_type,c.call_time,c.duration_sec,c.sms_verified,c.call_disposition,c.disposition_description,c.created, a.name FROM callhistory c join agents a on a.id=c.agent_id where c.call_type = '$searchTerm' order by id desc";$resul=$this->Callhistory->query($sqlQuery);}}$this->Callhistory->recursive = 0;$this->set('result', $resul);}public function admin_backlog() {// $backupSql="select ifnull(agent_id,'General') as agent_id,status,count(1) as count from retailers where status IN ('onboarding','followup') and (agent_id is NULL or agent_id=17) group by status,agent_id";$backupSql = "select ifnull(r.agent_id,'General') as agent_id , r.status as status,count(1) as count, ifnull(a.name,'General') as agent_name from retailers r left join agents a on r.agent_id= a.id where r.status IN ('onboarding','followup') group by r.status,r.agent_id";$resul=$this->Callhistory->query($backupSql);$this->set('result', $resul);}}