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