Subversion Repositories SmartDukaan

Rev

Rev 20444 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
19874 naman 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ItemcashbacksController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter() {
19
		parent::beforeFilter();
20
//		Configure::load('live');
21
		$this->apihost = Configure::read('pythonapihost');
22
	}
23
/**
24
 * admin_index method
25
 *
26
 * @return void
27
 */
28
	public function admin_index() {
29
		$type = $this->request->query('type');
30
		$search = $this->request->query('search');
31
		$page = $this->request->query('page');
32
		if(!isset($page)){
33
			$page = 1;
34
		}
35
 
36
		$limit = Configure::read('admindashboardlimit');
37
		$offset = ($page - 1)*$limit;
38
		if(isset($type) && !empty($type) && isset($search) && !empty($search))
39
		{
40
			$url = $this->apihost."Catalog/searchProducts/?class=ItemCashBack&".$type."=".$search;
41
		}
42
		else 
43
		{
44
			$url = $this->apihost."getItemCashback?offset=".$offset."&limit=".$limit;
45
		}
46
 
47
// 		$url = $this->apihost."getItemCashback/?limit=$limit&offset=$offset";
48
		$response = $this->make_request($url,null);
49
		$this->set('cashbacks', $response);
50
		$this->set('page',$page);
51
	}
52
 
53
/**
54
 * admin_view method
55
 *
56
 * @throws NotFoundException
57
 * @param string $id
58
 * @return void
59
 */
60
	public function admin_search() {
61
	}
62
 
63
/**
64
 * admin_add method
65
 *
66
 * @return void
67
 */
68
	public function admin_add() {
69
		if ($this->request->is('post')) {
70
			$data = $this->request->data['Itemcashbacks'];
71
			$senddata = array();
72
			$senddata['sku'] = $data['skuId'];
73
			$senddata['cash_back'] = $data['cash_back'];
74
			$senddata['cash_back_status'] = $data['cash_back_status'];
75
			$senddata['cash_back_type'] = $data['cash_back_type'];
76
			if($data['cash_back_type'] == 2)
77
			{
78
				$senddata['cash_back_description'] = "Amount";
79
			}
80
			else{
81
				$senddata['cash_back_description'] = "Percentage";
82
			}
83
// 			debug($senddata);
84
			$url = $this->apihost."getItemCashback";
85
			$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
86
			if ($response['result'] == "success") {
87
					$this->Session->setFlash("Data has been added successfully..");
88
					return $this->redirect(array('action' => 'index'));
89
			} else {
90
				$this->Session->setFlash("Data has not been added");
91
			}
92
 
93
		}
94
	}
95
 
96
/**
97
 * admin_edit method
98
 *
99
 * @throws NotFoundException
100
 * @param string $id
101
 * @return void
102
 */
103
	public function admin_edit($id = null) {
104
 
105
		if ($this->request->is(array('post', 'put'))) {
106
			$data = $this->request->data['Itemcashbacks'];
107
 
108
            $data = $this->request->data['Itemcashbacks'];
109
			$senddata = array();
110
			$senddata['class'] = 'ItemCashBack';
111
			$senddata['oid'] = $data['_id'];
112
			$senddata['sku'] = $data['skuId'];
113
			$senddata['cash_back'] = $data['cash_back'];
114
			$senddata['cash_back_status'] = $data['cash_back_status'];
115
			$senddata['cash_back_type'] = $data['cash_back_type'];
116
			if($data['cash_back_type'] == 2)
117
			{
118
				$senddata['cash_back_description'] = "Amount";
119
			}
120
			else{
121
				$senddata['cash_back_description'] = "Percentage";
122
			}
123
 
124
// 			$url = "http://localhost:8057/getItemCashback?status=update";
125
			$url = $this->apihost."Catalog/updateCollection";
126
			$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
127
 
128
			if (key($response)) {
129
					$this->Session->setFlash(current($response));
130
					return $this->redirect(array('action' => 'index'));
131
			} else {
132
				$this->Session->setFlash(current($response));
133
			}
134
		}
135
		else
136
		{
137
			$url = $this->apihost."getItemCashback?id=".$id;
138
			$response = $this->make_request($url,null);
139
			$Cashbacks = $response[0];
140
			$this->set(compact('Cashbacks'));
141
		}
142
	}
143
 
144
/**
145
 * admin_delete method
146
 *
147
 * @throws NotFoundException
148
 * @param string $id
149
 * @return void
150
 */
151
 
152
	public function admin_delete($id = null) {	
153
 
154
// 		$url = $this->apihost."deleteItemCashback/".$id;
155
		$senddata['class'] = "ItemCashBack";
156
		$senddata['oid'] = $id;
157
		$url  = $this->apihost."Catalog/deleteDocument";
158
// 		$url = "http://localhost:8057/getItemCashback?itemid=".$id."&type=delete";
159
		$response = $this->make_request($url,json_encode($senddata,JSON_NUMERIC_CHECK));
160
		if (key($response)) {
161
				$this->Session->setFlash(current($response));
162
				return $this->redirect(array('action' => 'index'));
163
		} else {
164
			$this->Session->setFlash(current($response));
165
		}
166
 
167
	}	
168
 
169
}