Subversion Repositories SmartDukaan

Rev

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

Rev 27859 Rev 27876
Line 63... Line 63...
63
import com.spice.profitmandi.common.web.util.ResponseSender;
63
import com.spice.profitmandi.common.web.util.ResponseSender;
64
import com.spice.profitmandi.dao.Interface.Campaign;
64
import com.spice.profitmandi.dao.Interface.Campaign;
65
import com.spice.profitmandi.dao.entity.auth.AuthUser;
65
import com.spice.profitmandi.dao.entity.auth.AuthUser;
66
import com.spice.profitmandi.dao.entity.auth.Menu;
66
import com.spice.profitmandi.dao.entity.auth.Menu;
67
import com.spice.profitmandi.dao.entity.catalog.Item;
67
import com.spice.profitmandi.dao.entity.catalog.Item;
68
import com.spice.profitmandi.dao.entity.catalog.Offer;
-
 
69
import com.spice.profitmandi.dao.entity.catalog.OfferPartner;
-
 
70
import com.spice.profitmandi.dao.entity.catalog.Offermargin;
-
 
71
import com.spice.profitmandi.dao.entity.catalog.TagListing;
68
import com.spice.profitmandi.dao.entity.catalog.TagListing;
72
import com.spice.profitmandi.dao.entity.cs.Position;
69
import com.spice.profitmandi.dao.entity.cs.Position;
73
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
70
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
74
import com.spice.profitmandi.dao.entity.dtr.Document;
71
import com.spice.profitmandi.dao.entity.dtr.Document;
75
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
72
import com.spice.profitmandi.dao.entity.dtr.NotificationCampaign;
76
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
73
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
77
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
74
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
78
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
75
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
79
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
76
import com.spice.profitmandi.dao.entity.fofo.PartnerTargetDetails;
80
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
77
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
81
import com.spice.profitmandi.dao.entity.fofo.PurchaseReturnItem;
-
 
82
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
78
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
83
import com.spice.profitmandi.dao.entity.transaction.Order;
79
import com.spice.profitmandi.dao.entity.transaction.Order;
84
import com.spice.profitmandi.dao.entity.user.Lead;
80
import com.spice.profitmandi.dao.entity.user.Lead;
85
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
-
 
86
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
81
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
87
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
82
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
88
import com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel;
83
import com.spice.profitmandi.dao.model.BrandWisePartnerSaleModel;
89
import com.spice.profitmandi.dao.model.BrandWiseUnbilledActivateStockModel;
84
import com.spice.profitmandi.dao.model.BrandWiseUnbilledActivateStockModel;
90
import com.spice.profitmandi.dao.model.CreateOfferRequest;
85
import com.spice.profitmandi.dao.model.CreateOfferRequest;
91
import com.spice.profitmandi.dao.model.InStockBrandItemModel;
86
import com.spice.profitmandi.dao.model.InStockBrandItemModel;
92
import com.spice.profitmandi.dao.model.InStockBrandModel;
87
import com.spice.profitmandi.dao.model.InStockBrandModel;
93
import com.spice.profitmandi.dao.model.ItemTypeParams;
-
 
94
import com.spice.profitmandi.dao.model.ItemWiseTertiaryModel;
88
import com.spice.profitmandi.dao.model.ItemWiseTertiaryModel;
95
import com.spice.profitmandi.dao.model.MonthSaleModel;
89
import com.spice.profitmandi.dao.model.MonthSaleModel;
96
import com.spice.profitmandi.dao.model.PartnerDetailModel;
90
import com.spice.profitmandi.dao.model.PartnerDetailModel;
97
import com.spice.profitmandi.dao.model.PartnerPendingIndentItemModel;
91
import com.spice.profitmandi.dao.model.PartnerPendingIndentItemModel;
98
import com.spice.profitmandi.dao.model.SimpleCampaign;
92
import com.spice.profitmandi.dao.model.SimpleCampaign;
Line 139... Line 133...
139
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
133
import com.spice.profitmandi.dao.repository.inventory.SaholicInventorySnapshotRepository;
140
import com.spice.profitmandi.service.PartnerInvestmentService;
134
import com.spice.profitmandi.service.PartnerInvestmentService;
141
import com.spice.profitmandi.service.PartnerStatsService;
135
import com.spice.profitmandi.service.PartnerStatsService;
142
import com.spice.profitmandi.service.authentication.RoleManager;
136
import com.spice.profitmandi.service.authentication.RoleManager;
143
import com.spice.profitmandi.service.inventory.InventoryService;
137
import com.spice.profitmandi.service.inventory.InventoryService;
-
 
