Subversion Repositories SmartDukaan

Rev

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

Rev 15188 Rev 15217
Line 42... Line 42...
42
		$activestores = Configure::read('activestores');
42
		$activestores = Configure::read('activestores');
43
		$amazonorderurl = Configure::read('amazonorderurl');
43
		$amazonorderurl = Configure::read('amazonorderurl');
44
		$this->set(compact('ignoredFields','page','totalPages','userId','activestores','storemapping','amazonorderurl'));
44
		$this->set(compact('ignoredFields','page','totalPages','userId','activestores','storemapping','amazonorderurl'));
45
	}
45
	}
46
 
46
 
-
 
47
	public function by($userId) {
-
 
48
		$page = $this->request->query('page');
-
 
49
		$page = isset($page)?$page:1;		
-
 
50
		$this->layout = "innerpages";
-
 
51
		$url = $this->apihost."storeorder/user/".$userId."?page=$page&window=10";
-
 
52
		$response = $this->make_request($url,null);
-
 
53
		$totalPages = $response['totalPages'];
-
 
54
		if(!empty($response['data'])){
-
 
55
			$this->set('orders',$response['data']);
-
 
56
		}
-
 
57
		$ignoredFields = array('imgUrl','status','productTitle','estimatedDeliveryDate','productCode','merchantSubOrderId','productUrl','closed','tracingkUrl','detailedStatus');
-
 
58
		$storemapping = Configure::read('storemapping');
-
 
59
		$activestores = Configure::read('activestores');
-
 
60
		$amazonorderurl = Configure::read('amazonorderurl');
-
 
61
		$this->set(compact('ignoredFields','page','totalPages','userId','activestores','storemapping','amazonorderurl'));
-
 
62
	}
-
 
63
 
47
	public function pendingcashbacks() {
64
	public function pendingcashbacks() {
48
		$userId = $this->request->query('user_id');
65
		$userId = $this->request->query('user_id');
49
		if(isset($userId) && !empty($userId)){
66
		if(isset($userId) && !empty($userId)){
50
			$this->loadModel('User');
67
			$this->loadModel('User');
51
			$dbuser = $this->User->findById($userId);
68
			$dbuser = $this->User->findById($userId);
Line 105... Line 122...
105
				$creditedOrders[$value['batch']] = $this->make_request($url,null);
122
				$creditedOrders[$value['batch']] = $this->make_request($url,null);
106
				// debug($creditedOrders);
123
				// debug($creditedOrders);
107
			}
124
			}
108
		}
125
		}
109
		$storemapping = Configure::read('storemapping');
126
		$storemapping = Configure::read('storemapping');
-
 
127
		$activestores = Configure::read('activestores');
-
 
128
		if(!empty($response['data'])){
-
 
129
			$this->set(compact('storemapping','activestores','pendingOrders','approvedOrders','creditedOrders','pendingCashbacks','creditedCashbacks','pendingAmount','approvedAmount','creditedAmount'));
-
 
130
		}
-
 
131
	}
-
 
132
 
-
 
133
	public function usercashbacks($userId) {		
-
 
134
		$this->layout = "innerpages";
-
 
135
		$url = $this->apihost."storeorder/user/".$userId."?page=1&window=50";
-
 
136
		$response = $this->make_request($url,null);
-
 
137
		// debug($response);
-
 
138
		$creditedOrders = $pendingOrders = $approvedOrders = array();
-
 
139
		$creditedAmount = $pendingAmount = $approvedAmount = 0;
-
 
140
		if(!empty($response['data'])){
-
 
141
			foreach ($response['data'] as $key => $order) {
-
 
142
				if(!empty($order['subOrders'])){
-
 
143
					foreach ($order['subOrders'] as $key => $suborder) {
-
 
144
						$suborder['storeId'] = $order['storeId'];
-
 
145
						if($order['storeId']!=4){
-
 
146
							$suborder['merchantOrderId'] = $order['merchantOrderId'];
-
 
147
						} else {
-
 
148
							$suborder['merchantOrderId'] = $suborder['merchantSubOrderId'];
-
 
149
						}
-
 
150
						if(!empty($order['orderTrackingUrl'])){
-
 
151
							$suborder['orderSuccessUrl'] = $order['orderTrackingUrl'];
-
 
152
						}
-
 
153
						switch($suborder['cashBackStatus']){
-
 
154
							// case 'Credited to wallet'://Credited
-
 
155
							// $creditedOrders[] = $suborder;
-
 
156
							// break;
-
 
157
							case 'Approved':
-
 
158
							$approvedOrders[] = $suborder;
-
 
159
							$approvedAmount += $suborder['cashBackAmount'];
-
 
160
							break;
-
 
161
							case 'Pending':
-
 
162
							$pendingOrders[] = $suborder;
-
 
163
							// $pendingAmount += $suborder['cashBackAmount'];
-
 
164
						}
-
 
165
					}
-
 
166
				}
-
 
167
			}
-
 
168
		}
-
 
169
		$url = $this->apihost.'pending-cashbacks/user/'.$userId;
-
 
170
		$result = $this->make_request($url,null);
-
 
171
		$pendingAmount = $result['amount'];
-
 
172
		//Get pending cashbacks
-
 
173
		$url = $this->apihost.'pending-refunds/user/'.$userId;
-
 
174
		$pendingCashbacks = $this->make_request($url,null);
-
 
175
		//Get credited cashbacks
-
 
176
		$url = $this->apihost.'refund/user/'.$userId;
-
 
177
		$creditedCashbacks = $this->make_request($url,null);
-
 
178
 
-
 
179
		if(!empty($creditedCashbacks)){
-
 
180
			foreach ($creditedCashbacks['data'] as $key => $value) {
-
 
181
				$creditedAmount += $value['userAmount'];				
-
 
182
				$data = array('subOrders.batchId'=>$value['batch']);
-
 
183
				$jsonVar = json_encode($data);
-
 
184
				$url = $this->apihost."storeorder/user/".$userId."?page=1&window=50&searchMap=$jsonVar";
-
 
185
				$creditedOrders[$value['batch']] = $this->make_request($url,null);
-
 
186
				// debug($creditedOrders);
-
 
187
			}
-
 
188
		}
-
 
189
		$storemapping = Configure::read('storemapping');
110
		$activestores = Configure::read('activestores');
190
		$activestores = Configure::read('activestores');
111
		if(!empty($response['data'])){
191
		if(!empty($response['data'])){
112
			$this->set(compact('storemapping','activestores','pendingOrders','approvedOrders','creditedOrders','pendingCashbacks','creditedCashbacks','pendingAmount','approvedAmount','creditedAmount'));
192
			$this->set(compact('storemapping','activestores','pendingOrders','approvedOrders','creditedOrders','pendingCashbacks','creditedCashbacks','pendingAmount','approvedAmount','creditedAmount'));
113
		}
193
		}
114
	}
194
	}