| 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;
|
| 33102 |
tejus.loha |
5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 34066 |
aman.kumar |
6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 28106 |
amit.gupta |
7 |
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
|
| 23612 |
amit.gupta |
8 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 30162 |
manish |
9 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 33102 |
tejus.loha |
10 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 26298 |
tejbeer |
11 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 34066 |
aman.kumar |
12 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 33102 |
tejus.loha |
13 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
|
| 33775 |
ranu |
15 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
|
|
16 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 33102 |
tejus.loha |
17 |
import com.spice.profitmandi.dao.model.*;
|
| 26298 |
tejbeer |
18 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 34066 |
aman.kumar |
20 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 28106 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23784 |
ashik.ali |
22 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 33102 |
tejus.loha |
23 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
|
|
|
25 |
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
|
| 33809 |
ranu |
26 |
import com.spice.profitmandi.dao.repository.transaction.*;
|
| 23798 |
amit.gupta |
27 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 30162 |
manish |
28 |
import com.spice.profitmandi.service.order.OrderService;
|
| 33775 |
ranu |
29 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 33102 |
tejus.loha |
30 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 33775 |
ranu |
31 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 23612 |
amit.gupta |
32 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
33 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 33775 |
ranu |
34 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 33092 |
tejus.loha |
35 |
import org.apache.http.HttpResponse;
|
|
|
36 |
import org.apache.logging.log4j.LogManager;
|
|
|
37 |
import org.apache.logging.log4j.Logger;
|
|
|
38 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
39 |
import org.springframework.core.io.InputStreamResource;
|
|
|
40 |
import org.springframework.http.HttpHeaders;
|
|
|
41 |
import org.springframework.http.HttpStatus;
|
|
|
42 |
import org.springframework.http.ResponseEntity;
|
|
|
43 |
import org.springframework.stereotype.Controller;
|
|
|
44 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
45 |
import org.springframework.ui.Model;
|
|
|
46 |
import org.springframework.web.bind.annotation.*;
|
| 23612 |
amit.gupta |
47 |
|
| 33092 |
tejus.loha |
48 |
import javax.servlet.http.HttpServletRequest;
|
|
|
49 |
import java.io.IOException;
|
|
|
50 |
import java.time.LocalDate;
|
|
|
51 |
import java.time.LocalDateTime;
|
|
|
52 |
import java.time.LocalTime;
|
|
|
53 |
import java.time.format.DateTimeFormatter;
|
|
|
54 |
import java.util.*;
|
| 33102 |
tejus.loha |
55 |
import java.util.stream.Collectors;
|
| 33092 |
tejus.loha |
56 |
|
| 23612 |
amit.gupta |
57 |
@Controller
|
| 26298 |
tejbeer |
58 |
@Transactional(rollbackFor = Throwable.class)
|
| 23612 |
amit.gupta |
59 |
public class ReportsController {
|
| 33143 |
tejus.loha |
60 |
private static final Logger LOGGER = LogManager.getLogger(OrderController.class);
|
|
|
61 |
private static final Logger Logger = LogManager.getLogger(OrderController.class);
|
|
|
62 |
@Autowired
|
|
|
63 |
private RoleRepository roleRepository;
|
|
|
64 |
@Autowired
|
|
|
65 |
private FofoOrderRepository fofoOrderRepository;
|
|
|
66 |
@Autowired
|
|
|
67 |
private RetailerService retailerService;
|
|
|
68 |
@Autowired
|
|
|
69 |
private PendingOrderItemRepository pendingOrderItemRepository;
|
|
|
70 |
@Autowired
|
|
|
71 |
private PendingOrderService pendingOrderService;
|
|
|
72 |
@Autowired
|
|
|
73 |
private CookiesProcessor cookiesProcessor;
|
|
|
74 |
@Autowired
|
|
|
75 |
private FofoStoreRepository fofoStoreRepository;
|
|
|
76 |
@Autowired
|
|
|
77 |
private ReporticoService reporticoService;
|
|
|
78 |
@Autowired
|
|
|
79 |
private OrderRepository orderRepository;
|
|
|
80 |
@Autowired
|
|
|
81 |
private RoleManager roleManager;
|
|
|
82 |
@Autowired
|
|
|
83 |
private OrderService orderService;
|
|
|
84 |
@Autowired
|
|
|
85 |
private CsService csService;
|
|
|
86 |
@Autowired
|
|
|
87 |
private AuthRepository authRepository;
|
| 33775 |
ranu |
88 |
@Autowired
|
|
|
89 |
private WalletService walletService;
|
|
|
90 |
@Autowired
|
|
|
91 |
private UserWalletHistoryRepository userWalletHistoryRepository;
|
|
|
92 |
@Autowired
|
|
|
93 |
private TransactionService transactionService;
|
| 33809 |
ranu |
94 |
@Autowired
|
|
|
95 |
private LoanStatementRepository loanStatementRepository;
|
| 34066 |
aman.kumar |
96 |
@Autowired
|
|
|
97 |
PositionRepository positionRepository;
|
| 26298 |
tejbeer |
98 |
|
| 33186 |
amit.gupta |
99 |
@PostMapping(value = "/reports/{projectName}/{fileName}")
|
| 33143 |
tejus.loha |
100 |
public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
|
| 33187 |
amit.gupta |
101 |
@PathVariable ReporticoProject projectName, @RequestBody Map<String, String> paramsMap)
|
| 33143 |
tejus.loha |
102 |
throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
|
|
103 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
104 |
HttpResponse response;
|
|
|
105 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
| 33102 |
tejus.loha |
106 |
|
| 33143 |
tejus.loha |
107 |
if (fileName.equalsIgnoreCase("LeadsReport")) {
|
|
|
108 |
if (paramsMap == null) {
|
|
|
109 |
paramsMap = new HashMap<String, String>();
|
|
|
110 |
}
|
|
|
111 |
Map<Integer, List<Integer>> mapping = csService.getL2L1Mapping();
|
| 33102 |
tejus.loha |
112 |
|
| 33143 |
tejus.loha |
113 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
| 33102 |
tejus.loha |
114 |
|
| 33143 |
tejus.loha |
115 |
List<Integer> authIds = mapping.get(authUser.getId());
|
|
|
116 |
if (authIds == null) {
|
|
|
117 |
authIds = new ArrayList<>();
|
|
|
118 |
}
|
|
|
119 |
authIds.add(authUser.getId());
|
| 33102 |
tejus.loha |
120 |
|
| 33143 |
tejus.loha |
121 |
paramsMap.put("authId", authIds + "");
|
|
|
122 |
}
|
|
|
123 |
} else {
|
|
|
124 |
if (paramsMap == null) {
|
|
|
125 |
paramsMap = new HashMap<String, String>();
|
|
|
126 |
}
|
| 26298 |
tejbeer |
127 |
|
| 33143 |
tejus.loha |
128 |
paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
|
| 23764 |
amit.gupta |
129 |
|
| 33143 |
tejus.loha |
130 |
}
|
|
|
131 |
response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
|
|
|
132 |
HttpHeaders headers = new HttpHeaders();
|
|
|
133 |
InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
|
|
|
134 |
headers.set("Content-Type", "application/vnd.ms-excel");
|
|
|
135 |
headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
|
|
|
136 |
headers.setContentLength(response.getEntity().getContentLength());
|
|
|
137 |
return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
|
|
|
138 |
}
|
| 26298 |
tejbeer |
139 |
|
| 33143 |
tejus.loha |
140 |
private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
|
|
|
141 |
Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
|
|
|
142 |
return reporticoService.getReportFile(projectName, fileName, reportParams);
|
|
|
143 |
}
|
| 26298 |
tejbeer |
144 |
|
| 33143 |
tejus.loha |
145 |
@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
|
|
|
146 |
public String getCollectionSummary(HttpServletRequest request,
|
|
|
147 |
Model model) throws ProfitMandiBusinessException {
|
|
|
148 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
149 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
150 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
151 |
LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
|
|
|
152 |
List<CollectionSummary> collectionSummaryList = orderRepository.selectCollectionSummary(fofoDetails.getFofoId(), currentStartMonth, currentDate);
|
|
|
153 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
| 34066 |
aman.kumar |
154 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
155 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
156 |
boolean isRBM = positions.stream()
|
|
|
157 |
.anyMatch(position ->
|
|
|
158 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
159 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
160 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
161 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
162 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
163 |
try {
|
|
|
164 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
165 |
} catch (ProfitMandiBusinessException e) {
|
|
|
166 |
// TODO Auto-generated catch block
|
|
|
167 |
return null;
|
|
|
168 |
}
|
|
|
169 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
170 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
171 |
}
|
|
|
172 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
173 |
model.addAttribute("startDate", currentDate.minusDays(30).toLocalDate());
|
|
|
174 |
model.addAttribute("endDate", LocalDate.now());
|
|
|
175 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
|
|
176 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
177 |
return "partner-collection-summary";
|
|
|
178 |
}
|
| 26298 |
tejbeer |
179 |
|
| 33143 |
tejus.loha |
180 |
@RequestMapping(value = "/collectionSummaryFetchReportByDate", method = RequestMethod.GET)
|
|
|
181 |
public String getcollectionSummaryFetchReport(HttpServletRequest request,
|
|
|
182 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
183 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
184 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
|
|
|
185 |
throws Exception {
|
|
|
186 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
187 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
188 |
if (isAdmin) {
|
|
|
189 |
startDate = LocalDate.now().minusDays(30);
|
|
|
190 |
endDate = LocalDate.now();
|
|
|
191 |
}
|
| 34066 |
aman.kumar |
192 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
193 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
194 |
boolean isRBM = positions.stream()
|
|
|
195 |
.anyMatch(position ->
|
|
|
196 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
197 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
198 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
199 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
200 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
201 |
try {
|
|
|
202 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
203 |
} catch (ProfitMandiBusinessException e) {
|
|
|
204 |
// TODO Auto-generated catch block
|
|
|
205 |
return null;
|
|
|
206 |
}
|
|
|
207 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
208 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
209 |
}
|
|
|
210 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
211 |
model.addAttribute("startDate", startDate);
|
|
|
212 |
model.addAttribute("endDate", endDate);
|
|
|
213 |
model.addAttribute("isAdmin", isAdmin);
|
| 23612 |
amit.gupta |
214 |
|
| 26298 |
tejbeer |
215 |
|
| 33143 |
tejus.loha |
216 |
if (isAdmin) {
|
|
|
217 |
if (fofoId == 0) {
|
|
|
218 |
//No need to send any data
|
|
|
219 |
model.addAttribute("collectionSummaryList", new ArrayList<>());
|
|
|
220 |
return "partner-collection-summary";
|
|
|
221 |
} else {
|
|
|
222 |
List<CollectionSummary> collectionSummaryList = orderRepository
|
|
|
223 |
.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
224 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
|
|
225 |
return "partner-collection-summary";
|
|
|
226 |
}
|
|
|
227 |
} else {
|
|
|
228 |
fofoId = fofoDetails.getFofoId();
|
|
|
229 |
List<CollectionSummary> collectionSummaryList = orderRepository
|
|
|
230 |
.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
231 |
model.addAttribute("collectionSummaryList", collectionSummaryList);
|
|
|
232 |
return "partner-collection-summary";
|
| 26298 |
tejbeer |
233 |
|
| 33143 |
tejus.loha |
234 |
}
|
|
|
235 |
}
|
| 26298 |
tejbeer |
236 |
|
| 33143 |
tejus.loha |
237 |
@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
|
|
|
238 |
public ResponseEntity<?> getDownloadCollectionSummary(HttpServletRequest request,
|
|
|
239 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
240 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
241 |
@RequestParam(name = "endDate") LocalDate endDate, Model model) throws Exception {
|
|
|
242 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
243 |
List<List<?>> rows = new ArrayList<>();
|
|
|
244 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
245 |
List<CollectionSummary> collectionSummaryList = null;
|
|
|
246 |
if (isAdmin) {
|
|
|
247 |
if (fofoId == 0) {
|
|
|
248 |
collectionSummaryList = new ArrayList<>();
|
|
|
249 |
} else {
|
|
|
250 |
collectionSummaryList = orderRepository.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
251 |
}
|
|
|
252 |
} else {
|
|
|
253 |
collectionSummaryList = orderRepository.selectCollectionSummary(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
254 |
}
|
|
|
255 |
Logger.info("CollectionSummaryList {}", collectionSummaryList);
|
|
|
256 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
|
|
|
257 |
for (CollectionSummary cs : collectionSummaryList) {
|
|
|
258 |
rows.add(Arrays.asList(cs.getDate().format(
|
|
|
259 |
dateTimeFormatter), cs.getReferenceType(), cs.getCash(), cs.getPinelabs(), cs.getBajajFinserv(), cs.getHomeCredit(), cs.getPaytm(),
|
|
|
260 |
cs.getCapitalFirst(), cs.getZestMoney(), cs.getSamsungSure(), cs.getTotalAmount()));
|
|
|
261 |
}
|
|
|
262 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
263 |
.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash", "Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
|
|
|
264 |
"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
|
|
|
265 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Collection Summary Report");
|
| 26298 |
tejbeer |
266 |
|
| 33143 |
tejus.loha |
267 |
return responseEntity;
|
|
|
268 |
}
|
| 26298 |
tejbeer |
269 |
|
| 33143 |
tejus.loha |
270 |
@RequestMapping(value = "/franchiseeSalesReport", method = RequestMethod.GET)
|
|
|
271 |
public String getFranchiseeSalesReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
|
|
272 |
@RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
|
|
|
273 |
throws ProfitMandiBusinessException {
|
|
|
274 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
275 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
276 |
if (startDate == null) {
|
|
|
277 |
startDate = LocalDate.now().minusDays(30);
|
| 26298 |
tejbeer |
278 |
|
| 33143 |
tejus.loha |
279 |
}
|
|
|
280 |
endDate = LocalDate.now();
|
| 34066 |
aman.kumar |
281 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
282 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
283 |
boolean isRBM = positions.stream()
|
|
|
284 |
.anyMatch(position ->
|
|
|
285 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
286 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
287 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
288 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
289 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
290 |
try {
|
|
|
291 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
292 |
} catch (ProfitMandiBusinessException e) {
|
|
|
293 |
// TODO Auto-generated catch block
|
|
|
294 |
return null;
|
|
|
295 |
}
|
|
|
296 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
297 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
298 |
}
|
|
|
299 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
300 |
model.addAttribute("startDate", startDate);
|
|
|
301 |
model.addAttribute("endDate", endDate);
|
|
|
302 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
303 |
LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
|
|
|
304 |
if (isAdmin) {
|
|
|
305 |
if (fofoId == 0) {
|
|
|
306 |
//No need to pull any data
|
|
|
307 |
model.addAttribute("focoSaleReportList", new ArrayList<>());
|
|
|
308 |
return "foco-sale-report";
|
| 23637 |
amit.gupta |
309 |
|
| 33143 |
tejus.loha |
310 |
}
|
|
|
311 |
} else {
|
|
|
312 |
fofoId = loginDetails.getFofoId();
|
|
|
313 |
}
|
| 33102 |
tejus.loha |
314 |
|
|
|
315 |
|
| 33143 |
tejus.loha |
316 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 33067 |
shampa |
317 |
|
| 33143 |
tejus.loha |
318 |
List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId, fs.getCode(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
319 |
model.addAttribute("focoSaleReportList", focoSaleReportList);
|
|
|
320 |
return "foco-sale-report";
|
|
|
321 |
}
|
| 33067 |
shampa |
322 |
|
| 33143 |
tejus.loha |
323 |
@RequestMapping(value = "/franchiseeSalesFetchReportByDate", method = RequestMethod.GET)
|
|
|
324 |
public String getfranchiseeSalesFetchReport(HttpServletRequest request, Model model,
|
|
|
325 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
326 |
@RequestParam(required = false) LocalDate startDate,
|
|
|
327 |
@RequestParam(required = false) LocalDate endDate)
|
|
|
328 |
throws Exception {
|
|
|
329 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
330 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
331 |
if (startDate == null) {
|
| 33067 |
shampa |
332 |
|
| 33143 |
tejus.loha |
333 |
startDate = LocalDate.now().minusDays(30);
|
|
|
334 |
endDate = LocalDate.now();
|
|
|
335 |
}
|
| 34066 |
aman.kumar |
336 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
337 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
338 |
boolean isRBM = positions.stream()
|
|
|
339 |
.anyMatch(position ->
|
|
|
340 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
341 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
342 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
343 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
344 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
345 |
try {
|
|
|
346 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
347 |
} catch (ProfitMandiBusinessException e) {
|
|
|
348 |
// TODO Auto-generated catch block
|
|
|
349 |
return null;
|
|
|
350 |
}
|
|
|
351 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
352 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
353 |
}
|
|
|
354 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
355 |
model.addAttribute("startDate", startDate);
|
|
|
356 |
model.addAttribute("endDate", endDate);
|
|
|
357 |
model.addAttribute("isAdmin", isAdmin);
|
| 33102 |
tejus.loha |
358 |
|
| 33143 |
tejus.loha |
359 |
// List<List<?>> rows = new ArrayList<>();
|
| 30162 |
manish |
360 |
|
| 33143 |
tejus.loha |
361 |
LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
|
|
|
362 |
if (isAdmin) {
|
|
|
363 |
if (fofoId == 0) {
|
|
|
364 |
//no need any data
|
|
|
365 |
model.addAttribute("focoSaleReportList", new ArrayList<>());
|
|
|
366 |
return "foco-sale-report";
|
|
|
367 |
}
|
|
|
368 |
} else {
|
|
|
369 |
fofoId = loginDetails.getFofoId();
|
|
|
370 |
}
|
|
|
371 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
372 |
List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId, fs.getCode(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
373 |
model.addAttribute("focoSaleReportList", focoSaleReportList);
|
|
|
374 |
return "foco-sale-report";
|
|
|
375 |
}
|
| 30162 |
manish |
376 |
|
|
|
377 |
|
| 33143 |
tejus.loha |
378 |
@RequestMapping(value = "/downloadFranchiseeSales", method = RequestMethod.GET)
|
|
|
379 |
public ResponseEntity<?> getdownloadFranchiseeSales(HttpServletRequest request,
|
|
|
380 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
381 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
382 |
@RequestParam(name = "endDate") LocalDate endDate,
|
|
|
383 |
Model model)
|
|
|
384 |
throws Exception {
|
|
|
385 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 33102 |
tejus.loha |
386 |
|
| 33143 |
tejus.loha |
387 |
List<List<?>> rows = new ArrayList<>();
|
|
|
388 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
389 |
List<FocoSaleReportModel> focoSaleReportList = null;
|
|
|
390 |
FofoStore fs = null;
|
|
|
391 |
if (isAdmin) {
|
|
|
392 |
fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
393 |
if (fofoId == 0) {
|
|
|
394 |
focoSaleReportList = new ArrayList<>();
|
|
|
395 |
} else {
|
| 33102 |
tejus.loha |
396 |
|
| 33143 |
tejus.loha |
397 |
focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId,
|
|
|
398 |
fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
|
|
|
399 |
}
|
| 33102 |
tejus.loha |
400 |
|
| 33143 |
tejus.loha |
401 |
} else {
|
|
|
402 |
fs = fofoStoreRepository.selectByRetailerId(fofoDetails.getFofoId());
|
| 33102 |
tejus.loha |
403 |
|
| 33143 |
tejus.loha |
404 |
focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoDetails.getFofoId(),
|
|
|
405 |
fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
|
|
|
406 |
}
|
|
|
407 |
LOGGER.info("FocoSaleReportList {}", focoSaleReportList);
|
|
|
408 |
String partnerName = null;
|
|
|
409 |
for (FocoSaleReportModel fsr : focoSaleReportList) {
|
|
|
410 |
partnerName = fsr.getName();
|
|
|
411 |
rows.add(Arrays.asList(fsr.getCode(), fsr.getName(), fsr.getCity(), fsr.getState(), fsr.getRegion(),
|
|
|
412 |
fsr.getItemId(), fsr.getBrand(), fsr.getModelName(), fsr.getModelNumber(), fsr.getColor(),
|
|
|
413 |
fsr.getQuantity(), fsr.getDp(), fsr.getSellingPrice(), fsr.getMop(), fsr.getSerialNumber(),
|
|
|
414 |
FormattingUtils.format(fsr.getCreateDate()), fsr.getCustomerName(), fsr.getCustomerPhone(),
|
|
|
415 |
fsr.getCustomerCity(), fsr.getCustomerPincode(), fsr.getInvoiceNumber(), fsr.getPurchaseReference(),
|
|
|
416 |
fsr.getCustomerGstNumber(), FormattingUtils.format(fsr.getCancelledTimestamp()),
|
|
|
417 |
FormattingUtils.format(fsr.getGrnCompleteDate()), fsr.getHygieneRating(), fsr.getRating(),
|
|
|
418 |
fsr.getStatus(), fsr.getRemark(), FormattingUtils.format(fsr.getCreatedTimestamp()),
|
|
|
419 |
FormattingUtils.format(fsr.getDisposedTimestamp()),
|
|
|
420 |
FormattingUtils.format(fsr.getNextTimestamp()),
|
|
|
421 |
FormattingUtils.format(fsr.getActivationTimestamp()),
|
|
|
422 |
FormattingUtils.format(fsr.getActivationTimestamp()), fsr.getLabel()));
|
| 33102 |
tejus.loha |
423 |
|
| 33143 |
tejus.loha |
424 |
}
|
| 33102 |
tejus.loha |
425 |
|
| 33143 |
tejus.loha |
426 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
427 |
Arrays.asList("Code", "Name", "City", "State", "Region", "Item Id", "Brand", "Model Name",
|
|
|
428 |
"Model Number", "Color", "Quantity", "Dp", "Selling_Price", "mop", "Serial Number",
|
|
|
429 |
"Create Date", "Customer Name", "Customer Phone", "Customer City", " Customer Pincode",
|
|
|
430 |
"Invoice Number", "Purchase Reference", "Customer Gst Number", " Cancelled Timestamp",
|
|
|
431 |
"GRN Complete Date", "Hygiene Rating", "Rating", "Status", "Remark", "Created Timestamp",
|
|
|
432 |
"Disposed Timestamp", " Next Timestamp", "Activation Timestamp", "Create Timestamp", "Label"),
|
|
|
433 |
rows);
|
| 33102 |
tejus.loha |
434 |
|
| 33143 |
tejus.loha |
435 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerName + " Franchisee Sales Report");
|
| 33102 |
tejus.loha |
436 |
|
| 33143 |
tejus.loha |
437 |
return responseEntity;
|
| 33102 |
tejus.loha |
438 |
|
| 33143 |
tejus.loha |
439 |
}
|
| 33102 |
tejus.loha |
440 |
|
| 33143 |
tejus.loha |
441 |
@RequestMapping(value = "/downloadWalletSummaryReport", method = RequestMethod.GET)
|
|
|
442 |
public ResponseEntity<?> getDownloadWalletSummaryReport(HttpServletRequest request,
|
|
|
443 |
@RequestParam(defaultValue = "0", name = "fofoId") int fofoId,
|
|
|
444 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
445 |
@RequestParam(name = "endDate") LocalDate endDate, Model model)
|
|
|
446 |
throws Exception {
|
| 33102 |
tejus.loha |
447 |
|
| 33143 |
tejus.loha |
448 |
List<List<?>> rows = new ArrayList<>();
|
|
|
449 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
450 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 33815 |
ranu |
451 |
float openingBalance = 0;
|
|
|
452 |
float openingPendingAmount = 0;
|
| 33143 |
tejus.loha |
453 |
List<WalletSummaryReportModel> walletSummartList = null;
|
|
|
454 |
if (isAdmin) {
|
|
|
455 |
if (fofoId == 0)
|
|
|
456 |
walletSummartList = new ArrayList<>();
|
|
|
457 |
else
|
| 33815 |
ranu |
458 |
|
| 33143 |
tejus.loha |
459 |
walletSummartList = fofoOrderRepository.selectWalletSummaryReport(
|
|
|
460 |
fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33815 |
ranu |
461 |
openingBalance = walletService.getOpeningTill(fofoId, startDate.atStartOfDay());
|
|
|
462 |
Map<Integer, Float> openingAmountMap = transactionService.getPendingIndentValueMap(startDate.atStartOfDay(), Optional.of(fofoId));
|
|
|
463 |
openingPendingAmount = openingAmountMap.get(fofoId) == null ? 0 : openingAmountMap.get(fofoId);
|
|
|
464 |
|
| 33143 |
tejus.loha |
465 |
} else {
|
| 33102 |
tejus.loha |
466 |
|
| 33143 |
tejus.loha |
467 |
walletSummartList = fofoOrderRepository.selectWalletSummaryReport(
|
|
|
468 |
fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33815 |
ranu |
469 |
|
|
|
470 |
|
| 33143 |
tejus.loha |
471 |
}
|
| 33815 |
ranu |
472 |
|
| 33143 |
tejus.loha |
473 |
LOGGER.info("walletSummartList {}", fofoId);
|
|
|
474 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
|
|
|
475 |
String partnerDetail = null;
|
| 33815 |
ranu |
476 |
// Headers for the table data
|
| 34066 |
aman.kumar |
477 |
rows.add(Arrays.asList(
|
|
|
478 |
// "Id","Business_timestamp",
|
|
|
479 |
"timestamp", "Reference_type", "Reference", "Amount", "Refundable_amount", "Running Balance", "Description"));
|
| 33143 |
tejus.loha |
480 |
for (WalletSummaryReportModel walletSummary : walletSummartList) {
|
|
|
481 |
partnerDetail = walletSummary.getName() + "(" + walletSummary.getCode() + "-" + walletSummary.getPhone() + ")" + "-" + walletSummary.getEmail();
|
| 33102 |
tejus.loha |
482 |
|
| 33143 |
tejus.loha |
483 |
rows.add(Arrays.asList(
|
| 34066 |
aman.kumar |
484 |
// walletSummary.getId(),
|
|
|
485 |
// FormattingUtils.format(walletSummary.getBusinessTimestamp() != null ? walletSummary.getBusinessTimestamp() : walletSummary.getTimestamp()),
|
|
|
486 |
walletSummary.getTimestamp(),
|
|
|
487 |
walletSummary.getReferenceType(),
|
|
|
488 |
walletSummary.getReference(),
|
| 33143 |
tejus.loha |
489 |
walletSummary.getAmount(),
|
|
|
490 |
walletSummary.getRefundableAmount(),
|
| 33815 |
ranu |
491 |
openingBalance + walletSummary.getAmount(),
|
| 33143 |
tejus.loha |
492 |
walletSummary.getDescription()
|
|
|
493 |
));
|
| 33102 |
tejus.loha |
494 |
|
| 33143 |
tejus.loha |
495 |
}
|
| 33102 |
tejus.loha |
496 |
|
| 33815 |
ranu |
497 |
|
|
|
498 |
float openingBalanceWithOpeningPendingAmount = openingPendingAmount + openingBalance;
|
| 33143 |
tejus.loha |
499 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
| 33816 |
ranu |
500 |
.getCSVByteStream(Arrays.asList("Opening Balance - : " + openingBalanceWithOpeningPendingAmount), rows);
|
| 33143 |
tejus.loha |
501 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerDetail + " Wallet Statement Report");
|
| 33102 |
tejus.loha |
502 |
|
| 33143 |
tejus.loha |
503 |
return responseEntity;
|
| 33102 |
tejus.loha |
504 |
|
| 33143 |
tejus.loha |
505 |
}
|
| 33102 |
tejus.loha |
506 |
|
| 33143 |
tejus.loha |
507 |
@RequestMapping(value = "/walletSummaryFetchReportByDate", method = RequestMethod.GET)
|
|
|
508 |
public String getwalletSummaryFetchReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
|
|
509 |
@RequestParam(required = false) LocalDate startDate,
|
|
|
510 |
@RequestParam(required = false) LocalDate endDate)
|
|
|
511 |
throws Exception {
|
|
|
512 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
513 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
514 |
if (startDate == null) {
|
|
|
515 |
startDate = LocalDate.now().minusDays(30);
|
|
|
516 |
}
|
| 34011 |
tejus.loha |
517 |
if (endDate == null) {
|
|
|
518 |
endDate = LocalDate.now();
|
|
|
519 |
}
|
|
|
520 |
List<WalletSummaryReportModel> walletSummartList = new ArrayList<>();
|
|
|
521 |
float openingBalance = 0;
|
|
|
522 |
float openingPendingAmount = 0;
|
| 33143 |
tejus.loha |
523 |
if (isAdmin) {
|
| 34011 |
tejus.loha |
524 |
if (fofoId > 0) {
|
|
|
525 |
openingBalance = walletService.getOpeningTill(fofoId, startDate.atStartOfDay());
|
| 33815 |
ranu |
526 |
Map<Integer, Float> openingAmountMap = transactionService.getPendingIndentValueMap(startDate.atStartOfDay(), Optional.of(fofoId));
|
| 34011 |
tejus.loha |
527 |
openingPendingAmount = openingAmountMap.get(fofoId) == null ? 0 : openingAmountMap.get(fofoId);
|
|
|
528 |
walletSummartList = fofoOrderRepository.selectWalletSummaryReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
529 |
LOGGER.info("startDate - " + startDate.atStartOfDay());
|
|
|
530 |
LOGGER.info("endDate - " + endDate.atTime(LocalTime.MAX));
|
| 33143 |
tejus.loha |
531 |
}
|
|
|
532 |
} else {
|
| 34011 |
tejus.loha |
533 |
walletSummartList = fofoOrderRepository.selectWalletSummaryReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33143 |
tejus.loha |
534 |
}
|
| 34066 |
aman.kumar |
535 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
536 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
537 |
boolean isRBM = positions.stream()
|
|
|
538 |
.anyMatch(position ->
|
|
|
539 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
540 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
541 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
542 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
543 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
544 |
try {
|
|
|
545 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
546 |
} catch (ProfitMandiBusinessException e) {
|
|
|
547 |
// TODO Auto-generated catch block
|
|
|
548 |
return null;
|
|
|
549 |
}
|
|
|
550 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
551 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
552 |
}
|
|
|
553 |
model.addAttribute("isRBM", isRBM);
|
|
|
554 |
|
| 34011 |
tejus.loha |
555 |
LOGGER.info("walletSummartList {}", walletSummartList);
|
|
|
556 |
model.addAttribute("walletSummartList", walletSummartList);
|
|
|
557 |
model.addAttribute("openingBalance", (openingBalance + openingPendingAmount));
|
|
|
558 |
model.addAttribute("startDate", startDate);
|
|
|
559 |
model.addAttribute("endDate", endDate);
|
|
|
560 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
561 |
return "wallet-summary-report";
|
| 33143 |
tejus.loha |
562 |
}
|
| 33102 |
tejus.loha |
563 |
|
| 33143 |
tejus.loha |
564 |
@RequestMapping(value = "/walletSummaryReport", method = RequestMethod.GET)
|
|
|
565 |
public String getWalletSummaryReport(HttpServletRequest request, Model model) throws Exception {
|
|
|
566 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
567 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 34011 |
tejus.loha |
568 |
LocalDateTime startDate = LocalDateTime.now().minusDays(30);
|
|
|
569 |
LocalDateTime endDate = LocalDateTime.now();
|
|
|
570 |
List<WalletSummaryReportModel> walletSummartList = new ArrayList<>();
|
|
|
571 |
if (!isAdmin) {
|
|
|
572 |
walletSummartList = fofoOrderRepository
|
|
|
573 |
.selectWalletSummaryReport(fofoDetails.getFofoId(), startDate, endDate);
|
|
|
574 |
}
|
| 34066 |
aman.kumar |
575 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
576 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
577 |
boolean isRBM = positions.stream()
|
|
|
578 |
.anyMatch(position ->
|
|
|
579 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
580 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
581 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
582 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
583 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
584 |
try {
|
|
|
585 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
586 |
} catch (ProfitMandiBusinessException e) {
|
|
|
587 |
// TODO Auto-generated catch block
|
|
|
588 |
return null;
|
|
|
589 |
}
|
|
|
590 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
591 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
592 |
}
|
|
|
593 |
model.addAttribute("isRBM", isRBM);
|
|
|
594 |
|
| 33143 |
tejus.loha |
595 |
LOGGER.info("walletSummartList {}", walletSummartList);
|
| 34011 |
tejus.loha |
596 |
model.addAttribute("startDate", startDate.toLocalDate());
|
|
|
597 |
model.addAttribute("endDate", endDate.toLocalDate());
|
| 33143 |
tejus.loha |
598 |
model.addAttribute("walletSummartList", walletSummartList);
|
|
|
599 |
model.addAttribute("isAdmin", isAdmin);
|
| 33102 |
tejus.loha |
600 |
|
| 33143 |
tejus.loha |
601 |
return "wallet-summary-report";
|
|
|
602 |
}
|
| 33102 |
tejus.loha |
603 |
|
| 33143 |
tejus.loha |
604 |
@RequestMapping(value = "/pendingIndentReport", method = RequestMethod.GET)
|
|
|
605 |
public String getPendingIndentReport(HttpServletRequest request, Model model) throws Exception {
|
|
|
606 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
607 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 34066 |
aman.kumar |
608 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
609 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
610 |
boolean isRBM = positions.stream()
|
|
|
611 |
.anyMatch(position ->
|
|
|
612 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
613 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
614 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
615 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
616 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
617 |
try {
|
|
|
618 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
619 |
} catch (ProfitMandiBusinessException e) {
|
|
|
620 |
// TODO Auto-generated catch block
|
|
|
621 |
return null;
|
|
|
622 |
}
|
|
|
623 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
624 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
625 |
}
|
|
|
626 |
model.addAttribute("isRBM", isRBM);
|
| 33102 |
tejus.loha |
627 |
|
| 33143 |
tejus.loha |
628 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
629 |
LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();
|
| 33102 |
tejus.loha |
630 |
|
| 33143 |
tejus.loha |
631 |
List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
|
|
|
632 |
.selectPendingIndentReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
|
|
|
633 |
LOGGER.info("pendingIndentReports {}", pendingIndentReports);
|
| 33102 |
tejus.loha |
634 |
|
| 33143 |
tejus.loha |
635 |
model.addAttribute("startDate", currentDate.minusMonths(2).toLocalDate());
|
|
|
636 |
model.addAttribute("endDate", LocalDate.now());
|
|
|
637 |
model.addAttribute("pendingIndentReports", pendingIndentReports);
|
|
|
638 |
model.addAttribute("isAdmin", isAdmin);
|
| 33102 |
tejus.loha |
639 |
|
|
|
640 |
|
| 33143 |
tejus.loha |
641 |
return "pending-indent-report";
|
|
|
642 |
}
|
| 33102 |
tejus.loha |
643 |
|
| 33143 |
tejus.loha |
644 |
@RequestMapping(value = "/pendingIndentFetchReportByDate", method = RequestMethod.GET)
|
|
|
645 |
public String getpendingIndentFetchReport(
|
|
|
646 |
HttpServletRequest request,
|
|
|
647 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
648 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
649 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,
|
|
|
650 |
Model model
|
|
|
651 |
) throws Exception {
|
|
|
652 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
653 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
654 |
if (startDate == null) {
|
|
|
655 |
startDate = LocalDate.now().minusDays(30);
|
|
|
656 |
endDate = LocalDate.now();
|
|
|
657 |
}
|
| 34066 |
aman.kumar |
658 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
659 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
660 |
boolean isRBM = positions.stream()
|
|
|
661 |
.anyMatch(position ->
|
|
|
662 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
663 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
664 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
665 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
666 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
667 |
try {
|
|
|
668 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
669 |
} catch (ProfitMandiBusinessException e) {
|
|
|
670 |
// TODO Auto-generated catch block
|
|
|
671 |
return null;
|
|
|
672 |
}
|
|
|
673 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
674 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
675 |
}
|
|
|
676 |
model.addAttribute("isRBM", isRBM);
|
|
|
677 |
|
| 33143 |
tejus.loha |
678 |
model.addAttribute("startDate", startDate);
|
|
|
679 |
model.addAttribute("endDate", endDate);
|
|
|
680 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
681 |
if (isAdmin) {
|
|
|
682 |
if (fofoId == 0) {
|
|
|
683 |
model.addAttribute("pendingIndentReports", new ArrayList<>());
|
|
|
684 |
return "pending-indent-report";
|
|
|
685 |
} else {
|
|
|
686 |
List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
|
|
|
687 |
.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
688 |
model.addAttribute("pendingIndentReports", pendingIndentReports);
|
|
|
689 |
return "pending-indent-report";
|
|
|
690 |
}
|
|
|
691 |
} else {
|
|
|
692 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
693 |
List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
|
|
|
694 |
.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
695 |
model.addAttribute("pendingIndentReports", pendingIndentReports);
|
|
|
696 |
return "pending-indent-report";
|
| 33102 |
tejus.loha |
697 |
|
| 33143 |
tejus.loha |
698 |
}
|
|
|
699 |
}
|
| 33102 |
tejus.loha |
700 |
|
|
|
701 |
|
| 33143 |
tejus.loha |
702 |
@RequestMapping(value = "/pendingIndentReportDownload", method = RequestMethod.GET)
|
|
|
703 |
public ResponseEntity<?> getPendingIndentReportDownload(HttpServletRequest request,
|
|
|
704 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
705 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
706 |
@RequestParam(name = "endDate") LocalDate endDate, Model model)
|
|
|
707 |
throws Exception {
|
|
|
708 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
709 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 33102 |
tejus.loha |
710 |
/*LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
711 |
LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();*/
|
| 33143 |
tejus.loha |
712 |
List<PendingIndentReportModel> pendingIndentReports = null;
|
|
|
713 |
List<List<?>> rows = new ArrayList<>();
|
|
|
714 |
if (isAdmin) {
|
|
|
715 |
if (fofoId == 0)
|
|
|
716 |
pendingIndentReports = new ArrayList<>();
|
|
|
717 |
else
|
|
|
718 |
pendingIndentReports = fofoOrderRepository
|
|
|
719 |
.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
720 |
} else {
|
|
|
721 |
pendingIndentReports = fofoOrderRepository
|
|
|
722 |
.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
723 |
|
| 33143 |
tejus.loha |
724 |
}
|
|
|
725 |
LOGGER.info("pendingIndentReports {}", pendingIndentReports);
|
|
|
726 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
|
| 33102 |
tejus.loha |
727 |
|
| 33143 |
tejus.loha |
728 |
for (PendingIndentReportModel pir : pendingIndentReports) {
|
| 33102 |
tejus.loha |
729 |
|
| 33143 |
tejus.loha |
730 |
rows.add(Arrays.asList(pir.getTransactionId(), pir.getOrderId(),
|
|
|
731 |
pir.getCreatTimestamp().format(dateTimeFormatter), pir.getItemId(), pir.getBrand(),
|
|
|
732 |
pir.getModelName(), pir.getModelNumber(), pir.getColor(), pir.getQuantity(), pir.getUnitPrice(),
|
|
|
733 |
pir.getWalletAmount(), pir.getStatus(), pir.getInvoiceNumber(),
|
|
|
734 |
pir.getBillingTimestamp() == null ? "" : pir.getBillingTimestamp().format(dateTimeFormatter)));
|
| 33102 |
tejus.loha |
735 |
|
| 33143 |
tejus.loha |
736 |
}
|
| 33102 |
tejus.loha |
737 |
|
| 33143 |
tejus.loha |
738 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList(
|
|
|
739 |
"Transaction Id", "Order Id", "Created_At", "Item_Id", "Brand", "Model Name", "Model Number", "Color",
|
|
|
740 |
"Quantity", "Unit Price", "Wallet Deduction", "Status", "Invoice Number", "Billing Timestamp"), rows);
|
| 33102 |
tejus.loha |
741 |
|
| 33143 |
tejus.loha |
742 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Order Status Summary Report");
|
| 33102 |
tejus.loha |
743 |
|
| 33143 |
tejus.loha |
744 |
return responseEntity;
|
|
|
745 |
}
|
| 33102 |
tejus.loha |
746 |
|
| 33143 |
tejus.loha |
747 |
@RequestMapping(value = "/schemePayoutReport", method = RequestMethod.GET)
|
|
|
748 |
public String getschemePayoutReport(HttpServletRequest request, Model model,
|
|
|
749 |
@RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
|
|
|
750 |
throws ProfitMandiBusinessException {
|
| 33102 |
tejus.loha |
751 |
|
| 33143 |
tejus.loha |
752 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
753 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
754 |
if (startDate == null) {
|
|
|
755 |
startDate = LocalDate.now().minusDays(30);
|
|
|
756 |
endDate = LocalDate.now();
|
|
|
757 |
}
|
| 34066 |
aman.kumar |
758 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
759 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
760 |
boolean isRBM = positions.stream()
|
|
|
761 |
.anyMatch(position ->
|
|
|
762 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
763 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
764 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
765 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
766 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
767 |
try {
|
|
|
768 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
769 |
} catch (ProfitMandiBusinessException e) {
|
|
|
770 |
// TODO Auto-generated catch block
|
|
|
771 |
return null;
|
|
|
772 |
}
|
|
|
773 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
774 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
775 |
}
|
|
|
776 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
777 |
model.addAttribute("startDate", startDate);
|
|
|
778 |
model.addAttribute("endDate", endDate);
|
|
|
779 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
780 |
//LOGGER.info("schemePayoutReports {}", schemePayoutReports);
|
|
|
781 |
List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
|
|
|
782 |
.selectSchemePayoutReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
783 |
model.addAttribute("schemePayoutReports", schemePayoutReports);
|
|
|
784 |
return "scheme-payout-report";
|
| 33102 |
tejus.loha |
785 |
|
| 33143 |
tejus.loha |
786 |
}
|
| 33102 |
tejus.loha |
787 |
|
| 33143 |
tejus.loha |
788 |
@RequestMapping(value = "/schemePayoutFetchReportByDate", method = RequestMethod.GET)
|
|
|
789 |
public String getschemePayoutFetchReportByDate(
|
|
|
790 |
HttpServletRequest request,
|
|
|
791 |
Model model,
|
|
|
792 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
793 |
@RequestParam(required = false) LocalDate startDate,
|
|
|
794 |
@RequestParam(required = false) LocalDate endDate)
|
|
|
795 |
throws ProfitMandiBusinessException {
|
|
|
796 |
//LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
797 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
798 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
799 |
if (startDate == null) {
|
|
|
800 |
startDate = LocalDate.now().minusDays(30);
|
|
|
801 |
endDate = LocalDate.now();
|
|
|
802 |
}
|
| 34066 |
aman.kumar |
803 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
804 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
805 |
boolean isRBM = positions.stream()
|
|
|
806 |
.anyMatch(position ->
|
|
|
807 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
808 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
809 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
810 |
List<Integer> fofoIds = pp.get(authUser.getId());
|
|
|
811 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
812 |
try {
|
|
|
813 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
814 |
} catch (ProfitMandiBusinessException e) {
|
|
|
815 |
// TODO Auto-generated catch block
|
|
|
816 |
return null;
|
|
|
817 |
}
|
|
|
818 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
819 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
820 |
}
|
|
|
821 |
|
|
|
822 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
823 |
model.addAttribute("startDate", startDate);
|
|
|
824 |
model.addAttribute("endDate", endDate);
|
|
|
825 |
model.addAttribute("isAdmin", isAdmin);
|
| 33102 |
tejus.loha |
826 |
|
| 33143 |
tejus.loha |
827 |
LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
|
|
|
828 |
if (isAdmin) {
|
|
|
829 |
if (fofoId == 0) {
|
|
|
830 |
//No need to pull any data
|
|
|
831 |
model.addAttribute("schemePayoutReports", new ArrayList<>());
|
|
|
832 |
return "scheme-payout-report";
|
| 33102 |
tejus.loha |
833 |
|
| 33143 |
tejus.loha |
834 |
} else {
|
|
|
835 |
List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
|
|
|
836 |
.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
837 |
|
| 33143 |
tejus.loha |
838 |
model.addAttribute("schemePayoutReports", schemePayoutReports);
|
|
|
839 |
return "scheme-payout-report";
|
|
|
840 |
}
|
|
|
841 |
} else {
|
|
|
842 |
fofoId = loginDetails.getFofoId();
|
| 33102 |
tejus.loha |
843 |
|
| 33143 |
tejus.loha |
844 |
List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
|
|
|
845 |
.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
846 |
|
| 33143 |
tejus.loha |
847 |
model.addAttribute("schemePayoutReports", schemePayoutReports);
|
|
|
848 |
return "scheme-payout-report";
|
|
|
849 |
}
|
| 33102 |
tejus.loha |
850 |
|
| 33143 |
tejus.loha |
851 |
}
|
| 33102 |
tejus.loha |
852 |
|
| 33143 |
tejus.loha |
853 |
@RequestMapping(value = "/offerPayoutReport", method = RequestMethod.GET)
|
|
|
854 |
public String getOfferPayoutReport(HttpServletRequest request, Model model, @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate) throws Exception {
|
|
|
855 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
856 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 34066 |
aman.kumar |
857 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
858 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
859 |
boolean isRBM = positions.stream()
|
|
|
860 |
.anyMatch(position ->
|
|
|
861 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
862 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
863 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
864 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
865 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
866 |
try {
|
|
|
867 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
868 |
} catch (ProfitMandiBusinessException e) {
|
|
|
869 |
// TODO Auto-generated catch block
|
|
|
870 |
return null;
|
|
|
871 |
}
|
|
|
872 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
873 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
874 |
}
|
|
|
875 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
876 |
if (startDate == null) {
|
|
|
877 |
startDate = LocalDate.now().minusDays(30);
|
|
|
878 |
endDate = LocalDate.now();
|
|
|
879 |
}
|
|
|
880 |
model.addAttribute("startDate", startDate);
|
|
|
881 |
model.addAttribute("endDate", endDate);
|
| 33102 |
tejus.loha |
882 |
|
|
|
883 |
|
| 33143 |
tejus.loha |
884 |
List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
|
|
|
885 |
.selectOfferPayoutDumpReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
886 |
LOGGER.info("offerPayoutDumpReports {}", offerPayoutDumpReports);
|
| 33102 |
tejus.loha |
887 |
|
| 33143 |
tejus.loha |
888 |
model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
|
|
|
889 |
model.addAttribute("isAdmin", isAdmin);
|
| 33102 |
tejus.loha |
890 |
|
| 33143 |
tejus.loha |
891 |
return "offer-payout-dump-report";
|
|
|
892 |
}
|
| 33102 |
tejus.loha |
893 |
|
| 33143 |
tejus.loha |
894 |
@RequestMapping(value = "/offerPayoutFetchReportByDate", method = RequestMethod.GET)
|
|
|
895 |
public String getofferPayoutFetchReportByDate(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
|
|
896 |
@RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
|
|
|
897 |
throws ProfitMandiBusinessException {
|
| 33102 |
tejus.loha |
898 |
|
| 33143 |
tejus.loha |
899 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
900 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
901 |
if (startDate == null) {
|
|
|
902 |
startDate = LocalDate.now().minusDays(30);
|
|
|
903 |
endDate = LocalDate.now();
|
|
|
904 |
}
|
| 34066 |
aman.kumar |
905 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
906 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
907 |
boolean isRBM = positions.stream()
|
|
|
908 |
.anyMatch(position ->
|
|
|
909 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
910 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
911 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
912 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
913 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
914 |
try {
|
|
|
915 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
916 |
} catch (ProfitMandiBusinessException e) {
|
|
|
917 |
// TODO Auto-generated catch block
|
|
|
918 |
return null;
|
|
|
919 |
}
|
|
|
920 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
921 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
922 |
}
|
|
|
923 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
924 |
model.addAttribute("startDate", startDate);
|
|
|
925 |
model.addAttribute("endDate", endDate);
|
|
|
926 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
927 |
LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
|
|
|
928 |
if (isAdmin) {
|
|
|
929 |
if (fofoId == 0) {
|
|
|
930 |
//No need to pull any data
|
|
|
931 |
model.addAttribute("offerPayoutReports", new ArrayList<>());
|
|
|
932 |
return "offer-payout-dump-report";
|
| 33102 |
tejus.loha |
933 |
|
| 33143 |
tejus.loha |
934 |
} else {
|
|
|
935 |
List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
|
|
|
936 |
.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
937 |
|
| 33143 |
tejus.loha |
938 |
model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
|
| 33102 |
tejus.loha |
939 |
|
|
|
940 |
|
| 33143 |
tejus.loha |
941 |
return "offer-payout-dump-report";
|
| 33102 |
tejus.loha |
942 |
|
| 33143 |
tejus.loha |
943 |
}
|
|
|
944 |
} else {
|
|
|
945 |
fofoId = loginDetails.getFofoId();
|
|
|
946 |
List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
|
|
|
947 |
.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
948 |
|
| 33143 |
tejus.loha |
949 |
model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
|
| 33102 |
tejus.loha |
950 |
|
|
|
951 |
|
| 33143 |
tejus.loha |
952 |
return "offer-payout-dump-report";
|
|
|
953 |
}
|
|
|
954 |
}
|
| 33102 |
tejus.loha |
955 |
|
|
|
956 |
|
| 33143 |
tejus.loha |
957 |
@RequestMapping(value = "/selectPartnerBillingSummaryReport", method = RequestMethod.GET)
|
|
|
958 |
public String getselectPartnerBillingSummaryReport(HttpServletRequest request, Model model) throws Exception {
|
|
|
959 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 33102 |
tejus.loha |
960 |
|
| 33143 |
tejus.loha |
961 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
962 |
LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
|
| 33102 |
tejus.loha |
963 |
|
| 33143 |
tejus.loha |
964 |
List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
|
|
|
965 |
.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
|
| 33102 |
tejus.loha |
966 |
|
| 33143 |
tejus.loha |
967 |
model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
|
|
|
968 |
model.addAttribute("endDate", LocalDate.now());
|
|
|
969 |
model.addAttribute("partnerBillingSummaryReports", partnerBillingSummaryReports);
|
| 33102 |
tejus.loha |
970 |
|
| 33143 |
tejus.loha |
971 |
return "partner-billing-summary-report";
|
|
|
972 |
}
|
| 33102 |
tejus.loha |
973 |
|
| 33143 |
tejus.loha |
974 |
@RequestMapping(value = "/priceDropReport", method = RequestMethod.GET)
|
|
|
975 |
public String getSelectPriceDropReport(HttpServletRequest request, @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
976 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model) throws Exception {
|
|
|
977 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
978 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
979 |
if (startDate == null) {
|
|
|
980 |
startDate = LocalDate.now().minusDays(30);
|
|
|
981 |
endDate = LocalDate.now();
|
|
|
982 |
}
|
| 34066 |
aman.kumar |
983 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
984 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
985 |
boolean isRBM = positions.stream()
|
|
|
986 |
.anyMatch(position ->
|
|
|
987 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
988 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
989 |
if (pp.containsKey(authUser.getId())) {
|
|
|
990 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
991 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
992 |
try {
|
|
|
993 |
return retailerService.getFofoRetailer(x);
|
|
|
994 |
} catch (ProfitMandiBusinessException e) {
|
|
|
995 |
// TODO Auto-generated catch block
|
|
|
996 |
return null;
|
|
|
997 |
}
|
|
|
998 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
999 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
1000 |
}
|
|
|
1001 |
|
|
|
1002 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
1003 |
model.addAttribute("startDate", startDate);
|
|
|
1004 |
model.addAttribute("endDate", endDate);
|
|
|
1005 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
1006 |
List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
|
|
|
1007 |
startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
1008 |
|
| 33143 |
tejus.loha |
1009 |
model.addAttribute("priceDropReports", priceDropReports);
|
| 33102 |
tejus.loha |
1010 |
|
| 33143 |
tejus.loha |
1011 |
return "price-drop-report";
|
|
|
1012 |
}
|
| 33102 |
tejus.loha |
1013 |
|
| 33143 |
tejus.loha |
1014 |
@RequestMapping(value = "/priceDropFetchReportByDate", method = RequestMethod.GET)
|
|
|
1015 |
public String getpriceDropFetchReportByDate(HttpServletRequest request,
|
|
|
1016 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
1017 |
@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
|
|
|
1018 |
@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
|
|
|
1019 |
throws Exception {
|
| 33102 |
tejus.loha |
1020 |
|
| 33143 |
tejus.loha |
1021 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1022 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
1023 |
if (startDate == null) {
|
|
|
1024 |
startDate = LocalDate.now().minusDays(30);
|
|
|
1025 |
endDate = LocalDate.now();
|
|
|
1026 |
}
|
| 34066 |
aman.kumar |
1027 |
AuthUser authUser = authRepository.selectByEmailOrMobile(fofoDetails.getEmailId());
|
|
|
1028 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
1029 |
boolean isRBM = positions.stream()
|
|
|
1030 |
.anyMatch(position ->
|
|
|
1031 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
1032 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
1033 |
if (pp.containsKey(authUser.getId())) {
|
|
|
1034 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
1035 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
1036 |
try {
|
|
|
1037 |
return retailerService.getFofoRetailer(x);
|
|
|
1038 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1039 |
// TODO Auto-generated catch block
|
|
|
1040 |
return null;
|
|
|
1041 |
}
|
|
|
1042 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
1043 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
1044 |
}
|
|
|
1045 |
|
|
|
1046 |
model.addAttribute("isRBM", isRBM);
|
| 33143 |
tejus.loha |
1047 |
model.addAttribute("startDate", startDate);
|
|
|
1048 |
model.addAttribute("endDate", endDate);
|
|
|
1049 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
1050 |
if (isAdmin) {
|
|
|
1051 |
if (fofoId == 0) {
|
|
|
1052 |
model.addAttribute("priceDropReports", new ArrayList<>());
|
|
|
1053 |
return "price-drop-report";
|
|
|
1054 |
} else {
|
|
|
1055 |
List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoId,
|
|
|
1056 |
startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1057 |
model.addAttribute("priceDropReports", priceDropReports);
|
|
|
1058 |
return "price-drop-report";
|
|
|
1059 |
}
|
| 33102 |
tejus.loha |
1060 |
|
| 33143 |
tejus.loha |
1061 |
} else {
|
|
|
1062 |
List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
|
|
|
1063 |
startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1064 |
model.addAttribute("priceDropReports", priceDropReports);
|
|
|
1065 |
return "price-drop-report";
|
|
|
1066 |
}
|
|
|
1067 |
}
|
| 33102 |
tejus.loha |
1068 |
|
|
|
1069 |
|
| 33143 |
tejus.loha |
1070 |
@RequestMapping(value = "/downloadPriceDropReport", method = RequestMethod.GET)
|
|
|
1071 |
public ResponseEntity<?> getSelectDownloadPriceDropReport(HttpServletRequest request,
|
|
|
1072 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
1073 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
1074 |
@RequestParam(name = "endDate") LocalDate endDate, Model model)
|
|
|
1075 |
throws Exception {
|
|
|
1076 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1077 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
1078 |
List<List<?>> rows = new ArrayList<>();
|
|
|
1079 |
List<PriceDropReportModel> priceDropReports = null;
|
|
|
1080 |
if (isAdmin) {
|
|
|
1081 |
if (fofoId == 0)
|
|
|
1082 |
priceDropReports = new ArrayList<>();
|
|
|
1083 |
else
|
|
|
1084 |
priceDropReports = orderRepository.selectPriceDropReport(fofoId,
|
|
|
1085 |
startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1086 |
} else {
|
|
|
1087 |
fofoId = fofoDetails.getFofoId();
|
|
|
1088 |
priceDropReports = orderRepository.selectPriceDropReport(fofoId,
|
|
|
1089 |
startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1090 |
}
|
|
|
1091 |
for (PriceDropReportModel pdr : priceDropReports) {
|
| 33102 |
tejus.loha |
1092 |
|
| 33143 |
tejus.loha |
1093 |
rows.add(Arrays.asList(pdr.getCode(), pdr.getId(), pdr.getBrand(), pdr.getModelName(), pdr.getModelNumber(),
|
|
|
1094 |
FormattingUtils.formatDate(pdr.getAffectedOn()), pdr.getAmount(), FormattingUtils.format(pdr.getCreditTimestamp()), pdr.getImei(), pdr.getStatus(),
|
|
|
1095 |
FormattingUtils.format(pdr.getRejectedTimestamp()), pdr.getRejectionReason()));
|
| 33102 |
tejus.loha |
1096 |
|
| 33143 |
tejus.loha |
1097 |
}
|
|
|
1098 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
|
|
1099 |
.getCSVByteStream(Arrays.asList("code", "Price_Drop_Id", "brand", "model_name", "model_number",
|
|
|
1100 |
"affected_on", "amount", "Credit Date", "Imei", "status", "Rejected Date", "Rejected Reason"), rows);
|
| 33102 |
tejus.loha |
1101 |
|
| 33143 |
tejus.loha |
1102 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price drop report");
|
| 33102 |
tejus.loha |
1103 |
|
| 33143 |
tejus.loha |
1104 |
return responseEntity;
|
| 33102 |
tejus.loha |
1105 |
|
| 33143 |
tejus.loha |
1106 |
}
|
| 33102 |
tejus.loha |
1107 |
|
| 33143 |
tejus.loha |
1108 |
@RequestMapping(value = "/downloadPartnerBillingSummaryReport", method = RequestMethod.GET)
|
|
|
1109 |
public ResponseEntity<?> getdownloadPartnerBillingSummaryReport(HttpServletRequest request,
|
|
|
1110 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
1111 |
@RequestParam(name = "endDate") LocalDate endDate, Model model)
|
|
|
1112 |
throws Exception {
|
| 33102 |
tejus.loha |
1113 |
|
| 33143 |
tejus.loha |
1114 |
List<List<?>> rows = new ArrayList<>();
|
|
|
1115 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 33102 |
tejus.loha |
1116 |
|
| 33143 |
tejus.loha |
1117 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
1118 |
LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
|
| 33102 |
tejus.loha |
1119 |
|
| 33143 |
tejus.loha |
1120 |
List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
|
|
|
1121 |
.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), startDate.atStartOfDay(),
|
|
|
1122 |
endDate.atTime(LocalTime.MAX));
|
| 33102 |
tejus.loha |
1123 |
|
| 33143 |
tejus.loha |
1124 |
for (PartnerBillingSummaryModel pbsr : partnerBillingSummaryReports) {
|
| 33102 |
tejus.loha |
1125 |
|
| 33143 |
tejus.loha |
1126 |
rows.add(Arrays.asList(pbsr.getId(),
|
|
|
1127 |
FormattingUtils.format(pbsr.getCreateTimestamp()),
|
|
|
1128 |
FormattingUtils.format(pbsr.getBillingTimestamp()),
|
|
|
1129 |
FormattingUtils.format(pbsr.getDeliveryTimestamp()),
|
|
|
1130 |
FormattingUtils.format(pbsr.getPartnerGrnTimestamp()),
|
|
|
1131 |
pbsr.getTransactionId(),
|
|
|
1132 |
pbsr.getLogisticsTransactionId(), pbsr.getAirwayBillNumber(), pbsr.getStatusSubGroup(),
|
|
|
1133 |
pbsr.getStatusName(), pbsr.getRetailerId(), pbsr.getRetailerName(), pbsr.getItemId(),
|
|
|
1134 |
pbsr.getBrand(), pbsr.getModelName(), pbsr.getModelNumber(), pbsr.getColor(), pbsr.getUnitPrice(),
|
|
|
1135 |
pbsr.getQuantity(), pbsr.getTotalPrice(), pbsr.getInvoiceNumber(), pbsr.getSellerName(), pbsr.getGstNumber(), pbsr.getHsnCode(), pbsr.getIgstRate(),
|
|
|
1136 |
pbsr.getCgstRate(), pbsr.getSgstRate()));
|
| 33102 |
tejus.loha |
1137 |
|
| 33143 |
tejus.loha |
1138 |
}
|
| 33102 |
tejus.loha |
1139 |
|
| 33143 |
tejus.loha |
1140 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("OrderId",
|
|
|
1141 |
"Created On", "Billed On", "Delivered On", "Grned On", "Transaction_id", "master_order_id",
|
|
|
1142 |
"airwaybill_no", "statusSubGroupp", "statusName", "customer_id", "customer_name", "Item_Id", "brand",
|
|
|
1143 |
"model_name", "model_number", "color", "selling_price", "Quantity", "total_price", "invoice_number",
|
|
|
1144 |
"seller_name", "gst_number", "hsn_code", "igstrate", "cgstrate", "sgstrate"), rows);
|
| 33102 |
tejus.loha |
1145 |
|
| 33143 |
tejus.loha |
1146 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Billing Statement Report");
|
| 33102 |
tejus.loha |
1147 |
|
| 33143 |
tejus.loha |
1148 |
return responseEntity;
|
| 33102 |
tejus.loha |
1149 |
|
|
|
1150 |
|
| 33143 |
tejus.loha |
1151 |
}
|
| 33102 |
tejus.loha |
1152 |
|
| 33143 |
tejus.loha |
1153 |
@RequestMapping(value = "/invoiceSchemeOutSummaryReport", method = RequestMethod.GET)
|
|
|
1154 |
public String getInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model) throws Exception {
|
|
|
1155 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 33102 |
tejus.loha |
1156 |
|
| 33143 |
tejus.loha |
1157 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
1158 |
LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
|
| 33102 |
tejus.loha |
1159 |
|
| 33143 |
tejus.loha |
1160 |
List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
|
|
|
1161 |
.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
|
|
|
1162 |
LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
|
| 33102 |
tejus.loha |
1163 |
|
| 33143 |
tejus.loha |
1164 |
model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
|
|
|
1165 |
model.addAttribute("endDate", LocalDate.now());
|
|
|
1166 |
model.addAttribute("focoSchemeOutReports", focoSchemeOutReports);
|
| 33102 |
tejus.loha |
1167 |
|
| 33143 |
tejus.loha |
1168 |
return "invoicewise-scheme-out-report";
|
|
|
1169 |
}
|
| 33102 |
tejus.loha |
1170 |
|
| 33143 |
tejus.loha |
1171 |
@RequestMapping(value = "/downloadInvoiceSchemeOutSummaryReport", method = RequestMethod.GET)
|
|
|
1172 |
public ResponseEntity<?> getDownloadInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model)
|
|
|
1173 |
throws Exception {
|
|
|
1174 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 33102 |
tejus.loha |
1175 |
|
| 33143 |
tejus.loha |
1176 |
List<List<?>> rows = new ArrayList<>();
|
|
|
1177 |
LocalDateTime currentDate = LocalDate.now().atStartOfDay();
|
|
|
1178 |
LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
|
| 33102 |
tejus.loha |
1179 |
|
| 33143 |
tejus.loha |
1180 |
List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
|
|
|
1181 |
.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
|
|
|
1182 |
LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
|
| 33102 |
tejus.loha |
1183 |
|
| 33143 |
tejus.loha |
1184 |
for (FocoSchemeOutReportModel fsor : focoSchemeOutReports) {
|
|
|
1185 |
rows.add(Arrays.asList(fsor.getInvoiceNumber(), fsor.getQuantity(), fsor.getBrand(), fsor.getModelName(),
|
|
|
1186 |
fsor.getModelNumber(), fsor.getColor(), fsor.getAmount()));
|
| 33102 |
tejus.loha |
1187 |
|
| 33143 |
tejus.loha |
1188 |
}
|
| 33102 |
tejus.loha |
1189 |
|
| 33143 |
tejus.loha |
1190 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
|
|
1191 |
Arrays.asList("InvoiceNumber", "Quantity", "Brand", "Model Name", "Model Number", "Color", "Amount"),
|
|
|
1192 |
rows);
|
| 33102 |
tejus.loha |
1193 |
|
| 33143 |
tejus.loha |
1194 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,
|
|
|
1195 |
"invoice wise scheme out Summary Report");
|
| 33102 |
tejus.loha |
1196 |
|
| 33143 |
tejus.loha |
1197 |
return responseEntity;
|
|
|
1198 |
}
|
| 33102 |
tejus.loha |
1199 |
|
| 33143 |
tejus.loha |
1200 |
@RequestMapping(value = "/schemePayoutReportDownload", method = RequestMethod.GET)
|
|
|
1201 |
public ResponseEntity<?> getSchemePayoutReportDownload(HttpServletRequest request,
|
|
|
1202 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
1203 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
1204 |
@RequestParam(name = "endDate") LocalDate endDate, Model model)
|
|
|
1205 |
throws Exception {
|
|
|
1206 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 33102 |
tejus.loha |
1207 |
|
| 33143 |
tejus.loha |
1208 |
List<List<?>> rows = new ArrayList<>();
|
| 33102 |
tejus.loha |
1209 |
|
| 33143 |
tejus.loha |
1210 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
| 33102 |
tejus.loha |
1211 |
|
| 33143 |
tejus.loha |
1212 |
List<SchemePayoutReportModel> schemePayoutReports = null;
|
|
|
1213 |
if (isAdmin) {
|
|
|
1214 |
if (fofoId == 0)
|
|
|
1215 |
schemePayoutReports = new ArrayList<>();
|
|
|
1216 |
else
|
|
|
1217 |
schemePayoutReports = fofoOrderRepository
|
|
|
1218 |
.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1219 |
} else {
|
|
|
1220 |
fofoId = fofoDetails.getFofoId();
|
|
|
1221 |
schemePayoutReports = fofoOrderRepository
|
|
|
1222 |
.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1223 |
}
|
|
|
1224 |
LOGGER.info("schemePayoutReports {}", schemePayoutReports);
|
| 33102 |
tejus.loha |
1225 |
|
| 33143 |
tejus.loha |
1226 |
for (SchemePayoutReportModel spr : schemePayoutReports) {
|
| 33102 |
tejus.loha |
1227 |
|
| 33143 |
tejus.loha |
1228 |
rows.add(Arrays.asList(spr.getId(), spr.getSerialNumber(), spr.getBrand(), spr.getModelName(),
|
|
|
1229 |
spr.getModelNumber(), spr.getColor(), spr.getSchemeInDp(), spr.getSchemeOutDp(), spr.getSchemeId(),
|
| 33646 |
amit.gupta |
1230 |
spr.getName(), spr.getType(), spr.getAmount(), spr.getAmountType(), spr.getSioAmount(), spr.getPurchaseReference(),
|
| 33656 |
amit.gupta |
1231 |
spr.getInvoiceNumber(), spr.getStatus(), spr.getStatusDescription(),
|
| 33646 |
amit.gupta |
1232 |
FormattingUtils.formatDateTime(spr.getCreateTimestamp()), FormattingUtils.formatDateTime(spr.getRolledBackTimestamp())));
|
| 33102 |
tejus.loha |
1233 |
|
| 33143 |
tejus.loha |
1234 |
}
|
| 33646 |
amit.gupta |
1235 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Item Id",
|
|
|
1236 |
"Serial No", "Brand", "Model Name", "Model Number", "Color", "Scheme In Dp", "Scheme Out Dp",
|
| 33656 |
amit.gupta |
1237 |
"Scheme Id", "Name", "Scheme Type", "Amount", "Amount Type", "Amount Paid", "Purchase Invoice", "Sale Invoice", "Status",
|
| 33646 |
amit.gupta |
1238 |
"Description", "Created on", "Reversed On"), rows);
|
| 33102 |
tejus.loha |
1239 |
|
| 33143 |
tejus.loha |
1240 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Scheme Payout Summary Report");
|
| 33102 |
tejus.loha |
1241 |
|
| 33143 |
tejus.loha |
1242 |
return responseEntity;
|
|
|
1243 |
}
|
| 33102 |
tejus.loha |
1244 |
|
|
|
1245 |
|
| 33143 |
tejus.loha |
1246 |
@RequestMapping(value = "/offerPayoutDumpReportDownload", method = RequestMethod.GET)
|
|
|
1247 |
public ResponseEntity<?> getOfferPayoutDumpReportDownload(HttpServletRequest request,
|
|
|
1248 |
@RequestParam(defaultValue = "0") int fofoId,
|
|
|
1249 |
@RequestParam(name = "startDate") LocalDate startDate,
|
|
|
1250 |
@RequestParam(name = "endDate") LocalDate endDate, Model model)
|
|
|
1251 |
throws Exception {
|
|
|
1252 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1253 |
List<List<?>> rows = new ArrayList<>();
|
|
|
1254 |
boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
|
|
|
1255 |
List<OfferPayoutDumpReportModel> offerPayoutReports = null;
|
|
|
1256 |
if (isAdmin) {
|
|
|
1257 |
if (fofoId == 0)
|
|
|
1258 |
offerPayoutReports = new ArrayList<>();
|
|
|
1259 |
else
|
|
|
1260 |
offerPayoutReports = fofoOrderRepository
|
|
|
1261 |
.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1262 |
} else {
|
|
|
1263 |
fofoId = fofoDetails.getFofoId();
|
|
|
1264 |
offerPayoutReports = fofoOrderRepository
|
|
|
1265 |
.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
|
|
|
1266 |
}
|
| 33102 |
tejus.loha |
1267 |
|
|
|
1268 |
|
| 33143 |
tejus.loha |
1269 |
for (OfferPayoutDumpReportModel opdr : offerPayoutReports) {
|
| 33102 |
tejus.loha |
1270 |
|
| 33143 |
tejus.loha |
1271 |
rows.add(Arrays.asList(opdr.getId(), opdr.getBrand(), opdr.getModelName(),
|
|
|
1272 |
opdr.getModelNumber(), opdr.getColor(), opdr.getSerialNumber(), opdr.getOfferId(),
|
|
|
1273 |
opdr.getName(), opdr.getType(),
|
|
|
1274 |
opdr.getSlabAmount(), opdr.getAmount(), opdr.getDescription(),
|
|
|
1275 |
opdr.getCreateTimestamp(), opdr.getRejectTimestamp()));
|
| 33102 |
tejus.loha |
1276 |
|
| 33143 |
tejus.loha |
1277 |
}
|
|
|
1278 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Id",
|
|
|
1279 |
"Brand", "Model Name", "Model Number", "Color", "Serial number",
|
|
|
1280 |
"Offer Id", "Name", "Type", "Slab Amount", "Amount",
|
|
|
1281 |
"Description", "Credited On", "Rejected On"), rows);
|
| 33102 |
tejus.loha |
1282 |
|
| 33143 |
tejus.loha |
1283 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Offer Payout Summary Report");
|
| 33102 |
tejus.loha |
1284 |
|
| 33143 |
tejus.loha |
1285 |
return responseEntity;
|
|
|
1286 |
}
|
| 33102 |
tejus.loha |
1287 |
|
|
|
1288 |
|
| 33143 |
tejus.loha |
1289 |
@GetMapping("/getAllOnlineOrder")
|
|
|
1290 |
public String getAllOrders(HttpServletRequest request, @RequestParam(required = false) LocalDate date, Model model)
|
|
|
1291 |
throws ProfitMandiBusinessException {
|
|
|
1292 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1293 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1294 |
if (date == null) {
|
|
|
1295 |
date = LocalDate.now().minusDays(3);
|
|
|
1296 |
}
|
| 33102 |
tejus.loha |
1297 |
|
| 33143 |
tejus.loha |
1298 |
LOGGER.info("date" + date);
|
|
|
1299 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
|
|
1300 |
.collect(Collectors.toList());
|
| 33102 |
tejus.loha |
1301 |
|
| 33143 |
tejus.loha |
1302 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| 33102 |
tejus.loha |
1303 |
|
| 33143 |
tejus.loha |
1304 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
|
|
1305 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
|
|
1306 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| 33102 |
tejus.loha |
1307 |
|
| 33143 |
tejus.loha |
1308 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
| 33102 |
tejus.loha |
1309 |
|
| 33143 |
tejus.loha |
1310 |
List<PendingOrderItem> pendingOrderItem = null;
|
| 33102 |
tejus.loha |
1311 |
|
| 33143 |
tejus.loha |
1312 |
pendingOrderItem = pendingOrderItemRepository.selectAll(date.atStartOfDay(), LocalDateTime.now());
|
| 33102 |
tejus.loha |
1313 |
|
| 33143 |
tejus.loha |
1314 |
Map<String, Object> map = pendingOrderService.getItemOrders(pendingOrderItem, 0);
|
| 33102 |
tejus.loha |
1315 |
|
| 33143 |
tejus.loha |
1316 |
model.addAttribute("pendingOrderItem", map.get("pendingOrderItem"));
|
|
|
1317 |
model.addAttribute("partnerInventoryMap", map.get("partnerInventoryMap"));
|
|
|
1318 |
model.addAttribute("date", date);
|
|
|
1319 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
1320 |
return "online-all-order-item";
|
|
|
1321 |
}
|
| 33102 |
tejus.loha |
1322 |
|
| 33143 |
tejus.loha |
1323 |
|
|
|
1324 |
@RequestMapping(value = "/reports", method = RequestMethod.GET)
|
|
|
1325 |
public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
|
|
|
1326 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
|
|
|
1327 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
|
| 28137 |
amit.gupta |
1328 |
/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
|
| 28106 |
amit.gupta |
1329 |
Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
|
|
|
1330 |
returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
|
|
|
1331 |
returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
|
| 28107 |
amit.gupta |
1332 |
returnMap = returnMap1;
|
| 28137 |
amit.gupta |
1333 |
}*/
|
| 33143 |
tejus.loha |
1334 |
model.addAttribute("reporticoProjectMap", returnMap);
|
|
|
1335 |
return "reports";
|
|
|
1336 |
}
|
| 33775 |
ranu |
1337 |
|
|
|
1338 |
@RequestMapping(value = "/account-statement", method = RequestMethod.GET)
|
|
|
1339 |
public String accountStatement(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
|
|
1340 |
@RequestParam(required = false) LocalDate startDate,
|
|
|
1341 |
@RequestParam(required = false) LocalDate endDate)
|
|
|
1342 |
throws Exception {
|
|
|
1343 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1344 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1345 |
|
| 34066 |
aman.kumar |
1346 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1347 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
1348 |
boolean isRBM = positions.stream()
|
|
|
1349 |
.anyMatch(position ->
|
|
|
1350 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
1351 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
1352 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
1353 |
Set<Integer> fofoIds = new HashSet<>(pp.get(authUser.getId()));
|
|
|
1354 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> {
|
|
|
1355 |
try {
|
|
|
1356 |
return retailerService.getFofoRetailers(true).get(x);
|
|
|
1357 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1358 |
// TODO Auto-generated catch block
|
|
|
1359 |
return null;
|
|
|
1360 |
}
|
|
|
1361 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
1362 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
1363 |
}
|
|
|
1364 |
|
| 33775 |
ranu |
1365 |
model.addAttribute("isAdmin", isAdmin);
|
| 34066 |
aman.kumar |
1366 |
model.addAttribute("isRBM", isRBM);
|
| 33775 |
ranu |
1367 |
|
|
|
1368 |
return "partner-account-statement";
|
|
|
1369 |
|
|
|
1370 |
}
|
|
|
1371 |
|
|
|
1372 |
@RequestMapping(value = "/account-statement-report", method = RequestMethod.GET)
|
|
|
1373 |
public String getPartnerAccountStatement(HttpServletRequest request, @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model, @RequestParam(defaultValue = "0") int fofoId) throws Exception {
|
|
|
1374 |
boolean isAdmin = roleManager.isAdmin(cookiesProcessor.getCookiesObject(request).getRoleIds());
|
|
|
1375 |
if (fofoId > 0) {
|
|
|
1376 |
if (!isAdmin) {
|
|
|
1377 |
throw new ProfitMandiBusinessException("Unauthorised access", "PartnerId", "Permission Denied");
|
|
|
1378 |
}
|
|
|
1379 |
} else {
|
|
|
1380 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
|
|
1381 |
}
|
|
|
1382 |
float openingBalance = walletService.getOpeningTill(fofoId, startDate);
|
|
|
1383 |
float closingBalance = walletService.getOpeningTill(fofoId, endDate);
|
|
|
1384 |
UserWallet uw = walletService.getUserWallet(fofoId);
|
|
|
1385 |
LOGGER.info("Start date - {}, end Date - {}", startDate, endDate);
|
|
|
1386 |
|
|
|
1387 |
List<UserWalletHistory> history = userWalletHistoryRepository.selectPaginatedByWalletId(uw.getId(), startDate, endDate, 0, 0);
|
|
|
1388 |
|
|
|
1389 |
history = history.stream().filter(x -> !x.getReferenceType().equals(WalletReferenceType.PURCHASE))
|
|
|
1390 |
.filter(x -> !WalletService.CN_WALLET_REFERENCES.contains(x.getReferenceType())).sorted(Comparator.comparing(UserWalletHistory::getId)).collect(Collectors.toList());
|
|
|
1391 |
Map<LocalDate, List<UserWalletHistory>> dateWalletMap = history.stream().collect(Collectors.groupingBy(x -> x.getTimestamp().toLocalDate()));
|
|
|
1392 |
CustomRetailer customRetailer = retailerService.getAllFofoRetailers().get(fofoId);
|
|
|
1393 |
List<StatementDetailModel> billedStatementDetails = orderRepository.selectDetailsBetween(fofoId, startDate, endDate);
|
|
|
1394 |
Map<Integer, Float> openingAmountMap = transactionService.getPendingIndentValueMap(startDate, Optional.of(fofoId));
|
|
|
1395 |
Map<Integer, Float> closingAmountMap = transactionService.getPendingIndentValueMap(endDate, Optional.of(fofoId));
|
|
|
1396 |
|
|
|
1397 |
float openingPendingAmount = openingAmountMap.get(fofoId) == null ? 0 : openingAmountMap.get(fofoId);
|
|
|
1398 |
float closingPendingAmount = closingAmountMap.get(fofoId) == null ? 0 : closingAmountMap.get(fofoId);
|
|
|
1399 |
LOGGER.info("Opening - {}, Closing - {}", openingPendingAmount, closingPendingAmount);
|
|
|
1400 |
|
|
|
1401 |
double grandTotalDebit = 0;
|
|
|
1402 |
double grandTotalCredit = 0;
|
|
|
1403 |
|
|
|
1404 |
for (UserWalletHistory walletEntry : history) {
|
|
|
1405 |
if (walletEntry.getAmount() < 0) {
|
|
|
1406 |
grandTotalDebit += Math.abs(walletEntry.getAmount());
|
|
|
1407 |
} else {
|
|
|
1408 |
grandTotalCredit += walletEntry.getAmount();
|
|
|
1409 |
}
|
|
|
1410 |
}
|
|
|
1411 |
|
|
|
1412 |
for (StatementDetailModel statement : billedStatementDetails) {
|
|
|
1413 |
if (statement.getAmount() < 0) {
|
|
|
1414 |
grandTotalCredit += Math.abs(statement.getAmount());
|
|
|
1415 |
} else {
|
|
|
1416 |
grandTotalDebit += statement.getAmount();
|
|
|
1417 |
}
|
|
|
1418 |
}
|
|
|
1419 |
|
|
|
1420 |
model.addAttribute("billedStatementDetails", billedStatementDetails);
|
|
|
1421 |
model.addAttribute("customRetailer", customRetailer);
|
|
|
1422 |
model.addAttribute("wallethistory", history);
|
|
|
1423 |
model.addAttribute("startDate", startDate);
|
|
|
1424 |
model.addAttribute("endDate", endDate);
|
|
|
1425 |
model.addAttribute("dateWalletMap", dateWalletMap);
|
|
|
1426 |
model.addAttribute("openingBalance", (openingBalance + openingPendingAmount));
|
|
|
1427 |
model.addAttribute("closingBalance", (closingBalance + closingPendingAmount));
|
|
|
1428 |
model.addAttribute("grandTotalDebit", grandTotalDebit);
|
|
|
1429 |
model.addAttribute("grandTotalCredit", grandTotalCredit);
|
|
|
1430 |
|
|
|
1431 |
return "account-statement-list";
|
|
|
1432 |
}
|
| 33809 |
ranu |
1433 |
|
|
|
1434 |
@RequestMapping(value = "/loan/loan-statement", method = RequestMethod.GET)
|
| 33814 |
ranu |
1435 |
public String loanStatement(HttpServletRequest request, Model model)
|
| 33809 |
ranu |
1436 |
throws Exception {
|
|
|
1437 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1438 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
| 34066 |
aman.kumar |
1439 |
AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
|
|
|
1440 |
List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId());
|
|
|
1441 |
boolean isRBM = positions.stream()
|
|
|
1442 |
.anyMatch(position ->
|
|
|
1443 |
ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId());
|
|
|
1444 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
1445 |
if (isRBM && pp.containsKey(authUser.getId())) {
|
|
|
1446 |
List<Integer> fofoIds = pp.get(authUser.getId());
|
|
|
1447 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(fofoId -> {
|
|
|
1448 |
try {
|
|
|
1449 |
return retailerService.getFofoRetailers(true).get(fofoId);
|
|
|
1450 |
} catch (ProfitMandiBusinessException e) {
|
|
|
1451 |
// TODO Auto-generated catch block
|
|
|
1452 |
return null;
|
|
|
1453 |
}
|
|
|
1454 |
}).filter(x -> x != null).collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
1455 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
|
|
1456 |
}
|
|
|
1457 |
model.addAttribute("isRBM", isRBM);
|
| 33809 |
ranu |
1458 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
1459 |
|
|
|
1460 |
return "partner-loan-statement";
|
|
|
1461 |
|
|
|
1462 |
}
|
|
|
1463 |
|
|
|
1464 |
@RequestMapping(value = "/loan/partner-loan-statement-report", method = RequestMethod.GET)
|
|
|
1465 |
public String partnerLoanStatement(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
|
|
1466 |
@RequestParam(required = false) LocalDateTime startDate,
|
|
|
1467 |
@RequestParam(required = false) LocalDateTime endDate)
|
|
|
1468 |
throws Exception {
|
|
|
1469 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1470 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1471 |
int partnerId = 0;
|
|
|
1472 |
|
|
|
1473 |
if (fofoId > 0) {
|
|
|
1474 |
partnerId = fofoId;
|
|
|
1475 |
} else {
|
|
|
1476 |
partnerId = loginDetails.getFofoId();
|
|
|
1477 |
}
|
|
|
1478 |
|
|
|
1479 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(partnerId);
|
|
|
1480 |
|
|
|
1481 |
List<LoanStatementReportModel> loanStatementReportModels = loanStatementRepository.selectByDatesAndStoreCode(startDate, endDate, fofoStore.getCode());
|
|
|
1482 |
|
|
|
1483 |
model.addAttribute("isAdmin", isAdmin);
|
|
|
1484 |
model.addAttribute("loanStatementReportModels", loanStatementReportModels);
|
|
|
1485 |
|
|
|
1486 |
return "partner-loan-statement-summary";
|
|
|
1487 |
|
|
|
1488 |
}
|
|
|
1489 |
|
|
|
1490 |
@RequestMapping(value = "/loan/download-partner-loan-statement-report", method = RequestMethod.GET)
|
|
|
1491 |
public ResponseEntity<?> downloadPartnerLoanStatement(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
|
|
|
1492 |
@RequestParam(required = false) LocalDateTime startDate,
|
|
|
1493 |
@RequestParam(required = false) LocalDateTime endDate)
|
|
|
1494 |
throws Exception {
|
|
|
1495 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
1496 |
boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
|
|
|
1497 |
|
|
|
1498 |
int partnerId = 0;
|
|
|
1499 |
|
|
|
1500 |
if (fofoId > 0) {
|
|
|
1501 |
partnerId = fofoId;
|
|
|
1502 |
} else {
|
|
|
1503 |
partnerId = loginDetails.getFofoId();
|
|
|
1504 |
}
|
|
|
1505 |
|
|
|
1506 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(partnerId);
|
|
|
1507 |
|
|
|
1508 |
List<List<?>> rows = new ArrayList<>();
|
|
|
1509 |
|
|
|
1510 |
List<LoanStatementReportModel> loanStatementReportModels = loanStatementRepository.selectByDatesAndStoreCode(startDate, endDate, fofoStore.getCode());// Extract the store name from the first loan statement
|
|
|
1511 |
String storeName = loanStatementReportModels.get(0).getStoreName();
|
|
|
1512 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
|
|
|
1513 |
for (LoanStatementReportModel loanStatement : loanStatementReportModels) {
|
|
|
1514 |
rows.add(Arrays.asList(
|
|
|
1515 |
loanStatement.getCode(), // Code
|
|
|
1516 |
String.valueOf(loanStatement.getId()), // ID (convert int to string)
|
|
|
1517 |
loanStatement.getStoreName(), // Store Name
|
|
|
1518 |
loanStatement.getState(), // State
|
|
|
1519 |
loanStatement.getZone(), // Zone
|
|
|
1520 |
loanStatement.getArea(), // Area
|
|
|
1521 |
loanStatement.getTerritory(), // Territory
|
|
|
1522 |
String.valueOf(loanStatement.getLoanId()), // Loan ID
|
|
|
1523 |
loanStatement.getInterestRate().toString(), // Interest Rate (BigDecimal to String)
|
|
|
1524 |
loanStatement.getIntialAmount().toString(), // Initial Amount (BigDecimal to String)
|
|
|
1525 |
loanStatement.getPendingAmount().toString(), // Pending Amount (BigDecimal to String)
|
|
|
1526 |
loanStatement.getCreatedOn().format(dateTimeFormatter), // Created On (format LocalDateTime)
|
|
|
1527 |
loanStatement.getDueDate().format(dateTimeFormatter), // Due Date (format LocalDateTime)
|
|
|
1528 |
loanStatement.getInterestAccrued().toString(), // Interest Accrued (BigDecimal to String)
|
|
|
1529 |
loanStatement.getInterestPaid().toString(), // Interest Paid (BigDecimal to String)
|
|
|
1530 |
String.valueOf(loanStatement.getFreeDays()), // Free Days (convert int to string)
|
|
|
1531 |
loanStatement.getLoanReferenceType().toString(), // Loan Reference Type (enum or string)
|
|
|
1532 |
loanStatement.getAmount().toString(), // Amount (BigDecimal to String)
|
|
|
1533 |
loanStatement.getBusinessDate().format(dateTimeFormatter), // Business Date (format LocalDateTime)
|
|
|
1534 |
loanStatement.getCreatedAt().format(dateTimeFormatter), // Created At (format LocalDateTime)
|
|
|
1535 |
loanStatement.getDescription(), // Description
|
|
|
1536 |
loanStatement.getStatus() // Status (calculated value)
|
|
|
1537 |
));
|
|
|
1538 |
}
|
|
|
1539 |
|
|
|
1540 |
// Set up the headers and create the CSV
|
|
|
1541 |
List<String> headers = Arrays.asList("Code", "ID", "Store Name", "State", "Zone", "Area", "Territory", "Loan ID",
|
|
|
1542 |
"Interest Rate", "Initial Amount", "Pending Amount", "Created On", "Due Date",
|
|
|
1543 |
"Interest Accrued", "Interest Paid", "Free Days", "Loan Reference Type",
|
|
|
1544 |
"Amount", "Business Date", "Created At", "Description", "Status");
|
|
|
1545 |
|
|
|
1546 |
// Create the CSV byte stream
|
|
|
1547 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, rows);
|
|
|
1548 |
ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Partner Loan Summary Report");
|
|
|
1549 |
|
|
|
1550 |
return responseEntity;
|
|
|
1551 |
|
|
|
1552 |
}
|
| 23612 |
amit.gupta |
1553 |
}
|