Subversion Repositories SmartDukaan

Rev

Rev 15051 | Rev 19768 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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
 
19748 naman 238
	public function admin_retailerverify($id,$tin){
239
		$options['conditions'] = array('id'=> $id);
240
		$pending = $this->Retailer->find('first',$options);
241
		$result = $pending['Retailer'];
242
		$tinresult = "";
243
		if($tin != null){
244
			$url = Configure::read('pythonapihost')."tinsearch?tin=".$tin;
245
			$tinres = $this->make_request($url, null);
246
			if(!$tinres['isError']){
247
				$tinresult = $tinres;
248
				$this->set(compact('tinresult'));
249
			}
250
		}
251
		$this->set(compact('result'));
252
	}
253
	public function admin_verifycancel($id,$type){
254
		if($type == "verify"){
255
			$retquery ="update retailers set status = 'retailer_verified' and isvalidated = 1  where id = ".$id."";
256
			$this->Retailer->query($retquery);
257
		}else if($type == "cancel"){
258
			$retquery ="update retailers set status = 'not_verified' where id = ".$id."";
259
			$this->Retailer->query($retquery);
260
		}
261
		$this->redirect("pendingretailer");
262
	}
15051 manas 263
}