Subversion Repositories SmartDukaan

Rev

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

Rev 27206 Rev 27208
Line 87... Line 87...
87
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
87
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
88
import com.spice.profitmandi.dao.entity.fofo.PartnerTypeChange;
88
import com.spice.profitmandi.dao.entity.fofo.PartnerTypeChange;
89
import com.spice.profitmandi.dao.entity.fofo.Purchase;
89
import com.spice.profitmandi.dao.entity.fofo.Purchase;
90
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
90
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
91
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
91
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
-
 
92
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
-
 
93
import com.spice.profitmandi.dao.entity.inventory.SaholicPOItem;
92
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
94
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
93
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
95
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
94
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
96
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
95
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
97
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
96
import com.spice.profitmandi.dao.entity.user.Address;
98
import com.spice.profitmandi.dao.entity.user.Address;
Line 156... Line 158...
156
import com.spice.profitmandi.dao.repository.user.UserRepository;
158
import com.spice.profitmandi.dao.repository.user.UserRepository;
157
import com.spice.profitmandi.service.NotificationService;
159
import com.spice.profitmandi.service.NotificationService;
158
import com.spice.profitmandi.service.PartnerInvestmentService;
160
import com.spice.profitmandi.service.PartnerInvestmentService;
159
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
161
import com.spice.profitmandi.service.integrations.toffee.ToffeeService;
160
import com.spice.profitmandi.service.inventory.InventoryService;
162
import com.spice.profitmandi.service.inventory.InventoryService;
-
 
163
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
161
import com.spice.profitmandi.service.order.OrderService;
164
import com.spice.profitmandi.service.order.OrderService;
162
import com.spice.profitmandi.service.pricing.PriceDropService;
165
import com.spice.profitmandi.service.pricing.PriceDropService;
163
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
166
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
164
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
167
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
165
import com.spice.profitmandi.service.scheme.SchemeService;
168
import com.spice.profitmandi.service.scheme.SchemeService;
Line 213... Line 216...
213
 
216
 
214
	@Autowired
217
	@Autowired
215
	private CsService csService;
218
	private CsService csService;
216
 
219
 
217
	@Autowired
220
	@Autowired
-
 
221
	private SaholicInventoryService saholicInventoryService;
-
 
222
 
-
 
223
	@Autowired
218
	private InsurancePolicyRepository insurancePolicyRepository;
224
	private InsurancePolicyRepository insurancePolicyRepository;
219
 
225
 
220
	@Autowired
226
	@Autowired
221
	private ToffeeService toffeeService;
227
	private ToffeeService toffeeService;
222
 
228
 
Line 2045... Line 2051...
2045
			for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
