| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.util.ArrayList;
|
| 3 |
import java.util.HashSet;
|
4 |
import java.util.HashSet;
|
| 4 |
import java.util.List;
|
5 |
import java.util.List;
|
| 5 |
import java.util.Set;
|
6 |
import java.util.Set;
|
| 6 |
|
7 |
|
| 7 |
import javax.servlet.http.HttpServletRequest;
|
8 |
import javax.servlet.http.HttpServletRequest;
|
| Line 18... |
Line 19... |
| 18 |
|
19 |
|
| 19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
20 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 20 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
21 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| 21 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
22 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 22 |
import com.spice.profitmandi.dao.entity.FofoItemId;
|
23 |
import com.spice.profitmandi.dao.entity.FofoItemId;
|
| - |
|
24 |
import com.spice.profitmandi.dao.entity.InventoryItem;
|
| 23 |
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
|
25 |
import com.spice.profitmandi.dao.repository.CurrentInventorySnapshotRepository;
|
| - |
|
26 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
| 24 |
import com.spice.profitmandi.web.model.FofoDetails;
|
27 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| - |
|
28 |
import com.spice.profitmandi.web.response.GrnHistory;
|
| 25 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
29 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
| 26 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
30 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 27 |
|
31 |
|
| 28 |
@Controller
|
32 |
@Controller
|
| 29 |
public class InventoryController {
|
33 |
public class InventoryController {
|
| Line 32... |
Line 36... |
| 32 |
|
36 |
|
| 33 |
@Autowired
|
37 |
@Autowired
|
| 34 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
38 |
CurrentInventorySnapshotRepository currentInventorySnapshotRepository;
|
| 35 |
|
39 |
|
| 36 |
@Autowired
|
40 |
@Autowired
|
| - |
|
41 |
InventoryItemRepository inventoryItemRepository;
|
| - |
|
42 |
|
| - |
|
43 |
@Autowired
|
| 37 |
MVCResponseSender mvcResponseSender;
|
44 |
MVCResponseSender mvcResponseSender;
|
| 38 |
|
45 |
|
| 39 |
@Autowired
|
46 |
@Autowired
|
| 40 |
CookiesFetcher cookiesFetcher;
|
47 |
CookiesFetcher cookiesFetcher;
|
| 41 |
|
48 |
|
| Line 93... |
Line 100... |
| 93 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
100 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("INVNTRY_SNPSHT", false, "/dashboard"));
|
| 94 |
return "response";
|
101 |
return "response";
|
| 95 |
}
|
102 |
}
|
| 96 |
}
|
103 |
}
|
| 97 |
|
104 |
|
| - |
|
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 |
|
| 98 |
}
|
144 |
}
|