| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21654 |
ashik.ali |
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.HashMap;
|
| 21612 |
ashik.ali |
5 |
import java.util.HashSet;
|
| 21577 |
ashik.ali |
6 |
import java.util.List;
|
| 21654 |
ashik.ali |
7 |
import java.util.Map;
|
| 21612 |
ashik.ali |
8 |
import java.util.Set;
|
| 21577 |
ashik.ali |
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
|
|
11 |
|
|
|
12 |
import org.slf4j.Logger;
|
|
|
13 |
import org.slf4j.LoggerFactory;
|
|
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
15 |
import org.springframework.stereotype.Controller;
|
| 21654 |
ashik.ali |
16 |
import org.springframework.transaction.annotation.Transactional;
|
| 21577 |
ashik.ali |
17 |
import org.springframework.ui.Model;
|
| 21581 |
ashik.ali |
18 |
import org.springframework.ui.ModelMap;
|
| 21577 |
ashik.ali |
19 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
22 |
|
|
|
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
24 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 21577 |
ashik.ali |
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21654 |
ashik.ali |
26 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 21577 |
ashik.ali |
27 |
import com.spice.profitmandi.dao.entity.FofoItemId;
|
| 21636 |
ashik.ali |
28 |
import com.spice.profitmandi.dao.entity.InventoryItem;
|
| 21654 |
ashik.ali |
29 |
import com.spice.profitmandi.dao.entity.Item;
|
|
|
30 |
import com.spice.profitmandi.dao.entity.LineItem;
|
|
|
31 |
import com.spice.profitmandi.dao.entity.Order;
|
|
|
32 |
import com.spice.profitmandi.dao.entity.Purchase;
|
| 21577 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
|
| 21636 |
ashik.ali |
34 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
| 21654 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.repository.ItemRepository;
|
|
|
36 |
import com.spice.profitmandi.dao.repository.OrderRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.PurchaseRepository;
|
| 21577 |
ashik.ali |
38 |
import com.spice.profitmandi.web.model.FofoDetails;
|
|
|
39 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
|
|
40 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
41 |
|
|
|
42 |
@Controller
|
| 21654 |
ashik.ali |
43 |
@Transactional
|
| 21577 |
ashik.ali |
44 |
public class InventoryController {
|
|
|
45 |
|
|
|
46 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
|
|
47 |
|
|
|
48 |
@Autowired
|
|
|
49 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
50 |
|
|
|
51 |
@Autowired
|
| 21636 |
ashik.ali |
52 |
InventoryItemRepository inventoryItemRepository;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
| 21654 |
ashik.ali |
55 |
PurchaseRepository purchaseRepository;
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
ItemRepository itemRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
OrderRepository orderRepository;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
| 21577 |
ashik.ali |
64 |
MVCResponseSender mvcResponseSender;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
|
|
67 |
CookiesFetcher cookiesFetcher;
|
|
|
68 |
|
|
|
69 |
@RequestMapping(value = "/checkCurrentAvailability")
|
| 21581 |
ashik.ali |
70 |
public String getCurrentAvailability(HttpServletRequest request, @ModelAttribute ModelMap model) throws Exception{
|
| 21577 |
ashik.ali |
71 |
FofoDetails fofoDetails;
|
|
|
72 |
try {
|
|
|
73 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
74 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
75 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
76 |
return "response";
|
| 21577 |
ashik.ali |
77 |
}
|
| 21612 |
ashik.ali |
78 |
List<Object[]> rows = currentInventorySnapshotRepository.selectCustomByFofoId(fofoDetails.getFofoId());
|
|
|
79 |
|
|
|
80 |
model.addAttribute("currentInventorySnapshots", this.getCustomCurrentInventorySnapshots(rows));
|
|
|
81 |
return "dashboard";
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
private Set<CustomCurrentInventorySnapshot> getCustomCurrentInventorySnapshots(List<Object[]> rows){
|
|
|
85 |
Set<CustomCurrentInventorySnapshot> currentInventorySnapshots = new HashSet<>();
|
|
|
86 |
for(Object[] row : rows){
|
|
|
87 |
currentInventorySnapshots.add(this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
88 |
}
|
| 21612 |
ashik.ali |
89 |
return currentInventorySnapshots;
|
| 21577 |
ashik.ali |
90 |
}
|
|
|
91 |
|
| 21612 |
ashik.ali |
92 |
private CustomCurrentInventorySnapshot createCustomCurrentInventorySnapshop(Object[] row)
|
|
|
93 |
{
|
|
|
94 |
CustomCurrentInventorySnapshot currentInventorySnapshot = new CustomCurrentInventorySnapshot();
|
|
|
95 |
currentInventorySnapshot.setItemId((Integer)row[0]);
|
|
|
96 |
currentInventorySnapshot.setAvailability((Integer)row[1]);
|
|
|
97 |
currentInventorySnapshot.setBrand((String)row[2]);
|
|
|
98 |
currentInventorySnapshot.setModelName((String)row[3]);
|
|
|
99 |
currentInventorySnapshot.setModelNumber((String)row[4]);
|
|
|
100 |
currentInventorySnapshot.setColor((String)row[5]);
|
|
|
101 |
return currentInventorySnapshot;
|
|
|
102 |
}
|
| 21577 |
ashik.ali |
103 |
@RequestMapping(value = "/checkItemAvailability")
|
|
|
104 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
|
|
|
105 |
FofoDetails fofoDetails;
|
|
|
106 |
try {
|
|
|
107 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
108 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
109 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
110 |
return "response";
|
| 21577 |
ashik.ali |
111 |
}
|
|
|
112 |
try{
|
|
|
113 |
FofoItemId fofoItemId = new FofoItemId();
|
|
|
114 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
|
|
115 |
fofoItemId.setItemId(itemId);
|
| 21612 |
ashik.ali |
116 |
Object[] row = currentInventorySnapshotRepository.selectCustomByFofoItemId(fofoItemId);
|
|
|
117 |
model.addAttribute("currentInventorySnapshots", this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
118 |
return "dashboard";
|
|
|
119 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21581 |
ashik.ali |
120 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
|
|
121 |
return "response";
|
| 21577 |
ashik.ali |
122 |
}
|
|
|
123 |
}
|
|
|
124 |
|
| 21654 |
ashik.ali |
125 |
@RequestMapping(value = "/grnHistoryByFofoId")
|
| 21657 |
ashik.ali |
126 |
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 = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize, Model model) throws Exception{
|
| 21654 |
ashik.ali |
127 |
FofoDetails fofoDetails;
|
|
|
128 |
try {
|
|
|
129 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
130 |
} catch (ProfitMandiBusinessException e) {
|
|
|
131 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
132 |
return "response";
|
| 21636 |
ashik.ali |
133 |
}
|
| 21657 |
ashik.ali |
134 |
|
| 21654 |
ashik.ali |
135 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
136 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
137 |
|
|
|
138 |
model.addAttribute("grnHistories", purchaseRepository.selectByFofoId(fofoDetails.getFofoId(), startDateTime, endDateTime, pageNumber, pageSize));
|
|
|
139 |
return "";
|
| 21636 |
ashik.ali |
140 |
}
|
|
|
141 |
|
| 21654 |
ashik.ali |
142 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseId")
|
|
|
143 |
public String grnHistoryByPurchaseId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_ID) int purchaseId, Model model) throws Exception{
|
| 21636 |
ashik.ali |
144 |
FofoDetails fofoDetails;
|
|
|
145 |
try {
|
|
|
146 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
147 |
} catch (ProfitMandiBusinessException e) {
|
|
|
148 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
149 |
return "response";
|
|
|
150 |
}
|
| 21654 |
ashik.ali |
151 |
Purchase purchase = null;
|
|
|
152 |
try {
|
|
|
153 |
purchase = purchaseRepository.selectById(purchaseId);
|
|
|
154 |
} catch (ProfitMandiBusinessException e) {
|
|
|
155 |
|
|
|
156 |
}
|
|
|
157 |
model.addAttribute("grnHistories", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
| 21636 |
ashik.ali |
158 |
return "";
|
|
|
159 |
}
|
|
|
160 |
|
| 21654 |
ashik.ali |
161 |
@RequestMapping(value = "/grnHistoryDetailByPurchaseReference")
|
|
|
162 |
public String grnHistoryByPurchaseReference(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PURCHASE_REFERENCE) String purchaseReference, Model model) throws Exception{
|
|
|
163 |
FofoDetails fofoDetails;
|
|
|
164 |
try {
|
|
|
165 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
166 |
} catch (ProfitMandiBusinessException e) {
|
|
|
167 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
168 |
return "response";
|
|
|
169 |
}
|
|
|
170 |
Purchase purchase = null;
|
|
|
171 |
try {
|
|
|
172 |
purchase = purchaseRepository.selectByPurchaseReference(purchaseReference);
|
|
|
173 |
} catch (ProfitMandiBusinessException e) {
|
|
|
174 |
|
|
|
175 |
}
|
|
|
176 |
model.addAttribute("grnHistories", this.grnHistoryDetails(purchase, fofoDetails.getFofoId()));
|
|
|
177 |
return "";
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
private Map<Integer, Map<String, Object>> grnHistoryDetails(Purchase purchase, int fofoId){
|
|
|
181 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
182 |
Set<Item> inventoryItemDetails = new HashSet<>();
|
|
|
183 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchase.getId());
|
|
|
184 |
for(InventoryItem inventoryItem : inventoryItems){
|
|
|
185 |
inventoryItemDetails.add(inventoryItem.getItem());
|
|
|
186 |
itemIds.add(inventoryItem.getItemId());
|
|
|
187 |
}
|
|
|
188 |
|
|
|
189 |
Map<Integer, Map<String, Object>> grnHistoryDetails = new HashMap<>();
|
|
|
190 |
this.createGrnHistoryDetails(grnHistoryDetails, inventoryItems);
|
|
|
191 |
Map<Integer, Map<String, Object>> completedItemDetails = this.toMap(inventoryItemDetails);
|
|
|
192 |
|
|
|
193 |
this.writeItemDetailstoGrnHistories(grnHistoryDetails, completedItemDetails);
|
|
|
194 |
|
|
|
195 |
if(!purchase.isCompleted()){
|
|
|
196 |
List<Order> orders = orderRepository.selectByInvoiceNumber(purchase.getPurchaseReference(), fofoId, itemIds);
|
|
|
197 |
for(Order order : orders){
|
|
|
198 |
LineItem lineItem = order.getLineItem();
|
|
|
199 |
//orderItemDetails.add(lineItem.getItem());
|
|
|
200 |
Item item = lineItem.getItem();
|
|
|
201 |
if(!grnHistoryDetails.containsKey(item.getId())){
|
|
|
202 |
Map<String, Object> grnHistoryDetail = new HashMap<>();
|
|
|
203 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, lineItem.getQuantity());
|
|
|
204 |
grnHistoryDetail.put(ProfitMandiConstants.BRAND, item.getBrand());
|
|
|
205 |
grnHistoryDetail.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
|
|
206 |
grnHistoryDetail.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
|
|
|
207 |
grnHistoryDetail.put(ProfitMandiConstants.COLOR, item.getColor());
|
|
|
208 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, false);
|
|
|
209 |
if(lineItem.getSerialNumber() == null || lineItem.getSerialNumber().equals("")){
|
|
|
210 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, false);
|
|
|
211 |
}else{
|
|
|
212 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, true);
|
|
|
213 |
Set<String> serialNumbers = new HashSet<>();
|
|
|
214 |
serialNumbers.add(lineItem.getSerialNumber());
|
|
|
215 |
grnHistoryDetail.put(ProfitMandiConstants.SERIAL_NUMBERS, serialNumbers);
|
|
|
216 |
}
|
|
|
217 |
grnHistoryDetails.put(item.getId(), grnHistoryDetail);
|
|
|
218 |
}else{
|
|
|
219 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(item.getId());
|
|
|
220 |
if((boolean)grnHistoryDetail.get(ProfitMandiConstants.SERIALIZED)){
|
|
|
221 |
@SuppressWarnings("unchecked")
|
|
|
222 |
Set<String> serialNumbers = (Set<String>)grnHistoryDetail.get(ProfitMandiConstants.SERIAL_NUMBERS);
|
|
|
223 |
serialNumbers.add(lineItem.getSerialNumber());
|
|
|
224 |
}
|
|
|
225 |
}
|
|
|
226 |
}
|
|
|
227 |
}
|
|
|
228 |
return grnHistoryDetails;
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
private void writeItemDetailstoGrnHistories(Map<Integer, Map<String, Object>> grnHistoryDetails, Map<Integer, Map<String, Object>> itemDetails){
|
|
|
232 |
for(int key : grnHistoryDetails.keySet()){
|
|
|
233 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(key);
|
|
|
234 |
grnHistoryDetail.putAll(itemDetails.get(key));
|
|
|
235 |
}
|
|
|
236 |
}
|
|
|
237 |
|
|
|
238 |
private Map<Integer, Map<String, Object>> toMap(Set<Item> items){
|
|
|
239 |
Map<Integer, Map<String, Object>> map = new HashMap<>();
|
|
|
240 |
for(Item item : items){
|
|
|
241 |
Map<String, Object> detailMap = new HashMap<>();
|
|
|
242 |
detailMap.put(ProfitMandiConstants.BRAND, item.getBrand());
|
|
|
243 |
detailMap.put(ProfitMandiConstants.MODEL_NAME, item.getModelName());
|
|
|
244 |
detailMap.put(ProfitMandiConstants.MODEL_NUMBER, item.getModelNumber());
|
|
|
245 |
detailMap.put(ProfitMandiConstants.COLOR, item.getColor());
|
|
|
246 |
map.put(item.getId(), detailMap);
|
|
|
247 |
}
|
|
|
248 |
return map;
|
|
|
249 |
}
|
|
|
250 |
|
|
|
251 |
private void createGrnHistoryDetails(Map<Integer, Map<String, Object>> grnHistoryDetails, List<InventoryItem> inventoryItems){
|
|
|
252 |
//Map<Integer, Map<String, Object>> grnHistoryDetails = new HashMap<>();
|
|
|
253 |
for(InventoryItem inventoryItem : inventoryItems){
|
|
|
254 |
if(!grnHistoryDetails.containsKey(inventoryItem.getItemId())){
|
|
|
255 |
Map<String, Object> grnHistoryDetail = new HashMap<>();
|
|
|
256 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, inventoryItem.getInitialQuantity());
|
|
|
257 |
grnHistoryDetail.put(ProfitMandiConstants.COMPLETED, true);
|
|
|
258 |
if(inventoryItem.getSerialNumber() == null || inventoryItem.getSerialNumber().equals("")){
|
|
|
259 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, false);
|
|
|
260 |
}else{
|
|
|
261 |
grnHistoryDetail.put(ProfitMandiConstants.SERIALIZED, true);
|
|
|
262 |
Set<String> serialNumbers = new HashSet<>();
|
|
|
263 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
|
|
264 |
grnHistoryDetail.put(ProfitMandiConstants.SERIAL_NUMBERS, serialNumbers);
|
|
|
265 |
}
|
|
|
266 |
grnHistoryDetails.put(inventoryItem.getItemId(), grnHistoryDetail);
|
|
|
267 |
//itemIds.add(inventoryItem.getItemId());
|
|
|
268 |
}else{
|
|
|
269 |
Map<String, Object> grnHistoryDetail = grnHistoryDetails.get(inventoryItem.getItemId());
|
|
|
270 |
if((boolean)grnHistoryDetail.get(ProfitMandiConstants.SERIALIZED)){
|
|
|
271 |
@SuppressWarnings("unchecked")
|
|
|
272 |
Set<String> serialNumbers = (Set<String>)grnHistoryDetail.get(ProfitMandiConstants.SERIAL_NUMBERS);
|
|
|
273 |
LOGGER.info("serialNumbers {}", serialNumbers);
|
|
|
274 |
serialNumbers.add(inventoryItem.getSerialNumber());
|
|
|
275 |
grnHistoryDetail.put(ProfitMandiConstants.QUANTITY, (int)grnHistoryDetail.get(ProfitMandiConstants.QUANTITY) + inventoryItem.getInitialQuantity());
|
|
|
276 |
}
|
|
|
277 |
}
|
|
|
278 |
|
|
|
279 |
}
|
|
|
280 |
//return null;
|
|
|
281 |
}
|
|
|
282 |
|
|
|
283 |
public List<Item> getItemsByItemIds(Set<Integer> itemIds){
|
|
|
284 |
return null;
|
|
|
285 |
}
|
|
|
286 |
|
|
|
287 |
/*@RequestMapping(value = "/grnHist")
|
|
|
288 |
public String grnHist(HttpServletRequest request) throws Exception{
|
|
|
289 |
LOGGER.info("result {}", orderRepository.selectByInvoiceNumber("58400149931", 963490));
|
|
|
290 |
return null;
|
|
|
291 |
}*/
|
|
|
292 |
|
|
|
293 |
@RequestMapping(value = "/grnHist")
|
|
|
294 |
public String grnHist(HttpServletRequest request ) throws Exception{
|
|
|
295 |
Purchase purchase = null;
|
|
|
296 |
try {
|
|
|
297 |
purchase = purchaseRepository.selectById(2);
|
|
|
298 |
} catch (ProfitMandiBusinessException e) {
|
|
|
299 |
// TODO Auto-generated catch block
|
|
|
300 |
e.printStackTrace();
|
|
|
301 |
}
|
|
|
302 |
LOGGER.info("grnHistoryDetails {}", StringUtils.toString(this.grnHistoryDetails(purchase, 963490)));
|
|
|
303 |
return null;
|
|
|
304 |
}
|
|
|
305 |
|
| 21577 |
ashik.ali |
306 |
}
|