Subversion Repositories SmartDukaan

Rev

Rev 30148 | Rev 30167 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30148 Rev 30162
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.io.ByteArrayInputStream;
-
 
4
import java.io.ByteArrayOutputStream;
-
 
5
import java.io.InputStream;
-
 
6
import java.time.LocalDate;
-
 
7
import java.time.LocalDateTime;
-
 
8
import java.time.format.DateTimeFormatter;
-
 
9
import java.time.temporal.ChronoUnit;
-
 
10
import java.util.ArrayList;
-
 
11
import java.util.Arrays;
-
 
12
import java.util.HashMap;
-
 
13
import java.util.HashSet;
-
 
14
import java.util.List;
-
 
15
import java.util.Map;
-
 
16
import java.util.Set;
-
 
17
import java.util.stream.Collectors;
-
 
18
 
-
 
19
import javax.servlet.http.HttpServletRequest;
-
 
20
import javax.servlet.http.HttpServletResponse;
-
 
21
 
-
 
22
import org.apache.logging.log4j.LogManager;
-
 
23
import org.apache.logging.log4j.Logger;
-
 
24
import org.json.JSONObject;
-
 
25
import org.springframework.beans.factory.annotation.Autowired;
-
 
26
import org.springframework.core.io.InputStreamResource;
-
 
27
import org.springframework.http.HttpHeaders;
-
 
28
import org.springframework.http.HttpStatus;
-
 
29
import org.springframework.http.MediaType;
-
 
30
import org.springframework.http.ResponseEntity;
-
 
31
import org.springframework.stereotype.Controller;
-
 
32
import org.springframework.transaction.annotation.Transactional;
-
 
33
import org.springframework.ui.Model;
-
 
34
import org.springframework.web.bind.annotation.GetMapping;
-
 
35
import org.springframework.web.bind.annotation.PathVariable;
-
 
36
import org.springframework.web.bind.annotation.PutMapping;
-
 
37
import org.springframework.web.bind.annotation.RequestBody;
-
 
38
import org.springframework.web.bind.annotation.RequestMapping;
-
 
39
import org.springframework.web.bind.annotation.RequestMethod;
-
 
40
import org.springframework.web.bind.annotation.RequestParam;
-
 
41
 
3
import com.google.gson.Gson;
42
import com.google.gson.Gson;
4
import com.spice.profitmandi.common.enumuration.SearchType;
43
import com.spice.profitmandi.common.enumuration.SearchType;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
44
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
6
import com.spice.profitmandi.common.model.*;
45
import com.spice.profitmandi.common.model.CartFofo;
-
 
46
import com.spice.profitmandi.common.model.CreateOrderRequest;
-
 
47
import com.spice.profitmandi.common.model.CreditNotePdfModel;
-
 
48
import com.spice.profitmandi.common.model.CustomCustomer;
-
 
49
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
50
import com.spice.profitmandi.common.model.FofoItemIdAmountModel;
-
 
51
import com.spice.profitmandi.common.model.FoiBadReturnRequest;
-
 
52
import com.spice.profitmandi.common.model.PartnerOptionsAndItemAmountModel;
-
 
53
import com.spice.profitmandi.common.model.PaymentOptionTransactionModel;
-
 
54
import com.spice.profitmandi.common.model.PdfModel;
-
 
55
import com.spice.profitmandi.common.model.PriceModel;
-
 
56
import com.spice.profitmandi.common.model.ProfitMandiConstants;
7
import com.spice.profitmandi.common.solr.SolrService;
57
import com.spice.profitmandi.common.solr.SolrService;
-
 
58
import com.spice.profitmandi.common.util.FileUtil;
8
import com.spice.profitmandi.common.util.PdfUtils;
59
import com.spice.profitmandi.common.util.PdfUtils;
9
import com.spice.profitmandi.common.util.StringUtils;
60
import com.spice.profitmandi.common.util.StringUtils;
10
import com.spice.profitmandi.common.web.util.ResponseSender;
61
import com.spice.profitmandi.common.web.util.ResponseSender;
11
import com.spice.profitmandi.dao.entity.catalog.Item;
62
import com.spice.profitmandi.dao.entity.catalog.Item;
12
import com.spice.profitmandi.dao.entity.catalog.TagListing;
63
import com.spice.profitmandi.dao.entity.catalog.TagListing;
13
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
64
import com.spice.profitmandi.dao.entity.dtr.InsurancePolicy;
14
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
65
import com.spice.profitmandi.dao.entity.dtr.InsuranceProvider;
15
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
66
import com.spice.profitmandi.dao.entity.dtr.PaymentOptionTransaction;
-
 
