Subversion Repositories SmartDukaan

Rev

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

Rev 26942 Rev 26945
Line 9... Line 9...
9
import java.time.format.DateTimeFormatter;
9
import java.time.format.DateTimeFormatter;
10
import java.time.temporal.ChronoUnit;
10
import java.time.temporal.ChronoUnit;
11
import java.util.ArrayList;
11
import java.util.ArrayList;
12
import java.util.Arrays;
12
import java.util.Arrays;
13
import java.util.Collections;
13
import java.util.Collections;
-
 
14
import java.util.Comparator;
14
import java.util.HashMap;
15
import java.util.HashMap;
15
import java.util.HashSet;
16
import java.util.HashSet;
16
import java.util.List;
17
import java.util.List;
17
import java.util.Map;
18
import java.util.Map;
18
import java.util.Optional;
19
import java.util.Optional;
Line 248... Line 249...
248
	PriceDropRepository priceDropRepository;
249
	PriceDropRepository priceDropRepository;
249
 
250
 
250
	@Autowired
251
	@Autowired
251
	private SchemeService schemeService;
252
	private SchemeService schemeService;
252
 
253
 
253
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com", 
254
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com",
254
			"adeel.yazdani@smartdukaan.com", "manoj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com",
255
			"adeel.yazdani@smartdukaan.com", "manoj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com",
255
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
256
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
256
			"hemant.kaura@smartdukaan.com","rajat.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "prakash.rai@smartdukaan.com" };
257
			"hemant.kaura@smartdukaan.com", "rajat.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com",
-
 
258
			"prakash.rai@smartdukaan.com" };
257
 
259
 
258
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
260
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
259
			"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com",
261
			"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com",
260
			"kuldeep.kumar@smartdukaan.com" };
262
			"kuldeep.kumar@smartdukaan.com" };
261
 
263
 
262
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
264
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
263
 
265
 
264
	private Object[] REPORT_HEADERS = { "Store Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager" };
-
 
265
 
-
 
266
	@Autowired
266
	@Autowired
267
	private ReporticoService reporticoService;
267
	private ReporticoService reporticoService;
268
 
268
 
269
	@Autowired
269
	@Autowired
270
	private PartnerInvestmentService partnerInvestmentService;
270
	private PartnerInvestmentService partnerInvestmentService;
Line 332... Line 332...
332
	@Autowired
332
	@Autowired
333
	private TargetSlabService targetService;
333
	private TargetSlabService targetService;
334
 
334
 
335
	@Value("${prod}")
335
	@Value("${prod}")
336
	private boolean prod;
336
	private boolean prod;
337
	
337
 
338
	@Autowired
338
	@Autowired
339
	private StateGstRateRepository stateGstRateRepository;
339
	private StateGstRateRepository stateGstRateRepository;
340
 
340
 
341
	@Autowired
341
	@Autowired
342
	private RetailerService retailerService;
342
	private RetailerService retailerService;
Line 707... Line 707...
707
			return l2;
707
			return l2;
708
		}
708
		}
709
 
709
 
710
	}
710
	}
711
 
711
 
-
 
712
	private class FofoReportingModel {
-
 
713
		private String code;
-
 
714
		private int fofoId;
-
 
715
		private String businessName;
-
 
716
		private String territoryManager;
-
 
717
		private String regionalManager;
-
 
718
 
-
 
719
		@Override
-
 
720
		public String toString() {
-
 
721
			return "FofoReportingModel [code=" + code + ", fofoId=" + fofoId + ", businessName=" + businessName
-
 
722
					+ ", territoryManager=" + territoryManager + ", regionalManager=" + regionalManager + "]";
-
 
723
		}
-
 
724
 
-
 
725
		public String getCode() {
-
 
726
			return code;
-
 
727
		}
-
 
728
 
-
 
729
		public void setCode(String code) {
-
 
730
			this.code = code;
-
 
731
		}
-
 
732
 
-
 
733
		public String getBusinessName() {
-
 
734
			return businessName;
-
 
735
		}
-
 
736
 
-
 
737
		public void setBusinessName(String businessName) {
-
 
738
			this.businessName = businessName;
-
 
739
		}
-
 
740
 
-
 
741
		public String getTerritoryManager() {
-
 
742
			return territoryManager;
-
 
743
		}
-
 
744
 
-
 
745
		public void setTerritoryManager(String territoryManager) {
-
 
746
			this.territoryManager = territoryManager;
-
 
747
		}
-
 
748
 
-
 
749
		public String getRegionalManager() {
-
 
750
			return regionalManager;
-
 
751
		}
-
 
752
 
-
 
753
		public void setRegionalManager(String regionalManager) {
-
 
754
			this.regionalManager = regionalManager;
-
 
755
		}
-
 
756
 
-
 
757
 
-
 
758
		private ScheduledTasks getOuterType() {
-
 
759
			return ScheduledTasks.this;
-
 
760
		}
-
 
761
 
-
 
762
		@Override
-
 
763
		public int hashCode() {
-
 
764
			final int prime = 31;
-
 
765
			int result = 1;
-
 
766
			result = prime * result + getOuterType().hashCode();
-
 
767
			result = prime * result + ((businessName == null) ? 0 : businessName.hashCode());
-
 
768
			result = prime * result + ((code == null) ? 0 : code.hashCode());
-
 
769
			result = prime * result + fofoId;
-
 
770
			result = prime * result + ((regionalManager == null) ? 0 : regionalManager.hashCode());
-
 
771
			result = prime * result + ((territoryManager == null) ? 0 : territoryManager.hashCode());
-
 
772
			return result;
-
 
773
		}
-
 
774
 
-
 
775
		@Override
-
 
776
		public boolean equals(Object obj) {
-
 
777
			if (this == obj)
-
 
778
				return true;
-
 
779
			if (obj == null)
-
 
780
				return false;
-
 
781
			if (getClass() != obj.getClass())
-
 
782
				return false;
-
 
783
			FofoReportingModel other = (FofoReportingModel) obj;
-
 
784
			if (!getOuterType().equals(other.getOuterType()))
-
 
785
				return false;
-
 
786
			if (businessName == null) {
-
 
787
				if (other.businessName != null)
-
 
788
					return false;
-
 
789
			} else if (!businessName.equals(other.businessName))
-
 
790
				return false;
-
 
791
			if (code == null) {
-
 
792
				if (other.code != null)
-
 
793
					return false;
-
 
794
			} else if (!code.equals(other.code))
-
 
795
				return false;
-
 
796
			if (fofoId != other.fofoId)
-
 
797
				return false;
-
 
798
			if (regionalManager == null) {
-
 
799
				if (other.regionalManager != null)
-
 
800
					return false;
-
 
801
			} else if (!regionalManager.equals(other.regionalManager))
-
 
802
				return false;
-
 
803
			if (territoryManager == null) {
-
 
804
				if (other.territoryManager != null)
-
 
805
					return false;
-
 
806
			} else if (!territoryManager.equals(other.territoryManager))
-
 
807
				return false;
-
 
808
			return true;
-
 
809
		}
-
 
810
 
-
 
811
		public int getFofoId() {
-
 
812
			return fofoId;
-
 
813
		}
-
 
814
 
-
 
815
		public void setFofoId(int fofoId) {
-
 
816
			this.fofoId = fofoId;
-
 
817
		}
-
 
818
 
-
 
819
	}
