Subversion Repositories SmartDukaan

Rev

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

Rev 23985 Rev 23993
Line 45... Line 45...
45
@Transactional(rollbackFor = Throwable.class)
45
@Transactional(rollbackFor = Throwable.class)
46
public class WalletController {
46
public class WalletController {
47
 
47
 
48
	@Autowired
48
	@Autowired
49
	private CookiesProcessor cookiesProcessor;
49
	private CookiesProcessor cookiesProcessor;
50
	
50
 
51
	@Autowired
51
	@Autowired
52
	private WalletService walletService;
52
	private WalletService walletService;
53
	
53
 
54
	@Autowired
54
	@Autowired
55
	private UserWalletRepository userWalletRepository;
55
	private UserWalletRepository userWalletRepository;
56
	
56
 
57
	@Autowired
57
	@Autowired
58
	private MVCResponseSender mvcResponseSender;
58
	private MVCResponseSender mvcResponseSender;
59
	
59
 
60
	@Autowired
60
	@Autowired
61
	private UserAccountRepository userAccountRepository;
61
	private UserAccountRepository userAccountRepository;
62
 
62
 
63
	@Autowired
63
	@Autowired
64
	JavaMailSender mailSender;
64
	JavaMailSender mailSender;
65
	
-
 
66
	
65
 
67
	@Autowired
66
	@Autowired
68
	private RetailerService retailerService;
67
	private RetailerService retailerService;
69
 
68
 
70
	
-
 
71
	@Autowired
69
	@Autowired
72
	AddWalletRequestRepository addWalletRequestRepository;
70
	AddWalletRequestRepository addWalletRequestRepository;
73
	private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
71
	private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
74
	
72
 
75
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
73
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
-
 
74
	public String dashboard(HttpServletRequest request,
-
 
75
			@RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString,
-
 
76
			@RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString,
-
 
77
			@RequestParam(name = "offset", defaultValue = "0") int offset,
76
	public String dashboard(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
78
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
-
 
79
			throws ProfitMandiBusinessException {
77
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
80
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
78
		
81
 
79
		UserWallet userWallet = null;
82
		UserWallet userWallet = null;
80
		try{
83
		try {
81
			userWallet = userWalletRepository.selectByRetailerId(fofoDetails.getFofoId());
84
			userWallet = userWalletRepository.selectByRetailerId(fofoDetails.getFofoId());
82
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
85
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
83
			LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
86
			LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
84
			//return "error";
87
			// return "error";
85
		}
88
		}
86
		
89
 
87
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
90
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
88
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
91
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
89
		
92
 
90
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
93
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
91
		try{
94
		try {
92
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
95
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(),
-
 
96
					startDateTime, endDateTime, offset, limit);
93
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
97
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
94
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
98
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
95
		}
99
		}
96
		
100
 
97
		long countItems = 0;
101
		long countItems = 0;
98
		try{
102
		try {
99
			countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
103
			countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
100
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
104
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
101
			LOGGER.error("UserWallet not found : ",profitMandiBusinessException);
105
			LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
102
		}
106
		}
103
		model.addAttribute("userWallet", userWallet);
107
		model.addAttribute("userWallet", userWallet);
104
		model.addAttribute("walletHistories", userWalletHistories);
108
		model.addAttribute("walletHistories", userWalletHistories);
105
		model.addAttribute("start", offset + 1);
109
		model.addAttribute("start", offset + 1);
106
		model.addAttribute("size",countItems);
110
		model.addAttribute("size", countItems);
107
		model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
111
		model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
108
		model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
112
		model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
109
		if (userWalletHistories.size() < limit){
113
		if (userWalletHistories.size() < limit) {
110
			model.addAttribute("end", offset + userWalletHistories.size());
114
			model.addAttribute("end", offset + userWalletHistories.size());
111
		}
-
 
112
		else{
115
		} else {
113
			model.addAttribute("end", offset + limit);
116
			model.addAttribute("end", offset + limit);
114
		}
117
		}
115
		return "wallet-details";
118
		return "wallet-details";
116
	}
119
	}
117
	
120
 
118
	@RequestMapping(value = "/getPaginatedWalletHistory")
121
	@RequestMapping(value = "/getPaginatedWalletHistory")
-
 
122
	public String getSaleHistoryPaginated(HttpServletRequest request,
119
	public String getSaleHistoryPaginated(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, Model model) throws ProfitMandiBusinessException{
123
			@RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString,
-
 
124
			@RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString,
-
 
125
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
126
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
-
 
127
			throws ProfitMandiBusinessException {
120
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
128
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
121
		
129
 
122
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
130
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
123
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
131
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
124
 
132
 
125
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
133
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
126
		try{
134
		try {
127
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
135
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(),
-
 
136
					startDateTime, endDateTime, offset, limit);
128
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
137
		} catch (ProfitMandiBusinessException profitMandiBusinessException) {
129
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
138
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
130
		}
139
		}
131
		
140
 
132
		model.addAttribute("walletHistories", userWalletHistories);
141
		model.addAttribute("walletHistories", userWalletHistories);
133
		return "wallet-history-paginated";
142
		return "wallet-history-paginated";
134
	}
143
	}
135
	
144
 
136
	@RequestMapping(value = "/getAddWalletRequest", method = RequestMethod.GET)
145
	@RequestMapping(value = "/getAddWalletRequest", method = RequestMethod.GET)
137
	public String getAddwalletRequest(HttpServletRequest request,
146
	public String getAddwalletRequest(HttpServletRequest request,
138
			@RequestParam(name = "offset", defaultValue = "0") int offset,
147
			@RequestParam(name = "offset", defaultValue = "0") int offset,
139
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
148
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
140
			throws ProfitMandiBusinessException {
-
 
141
		List<AddWalletRequest> walletRequest = null;
149
		List<AddWalletRequest> walletRequest = null;
142
		long size = 0;
150
		long size = 0;
143
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.pending);
151
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.pending);
144
		LOGGER .info("walletRequest" + walletRequest);
152
		LOGGER.info("walletRequest" + walletRequest);
145
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.pending);
153
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.pending);
146
		
154
		if (!walletRequest.isEmpty()) {
147
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
155
			List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
148
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
156
			Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
149
		
157
 
150
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
158
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
151
		model.addAttribute("walletRequest", walletRequest);
159
			model.addAttribute("walletRequest", walletRequest);
152
		model.addAttribute("rStatus","pending");
160
			model.addAttribute("rStatus", "pending");
153
		model.addAttribute("start", offset + 1);
161
			model.addAttribute("start", offset + 1);
154
		model.addAttribute("size", size);
162
			model.addAttribute("size", size);
155
		model.addAttribute("url","/getPaginatedWalletRequest");
163
			model.addAttribute("url", "/getPaginatedWalletRequest");
-
 
164
 
-
 
165
			if (walletRequest.size() < limit) {
-
 
166
				model.addAttribute("end", offset + walletRequest.size());
-
 
167
			} else {
-
 
168
				model.addAttribute("end", offset + limit);
-
 
169
			}
156
 
170
 
157
		if (walletRequest.size() < limit) {
-
 
158
			model.addAttribute("end", offset + walletRequest.size());
-
 
159
		} else {
171
		} else {
160
			model.addAttribute("end", offset + limit);
-
 
161
		}
-
 
162
 
172
 
-
 
173
			model.addAttribute("walletRequest", walletRequest);
-
 
174
			model.addAttribute("size", size);
-
 
175
 
-
 
176
		}
163
		return "add-wallet-request";
177
		return "add-wallet-request";
164
	}
