Subversion Repositories SmartDukaan

Rev

Rev 22860 | Go to most recent revision | Details | 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.fofo.FofoOrder;
23
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
24
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
25
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
26
import com.spice.profitmandi.service.wallet.WalletService;
27
import com.spice.profitmandi.web.model.LoginDetails;
28
import com.spice.profitmandi.web.util.CookiesProcessor;
29
import com.spice.profitmandi.web.util.MVCResponseSender;
30
 
31
@Controller
32
@Transactional(rollbackFor = Throwable.class)
33
public class WalletController {
34
 
35
	@Autowired
36
	CookiesProcessor cookiesProcessor;
37
 
38
	@Autowired
39
	MVCResponseSender mvcResponseSender;
40
 
41
	@Autowired
42
	WalletService walletService;
43
 
44
	@Autowired
45
	UserWalletRepository userWalletRepository;
46
 
47
	private static final Logger LOGGER = LoggerFactory.getLogger(WalletController.class);
48
 
49
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
50
	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{
51
		LoginDetails fofoDetails;
52
		try {
53
			fofoDetails = cookiesProcessor.getCookiesObject(request);
54
		} catch (ProfitMandiBusinessException e) {
55
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
56
			return "response";
57
		}
58
 
59
		fofoDetails.setFofoId(483649);
60
 
61
		UserWallet userWallet = null;
62
		try{
63
			userWallet = userWalletRepository.selectByRetailerId(fofoDetails.getFofoId());
64
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
65
			LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
66
			//return "error";
67
		}
68
 
69
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
70
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
71
 
72
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
73
		try{
74
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
75
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
76
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
77
		}
78
 
79
		long countItems = 0;
80
		try{
81
			countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
82
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
83
			LOGGER.error("UserWallet not found : ",profitMandiBusinessException);
84
		}
85
		model.addAttribute("userWallet", userWallet);
86
		model.addAttribute("walletHistories", userWalletHistories);
87
		model.addAttribute("start", offset + 1);
88
		model.addAttribute("size",countItems);
89
		model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
90
		model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
91
		if (userWalletHistories.size() < limit){
92
			model.addAttribute("end", offset + userWalletHistories.size());
93
		}
94
		else{
95
			model.addAttribute("end", offset + limit);
96
		}
97
		return "wallet-details";
98
	}
99
 
100
	@RequestMapping(value = "/getPaginatedWalletHistory")
101
	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{
102
		LoginDetails loginDetails;
103
		try {
104
			loginDetails = cookiesProcessor.getCookiesObject(request);
105
		} catch (ProfitMandiBusinessException e) {
106
			model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
107
			return "response";
108
		}
109
		LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
110
		LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
111
 
112
		List<UserWalletHistory> userWalletHistories = new ArrayList<>();
113
		try{
114
			userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
115
		}catch(ProfitMandiBusinessException profitMandiBusinessException){
116
			LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
117
		}
118
 
119
		//List<FofoOrder> saleHistories = fofoOrderRepository.selectByFofoId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
120
		model.addAttribute("walletHistories", userWalletHistories);
121
		return "wallet-history-paginated";
122
	}
123
 
124
}