Subversion Repositories SmartDukaan

Rev

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

Rev 25595 Rev 25597
Line 687... Line 687...
687
				.getFofoRetailers(new ArrayList<>(fofoStoresMap.keySet()));
687
				.getFofoRetailers(new ArrayList<>(fofoStoresMap.keySet()));
688
 
688
 
689
		Map<String, CustomRetailer> customRetailerEmailMap = customRetailerMap.values().stream()
689
		Map<String, CustomRetailer> customRetailerEmailMap = customRetailerMap.values().stream()
690
				.collect(Collectors.toMap(x -> x.getEmail(), x -> x));
690
				.collect(Collectors.toMap(x -> x.getEmail(), x -> x));
691
 
691
 
692
		List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager",
692
		List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "Current Category", "State Manager", "Teritory Manager", 
693
				"Team Leader", "Target Name", "Target Value", "Target Achieved", "Achived Percentage",
693
				"Team Leader", "Targeted Category", "Targeted Value", "Target Achieved", "Achived Percentage",
694
				"Remaining Target", "Today's Target", "Today's achievement");
694
				"Remaining Target", "Today's Target", "Today's achievement");
695
 
695
 
696
		List<List<? extends Serializable>> rows = new ArrayList<>();
696
		List<List<? extends Serializable>> rows = new ArrayList<>();
697
		Map<String, List<Serializable>> partnerRowMap = new HashMap<>();
697
		Map<String, List<Serializable>> partnerRowMap = new HashMap<>();
698
		for (Map.Entry<String, List<? extends Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap
698
		for (Map.Entry<String, List<? extends Serializable>> partnerSalesTargetRowEntry : partnerSalesTargetRowsMap
Line 718... Line 718...
718
			}
718
			}
719
 
719
 
720
		}
720
		}
721
 
721
 
722
		String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
722
		String fileName = "TargetVsSales-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
723
		for (Map.Entry<String, Set<String>> storeGuyEntry : getStoreGuyMap().entrySet()) {
723
		for (Map.Entry<String, Set<String>> storeGuyEntry : csService.getAuthUserPartnerEmailMapping().entrySet()) {
724
			List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
724
			List<List<? extends Serializable>> filteredRows = storeGuyEntry.getValue().stream()
725
					.map(x -> partnerRowMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
725
					.map(x -> partnerRowMap.get(x)).filter(x -> x != null).collect(Collectors.toList());
726
			ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
726
			ByteArrayOutputStream baos = FileUtil.getCSVByteStream(headers, filteredRows);
727
			String[] sendToArray = new String[] { storeGuyEntry.getKey() };
727
			String[] sendToArray = new String[] { storeGuyEntry.getKey() };
728
			Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA",
728
			Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA",
Line 733... Line 733...
733
		String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
733
		String[] sendToArray = sendTo.toArray(new String[sendTo.size()]);
734
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA", fileName,
734
		Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Target vs Sales Summary", "PFA", fileName,
735
				new ByteArrayResource(baos.toByteArray()));
735
				new ByteArrayResource(baos.toByteArray()));
736
	}
736
	}
737
 
737
 
738
	private Map<String, Set<String>> getStoreGuyMap() {
-
 
739
		Map<String, Set<String>> storeGuyMap = new HashMap<>();
-
 
740
		Set<Integer> activeFofoIds = fofoStoreRepository.selectActiveStores().stream().map(x->x.getId()).collect(Collectors.toSet());
-
 
741
		List<Position> categoryPositions = positionRepository.selectPositionByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES);
-
 
742
		Map<Integer, Position> positionsMap = categoryPositions.stream().collect(Collectors.toMap(x->x.getId(), x->x));
-
 
743
		
-
 
744
		Map<Integer, List<CustomRetailer>> positonPartnerMap = csService.getPositionCustomRetailerMap(categoryPositions);
-
 