67
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
-
 
68
import com.spice.profitmandi.dao.entity.fofo.Customer;
-
 
69
import com.spice.profitmandi.dao.entity.fofo.CustomerAddress;
-
 
70
import com.spice.profitmandi.dao.entity.fofo.CustomerCreditNote;
-
 
71
import com.spice.profitmandi.dao.entity.fofo.CustomerReturnItem;
-
 
72
import com.spice.profitmandi.dao.entity.fofo.FofoLineItem;
-
 
73
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
-
 
74
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
-
 
75
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
16
import com.spice.profitmandi.dao.entity.fofo.*;
76
import com.spice.profitmandi.dao.entity.fofo.Mou;
-
 
77
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
-
 
78
import com.spice.profitmandi.dao.entity.fofo.PendingOrder;
-
 
79
import com.spice.profitmandi.dao.entity.fofo.PendingOrderItem;
17
import com.spice.profitmandi.dao.entity.user.Address;
80
import com.spice.profitmandi.dao.entity.user.Address;
18
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
81
import com.spice.profitmandi.dao.enumuration.dtr.PaymentOptionReferenceType;
19
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
82
import com.spice.profitmandi.dao.enumuration.transaction.OrderStatus;
-
 
83
import com.spice.profitmandi.dao.model.FocoSaleReportModel;
-
 
84
import com.spice.profitmandi.dao.model.FocoSchemeOutReportModel;
-
 
85
import com.spice.profitmandi.dao.model.PartnerBillingSummaryModel;
-
 
86
import com.spice.profitmandi.dao.model.PendingIndentReportModel;
-
 
87
import com.spice.profitmandi.dao.model.PriceDropReportModel;
-
 
88
import com.spice.profitmandi.dao.model.SchemePayoutReportModel;
-
 
89
import com.spice.profitmandi.dao.model.WalletSummaryReportModel;
20
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
90
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
21
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
91
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
22
import com.spice.profitmandi.dao.repository.dtr.*;
92
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
93
import com.spice.profitmandi.dao.repository.dtr.InsurancePolicyRepository;
-
 
94
import com.spice.profitmandi.dao.repository.dtr.InsuranceProviderRepository;
-
 
95
import com.spice.profitmandi.dao.repository.dtr.PaymentOptionTransactionRepository;
-
 
96
import com.spice.profitmandi.dao.repository.dtr.RetailerRegisteredAddressRepository;
-
 
97
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
-
 
98
import com.spice.profitmandi.dao.repository.fofo.CustomerAddressRepository;
-
 
99
import com.spice.profitmandi.dao.repository.fofo.CustomerRepository;
-
 
100
import com.spice.profitmandi.dao.repository.fofo.CustomerReturnItemRepository;
-
 
101
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
-
 
102
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
-
 
103
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
23
import com.spice.profitmandi.dao.repository.fofo.*;
104
import com.spice.profitmandi.dao.repository.fofo.MouRepository;
-
 
105
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
-
 
106
import com.spice.profitmandi.dao.repository.fofo.PendingOrderItemRepository;
-
 
107
import com.spice.profitmandi.dao.repository.fofo.PendingOrderRepository;
-
 
108
import com.spice.profitmandi.dao.repository.fofo.PendingOrderService;
24
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
109
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
-
 
110
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
25
import com.spice.profitmandi.dao.repository.user.AddressRepository;
111
import com.spice.profitmandi.dao.repository.user.AddressRepository;
26
import com.spice.profitmandi.service.EmailService;
112
import com.spice.profitmandi.service.EmailService;
27
import com.spice.profitmandi.service.authentication.RoleManager;
113
import com.spice.profitmandi.service.authentication.RoleManager;
28
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
114
import com.spice.profitmandi.service.integrations.zest.InsuranceService;
29
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
115
import com.spice.profitmandi.service.integrations.zest.MobileInsurancePlan;
Line 137... Line 223...
137
	@Autowired