138
import com.spice.profitmandi.service.offers.OfferService;
144
import com.spice.profitmandi.service.transaction.TransactionService;
139
import com.spice.profitmandi.service.transaction.TransactionService;
145
import com.spice.profitmandi.service.user.RetailerService;
140
import com.spice.profitmandi.service.user.RetailerService;
146
import com.spice.profitmandi.web.model.LoginDetails;
141
import com.spice.profitmandi.web.model.LoginDetails;
147
import com.spice.profitmandi.web.util.CookiesProcessor;
142
import com.spice.profitmandi.web.util.CookiesProcessor;
148
import com.spice.profitmandi.web.util.MVCResponseSender;
143
import com.spice.profitmandi.web.util.MVCResponseSender;
Line 271... Line 266...
271
 
266
 
272
	@Autowired
267
	@Autowired
273
	private OfferPartnerRepository offerPartnerRepository;
268
	private OfferPartnerRepository offerPartnerRepository;
274
 
269
 
275
	@Autowired
270
	@Autowired
-
 
271
	private OfferService offerService;
-
 
272
 
-
 
273
	@Autowired
276
	private OfferMarginRepository offerMarginRepository;
274
	private OfferMarginRepository offerMarginRepository;
277
 
275
 
278
	@Autowired
276
	@Autowired
279
	private ItemRepository itemRepository;
277
	private ItemRepository itemRepository;
280
 
278
 
Line 328... Line 326...
328
			model.addAttribute("fofoStore", customRetailer);
326
			model.addAttribute("fofoStore", customRetailer);
329
			model.addAttribute("partnerType", partnerType);
327
			model.addAttribute("partnerType", partnerType);
330
			model.addAttribute("hasGift", hasGift(fofoId));
328
			model.addAttribute("hasGift", hasGift(fofoId));
331
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
329
			model.addAttribute("giftItemId", ProfitMandiConstants.GIFT_ID);
332
 
330
 
333
			model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
331
			// model.addAttribute("brandStockPrices", this.getBrandStockPrices(fofoId));
334
			model.addAttribute("salesMap", this.getSales(fofoId));
332
			model.addAttribute("salesMap", this.getSales(fofoId));
335
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
333
			model.addAttribute("activatedImeis", inventoryItemRepository.selectCountByActivatedNotSold(fofoId));
336
			// this.setInvestments
334
			// this.setInvestments
337
			//
335
			//
338
			model.addAttribute("investments", this.getInvestments(fofoId));
336
			model.addAttribute("investments", this.getInvestments(fofoId));
Line 574... Line 572...
574
				ChartModel cm = this.getBrandChart(loginDetails.getFofoId());
572
				ChartModel cm = this.getBrandChart(loginDetails.getFofoId());
575
 
573
 
576
				LOGGER.info("chartMap" + gson.toJson(cm));
574
				LOGGER.info("chartMap" + gson.toJson(cm));
577
				model.addAttribute("chartMap", gson.toJson(cm));
575
				model.addAttribute("chartMap", gson.toJson(cm));
578
 
576
 
-
 
577
				List<CreateOfferRequest> publishedOffers = offerService.getPublishedOffers(loginDetails.getFofoId(),
-
 
578
						YearMonth.from(LocalDateTime.now()));
-
 
579
				model.addAttribute("publishedOffers", publishedOffers);
579
				model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
580
				model.addAttribute("investments", this.getInvestments(loginDetails.getFofoId()));
580
				model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
581
				model.addAttribute("isInvestmentOk", partnerInvestmentService.isInvestmentOk(loginDetails.getFofoId(),
581
						10, ProfitMandiConstants.CUTOFF_INVESTMENT));
582
						10, ProfitMandiConstants.CUTOFF_INVESTMENT));
582
 
583
 
583
				List<Offer> offers = offerRepository.selectOfferByStatus(true);
-
 
