Subversion Repositories SmartDukaan

Rev

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

Rev 30043 Rev 30053
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.LocalTime;
-
 
9
import java.time.Month;
-
 
10
import java.time.YearMonth;
-
 
11
import java.time.format.DateTimeFormatter;
-
 
12
import java.util.ArrayList;
-
 
13
import java.util.Arrays;
-
 
14
import java.util.HashMap;
-
 
15
import java.util.HashSet;
-
 
16
import java.util.LinkedHashSet;
-
 
17
import java.util.List;
-
 
18
import java.util.Map;
-
 
19
import java.util.Set;
-
 
20
import java.util.stream.Collectors;
-
 
21
 
-
 
22
import javax.servlet.http.HttpServletRequest;
-
 
23
import javax.servlet.http.HttpServletResponse;
-
 
24
import javax.transaction.Transactional;
-
 
25
 
-
 
26
import org.apache.commons.csv.CSVRecord;
-
 
27
import org.apache.logging.log4j.LogManager;
-
 
28
import org.apache.logging.log4j.Logger;
-
 
29
import org.springframework.beans.factory.annotation.Autowired;
-
 
30
import org.springframework.beans.factory.annotation.Qualifier;
-
 
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.ui.Model;
-
 
37
import org.springframework.web.bind.annotation.PathVariable;
-
 
38
import org.springframework.web.bind.annotation.RequestBody;
-
 
39
import org.springframework.web.bind.annotation.RequestMapping;
-
 
40
import org.springframework.web.bind.annotation.RequestMethod;
-
 
41
import org.springframework.web.bind.annotation.RequestParam;
-
 
42
import org.springframework.web.bind.annotation.RequestPart;
-
 
43
import org.springframework.web.multipart.MultipartFile;
-
 
44
 
3
import com.spice.profitmandi.common.enumuration.DateTimePattern;
45
import com.spice.profitmandi.common.enumuration.DateTimePattern;
4
import com.spice.profitmandi.common.enumuration.ReporticoProject;
46
import com.spice.profitmandi.common.enumuration.ReporticoProject;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
47
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
48
import com.spice.profitmandi.common.model.CustomRetailer;
6
import com.spice.profitmandi.common.model.*;
49
import com.spice.profitmandi.common.model.MapWrapper;
-
 
50
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
51
import com.spice.profitmandi.common.model.SchemeItems;
-
 
52
import com.spice.profitmandi.common.model.SchemeModel;
7
import com.spice.profitmandi.common.services.ReporticoService;
53
import com.spice.profitmandi.common.services.ReporticoService;
-
 
54
import com.spice.profitmandi.common.util.ExcelUtils;
-
 
55
import com.spice.profitmandi.common.util.FileUtil;
-
 
56
import com.spice.profitmandi.common.util.FormattingUtils;
-
 
57
import com.spice.profitmandi.common.util.StringUtils;
8
import com.spice.profitmandi.common.util.*;
58
import com.spice.profitmandi.common.util.Utils;
9
import com.spice.profitmandi.common.web.util.ResponseSender;
59
import com.spice.profitmandi.common.web.util.ResponseSender;
-
 
60
import com.spice.profitmandi.dao.entity.catalog.CustomerOffer;
-
 
61
import com.spice.profitmandi.dao.entity.catalog.CustomerOfferItem;
-
 
62
import com.spice.profitmandi.dao.entity.catalog.EvaluateSchemeInvestmentPayoutModel;
10
import com.spice.profitmandi.dao.entity.catalog.*;
63
import com.spice.profitmandi.dao.entity.catalog.Item;
-
 
64
import com.spice.profitmandi.dao.entity.catalog.SamsungUpgradeOffer;
-
 
65
import com.spice.profitmandi.dao.entity.catalog.Scheme;
-
 
66
import com.spice.profitmandi.dao.entity.catalog.TagListing;
11
import com.spice.profitmandi.dao.entity.fofo.*;
67
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
68
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
-
 
69
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
-
 
70
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
-
 
71
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
-
 
72
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
12
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
73
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
13
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
74
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
14
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
75
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
15
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
76
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
16
import com.spice.profitmandi.dao.enumuration.catalog.UpgradeOfferStatus;
77
import com.spice.profitmandi.dao.enumuration.catalog.UpgradeOfferStatus;
17
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
78
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
18
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
79
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
19
import com.spice.profitmandi.dao.model.CreateOfferRequest;
80
import com.spice.profitmandi.dao.model.CreateOfferRequest;
20
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
81
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
-
 
82
import com.spice.profitmandi.dao.model.ImeiWiseIncomePairAndMapModel;
-
 
83
import com.spice.profitmandi.dao.model.IncomeImeiDate;
-
 
84
import com.spice.profitmandi.dao.model.LastMonthBrandWiseIncomeModel;
-
 
85
import com.spice.profitmandi.dao.model.LastMonthCreditedIncomeModel;
-
 
86
import com.spice.profitmandi.dao.model.LastMonthFrontEndImeiModel;
-
 
87
import com.spice.profitmandi.dao.model.LastMonthImeiModel;
-
 
88
import com.spice.profitmandi.dao.repository.catalog.CustomerOfferItemRepository;
-
 
89
import com.spice.profitmandi.dao.repository.catalog.CustomerOfferRepository;
21
import com.spice.profitmandi.dao.repository.catalog.*;
90
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
-
 
91
import com.spice.profitmandi.dao.repository.catalog.SamsungUpgradeOfferRepository;
-
 
92
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
-
 
93
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
-
 
94
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
22
import com.spice.profitmandi.dao.repository.cs.CsService;
95
import com.spice.profitmandi.dao.repository.cs.CsService;
23
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
96
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
24
import com.spice.profitmandi.dao.repository.dtr.Mongo;
97
import com.spice.profitmandi.dao.repository.dtr.Mongo;
-
 
98
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
-
 
99
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
-
 
100
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
-
 
101
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
25
import com.spice.profitmandi.dao.repository.fofo.*;
102
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
26
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
103
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
27
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
104
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
28
import com.spice.profitmandi.service.authentication.RoleManager;
105
import com.spice.profitmandi.service.authentication.RoleManager;
29
import com.spice.profitmandi.service.inventory.InventoryService;
106
import com.spice.profitmandi.service.inventory.InventoryService;
30
import com.spice.profitmandi.service.offers.OfferService;
107
import com.spice.profitmandi.service.offers.OfferService;
Line 32... Line 109...
32
import com.spice.profitmandi.service.user.RetailerService;
109
import com.spice.profitmandi.service.user.RetailerService;
33
import com.spice.profitmandi.service.wallet.WalletService;
110
import com.spice.profitmandi.service.wallet.WalletService;
34
import com.spice.profitmandi.web.model.LoginDetails;
111
import com.spice.profitmandi.web.model.LoginDetails;
35
import com.spice.profitmandi.web.util.CookiesProcessor;
112
import com.spice.profitmandi.web.util.CookiesProcessor;
36
import com.spice.profitmandi.web.util.MVCResponseSender;
113
import com.spice.profitmandi.web.util.MVCResponseSender;
37
import in.shop2020.model.v1.order.WalletReferenceType;
-
 
38
import org.apache.commons.csv.CSVRecord;
-
 
39
import org.apache.logging.log4j.LogManager;
-
 
40
import org.apache.logging.log4j.Logger;
-
 
41
import org.springframework.beans.factory.annotation.Autowired;
-
 
42
import org.springframework.beans.factory.annotation.Qualifier;
-
 
43
import org.springframework.core.io.InputStreamResource;
-
 
44
import org.springframework.http.HttpHeaders;
-
 
45
import org.springframework.http.HttpStatus;
-
 
