Subversion Repositories SmartDukaan

Rev

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

Rev 26792 Rev 26862
Line 251... Line 251...
251
	PriceDropRepository priceDropRepository;
251
	PriceDropRepository priceDropRepository;
252
 
252
 
253
	@Autowired
253
	@Autowired
254
	private SchemeService schemeService;
254
	private SchemeService schemeService;
255
 
255
 
256
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "amod.sen@smartdukaan.com",
256
	private static final String[] STOCK_AGEING_MAIL_LIST = new String[] { "uday.singh@smartudkaan.com", 
257
			"adeel.yazdani@smartdukaan.com", "manoj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com",
257
			"adeel.yazdani@smartdukaan.com", "manoj.singh@smartdukaan.com", "kamini.sharma@smartdukaan.com",
258
			"mohinder.mutreja@smartdukaan.com", "	ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
258
			"mohinder.mutreja@smartdukaan.com", "ankit.bhatia@smartdukaan.com", "tarun.verma@smartdukaan.com",
259
			"chaitnaya.vats@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "prakash.rai@smartdukaan.com" };
259
			"hemant.kaura@smartdukaan.com","rajat.gupta@smartdukaan.com", "kuldeep.kumar@smartdukaan.com", "prakash.rai@smartdukaan.com" };
260
 
260
 
261
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
261
	private static final String[] ITEMWISE_PENDING_INDENT_MAIL_LIST = new String[] { "kamini.sharma@smartdukaan.com",
262
			"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "chaitnaya.vats@smartdukaan.com",
262
			"prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com", "uday.singh@smartdukaan.com",
263
			"kuldeep.kumar@smartdukaan.com" };
263
			"kuldeep.kumar@smartdukaan.com" };
264
 
264
 
265
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
265
	private List<OrderStatus> orderStatusList = Arrays.asList(OrderStatus.SUBMITTED_FOR_PROCESSING);
266
 
266
 
267
	private Object[] REPORT_HEADERS = { "Store Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager" };
267
	private Object[] REPORT_HEADERS = { "Store Code", "Firm Name", "Store Name", "State Manager", "Teritory Manager" };
Line 714... Line 714...
714
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
714
		List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
715
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
715
		Map<Integer, CustomRetailer> customRetailerMap = retailerService
716
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
716
				.getFofoRetailers(fofoStores.stream().map(x -> x.getId()).collect(Collectors.toList()));
717
 
717
 
718
		List<String> headers = Arrays.asList("Code", "Firm Name", "Store Name", "State Manager", "Teritory/Team Lead",
718
		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",
719
				"Wallet Amount", "In Stock Amount", "Activated Stock", "Return In Transit Stock", "Unbilled Amount", "Grn Pending Amount",
720
				"Grn Pending Amount", "Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty",
720
				"Min Investment", "Investment Amount", "Investment Short", "Unbilled Qty", "Short Days");
721
				"Short Days");
-
 
722
		List<List<?>> rows = new ArrayList<>();
721
		List<List<?>> rows = new ArrayList<>();
723
		Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
722
		Map<Integer, List<?>> partnerRowsMap = new HashMap<>();
724
 
723
 
725
		Map<Integer, List<Serializable>> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
724
		Map<Integer, List<Serializable>> partnerIdSalesHeaderMap = this.getPartnerIdSalesHeaders();
726
 
725
		
727
		Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository
726
		Map<Integer, Integer> shortDaysMap = partnerDailyInvestmentRepository.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now())
728
				.selectAll(LocalDate.now().withDayOfMonth(1), LocalDate.now()).stream().collect(Collectors.groupingBy(
727
		.stream().collect(Collectors.groupingBy(x->x.getFofoId(), 
729
						x -> x.getFofoId(), Collectors.summingInt(x -> x.getShortPercentage() > 10 ? 1 : 0)));
728
				Collectors.summingInt(x-> x.getShortPercentage() > 10 ? 1 : 0)));
