Subversion Repositories SmartDukaan

Rev

Rev 33092 | Rev 33108 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
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;
28106 amit.gupta 6
import com.spice.profitmandi.common.model.ReporticoUrlInfo;
23612 amit.gupta 7
import com.spice.profitmandi.common.services.ReporticoService;
30162 manish 8
import com.spice.profitmandi.common.util.FileUtil;
33102 tejus.loha 9
import com.spice.profitmandi.common.util.FormattingUtils;
26298 tejbeer 10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
33102 tejus.loha 11
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
12
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
13
import com.spice.profitmandi.dao.model.*;
26298 tejbeer 14
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
15
import com.spice.profitmandi.dao.repository.cs.CsService;
28106 amit.gupta 16
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
23784 ashik.ali 17
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
33102 tejus.loha 18
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
19
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
20
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
30162 manish 21
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
23798 amit.gupta 22
import com.spice.profitmandi.service.authentication.RoleManager;
30162 manish 23
import com.spice.profitmandi.service.order.OrderService;
33102 tejus.loha 24
import com.spice.profitmandi.service.user.RetailerService;
23612 amit.gupta 25
import com.spice.profitmandi.web.model.LoginDetails;
26
import com.spice.profitmandi.web.util.CookiesProcessor;
33092 tejus.loha 27
import org.apache.http.HttpResponse;
28
import org.apache.logging.log4j.LogManager;
29
import org.apache.logging.log4j.Logger;
30
import org.springframework.beans.factory.annotation.Autowired;
31
import org.springframework.core.io.InputStreamResource;
32
import org.springframework.http.HttpHeaders;
33
import org.springframework.http.HttpStatus;
34
import org.springframework.http.ResponseEntity;
35
import org.springframework.stereotype.Controller;
36
import org.springframework.transaction.annotation.Transactional;
37
import org.springframework.ui.Model;
38
import org.springframework.web.bind.annotation.*;
23612 amit.gupta 39
 
33092 tejus.loha 40
import javax.servlet.http.HttpServletRequest;
41
import java.io.IOException;
42
import java.time.LocalDate;
43
import java.time.LocalDateTime;
44
import java.time.LocalTime;
45
import java.time.format.DateTimeFormatter;
46
import java.util.*;
33102 tejus.loha 47
import java.util.stream.Collectors;
33092 tejus.loha 48
 
23612 amit.gupta 49
@Controller
26298 tejbeer 50
@Transactional(rollbackFor = Throwable.class)
23612 amit.gupta 51
public class ReportsController {
33102 tejus.loha 52
	private static final Logger LOGGER = LogManager.getLogger(OrderController.class);
23637 amit.gupta 53
	@Autowired
23784 ashik.ali 54
	private RoleRepository roleRepository;
26298 tejbeer 55
 
23764 amit.gupta 56
	@Autowired
33102 tejus.loha 57
	private FofoOrderRepository fofoOrderRepository;
58
 
59
	@Autowired
60
	private RetailerService retailerService;
61
 
62
	@Autowired
63
	private PendingOrderItemRepository pendingOrderItemRepository;
64
 
65
	@Autowired
66
	private PendingOrderService pendingOrderService;
67
 
68
	@Autowired
26298 tejbeer 69
	private CookiesProcessor cookiesProcessor;
28106 amit.gupta 70
	@Autowired
71
	private FofoStoreRepository fofoStoreRepository;
26298 tejbeer 72
 
23784 ashik.ali 73
	@Autowired
23652 amit.gupta 74
	private ReporticoService reporticoService;
23764 amit.gupta 75
 
23798 amit.gupta 76
	@Autowired
30162 manish 77
	private OrderRepository orderRepository;
78
	@Autowired
23798 amit.gupta 79
	private RoleManager roleManager;
30162 manish 80
	@Autowired
33102 tejus.loha 81
	private OrderService orderService;
26298 tejbeer 82
 
83
	@Autowired
84
	private CsService csService;
85
 
86
	@Autowired
87
	private AuthRepository authRepository;
88
 
30162 manish 89
	private static final Logger Logger = LogManager.getLogger(OrderController.class);
23612 amit.gupta 90
 
26063 amit.gupta 91
	@RequestMapping(value = "/reports/{projectName}/{fileName}")
23764 amit.gupta 92
	public ResponseEntity<?> fetchReport(HttpServletRequest request, @PathVariable String fileName,
33102 tejus.loha 93
										 @PathVariable ReporticoProject projectName, @RequestBody(required = false) Map<String, String> paramsMap)
23764 amit.gupta 94
			throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
23612 amit.gupta 95
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
96
		HttpResponse response;
26298 tejbeer 97
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
98
 
99
			if (fileName.equalsIgnoreCase("LeadsReport")) {
100
				if (paramsMap == null) {
101
					paramsMap = new HashMap<String, String>();
102
				}
26460 amit.gupta 103
				Map<Integer, List<Integer>> mapping = csService.getL2L1Mapping();
26298 tejbeer 104
 
105
				AuthUser authUser = authRepository.selectByEmailOrMobile(loginDetails.getEmailId());
106
 
107
				List<Integer> authIds = mapping.get(authUser.getId());
108
				if (authIds == null) {
109
					authIds = new ArrayList<>();
110
				}
111
				authIds.add(authUser.getId());
112
 
113
				paramsMap.put("authId", authIds + "");
114
			}
23612 amit.gupta 115
		} else {
26298 tejbeer 116
			if (paramsMap == null) {
26164 amit.gupta 117
				paramsMap = new HashMap<String, String>();
118
			}
26298 tejbeer 119
 
26158 amit.gupta 120
			paramsMap.put("MANUAL_fofoId", loginDetails.getFofoId() + "");
26298 tejbeer 121
 
23612 amit.gupta 122
		}
