Subversion Repositories SmartDukaan

Rev

Rev 16811 | Rev 16873 | Go to most recent revision | Details | Compare with Previous | 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
 
16811 manas 199
	public function admin_appwise(){
16773 manas 200
		$this->AppTransaction->recursive = -1;
16811 manas 201
		$type = $this->request->query('date');
202
		$date_from = $this->request->query('date_from');
203
		$date_to = $this->request->query('date_to');
204
		if(!isset($type) && !isset($date_from) && !isset($date_to)){
205
			$date = date('Y-m-d',time());		
206
			$this->Paginator->settings = array(
16773 manas 207
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
16811 manas 208
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
209
	    	'order' => 'count desc' ,
16773 manas 210
	    	'group' => 'app_id'
16811 manas 211
	  		);
212
		  	$approvedCounts =  $this->Paginator->paginate();
213
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
214
		  	$approved = $this->AppTransaction->query($sql);
215
		  	foreach ($approved as $key => $value1) {
216
		  		$app_id=$value1['app_transactions']['app_id'];
217
		  		$value22=$value1['0']['count(1)'];
218
		  		foreach ($approvedCounts as $key2 => $value) {
219
					if($app_id==$value['AppTransaction']['app_id']){
220
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
221
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
222
					}
223
				}
16773 manas 224
			}
225
		}
16811 manas 226
		else if($type=='yesterday'){
227
			$date = date('Y-m-d',time()-86400);		
228
			$this->Paginator->settings = array(
229
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
230
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
231
	    	'order' => 'count desc' ,
232
	    	'group' => 'app_id'
233
	  		);
234
		  	$approvedCounts =  $this->Paginator->paginate();
235
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
236
		  	$approved = $this->AppTransaction->query($sql);
237
		  	foreach ($approved as $key => $value1) {
238
		  		$app_id=$value1['app_transactions']['app_id'];
239
		  		$value22=$value1['0']['count(1)'];
240
		  		foreach ($approvedCounts as $key2 => $value) {
241
					if($app_id==$value['AppTransaction']['app_id']){
242
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
243
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
244
					}
245
				}
246
			}	
247
		}else if(isset($date_from) && isset($date_to)){
248
			$this->Paginator->settings = array(
249
			'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
250
	    	'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to)),
251
	    	'order' => 'count desc' ,
252
	    	'group' => 'app_id'
253
	  		);
254
		  	$approvedCounts =  $this->Paginator->paginate();
255
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time) BETWEEN '$date_from' and '$date_to' and payout_description='Approved' group by app_id";
256
		  	$approved = $this->AppTransaction->query($sql);
257
		  	foreach ($approved as $key => $value1) {
258
		  		$app_id=$value1['app_transactions']['app_id'];
259
		  		$value22=$value1['0']['count(1)'];
260
		  		foreach ($approvedCounts as $key2 => $value) {
261
					if($app_id==$value['AppTransaction']['app_id']){
262
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
263
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
264
					}
265
				}
266
			}		
267
		}else{
268
			$date = date('Y-m-d',time());		
269
			$this->Paginator->settings = array(
270
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
271
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
272
	    	'order' => 'count desc' ,
273
	    	'group' => 'app_id'
274
	  		);
275
		  	$approvedCounts =  $this->Paginator->paginate();
276
		  	$sql="SELECT app_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by app_id";
277
		  	$approved = $this->AppTransaction->query($sql);
278
		  	foreach ($approved as $key => $value1) {
279
		  		$app_id=$value1['app_transactions']['app_id'];
280
		  		$value22=$value1['0']['count(1)'];
281
		  		foreach ($approvedCounts as $key2 => $value) {
282
					if($app_id==$value['AppTransaction']['app_id']){
283
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
284
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
285
					}
286
				}
287
			}
288
		}
16813 manas 289
	$totalClicks=0;	
290
	$totalApproved=0;
291
	foreach ($approvedCounts as $key => $value) {
292
		$totalClicks+=$value[0]['count'];
293
		if(!(isset($value['AppTransaction']['approved']))){
294
			$totalApproved+=0;
295
		}else{
296
			$totalApproved+=$value['AppTransaction']['approved'];
297
		}
16811 manas 298
	}
16813 manas 299
	$this->set('appTransactions', $approvedCounts);
300
	$this->set('totalClicks', $totalClicks);
301
	$this->set('totalApproved', $totalApproved);
302
}
16773 manas 303
 
