Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13637 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Skuschemes Controller
5
 *
6
 * @property Skuscheme $Skuscheme
7
 * @property PaginatorComponent $Paginator
8
 */
9
class SkuschemesController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public $apihost;
19
 
20
	public function beforeFilter() {
21
		parent::beforeFilter();
13946 anikendra 22
//		Configure::load('live');
13637 anikendra 23
		$this->apihost = Configure::read('pythonapihost');
24
	}
25
/**
26
 * admin_index method
27
 *
28
 * @return void
29
 */
30
	public function admin_index() {
14098 anikendra 31
		$page = $this->request->query('page');
32
		if(!isset($page)){
33
			$page = 1;
34
		}
35
		$limit = Configure::read('admindashboardlimit');
36
		$offset = ($page - 1)*$limit;
37
		$url = $this->apihost."discountInfo/getAllSkuSchemeDetails/?limit=$limit&offset=$offset";
13637 anikendra 38
		$response = $this->make_request($url,null);
39
		$this->set('skuschemes',$response);
14098 anikendra 40
		$this->set('page',$page);
13637 anikendra 41
		// $this->Skuscheme->recursive = 0;
42
		// $this->set('skuschemes', $this->Paginator->paginate());
43
	}
44
 
45
/**
46
 * admin_view method
47
 *
48
 * @throws NotFoundException
49
 * @param string $id
50
 * @return void
51
 */
14517 anikendra 52
	public function admin_search() {
53
		$type = $this->request->query('type');
54
		$search = $this->request->query('search');				
55
		$url = $this->apihost."Catalog/searchProducts/?class=SkuSchemeDetails&$type=$search";
56
		$response = $this->make_request($url,null);
57
		$this->set('skuschemes', $response);
58
		$this->set('page',1);
59
		$this->render('admin_index');
13637 anikendra 60
	}
61
 
14517 anikendra 62
	public function admin_searchdp() {
63
		$type = $this->request->query('type');
64
		$search = $this->request->query('search');				
65
		$url = $this->apihost."Catalog/searchProducts/?class=SkuDealerPrices&$type=$search";
66
		$response = $this->make_request($url,null);
67
		$this->set('dealerprices', $response);
68
		$this->set('page',1);
69
		$this->render('admin_dp');
70
	}
71
 
13637 anikendra 72
/**
73
 * admin_add method
74
 *
75
 * @return void
76
 */
77
	public function admin_add() {
78
		if ($this->request->is('post')) {
13646 anikendra 79
			$data = $this->request->data['Skuscheme'];
14225 anikendra 80
			//$data['startDate'] = 1000*strtotime($data['startDate']);
81
			//$data['endDate'] = 1000*strtotime($data['endDate']);
13637 anikendra 82
			$url = $this->apihost."discountInfo/addSkuSchemeDetails";
13646 anikendra 83
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
13637 anikendra 84
			$response = $this->make_request($url,$jsonVar);
85
			if (key($response)) {
86
				$this->Session->setFlash(current($response));
87
				return $this->redirect(array('action' => 'index'));
88
			} else {
89
				$this->Session->setFlash(current($response));
13646 anikendra 90
			}			
13637 anikendra 91
		}
92
	}
93
 
94
/**
95
 * admin_edit method
96
 *
97
 * @throws NotFoundException
98
 * @param string $id
99
 * @return void
100
 */
101
	public function admin_edit($id = null) {
102
		if (!$this->Skuscheme->exists($id)) {
103
			throw new NotFoundException(__('Invalid skuscheme'));
104
		}
105
		if ($this->request->is(array('post', 'put'))) {
106
			if ($this->Skuscheme->save($this->request->data)) {
107
				$this->Session->setFlash(__('The skuscheme has been saved.'));
108
				return $this->redirect(array('action' => 'index'));
109
			} else {
110
				$this->Session->setFlash(__('The skuscheme could not be saved. Please, try again.'));
111
			}
112
		} else {
113
			$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
114
			$this->request->data = $this->Skuscheme->find('first', $options);
115
		}
116
	}
117
 
118
/**
119
 * admin_delete method
120
 *
121
 * @throws NotFoundException
122
 * @param string $id
123
 * @return void
124
 */
14517 anikendra 125
	public function admin_delete($id = null) {		
126
		if ($this->remove($id,'SkuSchemeDetails')) {
127
			$this->Session->setFlash(__('The sku scheme deal has been deleted.'));
128
		} else {
129
			$this->Session->setFlash(__('The sku scheme could not be deleted. Please, try again.'));
13637 anikendra 130
		}
14517 anikendra 131
		return $this->redirect(array('action' => 'index'));
132
	}
133
 
134
	public function admin_deletedp($id = null) {		
135
		if ($this->remove($id,'SkuDealerPrices')) {
136
			$this->Session->setFlash(__('The sku scheme deal has been deleted.'));
13637 anikendra 137
		} else {
14517 anikendra 138
			// $this->Session->setFlash(__('The sku scheme could not be deleted. Please, try again.'));
13637 anikendra 139
		}
140
		return $this->redirect(array('action' => 'index'));
14099 anikendra 141
	}
14517 anikendra 142
 
14099 anikendra 143
	public function admin_dp(){		
144
		$page = $this->request->query('page');
145
		if(!isset($page)){
146
			$page = 1;
147
		}
148
		$limit = Configure::read('admindashboardlimit');
149
		$offset = ($page - 1)*$limit;
150
		$url = $this->apihost."dealerPrices/getAllDealerPrice/?limit=$limit&offset=$offset";
151
		$response = $this->make_request($url,null);
152
		$this->set('dealerprices',$response);
153
		$this->set('page',$page);
154
	}
155
 
156
	public function admin_adddp() {
157
		if ($this->request->is('post')) {
158
			$data = $this->request->data['Skuscheme'];
159
			$url = $this->apihost."dealerPrices/addDealerPrice";
160
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
161
			$response = $this->make_request($url,$jsonVar);
162
			if (key($response)) {
163
				$this->Session->setFlash(current($response));
164
				return $this->redirect(array('action' => 'admin_dp'));
165
			} else {
166
				$this->Session->setFlash(current($response));
167
			}			
168
		}
169
	}
170
}