-
 
820
 
712
	public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
821
	public void sendPartnerInvestmentDetails(List<String> sendTo) throws Exception {
713
		LocalDate yesterDay = LocalDate.now().minusDays(1);
822
		LocalDate yesterDay = LocalDate.now().minusDays(1);
714
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
823
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
715
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
824
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
716
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
825
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
717
 
826
 
718
		List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory/Team Lead",
827
		List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory/Team Lead",
719
				"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount", "Grn Pending Amount",
828
				"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount",
720
				"Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty", "Short Days");
829
				"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty",
-
 
830
				"Short Days");
721
		List<List<?>> rows = new ArrayList<>();
831
		List<List<?>> rows = new ArrayList<>();
722
		Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
832
		Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
723
 
833
 
724
		Map<Integer, List<Serializable>> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
834
		Map<Integer, FofoReportingModel> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
725
		
835
 
726
		Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now())
836
		Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository
727
		.stream().collect(Collectors.groupingBy(x->x.getFofoId(), 
837
				.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now()).stream().collect(Collectors.groupingBy(
728
				Collectors.summingInt(x-> x.getShortPercentage() > 10 ? 1 : 0)));
838
						x -> x.getFofoId(), Collectors.summingInt(x -> x.getShortPercentage() > 10 ? 1 : 0)));
729
 
839
 
730
		for (FofoStore fofoStore : fofoStores) {
840
		for (FofoStore fofoStore : fofoStores) {
731
			int fofoId = fofoStore.getId();
841
			int fofoId = fofoStore.getId();
732
			PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId,1);
842
			PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 1);
733
			partnerDailyInvestment.setDate(yesterDay);
843
			partnerDailyInvestment.setDate(yesterDay);
734
			
844
 
735
			try {
845
			try {
736
				partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
846
				partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
-
 
847
				shortDaysMap.put(fofoId,
737
				shortDaysMap.put(fofoId, shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
848
						shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
738
			} catch (Exception e) {
849
			} catch (Exception e) {
739
				// ignore the exceptions during persist
850
				// ignore the exceptions during persist
740
			}
851
			}
741
 
852
 
742
			CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
853
			CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
743
			if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
854
			if (retailer == null || partnerIdSalesHeaderMap.get(fofoStore.getId()) == null) {
744
				LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
855
				LOGGER.info("Could not find retailer with retailer Id {}", fofoStore.getId());
745
				continue;
856
				continue;
746
			}
857
			}
747
			List<Serializable> row = partnerIdSalesHeaderMap.get(fofoStore.getId());
858
			FofoReportingModel reportingModel = partnerIdSalesHeaderMap.get(fofoStore.getId());
-
 
859
			List<Serializable> row = new ArrayList<>();
-
 
860
			row.addAll(Arrays.asList(reportingModel.getCode(), reportingModel.getBusinessName(),
-
 
861
					reportingModel.getRegionalManager(), reportingModel.getTerritoryManager()));
748
			row.addAll(
862
			row.addAll(
749
					Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
863
					Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
750
							partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-":"("+partnerDailyInvestment.getActivatedStockAmount()+")",
864
							partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-"
-
 
865
									: "(" + partnerDailyInvestment.getActivatedStockAmount() + ")",
751
							0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
866
							0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
752
							partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
867
							partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
753
							partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),shortDaysMap.get(fofoId)));
868
							partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),
-
 
869
							shortDaysMap.get(fofoId)));
754
			partnerRowsMap.put(fofoStore.getId(), row);
870
			partnerRowsMap.put(fofoStore.getId(), row);
755
			rows.add(row);
871
			rows.add(row);
756
 
872
 
757
		}
873
		}
758
 
874
 
