Subversion Repositories SmartDukaan

Rev

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

Rev 23785 Rev 23786
Line 30... Line 30...
30
import com.spice.profitmandi.common.enumuration.CounterSize;
30
import com.spice.profitmandi.common.enumuration.CounterSize;
31
import com.spice.profitmandi.common.enumuration.IndentStatus;
31
import com.spice.profitmandi.common.enumuration.IndentStatus;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
32
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
33
import com.spice.profitmandi.common.model.BrandPerformance;
33
import com.spice.profitmandi.common.model.BrandPerformance;
34
import com.spice.profitmandi.common.model.CustomRetailer;
34
import com.spice.profitmandi.common.model.CustomRetailer;
-
 
35
import com.spice.profitmandi.common.model.ItemIdAvailability;
-
 
36
import com.spice.profitmandi.common.model.ItemIdQuantity;
-
 
37
import com.spice.profitmandi.common.model.ItemIdQuantityAvailability;
35
import com.spice.profitmandi.common.model.StockAllocationModel;
38
import com.spice.profitmandi.common.model.StockAllocationModel;
36
import com.spice.profitmandi.dao.entity.catalog.Item;
39
import com.spice.profitmandi.dao.entity.catalog.Item;
37
import com.spice.profitmandi.dao.entity.catalog.TagListing;
40
import com.spice.profitmandi.dao.entity.catalog.TagListing;
38
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
41
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
39
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
42
import com.spice.profitmandi.dao.entity.fofo.FofoOrderItem;
Line 90... Line 93...
90
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
93
	private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
91
 
94
 
92
	@Autowired
95
	@Autowired
93
	private MVCResponseSender mvcResponseSender;
96
	private MVCResponseSender mvcResponseSender;
94
 
97
 
95
	/*
-
 
96
	 * @RequestMapping(value = "/indent-item/save", method = RequestMethod.PUT)
-
 
97
	 * public String saveIndentItem(HttpServletRequest request, @RequestBody
-
 
98
	 * ItemIdQuantity itemIdQuantity, Model model) throws Exception { LoginDetails
-
 
99
	 * loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
100
	 * LOGGER.info("Item id is {}, And quantity is {}", itemIdQuantity.getItemId(),
-
 
101
	 * itemIdQuantity.getItemId()); boolean response = false;
-
 
102
	 * if(loginDetails.isAdmin()) { StockAllocationModel stockAllocationModel = new
-
 
103
	 * StockAllocationModel();
-
 
104
	 * stockAllocationModel.setQuantity(itemIdQuantity.getQuantity());
-
 
105
	 * stockAllocationModel.setItemId(itemIdQuantity.getItemId()); response =
-
 
106
	 * stockAllocationService.addToAllocation(stockAllocationModel); } //int fofoId
-
 
107
	 * = loginDetails.getFofoId(); model.addAttribute("response",
-
 
108
	 * mvcResponseSender.createResponseString(response)); return "response"; }
-
 
109
	 */
-
 
110
	
-
 
111
	@Autowired
98
	@Autowired
112
	RoleManager roleManager;
99
	RoleManager roleManager;
113
 
100
 
114
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
101
	@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
115
	public String saveOpenIndent(HttpServletRequest request, Model model,
102
	public String saveOpenIndent(HttpServletRequest request, Model model,
116
			@RequestBody List<StockAllocationModel> stockAllocationModelList, @RequestParam int fofoId)
103
			@RequestBody List<StockAllocationModel> stockAllocationModelList, @RequestParam int fofoId,
117
			throws Exception {
104
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
118
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
105
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
119
		boolean response = false;
106
		boolean response = false;
120
		if (fofoId > 0) {
107
		if (fofoId > 0) {
121
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
108
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
109
			stockAllocationModelList.forEach(x -> {
-
 
110
				x.setFofoId(fofoId);
-
 
111
				x.setCounterSize(fs.getCounterSize());
-
 
112
			});
-
 
113
		} else {
122
			stockAllocationModelList.forEach(x -> {x.setFofoId(fofoId);x.setCounterSize(fs.getCounterSize());});
114
			stockAllocationModelList.forEach(x -> {
-
 
115
				x.setFofoId(fofoId);
-
 
116
				x.setCounterSize(counterSize);
-
 
117
			});
123
		}
118
		}
124
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
119
		if (roleManager.isAdmin(loginDetails.getRoleIds())) {
125
			response = stockAllocationService.addToAllocation(stockAllocationModelList);
120
			response = stockAllocationService.addToAllocation(stockAllocationModelList);
126
			model.addAttribute("response", mvcResponseSender.createResponseString(response));
121
			model.addAttribute("response", mvcResponseSender.createResponseString(response));
127
		}
122
		}
Line 183... Line 178...
183
	}