16811 manas 304
	public function admin_retailer(){
305
		$this->AppTransaction->recursive = -1;
306
		$type = $this->request->query('date');
307
		$date_from = $this->request->query('date_from');
308
		$date_to = $this->request->query('date_to');
309
		if(!isset($type) && !isset($date_from) && !isset($date_to)){
310
			$date = date('Y-m-d',time());		
311
			$this->Paginator->settings = array(
312
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
313
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
314
	    	'order' => 'count desc' ,
315
	    	'group' => 'retailer_id'
316
	  		);
317
		  	$approvedCounts =  $this->Paginator->paginate();
318
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
319
		  	$approved = $this->AppTransaction->query($sql);
320
		  	foreach ($approved as $key => $value1) {
321
		  		$app_id=$value1['app_transactions']['retailer_id'];
322
		  		$value22=$value1['0']['count(1)'];
323
		  		foreach ($approvedCounts as $key2 => $value) {
324
					if($app_id==$value['AppTransaction']['retailer_id']){
325
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
326
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
327
					}
328
				}
329
			}
330
		}
331
		else if($type=='yesterday'){
332
			$date = date('Y-m-d',time()-86400);		
333
			$this->Paginator->settings = array(
334
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
335
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
336
	    	'order' => 'count desc' ,
337
	    	'group' => 'retailer_id'
338
	  		);
339
		  	$approvedCounts =  $this->Paginator->paginate();
340
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
341
		  	$approved = $this->AppTransaction->query($sql);
342
		  	foreach ($approved as $key => $value1) {
343
		  		$app_id=$value1['app_transactions']['retailer_id'];
344
		  		$value22=$value1['0']['count(1)'];
345
		  		foreach ($approvedCounts as $key2 => $value) {
346
					if($app_id==$value['AppTransaction']['retailer_id']){
347
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
348
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
349
					}
350
				}
351
			}	
352
		}else if(isset($date_from) && isset($date_to)){
353
			$this->Paginator->settings = array(
354
			'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
355
	    	'conditions' => array('Date(AppTransaction.transaction_time) BETWEEN ? AND ?' =>array($date_from, $date_to)),
356
	    	'order' => 'count desc' ,
357
	    	'group' => 'retailer_id'
358
	  		);
359
		  	$approvedCounts =  $this->Paginator->paginate();
360
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time) BETWEEN '$date_from' and '$date_to' and payout_description='Approved' group by retailer_id";
361
		  	$approved = $this->AppTransaction->query($sql);
362
		  	foreach ($approved as $key => $value1) {
363
		  		$app_id=$value1['app_transactions']['retailer_id'];
364
		  		$value22=$value1['0']['count(1)'];
365
		  		foreach ($approvedCounts as $key2 => $value) {
366
					if($app_id==$value['AppTransaction']['retailer_id']){
367
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
368
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
369
					}
370
				}
371
			}		
372
		}else{
373
			$date = date('Y-m-d',time());		
374
			$this->Paginator->settings = array(
375
	    	'fields' => array('AppTransaction.app_id','retailer_id','app_name', 'COUNT(*) AS count'),
376
	    	'conditions' => array('Date(AppTransaction.transaction_time)'=>$date),
377
	    	'order' => 'count desc' ,
378
	    	'group' => 'retailer_id'
379
	  		);
380
		  	$approvedCounts =  $this->Paginator->paginate();
381
		  	$sql="SELECT retailer_id,count(1) from app_transactions where date(transaction_time)='$date' and payout_description='Approved' group by retailer_id";
382
		  	$approved = $this->AppTransaction->query($sql);
383
		  	foreach ($approved as $key => $value1) {
384
		  		$app_id=$value1['app_transactions']['retailer_id'];
385
		  		$value22=$value1['0']['count(1)'];
386
		  		foreach ($approvedCounts as $key2 => $value) {
387
					if($app_id==$value['AppTransaction']['retailer_id']){
388
					 	$approvedCounts[$key2]['AppTransaction']['approved'] = $value22;
389
					 	$approvedCounts[$key2]['AppTransaction']['conversion_percentage']=ceil(($value22/$value[0]['count'])*100);
390
					}
391
				}
392
			}
393
		}
16813 manas 394
	$totalClicks=0;	
395
	$totalApproved=0;
396
	foreach ($approvedCounts as $key => $value) {
397
		$totalClicks+=$value[0]['count'];
398
		if(!(isset($value['AppTransaction']['approved']))){
399
			$totalApproved+=0;
400
		}else{
401
			$totalApproved+=$value['AppTransaction']['approved'];
402
		}
16773 manas 403
	}
16813 manas 404
	$this->set('appTransactions', $approvedCounts);
405
	$this->set('totalClicks', $totalClicks);
406
	$this->set('totalApproved', $totalApproved);
407
	}
16811 manas 408
}