Line 776... Line 892...
776
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
892
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Franchise Investment Summary", "PFA",
777
				fileName, new ByteArrayResource(baos.toByteArray()));
893
				fileName, new ByteArrayResource(baos.toByteArray()));
778
 
894
 
779
	}
895
	}
780
 
896
 
781
	private Map<Integer, List<Serializable>> getPartnerIdSalesHeaders() {
897
	private Map<Integer, FofoReportingModel> getPartnerIdSalesHeaders() {
782
		Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
898
		Map<String, SaleRoles> partnerEmailSalesMap = new HashMap<>();
783
 
899
 
784
		List<Position> positions = positionRepository
900
		List<Position> positions = positionRepository
785
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
901
				.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
786
		Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
902
		Map<Integer, AuthUser> authUsersMap = authRepository.selectAllActiveUser().stream()
Line 794... Line 910...
794
				if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
910
				if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
795
					partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
911
					partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
796
				}
912
				}
797
				SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
913
				SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
798
				AuthUser authUser = authUsersMap.get(position.getAuthUserId());
914
				AuthUser authUser = authUsersMap.get(position.getAuthUserId());
799
				if(authUser==null) {
915
				if (authUser == null) {
800
					continue;
916
					continue;
801
				}
917
				}
802
				String name = authUser.getFirstName() + " " + authUser.getLastName();
918
				String name = authUser.getFirstName() + " " + authUser.getLastName();
803
				if (position.getEscalationType().equals(EscalationType.L1)) {
919
				if (position.getEscalationType().equals(EscalationType.L1)) {
804
					saleRoles.getL1().add(name);
920
					saleRoles.getL1().add(name);
Line 814... Line 930...
814
		}
930
		}
815
 
931
 
816
		Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
932
		Map<Integer, FofoStore> fofoStoresMap = fofoStoreRepository.selectActiveStores().stream()
817
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
933
				.collect(Collectors.toMap(x -> x.getId(), x -> x));
818
 
934
 
819
		Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = new HashMap<>();
935
		Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = new HashMap<>();
820
 
936
 
821
		for (CustomRetailer cr : allCrList) {
937
		for (CustomRetailer cr : allCrList) {
822
			FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
938
			FofoStore fofoStore = fofoStoresMap.get(cr.getPartnerId());
823
			if (fofoStore == null) {
939
			if (fofoStore == null) {
824
				LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
940
				LOGGER.info("Could not find Store {} in active Store", cr.getBusinessName());
825
				continue;
941
				continue;
826
			}
942
			}
827
			String code = fofoStore.getCode() + "";
943
			String code = fofoStore.getCode();
-
 
944
			// String storeName = "SmartDukaan-" +
828
			String storeName = "SmartDukaan-" + fofoStore.getCode().replaceAll("[a-zA-Z]", "");
945
			// fofoStore.getCode().replaceAll("[a-zA-Z]", "");
829
			String businessName = cr.getBusinessName();
946
			String businessName = cr.getBusinessName();
830
			try {
947
			try {
831
				String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
948
				String stateManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL2(), ", ");
832
				String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
949
				String territoryManager = StringUtils.join(partnerEmailSalesMap.get(cr.getEmail()).getL1(), ", ");
833
				List<Serializable> row = new ArrayList<>(
950
				FofoReportingModel reportingModel = new FofoReportingModel();
-
 
951
				reportingModel.setBusinessName(businessName);
-
 
952
				reportingModel.setCode(code);
-
 
953
				reportingModel.setFofoId(fofoStore.getId());
-
 
954
				reportingModel.setRegionalManager(stateManager);
834
						Arrays.asList(code, businessName, storeName, stateManager, territoryManager));
955
				reportingModel.setTerritoryManager(territoryManager);
835
				partnerIdSalesHeadersMap.put(cr.getPartnerId(), row);
956
				partnerIdSalesHeadersMap.put(fofoStore.getId(), reportingModel);
836
 
-
 
837
			} catch (Exception e) {
957
			} catch (Exception e) {
838
				LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
958
				LOGGER.warn("Could not find partner with email - {}", cr.getEmail());
839
			}
959
			}
840
		}
960
		}
841
		return partnerIdSalesHeadersMap;
961
		return partnerIdSalesHeadersMap;
Line 852... Line 972...
852
			sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
972
			sendTo = Arrays.asList("tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com",
853
					"amit.gupta@shop2020.in", "amod.sen@smartdukaan.com", "prakash.rai@smartdukaan.com");
973
					"amit.gupta@shop2020.in", "amod.sen@smartdukaan.com", "prakash.rai@smartdukaan.com");
854
		}
974
		}
855
		Map<Integer, List<Serializable>> partnerSalesTargetRowsMap = targetService.getDailySaleReportVsTarget();
975
		Map<Integer, List<Serializable>> partnerSalesTargetRowsMap = targetService.getDailySaleReportVsTarget();
856
 
976
 
857
		Map<Integer, List<Serializable>> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
977
		Map<Integer, FofoReportingModel> partnerIdSalesHeadersMap = this.getPartnerIdSalesHeaders();
858
 
978
 
859
		List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager",
979
		List<String> headers = Arrays.asList("Code", "Firm Name", "State Manager", "Teritory Manager",
860
				"Current Category", "Target Value", "Target Achieved", "Achived Percentage", "Remaining Target",
980
				"Current Category", "Target Value", "Target Achieved", "Achived Percentage", "Remaining Target",
861
				"Today's Target", "Today's achievement");
981
				"Today's Target", "Today's achievement");
862
 
982
 
863
		List<List<?>> rows = new ArrayList<>();
