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