Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13532 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Orders Controller
5
 *
6
 * @property Order $Order
7
 * @property PaginatorComponent $Paginator
8
 */
9
class OrdersController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
13672 anikendra 18
	public function beforeFilter() {		
13591 anikendra 19
		parent::beforeFilter();
20
		$this->Auth->allow('add');
13672 anikendra 21
		$this->apihost = Configure::read('pythonapihost');
13591 anikendra 22
	}
23
 
13672 anikendra 24
	public function mine() {
25
		$this->layout = "innerpages";
26
		$url = $this->apihost."storeorder/user/".$this->Auth->User('id')."?page=1&window=10";
27
		$response = $this->make_request($url,null);
28
		if(!empty($response['data'])){
29
			$this->set('orders',$response['data']);
30
		}
31
	}
32
 
13532 anikendra 33
/**
34
 * index method
35
 *
36
 * @return void
37
 */
38
	public function index() {
13591 anikendra 39
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 40
		$this->Order->recursive = 0;
41
		$this->set('orders', $this->Paginator->paginate());
42
	}
43
 
44
/**
45
 * view method
46
 *
47
 * @throws NotFoundException
48
 * @param string $id
49
 * @return void
50
 */
51
	public function view($id = null) {
13591 anikendra 52
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 53
		if (!$this->Order->exists($id)) {
54
			throw new NotFoundException(__('Invalid order'));
55
		}
56
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
57
		$this->set('order', $this->Order->find('first', $options));
58
	}
59
 
60
/**
61
 * add method
62
 *
63
 * @return void
64
 */
65
	public function add() {
13633 anikendra 66
		$this->log(print_r($this->request->data,1),'orders');
13532 anikendra 67
		if ($this->request->is('post')) {
68
			$this->Order->create();
13633 anikendra 69
			if(!empty($this->request->data['sub_tag'])){
70
				$this->request->data['status'] = 'mapped';
71
			}
13532 anikendra 72
			if ($this->Order->save($this->request->data)) {
13591 anikendra 73
				$result =array('success'=>true,'message'=>__('The order has been saved.'));
13633 anikendra 74
/*
75
				$options = array('conditions'=>array('status'=>'mapped'),'recursive'=>-1);
76
				$order = $this->Order->find('first',$options);
77
				if(!empty($orders)) {
78
					foreach($orders AS $order) {
79
						$response = $this->PythonApi->postOrders($order);
80
						if(!empty($response) && $response['result']) {
81
							$sql = "UPDATE orders SET status = 'processed' WHERE id = ".$order['Order']['id'];
82
							$this->Order->query($sql);
83
						}
84
					}
85
				}
86
*/
13532 anikendra 87
			} else {
13591 anikendra 88
				$result = array('success'=>false,'message'=>__('The order could not be saved. Please, try again.'));
13532 anikendra 89
			}
13591 anikendra 90
			$this->response->type('json');
91
			$this->layout = 'ajax';
92
			$this->set(array(
93
			    'result' => $result,
94
			    // 'callback' => $callback,
95
			    '_serialize' => array('result')
96
			));
97
			$this->render('/Elements/json');		
98
		}			
13532 anikendra 99
	}
100
 
101
/**
102
 * edit method
103
 *
104
 * @throws NotFoundException
105
 * @param string $id
106
 * @return void
107
 */
108
	public function edit($id = null) {
13591 anikendra 109
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 110
		if (!$this->Order->exists($id)) {
111
			throw new NotFoundException(__('Invalid order'));
112
		}
113
		if ($this->request->is(array('post', 'put'))) {
114
			if ($this->Order->save($this->request->data)) {
115
				$this->Session->setFlash(__('The order has been saved.'));
116
				return $this->redirect(array('action' => 'index'));
117
			} else {
118
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
119
			}
120
		} else {
121
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
122
			$this->request->data = $this->Order->find('first', $options);
123
		}
124
		$users = $this->Order->User->find('list');
125
		$stores = $this->Order->Store->find('list');
126
		$storeOrders = $this->Order->StoreOrder->find('list');
127
		$this->set(compact('users', 'stores', 'storeOrders'));
128
	}