223
	@Autowired
138
	private ResponseSender<?> responseSender;
224
	private ResponseSender<?> responseSender;
139
 
225
 
140
	@Autowired
226
	@Autowired
141
	private PendingOrderRepository pendingOrderRepository;
227
	private PendingOrderRepository pendingOrderRepository;
-
 
228
	
-
 
229
	@Autowired
-
 
230
	private OrderRepository orderRepository;
142
 
231
	
143
	@Autowired
232
	@Autowired
144
	private PendingOrderItemRepository pendingOrderItemRepository;
233
	private PendingOrderItemRepository pendingOrderItemRepository;
145
 
234
 
146
	@Autowired
235
	@Autowired
147
	private FofoStoreRepository fofoStoreRepository;
236
	private FofoStoreRepository fofoStoreRepository;
Line 528... Line 617...
528
					paymentOptionTransaction);
617
					paymentOptionTransaction);
529
		}
618
		}
530
		return paymentOptionIdPaymentOptionTransactionMap;
619
		return paymentOptionIdPaymentOptionTransactionMap;
531
	}
620
	}
532
 
621
 
-
 
622
 
533
	@RequestMapping(value = "/create-order", method = RequestMethod.POST)
623
	@RequestMapping(value = "/create-order", method = RequestMethod.POST)
534
	public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
624
	public String createOrder(HttpServletRequest request, @RequestBody CreateOrderRequest createOrderRequest,
535
			Model model) throws ProfitMandiBusinessException {
625
			Model model) throws ProfitMandiBusinessException {
536
		// throw new ProfitMandiBusinessException("Billing is on hold temporarily",
626
		// throw new ProfitMandiBusinessException("Billing is on hold temporarily",
537
		// "Billing is on hold temporarily", "Billing is on hold temporarily");
627
		// "Billing is on hold temporarily", "Billing is on hold temporarily");
Line 1273... Line 1363...
1273
		model.addAttribute("partnerInventoryMap", map.get("partnerInventoryMap"));
1363
		model.addAttribute("partnerInventoryMap", map.get("partnerInventoryMap"));
1274
 
1364
 
1275
		model.addAttribute("isAdmin", isAdmin);
1365
		model.addAttribute("isAdmin", isAdmin);
1276
		return "online-order-item";
1366
		return "online-order-item";
1277
	}
1367
	}
-
 
1368
	
-
 
1369
	@RequestMapping(value = "/franchiseeSalesReport", method = RequestMethod.GET)
-
 
1370
	public String getFranchiseeSalesReport(HttpServletRequest request,
-
 
1371
			Model model) throws ProfitMandiBusinessException {
-
 
1372
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1373
		
-
 
1374
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1375
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
-
 
1376
		FofoStore fs =fofoStoreRepository.selectByRetailerId(fofoDetails.getFofoId());
-
 
1377
 
-
 
1378
	    List<FocoSaleReportModel> focoSaleReportList =fofoOrderRepository.selectFocoSaleReport(fofoDetails.getFofoId(),fs.getCode(),currentStartMonth, currentDate);
-
 
1379
		
-
 
1380
		LOGGER.info("focoSaleReportList {}", focoSaleReportList);
-
 
1381
		
-
 
1382
		
-
 
1383
		model.addAttribute("startDate",currentDate.minusDays(30).toLocalDate());
-
 
1384
		model.addAttribute("endDate", LocalDate.now());
-
 
1385
		model.addAttribute("focoSaleReportList", focoSaleReportList);
-
 
1386
		return "foco-sale-report";
-
 
1387
	}
-
 
1388
	
-
 
1389
	@RequestMapping(value = "/downloadFranchiseeSales", method = RequestMethod.GET)
-
 
