| 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;
|
| 21577 |
ashik.ali |
6 |
import java.util.List;
|
| 21654 |
ashik.ali |
7 |
import java.util.Map;
|
| 21577 |
ashik.ali |
8 |
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
| 21987 |
kshitij.so |
10 |
import javax.servlet.http.HttpServletResponse;
|
| 21577 |
ashik.ali |
11 |
|
| 23568 |
govind |
12 |
import org.apache.logging.log4j.Logger;
|
|
|
13 |
import org.apache.logging.log4j.LogManager;
|
| 21577 |
ashik.ali |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23784 |
ashik.ali |
15 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 21987 |
kshitij.so |
16 |
import org.springframework.beans.factory.annotation.Value;
|
| 22486 |
ashik.ali |
17 |
import org.springframework.core.io.InputStreamResource;
|
|
|
18 |
import org.springframework.http.HttpHeaders;
|
|
|
19 |
import org.springframework.http.HttpStatus;
|
| 22472 |
ashik.ali |
20 |
import org.springframework.http.ResponseEntity;
|
| 21577 |
ashik.ali |
21 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
22 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
23 |
import org.springframework.ui.Model;
|
| 22472 |
ashik.ali |
24 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 21577 |
ashik.ali |
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 22472 |
ashik.ali |
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21577 |
ashik.ali |
27 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
28 |
|
| 21987 |
kshitij.so |
29 |
import com.google.gson.Gson;
|
| 21577 |
ashik.ali |
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
31 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 22472 |
ashik.ali |
32 |
import com.spice.profitmandi.common.model.InventoryItemAgingModel;
|
| 21577 |
ashik.ali |
33 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22472 |
ashik.ali |
34 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 21987 |
kshitij.so |
35 |
import com.spice.profitmandi.common.util.Utils;
|
| 22927 |
ashik.ali |
36 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 22139 |
amit.gupta |
37 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 22069 |
ashik.ali |
38 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 21577 |
ashik.ali |
39 |
|
|
|
40 |
@Controller
|
| 22037 |
amit.gupta |
41 |
@Transactional(rollbackFor=Throwable.class)
|
| 21577 |
ashik.ali |
42 |
public class InventoryController {
|
| 21987 |
kshitij.so |
43 |
|
| 23568 |
govind |
44 |
private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
|
| 21987 |
kshitij.so |
45 |
|
| 21577 |
ashik.ali |
46 |
@Autowired
|
| 22927 |
ashik.ali |
47 |
private CookiesProcessor cookiesProcessor;
|
| 21577 |
ashik.ali |
48 |
|
| 22354 |
ashik.ali |
49 |
@Autowired
|
| 23784 |
ashik.ali |
50 |
@Qualifier("fofoInventoryService")
|
| 22927 |
ashik.ali |
51 |
private InventoryService inventoryService;
|
| 22354 |
ashik.ali |
52 |
|
| 21987 |
kshitij.so |
53 |
@Value("${saholic.api.host}")
|
|
|
54 |
private String host;
|
| 22927 |
ashik.ali |
55 |
|
| 21987 |
kshitij.so |
56 |
@Value("${saholic.api.port}")
|
|
|
57 |
private int port;
|
| 22927 |
ashik.ali |
58 |
|
| 21987 |
kshitij.so |
59 |
@Value("${saholic.api.webapp}")
|
|
|
60 |
private String webapp;
|
|
|
61 |
|
| 23784 |
ashik.ali |
62 |
@RequestMapping(value = "/getCurrentInventorySnapshot", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
63 |
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{
|
|
|
64 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
65 |
Map<String, Object> map = inventoryService.getCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
66 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
67 |
return "inventory-snapshot";
|
| 21612 |
ashik.ali |
68 |
}
|
| 21987 |
kshitij.so |
69 |
|
| 23784 |
ashik.ali |
70 |
@RequestMapping(value = "/getBadInventorySnapshot", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
71 |
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{
|
|
|
72 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
73 |
Map<String, Object> map = inventoryService.getBadInventorySnapshot(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
74 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
75 |
return "bad-inventory-snapshot";
|
|
|
76 |
}
|
|
|
77 |
|
| 23784 |
ashik.ali |
78 |
@RequestMapping(value = "/getPaginatedCurrentInventorySnapshot", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
79 |
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{
|
|
|
80 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
81 |
Map<String, Object> map = inventoryService.getPaginatedCurrentInventorySnapshot(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
82 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
83 |
return "inventory-snapshot-paginated";
|
|
|
84 |
}
|
| 21612 |
ashik.ali |
85 |
|
| 23784 |
ashik.ali |
86 |
@RequestMapping(value = "/getCatalog", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
87 |
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{
|
|
|
88 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
89 |
Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
90 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
91 |
return "catalog";
|
|
|
92 |
}
|
|
|
93 |
|
| 23784 |
ashik.ali |
94 |
@RequestMapping(value = "/getPaginatedCatalog", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
95 |
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{
|
|
|
96 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
97 |
Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
|
|
|
98 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
99 |
return "catalog-paginated";
|
|
|
100 |
}
|
|
|
101 |
|
|
|
102 |
|
| 23784 |
ashik.ali |
103 |
@RequestMapping(value = "/checkItemAvailability", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
104 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, Model model) throws ProfitMandiBusinessException{
|
|
|
105 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
106 |
CustomCurrentInventorySnapshot customCurrentInventorySnapshot = inventoryService.checkItemAvailability(itemId, loginDetails.getFofoId());
|
| 23376 |
amit.gupta |
107 |
customCurrentInventorySnapshot.setIconUrl(Utils.getIconUrl(customCurrentInventorySnapshot.getCatalogItemId(), host, port, webapp));
|
| 22927 |
ashik.ali |
108 |
model.addAttribute("currentInventorySnapshot", new Gson().toJson(customCurrentInventorySnapshot));
|
|
|
109 |
return "current-item-availability";
|
|
|
110 |
|
| 21577 |
ashik.ali |
111 |
}
|
|
|
112 |
|
| 23192 |
ashik.ali |
113 |
@RequestMapping(value = "/cart", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
114 |
public String addToCart(HttpServletRequest request, @RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
|
|
|
115 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 21657 |
ashik.ali |
116 |
|
| 22927 |
ashik.ali |
117 |
Map<String, Object> map = inventoryService.addToCart(cartData, loginDetails.getFofoId());
|
|
|
118 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
119 |
return "cart";
|
|
|
120 |
}
|
|
|
121 |
|
| 23192 |
ashik.ali |
122 |
@RequestMapping(value = "/validate-cart", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
123 |
public String validateCart(HttpServletRequest request, HttpServletResponse response,@RequestParam(name = "cartData") String cartData, Model model) throws ProfitMandiBusinessException{
|
|
|
124 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 21987 |
kshitij.so |
125 |
|
| 22927 |
ashik.ali |
126 |
Map<String, Object> map = inventoryService.validateCart(cartData, loginDetails.getFofoId());
|
|
|
127 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
128 |
return "validate-cart";
|
|
|
129 |
}
|
|
|
130 |
|
| 23784 |
ashik.ali |
131 |
@RequestMapping(value = "/grnHistory", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
132 |
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{
|
|
|
133 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
134 |
Map<String, Object> map = inventoryService.getGrnHistory(loginDetails.getFofoId(), startTimeString, endTimeString, offset, limit, purchaseReference, searchType);
|
|
|
135 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
136 |
return "grn-history";
|
| 21636 |
ashik.ali |
137 |
}
|
| 21987 |
kshitij.so |
138 |
|
| 23784 |
ashik.ali |
139 |
@RequestMapping(value = "/getPaginatedGrnHistory", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
140 |
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{
|
|
|
141 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
142 |
Map<String, Object> map = inventoryService.getPaginatedGrnHistory(loginDetails.getFofoId(), startTimeString, endTimeString, offset, limit);
|
|
|
143 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
144 |
return "grn-history-paginated";
|
|
|
145 |
}
|
|
|
146 |
|
| 23784 |
ashik.ali |
147 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
148 |
public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws ProfitMandiBusinessException{
|
|
|
149 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
150 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseId, host, port, webapp);
|
|
|
151 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
152 |
return "grn-details";
|
| 21636 |
ashik.ali |
153 |
}
|
| 21987 |
kshitij.so |
154 |
|
| 23784 |
ashik.ali |
155 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
156 |
public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws ProfitMandiBusinessException{
|
|
|
157 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
158 |
Map<String, Object> map = inventoryService.getGrnHistoryDetail(loginDetails.getFofoId(), purchaseReference, host, port, webapp);
|
|
|
159 |
model.addAllAttributes(map);
|
| 21987 |
kshitij.so |
160 |
return "grn-details";
|
| 21654 |
ashik.ali |
161 |
}
|
| 22472 |
ashik.ali |
162 |
|
|
|
163 |
@RequestMapping(value = "/getInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
164 |
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{
|
|
|
165 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
166 |
Map<String, Object> map = inventoryService.getPaginatedItemAgingByInterval(loginDetails.getFofoId(), intervals, searchContent, offset, limit);
|
|
|
167 |
model.addAllAttributes(map);
|
| 22523 |
ashik.ali |
168 |
return "item-aging";
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
@RequestMapping(value = "/downloadInventoryItemAgingByInterval", method = RequestMethod.POST)
|
| 22927 |
ashik.ali |
172 |
public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request, @RequestBody List<Integer> intervals, Model model) throws ProfitMandiBusinessException{
|
|
|
173 |
LOGGER.info("Request received at url{} with body {}", request.getRequestURI(), intervals);
|
|
|
174 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
175 |
|
|
|
176 |
List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService.getItemAgingByInterval(fofoDetails.getFofoId(), intervals);
|
|
|
177 |
|
| 22486 |
ashik.ali |
178 |
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
|
|
|
179 |
ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
|
|
|
180 |
|
|
|
181 |
final HttpHeaders headers=new HttpHeaders();
|
|
|
182 |
//private static final String CONTENT_TYPE_XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
|
|
|
183 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
|
|
184 |
//headers.set("Content-Type", "application/vnd.ms-excel");
|
|
|
185 |
headers.set("Content-disposition", "inline; filename=InventoryItemAging.xlsx");
|
|
|
186 |
headers.setContentLength(byteArrayOutputStream.toByteArray().length);
|
|
|
187 |
final InputStream inputStream=new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
|
|
|
188 |
final InputStreamResource inputStreamResource=new InputStreamResource(inputStream);
|
|
|
189 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
|
|
190 |
|
|
|
191 |
//return responseSender.ok(ResponseCodeHolder.getMessage("ITM_AGNG_OK_1000"));
|
| 22472 |
ashik.ali |
192 |
}
|
| 21987 |
kshitij.so |
193 |
|
| 21577 |
ashik.ali |
194 |
}
|