Subversion Repositories SmartDukaan

Rev

Rev 13646 | Rev 14098 | 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() {
31
		$url = $this->apihost."discountInfo/getAllSkuSchemeDetails";
32
		$response = $this->make_request($url,null);
33
		$this->set('skuschemes',$response);
34
		// $this->Skuscheme->recursive = 0;
35
		// $this->set('skuschemes', $this->Paginator->paginate());
36
	}
37
 
38
/**
39
 * admin_view method
40
 *
41
 * @throws NotFoundException
42
 * @param string $id
43
 * @return void
44
 */
45
	public function admin_view($id = null) {
46
		if (!$this->Skuscheme->exists($id)) {
47
			throw new NotFoundException(__('Invalid skuscheme'));
48
		}
49
		$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
50
		$this->set('skuscheme', $this->Skuscheme->find('first', $options));
51
	}
52
 
53
/**
54
 * admin_add method
55
 *
56
 * @return void
57
 */
58
	public function admin_add() {
59
		if ($this->request->is('post')) {
13646 anikendra 60
			$data = $this->request->data['Skuscheme'];
61
			$data['startDate'] = 1000*strtotime($data['startDate']);
62
			$data['endDate'] = 1000*strtotime($data['endDate']);
13637 anikendra 63
			$url = $this->apihost."discountInfo/addSkuSchemeDetails";
13646 anikendra 64
			$jsonVar = json_encode($data, JSON_NUMERIC_CHECK );
13637 anikendra 65
			$response = $this->make_request($url,$jsonVar);
66
			if (key($response)) {
67
				$this->Session->setFlash(current($response));
68
				return $this->redirect(array('action' => 'index'));
69
			} else {
70
				$this->Session->setFlash(current($response));
13646 anikendra 71
			}			
13637 anikendra 72
		}
73
	}
74
 
75
/**
76
 * admin_edit method
77
 *
78
 * @throws NotFoundException
79
 * @param string $id
80
 * @return void
81
 */
82
	public function admin_edit($id = null) {
83
		if (!$this->Skuscheme->exists($id)) {
84
			throw new NotFoundException(__('Invalid skuscheme'));
85
		}
86
		if ($this->request->is(array('post', 'put'))) {
87
			if ($this->Skuscheme->save($this->request->data)) {
88
				$this->Session->setFlash(__('The skuscheme has been saved.'));
89
				return $this->redirect(array('action' => 'index'));
90
			} else {
91
				$this->Session->setFlash(__('The skuscheme could not be saved. Please, try again.'));
92
			}
93
		} else {
94
			$options = array('conditions' => array('Skuscheme.' . $this->Skuscheme->primaryKey => $id));
95
			$this->request->data = $this->Skuscheme->find('first', $options);
96
		}
97
	}
98
 
99
/**
100
 * admin_delete method
101
 *
102
 * @throws NotFoundException
103
 * @param string $id
104
 * @return void
105
 */
106
	public function admin_delete($id = null) {
107
		$this->Skuscheme->id = $id;
108
		if (!$this->Skuscheme->exists()) {
109
			throw new NotFoundException(__('Invalid skuscheme'));
110
		}
111
		$this->request->onlyAllow('post', 'delete');
112
		if ($this->Skuscheme->delete()) {
113
			$this->Session->setFlash(__('The skuscheme has been deleted.'));
114
		} else {
115
			$this->Session->setFlash(__('The skuscheme could not be deleted. Please, try again.'));
116
		}
117
		return $this->redirect(array('action' => 'index'));
118
	}}