| Line 12... |
Line 12... |
| 12 |
import java.util.Set;
|
12 |
import java.util.Set;
|
| 13 |
import java.util.Map.Entry;
|
13 |
import java.util.Map.Entry;
|
| 14 |
import java.util.stream.Collectors;
|
14 |
import java.util.stream.Collectors;
|
| 15 |
|
15 |
|
| 16 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
|
16 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCISTable;
|
| 17 |
import com.spice.profitmandi.dao.enumuration.fofo.Milestone;
|
- |
|
| 18 |
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
|
17 |
import com.spice.profitmandi.dao.repository.inventory.SaholicCISTableRepository;
|
| - |
|
18 |
import com.spice.profitmandi.dao.repository.warehouse.BrandRegionMappingRepository;
|
| 19 |
import org.apache.logging.log4j.LogManager;
|
19 |
import org.apache.logging.log4j.LogManager;
|
| 20 |
import org.apache.logging.log4j.Logger;
|
20 |
import org.apache.logging.log4j.Logger;
|
| 21 |
import org.springframework.beans.factory.annotation.Autowired;
|
21 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 22 |
import org.springframework.stereotype.Component;
|
22 |
import org.springframework.stereotype.Component;
|
| 23 |
|
23 |
|
| Line 25... |
Line 25... |
| 25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 26 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
26 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 27 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
27 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 28 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
28 |
import com.spice.profitmandi.dao.entity.cs.PartnerRegion;
|
| 29 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
29 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 30 |
import com.spice.profitmandi.dao.entity.inventory.SaholicCIS;
|
- |
|
| 31 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
30 |
import com.spice.profitmandi.dao.entity.user.Cart;
|
| 32 |
import com.spice.profitmandi.dao.entity.user.CartLine;
|
31 |
import com.spice.profitmandi.dao.entity.user.CartLine;
|
| 33 |
import com.spice.profitmandi.dao.entity.user.User;
|
32 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 34 |
import com.spice.profitmandi.dao.model.CartItem;
|
33 |
import com.spice.profitmandi.dao.model.CartItem;
|
| 35 |
import com.spice.profitmandi.dao.model.CartItemResponseModel;
|
34 |
import com.spice.profitmandi.dao.model.CartItemResponseModel;
|
| Line 52... |
Line 51... |
| 52 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
51 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 53 |
|
52 |
|
| 54 |
@Component
|
53 |
@Component
|
| 55 |
public class CartServiceImpl implements CartService {
|
54 |
public class CartServiceImpl implements CartService {
|
| 56 |
|
55 |
|
| 57 |
private static final Set<Integer> tagIds = new HashSet<>(Arrays.asList(4));
|
56 |
private static final Set<Integer> tagIds = new HashSet<>(Arrays.asList(4));
|
| 58 |
|
57 |
|
| 59 |
private static final Logger logger = LogManager.getLogger(CartServiceImpl.class);
|
58 |
private static final Logger logger = LogManager.getLogger(CartServiceImpl.class);
|
| 60 |
|
59 |
|
| 61 |
private static final Map<Integer, List<Integer>> focusedModelVariantMap = new HashMap<>();
|
60 |
private static final Map<Integer, List<Integer>> focusedModelVariantMap = new HashMap<>();
|
| 62 |
|
61 |
|
| 63 |
@Autowired
|
62 |
@Autowired
|
| 64 |
CartRepository cartRepository;
|
63 |
CartRepository cartRepository;
|
| 65 |
|
64 |
|
| 66 |
@Autowired
|
65 |
@Autowired
|
| 67 |
CartLineRepository cartLineRepository;
|
66 |
CartLineRepository cartLineRepository;
|
| 68 |
|
67 |
|
| 69 |
@Autowired
|
68 |
@Autowired
|
| 70 |
FofoStoreRepository fofoStoreRepository;
|
69 |
FofoStoreRepository fofoStoreRepository;
|
| 71 |
|
70 |
|
| 72 |
@Autowired
|
71 |
@Autowired
|
| 73 |
TagListingRepository tagListingRepository;
|
72 |
TagListingRepository tagListingRepository;
|
| 74 |
|
73 |
|
| 75 |
@Autowired
|
74 |
@Autowired
|
| 76 |
UserRepository saholicUserRepository;
|
75 |
SaholicInventoryService saholicInventoryService;
|
| 77 |
|
76 |
|
| 78 |
@Autowired
|
77 |
@Autowired
|
| 79 |
ItemRepository itemRepository;
|
78 |
UserRepository saholicUserRepository;
|
| 80 |
|
79 |
|
| 81 |
@Autowired
|
80 |
@Autowired
|
| 82 |
SaholicInventoryService saholicInventoryService;
|
81 |
ItemRepository itemRepository;
|
| 83 |
|
82 |
|
| 84 |
@Autowired
|
83 |
|
| 85 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
84 |
@Autowired
|
| 86 |
|
85 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 87 |
@Autowired
|
86 |
|
| 88 |
private FocusedModelRepository focusedModelRepository;
|
87 |
@Autowired
|
| 89 |
|
88 |
private FocusedModelRepository focusedModelRepository;
|
| 90 |
@Autowired
|
89 |
|
| 91 |
private PartnerRegionRepository partnerRegionRepository;
|
90 |
@Autowired
|
| 92 |
|
91 |
private PartnerRegionRepository partnerRegionRepository;
|
| 93 |
@Autowired
|
92 |
|
| 94 |
private TransactionService transactionService;
|
93 |
@Autowired
|
| 95 |
|
94 |
private TransactionService transactionService;
|
| 96 |
@Autowired
|
95 |
|
| 97 |
private RetailerBlockBrandsRepository retailerBlockBrandRepository;
|
96 |
@Autowired
|
| 98 |
|
97 |
private RetailerBlockBrandsRepository retailerBlockBrandRepository;
|
| 99 |
@Autowired
|
98 |
|
| 100 |
private OrderRepository orderRepository;
|
99 |
@Autowired
|
| 101 |
|
100 |
private OrderRepository orderRepository;
|
| 102 |
@Autowired
|
101 |
|
| 103 |
private NotificationService notificationService;
|
102 |
@Autowired
|
| 104 |
@Autowired
|
103 |
private NotificationService notificationService;
|
| 105 |
private SaholicCISTableRepository saholicCISTableRepository;
|
104 |
@Autowired
|
| 106 |
|
105 |
private SaholicCISTableRepository saholicCISTableRepository;
|
| 107 |
@Override
|
106 |
|
| 108 |
// Unused method
|
107 |
@Autowired
|
| 109 |
public CartModel addToCart(int cartId, int itemId, int quantity, float sellingPrice) {
|
108 |
private BrandRegionMappingRepository brandRegionMappingRepository;
|
| 110 |
CartLine cartItem = cartLineRepository.selectByCartItem(cartId, itemId);
|
109 |
|
| 111 |
if (cartItem == null) {
|
110 |
@Override
|
| 112 |
this.createCartItem(cartId, itemId, quantity, sellingPrice);
|
111 |
// Unused method
|
| 113 |
} else {
|
112 |
public CartModel addToCart(int cartId, int itemId, int quantity, float sellingPrice) {
|
| 114 |
cartItem.setQuantity(quantity);
|
113 |
CartLine cartItem = cartLineRepository.selectByCartItem(cartId, itemId);
|
| 115 |
cartItem.setActualPrice(sellingPrice);
|
114 |
if (cartItem == null) {
|
| 116 |
}
|
115 |
this.createCartItem(cartId, itemId, quantity, sellingPrice);
|
| 117 |
return null;
|
116 |
} else {
|
| 118 |
}
|
117 |
cartItem.setQuantity(quantity);
|
| 119 |
|
118 |
cartItem.setActualPrice(sellingPrice);
|
| 120 |
private void createCartItem(int cartId, int itemId, int quantity, float sellingPrice) {
|
119 |
}
|
| 121 |
CartLine cartLine = new CartLine();
|
120 |
return null;
|
| 122 |
cartLine.setActualPrice(sellingPrice);
|
121 |
}
|
| 123 |
cartLine.setCartId(cartId);
|
122 |
|
| 124 |
cartLine.setQuantity(quantity);
|
123 |
private void createCartItem(int cartId, int itemId, int quantity, float sellingPrice) {
|
| 125 |
// TODO: Estmiate Logic
|
124 |
CartLine cartLine = new CartLine();
|
| 126 |
cartLine.setEstimate(2);
|
125 |
cartLine.setActualPrice(sellingPrice);
|
| 127 |
cartLineRepository.persist(cartLine);
|
126 |
cartLine.setCartId(cartId);
|
| 128 |
|
127 |
cartLine.setQuantity(quantity);
|
| 129 |
}
|
128 |
// TODO: Estmiate Logic
|
| 130 |
|
129 |
cartLine.setEstimate(2);
|
| 131 |
@Override
|
130 |
cartLineRepository.persist(cartLine);
|
| 132 |
public boolean clearCart(int cartId) throws ProfitMandiBusinessException {
|
131 |
|
| 133 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
132 |
}
|
| 134 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
133 |
|
| 135 |
Cart cart = cartRepository.selectById(cartId);
|
134 |
@Override
|
| 136 |
|
135 |
public boolean clearCart(int cartId) throws ProfitMandiBusinessException {
|
| 137 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
136 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 138 |
cart.setCheckoutTimestamp(null);
|
137 |
cartLines.stream().forEach(cartLine -> cartLineRepository.delete(cartLine));
|
| 139 |
cart.setTotalPrice(0);
|
138 |
Cart cart = cartRepository.selectById(cartId);
|
| 140 |
cart.setWalletAmount(0);
|
139 |
|
| 141 |
return true;
|
140 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
| 142 |
}
|
141 |
cart.setCheckoutTimestamp(null);
|
| 143 |
|
142 |
cart.setTotalPrice(0);
|
| 144 |
@Override
|
143 |
cart.setWalletAmount(0);
|
| 145 |
public CartModel getCart(int cartId) {
|
144 |
return true;
|
| 146 |
// TODO Auto-generated method stub
|
145 |
}
|
| 147 |
return null;
|
146 |
|
| 148 |
}
|
147 |
@Override
|
| 149 |
|
148 |
public CartModel getCart(int cartId) {
|
| 150 |
// As of now it only works for Fofo Partners need to be refactored later
|
149 |
// TODO Auto-generated method stub
|
| 151 |
private Map<Integer, Integer> getAvailabilityMap(User user, Set<Integer> itemIds) {
|
150 |
return null;
|
| 152 |
Map<Integer, Integer> itemAvailabilityMap = new HashMap<>();
|
151 |
}
|
| 153 |
List<TagListing> tags = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
152 |
|
| 154 |
tags.stream().forEach(tagListing -> {
|
153 |
// As of now it only works for Fofo Partners need to be refactored later
|
| 155 |
if (!tagListing.isActive() || tagListing.isHotDeals()) {
|
154 |
private Map<Integer, Integer> getAvailabilityMap(User user, Set<Integer> itemIds) {
|
| 156 |
// show actual values here
|
155 |
Map<Integer, Integer> itemAvailabilityMap = new HashMap<>();
|
| 157 |
} else {
|
156 |
List<TagListing> tags = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
| 158 |
itemAvailabilityMap.put(tagListing.getItemId(), 100);
|
157 |
tags.stream().forEach(tagListing -> {
|
| 159 |
}
|
158 |
if (!tagListing.isActive() || tagListing.isHotDeals()) {
|
| 160 |
});
|
159 |
// show actual values here
|
| 161 |
return itemAvailabilityMap;
|
160 |
} else {
|
| 162 |
}
|
161 |
itemAvailabilityMap.put(tagListing.getItemId(), 100);
|
| 163 |
|
162 |
}
|
| 164 |
// As of now it only works for Fofo Partners need to be refactored later
|
163 |
});
|
| 165 |
private Map<Integer, Integer> getMinBuyQtyMap(User user, Set<Integer> itemIds) {
|
164 |
return itemAvailabilityMap;
|
| 166 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
165 |
}
|
| 167 |
return items.stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getCategoryId() == 10020 ? 1 : 10));
|
166 |
|
| 168 |
}
|
167 |
// As of now it only works for Fofo Partners need to be refactored later
|
| 169 |
|
168 |
private Map<Integer, Integer> getMinBuyQtyMap(User user, Set<Integer> itemIds) {
|
| 170 |
// As of now it only works for Fofo Partners need to be refactored later
|
169 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| 171 |
private Map<Integer, Float> getPriceMap(User user, Set<Integer> itemIds) {
|
170 |
return items.stream().collect(Collectors.toMap(x -> x.getId(), x -> x.getCategoryId() == 10020 ? 1 : 10));
|
| 172 |
List<TagListing> tags = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
171 |
}
|
| 173 |
return tags.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getSellingPrice()));
|
172 |
|
| 174 |
|
173 |
// As of now it only works for Fofo Partners need to be refactored later
|
| 175 |
}
|
174 |
private Map<Integer, Float> getPriceMap(User user, Set<Integer> itemIds) {
|
| 176 |
|
175 |
List<TagListing> tags = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
| 177 |
@Override
|
176 |
return tags.stream().collect(Collectors.toMap(x -> x.getItemId(), x -> x.getSellingPrice()));
|
| 178 |
public CartResponse getCartValidation(int cartId) throws ProfitMandiBusinessException {
|
177 |
|
| 179 |
/*
|
178 |
}
|
| 180 |
* # No need to validate duplicate items since there are only two ways # to add
|
179 |
|
| 181 |
* items to a cart and both of them check whether the item being # added is a
|
180 |
@Override
|
| 182 |
* duplicate of an already existing item.
|
181 |
public CartResponse getCartValidation(int cartId) throws ProfitMandiBusinessException {
|
| 183 |
*/
|
182 |
/*
|
| 184 |
|
183 |
* # No need to validate duplicate items since there are only two ways # to add
|
| 185 |
Cart cart = cartRepository.selectById(cartId);
|
184 |
* items to a cart and both of them check whether the item being # added is a
|
| 186 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
185 |
* duplicate of an already existing item.
|
| 187 |
|
186 |
*/
|
| 188 |
User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
187 |
|
| 189 |
|
188 |
Cart cart = cartRepository.selectById(cartId);
|
| 190 |
int totalQty = 0;
|
189 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 191 |
double totalAmount = 0;
|
190 |
|
| 192 |
CartResponse cartResponse = new CartResponse();
|
191 |
User saholicUser = saholicUserRepository.selectByCartId(cartId);
|
| 193 |
List<CartMessage> cartMessages = new ArrayList<>();
|
192 |
|
| 194 |
List<CartItemResponseModel> cartItemModels = new ArrayList<>();
|
193 |
int totalQty = 0;
|
| 195 |
cartResponse.setCartMessages(cartMessages);
|
194 |
double totalAmount = 0;
|
| 196 |
cartResponse.setCartItems(cartItemModels);
|
195 |
CartResponse cartResponse = new CartResponse();
|
| 197 |
|
196 |
List<CartMessage> cartMessages = new ArrayList<>();
|
| 198 |
int cartMessageChanged = 0;
|
197 |
List<CartItemResponseModel> cartItemModels = new ArrayList<>();
|
| 199 |
int cartMessageOOS = 0;
|
198 |
cartResponse.setCartMessages(cartMessages);
|
| 200 |
int cartMessageUndeliverable = 0;
|
199 |
cartResponse.setCartItems(cartItemModels);
|
| 201 |
|
200 |
|
| 202 |
Set<Integer> itemIds = cartLines.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
201 |
int cartMessageChanged = 0;
|
| 203 |
logger.info("iteme ids -- {}", itemIds);
|
202 |
int cartMessageOOS = 0;
|
| 204 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
203 |
int cartMessageUndeliverable = 0;
|
| 205 |
Map<Integer, TagListing> tagListingsMap = tagListings.stream()
|
204 |
|
| 206 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
205 |
Set<Integer> itemIds = cartLines.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 207 |
|
206 |
List<TagListing> tagListings = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds);
|
| 208 |
cart.setTotalPrice(0);
|
207 |
Map<Integer, TagListing> tagListingsMap = tagListings.stream()
|
| 209 |
int nonAccessoryQuantity = 0;
|
208 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 210 |
for (CartLine cartLine : cartLines) {
|
209 |
|
| 211 |
boolean itemQuantityChanged = false;
|
210 |
User user = saholicUserRepository.selectByCartId(cartId);
|
| 212 |
CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
|
211 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(user.getId());
|
| 213 |
int oldEstimate = cartLine.getEstimate();
|
212 |
Map<Integer, Integer> warehouseItemQtyMap = saholicInventoryService.getSaholicNetAvailability(fs.getWarehouseId(), new ArrayList<>(itemIds));
|
| 214 |
int itemId = cartLine.getItemId();
|
213 |
|
| 215 |
Item item = null;
|
214 |
logger.info("warehouseItemQtyMap -- {}", warehouseItemQtyMap);
|
| 216 |
try {
|
215 |
|
| 217 |
item = itemRepository.selectById(itemId);
|
216 |
cart.setTotalPrice(0);
|
| 218 |
cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
|
217 |
int nonAccessoryQuantity = 0;
|
| 219 |
} catch (ProfitMandiBusinessException e) {
|
218 |
for (CartLine cartLine : cartLines) {
|
| 220 |
e.printStackTrace();
|
219 |
CartItemResponseModel cartItemResponseModel = new CartItemResponseModel();
|
| 221 |
logger.info("Error finding item with id {}", itemId);
|
220 |
int oldEstimate = cartLine.getEstimate();
|
| 222 |
cartLineRepository.delete(cartLine);
|
221 |
int itemId = cartLine.getItemId();
|
| 223 |
continue;
|
222 |
Item item = null;
|
| 224 |
}
|
223 |
try {
|
| 225 |
cartItemResponseModel.setItemId(itemId);
|
224 |
item = itemRepository.selectById(itemId);
|
| 226 |
cartItemResponseModel.setQuantity(0);
|
225 |
cartItemResponseModel.setTitle(item.getItemDescriptionNoColor());
|
| 227 |
cartItemResponseModel.setColor(item.getColor());
|
226 |
} catch (ProfitMandiBusinessException e) {
|
| 228 |
List<CartItemMessage> cartItemMessages = new ArrayList<>();
|
227 |
e.printStackTrace();
|
| 229 |
cartItemResponseModel.setCartItemMessages(cartItemMessages);
|
228 |
logger.info("Error finding item with id {}", itemId);
|
| 230 |
cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
|
229 |
cartLineRepository.delete(cartLine);
|
| 231 |
cartItemResponseModel.setMinBuyQuantity(1);
|
230 |
continue;
|
| 232 |
cartItemResponseModel.setQuantityStep(1);
|
231 |
}
|
| 233 |
cartItemResponseModel.setMaxQuantity(0);
|
232 |
cartItemResponseModel.setItemId(itemId);
|
| 234 |
|
233 |
cartItemResponseModel.setQuantity(cartLine.getQuantity());
|
| 235 |
/*
|
234 |
cartItemResponseModel.setColor(item.getColor());
|
| 236 |
* int netAvailability = itemAvailabilityMap.get(itemId).stream()
|
235 |
cartItemResponseModel.setCatalogItemId(item.getCatalogItemId());
|
| 237 |
* .collect(Collectors.summingInt(x -> x.getNetavailability()));
|
236 |
cartItemResponseModel.setMinBuyQuantity(1);
|
| 238 |
*/
|
237 |
cartItemResponseModel.setQuantityStep(1);
|
| 239 |
int availability = 1000;
|
238 |
cartItemResponseModel.setMaxQuantity(100);
|
| 240 |
if (availability < cartLine.getQuantity()) {
|
239 |
int currentAvailability = warehouseItemQtyMap.get(itemId) == null ? 0 : warehouseItemQtyMap.get(itemId);
|
| 241 |
cartLine.setQuantity(availability);
|
240 |
int oldAvailability = cartLine.getAvailability();
|
| 242 |
itemQuantityChanged = true;
|
241 |
cartItemResponseModel.setAvailability(currentAvailability);
|
| 243 |
}
|
242 |
|
| 244 |
cartItemResponseModel.setMaxQuantity(Math.max(availability, 100));
|
243 |
//Current availability is less than required quantity
|
| 245 |
if (availability < cartItemResponseModel.getMinBuyQuantity()) {
|
244 |
if (currentAvailability < cartLine.getQuantity()) {
|
| 246 |
cartItemResponseModel.setMinBuyQuantity(availability);
|
245 |
//Current Availability is reduced
|
| 247 |
}
|
246 |
if (oldAvailability > currentAvailability) {
|
| 248 |
if (cartLine.getQuantity() < cartItemResponseModel.getMinBuyQuantity()) {
|
247 |
cartMessageChanged += 1;
|
| 249 |
itemQuantityChanged = true;
|
248 |
}
|
| 250 |
cartLine.setQuantity(cartItemResponseModel.getMinBuyQuantity());
|
249 |
}
|
| 251 |
}
|
250 |
|
| 252 |
|
251 |
//As of now one can buy upto 100 Qty
|
| 253 |
if (cartLine.getQuantity() > cartItemResponseModel.getMaxQuantity()) {
|
252 |
if (cartLine.getQuantity() > cartItemResponseModel.getMaxQuantity()) {
|
| 254 |
itemQuantityChanged = true;
|
253 |
cartMessageChanged +=1;
|
| 255 |
cartLine.setQuantity(cartItemResponseModel.getMaxQuantity());
|
254 |
cartLine.setQuantity(cartItemResponseModel.getMaxQuantity());
|
| 256 |
}
|
255 |
}
|
| 257 |
cartLine.setActualPrice(tagListingsMap.get(itemId).getSellingPrice());
|
256 |
|
| 258 |
if (item.getCategoryId() == 10006 || item.getCategoryId() == 10010) {
|
257 |
cartLine.setActualPrice(tagListingsMap.get(itemId).getSellingPrice());
|
| 259 |
nonAccessoryQuantity += cartItemResponseModel.getQuantity();
|
258 |
if (item.getCategoryId() == 10006 || item.getCategoryId() == 10010) {
|
| 260 |
cartItemResponseModel.setCategoryName("mobile");
|
259 |
nonAccessoryQuantity += cartItemResponseModel.getQuantity();
|
| 261 |
}
|
260 |
cartItemResponseModel.setCategoryName("mobile");
|
| 262 |
cartItemResponseModel.setSellingPrice(cartLine.getActualPrice());
|
261 |
}
|
| 263 |
|
262 |
cartItemResponseModel.setSellingPrice(cartLine.getActualPrice());
|
| 264 |
if (availability > 0) {
|
263 |
|
| 265 |
cart.setTotalPrice(cart.getTotalPrice() + (cartLine.getActualPrice() * cartLine.getQuantity()));
|
264 |
//if (availability > 0) {
|
| 266 |
cartItemResponseModel.setQuantity(cartLine.getQuantity());
|
265 |
cart.setTotalPrice(cart.getTotalPrice() + (cartLine.getActualPrice() * cartLine.getQuantity()));
|
| 267 |
cartItemResponseModel.setEstimate(2);
|
266 |
cartItemResponseModel.setQuantity(cartLine.getQuantity());
|
| 268 |
if (itemQuantityChanged) {
|
267 |
cartItemResponseModel.setEstimate(2);
|
| 269 |
cartMessageChanged += 1;
|
268 |
cartLine.setEstimate(cartItemResponseModel.getEstimate());
|
| 270 |
if (oldEstimate != cartItemResponseModel.getEstimate()) {
|
269 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
| 271 |
cartLine.setEstimate(cartItemResponseModel.getEstimate());
|
270 |
|
| 272 |
cart.setUpdateTimestamp(LocalDateTime.now());
|
271 |
|
| 273 |
}
|
272 |
totalAmount += cartLine.getActualPrice() * cartLine.getQuantity();
|
| 274 |
}
|
273 |
totalQty += cartItemResponseModel.getQuantity();
|
| 275 |
totalAmount += cartLine.getActualPrice() * cartLine.getQuantity();
|
274 |
cartResponse.getCartItems().add(cartItemResponseModel);
|
| 276 |
} else {
|
275 |
|
| 277 |
cartItemResponseModel.setQuantity(0);
|
276 |
}
|
| 278 |
cartMessageOOS += 1;
|
277 |
if (cart.getCheckoutTimestamp() != null) {
|
| 279 |
CartItemMessage cartItemMessage = new CartItemMessage();
|
278 |
if (cart.getUpdateTimestamp().isBefore(cart.getCheckoutTimestamp())) {
|
| 280 |
cartItemMessage.setType("danger");
|
279 |
cart.setCheckoutTimestamp(null);
|
| 281 |
cartItemMessage.setMessageText("Out of Stock");
|
280 |
}
|
| 282 |
cartItemMessages.add(cartItemMessage);
|
281 |
}
|
| 283 |
cartLineRepository.delete(cartLine);
|
282 |
cartResponse.setTotalQty(totalQty);
|
| 284 |
}
|
283 |
cartResponse.setTotalAmount(totalAmount);
|
| 285 |
totalQty += cartItemResponseModel.getQuantity();
|
284 |
cartResponse.setNonAccessoryQuantity(nonAccessoryQuantity);
|
| 286 |
|
285 |
cartResponse.setShippingCharge(0);
|
| 287 |
if (cartItemMessages.size() > 0) {
|
286 |
cartResponse.setCartMessageChanged(cartMessageChanged);
|
| 288 |
cartResponse.getCartItems().add(0, cartItemResponseModel);
|
287 |
cartResponse.setCartMessageOOS(cartMessageOOS);
|
| 289 |
} else {
|
288 |
cartResponse.setCartMessageUndeliverable(cartMessageUndeliverable);
|
| 290 |
cartResponse.getCartItems().add(cartItemResponseModel);
|
289 |
cartResponse.setCod(false);
|
| 291 |
}
|
290 |
return cartResponse;
|
| 292 |
}
|
291 |
}
|
| 293 |
if (cart.getCheckoutTimestamp() != null) {
|
292 |
|
| 294 |
if (cart.getUpdateTimestamp().isBefore(cart.getCheckoutTimestamp())) {
|
293 |
@Override
|
| 295 |
cart.setCheckoutTimestamp(null);
|
294 |
public void addItemsToCart(int cartId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
| 296 |
}
|
295 |
logger.info("cart items {}", cartItems);
|
| 297 |
}
|
296 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
| 298 |
cartResponse.setTotalQty(totalQty);
|
297 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
| 299 |
cartResponse.setTotalAmount(totalAmount);
|
298 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
| 300 |
cartResponse.setNonAccessoryQuantity(nonAccessoryQuantity);
|
299 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
| 301 |
cartResponse.setShippingCharge(0);
|
300 |
// Delete cartLines with 0 values
|
| 302 |
cartResponse.setCartMessageChanged(cartMessageChanged);
|
301 |
for (CartLine cartLine : cartLines) {
|
| 303 |
cartResponse.setCartMessageOOS(cartMessageOOS);
|
302 |
Integer quantity = itemQuantityMap.get(cartLine.getItemId());
|
| 304 |
cartResponse.setCartMessageUndeliverable(cartMessageUndeliverable);
|
303 |
if (quantity == null || quantity.intValue() == 0) {
|
| 305 |
cartResponse.setCod(false);
|
304 |
cartLineRepository.delete(cartLine);
|
| 306 |
return cartResponse;
|
305 |
} else {
|
| 307 |
}
|
306 |
cartLine.setQuantity(itemQuantityMap.get(cartLine.getItemId()));
|
| 308 |
|
307 |
cartLine.setUpdateTimestapm(LocalDateTime.now());
|
| 309 |
@Override
|
308 |
}
|
| 310 |
public void addItemsToCart(int cartId, List<CartItem> cartItems) throws ProfitMandiBusinessException {
|
309 |
}
|
| 311 |
logger.info("cart items {}", cartItems);
|
310 |
for (CartItem cartItem : cartItems) {
|
| 312 |
cartItems = cartItems.stream().filter(x -> x.getQuantity() > 0).collect(Collectors.toList());
|
311 |
if (cartLineRepository.selectByCartItem(cartId, cartItem.getItemId()) == null) {
|
| 313 |
Map<Integer, Integer> itemQuantityMap = cartItems.stream()
|
312 |
CartLine cartLineNew = new CartLine();
|
| 314 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x.getQuantity()));
|
313 |
cartLineNew.setItemId(cartItem.getItemId());
|
| 315 |
List<CartLine> cartLines = cartLineRepository.selectAllByCart(cartId);
|
314 |
cartLineNew.setQuantity(cartItem.getQuantity());
|
| 316 |
// Delete cartLines with 0 values
|
315 |
cartLineNew.setCartId(cartId);
|
| 317 |
for (CartLine cartLine : cartLines) {
|
316 |
cartLineNew.setCreateTimestamp(LocalDateTime.now());
|
| 318 |
Integer quantity = itemQuantityMap.get(cartLine.getItemId());
|
317 |
cartLineRepository.persist(cartLineNew);
|
| 319 |
if (quantity == null || quantity.intValue() == 0) {
|
318 |
}
|
| 320 |
cartLineRepository.delete(cartLine);
|
319 |
}
|
| 321 |
} else {
|
320 |
|
| 322 |
cartLine.setQuantity(itemQuantityMap.get(cartLine.getItemId()));
|
321 |
}
|
| 323 |
cartLine.setUpdateTimestapm(LocalDateTime.now());
|
322 |
|
| 324 |
}
|
323 |
@Override
|
| 325 |
}
|
324 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
| 326 |
for (CartItem cartItem : cartItems) {
|
325 |
Cart cart = cartRepository.selectById(cartId);
|
| 327 |
if (cartLineRepository.selectByCartItem(cartId, cartItem.getItemId()) == null) {
|
326 |
cart.setAddressId((int) addressId);
|
| 328 |
CartLine cartLineNew = new CartLine();
|
327 |
|
| 329 |
cartLineNew.setItemId(cartItem.getItemId());
|
328 |
}
|
| 330 |
cartLineNew.setQuantity(cartItem.getQuantity());
|
329 |
|
| 331 |
cartLineNew.setCartId(cartId);
|
330 |
@Override
|
| 332 |
cartLineNew.setCreateTimestamp(LocalDateTime.now());
|
331 |
public void addShoppingBag(int cartId, long qty) {
|
| 333 |
cartLineRepository.persist(cartLineNew);
|
332 |
CartLine cl = new CartLine();
|
| 334 |
}
|
333 |
cl.setItemId(ProfitMandiConstants.ITEM_CARRY_BAG);
|
| 335 |
}
|
334 |
cl.setQuantity((int) qty);
|
| 336 |
|
335 |
cl.setCartId(cartId);
|
| 337 |
}
|
336 |
cl.setCreateTimestamp(LocalDateTime.now());
|
| 338 |
|
337 |
cl.setDataProtectionAmount(0);
|
| 339 |
@Override
|
338 |
cl.setEstimate(0);
|
| 340 |
public void addAddressToCart(int cartId, long addressId) throws ProfitMandiBusinessException {
|
339 |
cl.setInsuranceAmount(0f);
|
| 341 |
Cart cart = cartRepository.selectById(cartId);
|
340 |
cl.setDataProtectionInsurer(0);
|
| 342 |
cart.setAddressId((int) addressId);
|
341 |
cl.setActualPrice(0.01f);
|
| 343 |
|
342 |
cartLineRepository.persist(cl);
|
| 344 |
}
|
343 |
|
| 345 |
|
344 |
}
|
| 346 |
@Override
|
345 |
|
| 347 |
public void addShoppingBag(int cartId, long qty) {
|
346 |
@Override
|
| 348 |
CartLine cl = new CartLine();
|
347 |
public CartModel removeFromCart(int cartId, int itemId) {
|
| 349 |
cl.setItemId(ProfitMandiConstants.ITEM_CARRY_BAG);
|
348 |
// TODO Auto-generated method stub
|
| 350 |
cl.setQuantity((int) qty);
|
349 |
return null;
|
| 351 |
cl.setCartId(cartId);
|
350 |
}
|
| 352 |
cl.setCreateTimestamp(LocalDateTime.now());
|
351 |
|
| 353 |
cl.setDataProtectionAmount(0);
|
352 |
@Override
|
| 354 |
cl.setEstimate(0);
|
353 |
public List<FocusedShortageModel> focusedModelShortageValidation(int fofoId,
|
| 355 |
cl.setInsuranceAmount(0f);
|
354 |
Map<Integer, Integer> catalogCartQtyMap) throws ProfitMandiBusinessException {
|
| 356 |
cl.setDataProtectionInsurer(0);
|
355 |
|
| 357 |
cl.setActualPrice(0.01f);
|
356 |
logger.info("fofoId {}", fofoId);
|
| 358 |
cartLineRepository.persist(cl);
|
357 |
|
| 359 |
|
358 |
focusedModelVariantMap.put(1022771, Arrays.asList(1022771));
|
| 360 |
}
|
359 |
focusedModelVariantMap.put(1023025, Arrays.asList(1022975, 1022945));
|
| 361 |
|
360 |
|
| 362 |
@Override
|
361 |
focusedModelVariantMap.put(1023027, Arrays.asList(1022706));
|
| 363 |
public CartModel removeFromCart(int cartId, int itemId) {
|
362 |
|
| 364 |
// TODO Auto-generated method stub
|
363 |
focusedModelVariantMap.put(1022976, Arrays.asList(1022744));
|
| 365 |
return null;
|
364 |
focusedModelVariantMap.put(1023045, Arrays.asList(1022768));
|
| 366 |
}
|
365 |
|
| 367 |
|
366 |
focusedModelVariantMap.put(1023066, Arrays.asList(1022858));
|
| 368 |
@Override
|
367 |
|
| 369 |
public List<FocusedShortageModel> focusedModelShortageValidation(int fofoId,
|
368 |
Map<Integer, Long> inStockItemModel = new HashMap<>();
|
| 370 |
Map<Integer, Integer> catalogCartQtyMap) throws ProfitMandiBusinessException {
|
369 |
Map<Integer, Long> itempendingIndent = new HashMap<>();
|
| 371 |
|
370 |
Map<Integer, Long> grnItemPendingOrders = new HashMap<>();
|
| 372 |
logger.info("fofoId {}", fofoId);
|
371 |
|
| 373 |
|
372 |
Map<Integer, Integer> focusedModelMap = null;
|
| 374 |
focusedModelVariantMap.put(1022771, Arrays.asList(1022771));
|
373 |
|
| 375 |
focusedModelVariantMap.put(1023025, Arrays.asList(1022975, 1022945));
|
374 |
inStockItemModel = currentInventorySnapshotRepository.selectSumInMobileStockGroupByCatalog(fofoId).stream()
|
| 376 |
|
375 |
.collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x.getQty()));
|
| 377 |
focusedModelVariantMap.put(1023027, Arrays.asList(1022706));
|
376 |
|
| 378 |
|
377 |
itempendingIndent = transactionService.getInTransitOrders(fofoId).stream()
|
| 379 |
focusedModelVariantMap.put(1022976, Arrays.asList(1022744));
|
378 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItem().getCatalogItemId(),
|
| 380 |
focusedModelVariantMap.put(1023045, Arrays.asList(1022768));
|
379 |
Collectors.summingLong(x -> (long) x.getLineItem().getQuantity())));
|
| 381 |
|
380 |
|
| 382 |
focusedModelVariantMap.put(1023066, Arrays.asList(1022858));
|
381 |
grnItemPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
| 383 |
|
382 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItem().getCatalogItemId(),
|
| 384 |
Map<Integer, Long> inStockItemModel = new HashMap<>();
|
383 |
Collectors.summingLong(x -> (long) x.getLineItem().getQuantity())));
|
| 385 |
Map<Integer, Long> itempendingIndent = new HashMap<>();
|
384 |
List<PartnerRegion> partnerRegions = partnerRegionRepository.selectByfofoId(fofoId);
|
| 386 |
Map<Integer, Long> grnItemPendingOrders = new HashMap<>();
|
385 |
|
| 387 |
|
386 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 388 |
Map<Integer, Integer> focusedModelMap = null;
|
387 |
|
| 389 |
|
388 |
List<String> retailerBlockBrands = retailerBlockBrandRepository.selectAllByRetailer(fofoId).stream()
|
| 390 |
inStockItemModel = currentInventorySnapshotRepository.selectSumInMobileStockGroupByCatalog(fofoId).stream()
|
389 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
| 391 |
.collect(Collectors.toMap(x -> x.getCatalogItemId(), x -> x.getQty()));
|
390 |
|
| 392 |
|
391 |
if (partnerRegions.size() > 0) {
|
| 393 |
itempendingIndent = transactionService.getInTransitOrders(fofoId).stream()
|
392 |
focusedModelMap = focusedModelRepository
|
| 394 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItem().getCatalogItemId(),
|
393 |
.selectAllByRegionIds(
|
| 395 |
Collectors.summingLong(x -> (long) x.getLineItem().getQuantity())));
|
394 |
partnerRegions.stream().map(x -> x.getRegionId()).collect(Collectors.toList()))
|
| 396 |
|
395 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getMinimumQty()));
|
| 397 |
grnItemPendingOrders = orderRepository.selectPendingGrnOrders(fofoId).stream()
|
396 |
} else {
|
| 398 |
.collect(Collectors.groupingBy(x -> x.getLineItem().getItem().getCatalogItemId(),
|
397 |
focusedModelMap = new HashMap<>();
|
| 399 |
Collectors.summingLong(x -> (long) x.getLineItem().getQuantity())));
|
398 |
}
|
| 400 |
List<PartnerRegion> partnerRegions = partnerRegionRepository.selectByfofoId(fofoId);
|
399 |
|
| 401 |
|
400 |
Map<Integer, Integer> catalogItemAailabilityMap = new HashMap<>();
|
| 402 |
FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
|
401 |
|
| 403 |
|
402 |
for (Entry<Integer, Integer> fm : focusedModelMap.entrySet()) {
|
| 404 |
List<String> retailerBlockBrands = retailerBlockBrandRepository.selectAllByRetailer(fofoId).stream()
|
403 |
List<Item> items = itemRepository.selectAllByCatalogItemId(fm.getKey());
|
| 405 |
.map(x -> x.getBlockBrands()).collect(Collectors.toList());
|
404 |
int allColorNetAvailability = 0;
|
| 406 |
|
405 |
for (Item item : items) {
|
| 407 |
if (partnerRegions.size() > 0) {
|
406 |
if (retailerBlockBrands.contains(item.getBrand()))
|
| 408 |
focusedModelMap = focusedModelRepository
|
407 |
continue;
|
| 409 |
.selectAllByRegionIds(
|
408 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(item.getId(), fofoStore.getWarehouseId());
|
| 410 |
partnerRegions.stream().map(x -> x.getRegionId()).collect(Collectors.toList()))
|
409 |
|
| 411 |
.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getMinimumQty()));
|
410 |
if (currentAvailability != null) {
|
| 412 |
} else {
|
411 |
allColorNetAvailability += currentAvailability.stream()
|
| 413 |
focusedModelMap = new HashMap<>();
|
412 |
.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability));
|
| 414 |
}
|
413 |
}
|
| 415 |
|
414 |
}
|
| 416 |
Map<Integer, Integer> catalogItemAailabilityMap = new HashMap<>();
|
415 |
catalogItemAailabilityMap.put(fm.getKey(), allColorNetAvailability);
|
| 417 |
|
416 |
}
|
| 418 |
for (Entry<Integer, Integer> fm : focusedModelMap.entrySet()) {
|
417 |
|
| 419 |
List<Item> items = itemRepository.selectAllByCatalogItemId(fm.getKey());
|
418 |
List<FocusedShortageModel> focusedModelShortageList = new ArrayList<>();
|
| 420 |
int allColorNetAvailability = 0;
|
419 |
|
| 421 |
for (Item item : items) {
|
420 |
for (Entry<Integer, Integer> fm : focusedModelMap.entrySet()) {
|
| 422 |
if (retailerBlockBrands.contains(item.getBrand()))
|
421 |
|
| 423 |
continue;
|
422 |
logger.info("fm {}", fm);
|
| 424 |
List<SaholicCISTable> currentAvailability = saholicCISTableRepository.selectByItemWarehouse(item.getId(), fofoStore.getWarehouseId());
|
423 |
|
| 425 |
|
424 |
long overallStock = (inStockItemModel.get(fm.getKey()) == null ? 0 : inStockItemModel.get(fm.getKey()))
|
| 426 |
if (currentAvailability != null) {
|
425 |
+ (itempendingIndent.get(fm.getKey()) == null ? 0 : itempendingIndent.get(fm.getKey()))
|
| 427 |
allColorNetAvailability += currentAvailability.stream()
|
426 |
+ (grnItemPendingOrders.get(fm.getKey()) == null ? 0 : grnItemPendingOrders.get(fm.getKey()));
|
| 428 |
.collect(Collectors.summingInt(SaholicCISTable::getNetAvailability));
|
427 |
logger.info("overallStock {}", overallStock);
|
| 429 |
}
|
428 |
|
| 430 |
}
|
429 |
// Blocked brands available quantity is discussed to zero
|
| 431 |
catalogItemAailabilityMap.put(fm.getKey(), allColorNetAvailability);
|
430 |
long warehouseStock = catalogItemAailabilityMap.get(fm.getKey()) == null ? 0
|
| 432 |
}
|
431 |
: catalogItemAailabilityMap.get(fm.getKey());
|
| 433 |
|
432 |
logger.info("warehouseStock {}", warehouseStock);
|
| 434 |
List<FocusedShortageModel> focusedModelShortageList = new ArrayList<>();
|
433 |
|
| 435 |
|
434 |
long cartValue = catalogCartQtyMap.get(fm.getKey()) == null ? 0 : catalogCartQtyMap.get(fm.getKey());
|
| 436 |
for (Entry<Integer, Integer> fm : focusedModelMap.entrySet()) {
|
435 |
|
| 437 |
|
436 |
logger.info("cartValue" + cartValue);
|
| 438 |
logger.info("fm {}", fm);
|
437 |
long totalStock = overallStock + cartValue;
|
| 439 |
|
438 |
logger.info("totalStock" + totalStock);
|
| 440 |
long overallStock = (inStockItemModel.get(fm.getKey()) == null ? 0 : inStockItemModel.get(fm.getKey()))
|
439 |
|
| 441 |
+ (itempendingIndent.get(fm.getKey()) == null ? 0 : itempendingIndent.get(fm.getKey()))
|
440 |
long shortQty = Math.min(fm.getValue() - totalStock, warehouseStock);
|
| 442 |
+ (grnItemPendingOrders.get(fm.getKey()) == null ? 0 : grnItemPendingOrders.get(fm.getKey()));
|
441 |
logger.info("shortQty {}", shortQty);
|
| 443 |
logger.info("overallStock {}", overallStock);
|
442 |
|
| 444 |
|
443 |
if (shortQty > 0) {
|
| 445 |
// Blocked brands available quantity is discussed to zero
|
444 |
if (focusedModelVariantMap.get(fm.getKey()) != null) {
|
| 446 |
long warehouseStock = catalogItemAailabilityMap.get(fm.getKey()) == null ? 0
|
445 |
List<Integer> variantCatalogIds = focusedModelVariantMap.get(fm.getKey());
|
| 447 |
: catalogItemAailabilityMap.get(fm.getKey());
|
446 |
logger.info("variantCatalogIds {}", variantCatalogIds);
|
| 448 |
logger.info("warehouseStock {}", warehouseStock);
|
447 |
|
| 449 |
|
448 |
int variantAvailability = 0;
|
| 450 |
long cartValue = catalogCartQtyMap.get(fm.getKey()) == null ? 0 : catalogCartQtyMap.get(fm.getKey());
|
449 |
for (Integer vc : variantCatalogIds) {
|
| 451 |
|
450 |
long variantOverallStock = (inStockItemModel.get(vc) == null ? 0 : inStockItemModel.get(vc))
|
| 452 |
logger.info("cartValue" + cartValue);
|
451 |
+ (itempendingIndent.get(vc) == null ? 0 : itempendingIndent.get(vc))
|
| 453 |
long totalStock = overallStock + cartValue;
|
452 |
+ (grnItemPendingOrders.get(vc) == null ? 0 : grnItemPendingOrders.get(vc));
|
| 454 |
logger.info("totalStock" + totalStock);
|
453 |
logger.info("variantOverallStock {}", variantOverallStock);
|
| 455 |
|
454 |
|
| 456 |
long shortQty = Math.min(fm.getValue() - totalStock, warehouseStock);
|
455 |
// Blocked brands available quantity is discussed to zero
|
| 457 |
logger.info("shortQty {}", shortQty);
|
456 |
long variantWarehouseStock = catalogItemAailabilityMap.get(vc) == null ? 0
|
| 458 |
|
457 |
: catalogItemAailabilityMap.get(vc);
|
| 459 |
if (shortQty > 0) {
|
458 |
logger.info("variantWarehouseStock {}", variantWarehouseStock);
|
| 460 |
if (focusedModelVariantMap.get(fm.getKey()) != null) {
|
459 |
|
| 461 |
List<Integer> variantCatalogIds = focusedModelVariantMap.get(fm.getKey());
|
460 |
long variantCartValue = catalogCartQtyMap.get(vc) == null ? 0 : catalogCartQtyMap.get(vc);
|
| 462 |
logger.info("variantCatalogIds {}", variantCatalogIds);
|
461 |
|
| 463 |
|
462 |
logger.info("variantCartValue" + variantCartValue);
|
| 464 |
int variantAvailability = 0;
|
463 |
long variantTotalStock = variantOverallStock + variantCartValue;
|
| 465 |
for (Integer vc : variantCatalogIds) {
|
464 |
logger.info("variantTotalStock" + variantTotalStock);
|
| 466 |
long variantOverallStock = (inStockItemModel.get(vc) == null ? 0 : inStockItemModel.get(vc))
|
465 |
|
| 467 |
+ (itempendingIndent.get(vc) == null ? 0 : itempendingIndent.get(vc))
|
466 |
variantAvailability += (int) variantTotalStock;
|
| 468 |
+ (grnItemPendingOrders.get(vc) == null ? 0 : grnItemPendingOrders.get(vc));
|
467 |
|
| 469 |
logger.info("variantOverallStock {}", variantOverallStock);
|
468 |
}
|
| 470 |
|
469 |
|
| 471 |
// Blocked brands available quantity is discussed to zero
|
470 |
logger.info("variantAvailability {}", variantAvailability);
|
| 472 |
long variantWarehouseStock = catalogItemAailabilityMap.get(vc) == null ? 0
|
471 |
|
| 473 |
: catalogItemAailabilityMap.get(vc);
|
472 |
shortQty = shortQty - variantAvailability;
|
| 474 |
logger.info("variantWarehouseStock {}", variantWarehouseStock);
|
473 |
|
| 475 |
|
474 |
}
|
| 476 |
long variantCartValue = catalogCartQtyMap.get(vc) == null ? 0 : catalogCartQtyMap.get(vc);
|
475 |
}
|
| 477 |
|
476 |
|
| 478 |
logger.info("variantCartValue" + variantCartValue);
|
477 |
logger.info("shortQty" + shortQty);
|
| 479 |
long variantTotalStock = variantOverallStock + variantCartValue;
|
478 |
|
| 480 |
logger.info("variantTotalStock" + variantTotalStock);
|
479 |
if (shortQty > 0) {
|
| 481 |
|
480 |
|
| 482 |
variantAvailability += (int) variantTotalStock;
|
481 |
Map<Integer, Integer> requiredItemQty = new HashMap<>();
|
| 483 |
|
482 |
|
| 484 |
}
|
483 |
List<Item> it = itemRepository.selectAllByCatalogItemId(fm.getKey());
|
| 485 |
|
484 |
FocusedShortageModel fms = new FocusedShortageModel();
|
| 486 |
logger.info("variantAvailability {}", variantAvailability);
|
485 |
fms.setShortageQty((int) shortQty);
|
| 487 |
|
486 |
fms.setCatalogId(fm.getKey());
|
| 488 |
shortQty = shortQty - variantAvailability;
|
487 |
fms.setAvailabitiy(fm.getValue());
|
| 489 |
|
488 |
fms.setInStock(overallStock);
|
| 490 |
}
|
489 |
|
| 491 |
}
|
490 |
fms.setItemName(it.get(0).getBrand() + it.get(0).getModelNumber() + it.get(0).getModelName());
|
| 492 |
|
491 |
|
| 493 |
logger.info("shortQty" + shortQty);
|
492 |
Map<Integer, Integer> itemQtyMap = new HashMap<>();
|
| 494 |
|
493 |
|
| 495 |
if (shortQty > 0) {
|
494 |
for (Item i : it) {
|
| 496 |
|
495 |
|
| 497 |
Map<Integer, Integer> requiredItemQty = new HashMap<>();
|
496 |
List<SaholicCISTable> ca = saholicCISTableRepository.selectByItemWarehouse(i.getId(), fofoStore.getWarehouseId());
|
| 498 |
|
497 |
if (ca != null) {
|
| 499 |
List<Item> it = itemRepository.selectAllByCatalogItemId(fm.getKey());
|
498 |
itemQtyMap.put(i.getId(),
|
| 500 |
FocusedShortageModel fms = new FocusedShortageModel();
|
499 |
ca.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
|
| 501 |
fms.setShortageQty((int) shortQty);
|
500 |
}
|
| 502 |
fms.setCatalogId(fm.getKey());
|
501 |
}
|
| 503 |
fms.setAvailabitiy(fm.getValue());
|
502 |
|
| 504 |
fms.setInStock(overallStock);
|
503 |
itemQtyMap = itemQtyMap.entrySet().stream()
|
| 505 |
|
504 |
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors
|
| 506 |
fms.setItemName(it.get(0).getBrand() + it.get(0).getModelNumber() + it.get(0).getModelName());
|
505 |
.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
|
| 507 |
|
506 |
|
| 508 |
Map<Integer, Integer> itemQtyMap = new HashMap<>();
|
507 |
for (long i = shortQty; i > 0; i--) {
|
| 509 |
|
508 |
if (shortQty == 0) {
|
| 510 |
for (Item i : it) {
|
509 |
break;
|
| 511 |
|
510 |
}
|
| 512 |
List<SaholicCISTable> ca = saholicCISTableRepository.selectByItemWarehouse(i.getId(), fofoStore.getWarehouseId());
|
511 |
|
| 513 |
if (ca != null) {
|
512 |
for (Entry<Integer, Integer> itemQty : itemQtyMap.entrySet()) {
|
| 514 |
itemQtyMap.put(i.getId(),
|
513 |
|
| 515 |
ca.stream().collect(Collectors.summingInt(SaholicCISTable::getNetAvailability)));
|
514 |
int availbleQty = itemQty.getValue();
|
| 516 |
}
|
515 |
if (availbleQty == 0) {
|
| 517 |
}
|
516 |
break;
|
| 518 |
|
517 |
}
|
| 519 |
itemQtyMap = itemQtyMap.entrySet().stream()
|
518 |
if (requiredItemQty.get(itemQty.getKey()) == null) {
|
| 520 |
.sorted(Collections.reverseOrder(Map.Entry.comparingByValue())).collect(Collectors
|
519 |
requiredItemQty.put(itemQty.getKey(), 1);
|
| 521 |
.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2, LinkedHashMap::new));
|
520 |
availbleQty = availbleQty - 1;
|
| 522 |
|
521 |
if (availbleQty != 0) {
|
| 523 |
for (long i = shortQty; i > 0; i--) {
|
522 |
itemQtyMap.put(itemQty.getKey(), availbleQty);
|
| 524 |
if (shortQty == 0) {
|
523 |
}
|
| 525 |
break;
|
524 |
shortQty -= 1;
|
| 526 |
}
|
525 |
} else {
|
| 527 |
|
526 |
|
| 528 |
for (Entry<Integer, Integer> itemQty : itemQtyMap.entrySet()) {
|
527 |
int qty = requiredItemQty.get(itemQty.getKey());
|
| 529 |
|
528 |
|
| 530 |
int availbleQty = itemQty.getValue();
|
529 |
requiredItemQty.put(itemQty.getKey(), qty + 1);
|
| 531 |
if (availbleQty == 0) {
|
530 |
|
| 532 |
break;
|
531 |
availbleQty = availbleQty - 1;
|
| 533 |
}
|
532 |
if (availbleQty != 0) {
|
| 534 |
if (requiredItemQty.get(itemQty.getKey()) == null) {
|
533 |
itemQtyMap.put(itemQty.getKey(), availbleQty);
|
| 535 |
requiredItemQty.put(itemQty.getKey(), 1);
|
534 |
}
|
| 536 |
availbleQty = availbleQty - 1;
|
535 |
shortQty -= 1;
|
| 537 |
if (availbleQty != 0) {
|
536 |
}
|
| 538 |
itemQtyMap.put(itemQty.getKey(), availbleQty);
|
537 |
|
| 539 |
}
|
538 |
if (shortQty == 0) {
|
| 540 |
shortQty -= 1;
|
539 |
break;
|
| 541 |
} else {
|
540 |
}
|
| 542 |
|
541 |
|
| 543 |
int qty = requiredItemQty.get(itemQty.getKey());
|
542 |
}
|
| 544 |
|
543 |
|
| 545 |
requiredItemQty.put(itemQty.getKey(), qty + 1);
|
544 |
}
|
| 546 |
|
545 |
|
| 547 |
availbleQty = availbleQty - 1;
|
546 |
Set<CartItem> cartItems = new HashSet<>();
|
| 548 |
if (availbleQty != 0) {
|
547 |
for (Entry<Integer, Integer> itemQtySet : requiredItemQty.entrySet()) {
|
| 549 |
itemQtyMap.put(itemQty.getKey(), availbleQty);
|
548 |
|
| 550 |
}
|
549 |
CartItem ci = new CartItem();
|
| 551 |
shortQty -= 1;
|
550 |
Item item = itemRepository.selectById(itemQtySet.getKey());
|
| 552 |
}
|
551 |
TagListing tl = tagListingRepository.selectByItemId(item.getId());
|
| 553 |
|
552 |
ci.setItemId(item.getId());
|
| 554 |
if (shortQty == 0) {
|
553 |
ci.setQuantity(itemQtySet.getValue());
|
| 555 |
break;
|
554 |
ci.setSellingPrice(tl.getSellingPrice());
|
| 556 |
}
|
555 |
cartItems.add(ci);
|
| 557 |
|
556 |
|
| 558 |
}
|
557 |
}
|
| 559 |
|
558 |
fms.setCartItems(cartItems);
|
| 560 |
}
|
559 |
|
| 561 |
|
560 |
// fms.setItemQtyAvailability(requiredItemQty);
|
| 562 |
Set<CartItem> cartItems = new HashSet<>();
|
561 |
|
| 563 |
for (Entry<Integer, Integer> itemQtySet : requiredItemQty.entrySet()) {
|
562 |
focusedModelShortageList.add(fms);
|
| 564 |
|
563 |
|
| 565 |
CartItem ci = new CartItem();
|
564 |
}
|
| 566 |
Item item = itemRepository.selectById(itemQtySet.getKey());
|
565 |
|
| 567 |
TagListing tl = tagListingRepository.selectByItemId(item.getId());
|
566 |
}
|
| 568 |
ci.setItemId(item.getId());
|
567 |
|
| 569 |
ci.setQuantity(itemQtySet.getValue());
|
568 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
| 570 |
ci.setSellingPrice(tl.getSellingPrice());
|
569 |
return focusedModelShortageList;
|
| 571 |
cartItems.add(ci);
|
570 |
}
|
| 572 |
|
- |
|
| 573 |
}
|
- |
|
| 574 |
fms.setCartItems(cartItems);
|
- |
|
| 575 |
|
- |
|
| 576 |
// fms.setItemQtyAvailability(requiredItemQty);
|
- |
|
| 577 |
|
- |
|
| 578 |
focusedModelShortageList.add(fms);
|
- |
|
| 579 |
|
- |
|
| 580 |
}
|
- |
|
| 581 |
|
- |
|
| 582 |
}
|
- |
|
| 583 |
|
- |
|
| 584 |
logger.info("focusedModelShortageList {}", focusedModelShortageList);
|
- |
|
| 585 |
return focusedModelShortageList;
|
- |
|
| 586 |
}
|
- |
|
| 587 |
|
571 |
|
| 588 |
}
|
572 |
}
|