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