| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
4 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
5 |
import com.spice.profitmandi.common.model.ScanSerializedRequest;
|
| 5 |
import com.spice.profitmandi.common.web.client.RestClient;
|
6 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| - |
|
7 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
8 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 6 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
9 |
import com.spice.profitmandi.dao.entity.transaction.Order;
|
| - |
|
10 |
import com.spice.profitmandi.dao.model.ImeiInoviceModel;
|
| - |
|
11 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| 7 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
12 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 8 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
13 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 9 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
14 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
| 10 |
import com.spice.profitmandi.service.transaction.invoicing.InvoiceService;
|
15 |
import com.spice.profitmandi.service.transaction.invoicing.InvoiceService;
|
| 11 |
import com.spice.profitmandi.web.model.LoginDetails;
|
16 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| Line 22... |
Line 27... |
| 22 |
import org.springframework.http.MediaType;
|
27 |
import org.springframework.http.MediaType;
|
| 23 |
import org.springframework.http.ResponseEntity;
|
28 |
import org.springframework.http.ResponseEntity;
|
| 24 |
import org.springframework.stereotype.Controller;
|
29 |
import org.springframework.stereotype.Controller;
|
| 25 |
import org.springframework.transaction.annotation.Transactional;
|
30 |
import org.springframework.transaction.annotation.Transactional;
|
| 26 |
import org.springframework.ui.Model;
|
31 |
import org.springframework.ui.Model;
|
| 27 |
import org.springframework.web.bind.annotation.PathVariable;
|
- |
|
| 28 |
import org.springframework.web.bind.annotation.RequestMapping;
|
- |
|
| 29 |
import org.springframework.web.bind.annotation.RequestMethod;
|
- |
|
| 30 |
import org.springframework.web.bind.annotation.RequestParam;
|
32 |
import org.springframework.web.bind.annotation.*;
|
| 31 |
|
33 |
|
| 32 |
import javax.servlet.http.HttpServletRequest;
|
34 |
import javax.servlet.http.HttpServletRequest;
|
| 33 |
import java.io.ByteArrayInputStream;
|
35 |
import java.io.ByteArrayInputStream;
|
| 34 |
import java.io.ByteArrayOutputStream;
|
36 |
import java.io.ByteArrayOutputStream;
|
| 35 |
import java.io.File;
|
37 |
import java.io.File;
|
| Line 50... |
Line 52... |
| 50 |
|
52 |
|
| 51 |
@Autowired
|
53 |
@Autowired
|
| 52 |
private PurchaseService purchaseService;
|
54 |
private PurchaseService purchaseService;
|
| 53 |
|
55 |
|
| 54 |
@Autowired
|
56 |
@Autowired
|
| - |
|
57 |
private InventoryItemRepository inventoryItemRepository;
|
| - |
|
58 |
|
| - |
|
59 |
@Autowired
|
| 55 |
private OrderRepository orderRepository;
|
60 |
private OrderRepository orderRepository;
|
| 56 |
|
61 |
|
| 57 |
@Autowired
|
62 |
@Autowired
|
| 58 |
RestClient restClient;
|
63 |
RestClient restClient;
|
| 59 |
@Autowired
|
64 |
@Autowired
|
| 60 |
private RoleManager roleManager;
|
65 |
private RoleManager roleManager;
|
| 61 |
|
66 |
|
| 62 |
@Autowired
|
67 |
@Autowired
|
| - |
|
68 |
private ResponseSender responseSender;
|
| - |
|
69 |
|
| - |
|
70 |
@Autowired
|
| 63 |
private CookiesProcessor cookiesProcessor;
|
71 |
private CookiesProcessor cookiesProcessor;
|
| 64 |
|
72 |
|
| 65 |
@Autowired
|
73 |
@Autowired
|
| 66 |
private InvoiceService invoiceService;
|
74 |
private InvoiceService invoiceService;
|
| 67 |
|
75 |
|
| Line 77... |
Line 85... |
| 77 |
List<Order> pendingGrns = orderRepository.selectShipmentToDeliveredByRetailerId(fofoDetails.getFofoId());
|
85 |
List<Order> pendingGrns = orderRepository.selectShipmentToDeliveredByRetailerId(fofoDetails.getFofoId());
|
| 78 |
model.addAttribute("pendingGrns", pendingGrns);
|
86 |
model.addAttribute("pendingGrns", pendingGrns);
|
| 79 |
return "pending-grn";
|
87 |
return "pending-grn";
|
| 80 |
}
|
88 |
}
|
| 81 |
|
89 |
|
| - |
|
90 |
@RequestMapping(value = "/purchase/validate-imeis", method = RequestMethod.POST)
|
| - |
|
91 |
public ResponseEntity<?> validatePurchaseImeis(HttpServletRequest request, @RequestBody ImeiInoviceModel imeiInoviceModel, Model model) throws ProfitMandiBusinessException {
|
| - |
|
92 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
93 |
return responseSender.ok(this.getImeiValidationMap(fofoDetails.getFofoId(), imeiInoviceModel));
|
| - |
|
94 |
}
|
| - |
|
95 |
|
| - |
|
96 |
private Map<String, Boolean> getImeiValidationMap(int fofoId, ImeiInoviceModel imeiInoviceModel) throws ProfitMandiBusinessException {
|
| - |
|
97 |
LOGGER.info("serialNumbers - {}", imeiInoviceModel.getSerialNumbers());
|
| - |
|
98 |
Set<String> serialNumbers = new HashSet<>(orderRepository.selectSerialNumbers(imeiInoviceModel.getInvoiceNumber(), fofoId, imeiInoviceModel.getSerialNumbers()));
|
| - |
|
99 |
Map<String, Boolean> imeiValidationMap = new HashMap<>();
|
| - |
|
100 |
imeiInoviceModel.getSerialNumbers().stream().forEach(x -> {
|
| - |
|
101 |
imeiValidationMap.put(x, null);
|
| - |
|
102 |
});
|
| - |
|
103 |
if (serialNumbers.size() > 0) {
|
| - |
|
104 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoId, new HashSet<>(serialNumbers), false);
|
| - |
|
105 |
Set<String> grnedSerialNumberSet = inventoryItems.stream().map(x -> x.getSerialNumber()).collect(Collectors.toSet());
|
| - |
|
106 |
imeiInoviceModel.getSerialNumbers().stream().forEach(x -> {
|
| - |
|
107 |
imeiValidationMap.put(x, serialNumbers.contains(x) && !grnedSerialNumberSet.contains(x));
|
| - |
|
108 |
});
|
| - |
|
109 |
}
|
| - |
|
110 |
return imeiValidationMap;
|
| - |
|
111 |
}
|
| - |
|
112 |
|
| - |
|
113 |
@RequestMapping(value = "/purchase/grn-imeis", method = RequestMethod.POST)
|
| - |
|
114 |
public ResponseEntity<?> grnImeis(HttpServletRequest request, @RequestBody ImeiInoviceModel imeiInoviceModel, Model model) throws ProfitMandiBusinessException {
|
| - |
|
115 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
116 |
Map<String, Boolean> imeiValidationMap = this.getImeiValidationMap(fofoDetails.getFofoId(), imeiInoviceModel);
|
| - |
|
117 |
if (imeiValidationMap.values().stream().filter(x -> !x).findFirst().isPresent()) {
|
| - |
|
118 |
throw new ProfitMandiBusinessException("Found invalid imeis cant proceed", "invalid imeis", "invalid imeis");
|
| - |
|
119 |
}
|
| - |
|
120 |
|
| - |
|
121 |
Map<Integer, List<String>> itemSerialNumberMap = orderRepository.selectItemSerialNumberMap(imeiInoviceModel.getInvoiceNumber(), fofoDetails.getFofoId(), imeiInoviceModel.getSerialNumbers());
|
| - |
|
122 |
for (Map.Entry<Integer, List<String>> itemSerialNumberEntry : itemSerialNumberMap.entrySet()) {
|
| - |
|
123 |
ScanSerializedRequest scanSerializedRequest = new ScanSerializedRequest();
|
| - |
|
124 |
scanSerializedRequest.setSerialNumbers(itemSerialNumberEntry.getValue());
|
| - |
|
125 |
scanSerializedRequest.setInvoiceNumber(imeiInoviceModel.getInvoiceNumber());
|
| - |
|
126 |
scanSerializedRequest.setItemId(itemSerialNumberEntry.getKey());
|
| - |
|
127 |
purchaseService.scanSerializedItems(scanSerializedRequest, fofoDetails.getFofoId());
|
| - |
|
128 |
}
|
| - |
|
129 |
return responseSender.ok(true);
|
| - |
|
130 |
}
|
| - |
|
131 |
|
| - |
|
132 |
|
| 82 |
@RequestMapping(value = "/pendingGrnDetails", method = RequestMethod.GET)
|
133 |
@RequestMapping(value = "/pendingGrnDetails", method = RequestMethod.GET)
|
| 83 |
public String pendingGrnDetails(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException {
|
134 |
public String pendingGrnDetails(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.ORDER_ID) int orderId, Model model) throws ProfitMandiBusinessException {
|
| 84 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
135 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 85 |
LOGGER.info("Request Received at url [{}] with orderId [{}]", request.getRequestURI(), orderId);
|
136 |
LOGGER.info("Request Received at url [{}] with orderId [{}]", request.getRequestURI(), orderId);
|
| 86 |
model.addAttribute("pendingGrnDetails", purchaseService.getShippingDetailByOrderId(orderId, fofoDetails.getFofoId()));
|
137 |
model.addAttribute("pendingGrnDetails", purchaseService.getShippingDetailByOrderId(orderId, fofoDetails.getFofoId()));
|