178
	}
165
 
179
 
166
	@RequestMapping(value = "/getPaginatedWalletRequest", method = RequestMethod.GET)
180
	@RequestMapping(value = "/getPaginatedWalletRequest", method = RequestMethod.GET)
167
	public String getPaginatedWalletRequest(HttpServletRequest request,
181
	public String getPaginatedWalletRequest(HttpServletRequest request,
168
			@RequestParam(name = "offset", defaultValue = "0") int offset,
182
			@RequestParam(name = "offset", defaultValue = "0") int offset,
169
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
183
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
170
			throws ProfitMandiBusinessException {
-
 
171
		LOGGER .info("requested offset=[{}], limit = [{}]", offset, limit);
184
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
172
		List<AddWalletRequest> walletRequest = null;
185
		List<AddWalletRequest> walletRequest = null;
173
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.pending);
186
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.pending);
174
		LOGGER.info("walletRequest" + walletRequest);
187
		LOGGER.info("walletRequest" + walletRequest);
-
 
188
		if (!walletRequest.isEmpty()) {
175
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
189
			List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
176
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
190
			Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
177
		
191
 
178
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
192
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
179
		model.addAttribute("walletRequest", walletRequest);
193
			model.addAttribute("walletRequest", walletRequest);
180
		model.addAttribute("rStatus","pending");
194
			model.addAttribute("rStatus", "pending");
181
		model.addAttribute("url","/getPaginatedWalletRequest");
195
			model.addAttribute("url", "/getPaginatedWalletRequest");
-
 
196
 
-
 
197
		} else {
-
 
198
			model.addAttribute("walletRequest", walletRequest);
-
 
199
 
-
 
200
		}
182
 
201
 
183
		return "add-wallet-request-paginated";
202
		return "add-wallet-request-paginated";
184
	}
