| 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;
|
- |
|
| 4 |
import java.util.Arrays;
|
- |
|
| 5 |
import java.util.HashSet;
|
- |
|
| 6 |
import java.util.List;
|
- |
|
| 7 |
import java.util.Set;
|
3 |
import java.util.Map;
|
| 8 |
|
4 |
|
| 9 |
import javax.servlet.http.HttpServletRequest;
|
5 |
import javax.servlet.http.HttpServletRequest;
|
| 10 |
|
6 |
|
| 11 |
import org.slf4j.Logger;
|
7 |
import org.slf4j.Logger;
|
| 12 |
import org.slf4j.LoggerFactory;
|
8 |
import org.slf4j.LoggerFactory;
|
| Line 17... |
Line 13... |
| 17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
13 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
14 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 19 |
import org.springframework.web.bind.annotation.RequestParam;
|
15 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 20 |
|
16 |
|
| 21 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 22 |
import com.spice.profitmandi.common.model.CustomItem;
|
- |
|
| 23 |
import com.spice.profitmandi.common.model.CustomLineItem;
|
- |
|
| 24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
18 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 25 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
19 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
| 26 |
import com.spice.profitmandi.dao.model.ItemIdSum;
|
- |
|
| 27 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
- |
|
| 28 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
- |
|
| 29 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
- |
|
| 30 |
import com.spice.profitmandi.web.model.LoginDetails;
|
20 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 31 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
21 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 32 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
- |
|
| 33 |
|
- |
|
| 34 |
import in.shop2020.model.v1.catalog.ItemType;
|
- |
|
| 35 |
|
22 |
|
| 36 |
@Controller
|
23 |
@Controller
|
| 37 |
@Transactional(rollbackFor=Throwable.class)
|
24 |
@Transactional(rollbackFor=Throwable.class)
|
| 38 |
public class PurchaseController {
|
25 |
public class PurchaseController {
|
| 39 |
|
26 |
|
| 40 |
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);
|
27 |
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);
|
| 41 |
|
- |
|
| 42 |
@Autowired
|
- |
|
| 43 |
OrderRepository orderRepository;
|
- |
|
| 44 |
|
28 |
|
| 45 |
@Autowired
|
29 |
@Autowired
|
| 46 |
InventoryItemRepository inventoryItemRepository;
|
30 |
private PurchaseService purchaseService;
|
| 47 |
|
31 |
|
| 48 |
@Autowired
|
32 |
@Autowired
|
| 49 |
PurchaseRepository purchaseRepository;
|
- |
|
| 50 |
|
- |
|
| 51 |
@Autowired
|
- |
|
| 52 |
MVCResponseSender mvcResponseSender;
|
- |
|
| 53 |
|
- |
|
| 54 |
@Autowired
|
- |
|
| 55 |
CookiesProcessor cookiesProcessor;
|
33 |
private CookiesProcessor cookiesProcessor;
|
| 56 |
|
34 |
|
| 57 |
@RequestMapping(value = "/purchase", method = RequestMethod.POST)
|
35 |
@RequestMapping(value = "/purchase", method = RequestMethod.POST)
|
| 58 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws Throwable{
|
36 |
public String purchaseByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws ProfitMandiBusinessException{
|
| 59 |
|
- |
|
| 60 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
37 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 61 |
List<Object[]> rows = orderRepository.selectByAirwayBillOrInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
38 |
LOGGER.info("Request Received at url {} with airwayBillOrInvoiceNumber {}", request.getRequestURI(), airwayBillOrInvoiceNumber);
|
| 62 |
Set<Integer> itemIds = new HashSet<>();
|
- |
|
| 63 |
String invoiceNumber = null;
|
- |
|
| 64 |
for(Object[] row : rows){
|
- |
|
| 65 |
LOGGER.info("row {}", Arrays.toString(row));
|
- |
|
| 66 |
itemIds.add((int)row[0]);
|
- |
|
| 67 |
invoiceNumber = (String)row[9];
|
- |
|
| 68 |
}
|
39 |
|
| 69 |
List<ItemIdSum> itemIdSums = new ArrayList<ItemIdSum>();
|
- |
|
| 70 |
try{
|
- |
|
| 71 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(invoiceNumber);
|
- |
|
| 72 |
if (purchase.getFofoId() == fofoDetails.getFofoId()){
|
- |
|
| 73 |
itemIdSums = inventoryItemRepository.selectScannedCount(itemIds, fofoDetails.getFofoId(), purchase.getId());
|
40 |
Map<String, Object> map = purchaseService.purchaseByInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
| 74 |
}
|
- |
|
| 75 |
}
|
- |
|
| 76 |
catch(ProfitMandiBusinessException e){
|
- |
|
| 77 |
//Not to worry.No purchase exists
|
- |
|
| 78 |
}
|
- |
|
| 79 |
LOGGER.info("itemIdSums : {}", itemIdSums);
|
- |
|
| 80 |
List<CustomItem> customItems = new ArrayList<>();
|
- |
|
| 81 |
for(Object[] row : rows){
|
- |
|
| 82 |
CustomItem customItem = this.createCustomLineItem(row);
|
- |
|
| 83 |
for(ItemIdSum itemIdSum : itemIdSums){
|
- |
|
| 84 |
//LOGGER.info("itemIdCount{}",Arrays.toString(itemIdCount));
|
- |
|
| 85 |
if(itemIdSum.getItemId() == (int)row[0]){
|
- |
|
| 86 |
customItem.setScanned((float)row[5] == itemIdSum.getSumOfQuantity() ? true : false);
|
- |
|
| 87 |
}
|
- |
|
| 88 |
}
|
- |
|
| 89 |
customItems.add(customItem);
|
- |
|
| 90 |
}
|
- |
|
| 91 |
model.addAttribute("customItems", customItems);
|
41 |
model.addAllAttributes(map);
|
| 92 |
model.addAttribute("invoiceNumber",invoiceNumber);
|
- |
|
| 93 |
model.addAttribute("airwayBillOrInvoiceNumber",airwayBillOrInvoiceNumber);
|
- |
|
| 94 |
return "purchase";
|
42 |
return "purchase";
|
| 95 |
}
|
43 |
}
|
| 96 |
|
44 |
|
| 97 |
@RequestMapping(value = "/purchase", method = RequestMethod.GET)
|
45 |
@RequestMapping(value = "/purchase", method = RequestMethod.GET)
|
| 98 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request) throws Exception{
|
46 |
public String purchase(HttpServletRequest request) throws Exception{
|
| 99 |
return "purchase";
|
47 |
return "purchase";
|
| 100 |
}
|
48 |
}
|
| 101 |
|
- |
|
| 102 |
private String getVaildName(String name){
|
- |
|
| 103 |
return name!=null?name:"";
|
- |
|
| 104 |
}
|
- |
|
| 105 |
|
- |
|
| 106 |
private CustomItem createCustomLineItem(Object[] row){
|
- |
|
| 107 |
LOGGER.info("row {}", Arrays.toString(row));
|
- |
|
| 108 |
CustomItem customItem = new CustomItem();
|
- |
|
| 109 |
customItem.setItemId((int)row[0]);
|
- |
|
| 110 |
CustomLineItem customLineItem = new CustomLineItem();
|
- |
|
| 111 |
customLineItem.setBrand((String)row[1]);
|
- |
|
| 112 |
customLineItem.setModelName((String)row[2]);
|
- |
|
| 113 |
customLineItem.setModelNumber((String)row[3]);
|
- |
|
| 114 |
customLineItem.setUnitPrice((float)row[6]);
|
- |
|
| 115 |
customLineItem.setColor((String)row[4]);
|
- |
|
| 116 |
customLineItem.setQuantity((float)row[5]);
|
- |
|
| 117 |
customLineItem.setDisplayName((getVaildName((String)row[1])+" "+getVaildName((String)row[2])+" "+getVaildName((String)row[3])+" "+getVaildName((String)row[4])).replaceAll("\\s+", " "));
|
- |
|
| 118 |
customItem.setItemDetail(customLineItem);
|
- |
|
| 119 |
customItem.setInvoiceNumber((String)row[9]);
|
- |
|
| 120 |
customItem.setType(((ItemType)row[7]).toString());
|
- |
|
| 121 |
return customItem;
|
- |
|
| 122 |
}
|
- |
|
| 123 |
}
|
49 |
}
|
| 124 |
|
50 |
|