584
				if (!offers.isEmpty()) {
-
 
585
					List<CreateOfferRequest> cors = new ArrayList<>();
-
 
586
					for (Offer offer : offers) {
-
 
587
 
-
 
588
						List<OfferPartner> offerPartners = offerPartnerRepository.selectByOfferId(offer.getId());
-
 
589
 
-
 
590
						for (OfferPartner offerPartner : offerPartners) {
-
 
591
 
-
 
592
							if (offerPartner.getFofoId() == loginDetails.getFofoId()) {
-
 
593
								/*
-
 
594
								 * if (LocalDateTime.now().isAfter(offer.getStartDateTime()) &&
-
 
595
								 * LocalDateTime.now().isBefore(offer.getEndDateTime())) {
-
 
596
								 */
-
 
597
								int todayMonth = LocalDateTime.now().getMonthValue();
-
 
598
								if (todayMonth == offer.getStartDateTime().getMonthValue()
-
 
599
										|| todayMonth == offer.getEndDateTime().getMonthValue()) {
-
 
600
									LocalDateTime cur = LocalDate.now().minusMonths(2).atStartOfDay();
-
 
601
									LOGGER.info("value" + cur);
-
 
602
									Map<Integer, Double> value = offerRepository.selectSumOfferByRetailer(
-
 
603
											offer.getStartDateTime(), offer.getEndDateTime(), loginDetails.getFofoId(),
-
 
604
											offer, true);
-
 
605
									CreateOfferRequest createOfferRequest = new CreateOfferRequest();
-
 
606
									List<Offermargin> offerMargins = offerMarginRepository
-
 
607
											.selectByOfferId(offer.getId());
-
 
608
									LOGGER.info("value" + offer.getId());
-
 
609
									LOGGER.info("value" + value);
-
 
610
									for (Offermargin om : offerMargins) {
-
 
611
										if (value.get(loginDetails.getFofoId()) <= om.getValue()) {
-
 
612
											createOfferRequest.setMargin(om.getMargin());
-
 
613
											createOfferRequest.setValue(om.getValue());
-
 
614
											createOfferRequest.setShortAmount(
-
 
615
													om.getValue() - value.get(loginDetails.getFofoId()));
-
 
616
 
-
 
617
											break;
-
 
618
										} else {
-
 
619
											createOfferRequest.setMargin(om.getMargin());
-
 
620
 
-
 
621
										}
-
 
622
 
-
 
623
									}
-
 
624
									createOfferRequest.setId(offer.getId());
-
 
625
 
-
 
626
									createOfferRequest.setName(offer.getName());
-
 
627
									createOfferRequest.setDescription(offer.getDescription());
-
 
628
									createOfferRequest.setTargetType(offer.getTargetType());
-
 
629
									createOfferRequest.setAmountType(offer.getAmountType());
-
 
630
									createOfferRequest.setStartDateTime(offer.getStartDateTime().toLocalDate());
-
 
631
									createOfferRequest.setEndDateTime(offer.getEndDateTime().toLocalDate());
-
 
632
									createOfferRequest.setTotalSale(value.get(loginDetails.getFofoId()));
-
 
633
									createOfferRequest.setOfferMargin(offerMargins);
-
 
634
									cors.add(createOfferRequest);
-
 
635
 
-
 
636
									model.addAttribute("sales", value.get(loginDetails.getFofoId()));
-
 
637
								}
-
 
638
							}
-
 
639
 
-
 
640
						}
-
 
641
					}
-
 
642
					model.addAttribute("offers", cors);
-
 
643
 
-
 
644
				}
-
 
645
 
-
 
646
			} catch (ProfitMandiBusinessException e) {
584
			} catch (ProfitMandiBusinessException e) {
647
				LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
585
				LOGGER.error("FofoStore Code not found of fofoId {}", loginDetails.getFofoId());
648
 
586
 
649
			}
587
			}
650
		}
588
		}
Line 679... Line 617...
679
		} else {
617
		} else {
680
			return "dashboard1";
618
			return "dashboard1";
681
		}
619
		}
682
	}
620
	}
683
 
621
 
684
	@RequestMapping(value = "/getOfferMargins", method = RequestMethod.GET)
-
 
685
	public String getOfferMargins(HttpServletRequest request,
-
 
686
			@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
-
 
687
		Offer offer = offerRepository.selectById(offerId);
-
 
688
 
-
 
689
		LOGGER.info("offerId" + offer.getId());
-
 
690
 
-
 
691
		Map<Integer, Double> value = offerRepository.selectSumOfferByRetailer(offer.getStartDateTime(),
-
 
692
				offer.getEndDateTime(), 0, offer, true);
-
 
693
 
-
 
694
		LOGGER.info("value" + value);
-
 
695
		List<Offermargin> offerMargin = offerMarginRepository.selectByOfferId(offerId);
-
 
696
 
-
 
697
		ItemTypeParams scp = gson.fromJson(offer.getItemParam(), ItemTypeParams.class);
-
 
698
		if (offer.getItemCriteria().equals(ItemCriteriaType.Multiple_Brand)) {
-
 
699
			List<String> brands = scp.getBrands();
-
 
700
			model.addAttribute("brands", brands);
-
 
701
		}
-
 
702
		if (offer.getItemCriteria().equals(ItemCriteriaType.Item_Model)) {
-
 
703
			List<Integer> catalogIds = scp.getCatalogId();
-
 
704
			List<Item> newList = new ArrayList<>();
-
 
705
			Set<Integer> catalogId = new HashSet<>();
-
 
706
			List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds.stream().collect(Collectors.toSet()));
-
 
707
			for (Item item : items) {
-
 
708
				if (catalogId.add(item.getCatalogItemId())) {
-
 
709
					newList.add(item);
-
 
710
				}
-
 
711
			}
-
 
712
			model.addAttribute("items", newList);
-
 
713
		}
