Subversion Repositories SmartDukaan

Rev

Rev 20117 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
15219 manas 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Callhistories Controller
5
 *
6
 * @property Callhistory $Callhistory
7
 * @property PaginatorComponent $Paginator
8
 */
9
class CallhistoriesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
/**
19
 * admin_index method
20
 *
21
 * @return void
22
 */
23
	public function admin_index() {
15226 manas 24
		if ($this->request->is('post')) {
25
			alert('Clicked');
26
		}
15219 manas 27
		$this->Callhistory->recursive = 0;
28
		$this->Paginator->settings = array('order' => array('id'=>'desc'));
15226 manas 29
 
15219 manas 30
		$this->set('callhistories', $this->Paginator->paginate());
31
	}
32
 
33
/**
34
 * admin_view method
35
 *
36
 * @throws NotFoundException
37
 * @param string $id
38
 * @return void
39
 */
40
	public function admin_view($id = null) {
41
		if (!$this->Callhistory->exists($id)) {
42
			throw new NotFoundException(__('Invalid callhistory'));
43
		}
44
		$options = array('conditions' => array('Callhistory.' . $this->Callhistory->primaryKey => $id));
45
		$this->set('callhistory', $this->Callhistory->find('first', $options));
46
	}
47
 
48
/**
49
 * admin_add method
50
 *
51
 * @return void
52
 */
53
	public function admin_add() {
54
		if ($this->request->is('post')) {
55
			$this->Callhistory->create();
56
			if ($this->Callhistory->save($this->request->data)) {
57
				$this->Session->setFlash(__('The callhistory has been saved.'));
58
				return $this->redirect(array('action' => 'index'));
59
			} else {
60
				$this->Session->setFlash(__('The callhistory could not be saved. Please, try again.'));
61
			}
62
		}
63
		$retailers = $this->Callhistory->Retailer->find('list');
64
		$agents = $this->Callhistory->Agent->find('list');
65
		$this->set(compact('retailers', 'agents'));
66
	}
67
 
68
/**
69
 * admin_edit method
70
 *
71
 * @throws NotFoundException
72
 * @param string $id
73
 * @return void
74
 */
75
	public function admin_edit($id = null) {
76
		if (!$this->Callhistory->exists($id)) {
77
			throw new NotFoundException(__('Invalid callhistory'));
78
		}
79
		if ($this->request->is(array('post', 'put'))) {
80
			if ($this->Callhistory->save($this->request->data)) {
81
				$this->Session->setFlash(__('The callhistory has been saved.'));
82
				return $this->redirect(array('action' => 'index'));
83
			} else {
84
				$this->Session->setFlash(__('The callhistory could not be saved. Please, try again.'));
85
			}
86
		} else {
87
			$options = array('conditions' => array('Callhistory.' . $this->Callhistory->primaryKey => $id));
88
			$this->request->data = $this->Callhistory->find('first', $options);
89
		}
90
		$retailers = $this->Callhistory->Retailer->find('list');
91
		$agents = $this->Callhistory->Agent->find('list');
92
		$this->set(compact('retailers', 'agents'));
93
	}
94
 
95
/**
96
 * admin_delete method
97
 *
98
 * @throws NotFoundException
99
 * @param string $id
100
 * @return void
101
 */
102
	public function admin_delete($id = null) {
103
		$this->Callhistory->id = $id;
104
		if (!$this->Callhistory->exists()) {
105
			throw new NotFoundException(__('Invalid callhistory'));
106
		}
107
		$this->request->onlyAllow('post', 'delete');
108
		if ($this->Callhistory->delete()) {
109
			$this->Session->setFlash(__('The callhistory has been deleted.'));
110
		} else {
111
			$this->Session->setFlash(__('The callhistory could not be deleted. Please, try again.'));
112
		}
113
		return $this->redirect(array('action' => 'index'));
15226 manas 114
	}
115
	public function admin_search(){
15404 manas 116
		$type=$this->request->query('type');
15226 manas 117
		$date_from = $this->request->query('date_from');
118
		$date_to = $this->request->query('date_to');
15404 manas 119
		$searchTerm = $this->request->query('search');
120
		if(empty($searchTerm)){
121
			if(!empty($date_from) && !empty($date_to)){
122
				if(strtotime($date_from) > strtotime($date_to)){
123
					$userActions = array();
124
					$resul=$userActions;
125
					echo "Wrong date selected";
126
				}else{
127
					$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";
128
					$resul=$this->Callhistory->query($sqlQuery);	
129
				}
130
			}else{
131
				$userActions = array();
132
				$resul=$userActions;
133
			}
134
 
135
		}else if($type=='agent_name'){
136
			if(!empty($date_from) && !empty($date_to)){
137
				if(strtotime($date_from) > strtotime($date_to)){
138
					$userActions = array();
139
					$resul=$userActions;
140
					echo "Wrong date selected";
141
				}else{
142
					$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";
143
					$resul=$this->Callhistory->query($sqlQuery);	
144
				}
145
			}else{
146
				$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";
147
				$resul=$this->Callhistory->query($sqlQuery);	
148
			}			
149
		}else if($type=='agent_id'){
150
			if(!empty($date_from) && !empty($date_to)){
151
				if(strtotime($date_from) > strtotime($date_to)){
152
					$userActions = array();
153
					$resul=$userActions;
154
					echo "Wrong date selected";
155
				}else{
156
					$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";
157
					$resul=$this->Callhistory->query($sqlQuery);	
158
				}
159
			}else{
160
				$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";
161
				$resul=$this->Callhistory->query($sqlQuery);	
162
			}			
163
		}else if($type=='agent_role'){
164
			if(!empty($date_from) && !empty($date_to)){
165
				if(strtotime($date_from) > strtotime($date_to)){
166
					$userActions = array();
167
					$resul=$userActions;
168
					echo "Wrong date selected";
169
				}else{
170
					$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";
171
					$resul=$this->Callhistory->query($sqlQuery);	
172
				}
173
			}else{
174
				$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";
175
				$resul=$this->Callhistory->query($sqlQuery);	
176
			}		
177
		}	
15226 manas 178
		$this->Callhistory->recursive = 0;
15404 manas 179
 
15226 manas 180
		$this->set('result', $resul);
181
	}
17976 manas 182
 
183
	public function admin_backlog() {
20117 naman 184
// 		$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";
20120 naman 185
		$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";
186
		$resul=$this->Callhistory->query($backupSql);
17976 manas 187
		$this->set('result', $resul);		
188
	}
189
}