26298 tejbeer 123
		response = getAdminReportFile(loginDetails.getEmailId(), projectName, fileName + ".xml", paramsMap);
23612 amit.gupta 124
		HttpHeaders headers = new HttpHeaders();
23764 amit.gupta 125
		InputStreamResource is = new InputStreamResource(response.getEntity().getContent());
23765 amit.gupta 126
		headers.set("Content-Type", "application/vnd.ms-excel");
26298 tejbeer 127
		headers.set("Content-disposition", "inline; filename=report-" + fileName + ".csv");
23766 amit.gupta 128
		headers.setContentLength(response.getEntity().getContentLength());
23764 amit.gupta 129
		return new ResponseEntity<InputStreamResource>(is, headers, HttpStatus.OK);
23612 amit.gupta 130
	}
23637 amit.gupta 131
 
26298 tejbeer 132
	private HttpResponse getAdminReportFile(String email, ReporticoProject projectName, String fileName,
33102 tejus.loha 133
											Map<String, String> reportParams) throws ProfitMandiBusinessException, IOException {
26063 amit.gupta 134
		return reporticoService.getReportFile(projectName, fileName, reportParams);
135
	}
33102 tejus.loha 136
 
30162 manish 137
	@RequestMapping(value = "/collectionSummary", method = RequestMethod.GET)
138
	public String getCollectionSummary(HttpServletRequest request,
33102 tejus.loha 139
									   Model model) throws ProfitMandiBusinessException {
30162 manish 140
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
33092 tejus.loha 141
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
30162 manish 142
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
143
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
33102 tejus.loha 144
		List<CollectionSummary> collectionSummaryList = orderRepository.selectCollectionSummary(fofoDetails.getFofoId(), currentStartMonth, currentDate);
30162 manish 145
		Logger.info("CollectionSummaryList {}", collectionSummaryList);
33102 tejus.loha 146
		model.addAttribute("startDate", currentDate.minusDays(30).toLocalDate());
30162 manish 147
		model.addAttribute("endDate", LocalDate.now());
148
		model.addAttribute("collectionSummaryList", collectionSummaryList);
33092 tejus.loha 149
		model.addAttribute("isAdmin", isAdmin);
30162 manish 150
		return "partner-collection-summary";
151
	}
33102 tejus.loha 152
 
33067 shampa 153
	@RequestMapping(value = "/collectionSummaryFetchReportByDate", method = RequestMethod.GET)