1390
	public ResponseEntity<?> getdownloadFranchiseeSales(HttpServletRequest request,
-
 
1391
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
-
 
1392
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
-
 
1393
			throws Exception {
-
 
1394
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1395
		List<List<?>> rows = new ArrayList<>();
-
 
1396
 
-
 
1397
		FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoDetails.getFofoId());
-
 
1398
		List<FocoSaleReportModel> focoSaleReportList = fofoOrderRepository.selectFocoSaleReport(fofoDetails.getFofoId(),
-
 
1399
				fs.getCode(), startDate.atStartOfDay(), endDate.atStartOfDay());
-
 
1400
		LOGGER.info("FocoSaleReportList {}", focoSaleReportList);
-
 
1401
 
-
 
1402
		for (FocoSaleReportModel fsr : focoSaleReportList) {
-
 
1403
 
-
 
1404
			rows.add(Arrays.asList(fsr.getCode(), fsr.getName(), fsr.getCity(), fsr.getState(), fsr.getRegion(),
-
 
1405
					fsr.getItemId(), fsr.getBrand(), fsr.getModelName(), fsr.getModelNumber(), fsr.getColor(),
-
 
1406
					fsr.getQuantity(), fsr.getDp(), fsr.getSellingPrice(), fsr.getMop(), fsr.getSerialNumber(),
-
 
1407
					fsr.getCreateDate(), fsr.getCustomerName(), fsr.getCustomerPhone(), fsr.getCustomerCity(),
-
 
1408
					fsr.getCustomerPincode(), fsr.getInvoiceNumber(), fsr.getPurchaseReference(),
-
 
1409
					fsr.getCustomerGstNumber(), fsr.getCancelledTimestamp(), fsr.getGrnCompleteDate(),
-
 
1410
					fsr.getHygieneRating(), fsr.getRating(), fsr.getStatus(), fsr.getRemark(),
-
 
1411
					fsr.getCreatedTimestamp(), fsr.getDisposedTimestamp(), fsr.getNextTimestamp(),
-
 
1412
					fsr.getActivationTimestamp(), fsr.getActivationTimestamp(), fsr.getLabel()));
-
 
1413
 
-
 
1414
		}
-
 
1415
 
-
 
1416
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
-
 
1417
				Arrays.asList("Code", "Name", "City", "State", "Region", "Item Id", "Brand", "Model Name",
-
 
1418
						"Model Number", "Color", "Quantity", "Dp", "Selling_Price", "mop", "Serial Number",
-
 
1419
						"Create Date", "Customer Name", "Customer Phone", "Customer City", " Customer Pincode",
-
 
1420
						"Invoice  Number", "Purchase Reference", "Customer Gst Number", " Cancelled Timestamp",
-
 
1421
						"GRN Complete Date", "Hygiene Rating", "Rating", "Status", "Remark", "Created Timestamp",
-
 
1422
						"Disposed Timestamp", " Next Timestamp", "Activation Timestamp", "Create Timestamp", "Label"),
-
 
1423
				rows);
-
 
1424
 
-
 
1425
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Franchisee Sales Report");
-
 
1426
 
-
 
1427
		return responseEntity;
-
 
1428
 
-
 
1429
	}
-
 
1430
	
-
 
1431
	@RequestMapping(value = "/downloadWalletSummaryReport", method = RequestMethod.GET)
-
 