983
		List<List<?>> rows = new ArrayList<>();
864
		Map<Integer, List<? extends Serializable>> partnerRowMap = new HashMap<>();
984
		Map<Integer, List<? extends Serializable>> partnerRowMap = new HashMap<>();
865
		for (Map.Entry<Integer, List<Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap.entrySet()) {
985
		for (Map.Entry<Integer, List<Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap.entrySet()) {
866
			List<Serializable> row = partnerIdSalesHeadersMap.get(partnerSalesTargetRowEntry.getKey());
986
			FofoReportingModel fofoReportingModel = partnerIdSalesHeadersMap.get(partnerSalesTargetRowEntry.getKey());
867
			if (row == null) {
987
			if (fofoReportingModel == null) {
868
				LOGGER.warn("Could not find headers for partner ID - {}", partnerSalesTargetRowEntry.getKey());
988
				LOGGER.warn("Could not find headers for partner ID - {}", partnerSalesTargetRowEntry.getKey());
-
 
989
				continue;
869
			}
990
			}
-
 
991
			List<Serializable> row = Arrays.asList(fofoReportingModel.getCode(), fofoReportingModel.getBusinessName(),
-
 
992
					fofoReportingModel.getRegionalManager(), fofoReportingModel.getTerritoryManager());
870
			row.addAll(partnerSalesTargetRowEntry.getValue());
993
			row.addAll(partnerSalesTargetRowEntry.getValue());
871
			partnerRowMap.put(partnerSalesTargetRowEntry.getKey(), row);
994
			partnerRowMap.put(partnerSalesTargetRowEntry.getKey(), row);
872
			rows.add(row);
995
			rows.add(row);
873
		}
996
		}
874
 
997
 
Line 1356... Line 1479...
1356
 
1479
 
1357
		throw new Exception();
1480
		throw new Exception();
1358
 
1481
 
1359
	}
1482
	}
1360
 
1483
 
1361
	public void sendDailySalesNotificationToPartner(Integer fofoIdInt)
1484
	public void sendDailySalesNotificationToPartner(Integer fofoIdInt) throws Exception {
1362
			throws ProfitMandiBusinessException, MessagingException, IOException {
-
 
1363
 
1485
 
1364
		LocalDateTime now = LocalDateTime.now();
1486
		LocalDateTime now = LocalDateTime.now();
1365
		LocalDateTime from = now.with(LocalTime.MIN);
1487
		LocalDateTime from = now.with(LocalTime.MIN);
1366
		String timeString = "Today %s";
1488
		String timeString = "Today %s";
1367
		// Send yesterday's report
1489
		// Send yesterday's report
Line 1381... Line 1503...
1381
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
1503
		DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("h:m a");
1382
 
1504
 
1383
		Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
1505
		Map<Integer, Float> partnerPolicyAmountMap = insurancePolicyRepository.selectAmountSumGroupByRetailerId(now,
1384
				null);
1506
				null);
1385
		Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
1507
		Map<Integer, Long> partnerPolicyQtyMap = insurancePolicyRepository.selectQtyGroupByRetailerId(now, null);
1386
		
1508
 
1387
		Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
1509
		Map<Integer, Double> spPartnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
1388
				0, true);
1510
				true);
-
 
1511
 
-
 
1512
		Map<Integer, Double> spPartner3DaysOrderValMap = fofoOrderItemRepository
-
 
1513
				.selectSumAmountGroupByRetailer(from.minusDays(3), now, 0, true);
1389
		Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
1514
		Map<Integer, Long> spPartnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, true);
1390
 
1515
 
1391
		Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now,
1516
		Map<Integer, Double> partnerOrderValMap = fofoOrderItemRepository.selectSumAmountGroupByRetailer(from, now, 0,
1392
				0, false);
1517
				false);
1393
		Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
1518
		Map<Integer, Long> partnerOrderQtyMap = fofoOrderItemRepository.selectQtyGroupByRetailer(from, now, 0, false);
1394
		
1519
 
1395
		Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
1520
		Map<Integer, SaleTargetReportModel> saleTargetReportModelMap = new HashMap<>();