745
		for(Map.Entry<Integer, List<CustomRetailer>> positionPartnerEntry : positonPartnerMap.entrySet()) {
-
 
746
			int authUserId = positionsMap.get(positionPartnerEntry.getKey()).getAuthUserId();
-
 
747
			Set<String> partnerEmails = positionPartnerEntry.getValue().stream()
-
 
748
					.filter(x->activeFofoIds.contains(x.getPartnerId()))
-
 
749
					.map(x->x.getEmail()).collect(Collectors.toSet());
-
 
750
			AuthUser authUser = authRepository.selectById(authUserId);
-
 
751
			if(authUser.isActive()) {
-
 
752
				storeGuyMap.put(authUser.getEmailId(), partnerEmails);
-
 
753
			}
-
 
754
		}
-
 
755
		return storeGuyMap;
-
 
756
	}
-
 
757
 
-
 
758
	public void sendAgeingReport(String... sendTo) throws Exception {
738
	public void sendAgeingReport(String... sendTo) throws Exception {
759
 
739
 
760
		InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
740
		InputStreamSource isr = reporticoService.getReportInputStreamSource(ReporticoProject.WAREHOUSENEW,
761
				"itemstockageing.xml");
741
				"itemstockageing.xml");
762
		InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
742
		InputStreamSource isr1 = reporticoService.getReportInputStreamSource(ReporticoProject.FOCO,
Line 767... Line 747...
767
				"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
747
				"pending-indent-" + FormattingUtils.formatDate(LocalDateTime.now().minusDays(1)) + ".csv", isr1);
768
		Utils.sendMailWithAttachments(googleMailSender, sendTo, null, "Stock Aeging Report", "PFA", attachment,
748
		Utils.sendMailWithAttachments(googleMailSender, sendTo, null, "Stock Aeging Report", "PFA", attachment,
769
				attachment1);
749
				attachment1);
770
 
750
 
771
		//Reports to be sent to mapped partners
751
		//Reports to be sent to mapped partners
772
		Map<String, Set<String>> storeGuysMap = getStoreGuyMap();
752
		Map<String, Set<String>> storeGuysMap = csService.getAuthUserPartnerEmailMapping();
773
 
753
 
774
		String[] sendToArray = new String[storeGuysMap.size()];
754
		String[] sendToArray = new String[storeGuysMap.size()];
775
		int i = 0;
755
		int i = 0;
776
		for (String storeGuyName : storeGuysMap.keySet()) {
756
		for (String storeGuyName : storeGuysMap.keySet()) {
777
			sendToArray[i] = nameEmail.get(storeGuyName);
757
			sendToArray[i] = nameEmail.get(storeGuyName);
Line 1530... Line 1510...
1530
					partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now().plusDays(1)));
1510
					partnerTypeChangeService.getTypeOnDate(fofoStore.getId(), LocalDate.now().plusDays(1)));
1531
				UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoStore.getId());
1511
				UserWallet userWallet = userWalletRepository.selectByRetailerId(fofoStore.getId());
1532
				if(userWallet==null) continue;
1512
				if(userWallet==null) continue;
1533
				System.out.printf("Store Code %s, Wallet amount %d, Sum amount %f%n", fofoStore.getCode(), userWallet.getAmount(), walletService.getWalletAmount(fofoStore.getId()));
1513
				System.out.printf("Store Code %s, Wallet amount %d, Sum amount %f%n", fofoStore.getCode(), userWallet.getAmount(), walletService.getWalletAmount(fofoStore.getId()));
1534
		}*/
1514
		}*/
1535
		for (Map.Entry<String, Set<String>> storeGuyEntry : getStoreGuyMap().entrySet()) {
1515
		for (Map.Entry<String, Set<String>> storeGuyEntry : csService.getAuthUserPartnerEmailMapping().entrySet()) {
1536
			System.out.println(storeGuyEntry.getKey() + " = " + storeGuyEntry.getValue());
1516
			System.out.println(storeGuyEntry.getKey() + " = " + storeGuyEntry.getValue());
1537
		}
1517
		}
1538
	}
1518
	}
1539
}
1519
}