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