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