-
 
714
 
-
 
715
		model.addAttribute("offerMargin", offerMargin);
-
 
716
		model.addAttribute("offer", offer);
-
 
717
 
-
 
718
		return "offer_margin_detail_partner";
-
 
719
 
-
 
720
	}
-
 
721
 
-
 
722
	private ChartModel getBrandChart(int fofoId) {
622
	private ChartModel getBrandChart(int fofoId) {
723
 
623
 
724
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
624
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
725
 
625
 
726
		LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
626
		LOGGER.info("cur Date" + curDate.withDayOfMonth(1));
Line 746... Line 646...
746
		LOGGER.info("accesorieslmtdsale" + accesorieslmtdsale);
646
		LOGGER.info("accesorieslmtdsale" + accesorieslmtdsale);
747
		ChartModel cm = new ChartModel();
647
		ChartModel cm = new ChartModel();
748
 
648
 
749
		List<String> labels = new ArrayList<>();
649
		List<String> labels = new ArrayList<>();
750
		labels.addAll(brandwisesale.keySet());
650
		labels.addAll(brandwisesale.keySet());
-
 
651
		labels.addAll(lmtdBrandWiseSale.keySet());
751
		labels.add("Accessories");
652
		labels.add("Accessories");
752
		List<Double> values = new ArrayList<>();
653
		List<Double> values = new ArrayList<>();
753
		values.addAll(brandwisesale.values());
654
		values.addAll(brandwisesale.values());
754
		values.addAll(accesoriesmtdsale.values().size() > 0 ? accesoriesmtdsale.values() : Arrays.asList(0d));
655
		values.addAll(accesoriesmtdsale.values().size() > 0 ? accesoriesmtdsale.values() : Arrays.asList(0d));
755
 
656
 
Line 917... Line 818...
917
			{
818
			{
918
				menus = menuRepository.selectAll();
819
				menus = menuRepository.selectAll();
919
			} else if (positions.size() > 0) {
820
			} else if (positions.size() > 0) {
920
				if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
821
				if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
921
					menus = menuRepository.selectAll();
822
					menus = menuRepository.selectAll();
-
 
823
				} else if (positions.size() > 0) {
-
 
824
					if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
-
 
825
						menus = menuRepository.selectAll();
922
				} else {
826
					} else {
923
					List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
827
						List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
924
							.map(x -> x.getMenuId()).collect(Collectors.toList());
828
								.map(x -> x.getMenuId()).collect(Collectors.toList());
925
					if (menuIds.size() > 0) {
829
						if (menuIds.size() > 0) {
926
						menus = menuRepository.selectAllByIds(menuIds);
830
							menus = menuRepository.selectAllByIds(menuIds);
-
 
831
						}
-
 
832
					}
-
 
833
					List<Position> salesPositions = positions.stream()
-
 
834
							.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
-
 
835
							.collect(Collectors.toList());
-
 
836
					if (salesPositions.size() > 0) {
-
 
837
						Set<CustomRetailer> positionRetailers = new HashSet<>();
-
 
838
						csService.getPositionCustomRetailerMap(salesPositions).values().forEach(customRetailers -> {
-
 
839
							positionRetailers.addAll(customRetailers);
-
 
840
						});
-
 
841
						model.addAttribute("retailers", gson.toJson(positionRetailers));
-
 
842
						model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
-
 
843
						model.addAttribute("warehouses", getWarehouses(positionRetailers));
927
					}
844
					}
-
 
845
					List<Position> warehousePositions = positions.stream()
-
 
846
							.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
-
 
847
							.collect(Collectors.toList());
-
 
848
					if (warehousePositions.size() > 0) {
-
 
849
						Set<CustomRetailer> positionRetailers = new HashSet<>();
-
 
850
						csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
-
 
851
							positionRetailers.addAll(customRetailers);
-
 
852
						});
-
 
853
						model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
-
 
854
						model.addAttribute("retailers", gson.toJson(positionRetailers));
-
 
855
						model.addAttribute("warehouses", getWarehouses(positionRetailers));
-
 
856
					}
-
 
857
					model.addAttribute("authId", authUser.getId());
-
 
858
 
928
				}
859
				}
929
				List<Position> salesPositions = positions.stream()
860
				List<Position> salesPositions = positions.stream()
930
						.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
861
						.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_SALES)
931
						.collect(Collectors.toList());
862
						.collect(Collectors.toList());
932
				if (salesPositions.size() > 0) {
863
				if (salesPositions.size() > 0) {