129
 
130
/**
131
 * delete method
132
 *
133
 * @throws NotFoundException
134
 * @param string $id
135
 * @return void
136
 */
137
	public function delete($id = null) {
13591 anikendra 138
		throw new NotFoundException(__('Access Denied'));
13532 anikendra 139
		$this->Order->id = $id;
140
		if (!$this->Order->exists()) {
141
			throw new NotFoundException(__('Invalid order'));
142
		}
143
		$this->request->onlyAllow('post', 'delete');
144
		if ($this->Order->delete()) {
145
			$this->Session->setFlash(__('The order has been deleted.'));
146
		} else {
147
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
148
		}
149
		return $this->redirect(array('action' => 'index'));
150
	}
151
 
152
/**
153
 * admin_index method
154
 *
155
 * @return void
156
 */
157
	public function admin_index() {
158
		$this->Order->recursive = 0;
159
		$this->set('orders', $this->Paginator->paginate());
160
	}
161
 
162
/**
163
 * admin_view method
164
 *
165
 * @throws NotFoundException
166
 * @param string $id
167
 * @return void
168
 */
169
	public function admin_view($id = null) {
170
		if (!$this->Order->exists($id)) {
171
			throw new NotFoundException(__('Invalid order'));
172
		}
173
		$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
174
		$this->set('order', $this->Order->find('first', $options));
175
	}
176
 
177
/**
178
 * admin_add method
179
 *
180
 * @return void
181
 */
182
	public function admin_add() {
183
		if ($this->request->is('post')) {
184
			$this->Order->create();
185
			if ($this->Order->save($this->request->data)) {
186
				$this->Session->setFlash(__('The order has been saved.'));
187
				return $this->redirect(array('action' => 'index'));
188
			} else {
189
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
190
			}
191
		}
192
		$users = $this->Order->User->find('list');
193
		$stores = $this->Order->Store->find('list');
194
		$storeOrders = $this->Order->StoreOrder->find('list');
195
		$this->set(compact('users', 'stores', 'storeOrders'));
196
	}
197
 
198
/**
199
 * admin_edit method
200
 *
201
 * @throws NotFoundException
202
 * @param string $id
203
 * @return void
204
 */
205
	public function admin_edit($id = null) {
206
		if (!$this->Order->exists($id)) {
207
			throw new NotFoundException(__('Invalid order'));
208
		}
209
		if ($this->request->is(array('post', 'put'))) {
210
			if ($this->Order->save($this->request->data)) {
211
				$this->Session->setFlash(__('The order has been saved.'));
212
				return $this->redirect(array('action' => 'index'));
213
			} else {
214
				$this->Session->setFlash(__('The order could not be saved. Please, try again.'));
215
			}
216
		} else {
217
			$options = array('conditions' => array('Order.' . $this->Order->primaryKey => $id));
218
			$this->request->data = $this->Order->find('first', $options);
219
		}
220
		$users = $this->Order->User->find('list');
221
		$stores = $this->Order->Store->find('list');
222
		$storeOrders = $this->Order->StoreOrder->find('list');
223
		$this->set(compact('users', 'stores', 'storeOrders'));
224
	}
225
 
226
/**
227
 * admin_delete method
228
 *
229
 * @throws NotFoundException
230
 * @param string $id
231
 * @return void
232
 */
233
	public function admin_delete($id = null) {
234
		$this->Order->id = $id;
235
		if (!$this->Order->exists()) {
236
			throw new NotFoundException(__('Invalid order'));
237
		}
238
		$this->request->onlyAllow('post', 'delete');
239
		if ($this->Order->delete()) {
240
			$this->Session->setFlash(__('The order has been deleted.'));
241
		} else {
242
			$this->Session->setFlash(__('The order could not be deleted. Please, try again.'));
243
		}
244
		return $this->redirect(array('action' => 'index'));
245
	}}