Subversion Repositories SmartDukaan

Rev

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