1432
	public ResponseEntity<?> getDownloadWalletSummaryReport(HttpServletRequest request,
-
 
1433
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
-
 
1434
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
-
 
1435
			throws Exception {
-
 
1436
 
-
 
1437
		List<List<?>> rows = new ArrayList<>();
-
 
1438
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1439
 
-
 
1440
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1441
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
-
 
1442
 
-
 
1443
		List<WalletSummaryReportModel> walletSummartList = fofoOrderRepository
-
 
1444
				.selectWalletSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
1445
		LOGGER.info("walletSummartList {}", walletSummartList);
-
 
1446
 
-
 
1447
		for (WalletSummaryReportModel walletSummart : walletSummartList) {
1278
 
1448
 
-
 
1449
			rows.add(Arrays.asList(walletSummart.getId(), walletSummart.getCode(), walletSummart.getName(),
-
 
1450
					walletSummart.getEmail(), walletSummart.getPhone(), walletSummart.getAmount(),
-
 
1451
					walletSummart.getRefundableAmount(), walletSummart.getReference(), walletSummart.getReferenceType(),
-
 
1452
					walletSummart.getBusinessTimestamp(), walletSummart.getDescription()));
-
 
1453
 
-
 
1454
		}
-
 
1455
 
-
 
1456
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
1457
				.getCSVByteStream(Arrays.asList("Id", "Code", "Name", "Email", "Phone", "Amount", "Refundable_amount",
-
 
1458
						"Reference", "Reference_type", "Business_timestamp", "Description"), rows);
-
 
1459
 
-
 
1460
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Wallet Statement Report");
-
 
1461
 
-
 
1462
		return responseEntity;
-
 
1463
 
-
 
1464
	}
-
 
1465
	
-
 
1466
	@RequestMapping(value = "/walletSummaryReport", method = RequestMethod.GET)
-
 
1467
	public String getWalletSummaryReport(HttpServletRequest request,
-
 
1468
			Model model) throws Exception {
-
 
1469
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1470
	
-
 
1471
 
-
 
1472
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1473
		LocalDateTime currentStartMonth = currentDate.minusDays(30).toLocalDate().atStartOfDay();
-
 
1474
		
-
 
1475
		List<WalletSummaryReportModel> walletSummartList =fofoOrderRepository.selectWalletSummaryReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1476
		LOGGER.info("walletSummartList {}", walletSummartList);
-
 
1477
		
-
 
1478
		model.addAttribute("startDate",currentDate.minusDays(30).toLocalDate());
-
 
1479
		model.addAttribute("endDate", LocalDate.now());
-
 
1480
		model.addAttribute("walletSummartList", walletSummartList);
-
 
1481
	
-
 
1482
		return "wallet-summary-report";
-
 
1483
	}
-
 
1484
	
-
 
1485
	@RequestMapping(value = "/pendingIndentReport", method = RequestMethod.GET)
-
 
1486
	public String getPendingIndentReport(HttpServletRequest request,
-
 
1487
			Model model) throws Exception {
-
 
1488
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1489
	
-
 
1490
 
-
 
1491
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1492
		LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();
-
 
1493
		
-
 
1494
		List<PendingIndentReportModel> pendingIndentReports =fofoOrderRepository.selectPendingIndentReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1495
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
-
 
1496
		
-
 
1497
		model.addAttribute("startDate",currentDate.minusMonths(2).toLocalDate());
-
 
1498
		model.addAttribute("endDate", LocalDate.now());
-
 
1499
		model.addAttribute("pendingIndentReports", pendingIndentReports);
-
 
1500
	
-
 
1501
		return "pending-indent-report";
-
 
1502
	}
-
 
1503
	
-
 
1504
	
-
 
1505
	@RequestMapping(value = "/pendingIndentReportDownload", method = RequestMethod.GET)
-
 
1506
	public ResponseEntity<?> getPendingIndentReportDownload(HttpServletRequest request,
-
 
1507
			Model model) throws Exception {
-
 
1508
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1509
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1510
		LocalDateTime currentStartMonth = currentDate.minusMonths(2).toLocalDate().atStartOfDay();
-
 
1511
		List<List<?>> rows = new ArrayList<>();
-
 
1512
		List<PendingIndentReportModel> pendingIndentReports =fofoOrderRepository.selectPendingIndentReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1513
		LOGGER.info("pendingIndentReports {}", pendingIndentReports);
-
 
1514
		
-
 
1515
      for( PendingIndentReportModel pir : pendingIndentReports) {
-
 
1516
 
-
 
1517
     
-
 
1518
			rows.add(Arrays.asList(pir.getTransactionId(),pir.getOrderId(),pir.getCreatTimestamp(),pir.getItemId()
-
 
1519
					,pir.getBrand(),pir.getModelName(),pir.getModelNumber(),pir.getColor(),pir.getQuantity()
-
 
1520
					,pir.getUnitPrice(),pir.getWalletAmount(),pir.getStatus(),pir.getInvoiceNumber(),
-
 
1521
					pir.getBillingTimestamp()));
-
 
1522
			
-
 
1523
		}
-
 
1524
      
-
 
1525
    
-
 
1526
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
1527
				.getCSVByteStream(Arrays.asList("Transaction Id", "Order Id","Created_At", "Item_Id", "Brand", "Model Name",
-
 
1528
						"Model Number", "Color"  ,"Quantity", "Unit Price", "Wallet Deduction", "Status", "Invoice Number", "Billing Timestamp"),rows);
-
 
1529
						
-
 
1530
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows,"Order Status Summary Report");
-
 
1531
 
-
 
1532
		
-
 
1533
		return responseEntity;
-
 
1534
	}