2051
			for (Map.Entry<Integer, Optional<Integer>> entry : focusedCatalogIdAndQtyMap.entrySet()) {
2046
				int minQty = entry.getValue().get();
2052
				int minQty = entry.getValue().get();
2047
				int inStockQty = 0;
2053
				int inStockQty = 0;
2048
				int processingQty = 0;
2054
				int processingQty = 0;
2049
				int grnPendingQty = 0;
2055
				int grnPendingQty = 0;
-
 
2056
				int allColorNetAvailability = 0;
2050
				if (processingOrderMap != null) {
2057
				if (processingOrderMap != null) {
2051
					processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
2058
					processingQty = (processingOrderMap.get(entry.getKey()) == null) ? 0
2052
							: processingOrderMap.get(entry.getKey());
2059
							: processingOrderMap.get(entry.getKey());
2053
 
2060
 
2054
				}
2061
				}
Line 2067... Line 2074...
2067
				if (totalQty < minQty) {
2074
				if (totalQty < minQty) {
2068
 
2075
 
2069
					int shortageQty = minQty - totalQty;
2076
					int shortageQty = minQty - totalQty;
2070
					List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
2077
					List<Item> item = itemRepository.selectAllByCatalogItemId(entry.getKey());
2071
 
2078
 
-
 
2079
					Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
-
 
2080
 
-
 
2081
					Map<Integer, List<SaholicCIS>> itemAvailabilityMap = saholicInventoryService.getSaholicStock()
-
 
2082
							.get(warehouseMap.get(customRetailer.getWarehouseId()));
-
 
2083
 
-
 
2084
					Map<Integer, List<SaholicPOItem>> poItemAvailabilityMap = saholicInventoryService
-
 
2085
							.getSaholicPOItems().get(warehouseMap.get(customRetailer.getWarehouseId()));
-
 
2086
					for (Item it : item) {
-
 
2087
						List<SaholicCIS> currentAvailability = itemAvailabilityMap.get(it.getId());
-
 
2088
						List<SaholicPOItem> poItemAvailability = poItemAvailabilityMap.get(it.getId());
-
 
2089
						if (currentAvailability != null) {
-
 
2090
							allColorNetAvailability += currentAvailability.stream()
-
 
2091
									.collect(Collectors.summingInt(SaholicCIS::getNetavailability));
-
 
2092
						}
-
 
2093
						if (poItemAvailability != null) {
-
 
2094
							allColorNetAvailability += poItemAvailability.stream()
-
 
2095
									.collect(Collectors.summingInt(SaholicPOItem::getUnfulfilledQty));
-
 
2096
						}
-
 
2097
					}
-
 
2098
 
2072
					FocusedModelShortageModel fm = new FocusedModelShortageModel();
2099
					FocusedModelShortageModel fm = new FocusedModelShortageModel();
2073
					fm.setFofoId(fofoId);
2100
					fm.setFofoId(fofoId);
2074
					fm.setStoreName(customRetailer.getBusinessName());
2101
					fm.setStoreName(customRetailer.getBusinessName());
2075
 
-
 
-
 
2102
					fm.setBrandName(item.get(0).getBrand());
-
 
2103
					fm.setModelName(item.get(0).getModelName());
2076
					fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() + item.get(0).getModelName());
2104
					fm.setModelNumber(item.get(0).getModelNumber());
2077
					fm.setShortageQty(shortageQty);
2105
					fm.setShortageQty(shortageQty);
-
 
2106
					fm.setWarehouseName(warehouseMap.get(customRetailer.getWarehouseId()));
-
 
2107
					// fm.setItemName(item.get(0).getBrand() + item.get(0).getModelNumber() +
-
 
2108
					// item.get(0).getModelName());
-
 
2109
					fm.setAvailabitiy(allColorNetAvailability);
2078
 
2110
 
2079
					focusedModelShortageList.add(fm);
2111
					focusedModelShortageList.add(fm);
2080
				}
2112
				}
2081
 
2113
 
2082
			}
2114
			}
-
 
2115
			/*
2083
			if (!focusedModelShortageList.isEmpty()) {
2116
			 * if (!focusedModelShortageList.isEmpty()) { String subject = "Stock Alert";
2084
				String subject = "Stock Alert";
-
 
2085
				String messageText = this.getMessage(focusedModelShortageList);
2117
			 * String messageText = this.getMessage(focusedModelShortageList);
2086
 
2118
			 * 
2087
				this.sendMailWithAttachments(subject, messageText, customRetailer.getEmail());
2119
			 * this.sendMailWithAttachments(subject, messageText,
-
 
2120
			 * customRetailer.getEmail()); String notificationMessage =
2088
				String notificationMessage = this.getNotificationMessage(focusedModelShortageList);
2121
			 * this.getNotificationMessage(focusedModelShortageList);
2089
 
2122
			 * 
2090
				LOGGER.info("notificationMessage" + notificationMessage);
2123
			 * LOGGER.info("notificationMessage" + notificationMessage);
2091
 
2124
			 * 
2092
				SendNotificationModel sendNotificationModel = new SendNotificationModel();
2125
			 * SendNotificationModel sendNotificationModel = new SendNotificationModel();
2093
				sendNotificationModel.setCampaignName("Stock Alert");
2126
			 * sendNotificationModel.setCampaignName("Stock Alert");
2094
				sendNotificationModel.setTitle("Alert");
2127
			 * sendNotificationModel.setTitle("Alert");
2095
				sendNotificationModel.setMessage(notificationMessage);
2128
			 * sendNotificationModel.setMessage(notificationMessage);
2096
				sendNotificationModel.setType("url");
2129
			 * sendNotificationModel.setType("url"); sendNotificationModel.setUrl(
2097
				sendNotificationModel.setUrl("https://app.smartdukaan.com/pages/home/notifications");
2130
			 * "https://app.smartdukaan.com/pages/home/notifications");
2098
				sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
2131
			 * sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(2));
2099
				sendNotificationModel.setMessageType(MessageType.notification);
2132
			 * sendNotificationModel.setMessageType(MessageType.notification); int userId =
2100
				int userId = userAccountRepository.selectUserIdByRetailerId(fofoId);
2133
			 * userAccountRepository.selectUserIdByRetailerId(fofoId);
2101
				sendNotificationModel.setUserIds(Arrays.asList(userId));
2134
			 * sendNotificationModel.setUserIds(Arrays.asList(userId));
2102
				notificationService.sendNotification(sendNotificationModel);
2135
			 * notificationService.sendNotification(sendNotificationModel);
2103
 
2136
			 * 
2104
			}
2137
			 * }
2105
 
2138
			 */