1396
		for (int fofoId : fofoIds) {
1521
		for (int fofoId : fofoIds) {
1397
			SaleTargetReportModel model = new SaleTargetReportModel();
1522
			SaleTargetReportModel model = new SaleTargetReportModel();
1398
			model.setInsuranceSale(
1523
			model.setInsuranceSale(
1399
					partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
1524
					partnerPolicyAmountMap.containsKey(fofoId) ? partnerPolicyAmountMap.get(fofoId).doubleValue() : 0);
1400
			model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
1525
			model.setInsruanceQty(partnerPolicyQtyMap.containsKey(fofoId) ? partnerPolicyQtyMap.get(fofoId) : 0);
1401
			model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
1526
			model.setSmartphoneSale(spPartnerOrderValMap.containsKey(fofoId) ? spPartnerOrderValMap.get(fofoId) : 0);
1402
			model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
1527
			model.setSmartphoneQty(spPartnerOrderQtyMap.containsKey(fofoId) ? spPartnerOrderQtyMap.get(fofoId) : 0);
1403
			model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
1528
			model.setTotalSale(partnerOrderValMap.containsKey(fofoId) ? partnerOrderValMap.get(fofoId) : 0);
1404
			model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
1529
			model.setTotalQty(partnerOrderQtyMap.containsKey(fofoId) ? partnerOrderQtyMap.get(fofoId) : 0);
-
 
1530
			model.setPast3daysSale(
-
 
1531
					spPartner3DaysOrderValMap.containsKey(fofoId) ? spPartner3DaysOrderValMap.get(fofoId) : 0);
1405
			model.setFofoId(fofoId);
1532
			model.setFofoId(fofoId);
1406
			saleTargetReportModelMap.put(fofoId, model);
1533
			saleTargetReportModelMap.put(fofoId, model);
1407
		}
1534
		}
1408
 
1535
 
1409
		Map<Integer, List<Serializable>> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
1536
		Map<Integer, FofoReportingModel> partnerSalesHeadersMap = this.getPartnerIdSalesHeaders();
1410
		for (Integer fofoId : fofoIds) {
1537
		for (Integer fofoId : fofoIds) {
1411
			SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
1538
			SaleTargetReportModel model = saleTargetReportModelMap.get(fofoId);
1412
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
1539
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
1413
			sendNotificationModel.setCampaignName("Sales update alert");
1540
			sendNotificationModel.setCampaignName("Sales update alert");
1414
			sendNotificationModel.setTitle("Sale Update");
1541
			sendNotificationModel.setTitle("Sale Update");
Line 1422... Line 1549...
1422
			sendNotificationModel.setMessageType(MessageType.notification);
1549
			sendNotificationModel.setMessageType(MessageType.notification);
1423
			int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
1550
			int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
1424
			sendNotificationModel.setUserIds(Arrays.asList(userId));
1551
			sendNotificationModel.setUserIds(Arrays.asList(userId));
1425
			notificationService.sendNotification(sendNotificationModel);
1552
			notificationService.sendNotification(sendNotificationModel);
1426
		}
1553
		}
1427
		String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap, saleTargetReportModelMap);
1554
		// String saleReport = this.getDailySalesReportHtml(partnerSalesHeadersMap,
-
 
1555
		// saleTargetReportModelMap);
1428
		String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap);
1556
		String statewiseSaleReport = this.getStateWiseSales(saleTargetReportModelMap, partnerSalesHeadersMap);
1429
		LOGGER.info(saleReport);
-
 
1430
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
1557
		String cc[] = { "tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com",
1431
				"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "shankar.mushra@smartdukaan.com" };
1558
				"niranjan.kala@smartdukaan.com", "up.singh@smartdukaan.com", "sm@smartdukaan.com" };
1432
 
1559
 
1433
		String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
1560
		String subject = String.format("Sale till %s", String.format(timeString, now.format(timeFormatter)));
1434
		this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc, subject);
1561
		// this.sendMailOfHtmlFomat("amit.gupta@smartukaan.com", saleReport, cc,
-
 
1562
		// subject);
1435
		this.sendMailOfHtmlFomat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
1563
		this.sendMailOfHtmlFormat("amit.gupta@smartdukaan.com", statewiseSaleReport, cc, "Statewise" + subject);
1436
	}
1564
	}
1437
 
1565
 
1438
	public static class SaleTargetReportModel {
1566
	public static class SaleTargetReportModel {
1439
		private double totalSale;
1567
		private double totalSale;
1440
		private long totalQty;
1568
		private long totalQty;
-
 
1569
		private double past3daysSale;
1441
		private int fofoId;
1570
		private int fofoId;
1442
 
1571
 
1443
		public int getFofoId() {
1572
		public int getFofoId() {
1444
			return fofoId;
1573
			return fofoId;
1445
		}
1574
		}
Line 1451... Line 1580...
1451
		private double smartphoneSale;
1580
		private double smartphoneSale;
1452
		private long smartphoneQty;
1581
		private long smartphoneQty;
1453
		private double insuranceSale;
1582
		private double insuranceSale;
1454
		private long insruanceQty;
1583
		private long insruanceQty;
1455
 
1584
 
1456
		
-
 
1457
		public long getTotalQty() {
1585
		public long getTotalQty() {
1458
			return totalQty;
1586
			return totalQty;
1459
		}
1587
		}
1460
 
1588
 
1461
		public void setTotalQty(long totalQty) {
1589
		public void setTotalQty(long totalQty) {
1462
			this.totalQty = totalQty;
1590
			this.totalQty = totalQty;
1463
		}
1591
		}
1464
 
1592
 
-
 
1593
		public double getPast3daysSale() {
-
 
1594
			return past3daysSale;
-
 
1595
		}
-
 
1596
 
-
 
1597
		public void setPast3daysSale(double past3daysSale) {
-
 
1598
			this.past3daysSale = past3daysSale;
-
 
1599
		}
-
 
1600
 
1465
		@Override
1601
		@Override
1466
		public int hashCode() {
1602
		public int hashCode() {
1467
			final int prime = 31;
1603
			final int prime = 31;
1468
			int result = 1;
1604
			int result = 1;
1469
			result = prime * result + fofoId;
1605
			result = prime * result + fofoId;
Line 1546... Line 1682...
1546
			this.insruanceQty = insruanceQty;
1682
			this.insruanceQty = insruanceQty;
1547
		}
1683
		}
1548
 
1684
 
1549
		@Override
1685
		@Override
1550
		public String toString() {
1686
		public String toString() {
1551
			return "SaleTargetReportModel [totalSale=" + totalSale + ", totalQty=" + totalQty + ", fofoId=" + fofoId
1687
			return "SaleTargetReportModel [totalSale=" + totalSale + ", totalQty=" + totalQty + ", past3daysSale="
1552
					+ ", smartphoneSale=" + smartphoneSale + ", smartphoneQty=" + smartphoneQty + ", insuranceSale="
1688
					+ past3daysSale + ", fofoId=" + fofoId + ", smartphoneSale=" + smartphoneSale + ", smartphoneQty="
1553
					+ insuranceSale + ", insruanceQty=" + insruanceQty + "]";
1689
					+ smartphoneQty + ", insuranceSale=" + insuranceSale + ", insruanceQty=" + insruanceQty + "]";
1554
		}
1690
		}
1555
 
1691
 
1556
	}
1692
	}