203
	}
185
	
204
 
186
	@RequestMapping(value = "/getAddWalletApproved", method = RequestMethod.GET)
205
	@RequestMapping(value = "/getAddWalletApproved", method = RequestMethod.GET)
187
	public String getAddwalletRequestApproved(HttpServletRequest request,
206
	public String getAddwalletRequestApproved(HttpServletRequest request,
188
			@RequestParam(name = "offset", defaultValue = "0") int offset,
207
			@RequestParam(name = "offset", defaultValue = "0") int offset,
189
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
208
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
190
			throws ProfitMandiBusinessException {
209
			throws ProfitMandiBusinessException {
191
		List<AddWalletRequest> walletRequest = null;
210
		List<AddWalletRequest> walletRequest = null;
192
		
211
 
193
		long size = 0;
212
		long size = 0;
194
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.approved);
213
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.approved);
195
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.approved);
214
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.approved);
196
		LOGGER.info("walletRequest" + walletRequest);
215
		LOGGER.info("walletRequest" + walletRequest);
-
 
216
		if (!walletRequest.isEmpty()) {
197
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
217
			List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
198
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
218
			Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
199
		
219
 
200
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
220
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
201
		model.addAttribute("walletRequest", walletRequest);
221
			model.addAttribute("walletRequest", walletRequest);
202
		model.addAttribute("start", offset + 1);
222
			model.addAttribute("start", offset + 1);
203
		model.addAttribute("size", size);
223
			model.addAttribute("size", size);
204
		model.addAttribute("url","/getPaginatedWalletApproved");
224
			model.addAttribute("url", "/getPaginatedWalletApproved");
205
 
225
 
206
		if (walletRequest.size() < limit) {
226
			if (walletRequest.size() < limit) {
207
			model.addAttribute("end", offset + walletRequest.size());
227
				model.addAttribute("end", offset + walletRequest.size());
-
 
228
			} else {
-
 
229
				model.addAttribute("end", offset + limit);
-
 
230
			}
208
		} else {
231
		} else {
209
			model.addAttribute("end", offset + limit);
-
 
210
		}
-
 
211
 
232
 
-
 
233
			model.addAttribute("walletRequest", walletRequest);
-
 
234
			model.addAttribute("size", size);
-
 
235
 
-
 
236
		}
212
		return "add-wallet-request";
237
		return "add-wallet-request";
213
	}
238
	}
214
 
239
 
215
	@RequestMapping(value = "/getPaginatedWalletApproved", method = RequestMethod.GET)
240
	@RequestMapping(value = "/getPaginatedWalletApproved", method = RequestMethod.GET)