730
 
729
 
731
		for (FofoStore fofoStore : fofoStores) {
730
		for (FofoStore fofoStore : fofoStores) {
732
			int fofoId = fofoStore.getId();
731
			int fofoId = fofoStore.getId();
733
			PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId, 1);
732
			PartnerDailyInvestment partnerDailyInvestment = partnerInvestmentService.getInvestment(fofoId,1);
734
			partnerDailyInvestment.setDate(yesterDay);
733
			partnerDailyInvestment.setDate(yesterDay);
735
 
734
			
736
			try {
735
			try {
737
				partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
736
				partnerDailyInvestmentRepository.persist(partnerDailyInvestment);
738
				shortDaysMap.put(fofoId,
-
 
739
						shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
737
				shortDaysMap.put(fofoId, shortDaysMap.get(fofoId) + (partnerDailyInvestment.getShortPercentage() > 10 ? 1 : 0));
740
			} catch (Exception e) {
738
			} catch (Exception e) {
741
				// ignore the exceptions during persist
739
				// ignore the exceptions during persist
742
			}
740
			}
743
 
741
 
744
			CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
742
			CustomRetailer retailer = customRetailerMap.get(fofoStore.getId());
Line 747... Line 745...
747
				continue;
745
				continue;
748
			}
746
			}
749
			List<Serializable> row = partnerIdSalesHeaderMap.get(fofoStore.getId());
747
			List<Serializable> row = partnerIdSalesHeaderMap.get(fofoStore.getId());
750
			row.addAll(
748
			row.addAll(
751
					Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
749
					Arrays.asList(partnerDailyInvestment.getWalletAmount(), partnerDailyInvestment.getInStockAmount(),
752
							partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-"
750
							partnerDailyInvestment.getActivatedStockAmount() == 0 ? "-":"("+partnerDailyInvestment.getActivatedStockAmount()+")",
753
									: "(" + partnerDailyInvestment.getActivatedStockAmount() + ")",
-
 
754
							0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
751
							0, partnerDailyInvestment.getUnbilledAmount(), partnerDailyInvestment.getGrnPendingAmount(),
755
							partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
752
							partnerDailyInvestment.getMinInvestment(), partnerDailyInvestment.getTotalInvestment(),
756
							partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),
753
							partnerDailyInvestment.getShortInvestment(), partnerDailyInvestment.getUnbilledQty(),shortDaysMap.get(fofoId)));
757
							shortDaysMap.get(fofoId)));
-
 
758
			partnerRowsMap.put(fofoStore.getId(), row);
754
			partnerRowsMap.put(fofoStore.getId(), row);
759
			rows.add(row);
755
			rows.add(row);
760
 
756
 
761
		}
757
		}
762
 
758
 
Line 798... Line 794...
798
				if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
794
				if (!partnerEmailSalesMap.containsKey(cr.getEmail())) {
799
					partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
795
					partnerEmailSalesMap.put(cr.getEmail(), new SaleRoles());
800
				}
796
				}
801
				SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
797
				SaleRoles saleRoles = partnerEmailSalesMap.get(cr.getEmail());
802
				AuthUser authUser = authUsersMap.get(position.getAuthUserId());
798
				AuthUser authUser = authUsersMap.get(position.getAuthUserId());
803
				if (authUser == null) {
799
				if(authUser==null) {
804
					continue;
800
					continue;
805
				}
801
				}
806
				String name = authUser.getFirstName() + " " + authUser.getLastName();
802
				String name = authUser.getFirstName() + " " + authUser.getLastName();
807
				if (position.getEscalationType().equals(EscalationType.L1)) {
803
				if (position.getEscalationType().equals(EscalationType.L1)) {
808
					saleRoles.getL1().add(name);
804
					saleRoles.getL1().add(name);
Line 931... Line 927...
931
 
927
 
932
	}
928
	}
933
 
929
 