1557
 
1693
 
1558
	private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap) {
1694
	private String getStateWiseSales(Map<Integer, SaleTargetReportModel> saleTargetReportModelMap,
-
 
1695
			Map<Integer, FofoReportingModel> partnerSalesHeadersMap) throws Exception {
1559
		List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
1696
		List<FofoStore> stores = fofoStoreRepository.selectActiveStores();
1560
		Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors.groupingBy(
1697
		Map<String, List<Integer>> stateMap = stores.stream().collect(Collectors
1561
									x->x.getCode().substring(0,2), 
-
 
1562
									Collectors.mapping(x->x.getId(), Collectors.toList())));
1698
				.groupingBy(x -> x.getCode().substring(0, 2), Collectors.mapping(x -> x.getId(), Collectors.toList())));
1563
		List<List<Serializable>> stateWiseSales = new ArrayList<>();
1699
		List<List<Serializable>> stateWiseSales = new ArrayList<>();
1564
		for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
1700
		for (Map.Entry<String, List<Integer>> stateMapEntry : stateMap.entrySet()) {
-
 
1701
			long totalQty = stateMapEntry.getValue().stream()
1565
			long totalQty = stateMapEntry.getValue().stream().collect(Collectors.summingLong(x->saleTargetReportModelMap.get(x).getTotalQty()));
1702
					.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getTotalQty()));
-
 
1703
			double totalSale = stateMapEntry.getValue().stream()
1566
			double totalSale = stateMapEntry.getValue().stream().collect(Collectors.summingDouble(x->saleTargetReportModelMap.get(x).getTotalSale()));
1704
					.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getTotalSale()));
-
 
1705
			long smartPhoneQty = stateMapEntry.getValue().stream()
1567
			long smartPhoneQty = stateMapEntry.getValue().stream().collect(Collectors.summingLong(x->saleTargetReportModelMap.get(x).getSmartphoneQty()));
1706
					.collect(Collectors.summingLong(x -> saleTargetReportModelMap.get(x).getSmartphoneQty()));
-
 
1707
			double smartPhoneSale = stateMapEntry.getValue().stream()
1568
			double smartPhoneSale = stateMapEntry.getValue().stream().collect(Collectors.summingDouble(x->saleTargetReportModelMap.get(x).getSmartphoneSale()));
1708
					.collect(Collectors.summingDouble(x -> saleTargetReportModelMap.get(x).getSmartphoneSale()));
-
 
1709
			stateWiseSales
1569
			stateWiseSales.add(Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
1710
					.add(Arrays.asList(stateMapEntry.getKey(), smartPhoneQty, smartPhoneSale, totalQty, totalSale));
1570
		}
1711
		}
1571
		StringBuilder sb = new StringBuilder();
1712
		StringBuilder sb = new StringBuilder();
-
 
1713
		sb.append("<html><body>");
1572
		sb.append("<html><body><p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1714
		sb.append("<p>Statewise Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1573
		sb.append("<tbody>\n" + "	    <tr>"
1715
		sb.append("<tbody>\n" + "	    <tr>"
1574
				+ "	    					<th style='border:1px solid black;padding: 5px'>State</th>"
1716
				+ "	    					<th style='border:1px solid black;padding: 5px'>State</th>"
1575
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
1717
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
1576
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
1718
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Value</th>"
1577
				+ "	    					<th style='border:1px solid black;padding: 5px'>Total Qty</th>"
1719
				+ "	    					<th style='border:1px solid black;padding: 5px'>Total Qty</th>"
Line 1584... Line 1726...
1584
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
1726
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(2) + "</td>");
1585
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
1727
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(3) + "</td>");
1586
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
1728
			sb.append("<td style='border:1px solid black;padding: 5px'>" + stateSale.get(4) + "</td>");
1587
			sb.append("</tr>");
1729
			sb.append("</tr>");
1588
		}
1730
		}
1589
		sb.append("</tbody></table></body></html>");
1731
		sb.append("</tbody></table><br><br>");
1590
		return sb.toString();
-
 
1591
	}
-
 