154
	public String getcollectionSummaryFetchReport(HttpServletRequest request,
33092 tejus.loha 155
												  @RequestParam(defaultValue = "0") int fofoId,
33102 tejus.loha 156
												  @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
157
												  @RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
33067 shampa 158
			throws Exception {
159
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
33092 tejus.loha 160
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
161
		if (isAdmin) {
162
			startDate = LocalDate.now().minusDays(30);
163
			endDate = LocalDate.now();
164
		}
33102 tejus.loha 165
		model.addAttribute("startDate", startDate);
33092 tejus.loha 166
		model.addAttribute("endDate", endDate);
167
		model.addAttribute("isAdmin", isAdmin);
33067 shampa 168
 
169
 
33092 tejus.loha 170
		if (isAdmin) {
171
			if (fofoId == 0) {
172
				//No need to send any data
173
				model.addAttribute("collectionSummaryList", new ArrayList<>());
174
				return "partner-collection-summary";
175
			} else {
176
				List<CollectionSummary> collectionSummaryList = orderRepository
177
						.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
178
				model.addAttribute("collectionSummaryList", collectionSummaryList);
179
				return "partner-collection-summary";
180
			}
181
		} else {
182
			fofoId = fofoDetails.getFofoId();
183
			List<CollectionSummary> collectionSummaryList = orderRepository
184
					.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
185
			model.addAttribute("collectionSummaryList", collectionSummaryList);
186
			return "partner-collection-summary";
33067 shampa 187
 
33092 tejus.loha 188
		}
33067 shampa 189
	}
33102 tejus.loha 190
 
30162 manish 191
	@RequestMapping(value = "/downloadCollectionSummary", method = RequestMethod.GET)
33102 tejus.loha 192
	public ResponseEntity<?> getDownloadCollectionSummary(HttpServletRequest request,
193
														  @RequestParam int fofoId,
194
														  @RequestParam(name = "startDate") LocalDate startDate,
195
														  @RequestParam(name = "endDate") LocalDate endDate, Model model) throws Exception {
30162 manish 196
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
197
		List<List<?>> rows = new ArrayList<>();
33102 tejus.loha 198
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
199
		List<CollectionSummary> collectionSummaryList = null;
200
		if (isAdmin) {
201
			collectionSummaryList = orderRepository.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
202
		} else {
203
			fofoId = fofoDetails.getFofoId();
204
			collectionSummaryList = orderRepository.selectCollectionSummary(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
205
		}
30162 manish 206
		Logger.info("CollectionSummaryList {}", collectionSummaryList);
31377 tejbeer 207
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
33102 tejus.loha 208
		for (CollectionSummary cs : collectionSummaryList) {
31377 tejbeer 209
			rows.add(Arrays.asList(cs.getDate().format(
33102 tejus.loha 210
							dateTimeFormatter), cs.getReferenceType(), cs.getCash(), cs.getPinelabs(), cs.getBajajFinserv(), cs.getHomeCredit(), cs.getPaytm(),
211
					cs.getCapitalFirst(), cs.getZestMoney(), cs.getSamsungSure(), cs.getTotalAmount()));
30162 manish 212
		}
213
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
33102 tejus.loha 214
				.getCSVByteStream(Arrays.asList("Date", "Reference Type", "Cash", "Pinelabs", "Bajaj Finservice", "Home Credit", "Paymt",
30162 manish 215
						"Capital First", "Zest Money", "Samsung Sure", "Total Amount"), rows);
33102 tejus.loha 216
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Collection Summary Report");
30162 manish 217
 
218
		return responseEntity;
219
	}
220
 
33102 tejus.loha 221
	@RequestMapping(value = "/franchiseeSalesReport", method = RequestMethod.GET)
222
	public String getFranchiseeSalesReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
223
										   @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
224
			throws ProfitMandiBusinessException {
225
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
226
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
227
		if (startDate == null) {
228
			startDate = LocalDate.now().minusDays(30);
30162 manish 229
 
33102 tejus.loha 230
		}
231
		endDate = LocalDate.now();
232
		model.addAttribute("startDate", startDate);
233
		model.addAttribute("endDate", endDate);
234
		model.addAttribute("isAdmin", isAdmin);
235
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
236
		if (isAdmin) {
237
			if (fofoId == 0) {
238
				//No need to pull any data
239
				model.addAttribute("focoSaleReportList", new ArrayList<>());
240
				return "foco-sale-report";
241
 
242
			}
243
		} else {
244
			fofoId = loginDetails.getFofoId();
245
		}
246
 
247
 
248
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
249
 
250
		List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId, fs.getCode(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
251
		model.addAttribute("focoSaleReportList", focoSaleReportList);
252
		return "foco-sale-report";
253
	}
254
 
255
	@RequestMapping(value = "/franchiseeSalesFetchReportByDate", method = RequestMethod.GET)
256
	public String getfranchiseeSalesFetchReport(HttpServletRequest request, Model model,
257
												@RequestParam(defaultValue = "0") int fofoId,
258
												@RequestParam(required = false) LocalDate startDate,
259
												@RequestParam(required = false) LocalDate endDate)
260
			throws Exception {
261
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
262
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
263
		if (startDate == null) {
264
 
265
			startDate = LocalDate.now().minusDays(30);
266
			endDate = LocalDate.now();
267
		}
268
		model.addAttribute("startDate", startDate);
269
		model.addAttribute("endDate", endDate);
270
		model.addAttribute("isAdmin", isAdmin);
271
 
272
		// List<List<?>> rows = new ArrayList<>();
273
 
274
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
275
		if (isAdmin) {
276
			if (fofoId == 0) {
277
				//no need any data
278
				model.addAttribute("focoSaleReportList", new ArrayList<>());
279
				return "foco-sale-report";
280
			}
281
		} else {
282
			fofoId = loginDetails.getFofoId();
283
		}
284
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
285
		List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId, fs.getCode(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
286
		model.addAttribute("focoSaleReportList", focoSaleReportList);
287
		return "foco-sale-report";
288
	}
289
 
290
 
291
	@RequestMapping(value = "/downloadFranchiseeSales", method = RequestMethod.GET)
292
	public ResponseEntity<?> getdownloadFranchiseeSales(HttpServletRequest request,
293
														@RequestParam int fofoId,
294
														@RequestParam(name = "startDate") LocalDate startDate,
295
														@RequestParam(name = "endDate") LocalDate endDate,
296
														Model model)
297
			throws Exception {
298
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
299
 
300
		List<List<?>> rows = new ArrayList<>();
301
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
302
		List<FocoSaleReportModel> focoSaleReportList = null;
303
		FofoStore fs = null;
304
		if (isAdmin) {
305
			fs = fofoStoreRepository.selectByRetailerId(fofoId);
306
			focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoId,
307
					fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
308
 
309
		} else {
310
			fofoId = fofoDetails.getFofoId();
311
			fs = fofoStoreRepository.selectByRetailerId(fofoId);
312
 
313
			focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoDetails.getFofoId(),
314
					fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
315
		}
316
		LOGGER.info("FocoSaleReportList {}", focoSaleReportList);
317
		String partnerName = null;
318
		for (FocoSaleReportModel fsr : focoSaleReportList) {
319
			partnerName = fsr.getName();
320
			rows.add(Arrays.asList(fsr.getCode(), fsr.getName(), fsr.getCity(), fsr.getState(), fsr.getRegion(),
321
					fsr.getItemId(), fsr.getBrand(), fsr.getModelName(), fsr.getModelNumber(), fsr.getColor(),
322
					fsr.getQuantity(), fsr.getDp(), fsr.getSellingPrice(), fsr.getMop(), fsr.getSerialNumber(),
323
					FormattingUtils.format(fsr.getCreateDate()), fsr.getCustomerName(), fsr.getCustomerPhone(),
324
					fsr.getCustomerCity(), fsr.getCustomerPincode(), fsr.getInvoiceNumber(), fsr.getPurchaseReference(),
325
					fsr.getCustomerGstNumber(), FormattingUtils.format(fsr.getCancelledTimestamp()),
326
					FormattingUtils.format(fsr.getGrnCompleteDate()), fsr.getHygieneRating(), fsr.getRating(),
327
					fsr.getStatus(), fsr.getRemark(), FormattingUtils.format(fsr.getCreatedTimestamp()),
328
					FormattingUtils.format(fsr.getDisposedTimestamp()),
329
					FormattingUtils.format(fsr.getNextTimestamp()),
330
					FormattingUtils.format(fsr.getActivationTimestamp()),
331
					FormattingUtils.format(fsr.getActivationTimestamp()), fsr.getLabel()));
332
 
333
		}
334
 
335
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
336
				Arrays.asList("Code", "Name", "City", "State", "Region", "Item Id", "Brand", "Model Name",
337
						"Model Number", "Color", "Quantity", "Dp", "Selling_Price", "mop", "Serial Number",
338
						"Create Date", "Customer Name", "Customer Phone", "Customer City", " Customer Pincode",
339
						"Invoice  Number", "Purchase Reference", "Customer Gst Number", " Cancelled Timestamp",
340
						"GRN Complete Date", "Hygiene Rating", "Rating", "Status", "Remark", "Created Timestamp",
341
						"Disposed Timestamp", " Next Timestamp", "Activation Timestamp", "Create Timestamp", "Label"),
342
				rows);
343
 
344
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerName + " Franchisee Sales Report");
345
 
346
		return responseEntity;
347
 
348
	}
349
 
350
	@RequestMapping(value = "/downloadWalletSummaryReport", method = RequestMethod.GET)
351
	public ResponseEntity<?> getDownloadWalletSummaryReport(HttpServletRequest request,
352
															@RequestParam(defaultValue = "0", name = "fofoId") int fofoId,
353
															@RequestParam(name = "startDate") LocalDate startDate,
354
															@RequestParam(name = "endDate") LocalDate endDate, Model model)
355
			throws Exception {
356
 
357
		List<List<?>> rows = new ArrayList<>();
358
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
359
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
360
		List<WalletSummaryReportModel> walletSummartList = null;
361
		if (isAdmin) {
362
			walletSummartList = fofoOrderRepository.selectWalletSummaryReport(
363
					fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
364
		} else {
365
 
366
			walletSummartList = fofoOrderRepository.selectWalletSummaryReport(
367
					fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
368
		}
369
		LOGGER.info("walletSummartList {}", fofoId);
370
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
371
		String partnerName = null;
372
 
373
		for (WalletSummaryReportModel walletSummary : walletSummartList) {
374
			partnerName = walletSummary.getName();
375
 
376
			rows.add(Arrays.asList(
377
					walletSummary.getId(),
378
					walletSummary.getCode(),
379
					walletSummary.getName(),
380
					walletSummary.getEmail(),
381
					walletSummary.getPhone(),
382
					walletSummary.getAmount(),
383
					walletSummary.getRefundableAmount(),
384
					walletSummary.getReference(),
385
					walletSummary.getReferenceType(),
386
					FormattingUtils.format(walletSummary.getBusinessTimestamp())));
387
 
388
		}
389
 
390
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
391
				.getCSVByteStream(Arrays.asList("Id", "Code", "Name", "Email", "Phone", "Amount", "Refundable_amount",
392
						"Reference", "Reference_type", "Business_timestamp", "Description"), rows);
393
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, partnerName + " Wallet Statement Report");
394
 
395
		return responseEntity;
396
 
397
	}
398
 
399
	@RequestMapping(value = "/walletSummaryFetchReportByDate", method = RequestMethod.GET)
400
	public String getwalletSummaryFetchReport(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
401
											  @RequestParam(required = false) LocalDate startDate,
402
											  @RequestParam(required = false) LocalDate endDate)
403
			throws Exception {
404
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
405
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
406
		if (startDate == null) {
407
			startDate = LocalDate.now().minusDays(30);
408
		}
409
		endDate = LocalDate.now();
410
		model.addAttribute("startDate", startDate);
411
		model.addAttribute("endDate", endDate);
412
		model.addAttribute("isAdmin", isAdmin);
413
		if (isAdmin) {
414
			if (fofoId == 0) {
415
				//No need to send any data
416
				model.addAttribute("walletSummartList", new ArrayList<>());
417
 
418
				return "wallet-summary-report";
419
			} else {
420
				List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
421
						.selectWalletSummaryReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
422
				model.addAttribute("walletSummartList", walletSummartList);
423
 
424
				return "wallet-summary-report";
425
			}
426
 
427
		} else {
428
 
429
 
430
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
431
			List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
432
					.selectWalletSummaryReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
433
			//LOGGER.info("walletSummartList {}", walletSummartList);
434
 
435
			model.addAttribute("walletSummartList", walletSummartList);
436
 
437
			return "wallet-summary-report";
438
		}
439
	}
440
 
441
	@RequestMapping(value = "/walletSummaryReport", method = RequestMethod.GET)
442
	public String getWalletSummaryReport(HttpServletRequest request, Model model) throws Exception {
443
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
444
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
445
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
446
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
447
 
448
		List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
449
				.selectWalletSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
450
		LOGGER.info("walletSummartList {}", walletSummartList);
451
 
452
		model.addAttribute("startDate", currentDate.minusDays(30).toLocalDate());
453
		model.addAttribute("endDate", LocalDate.now());
454
		model.addAttribute("walletSummartList", walletSummartList);
455
		model.addAttribute("isAdmin", isAdmin);
456
 
457
		return "wallet-summary-report";
458
	}
459
 
460
	@RequestMapping(value = "/pendingIndentReport", method = RequestMethod.GET)
461
	public String getPendingIndentReport(HttpServletRequest request, Model model) throws Exception {
462
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
463
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
464
 
465
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
466
		LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();
467
 
468
		List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
469
				.selectPendingIndentReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
470
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
471
 
472
		model.addAttribute("startDate", currentDate.minusMonths(2).toLocalDate());
473
		model.addAttribute("endDate", LocalDate.now());
474
		model.addAttribute("pendingIndentReports", pendingIndentReports);
475
		model.addAttribute("isAdmin", isAdmin);
476
 
477
 
478
		return "pending-indent-report";
479
	}
480
 
481
	@RequestMapping(value = "/pendingIndentFetchReportByDate", method = RequestMethod.GET)
482
	public String getpendingIndentFetchReport(
483
			HttpServletRequest request,
484
			@RequestParam(defaultValue = "0") int fofoId,
485
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
486
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate,
487
			Model model
488
	) throws Exception {
489
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
490
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
491
		if (startDate == null) {
492
			startDate = LocalDate.now().minusDays(30);
493
			endDate = LocalDate.now();
494
		}
495
		model.addAttribute("startDate", startDate);
496
		model.addAttribute("endDate", endDate);
497
		model.addAttribute("isAdmin", isAdmin);
498
		if (isAdmin) {
499
			if (fofoId == 0) {
500
				model.addAttribute("pendingIndentReports", new ArrayList<>());
501
				return "pending-indent-report";
502
			} else {
503
				List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
504
						.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
505
				model.addAttribute("pendingIndentReports", pendingIndentReports);
506
				return "pending-indent-report";
507
			}
508
		} else {
509
			LocalDateTime currentDate = LocalDate.now().atStartOfDay();
510
			List<PendingIndentReportModel> pendingIndentReports = fofoOrderRepository
511
					.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
512
			model.addAttribute("pendingIndentReports", pendingIndentReports);
513
			return "pending-indent-report";
514
 
515
		}
516
	}
517
 
518
 
519
	@RequestMapping(value = "/pendingIndentReportDownload", method = RequestMethod.GET)
520
	public ResponseEntity<?> getPendingIndentReportDownload(HttpServletRequest request,
521
															@RequestParam int fofoId,
522
															@RequestParam(name = "startDate") LocalDate startDate,
523
															@RequestParam(name = "endDate") LocalDate endDate, Model model)
524
			throws Exception {
525
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
526
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
527
        /*LocalDateTime currentDate = LocalDate.now().atStartOfDay();
528
        LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();*/
529
		List<PendingIndentReportModel> pendingIndentReports = null;
530
		List<List<?>> rows = new ArrayList<>();
531
		if (isAdmin) {
532
			pendingIndentReports = fofoOrderRepository
533
					.selectPendingIndentReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
534
		} else {
535
			pendingIndentReports = fofoOrderRepository
536
					.selectPendingIndentReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
537
 
538
		}
539
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
540
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm");
541
 
542
		for (PendingIndentReportModel pir : pendingIndentReports) {
543
 
544
			rows.add(Arrays.asList(pir.getTransactionId(), pir.getOrderId(),
545
					pir.getCreatTimestamp().format(dateTimeFormatter), pir.getItemId(), pir.getBrand(),
546
					pir.getModelName(), pir.getModelNumber(), pir.getColor(), pir.getQuantity(), pir.getUnitPrice(),
547
					pir.getWalletAmount(), pir.getStatus(), pir.getInvoiceNumber(),
548
					pir.getBillingTimestamp() == null ? "" : pir.getBillingTimestamp().format(dateTimeFormatter)));
549
 
550
		}
551
 
552
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList(
553
				"Transaction Id", "Order Id", "Created_At", "Item_Id", "Brand", "Model Name", "Model Number", "Color",
554
				"Quantity", "Unit Price", "Wallet Deduction", "Status", "Invoice Number", "Billing Timestamp"), rows);
555
 
556
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Order Status Summary Report");
557
 
558
		return responseEntity;
559
	}
560
 
561
	@RequestMapping(value = "/schemePayoutReport", method = RequestMethod.GET)
562
	public String getschemePayoutReport(HttpServletRequest request, Model model,
563
										@RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
564
			throws ProfitMandiBusinessException {
565
 
566
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
567
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
568
		if (startDate == null) {
569
			startDate = LocalDate.now().minusDays(30);
570
			endDate = LocalDate.now();
571
		}
572
		model.addAttribute("startDate", startDate);
573
		model.addAttribute("endDate", endDate);
574
		model.addAttribute("isAdmin", isAdmin);
575
		//LOGGER.info("schemePayoutReports {}", schemePayoutReports);
576
		List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
577
				.selectSchemePayoutReport(loginDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
578
		model.addAttribute("schemePayoutReports", schemePayoutReports);
579
		return "scheme-payout-report";
580
 
581
	}
582
 
583
	@RequestMapping(value = "/schemePayoutFetchReportByDate", method = RequestMethod.GET)
584
	public String getschemePayoutFetchReportByDate(
585
			HttpServletRequest request,
586
			Model model,
587
			@RequestParam(defaultValue = "0") int fofoId,
588
			@RequestParam(required = false) LocalDate startDate,
589
			@RequestParam(required = false) LocalDate endDate)
590
			throws ProfitMandiBusinessException {
591
		//LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
592
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
593
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
594
		if (startDate == null) {
595
			startDate = LocalDate.now().minusDays(30);
596
			endDate = LocalDate.now();
597
		}
598
		model.addAttribute("startDate", startDate);
599
		model.addAttribute("endDate", endDate);
600
		model.addAttribute("isAdmin", isAdmin);
601
 
602
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
603
		if (isAdmin) {
604
			if (fofoId == 0) {
605
				//No need to pull any data
606
				model.addAttribute("schemePayoutReports", new ArrayList<>());
607
				return "scheme-payout-report";
608
 
609
			} else {
610
				List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
611
						.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
612
 
613
				model.addAttribute("schemePayoutReports", schemePayoutReports);
614
				return "scheme-payout-report";
615
			}
616
		} else {
617
			fofoId = loginDetails.getFofoId();
618
 
619
			List<SchemePayoutReportModel> schemePayoutReports = fofoOrderRepository
620
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
621
 
622
			model.addAttribute("schemePayoutReports", schemePayoutReports);
623
			return "scheme-payout-report";
624
		}
625
 
626
	}
627
 
628
	@RequestMapping(value = "/offerPayoutReport", method = RequestMethod.GET)
629
	public String getOfferPayoutReport(HttpServletRequest request, Model model, @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate) throws Exception {
630
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
631
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
632
 
633
		if (startDate == null) {
634
			startDate = LocalDate.now().minusDays(30);
635
			endDate = LocalDate.now();
636
		}
637
		model.addAttribute("startDate", startDate);
638
		model.addAttribute("endDate", endDate);
639
 
640
 
641
		List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
642
				.selectOfferPayoutDumpReport(fofoDetails.getFofoId(), startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
643
		LOGGER.info("offerPayoutDumpReports {}", offerPayoutDumpReports);
644
 
645
		model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
646
		model.addAttribute("isAdmin", isAdmin);
647
 
648
		return "offer-payout-dump-report";
649
	}
650
 
651
	@RequestMapping(value = "/offerPayoutFetchReportByDate", method = RequestMethod.GET)
652
	public String getofferPayoutFetchReportByDate(HttpServletRequest request, Model model, @RequestParam(defaultValue = "0") int fofoId,
653
												  @RequestParam(required = false) LocalDate startDate, @RequestParam(required = false) LocalDate endDate)
654
			throws ProfitMandiBusinessException {
655
 
656
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
657
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
658
		if (startDate == null) {
659
			startDate = LocalDate.now().minusDays(30);
660
			endDate = LocalDate.now();
661
		}
662
		model.addAttribute("startDate", startDate);
663
		model.addAttribute("endDate", endDate);
664
		model.addAttribute("isAdmin", isAdmin);
665
		LOGGER.info("q {}, starDate - {}, endDate - {}", fofoId, startDate, endDate);
666
		if (isAdmin) {
667
			if (fofoId == 0) {
668
				//No need to pull any data
669
				model.addAttribute("offerPayoutReports", new ArrayList<>());
670
				return "offer-payout-dump-report";
671
 
672
			} else {
673
				List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
674
						.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
675
 
676
				model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
677
 
678
 
679
				return "offer-payout-dump-report";
680
 
681
			}
682
		} else {
683
			fofoId = loginDetails.getFofoId();
684
			List<OfferPayoutDumpReportModel> offerPayoutDumpReports = fofoOrderRepository
685
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
686
 
687
			model.addAttribute("offerPayoutDumpReports", offerPayoutDumpReports);
688
 
689
 
690
			return "offer-payout-dump-report";
691
		}
692
	}
693
 
694
 
695
	@RequestMapping(value = "/selectPartnerBillingSummaryReport", method = RequestMethod.GET)
696
	public String getselectPartnerBillingSummaryReport(HttpServletRequest request, Model model) throws Exception {
697
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
698
 
699
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
700
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
701
 
702
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
703
				.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
704
 
705
		model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
706
		model.addAttribute("endDate", LocalDate.now());
707
		model.addAttribute("partnerBillingSummaryReports", partnerBillingSummaryReports);
708
 
709
		return "partner-billing-summary-report";
710
	}
711
 
712
	@RequestMapping(value = "/priceDropReport", method = RequestMethod.GET)
713
	public String getSelectPriceDropReport(HttpServletRequest request, @RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
714
										   @RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model) throws Exception {
715
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
716
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
717
		if (startDate == null) {
718
			startDate = LocalDate.now().minusDays(30);
719
			endDate = LocalDate.now();
720
		}
721
		model.addAttribute("startDate", startDate);
722
		model.addAttribute("endDate", endDate);
723
		model.addAttribute("isAdmin", isAdmin);
724
		List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
725
				startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
726
		model.addAttribute("priceDropReports", priceDropReports);
727
 
728
		return "price-drop-report";
729
	}
730
 
731
	@RequestMapping(value = "/priceDropFetchReportByDate", method = RequestMethod.GET)
732
	public String getpriceDropFetchReportByDate(HttpServletRequest request,
733
												@RequestParam(defaultValue = "0") int fofoId,
734
												@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
735
												@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
736
			throws Exception {
737
 
738
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
739
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
740
		if (startDate == null) {
741
			startDate = LocalDate.now().minusDays(30);
742
			endDate = LocalDate.now();
743
		}
744
		model.addAttribute("startDate", startDate);
745
		model.addAttribute("endDate", endDate);
746
		model.addAttribute("isAdmin", isAdmin);
747
		if (isAdmin) {
748
			if (fofoId == 0) {
749
				model.addAttribute("priceDropReports", new ArrayList<>());
750
				return "price-drop-report";
751
			} else {
752
				List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoId,
753
						startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
754
				model.addAttribute("priceDropReports", priceDropReports);
755
				return "price-drop-report";
756
			}
757
 
758
		} else {
759
			List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(),
760
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
761
			model.addAttribute("priceDropReports", priceDropReports);
762
			return "price-drop-report";
763
		}
764
	}
765
 
766
 
767
	@RequestMapping(value = "/downloadPriceDropReport", method = RequestMethod.GET)
768
	public ResponseEntity<?> getSelectDownloadPriceDropReport(HttpServletRequest request,
769
															  @RequestParam() int fofoId,
770
															  @RequestParam(name = "startDate") LocalDate startDate,
771
															  @RequestParam(name = "endDate") LocalDate endDate, Model model)
772
			throws Exception {
773
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
774
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
775
		List<List<?>> rows = new ArrayList<>();
776
		List<PriceDropReportModel> priceDropReports = null;
777
		if (isAdmin) {
778
			priceDropReports = orderRepository.selectPriceDropReport(fofoId,
779
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
780
		} else {
781
			fofoId = fofoDetails.getFofoId();
782
			priceDropReports = orderRepository.selectPriceDropReport(fofoId,
783
					startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
784
		}
785
		for (PriceDropReportModel pdr : priceDropReports) {
786
 
787
			rows.add(Arrays.asList(pdr.getCode(), pdr.getId(), pdr.getBrand(), pdr.getModelName(), pdr.getModelNumber(),
788
					pdr.getAffectedOn(), pdr.getAmount(), pdr.getPartnerPayout(), pdr.getImei(), pdr.getStatus(),
789
					pdr.getUpdateTimestamp(), pdr.getRejectionReason()));
790
 
791
		}
792
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
793
				.getCSVByteStream(Arrays.asList("code", "Price_Drop_Id", "brand", "model_name", "model_number",
794
						"affected_on", "amount", "partner_payout", "Imei", "status", "processed_on", "Reason"), rows);
795
 
796
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price drop report");
797
 
798
		return responseEntity;
799
 
800
	}
801
 
802
	@RequestMapping(value = "/downloadPartnerBillingSummaryReport", method = RequestMethod.GET)
803
	public ResponseEntity<?> getdownloadPartnerBillingSummaryReport(HttpServletRequest request,
804
																	@RequestParam(name = "startDate") LocalDate startDate,
805
																	@RequestParam(name = "endDate") LocalDate endDate, Model model)
806
			throws Exception {
807
 
808
		List<List<?>> rows = new ArrayList<>();
809
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
810
 
811
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
812
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
813
 
814
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository
815
				.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), startDate.atStartOfDay(),
816
						endDate.atTime(LocalTime.MAX));
817
 
818
		for (PartnerBillingSummaryModel pbsr : partnerBillingSummaryReports) {
819
 
820
			rows.add(Arrays.asList(pbsr.getId(),
821
					FormattingUtils.format(pbsr.getCreateTimestamp()),
822
					FormattingUtils.format(pbsr.getBillingTimestamp()),
823
					FormattingUtils.format(pbsr.getDeliveryTimestamp()),
824
					FormattingUtils.format(pbsr.getPartnerGrnTimestamp()),
825
					pbsr.getTransactionId(),
826
					pbsr.getLogisticsTransactionId(), pbsr.getAirwayBillNumber(), pbsr.getStatusSubGroup(),
827
					pbsr.getStatusName(), pbsr.getRetailerId(), pbsr.getRetailerName(), pbsr.getItemId(),
828
					pbsr.getBrand(), pbsr.getModelName(), pbsr.getModelNumber(), pbsr.getColor(), pbsr.getUnitPrice(),
829
					pbsr.getQuantity(), pbsr.getTotalPrice(), pbsr.getInvoiceNumber(), pbsr.getSellerName(), pbsr.getGstNumber(), pbsr.getHsnCode(), pbsr.getIgstRate(),
830
					pbsr.getCgstRate(), pbsr.getSgstRate()));
831
 
832
		}
833
 
834
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("OrderId",
835
				"Created On", "Billed On", "Delivered On", "Grned On", "Transaction_id", "master_order_id",
836
				"airwaybill_no", "statusSubGroupp", "statusName", "customer_id", "customer_name", "Item_Id", "brand",
837
				"model_name", "model_number", "color", "selling_price", "Quantity", "total_price", "invoice_number",
838
				"seller_name", "gst_number", "hsn_code", "igstrate", "cgstrate", "sgstrate"), rows);
839
 
840
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Billing Statement Report");
841
 
842
		return responseEntity;
843
 
844
 
845
	}
846
 
847
	@RequestMapping(value = "/invoiceSchemeOutSummaryReport", method = RequestMethod.GET)
848
	public String getInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model) throws Exception {
849
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
850
 
851
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
852
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
853
 
854
		List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
855
				.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
856
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
857
 
858
		model.addAttribute("startDate", currentDate.minusMonths(3).toLocalDate());
859
		model.addAttribute("endDate", LocalDate.now());
860
		model.addAttribute("focoSchemeOutReports", focoSchemeOutReports);
861
 
862
		return "invoicewise-scheme-out-report";
863
	}
864
 
865
	@RequestMapping(value = "/downloadInvoiceSchemeOutSummaryReport", method = RequestMethod.GET)
866
	public ResponseEntity<?> getDownloadInvoiceSchemeOutSummaryReport(HttpServletRequest request, Model model)
867
			throws Exception {
868
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
869
 
870
		List<List<?>> rows = new ArrayList<>();
871
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
872
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
873
 
874
		List<FocoSchemeOutReportModel> focoSchemeOutReports = fofoOrderRepository
875
				.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
876
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
877
 
878
		for (FocoSchemeOutReportModel fsor : focoSchemeOutReports) {
879
			rows.add(Arrays.asList(fsor.getInvoiceNumber(), fsor.getQuantity(), fsor.getBrand(), fsor.getModelName(),
880
					fsor.getModelNumber(), fsor.getColor(), fsor.getAmount()));
881
 
882
		}
883
 
884
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
885
				Arrays.asList("InvoiceNumber", "Quantity", "Brand", "Model Name", "Model Number", "Color", "Amount"),
886
				rows);
887
 
888
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,
889
				"invoice wise scheme out Summary Report");
890
 
891
		return responseEntity;
892
	}
893
 
894
	@RequestMapping(value = "/schemePayoutReportDownload", method = RequestMethod.GET)
895
	public ResponseEntity<?> getSchemePayoutReportDownload(HttpServletRequest request,
896
														   @RequestParam int fofoId,
897
														   @RequestParam(name = "startDate") LocalDate startDate,
898
														   @RequestParam(name = "endDate") LocalDate endDate, Model model)
899
			throws Exception {
900
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
901
 
902
		List<List<?>> rows = new ArrayList<>();
903
 
904
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
905
 
906
		List<SchemePayoutReportModel> schemePayoutReports = null;
907
		if (isAdmin) {
908
			schemePayoutReports = fofoOrderRepository
909
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
910
		} else {
911
			fofoId = fofoDetails.getFofoId();
912
			schemePayoutReports = fofoOrderRepository
913
					.selectSchemePayoutReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
914
		}
915
		LOGGER.info("schemePayoutReports {}", schemePayoutReports);
916
 
917
		for (SchemePayoutReportModel spr : schemePayoutReports) {
918
 
919
			rows.add(Arrays.asList(spr.getId(), spr.getSerialNumber(), spr.getBrand(), spr.getModelName(),
920
					spr.getModelNumber(), spr.getColor(), spr.getSchemeInDp(), spr.getSchemeOutDp(), spr.getSchemeId(),
921
					spr.getName(), spr.getType(), spr.getAmountType(), spr.getPurchaseReference(),
922
					spr.getInvoiceNumber(), spr.getSioAmount(), spr.getStatus(), spr.getStatusDescription(),
923
					spr.getCreateTimestamp(), spr.getRolledBackTimestamp()));
924
 
925
		}
926
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Item_Id",
927
				"serial_number", "Brand", "Model Name", "Model Number", "Color", "Scheme_IN_DP", "Scheme_out_dp",
928
				"Scheme_Id", "Name", "Type", "amount", "Purchase_Invoice", "SALE_INOVOICE", "Amount", "status",
929
				"description", "create_timestamp", "rolled_back_timestamp"), rows);
930
 
931
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Scheme Payout Summary Report");
932
 
933
		return responseEntity;
934
	}
