Subversion Repositories SmartDukaan

Rev

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

Rev 26897 Rev 26924
Line 61... Line 61...
61
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
61
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoDetailRepository;
62
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
62
import com.spice.profitmandi.dao.repository.fofo.SuggestedPoRepository;
63
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
63
import com.spice.profitmandi.dao.repository.inventory.ItemAvailabilityCacheRepository;
64
import com.spice.profitmandi.service.authentication.RoleManager;
64
import com.spice.profitmandi.service.authentication.RoleManager;
65
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
65
import com.spice.profitmandi.service.inventory.AvailabilityInfo;
-
 
66
import com.spice.profitmandi.service.inventory.AvailabilityModel;
66
import com.spice.profitmandi.service.inventory.Bucket;
67
import com.spice.profitmandi.service.inventory.Bucket;
67
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
68
import com.spice.profitmandi.service.inventory.FofoAvailabilityInfo;
68
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
69
import com.spice.profitmandi.service.inventory.FofoCatalogResponse;
-
 
70
import com.spice.profitmandi.service.inventory.InventoryService;
69
import com.spice.profitmandi.service.inventory.ItemBucketService;
71
import com.spice.profitmandi.service.inventory.ItemBucketService;
70
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
72
import com.spice.profitmandi.service.inventory.ItemQuantityPojo;
71
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
73
import com.spice.profitmandi.service.inventory.SaholicInventoryService;
72
import com.spice.profitmandi.service.pricing.PricingService;
74
import com.spice.profitmandi.service.pricing.PricingService;
73
import com.spice.profitmandi.service.scheme.SchemeService;
75
import com.spice.profitmandi.service.scheme.SchemeService;
Line 95... Line 97...
95
	private int port;
97
	private int port;
96
 
98
 
97
	@Autowired
99
	@Autowired
98
	RestClient restClient;
100
	RestClient restClient;
99
 
101
 
-
 
102
	@Autowired
-
 
103
	InventoryService inventoryService;
-
 
104
 
100
	// This is now unused as we are not supporting multiple companies.
105
	// This is now unused as we are not supporting multiple companies.
101
	@Value("${gadgetCops.invoice.cc}")
106
	@Value("${gadgetCops.invoice.cc}")
102
	private String[] ccGadgetCopInvoiceTo;
107
	private String[] ccGadgetCopInvoiceTo;
103
 
108
 
104
	@Autowired
109
	@Autowired
Line 586... Line 591...
586
		return responseSender.ok(responseObject);
591
		return responseSender.ok(responseObject);
587
	}
592
	}
588
 
593
 
589
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
594
	private List<FofoCatalogResponse> getCatalogResponse(JSONArray docs, boolean hotDeal, int fofoId)
590
			throws ProfitMandiBusinessException {
595
			throws ProfitMandiBusinessException {
591
		Map<Integer, Integer> ourItemAvailabilityMap = null;
-
 
592
		Map<Integer, Integer> partnerStockAvailabilityMap = null;
-
 
593
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
596
		List<FofoCatalogResponse> dealResponse = new ArrayList<>();
594
		List<Integer> tagIds = Arrays.asList(4);
597
		List<Integer> tagIds = Arrays.asList(4);
-
 
598
		List<Integer> itemIds = new ArrayList<>();
595
		if (docs.length() > 0) {
599
		if (docs.length() > 0) {
596
			HashSet<Integer> itemsSet = new HashSet<>();
-
 
597
			for (int i = 0; i < docs.length(); i++) {
600
			for (int i = 0; i < docs.length(); i++) {
598
				JSONObject doc = docs.getJSONObject(i);
601
				JSONObject doc = docs.getJSONObject(i);
599
				if (doc.has("_childDocuments_")) {
602
				if (doc.has("_childDocuments_")) {
600
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
603
					for (int j = 0; j < doc.getJSONArray("_childDocuments_").length(); j++) {
601
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
604
						JSONObject childItem = doc.getJSONArray("_childDocuments_").getJSONObject(j);
602
						int itemId = childItem.getInt("itemId_i");
605
						int itemId = childItem.getInt("itemId_i");
603
						itemsSet.add(itemId);
606
						itemIds.add(itemId);
604
					}
607
					}
605
				}
608
				}
606
			}
609
			}
607
			if (itemsSet.size() == 0) {
610
			if (itemIds.size() == 0) {
608
				return dealResponse;
611
				return dealResponse;
609
			}
612
			}
610
			if (hotDeal) {
-
 
611
				ourItemAvailabilityMap = saholicInventoryService
-
 
612
						.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
-
 
613
			} else if (fofoId > 0) {
-
 
614
				partnerStockAvailabilityMap = currentInventorySnapshotRepository.selectItemsStock(fofoId).stream()
-
 
615
						.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getAvailability()));
-
 
616
				ourItemAvailabilityMap = saholicInventoryService
-
 
617
						.getTotalAvailabilityByItemIds(new ArrayList<>(itemsSet));
-
 
618
			}
-
 
619
		}