46
import org.springframework.http.ResponseEntity;
-
 
47
import org.springframework.stereotype.Controller;
-
 
48
import org.springframework.ui.Model;
-
 
49
import org.springframework.web.bind.annotation.*;
-
 
50
import org.springframework.web.multipart.MultipartFile;
-
 
51
 
114
 
52
import javax.servlet.http.HttpServletRequest;
-
 
53
import javax.servlet.http.HttpServletResponse;
115
import in.shop2020.model.v1.order.WalletReferenceType;
54
import javax.transaction.Transactional;
-
 
55
import java.io.ByteArrayInputStream;
-
 
56
import java.io.ByteArrayOutputStream;
-
 
57
import java.io.InputStream;
-
 
58
import java.time.*;
-
 
59
import java.util.*;
-
 
60
import java.util.stream.Collectors;
-
 
61
 
116
 
62
@Controller
117
@Controller
63
@Transactional(rollbackOn = Throwable.class)
118
@Transactional(rollbackOn = Throwable.class)
64
public class SchemeController {
119
public class SchemeController {
65
 
120
 
Line 464... Line 519...
464
		return "response";
519
		return "response";
465
	}
520
	}
466
 
521
 
467
	@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
522
	@RequestMapping(value = "/schemes/delete", method = RequestMethod.DELETE)
