Subversion Repositories SmartDukaan

Rev

Rev 21038 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
14394 anikendra 1
<?php
2
App::uses('AppController', 'Controller');
3
/**
4
 * Exceptionalnlcs Controller
5
 *
6
 * @property Exceptionalnlc $Exceptionalnlc
7
 * @property PaginatorComponent $Paginator
8
 */
9
class ReportsController 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
	public function admin_orders() {
25
		$page = $this->request->query('page');
26
		if(!isset($page)){
27
			$page = 1;
28
		}
29
		$limit = Configure::read('admindashboardlimit');
30
		$params = array(
31
			'fields' => array('_id','subOrders','storeId', 'userId', 'merchantOrderId'),
32
			// 'conditions' => array('source_id' => array('$ne' => 0)),
33
			'order' => array('_id' => -1),
34
			'limit' => $limit,
35
			'page' => $page,
36
		);
37
		$orders = $this->Report->find('all', $params);
38
		// $this->loadModel('Category');
39
		// $categories = $this->Category->find('list');
40
		// $storemapping = Configure::read('storemapping');
41
		$this->set(compact('orders'));
42
	}	
43
 
44
	public function admin_ordersjson() {	
45
		$this->layout = 'ajax';
46
		$page = $this->request->query('page');
47
		if(!isset($page)){
48
			$page = 1;
49
		}
50
		$limit = $this->request->query('limit');
51
		$limit = Configure::read('admindashboardlimit');
52
		$params = array(
53
			'fields' => array('_id','subOrders','storeId', 'userId', 'merchantOrderId'),
54
			// 'conditions' => array('source_id' => array('$ne' => 0)),
55
			'order' => array('_id' => -1),
56
			'limit' => $limit,
57
			'page' => $page,
58
		);
59
		$orders = $this->Report->find('all', $params);
60
		$result = array('orders'=>$orders);
61
		$this->set(array(
62
		    'result' => $result,
63
		    '_serialize' => array('result')
64
		));
65
		$this->render('/Elements/json');
66
	}
15380 anikendra 67
 
68
	public function admin_activations() {
69
		$data = $this->request->data;
70
		if(!empty($data)){
71
			$date = $data['Report']['date']['year'].'-'.$data['Report']['date']['month'].'-'.$data['Report']['date']['day'];
19852 manas 72
			$otherSql="SELECT a.name, COUNT( r.id ) AS count FROM  `retailerlinks` r LEFT JOIN agents a ON r.agent_id = a.id join users u on r.user_id=u.id WHERE DATE( r.activated ) = '$date' and r.user_id is not null and date(u.activation_time)='$date' GROUP BY a.id";
21039 amit.gupta 73
			$sql = "SELECT DATE(activation_time ) AS date, id, utm_campaign,referrer , COUNT( id ) AS count FROM users WHERE DATE(activation_time) = '$date' AND  (utm_campaign IS NOT NULL OR referrer IS NOT NULL) GROUP BY DATE(activation_time) ,utm_campaign,referrer, id";
15380 anikendra 74
		} else{
19851 manas 75
			$otherSql="SELECT a.name, COUNT( r.id ) AS count FROM  `retailerlinks` r LEFT JOIN agents a ON r.agent_id = a.id join users u on r.user_id=u.id WHERE DATE( r.activated ) = CURDATE( ) and r.user_id is not null and date(u.activation_time)=curdate() GROUP BY a.id";
21038 amit.gupta 76
			$sql = "SELECT DATE(activation_time) AS date, id, utm_campaign,referrer , COUNT( id ) AS count FROM users WHERE  DATE(activation_time) = CURDATE() AND  (utm_campaign IS NOT NULL OR referrer IS NOT NULL) GROUP BY DATE(activation_time) ,utm_campaign,referrer, id";
15380 anikendra 77
		}
78
		$this->loadModel('User');		
79
		$activations = $this->User->query($sql);
15436 manas 80
		foreach ($activations as $key => $value) {
81
			if(isset($value['users']['utm_campaign'])){
82
				#debug($value['users']['utm_campaign']);		
21038 amit.gupta 83
				$val=$value['users']['id'];
84
				$sql = "SELECT name from agents where id = (select agent_id from retailerlinks where user_id=$val);";
15436 manas 85
				$this->loadModel('Agent');	
86
				$agentname = $this->Agent->query($sql);
21038 amit.gupta 87
				$citySql = "SELECT city from retailers where id = (select retailer_id from retailerlinks where user_id=$val);";
15582 manas 88
				$this->loadModel('Retailer');	
89
				$retailerCity = $this->Retailer->query($citySql);
15436 manas 90
				array_push($activations[$key], $agentname[0]['agents']['name']);
15582 manas 91
				array_push($activations[$key], $retailerCity[0]['retailers']['city']);
15436 manas 92
			}else{
93
				#debug($value['users']['referrer']);			
21038 amit.gupta 94
				$val=$value['users']['id'];
95
				$sql1 = "SELECT name from agents where id = (select agent_id from retailerlinks where user_id=$val);";
15436 manas 96
				$this->loadModel('Agent');	
97
				$agentname = $this->Agent->query($sql1);
21038 amit.gupta 98
				$citySql = "SELECT city from retailers where id = (select retailer_id from retailerlinks where user_id=$val);";
15582 manas 99
				$this->loadModel('Retailer');	
100
				$retailerCity = $this->Retailer->query($citySql);
15436 manas 101
				array_push($activations[$key], $agentname[0]['agents']['name']);
15582 manas 102
				array_push($activations[$key], $retailerCity[0]['retailers']['city']);
15436 manas 103
			}
104
		}
15469 manas 105
		$agentActivations = $this->User->query($otherSql);
106
		$this->set('agentActivations',$agentActivations);
15380 anikendra 107
		$this->set(compact('activations','date'));
108
	}