216
	public String getPaginatedWalletApproved(HttpServletRequest request,
241
	public String getPaginatedWalletApproved(HttpServletRequest request,
217
			@RequestParam(name = "offset", defaultValue = "0") int offset,
242
			@RequestParam(name = "offset", defaultValue = "0") int offset,
218
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
243
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
219
			throws ProfitMandiBusinessException {
244
			throws ProfitMandiBusinessException {
220
		LOGGER .info("requested offset=[{}], limit = [{}]", offset, limit);
245
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
221
		List<AddWalletRequest> walletRequest = null;
246
		List<AddWalletRequest> walletRequest = null;
222
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.approved);
247
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.approved);
223
		LOGGER.info("walletRequest" + walletRequest);
248
		LOGGER.info("walletRequest" + walletRequest);
-
 
249
		if (!walletRequest.isEmpty()) {
224
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
250
			List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
225
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
251
			Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
226
		
252
 
227
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
253
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
228
		model.addAttribute("walletRequest", walletRequest);
254
			model.addAttribute("walletRequest", walletRequest);
229
		model.addAttribute("url","/getPaginatedWalletApproved");
255
			model.addAttribute("url", "/getPaginatedWalletApproved");
-
 
256
		} else {
-
 
257
			model.addAttribute("walletRequest", walletRequest);
230
 
258
 
-
 
259
		}
231
		return "add-wallet-request-paginated";
260
		return "add-wallet-request-paginated";
232
	}
261
	}
233
	
262
 
234
	@RequestMapping(value = "/getAddWalletRequestRejected", method = RequestMethod.GET)
263
	@RequestMapping(value = "/getAddWalletRequestRejected", method = RequestMethod.GET)
235
	public String getAddwalletRequestRejected(HttpServletRequest request,
264
	public String getAddwalletRequestRejected(HttpServletRequest request,
236
			@RequestParam(name = "offset", defaultValue = "0") int offset,
265
			@RequestParam(name = "offset", defaultValue = "0") int offset,
237
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
266
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
238
			throws ProfitMandiBusinessException {
267
			throws ProfitMandiBusinessException {
239
		List<AddWalletRequest> walletRequest = null;
268
		List<AddWalletRequest> walletRequest = null;
240
		
269
 
241
		long size = 0;
270
		long size = 0;
242
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.rejected);
271
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.rejected);
243
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.rejected);
272
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.rejected);
244
		LOGGER.info("walletRequest" + walletRequest);
273
		LOGGER.info("walletRequest" + walletRequest);
-
 
274
		if (!walletRequest.isEmpty()) {
245
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
275
			List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
246
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
276
			Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
247
		
277
 
248
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
278
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
249
		model.addAttribute("walletRequest", walletRequest);
279
			model.addAttribute("walletRequest", walletRequest);
250
		model.addAttribute("start", offset + 1);
280
			model.addAttribute("start", offset + 1);
251
		model.addAttribute("size", size);
281
			model.addAttribute("size", size);
252
		model.addAttribute("url","/getPaginatedWalletRequestRejected");
282
			model.addAttribute("url", "/getPaginatedWalletRequestRejected");
253
 
283
 
254
		if (walletRequest.size() < limit) {
284
			if (walletRequest.size() < limit) {
255
			model.addAttribute("end", offset + walletRequest.size());
285
				model.addAttribute("end", offset + walletRequest.size());
-
 
286
			} else {
-
 
287
				model.addAttribute("end", offset + limit);
-
 
288
			}
256
		} else {
289
		} else {
-
 
290
			model.addAttribute("walletRequest", walletRequest);
257
			model.addAttribute("end", offset + limit);
291
			model.addAttribute("size", size);
258
		}
292
		}
259
 
293
 
260
		return "add-wallet-request";
294
		return "add-wallet-request";
261
	}
295
	}
262
	
-
 
263
	
296
 
264
	@RequestMapping(value = "/getPaginatedWalletRequestRejected", method = RequestMethod.GET)
297
	@RequestMapping(value = "/getPaginatedWalletRequestRejected", method = RequestMethod.GET)
