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