| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 22486 |
ashik.ali |
3 |
import java.io.ByteArrayInputStream;
|
|
|
4 |
import java.io.ByteArrayOutputStream;
|
|
|
5 |
import java.io.InputStream;
|
| 21654 |
ashik.ali |
6 |
import java.time.LocalDateTime;
|
| 21987 |
kshitij.so |
7 |
import java.util.ArrayList;
|
| 21654 |
ashik.ali |
8 |
import java.util.HashMap;
|
| 21612 |
ashik.ali |
9 |
import java.util.HashSet;
|
| 21987 |
kshitij.so |
10 |
import java.util.Iterator;
|
| 21577 |
ashik.ali |
11 |
import java.util.List;
|
| 21654 |
ashik.ali |
12 |
import java.util.Map;
|
| 21612 |
ashik.ali |
13 |
import java.util.Set;
|
| 22523 |
ashik.ali |
14 |
import java.util.function.Predicate;
|
|
|
15 |
import java.util.stream.Collectors;
|
| 21577 |
ashik.ali |
16 |
|
|
|
17 |
import javax.servlet.http.HttpServletRequest;
|
| 21987 |
kshitij.so |
18 |
import javax.servlet.http.HttpServletResponse;
|
| 21577 |
ashik.ali |
19 |
|
| 21987 |
kshitij.so |
20 |
import org.json.JSONObject;
|
| 21577 |
ashik.ali |
21 |
import org.slf4j.Logger;
|
|
|
22 |
import org.slf4j.LoggerFactory;
|
|
|
23 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21987 |
kshitij.so |
24 |
import org.springframework.beans.factory.annotation.Value;
|
| 22486 |
ashik.ali |
25 |
import org.springframework.core.io.InputStreamResource;
|
|
|
26 |
import org.springframework.http.HttpHeaders;
|
|
|
27 |
import org.springframework.http.HttpStatus;
|
| 22472 |
ashik.ali |
28 |
import org.springframework.http.ResponseEntity;
|
| 21577 |
ashik.ali |
29 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
30 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
31 |
import org.springframework.ui.Model;
|
| 22472 |
ashik.ali |
32 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21577 |
ashik.ali |
33 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 22472 |
ashik.ali |
34 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21577 |
ashik.ali |
35 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
36 |
|
| 21987 |
kshitij.so |
37 |
import com.google.gson.Gson;
|
| 21577 |
ashik.ali |
38 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21987 |
kshitij.so |
39 |
import com.spice.profitmandi.common.model.CartFofo;
|
| 21612 |
ashik.ali |
40 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 22472 |
ashik.ali |
41 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 22581 |
ashik.ali |
42 |
import com.spice.profitmandi.common.model.PriceModel;
|
| 21577 |
ashik.ali |
43 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22472 |
ashik.ali |
44 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 21654 |
ashik.ali |
45 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 21987 |
kshitij.so |
46 |
import com.spice.profitmandi.common.util.Utils;
|
| 22472 |
ashik.ali |
47 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| 21728 |
ashik.ali |
48 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 21987 |
kshitij.so |
49 |
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
|
| 21728 |
ashik.ali |
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;
|
| 22472 |
ashik.ali |
59 |
import com.spice.profitmandi.service.aging.InventoryItemAgingService;
|
| 22354 |
ashik.ali |
60 |
import com.spice.profitmandi.service.pricing.PricingService;
|
| 22139 |
amit.gupta |
61 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 21987 |
kshitij.so |
62 |
import com.spice.profitmandi.web.response.ValidateCart;
|
| 22069 |
ashik.ali |
63 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 21577 |
ashik.ali |
64 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
65 |
|
|
|
66 |
@Controller
|
| 22037 |
amit.gupta |
67 |
@Transactional(rollbackFor=Throwable.class)
|
| 21577 |
ashik.ali |
68 |
public class InventoryController {
|
| 21987 |
kshitij.so |
69 |
|
| 21577 |
ashik.ali |
70 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
| 21987 |
kshitij.so |
71 |
|
| 21577 |
ashik.ali |
72 |
@Autowired
|
|
|
73 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 21987 |
kshitij.so |
74 |
|
| 21577 |
ashik.ali |
75 |
@Autowired
|
| 21636 |
ashik.ali |
76 |
InventoryItemRepository inventoryItemRepository;
|
| 21987 |
kshitij.so |
77 |
|
| 21636 |
ashik.ali |
78 |
@Autowired
|
| 21654 |
ashik.ali |
79 |
PurchaseRepository purchaseRepository;
|
| 21987 |
kshitij.so |
80 |
|
| 21654 |
ashik.ali |
81 |
@Autowired
|
|
|
82 |
ItemRepository itemRepository;
|
| 21987 |
kshitij.so |
83 |
|
| 21654 |
ashik.ali |
84 |
@Autowired
|
|
|
85 |
OrderRepository orderRepository;
|
| 21987 |
kshitij.so |
86 |
|
| 21654 |
ashik.ali |
87 |
@Autowired
|
| 21577 |
ashik.ali |
88 |
MVCResponseSender mvcResponseSender;
|
| 21987 |
kshitij.so |
89 |
|
| 21577 |
ashik.ali |
90 |
@Autowired
|
| 22069 |
ashik.ali |
91 |
CookiesProcessor cookiesProcessor;
|
| 21577 |
ashik.ali |
92 |
|
| 22354 |
ashik.ali |
93 |
@Autowired
|
|
|
94 |
PricingService pricingService;
|
|
|
95 |
|
| 22472 |
ashik.ali |
96 |
@Autowired
|
|
|
97 |
InventoryItemAgingService inventoryItemAgingService;
|
|
|
98 |
|
|
|
99 |
@Autowired
|
|
|
100 |
ResponseSender<?> responseSender;
|
|
|
101 |
|
| 21987 |
kshitij.so |
102 |
@Value("${saholic.api.host}")
|
|
|
103 |
private String host;
|
|
|
104 |
@Value("${saholic.api.port}")
|
|
|
105 |
private int port;
|
|
|
106 |
@Value("${saholic.api.webapp}")
|
|
|
107 |
private String webapp;
|
|
|
108 |
|
|
|
109 |
|
|
|
110 |
@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{
|
| 22139 |
amit.gupta |
112 |
LoginDetails fofoDetails;
|
| 21577 |
ashik.ali |
113 |
try {
|
| 22069 |
ashik.ali |
114 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21577 |
ashik.ali |
115 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
116 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
117 |
return "response";
|
| 21577 |
ashik.ali |
118 |
}
|
| 21987 |
kshitij.so |
119 |
List<CurrentInventorySnapshot> currentInventorySnapshot = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
| 22354 |
ashik.ali |
120 |
|
| 21987 |
kshitij.so |
121 |
long countItems = currentInventorySnapshotRepository.getCurrentInventorySnapshotCount(fofoDetails.getFofoId(), searchTerm);
|
|
|
122 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
|
|
123 |
model.addAttribute("start",offset+1);
|
|
|
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";
|
| 21612 |
ashik.ali |
133 |
}
|
| 21987 |
kshitij.so |
134 |
|
|
|
135 |
@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{
|
|
|
137 |
try {
|
| 22472 |
ashik.ali |
138 |
cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
139 |
} catch (ProfitMandiBusinessException e) {
|
|
|
140 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
141 |
return "response";
|
|
|
142 |
}
|
|
|
143 |
model.addAttribute("badInventorySnapshot",new ArrayList<>());
|
|
|
144 |
model.addAttribute("searchTerm",searchTerm);
|
|
|
145 |
return "bad-inventory-snapshot";
|
|
|
146 |
}
|
|
|
147 |
|
|
|
148 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot")
|
| 22523 |
ashik.ali |
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{
|
| 22139 |
amit.gupta |
150 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
151 |
try {
|
| 22069 |
ashik.ali |
152 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
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);
|
|
|
158 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshot);
|
|
|
159 |
return "inventory-snapshot-paginated";
|
|
|
160 |
}
|
| 21612 |
ashik.ali |
161 |
|
| 21987 |
kshitij.so |
162 |
@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{
|
| 22139 |
amit.gupta |
164 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
165 |
try {
|
| 22069 |
ashik.ali |
166 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
167 |
} catch (ProfitMandiBusinessException e) {
|
|
|
168 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
169 |
return "response";
|
|
|
170 |
}
|
| 22354 |
ashik.ali |
171 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
| 21987 |
kshitij.so |
172 |
long countItems = currentInventorySnapshotRepository.getCurrentInventorySnapshotCount(fofoDetails.getFofoId(), searchTerm);
|
| 22354 |
ashik.ali |
173 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
174 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots ){
|
| 22860 |
ashik.ali |
175 |
itemIds.add(currentInventorySnapshot.getItemId());
|
| 21987 |
kshitij.so |
176 |
}
|
| 22581 |
ashik.ali |
177 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
| 22354 |
ashik.ali |
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);
|
|
|
198 |
model.addAttribute("searchTerm", searchTerm);
|
|
|
199 |
if (currentInventorySnapshots.size() < limit){
|
|
|
200 |
model.addAttribute("end", offset + currentInventorySnapshots.size());
|
|
|
201 |
}
|
| 21987 |
kshitij.so |
202 |
else{
|
| 22354 |
ashik.ali |
203 |
model.addAttribute("end",offset + limit);
|
| 21987 |
kshitij.so |
204 |
}
|
|
|
205 |
return "catalog";
|
|
|
206 |
}
|
|
|
207 |
|
|
|
208 |
@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{
|
| 22139 |
amit.gupta |
210 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
211 |
try {
|
| 22069 |
ashik.ali |
212 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
213 |
} catch (ProfitMandiBusinessException e) {
|
|
|
214 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
215 |
return "response";
|
|
|
216 |
}
|
| 22354 |
ashik.ali |
217 |
List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.getCurrentInventorySnapshot(fofoDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
218 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
219 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots ){
|
| 22860 |
ashik.ali |
220 |
itemIds.add(currentInventorySnapshot.getItemId());
|
| 22354 |
ashik.ali |
221 |
}
|
| 22581 |
ashik.ali |
222 |
Map<Integer, PriceModel> mopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
| 22354 |
ashik.ali |
223 |
model.addAttribute("currentInventorySnapshot",currentInventorySnapshots);
|
|
|
224 |
model.addAttribute("mopPriceMap", mopPriceMap);
|
| 21987 |
kshitij.so |
225 |
return "catalog-paginated";
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
|
|
|
229 |
private String getVaildName(String name){
|
|
|
230 |
return name!=null?name:"";
|
|
|
231 |
}
|
|
|
232 |
|
| 21612 |
ashik.ali |
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]);
|
| 21987 |
kshitij.so |
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));
|
| 21612 |
ashik.ali |
245 |
return currentInventorySnapshot;
|
|
|
246 |
}
|
| 21577 |
ashik.ali |
247 |
@RequestMapping(value = "/checkItemAvailability")
|
| 21987 |
kshitij.so |
248 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model) throws Exception{
|
| 22139 |
amit.gupta |
249 |
LoginDetails fofoDetails;
|
| 21577 |
ashik.ali |
250 |
try {
|
| 22069 |
ashik.ali |
251 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21577 |
ashik.ali |
252 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
253 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
254 |
return "response";
|
| 21577 |
ashik.ali |
255 |
}
|
|
|
256 |
try{
|
| 22860 |
ashik.ali |
257 |
Object[] row = currentInventorySnapshotRepository.selectCustomByItemIdAndFofoId(itemId, fofoDetails.getFofoId());
|
| 21987 |
kshitij.so |
258 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(this.createCustomCurrentInventorySnapshop(row)));
|
|
|
259 |
return "current-item-availability";
|
| 21577 |
ashik.ali |
260 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21581 |
ashik.ali |
261 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
|
|
262 |
return "response";
|
| 21577 |
ashik.ali |
263 |
}
|
|
|
264 |
}
|
|
|
265 |
|
| 21987 |
kshitij.so |
266 |
@RequestMapping(value = "/cart")
|
|
|
267 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| 22139 |
amit.gupta |
268 |
LoginDetails fofoDetails;
|
| 21654 |
ashik.ali |
269 |
try {
|
| 22069 |
ashik.ali |
270 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21654 |
ashik.ali |
271 |
} catch (ProfitMandiBusinessException e) {
|
|
|
272 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
273 |
return "response";
|
| 21636 |
ashik.ali |
274 |
}
|
| 21657 |
ashik.ali |
275 |
|
| 21987 |
kshitij.so |
276 |
JSONObject cartObject = new JSONObject(cartData);
|
|
|
277 |
Iterator<?> keys = cartObject.keys();
|
|
|
278 |
|
|
|
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);
|
|
|
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);
|
|
|
317 |
return "cart";
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
@RequestMapping(value = "/validate-cart")
|
|
|
321 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "cartData") String cartData, Model model) throws Exception{
|
| 22139 |
amit.gupta |
322 |
LoginDetails fofoDetails = null;
|
| 21987 |
kshitij.so |
323 |
try {
|
| 22069 |
ashik.ali |
324 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
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 |
|
|
|
336 |
if (cartObject.keySet().size() == 0){
|
|
|
337 |
model.addAttribute("validateCartResponse",new Gson().toJson(new ValidateCart("POST", "/cart", false, cartData)));
|
|
|
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);
|
|
|
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";
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
@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{
|
| 22139 |
amit.gupta |
381 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
382 |
try {
|
| 22069 |
ashik.ali |
383 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
384 |
} catch (ProfitMandiBusinessException e) {
|
|
|
385 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
386 |
return "response";
|
|
|
387 |
}
|
|
|
388 |
|
| 21654 |
ashik.ali |
389 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
390 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
391 |
|
| 21987 |
kshitij.so |
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);
|
|
|
407 |
}
|
|
|
408 |
model.addAttribute("grnHistories", grnHistory);
|
|
|
409 |
model.addAttribute("start",offset+1);
|
|
|
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";
|
| 21636 |
ashik.ali |
421 |
}
|
| 21987 |
kshitij.so |
422 |
|
|
|
423 |
@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{
|
| 22139 |
amit.gupta |
425 |
LoginDetails fofoDetails;
|
| 21987 |
kshitij.so |
426 |
try {
|
| 22069 |
ashik.ali |
427 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
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);
|
|
|
436 |
model.addAttribute("grnHistories", grnHistory);
|
|
|
437 |
return "grn-history-paginated";
|
|
|
438 |
}
|
|
|
439 |
|
| 21654 |
ashik.ali |
440 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
|
|
441 |
public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws Exception{
|
| 22139 |
amit.gupta |
442 |
LoginDetails fofoDetails;
|
| 21636 |
ashik.ali |
443 |
try {
|
| 22069 |
ashik.ali |
444 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21636 |
ashik.ali |
445 |
} catch (ProfitMandiBusinessException e) {
|
|
|
446 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
447 |
return "response";
|
|
|
448 |
}
|
| 21654 |
ashik.ali |
449 |
Purchase purchase = null;
|
|
|
450 |
try {
|
|
|
451 |
purchase = purchaseRepository.selectById(purchaseId);
|
|
|
452 |
} catch (ProfitMandiBusinessException e) {
|
| 21987 |
kshitij.so |
453 |
|
| 21654 |
ashik.ali |
454 |
}
|
| 21987 |
kshitij.so |
455 |
model.addAttribute("grnDetails", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
|
|
456 |
model.addAttribute("purchaseId",purchase.getId());
|
|
|
457 |
model.addAttribute("purchaseReference",purchase.getPurchaseReference());
|
|
|
458 |
return "grn-details";
|
| 21636 |
ashik.ali |
459 |
}
|
| 21987 |
kshitij.so |
460 |
|
| 21654 |
ashik.ali |
461 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
|
|
462 |
public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws Exception{
|
| 22139 |
amit.gupta |
463 |
LoginDetails fofoDetails;
|
| 21654 |
ashik.ali |
464 |
try {
|
| 22069 |
ashik.ali |
465 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 21654 |
ashik.ali |
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) {
|
| 21987 |
kshitij.so |
474 |
|
| 21654 |
ashik.ali |
475 |
}
|
| 21987 |
kshitij.so |
476 |
model.addAttribute("grnDetails", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
|
|
477 |
model.addAttribute("purchaseId",purchase.getId());
|
|
|
478 |
model.addAttribute("purchaseReference",purchase.getPurchaseReference());
|
|
|
479 |
return "grn-details";
|
| 21654 |
ashik.ali |
480 |
}
|
| 22472 |
ashik.ali |
481 |
|
|
|
482 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 22523 |
ashik.ali |
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{
|
| 22472 |
ashik.ali |
484 |
LoginDetails fofoDetails;
|
|
|
485 |
try {
|
|
|
486 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
487 |
} catch (ProfitMandiBusinessException e) {
|
| 22523 |
ashik.ali |
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 |
|
|
|
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){
|
|
|
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);
|
|
|
552 |
return "item-aging";
|
|
|
553 |
}
|
|
|
554 |
|
|
|
555 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
|
|
556 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model) throws Exception{
|
|
|
557 |
LoginDetails fofoDetails;
|
|
|
558 |
try {
|
|
|
559 |
fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
560 |
} catch (ProfitMandiBusinessException e) {
|
| 22472 |
ashik.ali |
561 |
//model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
562 |
return responseSender.badRequest(e);
|
|
|
563 |
}
|
|
|
564 |
try{
|
|
|
565 |
this.validateIntervals(intervals);
|
|
|
566 |
} catch (ProfitMandiBusinessException e) {
|
|
|
567 |
LOGGER.error("Unable to get valid interval values", e);
|
|
|
568 |
return responseSender.badRequest(e);
|
|
|
569 |
}
|
|
|
570 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryItemAgingService.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
|
|
571 |
//return responseSender.ok(inventoryItemAgingModels);
|
| 22486 |
ashik.ali |
572 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
573 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
|
|
574 |
|
|
|
575 |
final HttpHeaders headers=new HttpHeaders();
|
|
|
576 |
//private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
577 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
578 |
//headers.set("Content-Type", "application/vnd.ms-excel");
|
|
|
579 |
headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
|
|
|
580 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
581 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
582 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
|
|
583 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
584 |
|
|
|
585 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 22472 |
ashik.ali |
586 |
}
|
|
|
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 |
}
|
| 21987 |
kshitij.so |
601 |
|
| 21654 |
ashik.ali |
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);
|
| 21987 |
kshitij.so |
613 |
Map<Integer, Map<String, Object>> completedItemDetails = this.toMap(inventoryItemDetails, purchase);
|
|
|
614 |
|
| 21654 |
ashik.ali |
615 |
this.writeItemDetailstoGrnHistories(grnHistoryDetails, completedItemDetails);
|
| 21987 |
kshitij.so |
616 |
|
| 22860 |
ashik.ali |
617 |
if(purchase.getCompleteTimestamp() != null){
|
| 21680 |
ashik.ali |
618 |
List<Order> orders = orderRepository.selectByInvoiceNumberRetailerIdNotItemIds(purchase.getPurchaseReference(), fofoId, itemIds);
|
| 21654 |
ashik.ali |
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());
|
| 21987 |
kshitij.so |
630 |
grnHistoryDetail.put(ProfitMandiConstants.CATALOG_ITEM_ID, item.getCatalogItemId());
|
|
|
631 |
grnHistoryDetail.put("iconUrl",Utils.getIconUrl(item.getCatalogItemId(), host, port, webapp));
|
| 21654 |
ashik.ali |
632 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, false);
|
| 21987 |
kshitij.so |
633 |
grnHistoryDetail.put("purchaseReference", purchase.getPurchaseReference());
|
| 21654 |
ashik.ali |
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);
|
| 21987 |
kshitij.so |
648 |
serialNumbers.add(lineItem.getSerialNumber());
|
| 21654 |
ashik.ali |
649 |
}
|
|
|
650 |
}
|
|
|
651 |
}
|
|
|
652 |
}
|
|
|
653 |
return grnHistoryDetails;
|
|
|
654 |
}
|
| 21987 |
kshitij.so |
655 |
|
| 21654 |
ashik.ali |
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 |
}
|
| 21987 |
kshitij.so |
662 |
|
|
|
663 |
private Map<Integer, Map<String, Object>> toMap(Set<Item> items, Purchase purchase){
|
| 21654 |
ashik.ali |
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());
|
| 21987 |
kshitij.so |
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());
|
| 21654 |
ashik.ali |
674 |
map.put(item.getId(), detailMap);
|
|
|
675 |
}
|
|
|
676 |
return map;
|
|
|
677 |
}
|
| 21987 |
kshitij.so |
678 |
|
| 21654 |
ashik.ali |
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);
|
| 22244 |
ashik.ali |
693 |
grnHistoryDetail.put("formattedSerialNumbers", String.join(", ", serialNumbers));
|
| 21654 |
ashik.ali |
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);
|
| 21987 |
kshitij.so |
703 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
| 22244 |
ashik.ali |
704 |
grnHistoryDetail.put("formattedSerialNumbers", String.join(", ", serialNumbers));
|
| 21654 |
ashik.ali |
705 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, (int)grnHistoryDetail.get(ProfitMandiConstants.QUANTITY) + inventoryItem.getInitialQuantity());
|
|
|
706 |
}
|
|
|
707 |
}
|
| 21987 |
kshitij.so |
708 |
|
| 21654 |
ashik.ali |
709 |
}
|
|
|
710 |
//return null;
|
|
|
711 |
}
|
| 21987 |
kshitij.so |
712 |
|
| 21654 |
ashik.ali |
713 |
public List<Item> getItemsByItemIds(Set<Integer> itemIds){
|
|
|
714 |
return null;
|
|
|
715 |
}
|
| 21987 |
kshitij.so |
716 |
|
| 21577 |
ashik.ali |
717 |
}
|