| 23612 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.io.IOException;
|
| 30162 |
manish |
4 |
import java.time.LocalDate;
|
|
|
5 |
import java.time.LocalDateTime;
|
| 33067 |
shampa |
6 |
import java.time.LocalTime;
|
| 31377 |
tejbeer |
7 |
import java.time.format.DateTimeFormatter;
|
| 26298 |
tejbeer |
8 |
import java.util.ArrayList;
|
| 30162 |
manish |
9 |
import java.util.Arrays;
|
| 26164 |
amit.gupta |
10 |
import java.util.HashMap;
|
| 26298 |
tejbeer |
11 |
import java.util.List;
|
| 26063 |
amit.gupta |
12 |
import java.util.Map;
|
| 23612 |
amit.gupta |
13 |
|
|
|
14 |
import javax.servlet.http.HttpServletRequest;
|
|
|
15 |
|
| 33067 |
shampa |
16 |
import com.spice.profitmandi.dao.model.SchemePayoutReportModel;
|
| 23612 |
amit.gupta |
17 |
import org.apache.http.HttpResponse;
|
| 23654 |
amit.gupta |
18 |
import org.apache.logging.log4j.LogManager;
|
|
|
19 |
import org.apache.logging.log4j.Logger;
|
| 23637 |
amit.gupta |
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23612 |
amit.gupta |
21 |
import org.springframework.core.io.InputStreamResource;
|
|
|
22 |
import org.springframework.http.HttpHeaders;
|
|
|
23 |
import org.springframework.http.HttpStatus;
|
|
|
24 |
import org.springframework.http.ResponseEntity;
|
|
|
25 |
import org.springframework.stereotype.Controller;
|
| 23637 |
amit.gupta |
26 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
27 |
import org.springframework.ui.Model;
|
| 23612 |
amit.gupta |
28 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 26063 |
amit.gupta |
29 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23612 |
amit.gupta |
30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 30162 |
manish |
32 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23612 |
amit.gupta |
33 |
|
|
|
34 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 28106 |
amit.gupta |
36 |
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
|
| 23612 |
amit.gupta |
37 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 30162 |
manish |
38 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 26298 |
tejbeer |
39 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 30162 |
manish |
40 |
import com.spice.profitmandi.dao.model.CollectionSummary;
|
| 26298 |
tejbeer |
41 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
42 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 28106 |
amit.gupta |
43 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23784 |
ashik.ali |
44 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 30162 |
manish |
45 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 23798 |
amit.gupta |
46 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 30162 |
manish |
47 |
import com.spice.profitmandi.service.order.OrderService;
|
| 23612 |
amit.gupta |
48 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
49 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
50 |
|
|
|
51 |
@Controller
|
| 26298 |
tejbeer |
52 |
@Transactional(rollbackFor = Throwable.class)
|
| 23612 |
amit.gupta |
53 |
public class ReportsController {
|
| 26298 |
tejbeer |
54 |
|
| 23637 |
amit.gupta |
55 |
@Autowired
|
| 23784 |
ashik.ali |
56 |
private RoleRepository roleRepository;
|
| 26298 |
tejbeer |
57 |
|
| 23764 |
amit.gupta |
58 |
@Autowired
|
| 26298 |
tejbeer |
59 |
private CookiesProcessor cookiesProcessor;
|
| 28106 |
amit.gupta |
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
private FofoStoreRepository fofoStoreRepository;
|
| 26298 |
tejbeer |
63 |
|
| 23784 |
ashik.ali |
64 |
@Autowired
|
| 23652 |
amit.gupta |
65 |
private ReporticoService reporticoService;
|
| 23764 |
amit.gupta |
66 |
|
| 23798 |
amit.gupta |
67 |
@Autowired
|
| 30162 |
manish |
68 |
private OrderRepository orderRepository;
|
|
|
69 |
@Autowired
|
| 23798 |
amit.gupta |
70 |
private RoleManager roleManager;
|
| 30162 |
manish |
71 |
|
|
|
72 |
@Autowired
|
|
|
73 |
private OrderService orderService;
|
| 26298 |
tejbeer |
74 |
|
|
|
75 |
@Autowired
|
|
|
76 |
private CsService csService;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private AuthRepository authRepository;
|
|
|
80 |
|
| 30162 |
manish |
81 |
private static final Logger Logger = LogManager.getLogger(OrderController.class);
|
| 23612 |
amit.gupta |
82 |
|
| 26063 |
amit.gupta |
83 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 23764 |
amit.gupta |
84 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 26298 |
tejbeer |
85 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
| 23764 |
amit.gupta |
86 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 23612 |
amit.gupta |
87 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
88 |
HttpResponse response;
|
| 26298 |
tejbeer |
89 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
90 |
|
|
|
91 |
if (fileName.equalsIgnoreCase("LeadsReport")) {
|
|
|
92 |
if (paramsMap == null) {
|
|
|
93 |
paramsMap = new HashMap<String, String>();
|
|
|
94 |
}
|
| 26460 |
amit.gupta |
95 |
Map<Integer, List<Integer>> mapping = csService.getL2L1Mapping();
|
| 26298 |
tejbeer |
96 |
|
|
|
97 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
98 |
|
|
|
99 |
List<Integer> authIds = mapping.get(authUser.getId());
|
|
|
100 |
if (authIds == null) {
|
|
|
101 |
authIds = new ArrayList<>();
|
|
|
102 |
}
|
|
|
103 |
authIds.add(authUser.getId());
|
|
|
104 |
|
|
|
105 |
paramsMap.put("authId", authIds + "");
|
|
|
106 |
}
|
| 23612 |
amit.gupta |
107 |
} else {
|
| 26298 |
tejbeer |
108 |
if (paramsMap == null) {
|
| 26164 |
amit.gupta |
109 |
paramsMap = new HashMap<String, String>();
|
|
|
110 |
}
|
| 26298 |
tejbeer |
111 |
|
| 26158 |
amit.gupta |
112 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
| 26298 |
tejbeer |
113 |
|
| 23612 |
amit.gupta |
114 |
}
|
| 26298 |
tejbeer |
115 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
| 23612 |
amit.gupta |
116 |
HttpHeaders headers = new HttpHeaders();
|
| 23764 |
amit.gupta |
117 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
| 23765 |
amit.gupta |
118 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
| 26298 |
tejbeer |
119 |
headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
|
| 23766 |
amit.gupta |
120 |
headers.setContentLength(response.getEntity().getContentLength());
|
| 23764 |
amit.gupta |
121 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
| 23612 |
amit.gupta |
122 |
}
|
| 23637 |
amit.gupta |
123 |
|
| 26298 |
tejbeer |
124 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
|
|
125 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
| 26063 |
amit.gupta |
126 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
|
|
127 |
}
|
| 30162 |
manish |
128 |
|
|
|
129 |
@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
|
|
|
130 |
public String getCollectionSummary(HttpServletRequest request,
|
|
|
131 |
Model model) throws ProfitMandiBusinessException {
|
|
|
132 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
133 |
|
|
|
134 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
135 |
LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
|
|
|
136 |
|
|
|
137 |
List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),currentStartMonth, currentDate);
|
|
|
138 |
|
|
|
139 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
|
|
140 |
|
|
|
141 |
model.addAttribute("startDate",currentDate.minusDays(30).toLocalDate());
|
|
|
142 |
model.addAttribute("endDate", LocalDate.now());
|
|
|
143 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
|
|
144 |
return "partner-collection-summary";
|
|
|
145 |
}
|
| 33067 |
shampa |
146 |
@RequestMapping(value = "/collectionSummaryFetchReportByDate", method = RequestMethod.GET)
|
|
|
147 |
public String getcollectionSummaryFetchReport(HttpServletRequest request,
|
|
|
148 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
149 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
|
|
|
150 |
throws Exception {
|
|
|
151 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
152 |
|
|
|
153 |
List<List<?>> rows = new ArrayList<>();
|
|
|
154 |
|
|
|
155 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
156 |
|
|
|
157 |
List<CollectionSummary> collectionSummaryList =orderRepository
|
|
|
158 |
.selectCollectionSummary(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
159 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
|
|
160 |
|
|
|
161 |
model.addAttribute("startDate",startDate);
|
|
|
162 |
model.addAttribute("endDate", endDate);
|
|
|
163 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
|
|
164 |
return "partner-collection-summary";
|
|
|
165 |
}
|
| 30162 |
manish |
166 |
|
|
|
167 |
@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
|
|
|
168 |
public ResponseEntity<?> getDownloadCollectionSummary(HttpServletRequest request,
|
|
|
169 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
170 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,Model model) throws Exception {
|
|
|
171 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
172 |
List<List<?>> rows = new ArrayList<>();
|
| 26063 |
amit.gupta |
173 |
|
| 30162 |
manish |
174 |
|
| 33067 |
shampa |
175 |
List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 30162 |
manish |
176 |
|
|
|
177 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
| 31377 |
tejbeer |
178 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
|
| 30162 |
manish |
179 |
|
|
|
180 |
for( CollectionSummary cs : collectionSummaryList) {
|
|
|
181 |
|
| 31377 |
tejbeer |
182 |
rows.add(Arrays.asList(cs.getDate().format(
|
|
|
183 |
dateTimeFormatter), cs.getReferenceType(),cs.getCash(),cs.getPinelabs(),cs.getBajajFinserv(),cs.getHomeCredit(),cs.getPaytm(),
|
| 30162 |
manish |
184 |
cs.getCapitalFirst(),cs.getZestMoney(),cs.getSamsungSure(),cs.getTotalAmount()));
|
|
|
185 |
|
|
|
186 |
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
190 |
.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash","Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
|
|
|
191 |
"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
|
|
|
192 |
|
|
|
193 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,"Collection Summary Report");
|
|
|
194 |
|
|
|
195 |
|
|
|
196 |
return responseEntity;
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
|
|
|
200 |
|
|
|
201 |
|
|
|
202 |
|
| 23822 |
amit.gupta |
203 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 28106 |
amit.gupta |
204 |
public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
|
|
205 |
|
| 28137 |
amit.gupta |
206 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
|
| 28106 |
amit.gupta |
207 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
|
| 28137 |
amit.gupta |
208 |
/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
|
| 28106 |
amit.gupta |
209 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
|
|
|
210 |
returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
|
|
|
211 |
returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
|
| 28107 |
amit.gupta |
212 |
returnMap = returnMap1;
|
| 28137 |
amit.gupta |
213 |
}*/
|
| 28107 |
amit.gupta |
214 |
model.addAttribute("reporticoProjectMap", returnMap);
|
| 28106 |
amit.gupta |
215 |
|
| 23637 |
amit.gupta |
216 |
return "reports";
|
|
|
217 |
}
|
| 23612 |
amit.gupta |
218 |
}
|