-
 
1535
	
-
 
1536
	@RequestMapping(value = "/schemePayoutReport", method = RequestMethod.GET)
-
 
1537
	public String getSchemePayoutReport(HttpServletRequest request,
-
 
1538
			Model model) throws Exception {
-
 
1539
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1540
	
-
 
1541
 
-
 
1542
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1543
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1544
		
-
 
1545
		List<SchemePayoutReportModel> schemePayoutReports =fofoOrderRepository.selectSchemePayoutReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1546
		LOGGER.info("schemePayoutReports {}", schemePayoutReports);
-
 
1547
		
-
 
1548
		
-
 
1549
		
-
 
1550
		model.addAttribute("startDate",currentDate.minusMonths(3).toLocalDate());
-
 
1551
		model.addAttribute("endDate", LocalDate.now());
-
 
1552
		model.addAttribute("schemePayoutReports", schemePayoutReports);
-
 
1553
	
-
 
1554
		return "scheme-payout-report";
-
 
1555
	}
-
 
1556
	@RequestMapping(value = "/selectPartnerBillingSummaryReport", method = RequestMethod.GET)
-
 
1557
	public String getselectPartnerBillingSummaryReport(HttpServletRequest request,
-
 
1558
			Model model) throws Exception {
-
 
1559
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1560
	
-
 
1561
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1562
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1563
		
-
 
1564
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
1565
		
-
 
1566
		
-
 
1567
		model.addAttribute("startDate",currentDate.minusMonths(3).toLocalDate());
-
 
1568
		model.addAttribute("endDate", LocalDate.now());
-
 
1569
		model.addAttribute("partnerBillingSummaryReports", partnerBillingSummaryReports);
-
 
1570
		
-
 
1571
		return "partner-billing-summary-report";
-
 
1572
	}
-
 
1573
	
-
 
1574
	@RequestMapping(value = "/priceDropReport", method = RequestMethod.GET)
-
 
1575
	public String getSelectPriceDropReport(HttpServletRequest request,
-
 
1576
			Model model) throws Exception {
-
 
1577
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1578
	
-
 
1579
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1580
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1581
		
-
 
1582
		List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
1583
		
-
 
1584
		model.addAttribute("startDate",currentDate.minusMonths(3).toLocalDate());
-
 
1585
		model.addAttribute("endDate", LocalDate.now());
-
 
1586
		model.addAttribute("priceDropReports", priceDropReports);
-
 
1587
		
-
 
1588
		return "price-drop-report";
-
 
1589
	}
-
 
1590
	
-
 
1591
	@RequestMapping(value = "/downloadPriceDropReport", method = RequestMethod.GET)
-
 
1592
	public  ResponseEntity<?> getSelectDownloadPriceDropReport(HttpServletRequest request,
-
 
1593
			Model model) throws Exception {
-
 
1594
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1595
	
-
 
1596
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1597
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1598
		List<List<?>> rows = new ArrayList<>();
-
 
1599
		List<PriceDropReportModel> priceDropReports = orderRepository.selectPriceDropReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
1600
		
-
 
1601
     for (PriceDropReportModel pdr : priceDropReports) {
-
 
1602
			
-
 
1603
			rows.add(Arrays.asList(pdr.getCode(), pdr.getId(), pdr.getBrand(),pdr.getModelName(),
-
 
1604
					pdr.getModelNumber(), pdr.getAffectedOn() ,pdr.getAmount(), pdr.getPartnerPayout(),
-
 
1605
					pdr.getImei(), pdr.getStatus(),pdr.getUpdateTimestamp(),pdr.getRejectionReason()));
-
 
1606
 
-
 
1607
		}
-
 
1608
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
1609
				.getCSVByteStream(Arrays.asList("code","Price_Drop_Id","brand","model_name","model_number"
-
 
1610
						,"affected_on","amount", "partner_payout", "Imei", "status","processed_on"
-
 
1611
						  ,  "Reason"), rows);
-
 
1612
 
-
 
1613
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "price drop report");
-
 
1614
 
-
 
1615
		return responseEntity;
-
 
1616
		
-
 
1617
	}
-
 
1618
	
-
 
1619
	
-
 
1620
	@RequestMapping(value = "/downloadPartnerBillingSummaryReport", method = RequestMethod.GET)