1592
	private String getDailySalesReportHtml(Map<Integer, List<Serializable>> partnerSalesHeadersMap,
-
 
1593
			Map<Integer, SaleTargetReportModel> saleReportTargetMap) throws ProfitMandiBusinessException {
-
 
1594
		StringBuilder sb = new StringBuilder();
-
 
1595
 
1732
 
1596
		sb.append("<html><body><p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1733
		sb.append("<p>Sale Report:</p><br/><table style='border:1px solid black';cellspacing=0>");
1597
		sb.append("<tbody>\n" + "	    				<tr>\n"
1734
		sb.append("<tbody>\n" + "	    				<tr>\n"
1598
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1735
				+ "	    					<th style='border:1px solid black;padding: 5px'>Code</th>"
1599
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1736
				+ "	    					<th style='border:1px solid black;padding: 5px'>Business Name</th>"
1600
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
-
 
1601
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1737
				+ "	    					<th style='border:1px solid black;padding: 5px'>Regional Manager</th>"
1602
				+ "	    					<th style='border:1px solid black;padding: 5px'>%s</th>\n"
1738
				+ "	    					<th style='border:1px solid black;padding: 5px'>Territory Manager</th>"
1603
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>\n"
1739
				+ "	    					<th style='border:1px solid black;padding: 5px'>Sale</th>"
1604
				+ "	    					<th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>\n"
1740
				+ "	    					<th style='border:1px solid black;padding: 5px'>Smartphone Sale</th>"
1605
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>\n"
1741
				+ "	    					<th style='border:1px solid black;padding: 5px'>SmartPhone Qty</th>"
1606
				+ "	    					<th style='border:1px solid black;padding: 5px'>Insurance Sale</th>\n"
1742
				+ "	    					<th style='border:1px solid black;padding: 5px'>Insurance Sale</th>"
1607
				+ "	    					<th style='border:1px solid black;padding: 5px'>Insurance Qty</th>\n"
1743
				+ "	    					<th style='border:1px solid black;padding: 5px'>Insurance Qty</th>"
1608
				+ "	    				</tr>");
1744
				+ "	    				</tr>");
-
 
1745
 
1609
		List<Integer> sortedPartnerSalesHeaders = partnerSalesHeadersMap.entrySet().stream()
1746
		List<Integer> sortedPartnerSalesHeaders = partnerSalesHeadersMap.values().stream()
1610
				.sorted((x, y) -> ((String) (x.getValue().get(3))).compareTo((String) (y.getValue().get(3))))
1747
				.sorted(Comparator.comparing(FofoReportingModel::getBusinessName)
-
 
1748
						.thenComparing(FofoReportingModel::getRegionalManager))
1611
				.map(x -> x.getKey()).collect(Collectors.toList());
1749
				.map(FofoReportingModel::getFofoId).collect(Collectors.toList());
1612
		for (Integer fofoId : sortedPartnerSalesHeaders) {
1750
		for (Integer fofoId : sortedPartnerSalesHeaders) {
-
 
1751
			if(saleTargetReportModelMap.get(fofoId).getPast3daysSale()==0) {
1613
			sb.append("<tr>");
1752
				sb.append("<tr>");
-
 
1753
			} else {
1614
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(0)
1754
				sb.append("<tr style='background-color:red'>");
1615
					+ "</td>");
1755
			}
1616
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(1)
1756
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).getCode()
1617
					+ "</td>");
1757
					+ "</td>");
1618
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(2)
1758
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).getBusinessName()
1619
					+ "</td>");
1759
					+ "</td>");
1620
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(3)
1760
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).getRegionalManager()
1621
					+ "</td>");
1761
					+ "</td>");
1622
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).get(4)
1762
			sb.append("<td style='border:1px solid black;padding: 5px'>" + partnerSalesHeadersMap.get(fofoId).getTerritoryManager()
1623
					+ "</td>");
1763
					+ "</td>");
1624
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1764
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1625
					+ saleReportTargetMap.get(fofoId).getTotalSale() + "</td>");
1765
					+ saleTargetReportModelMap.get(fofoId).getTotalSale() + "</td>");
1626
			sb.append("<td style='border:1px solid black;padding: 5px'>"
-
 
1627
					+ saleReportTargetMap.get(fofoId).getSmartphoneSale() + "</td>");
-
 
1628
			sb.append("<td style='border:1px solid black;padding: 5px'>"
-
 
1629
					+ saleReportTargetMap.get(fofoId).getSmartphoneQty() + "</td>");
-
 
1630
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1766
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1631
					+ saleReportTargetMap.get(fofoId).getInsuranceSale() + "</td>");
1767
					+ saleTargetReportModelMap.get(fofoId).getSmartphoneSale() + "</td>");
1632
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1768
			sb.append("<td style='border:1px solid black;padding: 5px'>"
1633
					+ saleReportTargetMap.get(fofoId).getInsruanceQty() + "</td>");
1769
					+ saleTargetReportModelMap.get(fofoId).getSmartphoneQty() + "</td>");
1634
			sb.append("</tr>");
1770
			sb.append("</tr>");
1635
 
-
 
1636
		}
1771
		}
1637
 
1772
 
-
 
1773
		sb.append("</tr>");
-
 
1774
 
1638
		sb.append("</tbody></table></body></html>");
1775
		sb.append("</body></html>");
-
 
1776
 
1639
		return String.format(sb.toString(), REPORT_HEADERS);
1777
		return sb.toString();
1640
	}
1778
	}
1641
 
1779
 
1642
	private void sendMailOfHtmlFomat(String email, String body, String cc[], String subject)
1780
	private void sendMailOfHtmlFormat(String email, String body, String cc[], String subject)
