Subversion Repositories SmartDukaan

Rev

Rev 14098 | Rev 14225 | 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
 */
52
	public function admin_view($id = null) {
53
		if (!$this->Skuscheme->exists($id)) {
54
			throw new NotFoundException(__('Invalid skuscheme'));
55
		}
56
		$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
57
		$this->set('skuscheme', $this->Skuscheme->find('first', $options));
58
	}
59
 
60
/**
61
 * admin_add method
62
 *
63
 * @return void
64
 */
65
	public function admin_add() {
66
		if ($this->request->is('post')) {
13646 anikendra 67
			$data = $this->request->data['Skuscheme'];
68
			$data['startDate'] = 1000*strtotime($data['startDate']);
69
			$data['endDate'] = 1000*strtotime($data['endDate']);
13637 anikendra 70
			$url = $this->apihost."discountInfo/addSkuSchemeDetails";
13646 anikendra 71
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
13637 anikendra 72
			$response = $this->make_request($url,$jsonVar);
73
			if (key($response)) {
74
				$this->Session->setFlash(current($response));
75
				return $this->redirect(array('action' => 'index'));
76
			} else {
77
				$this->Session->setFlash(current($response));
13646 anikendra 78
			}			
13637 anikendra 79
		}
80
	}
81
 
82
/**
83
 * admin_edit method
84
 *
85
 * @throws NotFoundException
86
 * @param string $id
87
 * @return void
88
 */
89
	public function admin_edit($id = null) {
90
		if (!$this->Skuscheme->exists($id)) {
91
			throw new NotFoundException(__('Invalid skuscheme'));
92
		}
93
		if ($this->request->is(array('post', 'put'))) {
94
			if ($this->Skuscheme->save($this->request->data)) {
95
				$this->Session->setFlash(__('The skuscheme has been saved.'));
96
				return $this->redirect(array('action' => 'index'));
97
			} else {
98
				$this->Session->setFlash(__('The skuscheme could not be saved. Please, try again.'));
99
			}
100
		} else {
101
			$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
102
			$this->request->data = $this->Skuscheme->find('first', $options);
103
		}
104
	}
105
 
106
/**
107
 * admin_delete method
108
 *
109
 * @throws NotFoundException
110
 * @param string $id
111
 * @return void
112
 */
113
	public function admin_delete($id = null) {
114
		$this->Skuscheme->id = $id;
115
		if (!$this->Skuscheme->exists()) {
116
			throw new NotFoundException(__('Invalid skuscheme'));
117
		}
118
		$this->request->onlyAllow('post', 'delete');
119
		if ($this->Skuscheme->delete()) {
120
			$this->Session->setFlash(__('The skuscheme has been deleted.'));
121
		} else {
122
			$this->Session->setFlash(__('The skuscheme could not be deleted. Please, try again.'));
123
		}
124
		return $this->redirect(array('action' => 'index'));
14099 anikendra 125
	}
126
 
127
	public function admin_dp(){		
128
		$page = $this->request->query('page');
129
		if(!isset($page)){
130
			$page = 1;
131
		}
132
		$limit = Configure::read('admindashboardlimit');
133
		$offset = ($page - 1)*$limit;
134
		$url = $this->apihost."dealerPrices/getAllDealerPrice/?limit=$limit&offset=$offset";
135
		$response = $this->make_request($url,null);
136
		$this->set('dealerprices',$response);
137
		$this->set('page',$page);
138
	}
139
 
140
	public function admin_adddp() {
141
		if ($this->request->is('post')) {
142
			$data = $this->request->data['Skuscheme'];
143
			$url = $this->apihost."dealerPrices/addDealerPrice";
144
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
145
			$response = $this->make_request($url,$jsonVar);
146
			if (key($response)) {
147
				$this->Session->setFlash(current($response));
148
				return $this->redirect(array('action' => 'admin_dp'));
149
			} else {
150
				$this->Session->setFlash(current($response));
151
			}			
152
		}
153
	}
154
}