-
 
1621
	public ResponseEntity<?> getdownloadPartnerBillingSummaryReport(HttpServletRequest request,
-
 
1622
			@RequestParam(name = "startDate", required = true, defaultValue = "") LocalDate startDate,
-
 
1623
			@RequestParam(name = "endDate", required = true, defaultValue = "") LocalDate endDate, Model model)
-
 
1624
			throws Exception {
-
 
1625
 
-
 
1626
		List<List<?>> rows = new ArrayList<>();
-
 
1627
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1628
		
-
 
1629
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1630
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1631
		
-
 
1632
		List<PartnerBillingSummaryModel> partnerBillingSummaryReports = fofoOrderRepository.selectPartnerBillingSummaryReport(fofoDetails.getFofoId(), currentStartMonth, currentDate);
-
 
1633
	
-
 
1634
		for (PartnerBillingSummaryModel pbsr : partnerBillingSummaryReports) {
-
 
1635
			
-
 
1636
			rows.add(Arrays.asList(pbsr.getId(), pbsr.getCreateTimestamp(), pbsr.getBillingTimestamp(),pbsr.getDeliveryTimestamp(),
-
 
1637
					pbsr.getDeliveryTimestamp(), pbsr.getPartnerGrnTimestamp() ,pbsr.getTransactionId(), pbsr.getLogisticsTransactionId(),
-
 
1638
					pbsr.getAirwayBillNumber(), pbsr.getStatusSubGroup(), pbsr.getStatusName(),pbsr.getRetailerId(), pbsr.getRetailerName(),pbsr.getItemId(), pbsr.getBrand()
-
 
1639
					         , pbsr.getModelName(),  pbsr.getModelNumber(),pbsr.getColor(),pbsr.getUnitPrice(), pbsr.getQuantity(),
-
 
1640
					          pbsr.getTotalPrice(),pbsr.getInvoiceNumber(), pbsr.getIgstRate(),pbsr.getCgstRate(),pbsr.getSgstRate()));
-
 
1641
 
-
 
1642
		}
-
 
1643
 
-
 
1644
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
1645
				.getCSVByteStream(Arrays.asList("OrderId","CREATION_DATE","BILLING_DATE","DELIVERED_ON","SCANNED_IN_ON"
-
 
1646
						,"Transaction_id","master_order_id", "airwaybill_no", "statusSubGroupp", "statusName","customer_id"
-
 
1647
						  ,  "customer_name","Item_Id", "brand", "model_name",  "model_number" ,"color", "selling_price"
-
 
1648
						                 ,"Quantity","total_price","invoice_number","igstrate","cgstrate","sgstrate"), rows);
-
 
1649
 
-
 
1650
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Billing Statement Report");
-
 
1651
 
-
 
1652
		return responseEntity;
-
 
1653
 
-
 
1654
	}
-
 
1655
	
-
 
1656
	@RequestMapping(value = "/invoiceSchemeOutSummaryReport", method = RequestMethod.GET)
-
 
1657
	public String getInvoiceSchemeOutSummaryReport(HttpServletRequest request,
-
 
1658
			Model model) throws Exception {
-
 
1659
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1660
	
-
 
1661
 
-
 
1662
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1663
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1664
		
-
 
1665
		List<FocoSchemeOutReportModel> focoSchemeOutReports =fofoOrderRepository.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1666
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
-
 
1667
		
-
 
1668
		
-
 
1669
		
-
 
1670
		model.addAttribute("startDate",currentDate.minusMonths(3).toLocalDate());
-
 
1671
		model.addAttribute("endDate", LocalDate.now());
-
 
1672
		model.addAttribute("focoSchemeOutReports", focoSchemeOutReports);
-
 
1673
	
-
 
1674
		return "invoicewise-scheme-out-report";
-
 
1675
	}
-
 
1676
	
-
 
1677
	@RequestMapping(value = "/downloadInvoiceSchemeOutSummaryReport", method = RequestMethod.GET)
-
 
