Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
16773 manas 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * AppTransactions Controller
5
 *
6
 * @property AppTransaction $AppTransaction
7
 * @property PaginatorComponent $Paginator
8
 */
9
class AppTransactionsController extends AppController {
10
 
11
/**
12
 * Components
13
 *
14
 * @var array
15
 */
16
	public $components = array('Paginator');
17
 
18
	public function beforeFilter()
19
    {
20
       parent::beforeFilter();
21
       $this->Paginator->settings=array(
22
              'limit'=>100
23
       );
24
    } 
25
/**
26
 * index method
27
 *
28
 * @return void
29
 */
30
	public function index() {
31
		$this->AppTransaction->recursive = 0;
32
		$this->set('appTransactions', $this->Paginator->paginate());
33
	}
34
 
35
/**
36
 * view method
37
 *
38
 * @throws NotFoundException
39
 * @param string $id
40
 * @return void
41
 */
42
	public function view($id = null) {
43
		if (!$this->AppTransaction->exists($id)) {
44
			throw new NotFoundException(__('Invalid app transaction'));
45
		}
46
		$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
47
		$this->set('appTransaction', $this->AppTransaction->find('first', $options));
48
	}
49
 
50
/**
51
 * add method
52
 *
53
 * @return void
54
 */
55
	public function add() {
56
		if ($this->request->is('post')) {
57
			$this->AppTransaction->create();
58
			if ($this->AppTransaction->save($this->request->data)) {
59
				$this->Session->setFlash(__('The app transaction has been saved.'));
60
				return $this->redirect(array('action' => 'index'));
61
			} else {
62
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
63
			}
64
		}
65
	}
66
 
67
/**
68
 * edit method
69
 *
70
 * @throws NotFoundException
71
 * @param string $id
72
 * @return void
73
 */
74
	public function edit($id = null) {
75
		if (!$this->AppTransaction->exists($id)) {
76
			throw new NotFoundException(__('Invalid app transaction'));
77
		}
78
		if ($this->request->is(array('post', 'put'))) {
79
			if ($this->AppTransaction->save($this->request->data)) {
80
				$this->Session->setFlash(__('The app transaction has been saved.'));
81
				return $this->redirect(array('action' => 'index'));
82
			} else {
83
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
84
			}
85
		} else {
86
			$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
87
			$this->request->data = $this->AppTransaction->find('first', $options);
88
		}
89
	}
90
 
91
/**
92
 * delete method
93
 *
94
 * @throws NotFoundException
95
 * @param string $id
96
 * @return void
97
 */
98
	public function delete($id = null) {
99
		$this->AppTransaction->id = $id;
100
		if (!$this->AppTransaction->exists()) {
101
			throw new NotFoundException(__('Invalid app transaction'));
102
		}
103
		$this->request->onlyAllow('post', 'delete');
104
		if ($this->AppTransaction->delete()) {
105
			$this->Session->setFlash(__('The app transaction has been deleted.'));
106
		} else {
107
			$this->Session->setFlash(__('The app transaction could not be deleted. Please, try again.'));
108
		}
109
		return $this->redirect(array('action' => 'index'));
110
	}
111
 
112
/**
113
 * admin_index method
114
 *
115
 * @return void
116
 */
117
	public function admin_index() {
118
		$this->AppTransaction->recursive = 0;
119
		$this->set('appTransactions', $this->Paginator->paginate(array('AppTransaction.' . $this->AppTransaction.'payout_description'=>'Approved')));
120
	}
121
 
122
/**
123
 * admin_view method
124
 *
125
 * @throws NotFoundException
126
 * @param string $id
127
 * @return void
128
 */
129
	public function admin_view($id = null) {
130
		if (!$this->AppTransaction->exists($id)) {
131
			throw new NotFoundException(__('Invalid app transaction'));
132
		}
133
		$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
134
		$this->set('appTransaction', $this->AppTransaction->find('first', $options));
135
	}
136
 
137
/**
138
 * admin_add method
139
 *
140
 * @return void
141
 */
142
	public function admin_add() {
143
		if ($this->request->is('post')) {
144
			$this->AppTransaction->create();
145
			if ($this->AppTransaction->save($this->request->data)) {
146
				$this->Session->setFlash(__('The app transaction has been saved.'));
147
				return $this->redirect(array('action' => 'index'));
148
			} else {
149
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
150
			}
151
		}
152
	}
153
 
154
/**
155
 * admin_edit method
156
 *
157
 * @throws NotFoundException
158
 * @param string $id
159
 * @return void
160
 */
161
	public function admin_edit($id = null) {
162
		if (!$this->AppTransaction->exists($id)) {
163
			throw new NotFoundException(__('Invalid app transaction'));
164
		}
165
		if ($this->request->is(array('post', 'put'))) {
166
			if ($this->AppTransaction->save($this->request->data)) {
167
				$this->Session->setFlash(__('The app transaction has been saved.'));
168
				return $this->redirect(array('action' => 'index'));
169
			} else {
170
				$this->Session->setFlash(__('The app transaction could not be saved. Please, try again.'));
171
			}
172
		} else {
173
			$options = array('conditions' => array('AppTransaction.' . $this->AppTransaction->primaryKey => $id));
174
			$this->request->data = $this->AppTransaction->find('first', $options);
175
		}
176
	}
177
 
178
/**
179
 * admin_delete method
180
 *
181
 * @throws NotFoundException
182
 * @param string $id
183
 * @return void
184
 */
185
	public function admin_delete($id = null) {
186
		$this->AppTransaction->id = $id;
187
		if (!$this->AppTransaction->exists()) {
188
			throw new NotFoundException(__('Invalid app transaction'));
189
		}
190
		$this->request->onlyAllow('post', 'delete');
191
		if ($this->AppTransaction->delete()) {
192
			$this->Session->setFlash(__('The app transaction has been deleted.'));
193
		} else {
194
			$this->Session->setFlash(__('The app transaction could not be deleted. Please, try again.'));
195
		}
196
		return $this->redirect(array('action' => 'index'));
197
	}
198
 
199
	public function admin_retailer(){
200
 
201
		$this->AppTransaction->recursive = -1;
202
		#$data = $this->request->data;
203
		#$date = date('Y-m-d',time()-86400);		
204
		$this->Paginator->settings = array(
205
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
206
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>'2015-08-28'),
207
	    	'group' => 'app_id'
208
	  	);
209
	  	$approvedCounts =  $this->Paginator->paginate();
210
	  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='2015-08-28' and payout_description='Approved' group by app_id";
211
	  	$approved = $this->AppTransaction->query($sql);
212
	  	#debug($approved);
213
	  	foreach ($approved as $key => $value1) {
214
	  		$app_id=$value1['app_transactions']['app_id'];
215
	  		$value22=$value1['0']['count(1)'];
216
	  		foreach ($approvedCounts as $key2 => $value) {
217
				 debug($value);
218
				 if($app_id==$value['AppTransaction']['app_id']){
219
				 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
220
				 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value['AppTransaction']['count'])*100);
221
				 }else{
222
				 	$approvedCounts[$key2]['AppTransaction']['approved'] = 0;
223
				 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=0;
224
				 }
225
			}
226
			#debug($value['AppTransaction']['app_name']);
227
		}
228
		// $this->Paginator->settings = array(
229
	 //    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
230
	 //    	'conditions' => array('AppTransaction.payout_description'=>'Approved','Date(AppTransaction.transaction_time)'=>$date),
231
	 //    	'group' => 'app_id'
232
	 //  	);
233
 
234
		// debug($approvedCounts);
235
	    #$this->set('items', $this->Paginator->paginate('Item'));
236
	#	$this->Paginator->paginate(array('AppTransaction.' . $this->AppTransaction.'payout_description'=>'Approved'))
237
		$this->set('appTransactions', $approvedCounts);
238
	}
239
}