934
	public void sendAgeingReport() throws Exception {
930
	public void sendAgeingReport() throws Exception {
935
		sendAgeingReport("kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com",
931
		sendAgeingReport("kamini.sharma@smartdukaan.com", "prakash.rai@smartdukaan.com", "tarun.verma@smartdukaan.com",
936
				"chaitnaya.vats@smartdukaan.com");
932
				"hemant.kaura@smartdukaan.com");
937
	}
933
	}
938
 
934
 
939
	public void moveImeisToPriceDropImeis() throws Exception {
935
	public void moveImeisToPriceDropImeis() throws Exception {
940
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
936
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
941
		for (PriceDrop priceDrop : priceDrops) {
937
		for (PriceDrop priceDrop : priceDrops) {
Line 1686... Line 1682...
1686
				// check if pricedrop has been rolled out
1682
				// check if pricedrop has been rolled out
1687
				List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
1683
				List<UserWalletHistory> uwh = walletService.getAllByReference(inventoryItem.getFofoId(),
1688
						priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
1684
						priceDropIMEI.getPriceDropId(), WalletReferenceType.PRICE_DROP);
1689
				if (uwh.size() > 0) {
1685
				if (uwh.size() > 0) {
1690
					Item item = itemRepository.selectById(inventoryItem.getItemId());
1686
					Item item = itemRepository.selectById(inventoryItem.getItemId());
1691
					System.out.println(String.join("\t", Arrays.asList(priceDropIMEI.getImei(),
1687
					System.out.println(String.join("\t",
-
 
1688
							Arrays.asList(priceDropIMEI.getImei(), inventoryItem.getItemId() + "", item.getBrand(),
1692
							inventoryItem.getItemId() + "", item.getBrand(), item.getModelName(), item.getModelNumber(),
1689
									item.getModelName(), item.getModelNumber(), inventoryItem.getFofoId() + "",
1693
							inventoryItem.getFofoId() + "", customRetailer.getBusinessName(),
1690
									customRetailer.getBusinessName(), inventoryItem.getCreateTimestamp().format(dtf),
1694
							inventoryItem.getCreateTimestamp().format(dtf), priceDrop.getAffectedOn().format(dtf),
1691
									priceDrop.getAffectedOn().format(dtf),
1695
							priceDropIMEI.getUpdateTimestamp().format(dtf),
1692
									priceDropIMEI.getUpdateTimestamp().format(dtf),
1696
							inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
1693
									inventoryItem.getUpdateTimestamp().format(dtf), priceDrop.getAutoPartnerPayout() + "",
1697
							inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
1694
									inventoryItem.getLastScanType().equals(ScanType.DOA_OUT) + "")));
1698
				}
1695
				}
1699
			}
1696
			}
1700
		}
1697
		}
1701
	}
1698
	}
1702
 
1699
 
Line 1741... Line 1738...
1741
					FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
1738
					FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(scanRecord.getOrderId());
1742
					String rollbackReason = "Scheme reversed for "
1739
					String rollbackReason = "Scheme reversed for "
1743
							+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
1740
							+ itemRepository.selectById(inventoryItem.getItemId()).getItemDescription() + "/Inv - "
1744
							+ fofoOrder.getInvoiceNumber();
1741
							+ fofoOrder.getInvoiceNumber();
1745
					walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
1742
					walletService.rollbackAmountFromWallet(scanRecord.getFofoId(), sio.getAmount(),
1746
							scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason,
1743
							scanRecord.getOrderId(), WalletReferenceType.SCHEME_OUT, rollbackReason, LocalDateTime.now());
1747
							LocalDateTime.now());
-
 
1748
					System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
1744
					System.out.printf("Amount %f,SchemeId %d,Reason %s\n", sio.getAmount(), sio.getSchemeId(),
1749
							rollbackReason);
1745
							rollbackReason);
1750
				}
1746
				}
1751
			}
1747
			}
1752
		}
1748
		}