468
	public String deleteShcemes(HttpServletRequest request,
523
	public String deleteShcemes(HttpServletRequest request,
469
								@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
524
			@RequestParam(name = "schemeId", required = false, defaultValue = "0") int schemeId,
470
								@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
525
			@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
471
			throws Exception {
526
			throws Exception {
472
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
527
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
473
		if (!(schemeId == 0 && itemId == 0) || (!(schemeId == 0 || itemId == 0))) {
528
		if (!(schemeId == 0 && itemId == 0) || (!(schemeId == 0 || itemId == 0))) {
474
			schemeItemRepository.deletebyItemIdsandSchemeIds(itemId, schemeId);
529
			schemeItemRepository.deletebyItemIdsandSchemeIds(itemId, schemeId);
475
 
530
 
Line 501... Line 556...
501
	}
556
	}
502
 
557
 
503
	@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
558
	@RequestMapping(value = "/extendSchemeById", method = RequestMethod.POST)
504
	public String extendSchemeById(HttpServletRequest request,
559
	public String extendSchemeById(HttpServletRequest request,
505
 
560
 
506
								   @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
561
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
507
								   @RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
562
			@RequestBody LocalDateTime extendDatetime, Model model) throws Exception {
508
		extendDatetime = LocalDateTime.of(extendDatetime.toLocalDate(), Utils.MAX_TIME);
563
		extendDatetime = LocalDateTime.of(extendDatetime.toLocalDate(), Utils.MAX_TIME);
509
		Scheme scheme = schemeRepository.selectById(schemeId);
564
		Scheme scheme = schemeRepository.selectById(schemeId);
510
		if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
565
		if ((!(scheme.getActiveTimestamp() == null)) && scheme.getExpireTimestamp() == null) {
511
			scheme.setEndDateTime(extendDatetime);
566
			scheme.setEndDateTime(extendDatetime);
512
			schemeRepository.persist(scheme);
567
			schemeRepository.persist(scheme);
Line 517... Line 572...
517
		return "response";
572
		return "response";
518
	}
573
	}
519
 
574
 
520
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
575
	@RequestMapping(value = "/createScheme", method = RequestMethod.POST)
521
	public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
576
	public String createScheme(HttpServletRequest request, @RequestBody CreateSchemeRequest createSchemeRequest,
522
							   @RequestParam(name = "offset", defaultValue = "0") int offset,
577
			@RequestParam(name = "offset", defaultValue = "0") int offset,
523
							   @RequestParam(name = "limit", defaultValue = "10") int limit,
578
			@RequestParam(name = "limit", defaultValue = "10") int limit,
524
							   @RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
579
			@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
525
							   @RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
580
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
526
			throws ProfitMandiBusinessException {
581
			throws ProfitMandiBusinessException {
527
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
582
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
528
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
583
		LOGGER.info("CreateSchemeRequest {}", createSchemeRequest);
529
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
584
		schemeService.saveScheme(loginDetails.getFofoId(), createSchemeRequest);
530
		LOGGER.info("Scheme saved successfully");
585
		LOGGER.info("Scheme saved successfully");
Line 555... Line 610...
555
 
610
 
556
	}
611
	}
557
 
612
 
558
	@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
613
	@RequestMapping(value = "/getSchemes", method = RequestMethod.GET)
559
	public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
614
	public String getSchemes(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
560
							 @RequestParam(required = false) LocalDate date,
615
			@RequestParam(required = false) LocalDate date,
561
							 @RequestParam(name = "limit", defaultValue = "10") int limit,
616
			@RequestParam(name = "limit", defaultValue = "10") int limit,
562
							 @RequestParam(name = "searchItem", required = false, defaultValue = "0") int searchItem,
617
			@RequestParam(name = "searchItem", required = false, defaultValue = "0") int searchItem,
563
							 @RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
618
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
564
							 @RequestParam(name = "partnerType", required = false, defaultValue = "") PartnerType partnerType,
619
			@RequestParam(name = "partnerType", required = false, defaultValue = "") PartnerType partnerType,
565
							 @RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
620
			@RequestParam(name = "searchImei", required = false, defaultValue = "") String searchImei, Model model)
566
			throws ProfitMandiBusinessException {
621
			throws ProfitMandiBusinessException {
567
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
622
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
568
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
623
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
569
		if (date == null) {
624
		if (date == null) {
570
			date = LocalDate.now();
625
			date = LocalDate.now();
Line 751... Line 806...
751
			if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
806
			if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
752
				if (tagListing != null) {
807
				if (tagListing != null) {
753
					float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
808
					float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
754
					float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
809
					float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
755
					float amount = taxableSellingPrice * scheme.getAmount() / 100;
810
					float amount = taxableSellingPrice * scheme.getAmount() / 100;
756
					scheme.setAmountModel(
-
 
757
							FormattingUtils.formatDecimal(amount) + " (" + scheme.getAmount() + "%)");
811
					scheme.setAmountModel(FormattingUtils.formatDecimal(amount) + " (" + scheme.getAmount() + "%)");
758
					nlc -= amount;
812
					nlc -= amount;
759
				} else {
813
				} else {
760
					scheme.setAmountModel(scheme.getAmount() + "%");
814
					scheme.setAmountModel(scheme.getAmount() + "%");
761
				}
815
				}
762
			} else {
816
			} else {
Line 767... Line 821...
767
 
821
 
768
		return Math.round(nlc);
822
		return Math.round(nlc);
769
 
823
 
770
	}
824
	}
771
 
825
 
-
 
826
	@RequestMapping(value = "/getLastMonthCreditIncome", method = RequestMethod.GET)
-
 
827
	public String getLastMonthCreditIncome(HttpServletRequest request, Model model) throws Exception {
-
 
828
 
-
 
829
		String status = "CREDITED";
-
 
830
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
831
 
-
 
832
		LocalDateTime currentStartMonth = LocalDate.now().atStartOfDay().withDayOfMonth(1);
-
 
833
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
834
 
-
 
835
		YearMonth yearMonth = YearMonth.now();
-
 
836
		LOGGER.info("yearMonth" + yearMonth);
-
 
837
 
-
 
838
		boolean partnerType = partnerTypeChangeService.isPartnerTypeUpgraded(loginDetails.getFofoId(), yearMonth);
-
 
839
 
-
 
840
		LOGGER.info("partnerType" + partnerType);
-
 
841
 
-
 
842
		Map<String, Double> lastMonthCategoryUpgradeMarginMap = new HashMap<>();
-
 
843
 
-
 
844
		if (partnerType) {
-
 
845
			lastMonthCategoryUpgradeMarginMap = schemeInOutRepository
-
 
846
					.selectLastMonthCategoryUpgradeMarginByBrand(loginDetails.getFofoId(), currentStartMonth,
-
 
847
							currentDate)
-
 
848
					.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
-
 
849
		}
-
 
850
		List<LastMonthCreditedIncomeModel> lastMonthCreditedIncomeModels = schemeInOutRepository
-
 
851
				.selectLastMonthCreditedIncomeByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
-
 
852
 
-
 
853
		List<LastMonthCreditedIncomeModel> lastMonthPurchaseInMargins = schemeInOutRepository
-
 
854
				.selectLastMonthPurchaseInMarginByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
-
 
855
 
-
 
856
		List<LastMonthCreditedIncomeModel> lastMonthFrontEndIncomes = schemeInOutRepository
-
 
857
				.selectFrontIncomeByBrand(loginDetails.getFofoId(), currentStartMonth, currentDate);
-
 
858
 
-
 
859
		LOGGER.info("lastMonthCreditedIncomeModels" + lastMonthCreditedIncomeModels);
-
 
860
		LOGGER.info("lastMonthFrontEndIncomes" + lastMonthFrontEndIncomes);
-
 
861
		LOGGER.info("lastMonthPurchaseInMargins" + lastMonthPurchaseInMargins);
-
 
862
		LOGGER.info("lastMonthCategoryUpgradeMarginMap" + lastMonthCategoryUpgradeMarginMap);
-
 
863
 
-
 
864
		Map<String, LastMonthCreditedIncomeModel> lastMonthPurchaseInMarginMap = new HashMap<>();
-
 
865
 
-
 
866
		lastMonthPurchaseInMarginMap = lastMonthPurchaseInMargins.stream()
-
 
867
				.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
868
 
-
 
869
		Map<String, LastMonthCreditedIncomeModel> lastMonthSaleMarginMap = lastMonthCreditedIncomeModels.stream()
-
 
870
				.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
871
 
-
 
872
		lastMonthFrontEndIncomes.stream().forEach(x -> {
-
 
873
			if (lastMonthSaleMarginMap.containsKey(x.getBrand())) {
-
 
874
				x.setAmount(lastMonthSaleMarginMap.get(x.getBrand()).getAmount() + x.getAmount());
-
 
875
				lastMonthSaleMarginMap.put(x.getBrand(), x);
-
 
876
			} else {
-
 
877
				lastMonthSaleMarginMap.put(x.getBrand(), x);
-
 
878
			}
-
 
879
 
-
 
880
		});
-
 
881
		Map<String, Float> totalAmountMap = lastMonthSaleMarginMap.entrySet().stream()
-
 
882
				.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue().getAmount()));
-
 
883
 
-
 
884
		Set<String> keySet = new HashSet<String>();
-
 
885
		keySet.addAll(lastMonthPurchaseInMarginMap.keySet());
-
 
886
		keySet.addAll(lastMonthSaleMarginMap.keySet());
-
 
887
 
-
 
888
		lastMonthPurchaseInMarginMap.entrySet().stream().forEach(x -> {
-
 
889
			String brand = x.getKey();
-
 
890
			float amount = x.getValue().getAmount();
-
 
891
			if (!totalAmountMap.containsKey(brand)) {
-
 
892
				totalAmountMap.put(brand, 0f);
-
 
893
			}
-
 
894
			totalAmountMap.put(brand, totalAmountMap.get(brand) + amount);
-
 
895
 
-
 
896
		});
-
 
897
 
-
 
898
		Map<Integer, String> monthValueMap = new HashMap<>();
-
 
899
		for (int i = 0; i <= 5; i++) {
-
 
900
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
-
 
901
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
-
 
902
		}
-
 
903
		model.addAttribute("month", 0);
-
 
904
		model.addAttribute("monthValueMap", monthValueMap);
-
 
905
		model.addAttribute("keySet", keySet);
-
 
906
 
-
 
907
		model.addAttribute("lastMonthCategoryUpgradeMarginMap", lastMonthCategoryUpgradeMarginMap);
-
 
908
		model.addAttribute("lastMonthPurchaseInMarginMap", lastMonthPurchaseInMarginMap);
-
 
909
		model.addAttribute("lastMonthSaleMarginMap", lastMonthSaleMarginMap);
-
 
910
		model.addAttribute("status", status);
-
 
911
		model.addAttribute("totalAmountMap", totalAmountMap);
-
 
912
 
-
 
913
		return "last-month-credited-income";
-
 
914
	}
-
 
915
 
-
 
916
	@RequestMapping(value = "/getLastMonthPendingIncome", method = RequestMethod.GET)
-
 
917
	public String getLastMonthPendingIncome(HttpServletRequest request, Model model) throws Exception {
-
 
918
 
-
 
919
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
920
 
-
 
921
		LocalDateTime currentStartMonth = LocalDate.now().atStartOfDay().withDayOfMonth(1);
-
 
922
		LocalDateTime currentDate = LocalDate.now().atStartOfDay();
-
 
923
		String status = "PENDING";
-
 
924
 
-
 
925
		LOGGER.info("currentStartMonth" + currentStartMonth);
-
 
926
		LOGGER.info("currentDate" + currentDate);
-
 
927
 
-
 
928
		List<LastMonthCreditedIncomeModel> lastMonthPendingIncomeModels = schemeInOutRepository
-
 
929
				.selectLastMonthPendingIncomeByFofoId(loginDetails.getFofoId(), currentStartMonth, currentDate);
-
 
930
 
-
 
931
		Map<String, LastMonthCreditedIncomeModel> lastMonthMarginMap = new HashMap<>();
-
 
932
 
-
 
933
		for (LastMonthCreditedIncomeModel lastMonthPendingIncomeModel : lastMonthPendingIncomeModels) {
-
 
934
 
-
 
935
			lastMonthMarginMap.put(lastMonthPendingIncomeModel.getBrand(), lastMonthPendingIncomeModel);
-
 
936
		}
-
 
937
		LOGGER.info("lastMonthPendingIncomeModel" + lastMonthPendingIncomeModels);
-
 
938
		LOGGER.info("lastMonthMarginMap" + lastMonthMarginMap);
-
 
939
		model.addAttribute("lastMonthCreditedIncomeModels", lastMonthPendingIncomeModels);
-
 
940
		model.addAttribute("lastMonthMarginMap", lastMonthMarginMap);
-
 
941
		model.addAttribute("status", status);
-
 
942
 
-
 
943
		return "last-month-credited-income";
-
 
944
	}
-
 
945
 
-
 
946
	@RequestMapping(value = "/getLastMonthImeiWiseIncome", method = RequestMethod.GET)
-
 
947
	public String getLastMonthImeiWiseIncome(HttpServletRequest request,
-
 
948
			@RequestParam(name = "catalogItemId", required = false, defaultValue = "") int catalogItemId,
-
 
949
			@RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
-
 
950
			throws Exception {
-
 
951
 
-
 
952
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
953
 
-
 
954
		LocalDateTime lastMonthStart = LocalDate.now().minusMonths(month).withDayOfMonth(1).atStartOfDay();
-
 
955
		LocalDateTime currentMonthEnd = lastMonthStart.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
-
 
956
 
-
 
957
		HashSet<String> allImeiSet = new LinkedHashSet<>();
-
 
958
		HashSet<String> purchaseSet = new LinkedHashSet<>();
-
 
959
		HashSet<String> saleSet = new LinkedHashSet<>();
-
 
960
 
-
 
961
		List<LastMonthFrontEndImeiModel> lmfi = schemeInOutRepository
-
 
962
				.selectLastMonthFrontEndImei(loginDetails.getFofoId(), catalogItemId, lastMonthStart, currentMonthEnd);
-
 
963
		List<LastMonthImeiModel> lmpi = schemeInOutRepository.selectLastMonthPurchaseInImei(loginDetails.getFofoId(),
-
 
964
				catalogItemId, lastMonthStart, currentMonthEnd);
-
 
965
		List<LastMonthImeiModel> lmci = schemeInOutRepository.selectLastMonthCreditedImei(loginDetails.getFofoId(),
-
 
966
				catalogItemId, lastMonthStart, currentMonthEnd);
-
 
967
 
-
 
968
		Map<String, Double> lastmonthCategoryUpgradeMargin = schemeInOutRepository
-
 
969
				.selectLastMonthCategoryUpgradeMarginByImei(loginDetails.getFofoId(), catalogItemId, lastMonthStart,
-
 
970
						currentMonthEnd)
-
 
971
				.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
-
 
972
 
-
 
973
		allImeiSet.addAll(lmpi.stream().map(x -> x.getImei()).collect(Collectors.toList()));
-
 
974
		allImeiSet.addAll(lmci.stream().map(x -> x.getImei()).collect(Collectors.toList()));
-
 
975
		allImeiSet.addAll(lmfi.stream().map(x -> x.getImei()).collect(Collectors.toList()));
-
 
976
 
-
 
977
		List<String> allImeiList = new ArrayList<>(allImeiSet);
-
 
978
 
-
 
979
		LOGGER.info("allImeiList" + allImeiList);
-
 
980
		LOGGER.info("lmcm" + lastmonthCategoryUpgradeMargin);
-
 
981
		List<LastMonthFrontEndImeiModel> lastMonthFrontEndImeis = schemeInOutRepository
-
 
982
				.selectLastMonthFrontEndByImei(loginDetails.getFofoId(), allImeiList);
-
 
983
		List<LastMonthImeiModel> lastMonthPurchaseInImeis = schemeInOutRepository
-
 
984
				.selectLastMonthPurchaseInByImei(loginDetails.getFofoId(), allImeiList);
-
 
985
		List<LastMonthImeiModel> lastMonthCreditedImeis = schemeInOutRepository
-
 
986
				.selectLastMonthCreditedByImei(loginDetails.getFofoId(), allImeiList);
-
 
987
 
-
 
988
		LOGGER.info("lastMonthFrontEndImei {}", lastMonthFrontEndImeis);
-
 
989
		LOGGER.info("lastMonthPurchaseInImei {}", lastMonthPurchaseInImeis);
-
 
990
		LOGGER.info("lastMonthCreditedImei {}", lastMonthCreditedImeis);
-
 
991
 
-
 
992
		Map<IncomeImeiDate, Map<String, Double>> lastMonthPurchaseInMapPairMap = lastMonthPurchaseInImeis.stream()
-
 
993
				.collect(Collectors.groupingBy(x -> new IncomeImeiDate(x.getImei(), x.getCreateTimeStamp()),
-
 
994
						Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
-
 
995
 
-
 
996
		Map<IncomeImeiDate, Map<String, Double>> lastMonthCreditedMapPairMap = lastMonthCreditedImeis.stream()
-
 
997
				.collect(Collectors.groupingBy(x -> new IncomeImeiDate(x.getImei(), x.getCreateTimeStamp()),
-
 
998
						Collectors.groupingBy(x -> x.getDescription(), Collectors.summingDouble(x -> x.getAmount()))));
-
 
999
		// descriptionSet.add("")
-
 
1000
 
-
 
1001
		purchaseSet.addAll(lastMonthPurchaseInImeis.stream().map(x -> x.getDescription()).collect(Collectors.toList()));
-
 
1002
		saleSet.addAll(lastMonthCreditedImeis.stream().map(x -> x.getDescription()).collect(Collectors.toList()));
-
 
1003
 
-
 
1004
		List<String> purchaseList = new ArrayList<>(purchaseSet);
-
 
1005
		List<String> saleList = new ArrayList<>(saleSet);
-
 
1006
		Map<IncomeImeiDate, ImeiWiseIncomePairAndMapModel> imeiWiseIncomeMapOfMap = new HashMap<>();
-
 
1007
 
-
 
1008
		for (Map.Entry<IncomeImeiDate, Map<String, Double>> entry : lastMonthPurchaseInMapPairMap.entrySet()) {
-
 
1009
 
-
 
1010
			IncomeImeiDate imeiDate = entry.getKey();
-
 
1011
			Map<String, Double> descriptionAmountMap = entry.getValue();
-
 
1012
 
-
 
1013
			ImeiWiseIncomePairAndMapModel modelImeiMap = new ImeiWiseIncomePairAndMapModel(imeiDate.getImei(),
-
 
1014
					imeiDate.getLocalDateTime(), null, descriptionAmountMap);
-
 
1015
			imeiWiseIncomeMapOfMap.put(imeiDate, modelImeiMap);
-
 
1016
			double totalAmount = imeiWiseIncomeMapOfMap.get(imeiDate).getDescriptionAmountMap().entrySet().stream()
-
 
1017
					.collect(Collectors.summingDouble(x -> x.getValue()));
-
 
1018
			imeiWiseIncomeMapOfMap.get(imeiDate).setTotalIncome(totalAmount);
-
 
1019
		}
-
 
1020
 
-
 
1021
		for (Map.Entry<IncomeImeiDate, Map<String, Double>> entry : lastMonthCreditedMapPairMap.entrySet()) {
-
 
1022
			IncomeImeiDate imeiDate = entry.getKey();
-
 
1023
			Map<String, Double> descriptionAmountMap = entry.getValue();
-
 
1024
			if (!imeiWiseIncomeMapOfMap.containsKey(imeiDate)) {
-
 
1025
				ImeiWiseIncomePairAndMapModel modelImeiMap = new ImeiWiseIncomePairAndMapModel(imeiDate.getImei(), null,
-
 
1026
						imeiDate.getLocalDateTime(), descriptionAmountMap);
-
 
1027
				imeiWiseIncomeMapOfMap.put(imeiDate, modelImeiMap);
-
 
1028
 
-
 
1029
			} else {
-
 
1030
				ImeiWiseIncomePairAndMapModel modelImeiMap = imeiWiseIncomeMapOfMap.get(imeiDate);
-
 
1031
				modelImeiMap.setSaleDate(imeiDate.getLocalDateTime());
-
 
1032
				modelImeiMap.getDescriptionAmountMap().putAll(descriptionAmountMap);
-
 
1033
 
-
 
1034
			}
-
 
1035
			double totalAmount = descriptionAmountMap.entrySet().stream()
-
 
1036
					.collect(Collectors.summingDouble(x -> x.getValue()));
-
 
1037
			imeiWiseIncomeMapOfMap.get(imeiDate)
-
 
1038
					.setTotalIncome(totalAmount + imeiWiseIncomeMapOfMap.get(imeiDate).getTotalIncome());
-
 
1039
		}
-
 
1040
 
-
 
1041
		lastMonthFrontEndImeis.stream().forEach(x -> {
-
 
1042
			IncomeImeiDate incomeImeiDate = new IncomeImeiDate(x.getImei(), null);
-
 
1043
			if (imeiWiseIncomeMapOfMap.containsKey(incomeImeiDate)) {
-
 
1044
				ImeiWiseIncomePairAndMapModel imeiWiseIncomePairAndMapModel = imeiWiseIncomeMapOfMap
-
 
1045
						.get(incomeImeiDate);
-
 
1046
				double totalAmount = imeiWiseIncomePairAndMapModel.getTotalIncome() + x.getAmount();
-
 
1047
				imeiWiseIncomePairAndMapModel.setTotalIncome(totalAmount);
-
 
1048
				imeiWiseIncomePairAndMapModel.setFrontMargin(x.getAmount());
-
 
1049
			}
-
 
1050
		});
-
 
1051
 
-
 
1052
		model.addAttribute("month", month);
-
 
1053
		model.addAttribute("purchaseList", purchaseList);
-
 
1054
		model.addAttribute("saleList", saleList);
-
 
1055
		model.addAttribute("lastMonthPurchaseInMapPairMap", lastMonthPurchaseInMapPairMap);
-
 
1056
		model.addAttribute("lastMonthCreditedMapPairMap", lastMonthCreditedMapPairMap);
-
 
1057
		model.addAttribute("imeiWiseIncomeMapOfMap", imeiWiseIncomeMapOfMap);
-
 
1058
		model.addAttribute("lastmonthCategoryUpgradeMargin", lastmonthCategoryUpgradeMargin);
-
 
1059
 
-
 
1060
		LOGGER.info("lastMonthPurchaseInMapPairMap {}", lastMonthPurchaseInMapPairMap);
-
 
1061
		LOGGER.info("lastMonthCreditedMapPairMap {}", lastMonthCreditedMapPairMap);
-
 
1062
		LOGGER.info("imeiWiseIncomeMapOfMap {}", imeiWiseIncomeMapOfMap);
-
 
1063
 
-
 
1064
		return "last-month-imei-wise-income";
-
 
1065
	}
-
 
1066
 
-
 
1067
	@RequestMapping(value = "/brandWiseIncome", method = RequestMethod.GET)
-
 
1068
	public String getBrandWiseIncome(HttpServletRequest request,
-
 
1069
			@RequestParam(name = "brand", required = false, defaultValue = "") String brand,
-
 
1070
			@RequestParam(name = "status", required = false, defaultValue = "") String status,
-
 
1071
			@RequestParam(name = "month", required = false, defaultValue = "") int month, Model model)
-
 
1072
			throws ProfitMandiBusinessException {
-
 
1073
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1074
		LOGGER.info("loginDetails {}", loginDetails);
-
 
1075
		LOGGER.info("brand" + brand);
-
 
1076
		LOGGER.info("month {}", month);
-
 
1077
 
-
 
1078
		model.addAttribute("month", month);
-
 
1079
		LocalDateTime lastMonthStart = LocalDate.now().minusMonths(month).withDayOfMonth(1).atStartOfDay();
-
 
1080
		LocalDateTime currentMonthEnd = lastMonthStart.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
-
 
1081
 
-
 
1082
		List<LastMonthBrandWiseIncomeModel> lastMonthModelWiseIncomes = null;
-
 
1083
		List<LastMonthBrandWiseIncomeModel> modelWiseFrontIncomes = null;
-
 
1084
		List<LastMonthBrandWiseIncomeModel> purchaseInModelWiseIncomes = null;
-
 
1085
 
-
 
1086
		boolean partnerType = partnerTypeChangeService.isPartnerTypeUpgraded(loginDetails.getFofoId(), YearMonth.now());
-
 
1087
 
-
 
1088
		LOGGER.info("partnerType" + partnerType);
-
 
1089
 
-
 
1090
		Map<String, Double> categoryUpradeBrandModelMap = new HashMap<>();
-
 
1091
 
-
 
1092
		if (partnerType) {
-
 
1093
			categoryUpradeBrandModelMap = schemeInOutRepository
-
 
1094
					.selectLastMonthCategoryUpgradeMarginByBrandModel(loginDetails.getFofoId(), brand, lastMonthStart,
-
 
1095
							currentMonthEnd)
-
 
1096
					.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
-
 
1097
		}
-
 
1098
		LOGGER.info("partnerType {}", partnerType);
-
 
1099
		LOGGER.info("categoryUpradeBrandModelMap {}", categoryUpradeBrandModelMap);
-
 
1100
 
-
 
1101
		if (status.equals("PENDING")) {
-
 
1102
		}
-
 
1103
 
-
 
1104
		if (status.equals("CREDITED")) {
-
 
1105
			lastMonthModelWiseIncomes = schemeInOutRepository.selectLastMonthBrandWiseIncome(loginDetails.getFofoId(),
-
 
1106
					brand, lastMonthStart, currentMonthEnd);
-
 
1107
			modelWiseFrontIncomes = schemeInOutRepository.selectFrontIncomeBrandWise(loginDetails.getFofoId(), brand,
-
 
1108
					lastMonthStart, currentMonthEnd);
-
 
1109
			purchaseInModelWiseIncomes = schemeInOutRepository.selectLastMonthPurchaseBrandWiseIncome(
-
 
1110
					loginDetails.getFofoId(), brand, lastMonthStart, currentMonthEnd);
-
 
1111
			LOGGER.info("modelWiseFrontIncomes {}", modelWiseFrontIncomes);
-
 
1112
			LOGGER.info("lastMonthModelWiseIncomes {}", lastMonthModelWiseIncomes);
-
 
1113
			LOGGER.info("purchaseInModelWiseIncomes {}", purchaseInModelWiseIncomes);
-
 
1114
			Map<String, LastMonthBrandWiseIncomeModel> modelWiseMap = lastMonthModelWiseIncomes.stream()
-
 
1115
					.collect(Collectors.toMap(x -> x.getModelNumber(), x -> x));
-
 
1116
 
-
 
1117
			Map<String, LastMonthBrandWiseIncomeModel> purchaseWiseMap = purchaseInModelWiseIncomes.stream()
-
 
1118
					.collect(Collectors.toMap(x -> x.getModelNumber(), x -> x));
-
 
1119
 
-
 
1120
			Map<String, Double> modelWiseTotalAmount = new HashMap<>();
-
 
1121
			modelWiseFrontIncomes.stream().forEach(x -> {
-
 
1122
				if (modelWiseMap.containsKey(x.getModelNumber())) {
-
 
1123
 
-
 
1124
					x.setAmount(x.getAmount() + modelWiseMap.get(x.getModelNumber()).getAmount());
-
 
1125
 
-
 
1126
					modelWiseMap.put(x.getModelNumber(), x);
-
 
1127
				} else {
-
 
1128
					modelWiseMap.put(x.getModelNumber(), x);
-
 
1129
				}
-
 
1130
				if (modelWiseTotalAmount.containsKey(x.getModelNumber())) {
-
 
1131
 
-
 
1132
					double amount = x.getAmount() + modelWiseTotalAmount.get(x.getModelNumber());
-
 
1133
					modelWiseTotalAmount.put(x.getModelNumber(), amount);
-
 
1134
				} else {
-
 
1135
					modelWiseTotalAmount.put(x.getModelNumber(), x.getAmount());
-
 
1136
				}
-
 
1137
 
-
 
1138
			});
-
 
1139
			for (LastMonthBrandWiseIncomeModel pmi : purchaseInModelWiseIncomes) {
-
 
1140
 
-
 
1141
				if (!modelWiseMap.containsKey(pmi.getModelNumber())) {
-
 
1142
 
-
 
1143
					modelWiseMap.put(pmi.getModelNumber(), null);
-
 
1144
				}
-
 
1145
 
-
 
1146
				if (modelWiseTotalAmount.containsKey(pmi.getModelNumber())) {
-
 
1147
 
-
 
1148
					double amount = pmi.getAmount() + modelWiseTotalAmount.get(pmi.getModelNumber());
-
 
1149
					modelWiseTotalAmount.put(pmi.getModelNumber(), amount);
-
 
1150
				} else {
-
 
1151
					modelWiseTotalAmount.put(pmi.getModelNumber(), pmi.getAmount());
-
 
1152
				}
-
 
1153
 
-
 
1154
			}
-
 
1155
 
-
 
1156
			model.addAttribute("purchaseWiseMap", purchaseWiseMap);
-
 
1157
			model.addAttribute("categoryUpradeBrandModelMap", categoryUpradeBrandModelMap);
-
 
1158
			model.addAttribute("modelWiseMap", modelWiseMap);
-
 
1159
			model.addAttribute("modelWiseTotalAmount", modelWiseTotalAmount);
-
 
1160
 
-
 
1161
		}
-
 
1162
 
-
 
1163
		return "montly-brand-wise-income";
-
 
1164
 
-
 
1165
	}
-
 
1166
 
-
 
1167
	@RequestMapping(value = "/monthWisePartnerIncome/{yearMonth}", method = RequestMethod.GET)
-
 
1168
	public String publishedOffersOnMonthBefore(HttpServletRequest request, @PathVariable int yearMonth, Model model)
-
 
1169
			throws ProfitMandiBusinessException {
-
 
1170
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
1171
 
-
 
1172
		LocalDateTime lastMonthStart = LocalDate.now().minusMonths(yearMonth).withDayOfMonth(1).atStartOfDay();
-
 
1173
		LocalDateTime currentMonthEnd = lastMonthStart.plusMonths(1).withDayOfMonth(1).toLocalDate().atStartOfDay();
-
 
1174
 
-
 
1175
		YearMonth monthYear = YearMonth.now();
-
 
1176
 
-
 
1177
		boolean partnerType = partnerTypeChangeService.isPartnerTypeUpgraded(loginDetails.getFofoId(), monthYear);
-
 
1178
 
-
 
1179
		LOGGER.info("partnerType" + partnerType);
-
 
1180
 
-
 
1181
		Map<String, Double> lastMonthCategoryUpgradeMarginMap = new HashMap<>();
-
 
1182
 
-
 
1183
		if (partnerType) {
-
 
1184
			lastMonthCategoryUpgradeMarginMap = schemeInOutRepository
-
 
1185
					.selectLastMonthCategoryUpgradeMarginByBrand(loginDetails.getFofoId(), lastMonthStart,
-
 
1186
							currentMonthEnd)
-
 
1187
					.stream().collect(Collectors.toMap(x -> x.getBrand(), x -> x.getAmount()));
-
 
1188
		}
-
 
1189
 
-
 
1190
		String status = "CREDITED";
-
 
1191
		LOGGER.info("lastMonthStart" + lastMonthStart);
-
 
1192
		LOGGER.info("currentMonthEnd" + currentMonthEnd);
-
 
1193
 
-
 
1194
		List<LastMonthCreditedIncomeModel> lastMonthCreditedIncomeModels = schemeInOutRepository
-
 
1195
				.selectLastMonthCreditedIncomeByFofoId(loginDetails.getFofoId(), lastMonthStart, currentMonthEnd);
-
 
1196
 
-
 
1197
		List<LastMonthCreditedIncomeModel> lastMonthPurchaseInMargins = schemeInOutRepository
-
 
1198
				.selectLastMonthPurchaseInMarginByFofoId(loginDetails.getFofoId(), lastMonthStart, currentMonthEnd);
-
 
1199
 
-
 
1200
		List<LastMonthCreditedIncomeModel> lastMonthFrontEndIncomes = schemeInOutRepository
-
 
1201
				.selectFrontIncomeByBrand(loginDetails.getFofoId(), lastMonthStart, currentMonthEnd);
-
 
1202
 
-
 
1203
		LOGGER.info("lastMonthCreditedIncomeModels" + lastMonthCreditedIncomeModels);
-
 
1204
		LOGGER.info("lastMonthFrontEndIncomes" + lastMonthFrontEndIncomes);
-
 
1205
		LOGGER.info("lastMonthPurchaseInMargins" + lastMonthPurchaseInMargins);
-
 
1206
 
-
 
1207
		Map<String, LastMonthCreditedIncomeModel> lastMonthPurchaseInMarginMap = new HashMap<>();
-
 
1208
 
-
 
1209
		lastMonthPurchaseInMarginMap = lastMonthPurchaseInMargins.stream()
-
 
1210
				.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1211
 
-
 
1212
		Map<String, LastMonthCreditedIncomeModel> lastMonthSaleMarginMap = lastMonthCreditedIncomeModels.stream()
-
 
1213
				.collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1214
 
-
 
1215
		lastMonthFrontEndIncomes.stream().forEach(x -> {
-
 
1216
			if (lastMonthSaleMarginMap.containsKey(x.getBrand())) {
-
 
1217
				x.setAmount(lastMonthSaleMarginMap.get(x.getBrand()).getAmount() + x.getAmount());
-
 
1218
 
-
 
1219
				lastMonthSaleMarginMap.put(x.getBrand(), x);
-
 
1220
			} else {
-
 
1221
				lastMonthSaleMarginMap.put(x.getBrand(), x);
-
 
1222
			}
-
 
1223
 
-
 
1224
		});
-
 
1225
		Map<String, Float> totalAmountMap = lastMonthSaleMarginMap.entrySet().stream()
-
 
1226
				.collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue().getAmount()));
-
 
1227
		Set<String> keySet = new HashSet<String>();
-
 
1228
		keySet.addAll(lastMonthPurchaseInMarginMap.keySet());
-
 
1229
		keySet.addAll(lastMonthSaleMarginMap.keySet());
-
 
1230
 
-
 
1231
		lastMonthPurchaseInMarginMap.entrySet().stream().forEach(x -> {
-
 
1232
			String brand = x.getKey();
-
 
1233
			float amount = x.getValue().getAmount();
-
 
1234
			if (!totalAmountMap.containsKey(brand)) {
-
 
1235
				totalAmountMap.put(brand, 0f);
-
 
1236
			}
-
 
1237
			totalAmountMap.put(brand, totalAmountMap.get(brand) + amount);
-
 
1238
 
-
 
1239
		});
-
 
1240
 
-
 
1241
		Map<Integer, String> monthValueMap = new HashMap<>();
-
 
1242
		for (int i = 0; i <= 5; i++) {
-
 
1243
			LocalDateTime startOfMonth = LocalDateTime.now().withDayOfMonth(1).minusMonths(i);
-
 
1244
			monthValueMap.put(i, startOfMonth.format(DateTimeFormatter.ofPattern("MMM''uu")));
-
 
1245
		}
-
 
1246
		model.addAttribute("monthValueMap", monthValueMap);
-
 
1247
 
-
 
1248
		model.addAttribute("keySet", keySet);
-
 
1249
		model.addAttribute("lastMonthPurchaseInMarginMap", lastMonthPurchaseInMarginMap);
-
 
1250
		model.addAttribute("lastMonthSaleMarginMap", lastMonthSaleMarginMap);
-
 
1251
 
-
 
1252
		model.addAttribute("totalAmountMap", totalAmountMap);
-
 
1253
		model.addAttribute("status", status);
-
 
1254
		model.addAttribute("month", yearMonth);
-
 
1255
		model.addAttribute("lastMonthCategoryUpgradeMarginMap", lastMonthCategoryUpgradeMarginMap);
-
 
1256
		LOGGER.info("totalAmountMap {}", totalAmountMap);
-
 
1257
		LOGGER.info("lastMonthSaleMarginMap {}", lastMonthSaleMarginMap);
-
 
1258
 
-
 
1259
		return "last-month-credited-income";
-
 
1260
	}
-
 
1261
 
772
	@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
1262
	@RequestMapping(value = "/getPaginatedSchemes", method = RequestMethod.GET)
773
	public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(required = false) LocalDate date,
1263
	public String getPaginatedSchemes(HttpServletRequest request, @RequestParam(required = false) LocalDate date,
774
									  @RequestParam(name = "offset", defaultValue = "0") int offset,
1264
			@RequestParam(name = "offset", defaultValue = "0") int offset,
775
									  @RequestParam(name = "limit", defaultValue = "10") int limit,
1265
			@RequestParam(name = "limit", defaultValue = "10") int limit,
776
									  @RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
1266
			@RequestParam(name = "partnerType", required = false, defaultValue = "ALL") PartnerType partnerType,
777
									  Model model) throws ProfitMandiBusinessException {
1267
			Model model) throws ProfitMandiBusinessException {
778
 
1268
 
779
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1269
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
780
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
1270
		boolean isAdmin = roleManager.isAdmin(loginDetails.getRoleIds());
781
		if (date == null) {
1271
		if (date == null) {
782
			date = LocalDate.now();
1272
			date = LocalDate.now();
Line 790... Line 1280...
790
			if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
1280
			if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
791
				if (itemId > 0) {
1281
				if (itemId > 0) {
792
					float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
1282
					float taxRate = stateGstRateRepository.getIgstTaxRate(Arrays.asList(itemId)).get(itemId);
793
					float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
1283
					float taxableSellingPrice = tagListing.getSellingPrice() / (1 + taxRate / 100);
794
					float amount = taxableSellingPrice * scheme.getAmount() / 100;
1284
					float amount = taxableSellingPrice * scheme.getAmount() / 100;
795
					scheme.setAmountModel(
-
 
796
							FormattingUtils.formatDecimal(amount) + " (" + scheme.getAmount() + "%)");
1285
					scheme.setAmountModel(FormattingUtils.formatDecimal(amount) + " (" + scheme.getAmount() + "%)");
797
				} else {
1286
				} else {
798
					scheme.setAmountModel(scheme.getAmount() + "%");
1287
					scheme.setAmountModel(scheme.getAmount() + "%");
799
				}
1288
				}
800
			} else {
1289
			} else {
801
				scheme.setAmountModel("" + scheme.getAmount());
1290
				scheme.setAmountModel("" + scheme.getAmount());
Line 813... Line 1302...
813
		return "schemes-download";
1302
		return "schemes-download";
814
	}
1303
	}
815
 
1304
 
816
	@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
1305
	@RequestMapping(value = "/schemes/download", method = RequestMethod.GET)
817
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
1306
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request,
818
																  @RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString,
1307
			@RequestParam(name = ProfitMandiConstants.START_DATE_TIME) String startDateTimeString,
819
																  @RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model)
1308
			@RequestParam(name = ProfitMandiConstants.END_DATE_TIME) String endDateTimeString, Model model)
820
			throws ProfitMandiBusinessException {
1309
			throws ProfitMandiBusinessException {
821
		LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString,
1310
		LocalDateTime startDateTime = StringUtils.toDateTime(startDateTimeString,
822
				DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
1311
				DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
823
		LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
1312
		LocalDateTime endDateTime = StringUtils.toDateTime(endDateTimeString, DateTimePattern.DD_MM_yyyy_T_HH_MM_SS);
824
 
1313
 
Line 836... Line 1325...
836
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
1325
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
837
	}
1326
	}
838
 
1327
 
839
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
1328
	@RequestMapping(value = "/getSchemeById", method = RequestMethod.GET)
840
	public String getSchemeById(HttpServletRequest request,
1329
	public String getSchemeById(HttpServletRequest request,
841
								@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
1330
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId, Model model)
842
			throws ProfitMandiBusinessException {
1331
			throws ProfitMandiBusinessException {
843
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1332
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
844
 
1333
 
845
		boolean fullAccess = this.getAccess(loginDetails.getEmailId());
1334
		boolean fullAccess = this.getAccess(loginDetails.getEmailId());
846
		Scheme scheme = schemeService.getSchemeById(schemeId);
1335
		Scheme scheme = schemeService.getSchemeById(schemeId);
Line 851... Line 1340...
851
 
1340
 
852
	}
1341
	}
853
 
1342
 
854
	@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
1343
	@RequestMapping(value = "/activeSchemeById", method = RequestMethod.PUT)
855
	public String activeSchemeById(HttpServletRequest request,
1344
	public String activeSchemeById(HttpServletRequest request,
856
								   @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
1345
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
857
								   @RequestParam(name = "offset", defaultValue = "0") int offset,
1346
			@RequestParam(name = "offset", defaultValue = "0") int offset,
858
								   @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1347
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
859
			throws ProfitMandiBusinessException {
1348
			throws ProfitMandiBusinessException {
860
		schemeService.activeSchemeById(schemeId);
1349
		schemeService.activeSchemeById(schemeId);
861
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
1350
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
862
		model.addAttribute("schemes", schemes);
1351
		model.addAttribute("schemes", schemes);
863
		return "schemes-paginated";
1352
		return "schemes-paginated";
864
	}
1353
	}
865
 
1354
 
866
	@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
1355
	@RequestMapping(value = "/expireSchemeById", method = RequestMethod.PUT)
867
	public String expireSchemeById(HttpServletRequest request,
1356
	public String expireSchemeById(HttpServletRequest request,
868
								   @RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
1357
			@RequestParam(name = ProfitMandiConstants.SCHEME_ID) int schemeId,
869
								   @RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp,
1358
			@RequestParam(name = ProfitMandiConstants.EXPIRE_TIMESTAMP) LocalDateTime expiryTimestamp,
870
								   @RequestParam(name = "offset", defaultValue = "0") int offset,
1359
			@RequestParam(name = "offset", defaultValue = "0") int offset,
871
								   @RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1360
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
872
			throws ProfitMandiBusinessException {
1361
			throws ProfitMandiBusinessException {
873
		expiryTimestamp = LocalDateTime.of(expiryTimestamp.toLocalDate(), Utils.MAX_TIME);
1362
		expiryTimestamp = LocalDateTime.of(expiryTimestamp.toLocalDate(), Utils.MAX_TIME);
874
		schemeService.expireSchemeById(schemeId, expiryTimestamp);
1363
		schemeService.expireSchemeById(schemeId, expiryTimestamp);
875
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
1364
		List<Scheme> schemes = schemeRepository.selectAll(offset, limit);
876
		model.addAttribute("schemes", schemes);
1365
		model.addAttribute("schemes", schemes);
877
		return "schemes-paginated";
1366
		return "schemes-paginated";
878
	}
1367
	}
879
 
1368
 
880
	@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
1369
	@RequestMapping(value = "/getSchemesJson", method = RequestMethod.GET)
881
	public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
1370
	public ResponseEntity<?> getSchemesJson(HttpServletRequest request,
882
											@RequestParam(name = "offset", defaultValue = "0") int offset,
1371
			@RequestParam(name = "offset", defaultValue = "0") int offset,
883
											@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
1372
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
884
			throws ProfitMandiBusinessException {
1373
			throws ProfitMandiBusinessException {
885
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1374
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
886
		return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
1375
		return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
887
	}
1376
	}
888
 
1377
 
889
	@RequestMapping(value = "/searchSchemeByCategory")
1378
	@RequestMapping(value = "/searchSchemeByCategory")
890
	public String getSchemeByCategory(HttpServletRequest request,
1379
	public String getSchemeByCategory(HttpServletRequest request,
891
									  @RequestParam(name = "offset", defaultValue = "0") int offset,
1380
			@RequestParam(name = "offset", defaultValue = "0") int offset,
892
									  @RequestParam(name = "limit", defaultValue = "10") int limit,
1381
			@RequestParam(name = "limit", defaultValue = "10") int limit,
893
									  @RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
1382
			@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
894
									  @RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
1383
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
895
									  @RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
1384
			@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
896
			throws ProfitMandiBusinessException {
1385
			throws ProfitMandiBusinessException {
897
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1386
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
898
		List<Scheme> schemes = null;
1387
		List<Scheme> schemes = null;
899
		long size = 0;
1388
		long size = 0;
900
 
1389
 
Line 919... Line 1408...
919
		return "schemes";
1408
		return "schemes";
920
	}
1409
	}
921
 
1410
 
922
	@RequestMapping(value = "/getSchemeByCategoryPaginated")
1411
	@RequestMapping(value = "/getSchemeByCategoryPaginated")
923
	public String getSchemeByCategoryPaginated(HttpServletRequest request,
1412
	public String getSchemeByCategoryPaginated(HttpServletRequest request,
924
											   @RequestParam(name = "offset", defaultValue = "0") int offset,
1413
			@RequestParam(name = "offset", defaultValue = "0") int offset,
925
											   @RequestParam(name = "limit", defaultValue = "10") int limit,
1414
			@RequestParam(name = "limit", defaultValue = "10") int limit,
926
											   @RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
1415
			@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem,
927
											   @RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
1416
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
928
											   @RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
1417
			@RequestParam(name = "category", required = true, defaultValue = "") PartnerType category, Model model)
929
			throws ProfitMandiBusinessException {
1418
			throws ProfitMandiBusinessException {
930
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1419
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
931
		LOGGER.info("In search Item....");
1420
		LOGGER.info("In search Item....");
932
		List<Scheme> schemes = null;
1421
		List<Scheme> schemes = null;
933
 
1422
 
Line 939... Line 1428...
939
		return "schemes-paginated";
1428
		return "schemes-paginated";
940
	}
1429
	}
941
 
1430
 
942
	@RequestMapping(value = "/searchScheme")
1431
	@RequestMapping(value = "/searchScheme")
943
	public String getSchemeBySchemeId(HttpServletRequest request,
1432
	public String getSchemeBySchemeId(HttpServletRequest request,
944
									  @RequestParam(name = "offset", defaultValue = "0") int offset,
1433
			@RequestParam(name = "offset", defaultValue = "0") int offset,
945
									  @RequestParam(name = "limit", defaultValue = "10") int limit,
1434
			@RequestParam(name = "limit", defaultValue = "10") int limit,
946
									  @RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
1435
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
947
									  @RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
1436
			@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
948
			throws ProfitMandiBusinessException {
1437
			throws ProfitMandiBusinessException {
949
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1438
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
950
		List<Scheme> schemes = null;
1439
		List<Scheme> schemes = null;
951
		long size = 0;
1440
		long size = 0;
952
		if (!(searchTerm.equals("")) && searchItem.equals("")) {
1441
		if (!(searchTerm.equals("")) && searchItem.equals("")) {
Line 1013... Line 1502...
1013
		return "schemes";
1502
		return "schemes";
1014
	}
1503
	}
1015
 
1504
 
1016
	@RequestMapping(value = "/searchItemSchemePanigated")
1505
	@RequestMapping(value = "/searchItemSchemePanigated")
1017
	public String getSchemeByItemPanigated(HttpServletRequest request,
1506
	public String getSchemeByItemPanigated(HttpServletRequest request,
1018
										   @RequestParam(name = "offset", defaultValue = "0") int offset,
1507
			@RequestParam(name = "offset", defaultValue = "0") int offset,
1019
										   @RequestParam(name = "limit", defaultValue = "10") int limit,
1508
			@RequestParam(name = "limit", defaultValue = "10") int limit,
1020
										   @RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
1509
			@RequestParam(name = "searchItem", required = false, defaultValue = "") String searchItem, Model model)
1021
			throws ProfitMandiBusinessException {
1510
			throws ProfitMandiBusinessException {
1022
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1511
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
1023
		LOGGER.info("In search Item....");
1512
		LOGGER.info("In search Item....");
1024
		List<Scheme> schemes = null;
1513
		List<Scheme> schemes = null;
1025
		if (!searchItem.equals("")) {
1514
		if (!searchItem.equals("")) {
Line 1047... Line 1536...
1047
 
1536
 
1048
	}
1537
	}
1049
 
1538
 
1050
	@RequestMapping(value = "/createCustomerOffer", method = RequestMethod.POST)
1539
	@RequestMapping(value = "/createCustomerOffer", method = RequestMethod.POST)
1051
	public String createCustomerOffer(HttpServletRequest request, @RequestParam String offerName,
1540
	public String createCustomerOffer(HttpServletRequest request, @RequestParam String offerName,
1052
									  @RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
1541
			@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
1053
 
1542
 
1054
		CustomerOffer co = new CustomerOffer();
1543
		CustomerOffer co = new CustomerOffer();
1055
		co.setOfferName(offerName);
1544
		co.setOfferName(offerName);
1056
		co.setStartDate(startDate);
1545
		co.setStartDate(startDate);
1057
		co.setEndDate(endDate);
1546
		co.setEndDate(endDate);
Line 1083... Line 1572...
1083
 
1572
 
1084
	}
1573
	}
1085
 
1574
 
1086
	@RequestMapping(value = "/customerOfferItem/upload", method = RequestMethod.POST)
1575
	@RequestMapping(value = "/customerOfferItem/upload", method = RequestMethod.POST)
1087
	public String uploadCustomerOfferItem(HttpServletRequest request, Model model, @RequestParam int offerId,
1576
	public String uploadCustomerOfferItem(HttpServletRequest request, Model model, @RequestParam int offerId,
1088
										  HttpServletResponse response, @RequestPart MultipartFile file) throws Throwable {
1577
			HttpServletResponse response, @RequestPart MultipartFile file) throws Throwable {
1089
 
1578
 
1090
		List<CSVRecord> records = FileUtil.readFile(file);
1579
		List<CSVRecord> records = FileUtil.readFile(file);
1091
 
1580
 
1092
		for (CSVRecord record : records) {
1581
		for (CSVRecord record : records) {
1093
			if (Integer.parseInt(record.get(0)) == 0) {
1582
			if (Integer.parseInt(record.get(0)) == 0) {
Line 1141... Line 1630...
1141
 
1630
 
1142
	}
1631
	}
1143
 
1632
 
1144
	@RequestMapping(value = "/extendCustomerOffer", method = RequestMethod.POST)
1633
	@RequestMapping(value = "/extendCustomerOffer", method = RequestMethod.POST)
1145
	public String extendCustomerOffer(HttpServletRequest request, @RequestParam int id,
1634
	public String extendCustomerOffer(HttpServletRequest request, @RequestParam int id,
1146
									  @RequestParam LocalDateTime endDate, Model model) throws ProfitMandiBusinessException {
1635
			@RequestParam LocalDateTime endDate, Model model) throws ProfitMandiBusinessException {
1147
 
1636
 
1148
		CustomerOffer co = customerOfferRepository.selectById(id);
1637
		CustomerOffer co = customerOfferRepository.selectById(id);
1149
		co.setEndDate(endDate);
1638
		co.setEndDate(endDate);
1150
		co.setUpdatedTimestamp(LocalDateTime.now());
1639
		co.setUpdatedTimestamp(LocalDateTime.now());
1151
 
1640
 
Line 1188... Line 1677...
1188
 
1677
 
1189
		model.addAttribute("suo", suo);
1678
		model.addAttribute("suo", suo);
1190
		return "samsung-upgrade-offer-index";
1679
		return "samsung-upgrade-offer-index";
1191
 
1680
 
1192
	}
1681
	}
1193
 
-
 
1194
}
1682
}
1195
1683