| 23405 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23785 |
amit.gupta |
3 |
import java.util.ArrayList;
|
| 23405 |
amit.gupta |
4 |
import java.util.Arrays;
|
| 23796 |
amit.gupta |
5 |
import java.util.Collections;
|
|
|
6 |
import java.util.Comparator;
|
| 23785 |
amit.gupta |
7 |
import java.util.DoubleSummaryStatistics;
|
| 23796 |
amit.gupta |
8 |
import java.util.HashMap;
|
| 24406 |
amit.gupta |
9 |
import java.util.HashSet;
|
| 23785 |
amit.gupta |
10 |
import java.util.Iterator;
|
| 23405 |
amit.gupta |
11 |
import java.util.List;
|
|
|
12 |
import java.util.Map;
|
| 24231 |
amit.gupta |
13 |
import java.util.Optional;
|
| 23785 |
amit.gupta |
14 |
import java.util.Set;
|
| 23405 |
amit.gupta |
15 |
import java.util.stream.Collectors;
|
|
|
16 |
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
|
|
18 |
|
| 24231 |
amit.gupta |
19 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23717 |
amit.gupta |
20 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
21 |
import org.apache.logging.log4j.Logger;
|
| 23796 |
amit.gupta |
22 |
import org.apache.thrift.TException;
|
| 24349 |
amit.gupta |
23 |
import org.json.JSONArray;
|
| 23779 |
amit.gupta |
24 |
import org.json.JSONObject;
|
| 23405 |
amit.gupta |
25 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24231 |
amit.gupta |
26 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
27 |
import org.springframework.http.HttpHeaders;
|
|
|
28 |
import org.springframework.http.HttpStatus;
|
|
|
29 |
import org.springframework.http.ResponseEntity;
|
| 23405 |
amit.gupta |
30 |
import org.springframework.stereotype.Controller;
|
|
|
31 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
32 |
import org.springframework.ui.Model;
|
| 23855 |
amit.gupta |
33 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 23405 |
amit.gupta |
34 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
35 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
36 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 23779 |
amit.gupta |
37 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23405 |
amit.gupta |
38 |
|
| 24413 |
amit.gupta |
39 |
import com.mongodb.TaggableReadPreference;
|
| 23785 |
amit.gupta |
40 |
import com.spice.profitmandi.common.enumuration.CounterSize;
|
| 23405 |
amit.gupta |
41 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23785 |
amit.gupta |
42 |
import com.spice.profitmandi.common.model.BrandPerformance;
|
| 24231 |
amit.gupta |
43 |
import com.spice.profitmandi.common.model.CatalogListingModel;
|
| 23785 |
amit.gupta |
44 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 23786 |
amit.gupta |
45 |
import com.spice.profitmandi.common.model.ItemIdAvailability;
|
| 23779 |
amit.gupta |
46 |
import com.spice.profitmandi.common.model.StockAllocationModel;
|
| 24231 |
amit.gupta |
47 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23785 |
amit.gupta |
48 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 23405 |
amit.gupta |
49 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 23785 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 23796 |
amit.gupta |
51 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
|
|
52 |
import com.spice.profitmandi.dao.entity.user.User;
|
| 23405 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
|
|
54 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 23779 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 23405 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
| 23796 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
|
|
58 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
59 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
60 |
import com.spice.profitmandi.dao.repository.user.UserRepository;
|
| 23798 |
amit.gupta |
61 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 23779 |
amit.gupta |
62 |
import com.spice.profitmandi.service.inventory.StockAllocationService;
|
|
|
63 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 23796 |
amit.gupta |
64 |
import com.spice.profitmandi.thrift.clients.PaymentClient;
|
|
|
65 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
66 |
import com.spice.profitmandi.thrift.clients.UserClient;
|
| 23405 |
amit.gupta |
67 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
68 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
69 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
70 |
|
| 23796 |
amit.gupta |
71 |
import in.shop2020.logistics.PickUpType;
|
|
|
72 |
import in.shop2020.model.v1.order.LineItem;
|
|
|
73 |
import in.shop2020.model.v1.order.OrderSource;
|
|
|
74 |
import in.shop2020.model.v1.order.OrderStatus;
|
|
|
75 |
import in.shop2020.model.v1.order.OrderType;
|
|
|
76 |
import in.shop2020.model.v1.order.Transaction;
|
|
|
77 |
import in.shop2020.model.v1.order.TransactionService;
|
|
|
78 |
import in.shop2020.model.v1.order.TransactionStatus;
|
|
|
79 |
import in.shop2020.model.v1.user.ItemPriceQuantity;
|
|
|
80 |
import in.shop2020.model.v1.user.ShoppingCartException;
|
|
|
81 |
import in.shop2020.model.v1.user.UserContextService.Client;
|
| 24406 |
amit.gupta |
82 |
import in.shop2020.model.v1.user.UserContextService.forgotPassword_args;
|
| 23796 |
amit.gupta |
83 |
import in.shop2020.payments.Attribute;
|
|
|
84 |
import in.shop2020.payments.PaymentException;
|
|
|
85 |
import in.shop2020.payments.PaymentStatus;
|
|
|
86 |
|
| 23405 |
amit.gupta |
87 |
@Controller
|
|
|
88 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
89 |
public class IndentController {
|
|
|
90 |
|
| 23568 |
govind |
91 |
private static final Logger LOGGER = LogManager.getLogger(IndentController.class);
|
| 23796 |
amit.gupta |
92 |
private static final int WALLET_GATEWAY_ID = 8;
|
| 24406 |
amit.gupta |
93 |
private static final Set<Integer> defaultTags = new HashSet<Integer>(Arrays.asList(4));
|
| 23405 |
amit.gupta |
94 |
|
| 23796 |
amit.gupta |
95 |
private final List<OrderStatus> validOrderStatusList = Arrays.asList(OrderStatus.ACCEPTED,
|
|
|
96 |
OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
|
|
|
97 |
OrderStatus.DELIVERY_SUCCESS, OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
|
|
|
98 |
OrderStatus.REACHED_DESTINATION_CITY);
|
|
|
99 |
|
| 24231 |
amit.gupta |
100 |
private final List<OrderStatus> partnerPendingOrderList = Arrays.asList(OrderStatus.ACCEPTED,
|
|
|
101 |
OrderStatus.SUBMITTED_FOR_PROCESSING, OrderStatus.BILLED, OrderStatus.SHIPPED_FROM_WH,
|
|
|
102 |
OrderStatus.SHIPPED_TO_DESTINATION_CITY, OrderStatus.SHIPPED_TO_LOGST,
|
|
|
103 |
OrderStatus.REACHED_DESTINATION_CITY);
|
|
|
104 |
|
| 23405 |
amit.gupta |
105 |
@Autowired
|
|
|
106 |
private CookiesProcessor cookiesProcessor;
|
| 24231 |
amit.gupta |
107 |
|
| 23796 |
amit.gupta |
108 |
@Autowired
|
|
|
109 |
private UserWalletRepository userWalletRepository;
|
| 23785 |
amit.gupta |
110 |
|
| 23779 |
amit.gupta |
111 |
@Autowired
|
| 23796 |
amit.gupta |
112 |
private UserRepository userRepository;
|
|
|
113 |
|
|
|
114 |
@Autowired
|
| 23779 |
amit.gupta |
115 |
FofoStoreRepository fofoStoreRepository;
|
| 23405 |
amit.gupta |
116 |
|
|
|
117 |
@Autowired
|
| 23796 |
amit.gupta |
118 |
private OrderRepository orderRepository;
|
|
|
119 |
|
|
|
120 |
@Autowired
|
| 23405 |
amit.gupta |
121 |
private ItemRepository itemRepository;
|
|
|
122 |
|
|
|
123 |
@Autowired
|
| 23779 |
amit.gupta |
124 |
private StockAllocationService stockAllocationService;
|
|
|
125 |
|
|
|
126 |
@Autowired
|
|
|
127 |
private RetailerService retailerService;
|
| 23405 |
amit.gupta |
128 |
|
|
|
129 |
@Autowired
|
|
|
130 |
private TagListingRepository tagListingRepository;
|
|
|
131 |
|
|
|
132 |
@Autowired
|
|
|
133 |
private CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
134 |
|
|
|
135 |
@Autowired
|
| 23796 |
amit.gupta |
136 |
private PurchaseRepository purchaseRepository;
|
|
|
137 |
|
|
|
138 |
@Autowired
|
| 23405 |
amit.gupta |
139 |
private MVCResponseSender mvcResponseSender;
|
|
|
140 |
|
| 23785 |
amit.gupta |
141 |
@Autowired
|
|
|
142 |
RoleManager roleManager;
|
| 23405 |
amit.gupta |
143 |
|
| 23779 |
amit.gupta |
144 |
@RequestMapping(value = "/open-indent/save", method = RequestMethod.POST)
|
| 23785 |
amit.gupta |
145 |
public String saveOpenIndent(HttpServletRequest request, Model model,
|
| 23786 |
amit.gupta |
146 |
@RequestBody List<StockAllocationModel> stockAllocationModelList, @RequestParam int fofoId,
|
|
|
147 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
| 23405 |
amit.gupta |
148 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23779 |
amit.gupta |
149 |
boolean response = false;
|
| 23785 |
amit.gupta |
150 |
if (fofoId > 0) {
|
|
|
151 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
| 23786 |
amit.gupta |
152 |
stockAllocationModelList.forEach(x -> {
|
|
|
153 |
x.setFofoId(fofoId);
|
|
|
154 |
x.setCounterSize(fs.getCounterSize());
|
|
|
155 |
});
|
|
|
156 |
} else {
|
|
|
157 |
stockAllocationModelList.forEach(x -> {
|
|
|
158 |
x.setFofoId(fofoId);
|
|
|
159 |
x.setCounterSize(counterSize);
|
|
|
160 |
});
|
| 23785 |
amit.gupta |
161 |
}
|
|
|
162 |
if (roleManager.isAdmin(loginDetails.getRoleIds())) {
|
|
|
163 |
response = stockAllocationService.addToAllocation(stockAllocationModelList);
|
|
|
164 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
|
|
165 |
}
|
| 23405 |
amit.gupta |
166 |
return "response";
|
|
|
167 |
}
|
|
|
168 |
|
| 24231 |
amit.gupta |
169 |
@RequestMapping(value = "/indent/download", method = RequestMethod.GET)
|
|
|
170 |
public ResponseEntity<ByteArrayResource> downloadIndent(HttpServletRequest request, Model model,
|
|
|
171 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
|
|
172 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws Exception {
|
|
|
173 |
Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
|
|
|
174 |
LOGGER.info("Counter size is {}", counterSize);
|
|
|
175 |
LOGGER.info("Fofo Id is {}", fofoId);
|
|
|
176 |
if (roleManager.isAdmin(roleIds)) {
|
|
|
177 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
178 |
.collect(Collectors.toList());
|
|
|
179 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
| 23415 |
amit.gupta |
180 |
|
| 24232 |
amit.gupta |
181 |
List<StockAllocationModel> stockAllocationList = stockAllocationService.getStockAllocation(counterSize,
|
|
|
182 |
true);
|
|
|
183 |
Map<Integer, Integer> modelStockAllocationMap = stockAllocationList.stream()
|
|
|
184 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x.getQuantity()));
|
| 23405 |
amit.gupta |
185 |
|
| 24232 |
amit.gupta |
186 |
Map<String, Integer> catalogUserQtyMap = new HashMap<>();
|
| 24231 |
amit.gupta |
187 |
currentInventorySnapshotRepository.selectAll(Optional.of(true)).stream().forEach(x -> {
|
| 24232 |
amit.gupta |
188 |
int retailerId = x.getFofoId();
|
|
|
189 |
int catalogId;
|
|
|
190 |
try {
|
|
|
191 |
catalogId = itemRepository.selectById(x.getItemId()).getCatalogItemId();
|
|
|
192 |
String key = catalogId + "-" + retailerId;
|
|
|
193 |
if (!catalogUserQtyMap.containsKey(key)) {
|
|
|
194 |
catalogUserQtyMap.put(key, 0);
|
|
|
195 |
}
|
|
|
196 |
catalogUserQtyMap.put(key, catalogUserQtyMap.get(key) + x.getAvailability());
|
|
|
197 |
} catch (ProfitMandiBusinessException e) {
|
|
|
198 |
// TODO Auto-generated catch block
|
|
|
199 |
throw new RuntimeException(e);
|
| 24231 |
amit.gupta |
200 |
}
|
|
|
201 |
});
|
| 23779 |
amit.gupta |
202 |
|
| 24231 |
amit.gupta |
203 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoIds, partnerPendingOrderList);
|
| 24232 |
amit.gupta |
204 |
Map<String, Integer> catalogUserInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> {
|
|
|
205 |
try {
|
|
|
206 |
return itemRepository.selectById(x.getLineItem().getItemId()).getCatalogItemId() + "-"
|
|
|
207 |
+ x.getRetailerId();
|
|
|
208 |
} catch (ProfitMandiBusinessException e) {
|
|
|
209 |
// TODO Auto-generated catch block
|
|
|
210 |
return "";
|
|
|
211 |
}
|
|
|
212 |
}, Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
| 23779 |
amit.gupta |
213 |
|
| 24232 |
amit.gupta |
214 |
Map<String, CatalogListingModel> catalogListingMap = new HashMap<>();
|
|
|
215 |
|
|
|
216 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
|
|
217 |
Iterator<TagListing> iterator = tagListings.iterator();
|
| 24231 |
amit.gupta |
218 |
while (iterator.hasNext()) {
|
|
|
219 |
TagListing tagListing = iterator.next();
|
|
|
220 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
| 24232 |
amit.gupta |
221 |
int catalogId = item.getCatalogItemId();
|
| 24231 |
amit.gupta |
222 |
if (item.getCategoryId() != 10006) {
|
|
|
223 |
continue;
|
|
|
224 |
}
|
| 23779 |
amit.gupta |
225 |
|
| 24232 |
amit.gupta |
226 |
int catalogStockAllocationQuantity = modelStockAllocationMap.containsKey(catalogId)
|
|
|
227 |
? modelStockAllocationMap.get(catalogId)
|
|
|
228 |
: 0;
|
|
|
229 |
for (int retailerId : fofoIds) {
|
|
|
230 |
String key = catalogId + "-" + retailerId;
|
|
|
231 |
if (catalogListingMap.containsKey(key)) {
|
|
|
232 |
continue;
|
| 24231 |
amit.gupta |
233 |
}
|
| 24232 |
amit.gupta |
234 |
int catalogInTransit = catalogUserInTransit.containsKey(key) ? catalogUserInTransit.get(key) : 0;
|
|
|
235 |
int catalogInStock = catalogUserQtyMap.containsKey(key) ? catalogUserQtyMap.get(key) : 0;
|
|
|
236 |
if (catalogInTransit + catalogInStock == 0 && catalogStockAllocationQuantity == 0) {
|
|
|
237 |
continue;
|
|
|
238 |
}
|
|
|
239 |
CatalogListingModel catalogListingModel = new CatalogListingModel();
|
|
|
240 |
catalogListingModel.setFofoId(retailerId);
|
|
|
241 |
catalogListingModel.setModelName(item.getModelName());
|
|
|
242 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
|
|
243 |
catalogListingModel.setCatalogId(catalogId);
|
|
|
244 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
|
|
245 |
catalogListingModel.setMop(tagListing.getMop());
|
|
|
246 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
|
|
247 |
catalogListingModel.setAllocatedQuantity(catalogStockAllocationQuantity);
|
|
|
248 |
catalogListingModel.setInTransitQuantity(catalogInTransit);
|
|
|
249 |
catalogListingModel
|
|
|
250 |
.setToBeOrdered(catalogStockAllocationQuantity - catalogInTransit - catalogInStock);
|
| 24233 |
amit.gupta |
251 |
catalogListingModel.setStockInHand(catalogInStock);
|
| 24232 |
amit.gupta |
252 |
catalogListingModel.setBrand(item.getBrand());
|
|
|
253 |
catalogListingModel.setModelName(item.getModelName());
|
|
|
254 |
catalogListingModel.setModelNumber(item.getModelNumber());
|
|
|
255 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
|
|
256 |
catalogListingMap.put(key, catalogListingModel);
|
| 23405 |
amit.gupta |
257 |
}
|
|
|
258 |
}
|
| 24231 |
amit.gupta |
259 |
List<List<Object>> listOfRows = new ArrayList<>();
|
|
|
260 |
for (CatalogListingModel clm : catalogListingMap.values()) {
|
|
|
261 |
CustomRetailer cr = customRetailersMap.get(clm.getFofoId());
|
| 24349 |
amit.gupta |
262 |
listOfRows.add(Arrays.asList(cr.getPartnerId(), cr.getBusinessName(), clm.getCatalogId(),
|
|
|
263 |
clm.getBrand(), clm.getModelName(), clm.getModelNumber(), clm.getDp(), clm.getMop(),
|
|
|
264 |
clm.getAllocatedQuantity(), clm.getInTransitQuantity(), clm.getStockInHand(),
|
|
|
265 |
clm.getToBeOrdered()));
|
| 24231 |
amit.gupta |
266 |
}
|
| 24349 |
amit.gupta |
267 |
ByteArrayOutputStream baos = FileUtil
|
|
|
268 |
.getCSVByteStream(
|
|
|
269 |
Arrays.asList("StoreId", "StoreName", "Catalog Id", "Brand", "Model Name", "Model Number",
|
|
|
270 |
"DP", "MOP", "Allocated Quantity", "In Transit", "Stock In hand", "Shortage"),
|
|
|
271 |
listOfRows);
|
| 24231 |
amit.gupta |
272 |
HttpHeaders headers = new HttpHeaders();
|
|
|
273 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
274 |
headers.set("Content-disposition", "inline; filename=retailer-allocation.csv");
|
| 24232 |
amit.gupta |
275 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(baos.toByteArray()), headers,
|
|
|
276 |
HttpStatus.OK);
|
| 23405 |
amit.gupta |
277 |
}
|
| 24231 |
amit.gupta |
278 |
return null;
|
| 24232 |
amit.gupta |
279 |
|
| 23405 |
amit.gupta |
280 |
}
|
|
|
281 |
|
| 24349 |
amit.gupta |
282 |
@RequestMapping(value = "/itemsByCatalogId")
|
|
|
283 |
public String getItemsByCatalogId(HttpServletRequest request, Model model,
|
| 24410 |
amit.gupta |
284 |
@RequestParam(required = false) int catalogId, @RequestParam(required = false) int itemId)
|
|
|
285 |
throws ProfitMandiBusinessException
|
|
|
286 |
{
|
|
|
287 |
if (catalogId == 0) {
|
|
|
288 |
catalogId = itemRepository.selectById(itemId).getCatalogItemId();
|
|
|
289 |
}
|
| 24349 |
amit.gupta |
290 |
List<Item> items = itemRepository.selectAllByCatalogItemId(catalogId);
|
| 24414 |
amit.gupta |
291 |
LOGGER.info("Items {}", items);
|
|
|
292 |
Map<Integer, String> itemsColorMap = items.stream().filter(x->x.getColorNatural().startsWith("f_")).collect(Collectors.toMap(Item::getId, Item::getColor));
|
| 24413 |
amit.gupta |
293 |
Map<Integer, TagListing> tagsMap = tagListingRepository
|
|
|
294 |
.selectByItemIdsAndTagIds(items.stream().map(x -> x.getId()).collect(Collectors.toSet()), defaultTags)
|
|
|
295 |
.stream().collect(Collectors.toMap(TagListing::getItemId, x->x));
|
| 24414 |
amit.gupta |
296 |
LOGGER.info("Items color map {}", itemsColorMap);
|
| 24349 |
amit.gupta |
297 |
JSONArray response = new JSONArray();
|
| 24413 |
amit.gupta |
298 |
itemsColorMap.keySet().stream().forEach(x -> {
|
|
|
299 |
response.put(
|
|
|
300 |
new JSONObject()
|
|
|
301 |
.put("color", itemsColorMap.get(x))
|
|
|
302 |
.put("id", x)
|
|
|
303 |
.put("active", tagsMap.get(x)==null ? false : tagsMap.get(x).isActive()));
|
| 24349 |
amit.gupta |
304 |
});
|
|
|
305 |
model.addAttribute("response", response.toString());
|
|
|
306 |
return "response";
|
| 24410 |
amit.gupta |
307 |
|
| 24349 |
amit.gupta |
308 |
}
|
|
|
309 |
|
| 23405 |
amit.gupta |
310 |
@RequestMapping(value = "/indent/loadIndent")
|
| 23785 |
amit.gupta |
311 |
public String loadOpenIndent(HttpServletRequest request, Model model,
|
|
|
312 |
@RequestParam(required = false, defaultValue = "0") int fofoId,
|
| 23786 |
amit.gupta |
313 |
@RequestParam(defaultValue = "TEN_LAC") CounterSize counterSize) throws ProfitMandiBusinessException {
|
| 23785 |
amit.gupta |
314 |
Set<Integer> roleIds = cookiesProcessor.getCookiesObject(request).getRoleIds();
|
|
|
315 |
LOGGER.info("Counter size is {}", counterSize);
|
|
|
316 |
LOGGER.info("Fofo Id is {}", fofoId);
|
| 23786 |
amit.gupta |
317 |
|
|
|
318 |
Map<Integer, ItemIdAvailability> itemCisMap = null;
|
|
|
319 |
if (!roleManager.isAdmin(roleIds)) {
|
|
|
320 |
fofoId = cookiesProcessor.getCookiesObject(request).getFofoId();
|
| 23796 |
amit.gupta |
321 |
List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
322 |
.selectItemsStock(fofoId);
|
|
|
323 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
|
|
324 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 23786 |
amit.gupta |
325 |
} else {
|
|
|
326 |
if (fofoId == 0) {
|
| 23796 |
amit.gupta |
327 |
List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
328 |
.selectItemsStock();
|
|
|
329 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
|
|
330 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 23779 |
amit.gupta |
331 |
} else {
|
| 23796 |
amit.gupta |
332 |
List<ItemIdAvailability> currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
333 |
.selectItemsStock(fofoId);
|
|
|
334 |
itemCisMap = currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
|
|
335 |
.collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
| 23405 |
amit.gupta |
336 |
}
|
| 23786 |
amit.gupta |
337 |
}
|
|
|
338 |
List<BrandPerformance> brandPerformanceList = new ArrayList<>();
|
|
|
339 |
List<BrandPerformance> accsBrandPerformanceList = new ArrayList<>();
|
|
|
340 |
List<StockAllocationModel> stockAllocationList;
|
|
|
341 |
if (fofoId > 0) {
|
|
|
342 |
stockAllocationList = stockAllocationService.getStockAllocation(fofoId, true);
|
|
|
343 |
} else {
|
|
|
344 |
stockAllocationList = stockAllocationService.getStockAllocation(counterSize, true);
|
|
|
345 |
}
|
|
|
346 |
LOGGER.info("Stock Allocation list is {}", stockAllocationList);
|
| 23405 |
amit.gupta |
347 |
|
| 23786 |
amit.gupta |
348 |
Map<Integer, StockAllocationModel> itemStockAllocationMap = stockAllocationList.stream()
|
| 24231 |
amit.gupta |
349 |
.collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
|
| 23796 |
amit.gupta |
350 |
Map<Integer, Integer> itemsInTransit = null;
|
| 23786 |
amit.gupta |
351 |
LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
|
| 23855 |
amit.gupta |
352 |
List<TagListing> tagListings = tagListingRepository.selectAll(true);
|
| 23796 |
amit.gupta |
353 |
if (!roleManager.isAdmin(roleIds)) {
|
| 23786 |
amit.gupta |
354 |
tagListings = new ArrayList<>(tagListings);
|
| 23796 |
amit.gupta |
355 |
List<Order> inTransitOrders = orderRepository.selectOrders(fofoId, validOrderStatusList);
|
|
|
356 |
inTransitOrders = this.filterValidOrders(inTransitOrders);
|
|
|
357 |
itemsInTransit = inTransitOrders.stream().collect(Collectors.groupingBy(x -> x.getLineItem().getItemId(),
|
|
|
358 |
Collectors.summingInt(x -> x.getLineItem().getQuantity())));
|
|
|
359 |
} else {
|
|
|
360 |
itemsInTransit = new HashMap<>();
|
| 23786 |
amit.gupta |
361 |
}
|
|
|
362 |
Iterator<TagListing> iterator = tagListings.iterator();
|
| 23796 |
amit.gupta |
363 |
int totalPcs = 0;
|
|
|
364 |
int toBeOrdered = 0;
|
|
|
365 |
float totalAmount = 0;
|
| 24231 |
amit.gupta |
366 |
Map<Integer, CatalogListingModel> catalogListingMap = new HashMap<>();
|
| 23786 |
amit.gupta |
367 |
while (iterator.hasNext()) {
|
|
|
368 |
TagListing tagListing = iterator.next();
|
| 24231 |
amit.gupta |
369 |
|
| 23786 |
amit.gupta |
370 |
Item item = itemRepository.selectById(tagListing.getItemId());
|
| 24231 |
amit.gupta |
371 |
// itemRepository.select
|
|
|
372 |
// catalogTagListingMap
|
| 23786 |
amit.gupta |
373 |
if (roleManager.isAdmin(roleIds)) {
|
| 24231 |
amit.gupta |
374 |
if (item.getBrand() == null || item.getCategoryId() != 10006) {
|
| 23785 |
amit.gupta |
375 |
iterator.remove();
|
|
|
376 |
continue;
|
|
|
377 |
}
|
| 23786 |
amit.gupta |
378 |
} else {
|
| 24231 |
amit.gupta |
379 |
if (!(itemCisMap.containsKey(tagListing.getItemId())
|
| 24232 |
amit.gupta |
380 |
|| itemStockAllocationMap.containsKey(tagListing.getItemId()))) {
|
| 23786 |
amit.gupta |
381 |
iterator.remove();
|
|
|
382 |
continue;
|
| 23779 |
amit.gupta |
383 |
}
|
|
|
384 |
}
|
| 24231 |
amit.gupta |
385 |
int catalogId = item.getCatalogItemId();
|
|
|
386 |
|
|
|
387 |
CatalogListingModel catalogListingModel = catalogListingMap.get(catalogId);
|
|
|
388 |
if (!catalogListingMap.containsKey(catalogId)) {
|
|
|
389 |
catalogListingModel = new CatalogListingModel();
|
|
|
390 |
catalogListingModel.setCatalogId(catalogId);
|
|
|
391 |
catalogListingModel.setDp(tagListing.getSellingPrice());
|
|
|
392 |
catalogListingModel.setMop(tagListing.getMop());
|
|
|
393 |
catalogListingModel.setItemDescription(item.getItemDescriptionNoColor());
|
|
|
394 |
StockAllocationModel stockAllocationModel = itemStockAllocationMap.get(item.getCatalogItemId());
|
|
|
395 |
int stockAllocationQuantity = stockAllocationModel == null ? 0 : stockAllocationModel.getQuantity();
|
|
|
396 |
catalogListingModel.setAllocatedQuantity(stockAllocationQuantity);
|
|
|
397 |
catalogListingModel.setToBeOrdered(stockAllocationQuantity);
|
|
|
398 |
catalogListingModel.setBrand(item.getBrand());
|
|
|
399 |
if (item.getCategoryId() == 10006) {
|
|
|
400 |
catalogListingModel.setCategoryId(item.getCategoryId());
|
|
|
401 |
}
|
|
|
402 |
catalogListingMap.put(catalogId, catalogListingModel);
|
|
|
403 |
}
|
|
|
404 |
|
| 23796 |
amit.gupta |
405 |
ItemIdAvailability itemIdAvailability = itemCisMap.get(tagListing.getItemId());
|
| 24231 |
amit.gupta |
406 |
int itemAvailability = itemIdAvailability == null ? 0 : itemIdAvailability.getAvailability();
|
|
|
407 |
catalogListingModel.setStockInHand(catalogListingModel.getStockInHand() + itemAvailability);
|
| 23796 |
amit.gupta |
408 |
|
| 24231 |
amit.gupta |
409 |
Integer inTransitQuantity = itemsInTransit.get(item.getId());
|
|
|
410 |
int inTransitQty = (inTransitQuantity == null ? 0 : inTransitQuantity);
|
|
|
411 |
catalogListingModel.setInTransitQuantity(catalogListingModel.getInTransitQuantity() + inTransitQty);
|
|
|
412 |
|
|
|
413 |
if (catalogListingModel.getAllocatedQuantity() > 0) {
|
|
|
414 |
toBeOrdered = Math.max(catalogListingModel.getToBeOrdered() - inTransitQty - itemAvailability, 0);
|
|
|
415 |
catalogListingModel.setToBeOrdered(toBeOrdered);
|
| 23796 |
amit.gupta |
416 |
}
|
| 23786 |
amit.gupta |
417 |
}
|
| 24231 |
amit.gupta |
418 |
List<CatalogListingModel> catalogModelList = new ArrayList<>(catalogListingMap.values());
|
| 23405 |
amit.gupta |
419 |
|
| 24231 |
amit.gupta |
420 |
Map<Boolean, List<CatalogListingModel>> performanceMap = catalogModelList.stream()
|
|
|
421 |
.collect(Collectors.groupingBy(x -> x.getCategoryId() == 10006));
|
|
|
422 |
List<CatalogListingModel> mobileListing = performanceMap.get(true) == null ? new ArrayList<>()
|
|
|
423 |
: performanceMap.get(true);
|
|
|
424 |
List<CatalogListingModel> accsListing = performanceMap.get(false) == null ? new ArrayList<>()
|
|
|
425 |
: performanceMap.get(false);
|
| 23785 |
amit.gupta |
426 |
|
| 23786 |
amit.gupta |
427 |
Map<String, DoubleSummaryStatistics> accsStats = accsListing.stream().collect(Collectors.groupingBy(
|
|
|
428 |
x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
|
|
|
429 |
Map<String, DoubleSummaryStatistics> mobStats = mobileListing.stream().collect(Collectors.groupingBy(
|
|
|
430 |
x -> x.getBrand(), Collectors.summarizingDouble(x -> x.getAllocatedQuantity() * x.getMop())));
|
| 23785 |
amit.gupta |
431 |
|
| 23786 |
amit.gupta |
432 |
for (Map.Entry<String, DoubleSummaryStatistics> entry : mobStats.entrySet()) {
|
|
|
433 |
DoubleSummaryStatistics dss = entry.getValue();
|
|
|
434 |
BrandPerformance bp = new BrandPerformance();
|
|
|
435 |
bp.setTarget((float) dss.getSum());
|
|
|
436 |
bp.setBrandName(entry.getKey());
|
|
|
437 |
brandPerformanceList.add(bp);
|
|
|
438 |
}
|
|
|
439 |
for (Map.Entry<String, DoubleSummaryStatistics> entry : accsStats.entrySet()) {
|
|
|
440 |
DoubleSummaryStatistics dss = entry.getValue();
|
|
|
441 |
BrandPerformance bp = new BrandPerformance();
|
|
|
442 |
bp.setTarget((float) dss.getSum());
|
|
|
443 |
bp.setBrandName(entry.getKey());
|
|
|
444 |
accsBrandPerformanceList.add(bp);
|
|
|
445 |
}
|
|
|
446 |
brandPerformanceList = brandPerformanceList.stream().filter(x -> x.getTarget() > 0)
|
| 23796 |
amit.gupta |
447 |
.sorted(Comparator.comparing(x -> x.getTarget())).collect(Collectors.toList());
|
| 23786 |
amit.gupta |
448 |
accsBrandPerformanceList = accsBrandPerformanceList.stream().filter(x -> x.getTarget() > 0)
|
| 23796 |
amit.gupta |
449 |
.sorted(Comparator.comparing(x -> x.getTarget())).collect(Collectors.toList());
|
| 23785 |
amit.gupta |
450 |
|
| 23786 |
amit.gupta |
451 |
List<Integer> fofoIds = fofoStoreRepository.selectAll().stream().map(x -> x.getId())
|
|
|
452 |
.collect(Collectors.toList());
|
|
|
453 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
|
|
454 |
if (fofoId > 0) {
|
|
|
455 |
CustomRetailer customRetailer = customRetailersMap.get(fofoId);
|
|
|
456 |
model.addAttribute("retailerName",
|
|
|
457 |
customRetailer.getBusinessName() + "-" + customRetailer.getAddress().getCity());
|
|
|
458 |
FofoStore fs = fofoStoreRepository.selectByRetailerId(fofoId);
|
|
|
459 |
model.addAttribute("retailerId", customRetailer.getPartnerId());
|
|
|
460 |
model.addAttribute("counterSize", fs.getCounterSize().toString());
|
| 23779 |
amit.gupta |
461 |
} else {
|
| 23786 |
amit.gupta |
462 |
model.addAttribute("counterSize", counterSize.toString());
|
| 23405 |
amit.gupta |
463 |
}
|
| 23786 |
amit.gupta |
464 |
String customRetailers = JSONObject.valueToString(customRetailersMap.values());
|
|
|
465 |
LOGGER.info("Custom retailers {}", customRetailers);
|
| 24231 |
amit.gupta |
466 |
// Lits<CatalogTagListing> catalog
|
|
|
467 |
Comparator<CatalogListingModel> firstCmp = Comparator.comparing(CatalogListingModel::getToBeOrdered,
|
|
|
468 |
Comparator.reverseOrder());
|
|
|
469 |
model.addAttribute("catalogTagListings",
|
|
|
470 |
catalogModelList.stream().sorted(firstCmp).collect(Collectors.toList()));
|
| 23786 |
amit.gupta |
471 |
model.addAttribute("customRetailers", customRetailers);
|
|
|
472 |
model.addAttribute("brandPerformanceList", brandPerformanceList);
|
|
|
473 |
model.addAttribute("accsBrandPerformanceList", accsBrandPerformanceList);
|
|
|
474 |
model.addAttribute("counterSizes", CounterSize.values());
|
| 23796 |
amit.gupta |
475 |
model.addAttribute("isAdmin", roleManager.isAdmin(roleIds));
|
|
|
476 |
model.addAttribute("totalAmount", totalAmount);
|
|
|
477 |
model.addAttribute("totalPcs", totalPcs);
|
|
|
478 |
model.addAttribute("walletAmount", userWalletRepository.selectByRetailerId(fofoId).getAmount());
|
|
|
479 |
// model.addAttribute("itemCisMap", itemCisMap);
|
| 23786 |
amit.gupta |
480 |
return "open-indent";
|
| 23405 |
amit.gupta |
481 |
}
|
| 23796 |
amit.gupta |
482 |
|
|
|
483 |
private List<Order> filterValidOrders(List<Order> lastOrdersList) {
|
|
|
484 |
Iterator<Order> orderIterator = lastOrdersList.iterator();
|
|
|
485 |
while (orderIterator.hasNext()) {
|
|
|
486 |
Order o = orderIterator.next();
|
|
|
487 |
if (o.getInvoiceNumber() != null) {
|
|
|
488 |
try {
|
|
|
489 |
purchaseRepository.selectByPurchaseReferenceAndFofoId(o.getInvoiceNumber(), o.getRetailerId());
|
|
|
490 |
orderIterator.remove();
|
|
|
491 |
continue;
|
|
|
492 |
} catch (Exception e) {
|
|
|
493 |
|
|
|
494 |
}
|
|
|
495 |
}
|
|
|
496 |
}
|
|
|
497 |
return lastOrdersList;
|
|
|
498 |
}
|
|
|
499 |
|
| 24406 |
amit.gupta |
500 |
@RequestMapping(value = "/indent/confirm-pause", method = RequestMethod.POST)
|
| 24410 |
amit.gupta |
501 |
public String raisePO(HttpServletRequest request, Model model, @RequestBody String jsonArrayString)
|
|
|
502 |
throws Exception {
|
| 24406 |
amit.gupta |
503 |
JSONArray jsonArray = new JSONArray(jsonArrayString);
|
| 24410 |
amit.gupta |
504 |
for (int i = 0; i < jsonArray.length(); i++) {
|
| 24406 |
amit.gupta |
505 |
JSONObject obj = jsonArray.getJSONObject(i);
|
|
|
506 |
TagListing tl = tagListingRepository.selectByItemId(obj.getInt("id"));
|
|
|
507 |
tl.setActive(obj.getBoolean("active"));
|
|
|
508 |
tagListingRepository.persist(tl);
|
|
|
509 |
}
|
| 24410 |
amit.gupta |
510 |
model.addAttribute("response", true);
|
| 23855 |
amit.gupta |
511 |
return "response";
|
|
|
512 |
}
|
| 24231 |
amit.gupta |
513 |
|
|
|
514 |
@RequestMapping(value = "/indent/create-po", method = RequestMethod.POST)
|
| 23796 |
amit.gupta |
515 |
public String raisePO(HttpServletRequest request, Model model) throws Exception {
|
|
|
516 |
boolean success = false;
|
|
|
517 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
518 |
int fofoId = loginDetails.getFofoId();
|
|
|
519 |
List<ItemPriceQuantity> itemQuantities = this.getItemQuantities(fofoId);
|
|
|
520 |
CustomRetailer customRetailer = retailerService.getFofoRetailers(Arrays.asList(fofoId)).get(fofoId);
|
|
|
521 |
Client userClient = new UserClient().getClient();
|
| 24231 |
amit.gupta |
522 |
double totalAmount = itemQuantities.stream().mapToDouble(x -> x.getQty() * x.getPrice()).sum();
|
| 23796 |
amit.gupta |
523 |
|
| 24231 |
amit.gupta |
524 |
if (totalAmount > 0) {
|
| 23796 |
amit.gupta |
525 |
userClient.addItemPricingToCart(customRetailer.getCartId(), itemQuantities);
|
|
|
526 |
User user = userRepository.selectById(loginDetails.getFofoId());
|
|
|
527 |
userClient = new UserClient().getClient();
|
|
|
528 |
LOGGER.info("Setting wallet amount in cart");
|
| 24231 |
amit.gupta |
529 |
long transactionId = userClient.createOrders(user.getActiveCartId(), "", 0, "", 0, loginDetails.getFofoId(),
|
|
|
530 |
7890, OrderSource.WEBSITE.getValue(), true);
|
| 23796 |
amit.gupta |
531 |
LOGGER.info("Creating wallet payment for transactionId - {}", transactionId);
|
|
|
532 |
createPayment(user, totalAmount, transactionId);
|
| 24231 |
amit.gupta |
533 |
TransactionService.Client transactionClient = new TransactionClient().getClient();
|
| 23796 |
amit.gupta |
534 |
transactionClient.changeTransactionStatus(transactionId, TransactionStatus.AUTHORIZED,
|
| 24231 |
amit.gupta |
535 |
"Payment received for the order", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
|
| 23796 |
amit.gupta |
536 |
transactionClient.changeTransactionStatus(Long.valueOf(transactionId), TransactionStatus.IN_PROCESS,
|
| 24231 |
amit.gupta |
537 |
"Paid fully through wallet", PickUpType.RUNNER.getValue(), OrderType.B2B, OrderSource.WEBSITE);
|
| 23796 |
amit.gupta |
538 |
LOGGER.info("Successfully created transaction: " + transactionId + " for amount: " + totalAmount);
|
|
|
539 |
transactionClient = new TransactionClient().getClient();
|
|
|
540 |
transactionClient.markOrderForRegisteredGstInvoice(Collections.singletonList(Long.valueOf(transactionId)));
|
|
|
541 |
try {
|
|
|
542 |
transactionClient.enqueueTransactionInfoEmail(transactionId);
|
|
|
543 |
} catch (Exception e1) {
|
|
|
544 |
e1.printStackTrace();
|
|
|
545 |
LOGGER.error("Unable to update status of transaction. Thrift Exception:", e1);
|
|
|
546 |
}
|
|
|
547 |
resetCart(transactionClient.getTransaction(transactionId));
|
|
|
548 |
}
|
|
|
549 |
model.addAttribute("response", mvcResponseSender.createResponseString(success));
|
|
|
550 |
return "response";
|
|
|
551 |
}
|
| 24231 |
amit.gupta |
552 |
|
|
|
553 |
private void createPayment(User user, double totalAmount, long transactionId)
|
|
|
554 |
throws NumberFormatException, PaymentException, TException {
|
| 23796 |
amit.gupta |
555 |
List<Attribute> paymentAttributes = new ArrayList<Attribute>();
|
|
|
556 |
in.shop2020.payments.PaymentService.Client paymentClient = new PaymentClient().getClient();
|
|
|
557 |
paymentAttributes.add(new Attribute("payMethod", "7890"));
|
| 24231 |
amit.gupta |
558 |
long paymentId = paymentClient.createPayment(user.getId(), totalAmount, WALLET_GATEWAY_ID, transactionId,
|
|
|
559 |
false);
|
|
|
560 |
paymentClient.updatePaymentDetails(paymentId, null, null, null, null, null, null, null, null,
|
|
|
561 |
PaymentStatus.SUCCESS, null, paymentAttributes);
|
| 23796 |
amit.gupta |
562 |
}
|
| 24231 |
amit.gupta |
563 |
|
| 23796 |
amit.gupta |
564 |
private List<ItemPriceQuantity> getItemQuantities(int fofoId) throws ProfitMandiBusinessException {
|
|
|
565 |
List<ItemPriceQuantity> itemQuantities = new ArrayList<>();
|
| 24231 |
amit.gupta |
566 |
/*
|
|
|
567 |
* Map<Integer, ItemIdAvailability> itemCisMap = null; List<ItemIdAvailability>
|
|
|
568 |
* currentInventorySnapshots = currentInventorySnapshotRepository
|
|
|
569 |
* .selectItemsStock(fofoId); itemCisMap =
|
|
|
570 |
* currentInventorySnapshots.stream().filter(x -> x.getAvailability() > 0)
|
|
|
571 |
* .collect(Collectors.toMap(x -> x.getItemId(), x -> x));
|
|
|
572 |
* List<StockAllocationModel> stockAllocationList =
|
|
|
573 |
* stockAllocationService.getStockAllocation(fofoId, true);
|
|
|
574 |
*
|
|
|
575 |
* Map<Integer, StockAllocationModel> itemStockAllocationMap =
|
|
|
576 |
* stockAllocationList.stream() .collect(Collectors.toMap(x -> x.catalogId(), x
|
|
|
577 |
* -> x)); Map<Integer, Integer> itemsInTransit = null;
|
|
|
578 |
* LOGGER.info("Item Stock Allocation Model Map {}", itemStockAllocationMap);
|
|
|
579 |
* List<TagListing> tagListings = tagListingRepository.selectAll(false);
|
|
|
580 |
* List<Order> inTransitOrders = orderRepository.selectOrders(fofoId,
|
|
|
581 |
* validOrderStatusList); inTransitOrders =
|
|
|
582 |
* this.filterValidOrders(inTransitOrders); itemsInTransit =
|
|
|
583 |
* inTransitOrders.stream().collect(Collectors.groupingBy(x ->
|
|
|
584 |
* x.getLineItem().getItemId(), Collectors.summingInt(x ->
|
|
|
585 |
* x.getLineItem().getQuantity())));
|
|
|
586 |
*
|
|
|
587 |
* Iterator<TagListing> iterator = tagListings.iterator();
|
|
|
588 |
*
|
|
|
589 |
* int toBeOrdered = 0; while (iterator.hasNext()) { TagListing tagListing =
|
|
|
590 |
* iterator.next(); LOGGER.info(" tagListing.setAllocatedQuantity {}",
|
|
|
591 |
* tagListing.getAllocatedQuantity()); if
|
|
|
592 |
* (!itemCisMap.containsKey(tagListing.getItemId()) &&
|
|
|
593 |
* !itemStockAllocationMap.containsKey(tagListing.getItemId())) {
|
|
|
594 |
* iterator.remove(); continue; } ItemIdAvailability itemIdAvailability =
|
|
|
595 |
* itemCisMap.get(tagListing.getItemId());
|
|
|
596 |
* tagListing.setStockInHand(itemIdAvailability == null ? 0 :
|
|
|
597 |
* itemIdAvailability.getAvailability()); StockAllocationModel
|
|
|
598 |
* stockAllocationModel = itemStockAllocationMap.get(tagListing.getItemId());
|
|
|
599 |
*
|
|
|
600 |
* if (itemsInTransit.containsKey(tagListing.getItemId())) {
|
|
|
601 |
* tagListing.setInTransitQuantity(itemsInTransit.get(tagListing.getItemId()));
|
|
|
602 |
* } else { tagListing.setInTransitQuantity(0); } if (stockAllocationModel !=
|
|
|
603 |
* null) { tagListing.setAllocatedQuantity(stockAllocationModel.getQuantity());
|
|
|
604 |
* toBeOrdered = Math.max(tagListing.getAllocatedQuantity() -
|
|
|
605 |
* tagListing.getInTransitQuantity() - tagListing.getStockInHand(), 0); if
|
|
|
606 |
* (toBeOrdered > 0) { ItemPriceQuantity ipq = new ItemPriceQuantity();
|
|
|
607 |
* ipq.setItemId(tagListing.getItemId()); ipq.setQty((long) toBeOrdered);
|
|
|
608 |
* ipq.setPrice(tagListing.getSellingPrice()); itemQuantities.add(ipq); } } }
|
|
|
609 |
*/
|
| 23796 |
amit.gupta |
610 |
return itemQuantities;
|
|
|
611 |
|
|
|
612 |
}
|
| 24231 |
amit.gupta |
613 |
|
| 23796 |
amit.gupta |
614 |
private long resetCart(Transaction transaction) {
|
|
|
615 |
long sum = 0;
|
|
|
616 |
Map<Long, Double> items = new HashMap<Long, Double>();
|
|
|
617 |
for (in.shop2020.model.v1.order.Order order : transaction.getOrders()) {
|
|
|
618 |
sum += order.getGvAmount();
|
|
|
619 |
for (LineItem lineitem : order.getLineitems()) {
|
|
|
620 |
Long itemId = lineitem.getItem_id();
|
|
|
621 |
Double quantity = items.get(itemId);
|
|
|
622 |
if (quantity == null) {
|
|
|
623 |
quantity = lineitem.getQuantity();
|
|
|
624 |
} else {
|
|
|
625 |
quantity = quantity + lineitem.getQuantity();
|
|
|
626 |
}
|
|
|
627 |
items.put(itemId, quantity);
|
|
|
628 |
}
|
|
|
629 |
}
|
|
|
630 |
|
|
|
631 |
LOGGER.debug("Items to reset in cart are: " + items);
|
|
|
632 |
|
|
|
633 |
try {
|
|
|
634 |
Client userClient = new UserClient().getClient();
|
|
|
635 |
userClient.resetCart(transaction.getShoppingCartid(), items);
|
|
|
636 |
} catch (TException e) {
|
|
|
637 |
LOGGER.error("Error while updating information in payment database.", e);
|
|
|
638 |
} catch (ShoppingCartException e) {
|
|
|
639 |
LOGGER.error("Error while reseting the cart in cart database.", e);
|
|
|
640 |
} catch (Exception e) {
|
|
|
641 |
LOGGER.error("Unexpected exception", e);
|
|
|
642 |
}
|
|
|
643 |
return sum;
|
|
|
644 |
}
|
|
|
645 |
|
| 23405 |
amit.gupta |
646 |
}
|