Subversion Repositories SmartDukaan

Rev

Rev 18848 | Rev 19046 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 18848 Rev 18856
Line 1165... Line 1165...
1165
		if(!isset($page)){
1165
		if(!isset($page)){
1166
			$page = 1;
1166
			$page = 1;
1167
		}
1167
		}
1168
		$limit = 20;
1168
		$limit = 20;
1169
		$offset = ($page - 1)*$limit;
1169
		$offset = ($page - 1)*$limit;
-
 
1170
		$this->loadModel('UserAccount');
-
 
1171
		
-
 
1172
		if($cuid!= 0){
-
 
1173
			$opt = array('conditions'=>array('user_id'=>$cuid,'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');
-
 
1174
			$usId = $this->UserAccount->find('first',$opt);
-
 
1175
			$cuid = $usId['UserAccount']['account_key'];			
-
 
1176
		}
-
 
1177
 
1170
		$url = Configure::read('saholicapihost').'counter!getCreditHistory?userId='.$cuid.'&limit='.$limit.'&offset='.$offset;
1178
		$url = Configure::read('saholicapihost').'counter!getCreditHistory?userId='.$cuid.'&limit='.$limit.'&offset='.$offset;
1171
		$response = $this->make_request ( $url, null );
1179
		$response = $this->make_request ( $url, null );
1172
		$creditHistory = $response['response']['creditHistory'];
1180
		$creditHistory = $response['response']['creditHistory'];
1173
		$hasMore = $response['response']['hasMore'];
1181
		$hasMore = $response['response']['hasMore'];
1174
		$totalCount = $response['response']['totalCount'];
1182
		$totalCount = $response['response']['totalCount'];
1175
		$this->loadModel('UserAccount');
-
 
-
 
1183
		
1176
		$usersMap = array();
1184
		$usersMap = array();
1177
		foreach($creditHistory AS $creditH){
1185
		foreach($creditHistory AS $creditH){
1178
			if (!array_key_exists($creditH['user_id'], $usersMap)) {
1186
			if (!array_key_exists($creditH['user_id'], $usersMap)) {
1179
				$options = array('conditions'=>array('account_key'=>$creditH['user_id'],'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'user_id');
1187
				$options = array('conditions'=>array('account_key'=>$creditH['user_id'],'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'user_id');
1180
				$userId = $this->UserAccount->find('first',$options);
1188
				$userId = $this->UserAccount->find('first',$options);
1181
				$userId = $userId['UserAccount']['user_id'];
1189
				$userId = $userId['UserAccount']['user_id'];
1182
				$usersMap[$creditH['user_id']]=$userId;
1190
				$usersMap[$creditH['user_id']]=$userId;
1183
			}
1191
			}
1184
		}	
1192
		}
1185
		$this->set(compact('creditHistory','usersMap','hasMore','totalCount','page'));
1193
		$this->set(compact('creditHistory','usersMap','hasMore','totalCount','page'));
1186
	}
1194
	}
1187
	
1195
	
1188
	public function admin_loanhistory(){
1196
	public function admin_loanhistory($cuid = 0){
-
 
1197
		$page = $this->request->query('page');
-
 
1198
		if(!isset($page)){
-
 
1199
			$page = 1;
-
 
1200
		}
-
 
1201
		$limit = 20;
-
 
1202
		$offset = ($page - 1)*$limit;
-
 
1203
		$this->loadModel('UserAccount');
-
 
1204
		if($cuid!= 0){
-
 
1205
			$opt = array('conditions'=>array('user_id'=>$cuid,'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'account_key');
-
 
1206
			$usId = $this->UserAccount->find('first',$opt);
-
 
1207
			$cuid = $usId['UserAccount']['account_key'];
-
 
1208
		}
-
 
1209
		
1189
		$url = Configure::read('saholicapihost').'counter!getLoanHistory?limit=0&offset=0';
1210
		$url = Configure::read('saholicapihost').'counter!getLoanHistory?userId='.$cuid.'&limit='.$limit.'&offset='.$offset;
-
 
1211
		
1190
		$response = $this->make_request ( $url, null );
1212
		$response = $this->make_request ( $url, null );
1191
		$loanHistory = $response['response']['loanHistory'];
1213
		$loanHistory = $response['response']['loanHistory'];
1192
		$hasMore = $response['response']['hasMore'];
1214
		$hasMore = $response['response']['hasMore'];
1193
		$totalCount = $response['response']['totalCount'];
1215
		$totalCount = $response['response']['totalCount'];
1194
		$this->loadModel('UserAccount');
-
 
-
 
1216
		
1195
		$usersMap = array();
1217
		$usersMap = array();
1196
		foreach($loanHistory AS $loanH){
1218
		foreach($loanHistory AS $loanH){
1197
			if (!array_key_exists($loanH['user_id'], $usersMap)) {
1219
			if (!array_key_exists($loanH['user_id'], $usersMap)) {
1198
				$options = array('conditions'=>array('account_key'=>$loanH['user_id'],'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'user_id');
1220
				$options = array('conditions'=>array('account_key'=>$loanH['user_id'],'account_type'=>'saholic'),'recursive'=>-1,'fields'=>'user_id');
1199
				$userId = $this->UserAccount->find('first',$options);
1221
				$userId = $this->UserAccount->find('first',$options);
1200
				$userId = $userId['UserAccount']['user_id'];
1222
				$userId = $userId['UserAccount']['user_id'];
1201
				$usersMap[$loanH['user_id']]=$userId;
1223
				$usersMap[$loanH['user_id']]=$userId;
1202
			}
1224
			}
1203
		}
1225
		}
1204
					
1226
					
1205
		$this->set(compact('loanHistory','usersMap','hasMore','totalCount'));
1227
		$this->set(compact('loanHistory','usersMap','hasMore','totalCount','page'));
1206
	}
1228
	}
1207
}
1229
}