Subversion Repositories SmartDukaan

Rev

Rev 22551 | Rev 22927 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
22551 ashik.ali 1
package com.spice.profitmandi.web.controller;
2
 
3
import java.time.LocalDateTime;
4
import java.util.ArrayList;
5
import java.util.List;
6
 
7
import javax.servlet.http.HttpServletRequest;
8
 
9
import org.slf4j.Logger;
10
import org.slf4j.LoggerFactory;
11
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.stereotype.Controller;
13
import org.springframework.transaction.annotation.Transactional;
14
import org.springframework.ui.Model;
15
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestParam;
18
 
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.common.util.StringUtils;
22
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
23
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
24
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
25
import com.spice.profitmandi.service.wallet.WalletService;
26
import com.spice.profitmandi.web.model.LoginDetails;
27
import com.spice.profitmandi.web.util.CookiesProcessor;
28
import com.spice.profitmandi.web.util.MVCResponseSender;
29
 
30
@Controller
31
@Transactional(rollbackFor = Throwable.class)
32
public class WalletController {
33
 
34
	@Autowired
35
	CookiesProcessor cookiesProcessor;
36
 
37
	@Autowired
38
	MVCResponseSender mvcResponseSender;
39
 
40
	@Autowired
41
	WalletService walletService;
42
 
43
	@Autowired
44
	UserWalletRepository userWalletRepository;
45
 
46
	private static final Logger LOGGER = LoggerFactory.getLogger(WalletController.class);
47
 
48
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
49
	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 Exception{
50
		LoginDetails fofoDetails;
51
		try {
52
			fofoDetails = cookiesProcessor.getCookiesObject(request);
53
		} catch (ProfitMandiBusinessException e) {
54
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
55
			return "response";
56
		}
57
 
58
		UserWallet userWallet = null;
59
		try{
60
			userWallet = userWalletRepository.selectByRetailerId(fofoDetails.getFofoId());
61
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
62
			LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
63
			//return "error";
64
		}
65
 
66
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
67
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
68
 
69
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
70
		try{
71
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
72
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
73
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
74
		}
75
 
76
		long countItems = 0;
77
		try{
78
			countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
79
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
80
			LOGGER.error("UserWallet not found : ",profitMandiBusinessException);
81
		}
82
		model.addAttribute("userWallet", userWallet);
83
		model.addAttribute("walletHistories", userWalletHistories);
84
		model.addAttribute("start", offset + 1);
85
		model.addAttribute("size",countItems);
86
		model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
87
		model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
88
		if (userWalletHistories.size() < limit){
89
			model.addAttribute("end", offset + userWalletHistories.size());
90
		}
91
		else{
92
			model.addAttribute("end", offset + limit);
93
		}
94
		return "wallet-details";
95
	}
96
 
97
	@RequestMapping(value = "/getPaginatedWalletHistory")
98
	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, @RequestParam(name = ProfitMandiConstants.INVOICE_NUMBER, defaultValue="") String invoiceNumber, @RequestParam(name = "searchType", defaultValue = "") String searchType, Model model) throws Exception{
99
		LoginDetails loginDetails;
100
		try {
101
			loginDetails = cookiesProcessor.getCookiesObject(request);
102
		} catch (ProfitMandiBusinessException e) {
103
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
104
			return "response";
105
		}
106
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
107
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
108
 
109
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
110
		try{
111
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
112
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
113
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
114
		}
115
 
116
		//List<FofoOrder> saleHistories = fofoOrderRepository.selectByFofoId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
117
		model.addAttribute("walletHistories", userWalletHistories);
118
		return "wallet-history-paginated";
119
	}
120
 
121
}