178
	}
184
 
179
 
185
	@RequestMapping(value = "/indent/loadIndent")
180
	@RequestMapping(value = "/indent/loadIndent")
186
	public String loadOpenIndent(HttpServletRequest request, Model model,
181
	public String loadOpenIndent(HttpServletRequest request, Model model,
187
			@RequestParam(required = false, defaultValue = "0") int fofoId,
182
			@RequestParam(required = false, defaultValue = "0") int fofoId,
188
			@RequestParam(defaultValue="TEN_LAC") CounterSize counterSize) throws ProfitMandiBusinessException {
183
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws ProfitMandiBusinessException {
189
		Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
184
		Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
190
		LOGGER.info("Counter size is {}", counterSize);
185
		LOGGER.info("Counter size is {}", counterSize);
191
		LOGGER.info("Fofo Id is {}", fofoId);
186
		LOGGER.info("Fofo Id is {}", fofoId);
-
 
187
 
-
 
188
		Map<Integer, ItemIdAvailability> itemCisMap = null;
192
		if (roleManager.isAdmin(roleIds)) {
189
		if (!roleManager.isAdmin(roleIds)) {
193
			List<BrandPerformance> brandPerformanceList = new ArrayList<>();
190
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
194
			List<BrandPerformance> accsBrandPerformanceList = new ArrayList<>();
191
			List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository.selectItemsStock(fofoId);
195
			List<StockAllocationModel> stockAllocationList;
192
			itemCisMap = currentInventorySnapshots.stream().filter(x->x.getAvailability()>0).collect(Collectors.toMap(x -> x.getItemId(), x -> x));
-
 
193
		} else {
196
			if (fofoId > 0) {
194
			if (fofoId == 0) {
197
				stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
195
				List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository.selectItemsStock();
-
 
196
				itemCisMap = currentInventorySnapshots.stream().filter(x->x.getAvailability()>0).collect(Collectors.toMap(x -> x.getItemId(), x -> x));
198
			} else {
197
			} else {
199
				stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
198
				List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository.selectItemsStock(fofoId);
-
 
199
				itemCisMap = currentInventorySnapshots.stream().filter(x->x.getAvailability()>0).collect(Collectors.toMap(x -> x.getItemId(), x -> x));
200
			}
200
			}
-
 
201
		}
-
 
202
		List<BrandPerformance> brandPerformanceList = new ArrayList<>();
-
 
203
		List<BrandPerformance> accsBrandPerformanceList = new ArrayList<>();
-
 
204
		List<StockAllocationModel> stockAllocationList;
-
 
205
		if (fofoId > 0) {
-
 
206
			stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
-
 
207
		} else {
-
 
208
			stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
-
 
209
		}
201
			LOGGER.info("Stock Allocation list  is {}", stockAllocationList);
210
		LOGGER.info("Stock Allocation list  is {}", stockAllocationList);
202
 
211
 
203
			Map<Integer, StockAllocationModel> itemStockAllocationMap = stockAllocationList.stream()
212
		Map<Integer, StockAllocationModel> itemStockAllocationMap = stockAllocationList.stream()
204
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
213
				.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
205
 
214
 
206
			LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
215
		LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
207
			List<TagListing> tagListings = tagListingRepository.selectAll();
216
		List<TagListing> tagListings = tagListingRepository.selectAll();
-
 
217
		if(!roleManager.isAdmin(roleIds)) {
-
 
218
			tagListings = new ArrayList<>(tagListings);
-
 
219
		}
208
			Iterator<TagListing> iterator = tagListings.iterator();
220
		Iterator<TagListing> iterator = tagListings.iterator();
209
			while (iterator.hasNext()) {
221
		while (iterator.hasNext()) {
210
				TagListing tagListing = iterator.next();
222
			TagListing tagListing = iterator.next();
211
				LOGGER.info(" tagListing.setAllocatedQuantity {}", tagListing.getAllocatedQuantity());
223
			LOGGER.info(" tagListing.setAllocatedQuantity {}", tagListing.getAllocatedQuantity());
212
				Item item = itemRepository.selectById(tagListing.getItemId());
224
			Item item = itemRepository.selectById(tagListing.getItemId());
-
 
225
			if (roleManager.isAdmin(roleIds)) {
213
				if (item.getBrand() == null || item.getCategoryId()==0) {
226
				if (item.getBrand() == null || item.getCategoryId() == 0) {
214
					iterator.remove();
227
					iterator.remove();
215
					continue;
228
					continue;
216
				}
229
				}
217
				StockAllocationModel stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
-
 
218
				LOGGER.info(" stockAllocationModel {}", stockAllocationModel);
-
 
219
				LOGGER.info(" tagListing.setAllocatedQuantity {}", tagListing.getAllocatedQuantity());
-
 
220
				if (stockAllocationModel != null) {
-
 
221
					tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
-
 
222
				} else {
230
			} else {
223
					tagListing.setAllocatedQuantity(0);
-
 
224
				}
-
 
225
				tagListing.setBrand(item.getBrand());
-
 
226
				tagListing.setItemDescription(item.getItemDescription());
231
				if(!itemCisMap.containsKey(tagListing.getItemId()) && itemStockAllocationMap.containsKey(tagListing.getItemId())) {
227
				if (item.getCategoryId() == 10006) {
232
					iterator.remove();
228
					tagListing.setCategoryId(item.getCategoryId());
233
					continue;
229
				}
234
				}
230
				LOGGER.info(" tagListing.setAllocatedQuantity {}", tagListing.getAllocatedQuantity());
-
 
231
			}
235
			}
232
 
-
 
233
			Map<Integer, List<TagListing>> performanceMap = tagListings.stream()
236
			StockAllocationModel stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
234
					.collect(Collectors.groupingBy(x -> x.getCategoryId()));
237
			LOGGER.info(" stockAllocationModel {}", stockAllocationModel);
235
			List<TagListing> accsListing = performanceMap.get(0);
-
 
236
			List<TagListing> mobileListing = performanceMap.get(10006);
-
 
237
 
-
 
238
			Map<String, DoubleSummaryStatistics> accsStats = accsListing.stream().collect(Collectors.groupingBy(
-
 
239
					x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
-
 
240
			Map<String, DoubleSummaryStatistics> mobStats = mobileListing.stream().collect(Collectors.groupingBy(
-
 
241
					x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
238
			LOGGER.info(" tagListing.setAllocatedQuantity {}", tagListing.getAllocatedQuantity());
242
 
-
 
243
			for (Map.Entry<String, DoubleSummaryStatistics> entry : mobStats.entrySet()) {
-
 
244
				DoubleSummaryStatistics dss = entry.getValue();
239
			if (stockAllocationModel != null) {
245
				BrandPerformance bp = new BrandPerformance();
240
				tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
246
				bp.setTarget((float) dss.getSum());
241
			} else {
247
				bp.setBrandName(entry.getKey());
242
				tagListing.setAllocatedQuantity(0);
248
				brandPerformanceList.add(bp);
-
 
249
			}
243
			}
250
			for (Map.Entry<String, DoubleSummaryStatistics> entry : accsStats.entrySet()) {
-
 
251
				DoubleSummaryStatistics dss = entry.getValue();
244
			tagListing.setBrand(item.getBrand());
252
				BrandPerformance bp = new BrandPerformance();
245
			tagListing.setItemDescription(item.getItemDescription());
253
				bp.setTarget((float) dss.getSum());
246
			if (item.getCategoryId() == 10006) {
254
				bp.setBrandName(entry.getKey());
247
				tagListing.setCategoryId(item.getCategoryId());
255
				accsBrandPerformanceList.add(bp);
-
 
256
			}
248
			}
257
			brandPerformanceList = brandPerformanceList.stream().filter(x->x.getTarget()>0).sorted((BrandPerformance o1, BrandPerformance o2)->(int)(o1.getTarget() - o2.getTarget())).collect(Collectors.toList());
249
			LOGGER.info(" tagListing.setAllocatedQuantity {}", tagListing.getAllocatedQuantity());
258
			accsBrandPerformanceList = accsBrandPerformanceList.stream().filter(x->x.getTarget()>0).sorted((BrandPerformance o1, BrandPerformance o2)->(int)(o1.getTarget() - o2.getTarget())).collect(Collectors.toList());
-
 
259
			
250
		}
260
 
251
 
-
 
252
		Map<Integer, List<TagListing>> performanceMap = tagListings.stream()
-
 
253
				.collect(Collectors.groupingBy(x -> x.getCategoryId()));
-
 
254
		List<TagListing> accsListing = performanceMap.get(0);
-
 
255
		List<TagListing> mobileListing = performanceMap.get(10006);
-
 
256
 
-
 
257
		Map<String, DoubleSummaryStatistics> accsStats = accsListing.stream().collect(Collectors.groupingBy(
-
 
258
				x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
-
 
259
		Map<String, DoubleSummaryStatistics> mobStats = mobileListing.stream().collect(Collectors.groupingBy(
-
 
260
				x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
-
 
261
 
-
 
262
		for (Map.Entry<String, DoubleSummaryStatistics> entry : mobStats.entrySet()) {
-
 
263
			DoubleSummaryStatistics dss = entry.getValue();
-
 
264
			BrandPerformance bp = new BrandPerformance();
-
 
265
			bp.setTarget((float) dss.getSum());
-
 
266
			bp.setBrandName(entry.getKey());
-
 
267
			brandPerformanceList.add(bp);
-
 
268
		}
-
 
269
		for (Map.Entry<String, DoubleSummaryStatistics> entry : accsStats.entrySet()) {
-
 
270
			DoubleSummaryStatistics dss = entry.getValue();
-
 
271
			BrandPerformance bp = new BrandPerformance();
-
 
272
			bp.setTarget((float) dss.getSum());
-
 
273
			bp.setBrandName(entry.getKey());
-
 
274
			accsBrandPerformanceList.add(bp);
-
 
275
		}
-
 
276
		brandPerformanceList = brandPerformanceList.stream().filter(x -> x.getTarget() > 0)
-
 
277
				.sorted((BrandPerformance o1, BrandPerformance o2) -> (int) (o1.getTarget() - o2.getTarget()))
-
 
278
				.collect(Collectors.toList());
-
 
279
		accsBrandPerformanceList = accsBrandPerformanceList.stream().filter(x -> x.getTarget() > 0)
-
 
280
				.sorted((BrandPerformance o1, BrandPerformance o2) -> (int) (o1.getTarget() - o2.getTarget()))
-
 
281
				.collect(Collectors.toList());
-
 
282
 
261
			List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
283
		List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
262
					.collect(Collectors.toList());
284
				.collect(Collectors.toList());
263
			model.addAttribute("tagListings", tagListings);
285
		model.addAttribute("tagListings", tagListings);
264
			Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
286
		Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
265
			if (fofoId > 0) {
287
		if (fofoId > 0) {
266
				CustomRetailer customRetailer = customRetailersMap.get(fofoId);
288
			CustomRetailer customRetailer = customRetailersMap.get(fofoId);
267
				model.addAttribute("retailerName",
289
			model.addAttribute("retailerName",
268
						customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
290
					customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
269
				FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
291
			FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
270
				model.addAttribute("retailerId", customRetailer.getPartnerId());
292
			model.addAttribute("retailerId", customRetailer.getPartnerId());
271
				model.addAttribute("counterSize", fs.getCounterSize().toString());
293
			model.addAttribute("counterSize", fs.getCounterSize().toString());
272
			} else {
-
 
273
				model.addAttribute("counterSize", counterSize.toString());
-
 
274
			}
-
 
275
			String customRetailers = JSONObject.valueToString(customRetailersMap.values());
-
 
276
			LOGGER.info("Custom retailers {}", customRetailers);
-
 
277
			model.addAttribute("customRetailers", customRetailers);
-
 
278
			model.addAttribute("brandPerformanceList", brandPerformanceList);
-
 
279
			model.addAttribute("accsBrandPerformanceList", accsBrandPerformanceList);
-
 
280
			model.addAttribute("counterSizes", CounterSize.values());
-
 
281
			return "open-indent";
-
 
282
		} else {
294
		} else {
283
			throw new ProfitMandiBusinessException("Unauthorised", cookiesProcessor.getCookiesObject(request).getEmailId(),
-
 
284
					"Can't access the resource");
295
			model.addAttribute("counterSize", counterSize.toString());
285
		}
296
		}
-
 
297
		String customRetailers = JSONObject.valueToString(customRetailersMap.values());
-
 
298
		LOGGER.info("Custom retailers {}", customRetailers);
-
 
299
		model.addAttribute("customRetailers", customRetailers);
-
 
300
		model.addAttribute("brandPerformanceList", brandPerformanceList);
-
 
301
		model.addAttribute("accsBrandPerformanceList", accsBrandPerformanceList);
-
 
302
		model.addAttribute("counterSizes", CounterSize.values());
-
 
303
		model.addAttribute("itemCisMap", itemCisMap);
-
 
304
		return "open-indent";
286
	}
305
	}
287
}
306
}