935
 
936
 
937
	@RequestMapping(value = "/offerPayoutDumpReportDownload", method = RequestMethod.GET)
938
	public ResponseEntity<?> getOfferPayoutDumpReportDownload(HttpServletRequest request,
939
															  @RequestParam int fofoId,
940
															  @RequestParam(name = "startDate") LocalDate startDate,
941
															  @RequestParam(name = "endDate") LocalDate endDate, Model model)
942
			throws Exception {
943
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
944
		List<List<?>> rows = new ArrayList<>();
945
		boolean isAdmin = roleManager.isAdmin(fofoDetails.getRoleIds());
946
		List<OfferPayoutDumpReportModel> offerPayoutReports = null;
947
		if (isAdmin) {
948
			offerPayoutReports = fofoOrderRepository
949
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
950
		} else {
951
			fofoId = fofoDetails.getFofoId();
952
			offerPayoutReports = fofoOrderRepository
953
					.selectOfferPayoutDumpReport(fofoId, startDate.atStartOfDay(), endDate.atTime(LocalTime.MAX));
954
		}
955
 
956
 
957
		for (OfferPayoutDumpReportModel opdr : offerPayoutReports) {
958
 
959
			rows.add(Arrays.asList(opdr.getId(), opdr.getBrand(), opdr.getModelName(),
960
					opdr.getModelNumber(), opdr.getColor(), opdr.getSerialNumber(), opdr.getOfferId(),
961
					opdr.getName(), opdr.getType(),
962
					opdr.getSlabAmount(), opdr.getAmount(), opdr.getDescription(),
963
					opdr.getCreateTimestamp(), opdr.getRejectTimestamp()));
964
 
965
		}
966
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("Id",
967
				"Brand", "Model Name", "Model Number", "Color", "Serial number",
968
				"Offer Id", "Name", "Type", "Slab Amount", "Amount",
969
				"Description", "Credited On", "Rejected On"), rows);