265
	public String getPaginatedWalletRequestRejected(HttpServletRequest request,
298
	public String getPaginatedWalletRequestRejected(HttpServletRequest request,
266
			@RequestParam(name = "offset", defaultValue = "0") int offset,
299
			@RequestParam(name = "offset", defaultValue = "0") int offset,
267
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
300
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
268
			throws ProfitMandiBusinessException {
301
			throws ProfitMandiBusinessException {
269
		LOGGER .info("requested offset=[{}], limit = [{}]", offset, limit);
302
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
270
		List<AddWalletRequest> walletRequest = null;
303
		List<AddWalletRequest> walletRequest = null;
271
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.rejected);
304
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.rejected);
272
		LOGGER.info("walletRequest" + walletRequest);
305
		LOGGER.info("walletRequest" + walletRequest);
-
 
306
		if (!walletRequest.isEmpty()) {
273
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
307
			List<Integer> fofoIds = this.getFofoIdsFromWalletRequest(walletRequest);
274
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
308
			Map<Integer, CustomRetailer> fofoIdsAndRetailerName = retailerService.getFofoRetailers(fofoIds);
275
		
309
 
276
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
310
			model.addAttribute("fofoIdsAndRetailerName", fofoIdsAndRetailerName);
277
		model.addAttribute("walletRequest", walletRequest);
311
			model.addAttribute("walletRequest", walletRequest);
278
		model.addAttribute("url","/getPaginatedWalletRequestRejected");
312
			model.addAttribute("url", "/getPaginatedWalletRequestRejected");
-
 
313
		} else {
-
 
314
			model.addAttribute("walletRequest", walletRequest);
-
 
315
 
-
 
316
		}
279
 
317
 
280
		return "add-wallet-request-paginated";
318
		return "add-wallet-request-paginated";
281
	}
319
	}
-
 
320
 
282
	@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
321
	@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
283
	public String addAmountToWallet(HttpServletRequest request,@RequestParam(name = "id", defaultValue = "0")int id,Model model)
322
	public String addAmountToWallet(HttpServletRequest request, @RequestParam(name = "id", defaultValue = "0") int id,
284
			throws Exception {
323
			Model model) throws Exception {
285
		
324
 
286
		AddWalletRequest addWalletRequest= addWalletRequestRepository.selectById(id);
325
		AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
-
 
326
		if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
287
	    walletService.addAmountToWallet(addWalletRequest.getRetailerId(), id,WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs",addWalletRequest.getAmount());		
327
			walletService.addAmountToWallet(addWalletRequest.getRetailerId(), id, WalletReferenceType.ADVANCE_AMOUNT,
-
 
328
					"ntfs/rgfs", addWalletRequest.getAmount());
288
        addWalletRequest.setStatus(AddWalletRequestStatus.approved);
329
			addWalletRequest.setStatus(AddWalletRequestStatus.approved);
289
        addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
330
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
290
	    addWalletRequestRepository.persist(addWalletRequest);
331
			addWalletRequestRepository.persist(addWalletRequest);
291
	    model.addAttribute("response", mvcResponseSender.createResponseString(true));
332
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
292
		CustomRetailer customRetailer=retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
333
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
293
	    String subject = "Request Approved for "+customRetailer.getBusinessName()+" of Rs."+ addWalletRequest.getAmount();
334
			String subject = "Request Approved for " + customRetailer.getBusinessName() + " of Rs."
-
 
335
					+ addWalletRequest.getAmount();
-
 
336
			String messageText = MessageFormat.format(
294
		String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
337
					"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
295
				new Integer(addWalletRequest.getRetailerId()),customRetailer.getBusinessName(),customRetailer.getEmail(),customRetailer.getMobileNumber(),addWalletRequest.getTransaction_reference(),
338
					new Integer(addWalletRequest.getRetailerId()), customRetailer.getBusinessName(),
-
 
339
					customRetailer.getEmail(), customRetailer.getMobileNumber(),
296
				new Float(addWalletRequest.getAmount()));
340
					addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
297
		
341
 
298
		this.sendMailWithAttachments(subject, messageText);
342
			this.sendMailWithAttachments(subject, messageText);
-
 
343
			return "response";
-
 
344
		} else {
-
 
345
			model.addAttribute("response", mvcResponseSender.createResponseString(false));
299
	    return "response";
346
			return "response";
-
 
347
		}
300
	}
348
	}
301
	
349
 
302
	@RequestMapping(value = "/addAmountToWalletRequestRejected", method = RequestMethod.PUT)
350
	@RequestMapping(value = "/addAmountToWalletRequestRejected", method = RequestMethod.PUT)
