| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| - |
|
4 |
import java.time.LocalDate;
|
| - |
|
5 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| - |
|
7 |
import java.util.Arrays;
|
| 5 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 6 |
import java.util.List;
|
9 |
import java.util.List;
|
| 7 |
import java.util.Map;
|
10 |
import java.util.Map;
|
| 8 |
import java.util.Scanner;
|
- |
|
| 9 |
import java.util.stream.Collectors;
|
- |
|
| 10 |
|
11 |
|
| 11 |
import javax.servlet.http.HttpServletRequest;
|
12 |
import javax.servlet.http.HttpServletRequest;
|
| 12 |
|
13 |
|
| 13 |
import org.apache.http.HttpResponse;
|
14 |
import org.apache.http.HttpResponse;
|
| 14 |
import org.apache.logging.log4j.LogManager;
|
15 |
import org.apache.logging.log4j.LogManager;
|
| Line 23... |
Line 24... |
| 23 |
import org.springframework.ui.Model;
|
24 |
import org.springframework.ui.Model;
|
| 24 |
import org.springframework.web.bind.annotation.PathVariable;
|
25 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 25 |
import org.springframework.web.bind.annotation.RequestBody;
|
26 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 26 |
import org.springframework.web.bind.annotation.RequestMapping;
|
27 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 27 |
import org.springframework.web.bind.annotation.RequestMethod;
|
28 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| - |
|
29 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 28 |
|
30 |
|
| 29 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
31 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
32 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 31 |
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
|
33 |
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
|
| 32 |
import com.spice.profitmandi.common.services.ReporticoService;
|
34 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| - |
|
35 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 33 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
36 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| - |
|
37 |
import com.spice.profitmandi.dao.model.CollectionSummary;
|
| 34 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
38 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
39 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 36 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
40 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
41 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| - |
|
42 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 38 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
43 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| - |
|
44 |
import com.spice.profitmandi.service.order.OrderService;
|
| 39 |
import com.spice.profitmandi.web.model.LoginDetails;
|
45 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 40 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
46 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 41 |
|
47 |
|
| 42 |
@Controller
|
48 |
@Controller
|
| 43 |
@Transactional(rollbackFor = Throwable.class)
|
49 |
@Transactional(rollbackFor = Throwable.class)
|
| Line 54... |
Line 60... |
| 54 |
|
60 |
|
| 55 |
@Autowired
|
61 |
@Autowired
|
| 56 |
private ReporticoService reporticoService;
|
62 |
private ReporticoService reporticoService;
|
| 57 |
|
63 |
|
| 58 |
@Autowired
|
64 |
@Autowired
|
| - |
|
65 |
private OrderRepository orderRepository;
|
| - |
|
66 |
@Autowired
|
| 59 |
private RoleManager roleManager;
|
67 |
private RoleManager roleManager;
|
| - |
|
68 |
|
| - |
|
69 |
@Autowired
|
| - |
|
70 |
private OrderService orderService;
|
| 60 |
|
71 |
|
| 61 |
@Autowired
|
72 |
@Autowired
|
| 62 |
private CsService csService;
|
73 |
private CsService csService;
|
| 63 |
|
74 |
|
| 64 |
@Autowired
|
75 |
@Autowired
|
| 65 |
private AuthRepository authRepository;
|
76 |
private AuthRepository authRepository;
|
| 66 |
|
77 |
|
| 67 |
private static final Logger log = LogManager.getLogger(OrderController.class);
|
78 |
private static final Logger Logger = LogManager.getLogger(OrderController.class);
|
| 68 |
|
79 |
|
| 69 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
80 |
@RequestMapping(value = "/reports/{projectName}/{fileName}")
|
| 70 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
81 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 71 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
82 |
@PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
|
| 72 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
83 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| Line 109... |
Line 120... |
| 109 |
|
120 |
|
| 110 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
121 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
| 111 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
122 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
| 112 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
123 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
| 113 |
}
|
124 |
}
|
| - |
|
125 |
|
| - |
|
126 |
@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
|
| - |
|
127 |
public String getCollectionSummary(HttpServletRequest request,
|
| - |
|
128 |
Model model) throws ProfitMandiBusinessException {
|
| - |
|
129 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
130 |
|
| - |
|
131 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
| - |
|
132 |
LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
|
| - |
|
133 |
|
| - |
|
134 |
List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),currentStartMonth, currentDate);
|
| - |
|
135 |
|
| - |
|
136 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
| - |
|
137 |
|
| - |
|
138 |
model.addAttribute("startDate",currentDate.minusDays(30).toLocalDate());
|
| - |
|
139 |
model.addAttribute("endDate", LocalDate.now());
|
| - |
|
140 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
| - |
|
141 |
return "partner-collection-summary";
|
| - |
|
142 |
}
|
| - |
|
143 |
|
| - |
|
144 |
@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
|
| - |
|
145 |
public ResponseEntity<?> getDownloadCollectionSummary(HttpServletRequest request,
|
| - |
|
146 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
| - |
|
147 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,Model model) throws Exception {
|
| - |
|
148 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
149 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
150 |
|
| - |
|
151 |
|
| - |
|
152 |
List<CollectionSummary> collectionSummaryList =orderRepository.selectCollectionSummary(fofoDetails.getFofoId(),startDate.atStartOfDay(), endDate.atStartOfDay());
|
| - |
|
153 |
|
| - |
|
154 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
| - |
|
155 |
|
| - |
|
156 |
for( CollectionSummary cs : collectionSummaryList) {
|
| - |
|
157 |
|
| - |
|
158 |
rows.add(Arrays.asList(cs.getDate(), cs.getReferenceType(),cs.getCash(),cs.getPinelabs(),cs.getBajajFinserv(),cs.getHomeCredit(),cs.getPaytm(),
|
| - |
|
159 |
cs.getCapitalFirst(),cs.getZestMoney(),cs.getSamsungSure(),cs.getTotalAmount()));
|
| - |
|
160 |
|
| - |
|
161 |
|
| - |
|
162 |
}
|
| - |
|
163 |
|
| - |
|
164 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
| - |
|
165 |
.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash","Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
|
| - |
|
166 |
"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
|
| - |
|
167 |
|
| - |
|
168 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,"Collection Summary Report");
|
| - |
|
169 |
|
| - |
|
170 |
|
| - |
|
171 |
return responseEntity;
|
| - |
|
172 |
}
|
| - |
|
173 |
|
| - |
|
174 |
|
| - |
|
175 |
|
| - |
|
176 |
|
| 114 |
|
177 |
|
| 115 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
178 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
| 116 |
public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
179 |
public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
| 117 |
|
180 |
|
| 118 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
|
181 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
|