Line 2027... Line 2023...
2027
			sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
2023
			sendNotificationModel.setUserIds(Arrays.asList(authUserKeyMap.get(lead.getAssignTo())));
2028
			System.out.println(sendNotificationModel);
2024
			System.out.println(sendNotificationModel);
2029
			notificationService.sendNotification(sendNotificationModel);
2025
			notificationService.sendNotification(sendNotificationModel);
2030
		}
2026
		}
2031
	}
2027
	}
2032
 
-
 
2033
	public void notifyVisits() throws Exception {
2028
	public void notifyVisits() throws Exception {
2034
		List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository
2029
		List<FranchiseeVisit> franchiseeVisits = franchiseeVisitRepository.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), 
2035
				.selectVisitsScheduledBetweenDate(LocalDateTime.now().minusDays(15), LocalDateTime.now().plusHours(4));
2030
				LocalDateTime.now().plusHours(4));
2036
		Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
2031
		Map<Integer, String> authUserEmailMap = authRepository.selectAllActiveUser().stream()
2037
				.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
2032
				.collect(Collectors.toMap(x -> x.getId(), x -> x.getEmailId()));
2038
		Map<String, Integer> dtrEmailMap = dtrUserRepository
2033
		Map<String, Integer> dtrEmailMap = dtrUserRepository
2039
				.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
2034
				.selectAllByEmailIds(new ArrayList<>(authUserEmailMap.values())).stream()
2040
				.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
2035
				.collect(Collectors.toMap(x -> x.getEmailId(), x -> x.getId()));
2041
		Map<Integer, Integer> authUserKeyMap = new HashMap<>();
2036
		Map<Integer, Integer> authUserKeyMap = new HashMap<>();
2042
 
2037
		
2043
		for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
2038
		for (Map.Entry<Integer, String> authUserEmail : authUserEmailMap.entrySet()) {
2044
			int authId = authUserEmail.getKey();
2039
			int authId = authUserEmail.getKey();
2045
			String email = authUserEmail.getValue();
2040
			String email = authUserEmail.getValue();
2046
			authUserKeyMap.put(authId, dtrEmailMap.get(email));
2041
			authUserKeyMap.put(authId, dtrEmailMap.get(email));
2047
		}
2042
		}
Line 2052... Line 2047...
2052
			if (authUserKeyMap.containsKey(visit.getAuthId())) {
2047
			if (authUserKeyMap.containsKey(visit.getAuthId())) {
2053
				continue;
2048
				continue;
2054
			}
2049
			}
2055
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
2050
			SendNotificationModel sendNotificationModel = new SendNotificationModel();
2056
			String message = null;
2051
			String message = null;
2057
			if (visit.getFranchiseActivityId() == 0) {
2052
			if(visit.getFranchiseActivityId()==0) {
2058
				message = String.format(visitTemplate, visit.getPartnerName(),
2053
				 message = String.format(visitTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
2059
						timeFormatter.format(visit.getSchelduleTimestamp()));
-
 
2060
				sendNotificationModel.setCampaignName("Franchisee visit Reminder");
2054
				 sendNotificationModel.setCampaignName("Franchisee visit Reminder");
2061
			} else {
2055
			} else {
2062
				message = String.format(followupTemplate, visit.getPartnerName(),
2056
				message = String.format(followupTemplate, visit.getPartnerName(), timeFormatter.format(visit.getSchelduleTimestamp()));
2063
						timeFormatter.format(visit.getSchelduleTimestamp()));
-
 
2064
				sendNotificationModel.setCampaignName("Franchisee followup Reminder");
2057
				sendNotificationModel.setCampaignName("Franchisee followup Reminder");
2065
			}
2058
			}
2066
			sendNotificationModel.setMessage(message);
2059
			sendNotificationModel.setMessage(message);
2067
			sendNotificationModel.setType("url");
2060
			sendNotificationModel.setType("url");
2068
			sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
2061
			sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");