Subversion Repositories SmartDukaan

Rev

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

Rev 25732 Rev 25736
Line 36... Line 36...
36
import org.springframework.web.bind.annotation.RequestBody;
36
import org.springframework.web.bind.annotation.RequestBody;
37
import org.springframework.web.bind.annotation.RequestMapping;
37
import org.springframework.web.bind.annotation.RequestMapping;
38
import org.springframework.web.bind.annotation.RequestMethod;
38
import org.springframework.web.bind.annotation.RequestMethod;
39
import org.springframework.web.bind.annotation.RequestParam;
39
import org.springframework.web.bind.annotation.RequestParam;
40
 
40
 
-
 
41
import com.mongodb.DBObject;
41
import com.spice.profitmandi.common.enumuration.CounterSize;
42
import com.spice.profitmandi.common.enumuration.CounterSize;
42
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
43
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
44
import com.spice.profitmandi.common.model.BrandStockPrice;
43
import com.spice.profitmandi.common.model.CatalogListingModel;
45
import com.spice.profitmandi.common.model.CatalogListingModel;
44
import com.spice.profitmandi.common.model.CustomRetailer;
46
import com.spice.profitmandi.common.model.CustomRetailer;
45
import com.spice.profitmandi.common.model.ItemIdAvailability;
47
import com.spice.profitmandi.common.model.ItemIdAvailability;
46
import com.spice.profitmandi.common.model.PlannedModel;
48
import com.spice.profitmandi.common.model.PlannedModel;
47
import com.spice.profitmandi.common.model.StockAllocationModel;
49
import com.spice.profitmandi.common.model.StockAllocationModel;
Line 59... Line 61...
59
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
61
import com.spice.profitmandi.dao.repository.catalog.FocusedModelRepository;
60
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
62
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
61
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
63
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
62
import com.spice.profitmandi.dao.repository.cs.CsService;
64
import com.spice.profitmandi.dao.repository.cs.CsService;
63
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
65
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
66
import com.spice.profitmandi.dao.repository.dtr.Mongo;
64
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
67
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
65
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
68
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
66
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
69
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
67
import com.spice.profitmandi.dao.repository.fofo.MonthlyPlannedRepository;
70
import com.spice.profitmandi.dao.repository.fofo.MonthlyPlannedRepository;
68
import com.spice.profitmandi.dao.repository.fofo.PlannedDetailRepository;
71
import com.spice.profitmandi.dao.repository.fofo.PlannedDetailRepository;
69
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
72
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
70
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
73
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
71
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
74
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
72
import com.spice.profitmandi.dao.repository.user.UserRepository;
75
import com.spice.profitmandi.dao.repository.user.UserRepository;
73
import com.spice.profitmandi.service.authentication.RoleManager;
76
import com.spice.profitmandi.service.authentication.RoleManager;
-
 
77
import com.spice.profitmandi.service.inventory.InventoryService;
74
import com.spice.profitmandi.service.inventory.StockAllocationService;
78
import com.spice.profitmandi.service.inventory.StockAllocationService;
75
import com.spice.profitmandi.service.user.RetailerService;
79
import com.spice.profitmandi.service.user.RetailerService;
76
import com.spice.profitmandi.service.wallet.WalletService;
80
import com.spice.profitmandi.service.wallet.WalletService;
77
import com.spice.profitmandi.thrift.clients.PaymentClient;
81
import com.spice.profitmandi.thrift.clients.PaymentClient;
78
import com.spice.profitmandi.thrift.clients.TransactionClient;
82
import com.spice.profitmandi.thrift.clients.TransactionClient;
Line 173... Line 177...
173
 
177
 
174
	@Autowired
178
	@Autowired
175
	RoleManager roleManager;
179
	RoleManager roleManager;
176
 
180
 
177
	@Autowired
181
	@Autowired
-
 
182
	private Mongo mongoClient;
-
 
183
 
-
 
184
	@Autowired
-
 
185
	private InventoryService inventoryService;
-
 
186
 
-
 
187
	@Autowired
178
	CsService csService;
188
	CsService csService;
179
 
189
 