15607 anikendra 109
 
110
	public function admin_brandpreferences_report() {
15621 anikendra 111
		$this->loadModel('BrandPreference');
15607 anikendra 112
		$sql = "SELECT DATE( created ) date, brand, COUNT( id ) count FROM  `brand_preferences` WHERE STATUS =  'show' AND DATEDIFF( NOW( ) , created ) <= 7 GROUP BY  `brand_preferences`.`brand` , DATE( created ) ORDER BY DATE( created ) DESC,count desc";
113
		$brand_preferences = $this->BrandPreference->query($sql);
15621 anikendra 114
		$sql = "SELECT brand, COUNT( id ) count FROM  `brand_preferences` WHERE STATUS =  'show' AND DATEDIFF( NOW( ) , created ) <= 7 GROUP BY  `brand_preferences`.`brand` ORDER BY count desc";
115
		$count = $this->BrandPreference->query($sql);
116
		$this->set(compact('brand_preferences','count'));
15607 anikendra 117
	}
118
 
15621 anikendra 119
	public function admin_brandfilters_report() {		
120
		set_time_limit(180);
121
		$this->loadModel('UserFilter');		
122
		$sql = "select date(created) date,group_concat(filters separator '|') brands from user_filters where type = 'brand' group by date(created) ORDER BY id DESC";
15607 anikendra 123
		$brand_filters = $this->UserFilter->query($sql);
15621 anikendra 124
		$this->set(compact('brand_filters','all'));
15607 anikendra 125
	}
15667 anikendra 126
 
127
	public function admin_dailyupgrades_report() {
128
		$this->loadModel('Device');
129
		$data = $this->request->data;
130
		if(!empty($data)){
131
			$date = $data['Report']['date']['year'].'-'.$data['Report']['date']['month'].'-'.$data['Report']['date']['day'];
132
			$sql = "select count(id) as count,date(created) as date,user_id  from devices where imeinumber in (select imeinumber from devices where date(created) = '$date') group by imeinumber having count(id) > 1 order by id desc";
133
		} else{
134
			$sql = "select count(id) as count,date(created) as date,user_id  from devices where imeinumber in (select imeinumber from devices where date(created) = curdate()) group by imeinumber having count(id) > 1 order by id desc";
135
		}
136
		$device_upgrades = $this->Device->query($sql);
137
		$this->set(compact('device_upgrades'));
138
	}
15718 manas 139
 
140
	public function admin_clicks_report($product=null){
141
		$this->loadModel('Click');
142
		$date = $this->request->query('date');
143
		if($product==null || $product=='search'){	
144
			if(!empty($date)){
15723 manas 145
				$sql = "select count(*) as count,product_name,brand,count(distinct user_id) as countUserId from clicks where length(product_name)>0 and store_product_id>0 and date(created)='$date' group by store_product_id order by count desc";
15718 manas 146
			} else{
15723 manas 147
				$sql = "select count(*) as count,product_name,brand,count(distinct user_id) as countUserId from clicks where length(product_name)>0 and store_product_id>0 and date(created)=curdate() group by store_product_id order by count desc";
15718 manas 148
			}
15901 anikendra 149
			$clicks_count = $this->Click->query($sql);
150
			$this->set(compact('clicks_count'));
15718 manas 151
		}else{
15723 manas 152
			$sql="select count(*) as count,date(created) date,count(distinct user_id) as countUserId from clicks where length(product_name)>0 and store_product_id>0 and product_name ='$product' group by date(created) order by date desc";
15718 manas 153
			$product_count = $this->Click->query($sql);
154
			$this->set(compact('product_count','product'));
155
		}
156
	}
15901 anikendra 157
 
