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