2106
		}
2139
		}
2107
		if (!focusedModelShortageReportMap.isEmpty()) {
2140
		if (!focusedModelShortageReportMap.isEmpty()) {
2108
			String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
2141
			String fileName = "Stock Alert-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".csv";
2109
			Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
2142
			Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
2110
			Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
2143
			Map<String, List<List<?>>> emailRowsMap = new HashMap<>();
Line 2114... Line 2147...
2114
 
2147
 
2115
					if (y.getValue().contains(x.getKey())) {
2148
					if (y.getValue().contains(x.getKey())) {
2116
						if (!emailRowsMap.containsKey(y.getKey())) {
2149
						if (!emailRowsMap.containsKey(y.getKey())) {
2117
							emailRowsMap.put(y.getKey(), new ArrayList<>());
2150
							emailRowsMap.put(y.getKey(), new ArrayList<>());
2118
						}
2151
						}
2119
						List<List<? extends Serializable>> fms = x.getValue().stream().map(r -> Arrays
2152
						List<List<? extends Serializable>> fms = x.getValue().stream()
-
 
2153
								.map(r -> Arrays.asList(r.getStoreCode(), r.getStoreName(), r.getBrandName(),
2120
								.asList(r.getFofoId(), r.getStoreName(), r.getItemName(), r.getShortageQty()))
2154
										r.getModelName(), r.getModelNumber(), r.getShortageQty()))
2121
								.collect(Collectors.toList());
2155
								.collect(Collectors.toList());
2122
						emailRowsMap.get(y.getKey()).addAll(fms);
2156
						emailRowsMap.get(y.getKey()).addAll(fms);
2123
 
2157
 
2124
					}
2158
					}
2125
 
2159
 
2126
				});
2160
				});
2127
 
2161
 
2128
			});
2162
			});
2129
 
2163
 
2130
			List<String> headers = Arrays.asList("Partner Id", "Partner Name", "Model Name", "Shortage Qty");
2164
			List<String> headers = Arrays.asList("Partner Code", "Partner Name", "Brand", "Model Name", "Model Number",
-
 
2165
					"Shortage Qty");
2131
			emailRowsMap.entrySet().forEach(entry -> {
2166
			emailRowsMap.entrySet().forEach(entry -> {
2132
 
2167
 
2133
				ByteArrayOutputStream baos = null;
2168
				ByteArrayOutputStream baos = null;
2134
				try {
2169
				try {
2135
					baos = FileUtil.getCSVByteStream(headers, entry.getValue());
2170
					baos = FileUtil.getCSVByteStream(headers, entry.getValue());
2136
				} catch (Exception e2) {
2171
				} catch (Exception e2) {
2137
					e2.printStackTrace();
2172
					e2.printStackTrace();
2138
				}
2173
				}
2139
				String[] sendToArray = new String[] { entry.getKey() };
2174
				String[] sendToArray = new String[] {
-
 
2175
						// entry.getKey()
-
 
2176
						"tejbeer.kaur@shop2020.in" };
2140
				try {
2177
				try {
2141
					Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
2178
					Utils.sendMailWithAttachment(googleMailSender, sendToArray, null, "Stock Alert", "PFA", fileName,
2142
							new ByteArrayResource(baos.toByteArray()));
2179
							new ByteArrayResource(baos.toByteArray()));
2143
				} catch (Exception e1) { // TODO Auto-generated catch block
2180
				} catch (Exception e1) { // TODO Auto-generated catch block
2144
					e1.printStackTrace();
2181
					e1.printStackTrace();