| 21577 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 21636 |
ashik.ali |
3 |
import java.util.ArrayList;
|
| 21612 |
ashik.ali |
4 |
import java.util.HashSet;
|
| 21577 |
ashik.ali |
5 |
import java.util.List;
|
| 21612 |
ashik.ali |
6 |
import java.util.Set;
|
| 21577 |
ashik.ali |
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
|
|
10 |
import org.slf4j.Logger;
|
|
|
11 |
import org.slf4j.LoggerFactory;
|
|
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.ui.Model;
|
| 21581 |
ashik.ali |
15 |
import org.springframework.ui.ModelMap;
|
| 21577 |
ashik.ali |
16 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
19 |
|
|
|
20 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21612 |
ashik.ali |
21 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 21577 |
ashik.ali |
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
23 |
import com.spice.profitmandi.dao.entity.FofoItemId;
|
| 21636 |
ashik.ali |
24 |
import com.spice.profitmandi.dao.entity.InventoryItem;
|
| 21577 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
|
| 21636 |
ashik.ali |
26 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
| 21577 |
ashik.ali |
27 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 21636 |
ashik.ali |
28 |
import com.spice.profitmandi.web.response.GrnHistory;
|
| 21577 |
ashik.ali |
29 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
|
|
30 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
31 |
|
|
|
32 |
@Controller
|
|
|
33 |
public class InventoryController {
|
|
|
34 |
|
|
|
35 |
private static final Logger LOGGER = LoggerFactory.getLogger(InventoryController.class);
|
|
|
36 |
|
|
|
37 |
@Autowired
|
|
|
38 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
|
|
39 |
|
|
|
40 |
@Autowired
|
| 21636 |
ashik.ali |
41 |
InventoryItemRepository inventoryItemRepository;
|
|
|
42 |
|
|
|
43 |
@Autowired
|
| 21577 |
ashik.ali |
44 |
MVCResponseSender mvcResponseSender;
|
|
|
45 |
|
|
|
46 |
@Autowired
|
|
|
47 |
CookiesFetcher cookiesFetcher;
|
|
|
48 |
|
|
|
49 |
@RequestMapping(value = "/checkCurrentAvailability")
|
| 21581 |
ashik.ali |
50 |
public String getCurrentAvailability(HttpServletRequest request, @ModelAttribute ModelMap model) throws Exception{
|
| 21577 |
ashik.ali |
51 |
FofoDetails fofoDetails;
|
|
|
52 |
try {
|
|
|
53 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
54 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
55 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
56 |
return "response";
|
| 21577 |
ashik.ali |
57 |
}
|
| 21612 |
ashik.ali |
58 |
List<Object[]> rows = currentInventorySnapshotRepository.selectCustomByFofoId(fofoDetails.getFofoId());
|
|
|
59 |
|
|
|
60 |
model.addAttribute("currentInventorySnapshots", this.getCustomCurrentInventorySnapshots(rows));
|
|
|
61 |
return "dashboard";
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
private Set<CustomCurrentInventorySnapshot> getCustomCurrentInventorySnapshots(List<Object[]> rows){
|
|
|
65 |
Set<CustomCurrentInventorySnapshot> currentInventorySnapshots = new HashSet<>();
|
|
|
66 |
for(Object[] row : rows){
|
|
|
67 |
currentInventorySnapshots.add(this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
68 |
}
|
| 21612 |
ashik.ali |
69 |
return currentInventorySnapshots;
|
| 21577 |
ashik.ali |
70 |
}
|
|
|
71 |
|
| 21612 |
ashik.ali |
72 |
private CustomCurrentInventorySnapshot createCustomCurrentInventorySnapshop(Object[] row)
|
|
|
73 |
{
|
|
|
74 |
CustomCurrentInventorySnapshot currentInventorySnapshot = new CustomCurrentInventorySnapshot();
|
|
|
75 |
currentInventorySnapshot.setItemId((Integer)row[0]);
|
|
|
76 |
currentInventorySnapshot.setAvailability((Integer)row[1]);
|
|
|
77 |
currentInventorySnapshot.setBrand((String)row[2]);
|
|
|
78 |
currentInventorySnapshot.setModelName((String)row[3]);
|
|
|
79 |
currentInventorySnapshot.setModelNumber((String)row[4]);
|
|
|
80 |
currentInventorySnapshot.setColor((String)row[5]);
|
|
|
81 |
return currentInventorySnapshot;
|
|
|
82 |
}
|
| 21577 |
ashik.ali |
83 |
@RequestMapping(value = "/checkItemAvailability")
|
|
|
84 |
public String getItemAvailability(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ITEM_ID) int itemId, @ModelAttribute Model model) throws Exception{
|
|
|
85 |
FofoDetails fofoDetails;
|
|
|
86 |
try {
|
|
|
87 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
88 |
} catch (ProfitMandiBusinessException e) {
|
| 21581 |
ashik.ali |
89 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
90 |
return "response";
|
| 21577 |
ashik.ali |
91 |
}
|
|
|
92 |
try{
|
|
|
93 |
FofoItemId fofoItemId = new FofoItemId();
|
|
|
94 |
fofoItemId.setFofoId(fofoDetails.getFofoId());
|
|
|
95 |
fofoItemId.setItemId(itemId);
|
| 21612 |
ashik.ali |
96 |
Object[] row = currentInventorySnapshotRepository.selectCustomByFofoItemId(fofoItemId);
|
|
|
97 |
model.addAttribute("currentInventorySnapshots", this.createCustomCurrentInventorySnapshop(row));
|
| 21577 |
ashik.ali |
98 |
return "dashboard";
|
|
|
99 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
| 21581 |
ashik.ali |
100 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
|
|
101 |
return "response";
|
| 21577 |
ashik.ali |
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
| 21636 |
ashik.ali |
105 |
private List<GrnHistory> grnHistory(List<InventoryItem> inventoryItems){
|
|
|
106 |
List<GrnHistory> grnHistories = new ArrayList<>();
|
|
|
107 |
for(InventoryItem inventoryItem : inventoryItems){
|
|
|
108 |
GrnHistory searchablePurchaseReference = new GrnHistory();
|
|
|
109 |
searchablePurchaseReference.setPurchaseReference(inventoryItem.getPurchaseId());
|
|
|
110 |
if(!grnHistories.contains(searchablePurchaseReference)){
|
|
|
111 |
GrnHistory grnHistory = new GrnHistory();
|
|
|
112 |
grnHistory.setPurchaseReference(inventoryItem.getPurchaseId());
|
|
|
113 |
if(null != inventoryItem.getSerialNumber() || !inventoryItem.getSerialNumber().equals("")){
|
|
|
114 |
grnHistory.setSerializedQuantity(inventoryItem.getInitialQuantity());
|
|
|
115 |
}else{
|
|
|
116 |
grnHistory.setNonSerializedQuantity(inventoryItem.getInitialQuantity());
|
|
|
117 |
}
|
|
|
118 |
grnHistory.setTotalQuantity(grnHistory.getSerializedQuantity() + grnHistory.getNonSerializedQuantity());
|
|
|
119 |
grnHistories.add(grnHistory);
|
|
|
120 |
}else{
|
|
|
121 |
GrnHistory grnHistory = grnHistories.get(grnHistories.indexOf(searchablePurchaseReference));
|
|
|
122 |
grnHistory.setSerializedQuantity(grnHistory.getSerializedQuantity() + 1);
|
|
|
123 |
grnHistory.setNonSerializedQuantity(grnHistory.getNonSerializedQuantity() + 1);
|
|
|
124 |
grnHistory.setTotalQuantity(grnHistory.getSerializedQuantity() + grnHistory.getNonSerializedQuantity());
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
return grnHistories;
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
@RequestMapping(value = "/grnHistory")
|
|
|
131 |
public String grnHistory(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.PAGE_NUMBER) int pageNumber, @RequestParam(name = ProfitMandiConstants.PAGE_SIZE) int pageSize, Model model) throws Exception{
|
|
|
132 |
FofoDetails fofoDetails;
|
|
|
133 |
try {
|
|
|
134 |
fofoDetails = cookiesFetcher.getCookiesObject(request);
|
|
|
135 |
} catch (ProfitMandiBusinessException e) {
|
|
|
136 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
|
|
137 |
return "response";
|
|
|
138 |
}
|
|
|
139 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoId(fofoDetails.getFofoId(), pageNumber, pageSize);
|
|
|
140 |
model.addAttribute("grnHistories", this.grnHistory(inventoryItems));
|
|
|
141 |
return "";
|
|
|
142 |
}
|
|
|
143 |
|
| 21577 |
ashik.ali |
144 |
}
|