| 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 |
|
| 22846 |
amit.gupta |
11 |
/**
|
|
|
12 |
* Components
|
|
|
13 |
*
|
|
|
14 |
* @var array
|
|
|
15 |
*/
|
| 15051 |
manas |
16 |
public $components = array('Paginator');
|
|
|
17 |
|
| 22846 |
amit.gupta |
18 |
/**
|
|
|
19 |
* index method
|
|
|
20 |
*
|
|
|
21 |
* @return void
|
|
|
22 |
*/
|
| 15051 |
manas |
23 |
public function index() {
|
|
|
24 |
$this->layout = 'ajax';
|
|
|
25 |
$this->Retailer->recursive = 0;
|
| 22846 |
amit.gupta |
26 |
$options = array('conditions'=>array('status' =>'new'));
|
| 15051 |
manas |
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 |
}
|
| 22846 |
amit.gupta |
34 |
public function notificationactive(){
|
| 15051 |
manas |
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);
|
| 22846 |
amit.gupta |
38 |
|
| 15051 |
manas |
39 |
if(!$count){
|
|
|
40 |
$result = array('success'=>false);
|
|
|
41 |
}else{
|
|
|
42 |
$result = array('success'=>true);
|
|
|
43 |
}
|
| 22846 |
amit.gupta |
44 |
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
54 |
/*public function index() {
|
| 15051 |
manas |
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'));
|
| 22846 |
amit.gupta |
59 |
$lasttimestamp = $this->Mobileappsetting->find('first',$options);
|
| 15051 |
manas |
60 |
$result = array('settings' => $settings,'t'=>$lasttimestamp[0]['t']);
|
|
|
61 |
$this->set(array(
|
| 22846 |
amit.gupta |
62 |
'result' => $result,
|
|
|
63 |
'_serialize' => array('result')
|
| 15051 |
manas |
64 |
));
|
|
|
65 |
$this->render('/Elements/json');
|
| 22846 |
amit.gupta |
66 |
}*/
|
|
|
67 |
/**
|
|
|
68 |
* view method
|
|
|
69 |
*
|
|
|
70 |
* @throws NotFoundException
|
|
|
71 |
* @param string $id
|
|
|
72 |
* @return void
|
|
|
73 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
82 |
/**
|
|
|
83 |
* add method
|
|
|
84 |
*
|
|
|
85 |
* @return void
|
|
|
86 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
99 |
/**
|
|
|
100 |
* edit method
|
|
|
101 |
*
|
|
|
102 |
* @throws NotFoundException
|
|
|
103 |
* @param string $id
|
|
|
104 |
* @return void
|
|
|
105 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
123 |
/**
|
|
|
124 |
* delete method
|
|
|
125 |
*
|
|
|
126 |
* @throws NotFoundException
|
|
|
127 |
* @param string $id
|
|
|
128 |
* @return void
|
|
|
129 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
144 |
/**
|
|
|
145 |
* admin_index method
|
|
|
146 |
*
|
|
|
147 |
* @return void
|
|
|
148 |
*/
|
| 15051 |
manas |
149 |
public function admin_index() {
|
|
|
150 |
$this->Retailer->recursive = 0;
|
|
|
151 |
$this->set('retailers', $this->Paginator->paginate());
|
|
|
152 |
}
|
|
|
153 |
|
| 22846 |
amit.gupta |
154 |
/**
|
|
|
155 |
* admin_view method
|
|
|
156 |
*
|
|
|
157 |
* @throws NotFoundException
|
|
|
158 |
* @param string $id
|
|
|
159 |
* @return void
|
|
|
160 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
169 |
/**
|
|
|
170 |
* admin_add method
|
|
|
171 |
*
|
|
|
172 |
* @return void
|
|
|
173 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
186 |
/**
|
|
|
187 |
* admin_edit method
|
|
|
188 |
*
|
|
|
189 |
* @throws NotFoundException
|
|
|
190 |
* @param string $id
|
|
|
191 |
* @return void
|
|
|
192 |
*/
|
| 15051 |
manas |
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 |
|
| 22846 |
amit.gupta |
210 |
/**
|
|
|
211 |
* admin_delete method
|
|
|
212 |
*
|
|
|
213 |
* @throws NotFoundException
|
|
|
214 |
* @param string $id
|
|
|
215 |
* @return void
|
|
|
216 |
*/
|
| 15051 |
manas |
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(){
|
| 22846 |
amit.gupta |
232 |
// $options['conditions'] = array('status LIKE '=>"%$search%");
|
| 19748 |
naman |
233 |
$opt = array('conditions' => array('status'=> 'pending_verification'));
|
|
|
234 |
$pending = $this->Retailer->find('all',$opt);
|
|
|
235 |
$this->set(compact('pending'));
|
|
|
236 |
}
|
| 22846 |
amit.gupta |
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 |
}
|
| 22846 |
amit.gupta |
243 |
|
| 21011 |
amit.gupta |
244 |
public function admin_activate($id, $userid) {
|
|
|
245 |
$agentid = Configure::read('agentid');
|
|
|
246 |
$code = Configure::read('activation_code_crm');
|
|
|
247 |
$cur_date = date('Y-m-d H:i:s', time());
|
| 21027 |
amit.gupta |
248 |
$retailerlinks="insert into retailerlinks (retailer_id, agent_id, code, activated, user_id, created)
|
| 21026 |
amit.gupta |
249 |
values ($id, $agentid, '$code','$cur_date', $userid, '$cur_date')";
|
| 22846 |
amit.gupta |
250 |
$this->Retailer->query($retailerlinks);
|
| 21032 |
amit.gupta |
251 |
$activateuserquery = "update users set activated=1, referrer='$code' where id=$userid";
|
| 22846 |
amit.gupta |
252 |
$this->Retailer->query($activateuserquery);
|
| 21029 |
amit.gupta |
253 |
$this->markUserActivated($userid);
|
| 22846 |
amit.gupta |
254 |
|
| 21011 |
amit.gupta |
255 |
$this->redirect("pendingretailer");
|
| 22846 |
amit.gupta |
256 |
|
| 21011 |
amit.gupta |
257 |
}
|
| 22846 |
amit.gupta |
258 |
|
| 19748 |
naman |
259 |
public function admin_retailerverify($id,$tin){
|
| 19793 |
naman |
260 |
$agentid = Configure::read('agentid');
|
| 19768 |
naman |
261 |
if($this->request->is('post')){
|
|
|
262 |
$data = $this->request->data;
|
|
|
263 |
$retId = $data['Retailer']['retId'];
|
|
|
264 |
$retcontact = $data['Retailer']['contact'];
|
| 19789 |
naman |
265 |
$cur_date = date('Y-m-d H:i:s', time());
|
| 19768 |
naman |
266 |
if($data['type'] == "Verify"){
|
| 19775 |
naman |
267 |
$retquery ="update retailers set status = 'retailer_verified' ,modified = '".$cur_date."' , isvalidated = 1 where id = ".$retId."";
|
| 19768 |
naman |
268 |
$this->Retailer->query($retquery);
|
|
|
269 |
}elseif($data['type'] == "Cancel"){
|
| 19775 |
naman |
270 |
$retquery ="update retailers set status = 'not_verified' ,modified = '".$cur_date."' , comments = '".$data['Retailer']['text']."' where id = ".$retId."";
|
| 19768 |
naman |
271 |
$this->Retailer->query($retquery);
|
| 22846 |
amit.gupta |
272 |
|
|
|
273 |
$callhistoryquery = "insert into callhistory
|
| 19768 |
naman |
274 |
(retailer_id,agent_id,mobile_number,call_type,sms_verified,call_time,duration_sec,
|
|
|
275 |
last_fetch_time,call_disposition,disposition_description,disposition_comments,created)
|
|
|
276 |
values
|
| 19793 |
naman |
277 |
(".$retId.",".$agentid.",'".$retcontact."','verification',0,'".$cur_date."',0,'".$cur_date."',
|
| 19775 |
naman |
278 |
'other','verification cancelled','".$data['Retailer']['text']."','".$cur_date."')";
|
| 19768 |
naman |
279 |
$this->Retailer->query($callhistoryquery);
|
|
|
280 |
}elseif($data['type'] == "Pending"){
|
| 19775 |
naman |
281 |
$retquery ="update retailers set comments = '".$data['Retailer']['text']."' ,modified = '".$cur_date."' where id = ".$retId."";
|
| 19768 |
naman |
282 |
$this->Retailer->query($retquery);
|
|
|
283 |
$callhistoryquery = "insert into callhistory
|
|
|
284 |
(retailer_id,agent_id,mobile_number,call_type,sms_verified,call_time,duration_sec,
|
|
|
285 |
last_fetch_time,call_disposition,disposition_description,disposition_comments,created)
|
|
|
286 |
values
|
| 19793 |
naman |
287 |
(".$retId.",".$agentid.",'".$retcontact."','verification',0,'".$cur_date."',0,'".$cur_date."',
|
| 19775 |
naman |
288 |
'other','verification still in process','".$data['Retailer']['text']."','".$cur_date."')";
|
| 19768 |
naman |
289 |
$this->Retailer->query($callhistoryquery);
|
|
|
290 |
}
|
|
|
291 |
$this->redirect("pendingretailer");
|
|
|
292 |
}
|
| 19748 |
naman |
293 |
$options['conditions'] = array('id'=> $id);
|
|
|
294 |
$pending = $this->Retailer->find('first',$options);
|
|
|
295 |
$result = $pending['Retailer'];
|
|
|
296 |
$tinresult = "";
|
|
|
297 |
if($tin != null){
|
|
|
298 |
$url = Configure::read('pythonapihost')."tinsearch?tin=".$tin;
|
|
|
299 |
$tinres = $this->make_request($url, null);
|
|
|
300 |
if(!$tinres['isError']){
|
|
|
301 |
$tinresult = $tinres;
|
|
|
302 |
$this->set(compact('tinresult'));
|
|
|
303 |
}
|
|
|
304 |
}
|
|
|
305 |
$this->set(compact('result'));
|
|
|
306 |
}
|
| 22846 |
amit.gupta |
307 |
|
|
|
308 |
|
| 19768 |
naman |
309 |
public function sendsms(){
|
|
|
310 |
$this->autoRender = false;
|
|
|
311 |
$this->request->onlyAllow('ajax');
|
| 19793 |
naman |
312 |
$agentid = Configure::read('agentid');
|
| 19768 |
naman |
313 |
$contact = $this->request->query('contact');
|
|
|
314 |
$retid = $this->request->query('retid');
|
| 19793 |
naman |
315 |
$url = Configure::read('pythonapihost')."sendTransSms/code/".$retid."/".$agentid;
|
| 22846 |
amit.gupta |
316 |
// $url = "http://45.79.106.95:8057/sendTransSms/code/6836700/2";
|
| 19768 |
naman |
317 |
if($contact != null || !empty($contact)){
|
|
|
318 |
$url = $url."?mobile_number=".$contact;
|
| 19748 |
naman |
319 |
}
|
| 19768 |
naman |
320 |
$response = $this->make_request($url,'{}');
|
| 22846 |
amit.gupta |
321 |
|
| 19768 |
naman |
322 |
return json_encode($response);
|
| 19748 |
naman |
323 |
}
|
| 22846 |
amit.gupta |
324 |
|
| 19825 |
naman |
325 |
public function admin_editretailer($id){
|
|
|
326 |
if($this->request->is('post') || $this->request->is('put')){
|
|
|
327 |
$retdet = $this->request->data['Retailer'];
|
|
|
328 |
$cur_date = date('Y-m-d H:i:s', time());
|
|
|
329 |
if($retdet['tinNumber'] == '' || empty($retdet['tinNumber']))
|
|
|
330 |
{
|
|
|
331 |
$upquery = "update retailers set title = '".$retdet['storeName']."' , address = '".$retdet['completeAddress']."',pin = ".$retdet['pin'].",tinnumber = NULL,city = '".$retdet['city']."',state='".$retdet['state']."' , modified='".$cur_date."' where id =".$retdet['id']."";
|
|
|
332 |
}
|
|
|
333 |
else{
|
|
|
334 |
$upquery = "update retailers set title = '".$retdet['storeName']."' , address = '".$retdet['completeAddress']."',pin = ".$retdet['pin'].",tinnumber = ".$retdet['tinNumber'].",city = '".$retdet['city']."',state='".$retdet['state']."' , modified='".$cur_date."' where id =".$retdet['id']."";
|
|
|
335 |
}
|
| 22846 |
amit.gupta |
336 |
|
|
|
337 |
|
|
|
338 |
|
| 19825 |
naman |
339 |
$this->Retailer->query($upquery);
|
|
|
340 |
$this->redirect("retailerverify/".$retdet['id']."/".$retdet['tinNumber']);
|
|
|
341 |
}
|
|
|
342 |
if($id !=null){
|
|
|
343 |
$opt['conditions'] = array('id' => $id);
|
|
|
344 |
$retailer = $this->Retailer->find('first',$opt);
|
|
|
345 |
$this->set(compact('retailer'));
|
| 22846 |
amit.gupta |
346 |
|
| 19825 |
naman |
347 |
}
|
|
|
348 |
}
|
| 22846 |
amit.gupta |
349 |
|
| 19841 |
naman |
350 |
public function admin_filterretailer(){
|
| 22846 |
amit.gupta |
351 |
|
| 19841 |
naman |
352 |
if($this->request->is('post')){
|
|
|
353 |
$filter = $this->request->data['Retailer']['searchReatailerBy'];
|
| 22846 |
amit.gupta |
354 |
// debug($retdet);
|
| 19841 |
naman |
355 |
if($filter == '0'){
|
| 20892 |
amit.gupta |
356 |
$cnaquery ="select r.*, rl.code from retailers r join profitmandi_sms p on r.id=p.identifier join retailerlinks rl on r.id= rl.retailer_id and rl.user_id is not null order by r.id desc";
|
| 19841 |
naman |
357 |
}else if($filter == '1') {
|
| 20892 |
amit.gupta |
358 |
$cnaquery ="select r.*, rl.code from retailers r join profitmandi_sms p on r.id=p.identifier join retailerlinks rl on r.id= rl.retailer_id and rl.user_id is null order by r.id desc";
|
| 19841 |
naman |
359 |
}else if($filter == '2') {
|
| 20889 |
amit.gupta |
360 |
$cnaquery ="select r.* from retailers r where r.status = 'not_verified' order by r.id desc";
|
| 19841 |
naman |
361 |
}
|
|
|
362 |
|
| 20896 |
amit.gupta |
363 |
$result = $this->Retailer->query($cnaquery);;
|
| 19841 |
naman |
364 |
$this->set(compact('result'));
|
| 22762 |
amit.gupta |
365 |
}
|
| 22846 |
amit.gupta |
366 |
}
|
|
|
367 |
|
| 22761 |
amit.gupta |
368 |
public function admin_pendingretailer_new() {
|
| 22765 |
amit.gupta |
369 |
if($this->request->is('get')) {
|
| 22850 |
amit.gupta |
370 |
$prquery = "select r.*,a.*, u.*, s.* from retailer r join user_accounts ua on (ua.account_key=r.id and ua.account_type='saholic')
|
|
|
371 |
join users u on u.id=ua.user_id join retailer_registered_address rra on rra.retailer_id=r.id join user.address a on rra.address_id=a.id join shop s on s.retailer_id=r.id where u.created > '2017-11-03' order by u.id desc limit 100";
|
| 22846 |
amit.gupta |
372 |
//join users u on u.id=ua.user_id join retailer_registered_address rra on rra.retailer_id=r.id join user.address a on rra.address_id=a.id where (r.migrated=0 and r.active=0)";
|
| 22761 |
amit.gupta |
373 |
$result = $this->Retailer->query($prquery);
|
| 22764 |
amit.gupta |
374 |
$this->set(compact('result'));
|
| 22761 |
amit.gupta |
375 |
}
|
|
|
376 |
}
|
| 22846 |
amit.gupta |
377 |
|
| 15051 |
manas |
378 |
}
|