| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
3 |
import java.io.ByteArrayInputStream;
|
| 4 |
import java.io.ByteArrayOutputStream;
|
4 |
import java.io.ByteArrayOutputStream;
|
| 5 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| 6 |
import java.time.LocalDateTime;
|
- |
|
| 7 |
import java.util.ArrayList;
|
- |
|
| 8 |
import java.util.HashMap;
|
- |
|
| 9 |
import java.util.HashSet;
|
- |
|
| 10 |
import java.util.Iterator;
|
- |
|
| 11 |
import java.util.List;
|
6 |
import java.util.List;
|
| 12 |
import java.util.Map;
|
7 |
import java.util.Map;
|
| 13 |
import java.util.Set;
|
- |
|
| 14 |
import java.util.function.Predicate;
|
- |
|
| 15 |
import java.util.stream.Collectors;
|
- |
|
| 16 |
|
8 |
|
| 17 |
import javax.servlet.http.HttpServletRequest;
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 18 |
import javax.servlet.http.HttpServletResponse;
|
10 |
import javax.servlet.http.HttpServletResponse;
|
| 19 |
|
11 |
|
| 20 |
import org.json.JSONObject;
|
- |
|
| 21 |
import org.slf4j.Logger;
|
12 |
import org.slf4j.Logger;
|
| 22 |
import org.slf4j.LoggerFactory;
|
13 |
import org.slf4j.LoggerFactory;
|
| 23 |
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24 |
import org.springframework.beans.factory.annotation.Value;
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
| 25 |
import org.springframework.core.io.InputStreamResource;
|
16 |
import org.springframework.core.io.InputStreamResource;
|
| Line 34... |
Line 25... |
| 34 |
import org.springframework.web.bind.annotation.RequestMethod;
|
25 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 35 |
import org.springframework.web.bind.annotation.RequestParam;
|
26 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 36 |
|
27 |
|
| 37 |
import com.google.gson.Gson;
|
28 |
import com.google.gson.Gson;
|
| 38 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 39 |
import com.spice.profitmandi.common.model.CartFofo;
|
- |
|
| 40 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
30 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 41 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
31 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 42 |
import com.spice.profitmandi.common.model.PriceModel;
|
- |
|
| 43 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
32 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 44 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
33 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 45 |
import com.spice.profitmandi.common.util.StringUtils;
|
- |
|
| 46 |
import com.spice.profitmandi.common.util.Utils;
|
34 |
import com.spice.profitmandi.common.util.Utils;
|
| 47 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
- |
|
| 48 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
- |
|
| 49 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
- |
|
| 50 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
- |
|
| 51 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
- |
|
| 52 |
import com.spice.profitmandi.dao.entity.transaction.LineItem;
|
- |
|
| 53 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
- |
|
| 54 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
- |
|
| 55 |
import com.spice.profitmandi.dao.repository.fofo.CurrentInventorySnapshotRepository;
|
- |
|
| 56 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
- |
|
| 57 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
- |
|
| 58 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
- |
|
| 59 |
import com.spice.profitmandi.service.aging.InventoryItemAgingService;
|
35 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 60 |
import com.spice.profitmandi.service.pricing.PricingService;
|
- |
|
| 61 |
import com.spice.profitmandi.web.model.LoginDetails;
|
36 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 62 |
import com.spice.profitmandi.web.response.ValidateCart;
|
- |
|
| 63 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
37 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 64 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
- |
|
| 65 |
|
38 |
|
| 66 |
@Controller
|
39 |
@Controller
|
| 67 |
@Transactional(rollbackFor=Throwable.class)
|
40 |
@Transactional(rollbackFor=Throwable.class)
|
| 68 |
public class InventoryController {
|
41 |
public class InventoryController {
|
| 69 |
|
42 |
|
| 70 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
43 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
| 71 |
|
44 |
|
| 72 |
@Autowired
|
45 |
@Autowired
|
| 73 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
- |
|
| 74 |
|
- |
|
| 75 |
@Autowired
|
- |
|
| 76 |
InventoryItemRepository inventoryItemRepository;
|
- |
|
| 77 |
|
- |
|
| 78 |
@Autowired
|
- |
|
| 79 |
PurchaseRepository purchaseRepository;
|
- |
|
| 80 |
|
- |
|
| 81 |
@Autowired
|
- |
|
| 82 |
ItemRepository itemRepository;
|
- |
|
| 83 |
|
- |
|
| 84 |
@Autowired
|
- |
|
| 85 |
OrderRepository orderRepository;
|
- |
|
| 86 |
|
- |
|
| 87 |
@Autowired
|
- |
|
| 88 |
MVCResponseSender mvcResponseSender;
|
- |
|
| 89 |
|
- |
|
| 90 |
@Autowired
|
- |
|
| 91 |
CookiesProcessor cookiesProcessor;
|
46 |
private CookiesProcessor cookiesProcessor;
|
| 92 |
|
- |
|
| 93 |
@Autowired
|
- |
|
| 94 |
PricingService pricingService;
|
- |
|
| 95 |
|
47 |
|
| 96 |
@Autowired
|
48 |
@Autowired
|
| 97 |
InventoryItemAgingService inventoryItemAgingService;
|
49 |
private InventoryService inventoryService;
|
| 98 |
|
- |
|
| 99 |
@Autowired
|
- |
|
| 100 |
ResponseSender<?> responseSender;
|
- |
|
| 101 |
|
50 |
|
| 102 |
@Value("${saholic.api.host}")
|
51 |
@Value("${saholic.api.host}")
|
| 103 |
private String host;
|
52 |
private String host;
|
| - |
|
53 |
|
| 104 |
@Value("${saholic.api.port}")
|
54 |
@Value("${saholic.api.port}")
|
| 105 |
private int port;
|
55 |
private int port;
|
| - |
|
56 |
|
| 106 |
@Value("${saholic.api.webapp}")
|
57 |
@Value("${saholic.api.webapp}")
|
| 107 |
private String webapp;
|
58 |
private String webapp;
|
| 108 |
|
59 |
|
| 109 |
|
- |
|
| 110 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
60 |
@RequestMapping(value = "/getCurrentInventorySnapshot")
|
| 111 |
public String getCurrentAvailability(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws Exception{
|
61 |
public String getCurrentAvailability(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws ProfitMandiBusinessException{
|
| 112 |
LoginDetails fofoDetails;
|
- |
|
| 113 |
try {
|
- |
|
| 114 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
62 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 115 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 116 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 117 |
return "response";
|
- |
|
| 118 |
}
|
- |
|
| 119 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
63 |
Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit, searchTerm);
|
| 120 |
|
- |
|
| 121 |
long countItems = currentInventorySnapshotRepository.getCurrentInventorySnapshotCount(fofoDetails.getFofoId(), searchTerm);
|
- |
|
| 122 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
- |
|
| 123 |
model.addAttribute("start",offset+1);
|
64 |
model.addAllAttributes(map);
|
| 124 |
model.addAttribute("size",countItems);
|
- |
|
| 125 |
model.addAttribute("searchTerm",searchTerm);
|
- |
|
| 126 |
if (currentInventorySnapshot.size() < limit){
|
- |
|
| 127 |
model.addAttribute("end",offset+currentInventorySnapshot.size());
|
- |
|
| 128 |
}
|
- |
|
| 129 |
else{
|
- |
|
| 130 |
model.addAttribute("end",offset+limit);
|
- |
|
| 131 |
}
|
- |
|
| 132 |
return "inventory-snapshot";
|
65 |
return "inventory-snapshot";
|
| 133 |
}
|
66 |
}
|
| 134 |
|
67 |
|
| 135 |
@RequestMapping(value = "/getBadInventorySnapshot")
|
68 |
@RequestMapping(value = "/getBadInventorySnapshot")
|
| 136 |
public String getBadAvailability(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws Exception{
|
69 |
public String getBadAvailability(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws ProfitMandiBusinessException{
|
| 137 |
try {
|
- |
|
| 138 |
cookiesProcessor.getCookiesObject(request);
|
70 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 139 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 140 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
71 |
Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit, searchTerm);
|
| 141 |
return "response";
|
- |
|
| 142 |
}
|
- |
|
| 143 |
model.addAttribute("badInventorySnapshot",new ArrayList<>());
|
- |
|
| 144 |
model.addAttribute("searchTerm",searchTerm);
|
72 |
model.addAllAttributes(map);
|
| 145 |
return "bad-inventory-snapshot";
|
73 |
return "bad-inventory-snapshot";
|
| 146 |
}
|
74 |
}
|
| 147 |
|
75 |
|
| 148 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
76 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
| 149 |
public String getCurrentAvailabilityPaginated(HttpServletRequest request, @RequestParam(name = "offset", defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm , Model model) throws Exception{
|
77 |
public String getPaginatedCurrentInventorySnapshot(HttpServletRequest request, @RequestParam(name = "offset", defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm , Model model) throws ProfitMandiBusinessException{
|
| 150 |
LoginDetails fofoDetails;
|
- |
|
| 151 |
try {
|
- |
|
| 152 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
78 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 153 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 154 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 155 |
return "response";
|
- |
|
| 156 |
}
|
- |
|
| 157 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
79 |
Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit, searchTerm);
|
| 158 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
80 |
model.addAllAttributes(map);
|
| 159 |
return "inventory-snapshot-paginated";
|
81 |
return "inventory-snapshot-paginated";
|
| 160 |
}
|
82 |
}
|
| 161 |
|
83 |
|
| 162 |
@RequestMapping(value = "/getCatalog")
|
84 |
@RequestMapping(value = "/getCatalog")
|
| 163 |
public String getCatalog(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws Exception{
|
85 |
public String getCatalog(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit , @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm ,Model model) throws ProfitMandiBusinessException{
|
| 164 |
LoginDetails fofoDetails;
|
- |
|
| 165 |
try {
|
- |
|
| 166 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
86 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 167 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 168 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 169 |
return "response";
|
- |
|
| 170 |
}
|
- |
|
| 171 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
87 |
Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
| 172 |
long countItems = currentInventorySnapshotRepository.getCurrentInventorySnapshotCount(fofoDetails.getFofoId(), searchTerm);
|
- |
|
| 173 |
Set<Integer> itemIds = new HashSet<>();
|
- |
|
| 174 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots ){
|
- |
|
| 175 |
itemIds.add(currentInventorySnapshot.getItemId());
|
- |
|
| 176 |
}
|
- |
|
| 177 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
- |
|
| 178 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds);
|
- |
|
| 179 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
- |
|
| 180 |
for(InventoryItem inventoryItem : inventoryItems){
|
- |
|
| 181 |
if(inventoryItem.getSerialNumber() != null && !inventoryItem.getSerialNumber().isEmpty()){
|
- |
|
| 182 |
if(!itemIdSerialNumbers.containsKey(inventoryItem.getItemId())){
|
- |
|
| 183 |
Set<String> serialNumbers = new HashSet<>();
|
- |
|
| 184 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
- |
|
| 185 |
itemIdSerialNumbers.put(inventoryItem.getItemId(), serialNumbers);
|
- |
|
| 186 |
}else{
|
- |
|
| 187 |
itemIdSerialNumbers.get(inventoryItem.getItemId()).add(inventoryItem.getSerialNumber());
|
- |
|
| 188 |
}
|
- |
|
| 189 |
}
|
- |
|
| 190 |
}
|
- |
|
| 191 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshots);
|
- |
|
| 192 |
LOGGER.info("mopPriceMap [{}]", mopPriceMap);
|
- |
|
| 193 |
LOGGER.info("itemIdSerialNumbers [{}]", itemIdSerialNumbers);
|
- |
|
| 194 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
- |
|
| 195 |
model.addAttribute("itemIdSerialNumbers", itemIdSerialNumbers);
|
- |
|
| 196 |
model.addAttribute("start", offset + 1);
|
- |
|
| 197 |
model.addAttribute("size", countItems);
|
88 |
model.addAllAttributes(map);
|
| 198 |
model.addAttribute("searchTerm", searchTerm);
|
- |
|
| 199 |
if (currentInventorySnapshots.size() < limit){
|
- |
|
| 200 |
model.addAttribute("end", offset + currentInventorySnapshots.size());
|
- |
|
| 201 |
}
|
- |
|
| 202 |
else{
|
- |
|
| 203 |
model.addAttribute("end",offset + limit);
|
- |
|
| 204 |
}
|
- |
|
| 205 |
return "catalog";
|
89 |
return "catalog";
|
| 206 |
}
|
90 |
}
|
| 207 |
|
91 |
|
| 208 |
@RequestMapping(value = "/getPaginatedCatalog")
|
92 |
@RequestMapping(value = "/getPaginatedCatalog")
|
| 209 |
public String getCatalogPaginated(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm , Model model) throws Exception{
|
93 |
public String getCatalogPaginated(HttpServletRequest request,@RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = "searchTerm", required=false, defaultValue="") String searchTerm , Model model) throws ProfitMandiBusinessException{
|
| 210 |
LoginDetails fofoDetails;
|
- |
|
| 211 |
try {
|
- |
|
| 212 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
94 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 213 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 214 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 215 |
return "response";
|
- |
|
| 216 |
}
|
- |
|
| 217 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
95 |
Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
| 218 |
Set<Integer> itemIds = new HashSet<>();
|
- |
|
| 219 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots ){
|
- |
|
| 220 |
itemIds.add(currentInventorySnapshot.getItemId());
|
- |
|
| 221 |
}
|
- |
|
| 222 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
- |
|
| 223 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshots);
|
- |
|
| 224 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
96 |
model.addAllAttributes(map);
|
| 225 |
return "catalog-paginated";
|
97 |
return "catalog-paginated";
|
| 226 |
}
|
98 |
}
|
| 227 |
|
99 |
|
| 228 |
|
100 |
|
| 229 |
private String getVaildName(String name){
|
- |
|
| 230 |
return name!=null?name:"";
|
- |
|
| 231 |
}
|
- |
|
| 232 |
|
- |
|
| 233 |
private CustomCurrentInventorySnapshot createCustomCurrentInventorySnapshop(Object[] row)
|
- |
|
| 234 |
{
|
- |
|
| 235 |
CustomCurrentInventorySnapshot currentInventorySnapshot = new CustomCurrentInventorySnapshot();
|
- |
|
| 236 |
currentInventorySnapshot.setItemId((Integer)row[0]);
|
- |
|
| 237 |
currentInventorySnapshot.setAvailability((Integer)row[1]);
|
- |
|
| 238 |
currentInventorySnapshot.setBrand((String)row[2]);
|
- |
|
| 239 |
currentInventorySnapshot.setModelName((String)row[3]);
|
- |
|
| 240 |
currentInventorySnapshot.setModelNumber((String)row[4]);
|
- |
|
| 241 |
currentInventorySnapshot.setColor((String)row[5]);
|
- |
|
| 242 |
currentInventorySnapshot.setCatalogItemId((Integer)row[6]);
|
- |
|
| 243 |
currentInventorySnapshot.setDisplayName((getVaildName((String)row[2])+" "+getVaildName((String)row[3])+" "+getVaildName((String)row[4])+" "+getVaildName((String)row[5])).replaceAll("\\s+", " "));
|
- |
|
| 244 |
currentInventorySnapshot.setIconUrl(Utils.getIconUrl(currentInventorySnapshot.getCatalogItemId(), host, port, webapp));
|
- |
|
| 245 |
return currentInventorySnapshot;
|
- |
|
| 246 |
}
|
- |
|
| 247 |
@RequestMapping(value = "/checkItemAvailability")
|
101 |
@RequestMapping(value = "/checkItemAvailability")
|
| 248 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model) throws Exception{
|
102 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model) throws ProfitMandiBusinessException{
|
| 249 |
LoginDetails fofoDetails;
|
- |
|
| 250 |
try {
|
- |
|
| 251 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
103 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 252 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 253 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
104 |
CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId, loginDetails.getFofoId());
|
| 254 |
return "response";
|
- |
|
| 255 |
}
|
- |
|
| 256 |
try{
|
- |
|
| 257 |
Object[] row = currentInventorySnapshotRepository.selectCustomByItemIdAndFofoId(itemId, fofoDetails.getFofoId());
|
105 |
customCurrentInventorySnapshot.setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(), host, port, webapp));
|
| 258 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(this.createCustomCurrentInventorySnapshop(row)));
|
106 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
|
| 259 |
return "current-item-availability";
|
107 |
return "current-item-availability";
|
| 260 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
- |
|
| 261 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
- |
|
| 262 |
return "response";
|
- |
|
| 263 |
}
|
108 |
|
| 264 |
}
|
109 |
}
|
| 265 |
|
110 |
|
| 266 |
@RequestMapping(value = "/cart")
|
111 |
@RequestMapping(value = "/cart")
|
| 267 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
112 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
|
| 268 |
LoginDetails fofoDetails;
|
- |
|
| 269 |
try {
|
- |
|
| 270 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
113 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 271 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 272 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 273 |
return "response";
|
- |
|
| 274 |
}
|
- |
|
| 275 |
|
- |
|
| 276 |
JSONObject cartObject = new JSONObject(cartData);
|
- |
|
| 277 |
Iterator<?> keys = cartObject.keys();
|
- |
|
| 278 |
|
114 |
|
| 279 |
Set<Integer> itemIds = new HashSet<>();
|
- |
|
| 280 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
- |
|
| 281 |
|
- |
|
| 282 |
while( keys.hasNext() ) {
|
- |
|
| 283 |
String key = (String)keys.next();
|
- |
|
| 284 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
- |
|
| 285 |
System.out.println(cartObject.get(key));
|
- |
|
| 286 |
}
|
- |
|
| 287 |
CartFofo cf = new CartFofo();
|
- |
|
| 288 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
- |
|
| 289 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
- |
|
| 290 |
cf.setDisplayName(cartObject.getJSONObject(key).getString("displayName"));
|
- |
|
| 291 |
cf.setIconUrl(cartObject.getJSONObject(key).getString("iconUrl"));
|
- |
|
| 292 |
cf.setAvailability(0);
|
- |
|
| 293 |
cartItems.add(cf);
|
- |
|
| 294 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
- |
|
| 295 |
}
|
- |
|
| 296 |
if (itemIds.size() > 0){
|
- |
|
| 297 |
List<CurrentInventorySnapshot> cisList = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
115 |
Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
|
| 298 |
for (CurrentInventorySnapshot cis: cisList ){
|
- |
|
| 299 |
for (CartFofo cartItem : cartItems){
|
- |
|
| 300 |
if (cartItem.getItemId() == cis.getItem().getId()){
|
- |
|
| 301 |
cartItem.setAvailability(cis.getAvailability());
|
- |
|
| 302 |
}
|
- |
|
| 303 |
}
|
- |
|
| 304 |
}
|
- |
|
| 305 |
for (CartFofo cartItem : cartItems){
|
- |
|
| 306 |
if (cartItem.getAvailability() < cartItem.getQuantity() && cartItem.getAvailability()!=0){
|
- |
|
| 307 |
cartItem.setQuantity(cartItem.getAvailability());
|
- |
|
| 308 |
cartItem.setMessage("Item quantity changed.Less stock available");
|
- |
|
| 309 |
}
|
- |
|
| 310 |
if (cartItem.getAvailability() == 0){
|
- |
|
| 311 |
cartItem.setQuantity(0);
|
- |
|
| 312 |
cartItem.setMessage("You don't have stock for this item");
|
- |
|
| 313 |
}
|
- |
|
| 314 |
}
|
- |
|
| 315 |
}
|
- |
|
| 316 |
model.addAttribute("cartObj", cartItems);
|
116 |
model.addAllAttributes(map);
|
| 317 |
return "cart";
|
117 |
return "cart";
|
| 318 |
}
|
118 |
}
|
| 319 |
|
119 |
|
| 320 |
@RequestMapping(value = "/validate-cart")
|
120 |
@RequestMapping(value = "/validate-cart")
|
| 321 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
121 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
|
| 322 |
LoginDetails fofoDetails = null;
|
- |
|
| 323 |
try {
|
- |
|
| 324 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
122 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 325 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 326 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 327 |
return "response";
|
- |
|
| 328 |
}
|
- |
|
| 329 |
|
- |
|
| 330 |
JSONObject cartObject = new JSONObject(cartData);
|
- |
|
| 331 |
Iterator<?> keys = cartObject.keys();
|
- |
|
| 332 |
|
- |
|
| 333 |
Set<Integer> itemIds = new HashSet<>();
|
- |
|
| 334 |
List<CartFofo> cartItems = new ArrayList<CartFofo>();
|
- |
|
| 335 |
|
123 |
|
| 336 |
if (cartObject.keySet().size() == 0){
|
- |
|
| 337 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
124 |
Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
|
| 338 |
return "validate-cart";
|
- |
|
| 339 |
}
|
- |
|
| 340 |
|
- |
|
| 341 |
while( keys.hasNext() ) {
|
- |
|
| 342 |
String key = (String)keys.next();
|
- |
|
| 343 |
if ( cartObject.get(key) instanceof JSONObject ) {
|
- |
|
| 344 |
System.out.println(cartObject.get(key));
|
- |
|
| 345 |
}
|
- |
|
| 346 |
CartFofo cf = new CartFofo();
|
- |
|
| 347 |
cf.setItemId(cartObject.getJSONObject(key).getInt("itemId"));
|
- |
|
| 348 |
cf.setQuantity(cartObject.getJSONObject(key).getInt("quantity"));
|
- |
|
| 349 |
cf.setDisplayName(cartObject.getJSONObject(key).getString("displayName"));
|
- |
|
| 350 |
cf.setIconUrl(cartObject.getJSONObject(key).getString("iconUrl"));
|
- |
|
| 351 |
cf.setAvailability(0);
|
125 |
model.addAllAttributes(map);
|
| 352 |
cartItems.add(cf);
|
- |
|
| 353 |
itemIds.add(cartObject.getJSONObject(key).getInt("itemId"));
|
- |
|
| 354 |
}
|
- |
|
| 355 |
if (itemIds.size() > 0){
|
- |
|
| 356 |
List<CurrentInventorySnapshot> cisList = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
|
- |
|
| 357 |
for (CurrentInventorySnapshot cis: cisList ){
|
- |
|
| 358 |
for (CartFofo cartItem : cartItems){
|
- |
|
| 359 |
if (cartItem.getItemId() == cis.getItem().getId()){
|
- |
|
| 360 |
cartItem.setAvailability(cis.getAvailability());
|
- |
|
| 361 |
}
|
- |
|
| 362 |
}
|
- |
|
| 363 |
}
|
- |
|
| 364 |
for (CartFofo cartItem : cartItems){
|
- |
|
| 365 |
if (cartItem.getAvailability() < cartItem.getQuantity()){
|
- |
|
| 366 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
- |
|
| 367 |
return "validate-cart";
|
- |
|
| 368 |
}
|
- |
|
| 369 |
}
|
- |
|
| 370 |
}
|
- |
|
| 371 |
else{
|
- |
|
| 372 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
- |
|
| 373 |
return "validate-cart";
|
- |
|
| 374 |
}
|
- |
|
| 375 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/order", true, cartData)));
|
- |
|
| 376 |
return "validate-cart";
|
126 |
return "validate-cart";
|
| 377 |
}
|
127 |
}
|
| 378 |
|
128 |
|
| 379 |
@RequestMapping(value = "/grnHistory")
|
129 |
@RequestMapping(value = "/grnHistory")
|
| 380 |
public String grnHistoryByFofoId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE,defaultValue="") String purchaseReference, @RequestParam(name = "searchType",defaultValue="") String searchType,Model model) throws Exception{
|
130 |
public String getGrnHistory(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE,defaultValue="") String purchaseReference, @RequestParam(name = "searchType",defaultValue="") String searchType,Model model) throws ProfitMandiBusinessException{
|
| 381 |
LoginDetails fofoDetails;
|
- |
|
| 382 |
try {
|
- |
|
| 383 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
131 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 384 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 385 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 386 |
return "response";
|
- |
|
| 387 |
}
|
- |
|
| 388 |
|
- |
|
| 389 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
- |
|
| 390 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
- |
|
| 391 |
|
- |
|
| 392 |
List<Purchase> grnHistory = new ArrayList<Purchase>();
|
- |
|
| 393 |
long countItems = 0;
|
- |
|
| 394 |
if (searchType.equalsIgnoreCase("purchaseReference") && purchaseReference.trim().length() > 0){
|
- |
|
| 395 |
try{
|
- |
|
| 396 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(purchaseReference);
|
- |
|
| 397 |
grnHistory.add(purchase);
|
- |
|
| 398 |
countItems = 1;
|
- |
|
| 399 |
}
|
- |
|
| 400 |
catch(Exception | ProfitMandiBusinessException e){
|
- |
|
| 401 |
LOGGER.info("Unable to get purchase reference "+purchaseReference);
|
- |
|
| 402 |
}
|
- |
|
| 403 |
}
|
- |
|
| 404 |
else{
|
- |
|
| 405 |
grnHistory = purchaseRepository.selectByFofoId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
- |
|
| 406 |
countItems = purchaseRepository.getPurchaseCount(fofoDetails.getFofoId(), startDateTime, endDateTime, purchaseReference, searchType);
|
132 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTimeString, endTimeString, offset, limit, purchaseReference, searchType);
|
| 407 |
}
|
- |
|
| 408 |
model.addAttribute("grnHistories", grnHistory);
|
- |
|
| 409 |
model.addAttribute("start",offset+1);
|
133 |
model.addAllAttributes(map);
|
| 410 |
model.addAttribute("size",countItems);
|
- |
|
| 411 |
model.addAttribute("searchType",searchType);
|
- |
|
| 412 |
model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
|
- |
|
| 413 |
model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
|
- |
|
| 414 |
if (grnHistory.size() < limit){
|
- |
|
| 415 |
model.addAttribute("end",offset+grnHistory.size());
|
- |
|
| 416 |
}
|
- |
|
| 417 |
else{
|
- |
|
| 418 |
model.addAttribute("end",offset+limit);
|
- |
|
| 419 |
}
|
- |
|
| 420 |
return "grn-history";
|
134 |
return "grn-history";
|
| 421 |
}
|
135 |
}
|
| 422 |
|
136 |
|
| 423 |
@RequestMapping(value = "/getPaginatedGrnHistory")
|
137 |
@RequestMapping(value = "/getPaginatedGrnHistory")
|
| 424 |
public String getGrnHistoryPaginated(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE,defaultValue="") String purchaseReference, @RequestParam(name = "searchType",defaultValue="") String searchType,Model model) throws Exception{
|
138 |
public String getPaginatedGrnHistory(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE,defaultValue="") String purchaseReference, @RequestParam(name = "searchType",defaultValue="") String searchType,Model model) throws ProfitMandiBusinessException{
|
| 425 |
LoginDetails fofoDetails;
|
- |
|
| 426 |
try {
|
- |
|
| 427 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
139 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 428 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 429 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 430 |
return "response";
|
- |
|
| 431 |
}
|
- |
|
| 432 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
- |
|
| 433 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
- |
|
| 434 |
|
- |
|
| 435 |
List<Purchase> grnHistory = purchaseRepository.selectByFofoId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
140 |
Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTimeString, endTimeString, offset, limit);
|
| 436 |
model.addAttribute("grnHistories", grnHistory);
|
141 |
model.addAllAttributes(map);
|
| 437 |
return "grn-history-paginated";
|
142 |
return "grn-history-paginated";
|
| 438 |
}
|
143 |
}
|
| 439 |
|
144 |
|
| 440 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
145 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
| 441 |
public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws Exception{
|
146 |
public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws ProfitMandiBusinessException{
|
| 442 |
LoginDetails fofoDetails;
|
- |
|
| 443 |
try {
|
- |
|
| 444 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
147 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 445 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 446 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 447 |
return "response";
|
- |
|
| 448 |
}
|
- |
|
| 449 |
Purchase purchase = null;
|
- |
|
| 450 |
try {
|
- |
|
| 451 |
purchase = purchaseRepository.selectById(purchaseId);
|
- |
|
| 452 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 453 |
|
- |
|
| 454 |
}
|
- |
|
| 455 |
model.addAttribute("grnDetails", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
148 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port, webapp);
|
| 456 |
model.addAttribute("purchaseId",purchase.getId());
|
149 |
model.addAllAttributes(map);
|
| 457 |
model.addAttribute("purchaseReference",purchase.getPurchaseReference());
|
- |
|
| 458 |
return "grn-details";
|
150 |
return "grn-details";
|
| 459 |
}
|
151 |
}
|
| 460 |
|
152 |
|
| 461 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
153 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
| 462 |
public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws Exception{
|
154 |
public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws ProfitMandiBusinessException{
|
| 463 |
LoginDetails fofoDetails;
|
- |
|
| 464 |
try {
|
- |
|
| 465 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
155 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 466 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 467 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 468 |
return "response";
|
- |
|
| 469 |
}
|
- |
|
| 470 |
Purchase purchase = null;
|
- |
|
| 471 |
try {
|
- |
|
| 472 |
purchase = purchaseRepository.selectByPurchaseReference(purchaseReference);
|
- |
|
| 473 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 474 |
|
- |
|
| 475 |
}
|
- |
|
| 476 |
model.addAttribute("grnDetails", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
156 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference, host, port, webapp);
|
| 477 |
model.addAttribute("purchaseId",purchase.getId());
|
157 |
model.addAllAttributes(map);
|
| 478 |
model.addAttribute("purchaseReference",purchase.getPurchaseReference());
|
- |
|
| 479 |
return "grn-details";
|
158 |
return "grn-details";
|
| 480 |
}
|
159 |
}
|
| 481 |
|
160 |
|
| 482 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
161 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 483 |
public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit) throws Exception{
|
162 |
public String getInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model, @RequestParam(name = "searchContent", defaultValue = "") String searchContent, @RequestParam(name = "offset",defaultValue="0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit) throws ProfitMandiBusinessException{
|
| 484 |
LoginDetails fofoDetails;
|
- |
|
| 485 |
try {
|
- |
|
| 486 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
163 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 487 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 488 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 489 |
return "response";
|
- |
|
| 490 |
}
|
- |
|
| 491 |
try{
|
- |
|
| 492 |
this.validateIntervals(intervals);
|
- |
|
| 493 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 494 |
LOGGER.error("Unable to get valid interval values", e);
|
- |
|
| 495 |
return "response";
|
- |
|
| 496 |
}
|
- |
|
| 497 |
|
- |
|
| 498 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryItemAgingService.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
- |
|
| 499 |
|
164 |
|
| 500 |
if(!searchContent.isEmpty()){
|
- |
|
| 501 |
Predicate<InventoryItemAgingModel> searchContentPredicate = new Predicate<InventoryItemAgingModel>() {
|
- |
|
| 502 |
@Override
|
- |
|
| 503 |
public boolean test(InventoryItemAgingModel inventoryItemAgingModel) {
|
- |
|
| 504 |
if(!searchContent.contains(" ")){
|
- |
|
| 505 |
return this.search(inventoryItemAgingModel, searchContent);
|
- |
|
| 506 |
}else{
|
- |
|
| 507 |
String[] searchContents = searchContent.split(" ");
|
- |
|
| 508 |
for(String element : searchContents){
|
- |
|
| 509 |
return this.search(inventoryItemAgingModel, element);
|
- |
|
| 510 |
}
|
- |
|
| 511 |
}
|
- |
|
| 512 |
return false;
|
- |
|
| 513 |
}
|
- |
|
| 514 |
private boolean search(InventoryItemAgingModel inventoryItemAgingModel, String searchContent){
|
165 |
Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals, searchContent, offset, limit);
|
| 515 |
if(inventoryItemAgingModel.getBrand() != null && !inventoryItemAgingModel.getBrand().isEmpty() && inventoryItemAgingModel.getBrand().contains(searchContent)){
|
- |
|
| 516 |
return true;
|
- |
|
| 517 |
}
|
- |
|
| 518 |
if(inventoryItemAgingModel.getModelName() != null && !inventoryItemAgingModel.getModelName().isEmpty() && inventoryItemAgingModel.getModelName().contains(searchContent)){
|
- |
|
| 519 |
return true;
|
- |
|
| 520 |
}
|
- |
|
| 521 |
if(inventoryItemAgingModel.getModelNumber() != null && !inventoryItemAgingModel.getModelNumber().isEmpty() && inventoryItemAgingModel.getModelNumber().contains(searchContent)){
|
- |
|
| 522 |
return true;
|
- |
|
| 523 |
}
|
- |
|
| 524 |
if(inventoryItemAgingModel.getColor() != null && !inventoryItemAgingModel.getColor().isEmpty() && inventoryItemAgingModel.getColor().contains(searchContent)){
|
- |
|
| 525 |
return true;
|
- |
|
| 526 |
}
|
- |
|
| 527 |
return false;
|
- |
|
| 528 |
}
|
- |
|
| 529 |
};
|
- |
|
| 530 |
inventoryItemAgingModels = inventoryItemAgingModels.stream().filter(searchContentPredicate).collect(Collectors.toList());
|
- |
|
| 531 |
}
|
- |
|
| 532 |
|
- |
|
| 533 |
List<InventoryItemAgingModel> paginatedInventoryItemModels = new ArrayList<>();
|
- |
|
| 534 |
if((offset + limit) > inventoryItemAgingModels.size()){
|
- |
|
| 535 |
limit = inventoryItemAgingModels.size();
|
- |
|
| 536 |
}
|
- |
|
| 537 |
for(int index = offset; index < limit; index++){
|
- |
|
| 538 |
paginatedInventoryItemModels.add(inventoryItemAgingModels.get(index));
|
- |
|
| 539 |
}
|
- |
|
| 540 |
|
- |
|
| 541 |
model.addAttribute("inventoryItemAgingModels", paginatedInventoryItemModels);
|
- |
|
| 542 |
model.addAttribute("intervals", intervals);
|
- |
|
| 543 |
model.addAttribute("start", offset);
|
- |
|
| 544 |
model.addAttribute("size", inventoryItemAgingModels.size());
|
- |
|
| 545 |
int end = 0;
|
- |
|
| 546 |
if (paginatedInventoryItemModels.size() < limit){
|
- |
|
| 547 |
end = offset + paginatedInventoryItemModels.size();
|
- |
|
| 548 |
}else{
|
- |
|
| 549 |
end = offset + limit;
|
- |
|
| 550 |
}
|
- |
|
| 551 |
model.addAttribute("end", end);
|
166 |
model.addAllAttributes(map);
|
| 552 |
return "item-aging";
|
167 |
return "item-aging";
|
| 553 |
}
|
168 |
}
|
| 554 |
|
169 |
|
| 555 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
170 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 556 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model) throws Exception{
|
171 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException{
|
| 557 |
LoginDetails fofoDetails;
|
172 |
LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
|
| 558 |
try {
|
- |
|
| 559 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
173 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 560 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 561 |
//model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
- |
|
| 562 |
return responseSender.badRequest(e);
|
- |
|
| 563 |
}
|
174 |
|
| 564 |
try{
|
- |
|
| 565 |
this.validateIntervals(intervals);
|
- |
|
| 566 |
} catch (ProfitMandiBusinessException e) {
|
- |
|
| 567 |
LOGGER.error("Unable to get valid interval values", e);
|
175 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
| 568 |
return responseSender.badRequest(e);
|
- |
|
| 569 |
}
|
176 |
|
| 570 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryItemAgingService.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
- |
|
| 571 |
//return responseSender.ok(inventoryItemAgingModels);
|
- |
|
| 572 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
177 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
| 573 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
178 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
| 574 |
|
179 |
|
| 575 |
final HttpHeaders headers=new HttpHeaders();
|
180 |
final HttpHeaders headers=new HttpHeaders();
|
| 576 |
//private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
181 |
//private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
| Line 582... |
Line 187... |
| 582 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
187 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
| 583 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
188 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 584 |
|
189 |
|
| 585 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
190 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 586 |
}
|
191 |
}
|
| 587 |
|
- |
|
| 588 |
|
- |
|
| 589 |
private void validateIntervals(List<Integer> intervals)throws ProfitMandiBusinessException{
|
- |
|
| 590 |
if(intervals.isEmpty()){
|
- |
|
| 591 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.INTERVAL, intervals , "VE_1010");
|
- |
|
| 592 |
}
|
- |
|
| 593 |
int max = intervals.get(0);
|
- |
|
| 594 |
for(int index = 1; index < intervals.size(); index++){
|
- |
|
| 595 |
if(intervals.get(index) <= max){
|
- |
|
| 596 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.INTERVAL, intervals, "VE_1011");
|
- |
|
| 597 |
}
|
- |
|
| 598 |
max = intervals.get(index);
|
- |
|
| 599 |
}
|
- |
|
| 600 |
}
|
- |
|
| 601 |
|
- |
|
| 602 |
private Map<Integer, Map<String, Object>> grnHistoryDetails(Purchase purchase, int fofoId){
|
- |
|
| 603 |
Set<Integer> itemIds = new HashSet<>();
|
- |
|
| 604 |
Set<Item> inventoryItemDetails = new HashSet<>();
|
- |
|
| 605 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
|
- |
|
| 606 |
for(InventoryItem inventoryItem : inventoryItems){
|
- |
|
| 607 |
inventoryItemDetails.add(inventoryItem.getItem());
|
- |
|
| 608 |
itemIds.add(inventoryItem.getItemId());
|
- |
|
| 609 |
}
|
- |
|
| 610 |
|
- |
|
| 611 |
Map<Integer, Map<String, Object>> grnHistoryDetails = new HashMap<>();
|
- |
|
| 612 |
this.createGrnHistoryDetails(grnHistoryDetails, inventoryItems);
|
- |
|
| 613 |
Map<Integer, Map<String, Object>> completedItemDetails = this.toMap(inventoryItemDetails, purchase);
|
- |
|
| 614 |
|
- |
|
| 615 |
this.writeItemDetailstoGrnHistories(grnHistoryDetails, completedItemDetails);
|
- |
|
| 616 |
|
- |
|
| 617 |
if(purchase.getCompleteTimestamp() != null){
|
- |
|
| 618 |
List<Order> orders = orderRepository.selectByInvoiceNumberRetailerIdNotItemIds(purchase.getPurchaseReference(), fofoId, itemIds);
|
- |
|
| 619 |
for(Order order : orders){
|
- |
|
| 620 |
LineItem lineItem = order.getLineItem();
|
- |
|
| 621 |
//orderItemDetails.add(lineItem.getItem());
|
- |
|
| 622 |
Item item = lineItem.getItem();
|
- |
|
| 623 |
if(!grnHistoryDetails.containsKey(item.getId())){
|
- |
|
| 624 |
Map<String, Object> grnHistoryDetail = new HashMap<>();
|
- |
|
| 625 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, lineItem.getQuantity());
|
- |
|
| 626 |
grnHistoryDetail.put(ProfitMandiConstants.BRAND, item.getBrand());
|
- |
|
| 627 |
grnHistoryDetail.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
- |
|
| 628 |
grnHistoryDetail.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
|
- |
|
| 629 |
grnHistoryDetail.put(ProfitMandiConstants.COLOR, item.getColor());
|
- |
|
| 630 |
grnHistoryDetail.put(ProfitMandiConstants.CATALOG_ITEM_ID, item.getCatalogItemId());
|
- |
|
| 631 |
grnHistoryDetail.put("iconUrl",Utils.getIconUrl(item.getCatalogItemId(), host, port, webapp));
|
- |
|
| 632 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, false);
|
- |
|
| 633 |
grnHistoryDetail.put("purchaseReference", purchase.getPurchaseReference());
|
- |
|
| 634 |
if(lineItem.getSerialNumber() == null || lineItem.getSerialNumber().equals("")){
|
- |
|
| 635 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, false);
|
- |
|
| 636 |
}else{
|
- |
|
| 637 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, true);
|
- |
|
| 638 |
Set<String> serialNumbers = new HashSet<>();
|
- |
|
| 639 |
serialNumbers.add(lineItem.getSerialNumber());
|
- |
|
| 640 |
grnHistoryDetail.put(ProfitMandiConstants.SERIAL_NUMBERS, serialNumbers);
|
- |
|
| 641 |
}
|
- |
|
| 642 |
grnHistoryDetails.put(item.getId(), grnHistoryDetail);
|
- |
|
| 643 |
}else{
|
- |
|
| 644 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(item.getId());
|
- |
|
| 645 |
if((boolean)grnHistoryDetail.get(ProfitMandiConstants.SERIALIZED)){
|
- |
|
| 646 |
@SuppressWarnings("unchecked")
|
- |
|
| 647 |
Set<String> serialNumbers = (Set<String>)grnHistoryDetail.get(ProfitMandiConstants.SERIAL_NUMBERS);
|
- |
|
| 648 |
serialNumbers.add(lineItem.getSerialNumber());
|
- |
|
| 649 |
}
|
- |
|
| 650 |
}
|
- |
|
| 651 |
}
|
- |
|
| 652 |
}
|
- |
|
| 653 |
return grnHistoryDetails;
|
- |
|
| 654 |
}
|
- |
|
| 655 |
|
- |
|
| 656 |
private void writeItemDetailstoGrnHistories(Map<Integer, Map<String, Object>> grnHistoryDetails, Map<Integer, Map<String, Object>> itemDetails){
|
- |
|
| 657 |
for(int key : grnHistoryDetails.keySet()){
|
- |
|
| 658 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(key);
|
- |
|
| 659 |
grnHistoryDetail.putAll(itemDetails.get(key));
|
- |
|
| 660 |
}
|
- |
|
| 661 |
}
|
- |
|
| 662 |
|
- |
|
| 663 |
private Map<Integer, Map<String, Object>> toMap(Set<Item> items, Purchase purchase){
|
- |
|
| 664 |
Map<Integer, Map<String, Object>> map = new HashMap<>();
|
- |
|
| 665 |
for(Item item : items){
|
- |
|
| 666 |
Map<String, Object> detailMap = new HashMap<>();
|
- |
|
| 667 |
detailMap.put(ProfitMandiConstants.BRAND, item.getBrand());
|
- |
|
| 668 |
detailMap.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
- |
|
| 669 |
detailMap.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
|
- |
|
| 670 |
detailMap.put(ProfitMandiConstants.COLOR, item.getColor());
|
- |
|
| 671 |
detailMap.put(ProfitMandiConstants.CATALOG_ITEM_ID, item.getCatalogItemId());
|
- |
|
| 672 |
detailMap.put("iconUrl",Utils.getIconUrl(item.getCatalogItemId(), host, port, webapp));
|
- |
|
| 673 |
detailMap.put("purchaseReference", purchase.getPurchaseReference());
|
- |
|
| 674 |
map.put(item.getId(), detailMap);
|
- |
|
| 675 |
}
|
- |
|
| 676 |
return map;
|
- |
|
| 677 |
}
|
- |
|
| 678 |
|
- |
|
| 679 |
private void createGrnHistoryDetails(Map<Integer, Map<String, Object>> grnHistoryDetails, List<InventoryItem> inventoryItems){
|
- |
|
| 680 |
//Map<Integer, Map<String, Object>> grnHistoryDetails = new HashMap<>();
|
- |
|
| 681 |
for(InventoryItem inventoryItem : inventoryItems){
|
- |
|
| 682 |
if(!grnHistoryDetails.containsKey(inventoryItem.getItemId())){
|
- |
|
| 683 |
Map<String, Object> grnHistoryDetail = new HashMap<>();
|
- |
|
| 684 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, inventoryItem.getInitialQuantity());
|
- |
|
| 685 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, true);
|
- |
|
| 686 |
if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().equals("")){
|
- |
|
| 687 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, false);
|
- |
|
| 688 |
}else{
|
- |
|
| 689 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, true);
|
- |
|
| 690 |
Set<String> serialNumbers = new HashSet<>();
|
- |
|
| 691 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
- |
|
| 692 |
grnHistoryDetail.put(ProfitMandiConstants.SERIAL_NUMBERS, serialNumbers);
|
- |
|
| 693 |
grnHistoryDetail.put("formattedSerialNumbers", String.join(", ", serialNumbers));
|
- |
|
| 694 |
}
|
- |
|
| 695 |
grnHistoryDetails.put(inventoryItem.getItemId(), grnHistoryDetail);
|
- |
|
| 696 |
//itemIds.add(inventoryItem.getItemId());
|
- |
|
| 697 |
}else{
|
- |
|
| 698 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(inventoryItem.getItemId());
|
- |
|
| 699 |
if((boolean)grnHistoryDetail.get(ProfitMandiConstants.SERIALIZED)){
|
- |
|
| 700 |
@SuppressWarnings("unchecked")
|
- |
|
| 701 |
Set<String> serialNumbers = (Set<String>)grnHistoryDetail.get(ProfitMandiConstants.SERIAL_NUMBERS);
|
- |
|
| 702 |
LOGGER.info("serialNumbers {}", serialNumbers);
|
- |
|
| 703 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
- |
|
| 704 |
grnHistoryDetail.put("formattedSerialNumbers", String.join(", ", serialNumbers));
|
- |
|
| 705 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, (int)grnHistoryDetail.get(ProfitMandiConstants.QUANTITY) + inventoryItem.getInitialQuantity());
|
- |
|
| 706 |
}
|
- |
|
| 707 |
}
|
- |
|
| 708 |
|
- |
|
| 709 |
}
|
- |
|
| 710 |
//return null;
|
- |
|
| 711 |
}
|
- |
|
| 712 |
|
- |
|
| 713 |
public List<Item> getItemsByItemIds(Set<Integer> itemIds){
|
- |
|
| 714 |
return null;
|
- |
|
| 715 |
}
|
- |
|
| 716 |
|
192 |
|
| 717 |
}
|
193 |
}
|