180
	/*
190
	/*
181
	 * @RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
191
	 * @RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
182
	 * public String saveOpenIndent(HttpServletRequest request, Model model,
192
	 * public String saveOpenIndent(HttpServletRequest request, Model model,
Line 432... Line 442...
432
	}
442
	}
433
 
443
 
434
	@RequestMapping(value = "/indent/loadIndent")
444
	@RequestMapping(value = "/indent/loadIndent")
435
	public String loadOpenIndent(HttpServletRequest request, Model model,
445
	public String loadOpenIndent(HttpServletRequest request, Model model,
436
			@RequestParam(required = false, defaultValue = "0") int fofoId,
446
			@RequestParam(required = false, defaultValue = "0") int fofoId,
437
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws ProfitMandiBusinessException {
447
			@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
438
 
448
 
439
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
449
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
440
		Set<Integer> roleIds = loginDetails.getRoleIds();
450
		Set<Integer> roleIds = loginDetails.getRoleIds();
441
		LOGGER.info("Counter size is {}", counterSize);
451
		LOGGER.info("Counter size is {}", counterSize);
442
		LOGGER.info("Fofo Id is {}", fofoId);
452
		LOGGER.info("Fofo Id is {}", fofoId);
443
		boolean isAdmin = !roleManager.isAdmin(roleIds);
453
		boolean isAdmin = roleManager.isAdmin(roleIds);
444
		Map<Integer, ItemIdAvailability> itemCisMap = null;
454
		Map<Integer, Integer> itemCisMap;
445
		if (!isAdmin && fofoId == 0) {
455
		if (!isAdmin && fofoId == 0) {
446
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
456
			fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
447
			List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
457
			List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
448
					.selectItemsStock(fofoId);
458
					.selectItemsStock(fofoId);
-
 
459
			LOGGER.info("currentInventorySnapshots" + currentInventorySnapshots);
449
			itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
460
			itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
450
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
461
					.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
-
 
462
 
451
		} else {
463
		} else {
452
			if (fofoId == 0) {
464
			if (fofoId == 0) {
453
				List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
465
				List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
454
						.selectItemsStock();
466
						.selectItemsStock();
-
 
467
				LOGGER.info("currentInventorySnapshots2" + currentInventorySnapshots);
455
				itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
468
				itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
456
						.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
469
						.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
457
			} else {
470
			} else {
458
				List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
471
				List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
459
						.selectItemsStock(fofoId);
472
						.selectItemsStock(fofoId);
-
 
473
				LOGGER.info("currentInventorySnapshots3" + currentInventorySnapshots);
460
				itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
474
				itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
461
						.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
475
						.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
462
			}
476
			}
463
		}
477
		}
-
 
478
		Map<Integer, Integer> currentStock = null;
-
 
479
		if (!itemCisMap.isEmpty()) {
-
 
480
			currentStock = itemRepository.selectByIds(itemCisMap.keySet()).stream().collect(Collectors
-
 
481
					.groupingBy(x -> x.getCatalogItemId(), Collectors.summingInt(x -> itemCisMap.get(x.getId()))));
464
 
482
		}
465
		List<StockAllocationModel> stockAllocationList;
483
		List<StockAllocationModel> stockAllocationList;
466
		if (fofoId > 0) {
484
		if (fofoId > 0) {
467
			stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
485
			stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
468
		} else {
486
		} else {
469
			stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
487
			stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
Line 522... Line 540...
522
			TagListing tagListing = iterator.next();
540
			TagListing tagListing = iterator.next();
523
 
541
 
524
			Item item = items.get(tagListing.getItemId());
542
			Item item = items.get(tagListing.getItemId());
525
			// itemRepository.select
543
			// itemRepository.select
526
			// catalogTagListingMap
544
			// catalogTagListingMap
527
			if (isAdmin) {
-
 
-
 
545
 
528
				if (item.getBrand() == null || item.getCategoryId() != 10006) {
546
			if (item.getBrand() == null || item.getCategoryId() != 10006) {
529
					iterator.remove();
-
 
530
					continue;
-
 
531
				}
-
 
532
			} else {
-
 
533
				if (!(itemCisMap.containsKey(tagListing.getItemId())
-
 
534
						|| itemStockAllocationMap.containsKey(tagListing.getItemId()))) {
-
 
535
					iterator.remove();
547
				iterator.remove();
536
					continue;
548
				continue;
537
				}
-
 
538
			}
549
			}
539
 
550
 
540
			int catalogId = item.getCatalogItemId();
551
			int catalogId = item.getCatalogItemId();
541
 
552
 
542
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
553
			CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
Line 589... Line 600...
589
				}
600
				}
590
 
601
 
591
				catalogListingMap.put(catalogId, catalogListingModel);
602
				catalogListingMap.put(catalogId, catalogListingModel);
592
 
603
 
593
			}
604
			}
594
 
-
 
-
 
605
			int itemAvailability = 0;
-
 
606
			if (currentStock != null) {
595
			ItemIdAvailability itemIdAvailability = itemCisMap.get(tagListing.getItemId());
607
				Integer qty = currentStock.get(catalogId);
596
			int itemAvailability = itemIdAvailability == null ? 0 : itemIdAvailability.getAvailability();
608
				itemAvailability = qty == null ? 0 : qty;
597
			catalogListingModel.setStockInHand(catalogListingModel.getStockInHand() + itemAvailability);
609
				catalogListingModel.setStockInHand(itemAvailability);
-
 
610
			} else {
-
 
611
				catalogListingModel.setStockInHand(0);
598
 
612
			}
599
			Integer inTransitQuantity = itemsInTransit.get(item.getId());
613
			Integer inTransitQuantity = itemsInTransit.get(item.getId());
600
			int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
614
			int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
601
			catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
615
			catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
602
 
616
 
603
			if (catalogListingModel.getAllocatedQuantity() > 0) {
617
			if (catalogListingModel.getAllocatedQuantity() > 0) {
Line 626... Line 640...
626
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
640
		Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getMinimumQty,
627
				Comparator.reverseOrder());
641
				Comparator.reverseOrder());
628
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
642
		LOGGER.info("monthlyPlanned" + monthlyPlanned);
629
		model.addAttribute("catalogTagListings", catalogModel.stream().sorted(firstCmp).collect(Collectors.toList()));
643
		model.addAttribute("catalogTagListings", catalogModel.stream().sorted(firstCmp).collect(Collectors.toList()));
630
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
644
		model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
-
 
645
		model.addAttribute("brandStockPrices",this.getBrandStockPrices(loginDetails.getFofoId()));
631
		model.addAttribute("customRetailers", customRetailers);
646
		model.addAttribute("customRetailers", customRetailers);
632
		model.addAttribute("totalAmount", totalAmount);
647
		model.addAttribute("totalAmount", totalAmount);
633
		model.addAttribute("monthlyPlanned", monthlyPlanned);
648
		model.addAttribute("monthlyPlanned", monthlyPlanned);
634
		model.addAttribute("totalPcs", totalPcs);
649
		model.addAttribute("totalPcs", totalPcs);
635
		return "open-indent";
650
		return "open-indent";
Line 806... Line 821...
806
	@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
821
	@RequestMapping(value = "/getFocusedModel", method = RequestMethod.GET)
807
	public String getFocusedModel(HttpServletRequest request,
822
	public String getFocusedModel(HttpServletRequest request,
808
			@RequestParam(name = "offset", defaultValue = "0") int offset,
823
			@RequestParam(name = "offset", defaultValue = "0") int offset,
809
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
824
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
810
			throws ProfitMandiBusinessException {
825
			throws ProfitMandiBusinessException {
-
 
826
 
-
 
827
		long size = 0;
811
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
828
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
-
 
829
		size = focusedModelRepository.selectAllCount();
-
 
830
 
-
 
831
		if (!focusedModels.isEmpty()) {
-
 
832
			Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
-
 
833
 
-
 
834
			model.addAttribute("focusedModels", focusedModels);
-
 
835
			model.addAttribute("itemMap", itemMap);
812
 
836
 
-
 
837
			model.addAttribute("start", offset + 1);
-
 
838
			model.addAttribute("size", size);
813
		Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
839
			model.addAttribute("url", "/getPaginatedFocusedModel");
814
 
840
 
-
 
841
			if (focusedModels.size() < limit) {
-
 
842
				model.addAttribute("end", offset + focusedModels.size());
-
 
843
			} else {
-
 
844
				model.addAttribute("end", offset + limit);
-
 
845
			}
-
 
846
		} else {
-
 
847
 
815
		model.addAttribute("focusedModels", focusedModels);
848
			model.addAttribute("walletRequest", focusedModels);
816
		model.addAttribute("itemMap", itemMap);
849
			model.addAttribute("size", size);
-
 
850
 
-
 
851
		}
817
 
852
 
818
		return "focused_model";
853
		return "focused_model";
819
	}
854
	}
820
 
855
 
-
 
856
	@RequestMapping(value = "/getPaginatedFocusedModel", method = RequestMethod.GET)
-
 
857
	public String getPaginatedFocusedModel(HttpServletRequest request,
-
 
858
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
859
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
-
 
860
			throws ProfitMandiBusinessException {
-
 
861
		LOGGER.info("requested offset=[{}], limit = [{}]", offset, limit);
-
 
862
		List<FocusedModel> focusedModels = focusedModelRepository.selectAll(offset, limit);
-
 
863
 
-
 
864
		if (!focusedModels.isEmpty()) {
-
 
865
			Map<Integer, Item> itemMap = this.getItemByCatalogId(focusedModels);
-
 
866
 
-
 
867
			model.addAttribute("focusedModels", focusedModels);
-
 
868
			model.addAttribute("itemMap", itemMap);
-
 
869
 
-
 
870
			model.addAttribute("url", "/getPaginatedFocusedModel");
-
 
871
		} else {
-
 
872
			model.addAttribute("focusedModels", focusedModels);
-
 
873
 
-
 
874
		}
-
 
875
		return "focused-model-paginated";
-
 
876
	}
-
 
877
 
821
	private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
878
	private Map<Integer, Item> getItemByCatalogId(List<FocusedModel> focusedModels) {
822
		Map<Integer, Item> itemMap = new HashMap<>();
879
		Map<Integer, Item> itemMap = new HashMap<>();
823
		for (FocusedModel focusedModel : focusedModels) {
880
		for (FocusedModel focusedModel : focusedModels) {
824
			List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
881
			List<Item> items = itemRepository.selectAllByCatalogItemId(focusedModel.getCatalogId());
825
			itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
882
			itemMap.put(items.get(0).getCatalogItemId(), items.get(0));
Line 847... Line 904...
847
 
904
 
848
		focusedModelRepository.deleteById(catalogId);
905
		focusedModelRepository.deleteById(catalogId);
849
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
906
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
850
		return "response";
907
		return "response";
851
	}
908
	}
-
 
909
 
-
 
910
	private List<BrandStockPrice> getBrandStockPrices(int fofoId) throws Exception {
-
 
911
		Map<String, BrandStockPrice> brandStockPricesMap = inventoryService.getBrandWiseStockValue(fofoId);
-
 
912
 
-
 
913
		List<DBObject> mobileBrands = mongoClient.getMongoBrands(fofoId, "", 3);
-
 
914
		List<BrandStockPrice> brandStockPrices = new ArrayList<>();
-
 
915
 
-
 
916
		mobileBrands.stream().forEach(x -> {
-
 
917
			String brand = (String) x.get("name");
-
 
918
			if (brandStockPricesMap.containsKey(brand)) {
-
 
919
				BrandStockPrice brandStockPrice = brandStockPricesMap.get(brand);
-
 
920
				brandStockPrice.setBrandUrl((String) x.get("url"));
-
 
921
				brandStockPrice.setRank(((Double) x.get("rank")).intValue());
-
 
922
				brandStockPrices.add(brandStockPrice);
-
 
923
			}
-
 
924
		});
-
 
925
 
-
 
926
		return brandStockPrices.stream().filter(x -> x.getTotalQty() > 0).sorted((x, y) -> x.getRank() - y.getRank())
-
 
927
				.collect(Collectors.toList());
-
 
928
	}
-
 
929
 
852
}
930
}
853
931