303
	public String addAmountToWalletRequestRejected(HttpServletRequest request,@RequestParam(name = "id", defaultValue = "0")int id,Model model)
351
	public String addAmountToWalletRequestRejected(HttpServletRequest request,
304
			throws Exception {
352
			@RequestParam(name = "id", defaultValue = "0") int id, Model model) throws Exception {
305
		
353
 
306
		AddWalletRequest addWalletRequest= addWalletRequestRepository.selectById(id);
354
		AddWalletRequest addWalletRequest = addWalletRequestRepository.selectById(id);
-
 
355
		if (addWalletRequest.getStatus().equals(AddWalletRequestStatus.pending)) {
307
        addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
356
			addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
308
        addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
357
			addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
309
	    addWalletRequestRepository.persist(addWalletRequest);
358
			addWalletRequestRepository.persist(addWalletRequest);
310
	    model.addAttribute("response", mvcResponseSender.createResponseString(true));
359
			model.addAttribute("response", mvcResponseSender.createResponseString(true));
311
		CustomRetailer customRetailer=retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
360
			CustomRetailer customRetailer = retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
312
	    String subject = "Request Rejected for "+customRetailer.getBusinessName()+" of Rs."+ addWalletRequest.getAmount();
361
			String subject = "Request Rejected for " + customRetailer.getBusinessName() + " of Rs."
-
 
362
					+ addWalletRequest.getAmount();
-
 
363
			String messageText = MessageFormat.format(
313
		String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
364
					"User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
314
				new Integer(addWalletRequest.getRetailerId()),customRetailer.getBusinessName(),customRetailer.getEmail(),customRetailer.getMobileNumber(),addWalletRequest.getTransaction_reference(),
365
					new Integer(addWalletRequest.getRetailerId()), customRetailer.getBusinessName(),
-
 
366
					customRetailer.getEmail(), customRetailer.getMobileNumber(),
315
				new Float(addWalletRequest.getAmount()));
367
					addWalletRequest.getTransaction_reference(), new Float(addWalletRequest.getAmount()));
316
		
368
 
317
		this.sendMailWithAttachments(subject, messageText);
369
			this.sendMailWithAttachments(subject, messageText);
-
 
370
			return "response";
-
 
371
		} else {
-
 
372
			model.addAttribute("response", mvcResponseSender.createResponseString(false));
318
	    return "response";
373
			return "response";
-
 
374
		}
319
	}
375
	}
320
	
376
 
321
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
377
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
322
		MimeMessage message = mailSender.createMimeMessage();
378
		MimeMessage message = mailSender.createMimeMessage();
323
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
379
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
324
		String[] email = {"adeel.yazdani@smartdukaan.com","kamini.sharma@smartdukaan.com","care@smartdukaan.com","mohinder.mutreja@smartdukaan.com"};
380
		String[] email = { "adeel.yazdani@smartdukaan.com", "kamini.sharma@smartdukaan.com", "care@smartdukaan.com",
-
 
381
				"mohinder.mutreja@smartdukaan.com" };
325
		helper.setSubject(subject);
382
		helper.setSubject(subject);
326
		helper.setText(messageText);
383
		helper.setText(messageText);
327
		helper.setTo(email);
384
		helper.setTo(email);
328
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
385
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
329
		helper.setFrom(senderAddress);
386
		helper.setFrom(senderAddress);
330
		mailSender.send(message);
387
		mailSender.send(message);
331
 
388
 
332
	}
389
	}
-
 
390
 
333
	private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest)
391
	private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest) {
334
	{
-
 
335
		List<Integer> fofoIds = new ArrayList<>();
392
		List<Integer> fofoIds = new ArrayList<>();
336
		for(AddWalletRequest  walletdetail :walletRequest ) {
393
		for (AddWalletRequest walletdetail : walletRequest) {
337
			fofoIds.add(walletdetail.getRetailerId());
394
			fofoIds.add(walletdetail.getRetailerId());
338
		}
395
		}
339
		return fofoIds;
396
		return fofoIds;
340
	}	
397
	}
341
 
-
 
342
 
398
 
343
}
399
}