| 15051 |
manas |
1 |
<?php
|
|
|
2 |
App::uses('AppController', 'Controller');
|
|
|
3 |
/**
|
|
|
4 |
* Retailers Controller
|
|
|
5 |
*
|
|
|
6 |
* @property Retailer $Retailer
|
|
|
7 |
* @property PaginatorComponent $Paginator
|
|
|
8 |
*/
|
|
|
9 |
class RetailersController extends AppController {
|
|
|
10 |
|
|
|
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
|
|
16 |
public $components = array('Paginator');
|
|
|
17 |
|
|
|
18 |
/**
|
|
|
19 |
* index method
|
|
|
20 |
*
|
|
|
21 |
* @return void
|
|
|
22 |
*/
|
|
|
23 |
public function index() {
|
|
|
24 |
$this->layout = 'ajax';
|
|
|
25 |
$this->Retailer->recursive = 0;
|
|
|
26 |
$options = array('conditions'=>array('status' =>'new'));
|
|
|
27 |
$result = $this->Retailer->find('first',$options);
|
|
|
28 |
$this->set(array(
|
|
|
29 |
'result' => $result,
|
|
|
30 |
'_serialize' => array('result')
|
|
|
31 |
));
|
|
|
32 |
$this->render('/Elements/json');
|
|
|
33 |
}
|
|
|
34 |
public function notificationactive(){
|
|
|
35 |
$retailerId = $this->request->query('retailerid');
|
|
|
36 |
$options = array('conditions' => array('id'=> $retailerId,'status'=>'new','expiresAt >'=>date('Y-m-d H:i:s',time())));
|
|
|
37 |
$count = $this->NotificationCampaign->find('count',$options);
|
|
|
38 |
|
|
|
39 |
if(!$count){
|
|
|
40 |
$result = array('success'=>false);
|
|
|
41 |
}else{
|
|
|
42 |
$result = array('success'=>true);
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
$this->response->type('json');
|
|
|
46 |
$this->layout = 'ajax';
|
|
|
47 |
$this->set(array(
|
|
|
48 |
'result' => $result,
|
|
|
49 |
'_serialize' => array('result')
|
|
|
50 |
));
|
|
|
51 |
$this->render('/Elements/json');
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
/*public function index() {
|
|
|
55 |
$this->layout = 'ajax';
|
|
|
56 |
$t = $this->request->query('t');
|
|
|
57 |
$retailer = $this->Mobileappsetting->find('one',$options);
|
|
|
58 |
$options = array('fields'=>array("unix_timestamp(modified) t"),'order'=>array('modified'=>'desc'));
|
|
|
59 |
$lasttimestamp = $this->Mobileappsetting->find('first',$options);
|
|
|
60 |
$result = array('settings' => $settings,'t'=>$lasttimestamp[0]['t']);
|
|
|
61 |
$this->set(array(
|
|
|
62 |
'result' => $result,
|
|
|
63 |
'_serialize' => array('result')
|
|
|
64 |
));
|
|
|
65 |
$this->render('/Elements/json');
|
|
|
66 |
}*/
|
|
|
67 |
/**
|
|
|
68 |
* view method
|
|
|
69 |
*
|
|
|
70 |
* @throws NotFoundException
|
|
|
71 |
* @param string $id
|
|
|
72 |
* @return void
|
|
|
73 |
*/
|
|
|
74 |
public function view($id = null) {
|
|
|
75 |
if (!$this->Retailer->exists($id)) {
|
|
|
76 |
throw new NotFoundException(__('Invalid retailer'));
|
|
|
77 |
}
|
|
|
78 |
$options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
|
|
|
79 |
$this->set('retailer', $this->Retailer->find('first', $options));
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
/**
|
|
|
83 |
* add method
|
|
|
84 |
*
|
|
|
85 |
* @return void
|
|
|
86 |
*/
|
|
|
87 |
public function add() {
|
|
|
88 |
if ($this->request->is('post')) {
|
|
|
89 |
$this->Retailer->create();
|
|
|
90 |
if ($this->Retailer->save($this->request->data)) {
|
|
|
91 |
$this->Session->setFlash(__('The retailer has been saved.'));
|
|
|
92 |
return $this->redirect(array('action' => 'index'));
|
|
|
93 |
} else {
|
|
|
94 |
$this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
|
|
|
95 |
}
|
|
|
96 |
}
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
/**
|
|
|
100 |
* edit method
|
|
|
101 |
*
|
|
|
102 |
* @throws NotFoundException
|
|
|
103 |
* @param string $id
|
|
|
104 |
* @return void
|
|
|
105 |
*/
|
|
|
106 |
public function edit($id = null) {
|
|
|
107 |
if (!$this->Retailer->exists($id)) {
|
|
|
108 |
throw new NotFoundException(__('Invalid retailer'));
|
|
|
109 |
}
|
|
|
110 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
111 |
if ($this->Retailer->save($this->request->data)) {
|
|
|
112 |
$this->Session->setFlash(__('The retailer has been saved.'));
|
|
|
113 |
return $this->redirect(array('action' => 'index'));
|
|
|
114 |
} else {
|
|
|
115 |
$this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
|
|
|
116 |
}
|
|
|
117 |
} else {
|
|
|
118 |
$options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
|
|
|
119 |
$this->request->data = $this->Retailer->find('first', $options);
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
/**
|
|
|
124 |
* delete method
|
|
|
125 |
*
|
|
|
126 |
* @throws NotFoundException
|
|
|
127 |
* @param string $id
|
|
|
128 |
* @return void
|
|
|
129 |
*/
|
|
|
130 |
public function delete($id = null) {
|
|
|
131 |
$this->Retailer->id = $id;
|
|
|
132 |
if (!$this->Retailer->exists()) {
|
|
|
133 |
throw new NotFoundException(__('Invalid retailer'));
|
|
|
134 |
}
|
|
|
135 |
$this->request->onlyAllow('post', 'delete');
|
|
|
136 |
if ($this->Retailer->delete()) {
|
|
|
137 |
$this->Session->setFlash(__('The retailer has been deleted.'));
|
|
|
138 |
} else {
|
|
|
139 |
$this->Session->setFlash(__('The retailer could not be deleted. Please, try again.'));
|
|
|
140 |
}
|
|
|
141 |
return $this->redirect(array('action' => 'index'));
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
/**
|
|
|
145 |
* admin_index method
|
|
|
146 |
*
|
|
|
147 |
* @return void
|
|
|
148 |
*/
|
|
|
149 |
public function admin_index() {
|
|
|
150 |
$this->Retailer->recursive = 0;
|
|
|
151 |
$this->set('retailers', $this->Paginator->paginate());
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
/**
|
|
|
155 |
* admin_view method
|
|
|
156 |
*
|
|
|
157 |
* @throws NotFoundException
|
|
|
158 |
* @param string $id
|
|
|
159 |
* @return void
|
|
|
160 |
*/
|
|
|
161 |
public function admin_view($id = null) {
|
|
|
162 |
if (!$this->Retailer->exists($id)) {
|
|
|
163 |
throw new NotFoundException(__('Invalid retailer'));
|
|
|
164 |
}
|
|
|
165 |
$options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
|
|
|
166 |
$this->set('retailer', $this->Retailer->find('first', $options));
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
/**
|
|
|
170 |
* admin_add method
|
|
|
171 |
*
|
|
|
172 |
* @return void
|
|
|
173 |
*/
|
|
|
174 |
public function admin_add() {
|
|
|
175 |
if ($this->request->is('post')) {
|
|
|
176 |
$this->Retailer->create();
|
|
|
177 |
if ($this->Retailer->save($this->request->data)) {
|
|
|
178 |
$this->Session->setFlash(__('The retailer has been saved.'));
|
|
|
179 |
return $this->redirect(array('action' => 'index'));
|
|
|
180 |
} else {
|
|
|
181 |
$this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
|
|
|
182 |
}
|
|
|
183 |
}
|
|
|
184 |
}
|
|
|
185 |
|
|
|
186 |
/**
|
|
|
187 |
* admin_edit method
|
|
|
188 |
*
|
|
|
189 |
* @throws NotFoundException
|
|
|
190 |
* @param string $id
|
|
|
191 |
* @return void
|
|
|
192 |
*/
|
|
|
193 |
public function admin_edit($id = null) {
|
|
|
194 |
if (!$this->Retailer->exists($id)) {
|
|
|
195 |
throw new NotFoundException(__('Invalid retailer'));
|
|
|
196 |
}
|
|
|
197 |
if ($this->request->is(array('post', 'put'))) {
|
|
|
198 |
if ($this->Retailer->save($this->request->data)) {
|
|
|
199 |
$this->Session->setFlash(__('The retailer has been saved.'));
|
|
|
200 |
return $this->redirect(array('action' => 'index'));
|
|
|
201 |
} else {
|
|
|
202 |
$this->Session->setFlash(__('The retailer could not be saved. Please, try again.'));
|
|
|
203 |
}
|
|
|
204 |
} else {
|
|
|
205 |
$options = array('conditions' => array('Retailer.' . $this->Retailer->primaryKey => $id));
|
|
|
206 |
$this->request->data = $this->Retailer->find('first', $options);
|
|
|
207 |
}
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
/**
|
|
|
211 |
* admin_delete method
|
|
|
212 |
*
|
|
|
213 |
* @throws NotFoundException
|
|
|
214 |
* @param string $id
|
|
|
215 |
* @return void
|
|
|
216 |
*/
|
|
|
217 |
public function admin_delete($id = null) {
|
|
|
218 |
$this->Retailer->id = $id;
|
|
|
219 |
if (!$this->Retailer->exists()) {
|
|
|
220 |
throw new NotFoundException(__('Invalid retailer'));
|
|
|
221 |
}
|
|
|
222 |
$this->request->onlyAllow('post', 'delete');
|
|
|
223 |
if ($this->Retailer->delete()) {
|
|
|
224 |
$this->Session->setFlash(__('The retailer has been deleted.'));
|
|
|
225 |
} else {
|
|
|
226 |
$this->Session->setFlash(__('The retailer could not be deleted. Please, try again.'));
|
|
|
227 |
}
|
|
|
228 |
return $this->redirect(array('action' => 'index'));
|
|
|
229 |
}
|
|
|
230 |
|
| 19748 |
naman |
231 |
public function admin_pendingretailer(){
|
|
|
232 |
// $options['conditions'] = array('status LIKE '=>"%$search%");
|
|
|
233 |
$opt = array('conditions' => array('status'=> 'pending_verification'));
|
|
|
234 |
$pending = $this->Retailer->find('all',$opt);
|
|
|
235 |
$this->set(compact('pending'));
|
|
|
236 |
}
|
| 15051 |
manas |
237 |
|
| 19768 |
naman |
238 |
public function admin_verifiedretailer(){
|
|
|
239 |
$opt['conditions']= array('status' => 'retailer_verified');
|
|
|
240 |
$verified = $this->Retailer->find('all',$opt);
|
|
|
241 |
$this->set(compact('verified'));
|
|
|
242 |
}
|
|
|
243 |
|
| 19748 |
naman |
244 |
public function admin_retailerverify($id,$tin){
|
| 19793 |
naman |
245 |
$agentid = Configure::read('agentid');
|
| 19768 |
naman |
246 |
if($this->request->is('post')){
|
|
|
247 |
$data = $this->request->data;
|
|
|
248 |
$retId = $data['Retailer']['retId'];
|
|
|
249 |
$retcontact = $data['Retailer']['contact'];
|
| 19789 |
naman |
250 |
$cur_date = date('Y-m-d H:i:s', time());
|
| 19768 |
naman |
251 |
if($data['type'] == "Verify"){
|
| 19775 |
naman |
252 |
$retquery ="update retailers set status = 'retailer_verified' ,modified = '".$cur_date."' , isvalidated = 1 where id = ".$retId."";
|
| 19768 |
naman |
253 |
$this->Retailer->query($retquery);
|
|
|
254 |
}elseif($data['type'] == "Cancel"){
|
| 19775 |
naman |
255 |
$retquery ="update retailers set status = 'not_verified' ,modified = '".$cur_date."' , comments = '".$data['Retailer']['text']."' where id = ".$retId."";
|
| 19768 |
naman |
256 |
$this->Retailer->query($retquery);
|
|
|
257 |
|
|
|
258 |
$callhistoryquery = "insert into callhistory
|
|
|
259 |
(retailer_id,agent_id,mobile_number,call_type,sms_verified,call_time,duration_sec,
|
|
|
260 |
last_fetch_time,call_disposition,disposition_description,disposition_comments,created)
|
|
|
261 |
values
|
| 19793 |
naman |
262 |
(".$retId.",".$agentid.",'".$retcontact."','verification',0,'".$cur_date."',0,'".$cur_date."',
|
| 19775 |
naman |
263 |
'other','verification cancelled','".$data['Retailer']['text']."','".$cur_date."')";
|
| 19768 |
naman |
264 |
$this->Retailer->query($callhistoryquery);
|
|
|
265 |
}elseif($data['type'] == "Pending"){
|
| 19775 |
naman |
266 |
$retquery ="update retailers set comments = '".$data['Retailer']['text']."' ,modified = '".$cur_date."' where id = ".$retId."";
|
| 19768 |
naman |
267 |
$this->Retailer->query($retquery);
|
|
|
268 |
$callhistoryquery = "insert into callhistory
|
|
|
269 |
(retailer_id,agent_id,mobile_number,call_type,sms_verified,call_time,duration_sec,
|
|
|
270 |
last_fetch_time,call_disposition,disposition_description,disposition_comments,created)
|
|
|
271 |
values
|
| 19793 |
naman |
272 |
(".$retId.",".$agentid.",'".$retcontact."','verification',0,'".$cur_date."',0,'".$cur_date."',
|
| 19775 |
naman |
273 |
'other','verification still in process','".$data['Retailer']['text']."','".$cur_date."')";
|
| 19768 |
naman |
274 |
$this->Retailer->query($callhistoryquery);
|
|
|
275 |
}
|
|
|
276 |
$this->redirect("pendingretailer");
|
|
|
277 |
}
|
| 19748 |
naman |
278 |
$options['conditions'] = array('id'=> $id);
|
|
|
279 |
$pending = $this->Retailer->find('first',$options);
|
|
|
280 |
$result = $pending['Retailer'];
|
|
|
281 |
$tinresult = "";
|
|
|
282 |
if($tin != null){
|
|
|
283 |
$url = Configure::read('pythonapihost')."tinsearch?tin=".$tin;
|
|
|
284 |
$tinres = $this->make_request($url, null);
|
|
|
285 |
if(!$tinres['isError']){
|
|
|
286 |
$tinresult = $tinres;
|
|
|
287 |
$this->set(compact('tinresult'));
|
|
|
288 |
}
|
|
|
289 |
}
|
|
|
290 |
$this->set(compact('result'));
|
|
|
291 |
}
|
| 19768 |
naman |
292 |
|
|
|
293 |
|
|
|
294 |
public function sendsms(){
|
|
|
295 |
$this->autoRender = false;
|
|
|
296 |
$this->request->onlyAllow('ajax');
|
| 19793 |
naman |
297 |
$agentid = Configure::read('agentid');
|
| 19768 |
naman |
298 |
$contact = $this->request->query('contact');
|
|
|
299 |
$retid = $this->request->query('retid');
|
| 19793 |
naman |
300 |
$url = Configure::read('pythonapihost')."sendTransSms/code/".$retid."/".$agentid;
|
| 19768 |
naman |
301 |
// $url = "http://45.79.106.95:8057/sendTransSms/code/6836700/2";
|
|
|
302 |
if($contact != null || !empty($contact)){
|
|
|
303 |
$url = $url."?mobile_number=".$contact;
|
| 19748 |
naman |
304 |
}
|
| 19768 |
naman |
305 |
$response = $this->make_request($url,'{}');
|
|
|
306 |
|
|
|
307 |
return json_encode($response);
|
| 19748 |
naman |
308 |
}
|
| 15051 |
manas |
309 |
}
|