970
 
971
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Offer Payout Summary Report");
972
 
973
		return responseEntity;
974
	}
975
 
976
 
977
	@GetMapping("/getAllOnlineOrder")
978
	public String getAllOrders(HttpServletRequest request, @RequestParam(required = false) LocalDate date, Model model)
979
			throws ProfitMandiBusinessException {
980
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
981
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
982
		if (date == null) {
983
			date = LocalDate.now().minusDays(3);
984
		}
985
 
986
		LOGGER.info("date" + date);
987
		List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
988
				.collect(Collectors.toList());
989
 
990
		Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
991
 
992
		Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
993
				.filter(x -> x != null).collect(Collectors.toList()).stream()
994
				.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
995
 
996
		model.addAttribute("customRetailersMap", customRetailersMap);
997
 
998
		List<PendingOrderItem> pendingOrderItem = null;
999
 
1000
		pendingOrderItem = pendingOrderItemRepository.selectAll(date.atStartOfDay(), LocalDateTime.now());
1001
 
1002
		Map<String, Object> map = pendingOrderService.getItemOrders(pendingOrderItem, 0);
1003
 
1004
		model.addAttribute("pendingOrderItem", map.get("pendingOrderItem"));
1005
		model.addAttribute("partnerInventoryMap", map.get("partnerInventoryMap"));
1006
		model.addAttribute("date", date);
1007
		model.addAttribute("isAdmin", isAdmin);
1008
		return "online-all-order-item";
1009
	}