1643
			throws MessagingException, ProfitMandiBusinessException, IOException {
1781
			throws MessagingException, ProfitMandiBusinessException, IOException {
1644
		MimeMessage message = mailSender.createMimeMessage();
1782
		MimeMessage message = mailSender.createMimeMessage();
1645
		MimeMessageHelper helper = new MimeMessageHelper(message);
1783
		MimeMessageHelper helper = new MimeMessageHelper(message);
1646
		helper.setSubject(subject);
1784
		helper.setSubject(subject);
1647
		helper.setText(body, true);
1785
		helper.setText(body, true);
Line 1698... Line 1836...
1698
					if (response.getStatusLine().getStatusCode() == 200) {
1836
					if (response.getStatusLine().getStatusCode() == 200) {
1699
						pushNotification.setSentTimestamp(LocalDateTime.now());
1837
						pushNotification.setSentTimestamp(LocalDateTime.now());
1700
					} else {
1838
					} else {
1701
						pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
1839
						pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
1702
						LOGGER.info("message" + "not sent");
1840
						LOGGER.info("message" + "not sent");
-
 
1841
						response.toString();
1703
					}
1842
					}
1704
 
1843
 
1705
				} catch (Exception e) {
1844
				} catch (Exception e) {
1706
					e.printStackTrace();
1845
					e.printStackTrace();
1707
					pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
1846
					pushNotification.setSentTimestamp(LocalDateTime.of(1970, 1, 1, 00, 00));
Line 1737... Line 1876...
1737
				// check if pricedrop has been rolled out
1876
				// check if pricedrop has been rolled out
1738
				List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
1877
				List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
1739
						priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
1878
						priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
1740
				if (uwh.size() > 0) {
1879
				if (uwh.size() > 0) {
1741
					Item item = itemRepository.selectById(inventoryItem.getItemId());
1880
					Item item = itemRepository.selectById(inventoryItem.getItemId());
1742
					System.out.println(String.join("\t",
1881
					System.out.println(String.join("\t", Arrays.asList(priceDropIMEI.getImei(),
1743
							Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
-
 
1744
									item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
1882
							inventoryItem.getItemId() + "", item.getBrand(), item.getModelName(), item.getModelNumber(),
1745
									customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
1883
							inventoryItem.getFofoId() + "", customRetailer.getBusinessName(),
1746
									priceDrop.getAffectedOn().format(dtf),
1884
							inventoryItem.getCreateTimestamp().format(dtf), priceDrop.getAffectedOn().format(dtf),
1747
									priceDropIMEI.getUpdateTimestamp().format(dtf),
1885
							priceDropIMEI.getUpdateTimestamp().format(dtf),
1748
									inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
1886
							inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
1749
									inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
1887
							inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
1750
				}
1888
				}
1751
			}
1889
			}
1752
		}
1890
		}
1753
	}
1891
	}
1754
 
1892
 
Line 1793... Line 1931...
1793
					FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
1931
					FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
1794
					String rollbackReason = "Scheme reversed for "
1932
					String rollbackReason = "Scheme reversed for "
1795
							+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
1933
							+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
1796
							+ fofoOrder.getInvoiceNumber();
1934
							+ fofoOrder.getInvoiceNumber();
1797
					walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
1935
					walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
1798
							scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason, LocalDateTime.now());
1936
							scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason,
-
 
1937
							LocalDateTime.now());
1799
					System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
1938
					System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
1800
							rollbackReason);
1939
							rollbackReason);
1801
				}
1940
				}
1802
			}
1941
			}
1803
		}
1942
		}
Line 2078... Line 2217...
2078
			sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
2217
			sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
2079
			System.out.println(sendNotificationModel);
2218
			System.out.println(sendNotificationModel);
2080
			notificationService.sendNotification(sendNotificationModel);
2219
			notificationService.sendNotification(sendNotificationModel);
2081
		}
2220
		}
2082
	}
2221
	}
-
 
2222
 
2083
	public void notifyVisits() throws Exception {
2223
	public void notifyVisits() throws Exception {
2084
		List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), 
2224
		List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository
2085
				LocalDateTime.now().plusHours(4));
2225
				.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
2086
		Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
2226
		Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
2087
				.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
2227
				.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
2088
		Map<String, Integer> dtrEmailMap = dtrUserRepository
2228
		Map<String, Integer> dtrEmailMap = dtrUserRepository
2089
				.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
2229
				.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
2090
				.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
2230
				.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
2091
		Map<Integer, Integer> authUserKeyMap = new HashMap<>();
2231
		Map<Integer, Integer> authUserKeyMap = new HashMap<>();
2092
		
2232
 
2093
		for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
2233
		for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
2094
			int authId = authUserEmail.getKey();
2234
			int authId = authUserEmail.getKey();
2095
			String email = authUserEmail.getValue();
2235
			String email = authUserEmail.getValue();
2096
			authUserKeyMap.put(authId, dtrEmailMap.get(email));
2236
			authUserKeyMap.put(authId, dtrEmailMap.get(email));
2097
		}
2237
		}
Line 2102... Line 2242...
2102
			if (authUserKeyMap.containsKey(visit.getAuthId())) {
2242
			if (authUserKeyMap.containsKey(visit.getAuthId())) {
2103
				continue;
2243
				continue;
2104
			}
2244
			}
2105
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
2245
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
2106
			String message = null;
2246
			String message = null;
2107
			if(visit.getFranchiseActivityId()==0) {
2247
			if (visit.getFranchiseActivityId() == 0) {
2108
				 message = String.format(visitTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
2248
				message = String.format(visitTemplate, visit.getPartnerName(),
-
 
2249
						timeFormatter.format(visit.getSchelduleTimestamp()));
2109
				 sendNotificationModel.setCampaignName("Franchisee visit Reminder");
2250
				sendNotificationModel.setCampaignName("Franchisee visit Reminder");
2110
			} else {
2251
			} else {
2111
				message = String.format(followupTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
2252
				message = String.format(followupTemplate, visit.getPartnerName(),
-
 
2253
						timeFormatter.format(visit.getSchelduleTimestamp()));
2112
				sendNotificationModel.setCampaignName("Franchisee followup Reminder");
2254
				sendNotificationModel.setCampaignName("Franchisee followup Reminder");
2113
			}
2255
			}
2114
			sendNotificationModel.setMessage(message);
2256
			sendNotificationModel.setMessage(message);
2115
			sendNotificationModel.setType("url");
2257
			sendNotificationModel.setType("url");
2116
			sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
2258
			sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");