1678
	public ResponseEntity<?> getDownloadInvoiceSchemeOutSummaryReport(HttpServletRequest request,
-
 
1679
			Model model) throws Exception {
-
 
1680
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1681
	
-
 
1682
		List<List<?>> rows = new ArrayList<>();
-
 
1683
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1684
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1685
		
-
 
1686
		List<FocoSchemeOutReportModel> focoSchemeOutReports =fofoOrderRepository.selectInvoiceSchemeOutSummaryReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1687
		LOGGER.info("focoSchemeOutReportModel {}", focoSchemeOutReports);
-
 
1688
		
-
 
1689
		for( FocoSchemeOutReportModel  fsor : focoSchemeOutReports) {
-
 
1690
			rows.add(Arrays.asList(fsor.getInvoiceNumber(),fsor.getQuantity(),fsor.getBrand(),fsor.getModelName()
-
 
1691
					,fsor.getModelNumber(),fsor.getColor(),fsor.getAmount()));
-
 
1692
			
-
 
1693
		}
-
 
1694
	
-
 
1695
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
1696
				.getCSVByteStream(Arrays.asList("InvoiceNumber", "Quantity","Brand", "Model Name", "Model Number", 
-
 
1697
						 "Color"  ,"Amount"),rows);
-
 
1698
						
-
 
1699
		ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "invoice wise scheme out Summary Report");
-
 
1700
 
-
 
1701
		return responseEntity;
-
 
1702
	}
-
 
1703
	
-
 
1704
	@RequestMapping(value = "/schemePayoutReportDownload", method = RequestMethod.GET)
-
 
1705
	public ResponseEntity<?> getSchemePayoutReportDownload(HttpServletRequest request,
-
 
1706
			Model model) throws Exception {
-
 
1707
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
-
 
1708
	
-
 
1709
		List<List<?>> rows = new ArrayList<>();
-
 
1710
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
1711
		LocalDateTime currentStartMonth = currentDate.minusMonths(3).toLocalDate().atStartOfDay();
-
 
1712
		
-
 
1713
		List<SchemePayoutReportModel> schemePayoutReports =fofoOrderRepository.selectSchemePayoutReport(fofoDetails.getFofoId(),currentStartMonth, currentDate);
-
 
1714
		LOGGER.info("schemePayoutReports {}", schemePayoutReports);
-
 
1715
	
-
 
1716
	
-
 
1717
		 for( SchemePayoutReportModel spr : schemePayoutReports) {
-
 
1718
			
-
 
1719
				rows.add(Arrays.asList(spr.getId(),spr.getSerialNumber(),spr.getBrand(),spr.getModelName()
-
 
1720
						,spr.getModelNumber(),spr.getColor(),spr.getSchemeInDp(),spr.getSchemeOutDp(),
-
 
1721
						spr.getSchemeId(),spr.getName(),spr.getType(),spr.getAmountType(),spr.getPurchaseReference()
-
 
1722
						,spr.getInvoiceNumber(),spr.getSioAmount(),spr.getStatus(),spr.getStatusDescription()
-
 
1723
						,spr.getCreateTimestamp(),spr.getRolledBackTimestamp()));
-
 
1724
				
-
 
1725
			}
-
 
1726
			org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
1727
					.getCSVByteStream(Arrays.asList("Item_Id", "serial_number","Brand", "Model Name", "Model Number", 
-
 
1728
							 "Color"  ,"Scheme_IN_DP", "Scheme_out_dp", "Scheme_Id", "Name", "Type", "amount", "Purchase_Invoice",
-
 
1729
							 "SALE_INOVOICE","Amount","status","description","create_timestamp","rolled_back_timestamp"),rows);
-
 
1730
							
-
 
1731
			ResponseEntity<?> responseEntity = orderService.downloadReportInCsv(baos, rows, "Scheme Payout Summary Report");
-
 
1732
 
-
 
1733
			
-
 
1734
			return responseEntity;
-
 
1735
	}
-
 
1736
	
-
 
1737
	
1279
	@GetMapping("/getAllOnlineOrder")
1738
	@GetMapping("/getAllOnlineOrder")
1280
	public String getAllOrders(HttpServletRequest request, @RequestParam(required = false) LocalDate date, Model model)
1739
	public String getAllOrders(HttpServletRequest request, @RequestParam(required = false) LocalDate date, Model model)
1281
			throws ProfitMandiBusinessException {
1740
			throws ProfitMandiBusinessException {
1282
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1741
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1283
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1742
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());