1010
 
1011
 
23822 amit.gupta 1012
	@RequestMapping(value = "/reports", method = RequestMethod.GET)
28106 amit.gupta 1013
	public String reports(HttpServletRequest httpServletRequest, Model model) throws ProfitMandiBusinessException, UnsupportedOperationException, IOException {
28137 amit.gupta 1014
		//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(httpServletRequest);
28106 amit.gupta 1015
		Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap = ReporticoProject.reporticoProjectMap;
28137 amit.gupta 1016
		/*if(fofoStoreRepository.getWarehousePartnerMap().get(7720).stream().filter(x->x.getId()==loginDetails.getFofoId()).count() > 0) {
28106 amit.gupta 1017
			Map<ReporticoProject, List<ReporticoUrlInfo>> returnMap1 = new HashMap<ReporticoProject, List<ReporticoUrlInfo>>();
1018
			returnMap1.put(ReporticoProject.FOCO, returnMap.get(ReporticoProject.FOCO));
1019
			returnMap1.put(ReporticoProject.FOCOR, returnMap.get(ReporticoProject.FOCOR).stream().skip(1).collect(Collectors.toList()));
28107 amit.gupta 1020
			returnMap = returnMap1;
28137 amit.gupta 1021
		}*/
28107 amit.gupta 1022
		model.addAttribute("reporticoProjectMap", returnMap);
23637 amit.gupta 1023
		return "reports";
1024
	}
23612 amit.gupta 1025
}