613
		}
-
 
614
		
-
 
615
		Map<Integer, AvailabilityModel> itemAvailabilityMap = inventoryService.getStoreAndOurStock(fofoId, itemIds);
620
 
616
		
621
		for (int i = 0; i < docs.length(); i++) {
617
		for (int i = 0; i < docs.length(); i++) {
622
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
618
			Map<Integer, FofoAvailabilityInfo> fofoAvailabilityInfoMap = new HashMap<>();
623
			JSONObject doc = docs.getJSONObject(i);
619
			JSONObject doc = docs.getJSONObject(i);
624
			FofoCatalogResponse ffdr = new FofoCatalogResponse();
620
			FofoCatalogResponse ffdr = new FofoCatalogResponse();
625
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
621
			ffdr.setCatalogId(doc.getInt("catalogId_i"));
Line 642... Line 638...
642
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
638
							fofoAvailabilityInfoMap.get(itemId).setSellingPrice(sellingPrice);
643
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
639
							fofoAvailabilityInfoMap.get(itemId).setMop((float) childItem.getDouble("mop_f"));
644
						}
640
						}
645
					} else {
641
					} else {
646
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
642
						FofoAvailabilityInfo fdi = new FofoAvailabilityInfo();
-
 
643
						AvailabilityModel currentAvailability = itemAvailabilityMap.get(itemId);
647
						fdi.setSellingPrice(sellingPrice);
644
						fdi.setSellingPrice(sellingPrice);
648
						fdi.setActive(childItem.getBoolean("active_b"));
645
						fdi.setActive(childItem.getBoolean("active_b"));
649
						fdi.setMrp(childItem.getDouble("mrp_f"));
646
						fdi.setMrp(childItem.getDouble("mrp_f"));
650
						fdi.setMop((float) childItem.getDouble("mop_f"));
647
						fdi.setMop((float) childItem.getDouble("mop_f"));
651
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
648
						fdi.setColor(childItem.has("color_s") ? childItem.getString("color_s") : "");
Line 654... Line 651...
654
						Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
651
						Float cashBack = schemeService.getItemSchemeCashBack().get(itemId);
655
						cashBack = cashBack == null ? 0 : cashBack;
652
						cashBack = cashBack == null ? 0 : cashBack;
656
						fdi.setCashback(cashBack);
653
						fdi.setCashback(cashBack);
657
						fdi.setMinBuyQuantity(1);
654
						fdi.setMinBuyQuantity(1);
658
						if (hotDeal) {
655
						if (hotDeal) {
659
							try {
-
 
660
								int totalAvailability = ourItemAvailabilityMap.get(itemId);
-
 
661
								if (totalAvailability <= 0) {
-
 
662
									continue;
-
 
663
								}
-
 
664
								fdi.setAvailability(ourItemAvailabilityMap.get(itemId));
656
							fdi.setAvailability(currentAvailability.getWarehouseAvailability());
665
							} catch (Exception e) {
-
 
666
								continue;
-
 
667
							}
-
 
668
						} else if (fofoId == 0) {
657
						} else if (fofoId == 0) {
669
							// For accessories item availability should at be ordered for Rs.1000
658
							// For accessories item availability should at be ordered for Rs.1000
670
							fdi.setAvailability(100);
659
							fdi.setAvailability(100);
671
							Item item = itemRepository.selectById(itemId);
660
							Item item = itemRepository.selectById(itemId);
672
							// In case its tampered glass moq should be 5
661
							// In case its tampered glass moq should be 5
673
							if (item.getCategoryId() == 10020) {
662
							if (item.getCategoryId() == 10020) {
674
								fdi.setMinBuyQuantity(5);
663
								fdi.setMinBuyQuantity(5);
675
							}
664
							}
676
						} else {
665
						} else {
677
							int ourStockAvailability = ourItemAvailabilityMap.get(itemId) == null ? 0
-
 
678
									: ourItemAvailabilityMap.get(itemId);
-
 
679
							int partnerAvailability = partnerStockAvailabilityMap.get(itemId) == null ? 0
-
 
680
									: partnerStockAvailabilityMap.get(itemId);
-
 
681
							fdi.setAvailability(ourStockAvailability + partnerAvailability);
666
							fdi.setAvailability(currentAvailability.getMaxAvailability());
682
						}
667
						}
683
						fdi.setQuantityStep(1);
668
						fdi.setQuantityStep(1);
684
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
669
						fdi.setMaxQuantity(Math.min(fdi.getAvailability(), 100));
685
						fofoAvailabilityInfoMap.put(itemId, fdi);
670
						fofoAvailabilityInfoMap.put(itemId, fdi);
686
					}
671
					}