158
	public function admin_productviews_report($product=null) {	
159
		set_time_limit(180);
160
		$this->loadModel('UserUrl');
161
		$this->loadModel('MasterData');
162
		$date = $this->request->query('date');
163
 
164
		if($product==null || $product=='search'){	
165
			if(!empty($date)){
16351 anikendra 166
				$sql = "SELECT DATE( created ) date, count(id) AS count,count(distinct user_id) as countUserId, SUBSTRING_INDEX(SUBSTRING_INDEX( url,  '/', -1 ),'?',1)  AS skuBundleId FROM  `user_urls` WHERE date(created) = '$date' AND url LIKE '%store_products/view%' GROUP BY skuBundleId ORDER BY countUserId DESC,count DESC";
15901 anikendra 167
			} else{
16351 anikendra 168
				$sql = "SELECT DATE( created ) date, count(id) AS count,count(distinct user_id) as countUserId, SUBSTRING_INDEX(SUBSTRING_INDEX( url,  '/', -1 ),'?',1)  AS skuBundleId FROM  `user_urls` WHERE date(created) = curdate() AND url LIKE '%store_products/view%' group by skuBundleId ORDER BY countUserId DESC,count DESC";
15901 anikendra 169
			}
170
			$clicks_count = $this->UserUrl->query($sql);
171
			$this->set(compact('clicks_count'));
172
		} else{
16351 anikendra 173
			$sql = "SELECT DATE( created ) date, count(id) AS count,count(distinct user_id) as countUserId, SUBSTRING_INDEX(SUBSTRING_INDEX( url,  '/', -1 ),  '/', -1 ) AS skuBundleId FROM  `user_urls` WHERE SUBSTRING_INDEX( url,  '/', -1 ) = $product group by date(created) ORDER BY id DESC ";
15901 anikendra 174
			$product_count = $this->UserUrl->query($sql);
175
			$this->set(compact('product_count','product'));
176
		}	
177
		$params = array(
178
			'fields' => array('skuBundleId','brand','source_product_name'),
179
			'conditions' => array('source_id' => array('$ne' => 0)),
180
			'order' => array('_id' => 1),
181
		);
182
		$masterdata = $this->MasterData->find('all', $params);
183
 
184
		foreach ($masterdata as $key => $value) {
185
			$map[$value['MasterData']['skuBundleId']] = array('name'=>$value['MasterData']['source_product_name'],'brand'=>$value['MasterData']['brand']);
186
		}
187
		$this->set(compact('map'));
188
	}
17374 naman 189
 
190
	public function admin_saledetail(){
191
		$date  = date("Y-m-d");
192
		$dt   = new DateTime($date);
193
		$url = $this->apihost."getSaleDetail/".$dt->getTimestamp();
194
		$result = $this->make_request($url,null);
195
		$this->set(compact('result'));
196
	}
197
	public  function getDetails($dateval)
198
	{
199
		$this->autoRender = false;	
200
		$this->request->onlyAllow('ajax');
201
		$dt   = new DateTime($dateval);
202
		$url = $this->apihost."getSaleDetail/".$dt->getTimestamp();
203
		$result = $this->make_request($url,null);
204
		return json_encode($result);
205
	}
19465 naman 206
 
19466 naman 207
	public function admin_pendingapproval($type = null,$id = null,$user_id = null,$amount = null,$rtype = null){
19465 naman 208
		$page = $this->request->query('page');
209
		if(!isset($page)){
210
			$page = 1;
211
		}
212
		$limit = 20;
213
		$offset = ($page - 1)*$limit;
214
		$sendata = array();
215
		if($type != null){
216
			$senddata['user_id'] = $user_id;
217
			$senddata['_id'] = $id;
218
			$senddata['amount'] = $amount;
19468 naman 219
			$senddata['type'] = $rtype;
19498 naman 220
			$senddata['approved_by'] = $this->Auth->user('email');
19465 naman 221
// 			$senddata = '{"user_id" : '.$user_id.' , "_id" : '.$id.'}';
222
			$sendurl = $this->apihost."updateRefundStatus?status=".$type;
223
			$this->make_request($sendurl, json_encode($senddata));
19468 naman 224
 			return $this->redirect(array('action' => 'admin_pendingapproval'));
225
		}		
19465 naman 226
		$url  = $this->apihost."refundToWallet?offset=".$offset."&limit=".$limit."&status=Pending";
227
		$pending = $this->make_request($url, null);;
228
		$this->set(compact('pending','page'));
229
	}
19530 manas 230
 
231
		public function admin_allstatus($type = null,$id = null,$user_id = null,$amount = null,$rtype = null){
232
		$page = $this->request->query('page');
233
		if(!isset($page)){
234
			$page = 1;
235
		}
236
		$limit = 50;
237
		$offset = ($page - 1)*$limit;
238
		$url  = $this->apihost."refundToWallet?offset=".$offset."&limit=".$limit;
239
		$pending = $this->make_request($url, null);;
240
		$this->set(compact('pending','page'));
241
	}
14394 anikendra 242
}