| 21561 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
| 21555 |
kshitij.so |
2 |
|
| 21583 |
ashik.ali |
3 |
import java.util.ArrayList;
|
| 21615 |
kshitij.so |
4 |
import java.util.Arrays;
|
| 21583 |
ashik.ali |
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Set;
|
|
|
8 |
|
| 21574 |
ashik.ali |
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
|
|
11 |
import org.slf4j.Logger;
|
|
|
12 |
import org.slf4j.LoggerFactory;
|
|
|
13 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21555 |
kshitij.so |
14 |
import org.springframework.stereotype.Controller;
|
| 21574 |
ashik.ali |
15 |
import org.springframework.ui.Model;
|
| 21615 |
kshitij.so |
16 |
import org.springframework.web.bind.annotation.ModelAttribute;
|
| 21555 |
kshitij.so |
17 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
18 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 21583 |
ashik.ali |
19 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21555 |
kshitij.so |
20 |
|
| 21583 |
ashik.ali |
21 |
import com.spice.profitmandi.common.model.CustomItem;
|
|
|
22 |
import com.spice.profitmandi.common.model.CustomLineItem;
|
|
|
23 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
| 21574 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.repository.OrderRepository;
|
|
|
26 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 21582 |
kshitij.so |
27 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
| 21574 |
ashik.ali |
28 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21555 |
kshitij.so |
29 |
|
| 21583 |
ashik.ali |
30 |
import in.shop2020.model.v1.catalog.ItemType;
|
|
|
31 |
|
| 21555 |
kshitij.so |
32 |
@Controller
|
| 21582 |
kshitij.so |
33 |
public class PurchaseController {
|
| 21555 |
kshitij.so |
34 |
|
| 21582 |
kshitij.so |
35 |
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);
|
| 21615 |
kshitij.so |
36 |
|
| 21574 |
ashik.ali |
37 |
@Autowired
|
|
|
38 |
OrderRepository orderRepository;
|
| 21615 |
kshitij.so |
39 |
|
| 21574 |
ashik.ali |
40 |
@Autowired
|
| 21583 |
ashik.ali |
41 |
InventoryItemRepository inventoryItemRepository;
|
| 21615 |
kshitij.so |
42 |
|
| 21582 |
kshitij.so |
43 |
@Autowired
|
| 21574 |
ashik.ali |
44 |
MVCResponseSender mvcResponseSender;
|
| 21615 |
kshitij.so |
45 |
|
| 21583 |
ashik.ali |
46 |
@Autowired
|
|
|
47 |
CookiesFetcher cookiesFetcher;
|
| 21615 |
kshitij.so |
48 |
|
| 21591 |
kshitij.so |
49 |
@RequestMapping(value = "/purchase", method = RequestMethod.POST)
|
| 21587 |
kshitij.so |
50 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws Throwable{
|
| 21582 |
kshitij.so |
51 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 21583 |
ashik.ali |
52 |
List<Object[]> rows = orderRepository.selectByAirwayBillOrInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
|
|
53 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
54 |
String invoiceNumber = null;
|
|
|
55 |
for(Object[] row : rows){
|
| 21615 |
kshitij.so |
56 |
LOGGER.info("row {}", Arrays.toString(row));
|
| 21583 |
ashik.ali |
57 |
itemIds.add((int)row[0]);
|
|
|
58 |
invoiceNumber = (String)row[9];
|
|
|
59 |
}
|
|
|
60 |
List<Object[]> itemIdCounts = inventoryItemRepository.selectScannedCount(itemIds, fofoDetails.getFofoId(), invoiceNumber);
|
|
|
61 |
List<CustomItem> customItems = new ArrayList<>();
|
| 21615 |
kshitij.so |
62 |
for(Object[] row : rows){
|
|
|
63 |
CustomItem customItem = this.createCustomLineItem(row);
|
|
|
64 |
for(Object[] itemIdCount : itemIdCounts){
|
|
|
65 |
LOGGER.info("itemIdCount{}",Arrays.toString(itemIdCount));
|
| 21583 |
ashik.ali |
66 |
if((int)itemIdCount[0] == (int)row[0]){
|
| 21615 |
kshitij.so |
67 |
customItem.setScanned((float)row[5] == (long)itemIdCount[1] ? true : false);
|
| 21583 |
ashik.ali |
68 |
}
|
|
|
69 |
}
|
| 21615 |
kshitij.so |
70 |
customItems.add(customItem);
|
| 21583 |
ashik.ali |
71 |
}
|
|
|
72 |
model.addAttribute("customItems", customItems);
|
| 21615 |
kshitij.so |
73 |
model.addAttribute("invoiceNumber",invoiceNumber);
|
|
|
74 |
model.addAttribute("airwayBillOrInvoiceNumber",airwayBillOrInvoiceNumber);
|
| 21587 |
kshitij.so |
75 |
return "purchase";
|
| 21555 |
kshitij.so |
76 |
}
|
| 21615 |
kshitij.so |
77 |
|
| 21587 |
kshitij.so |
78 |
@RequestMapping(value = "/purchase", method = RequestMethod.GET)
|
|
|
79 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request) throws Exception{
|
|
|
80 |
return "purchase";
|
|
|
81 |
}
|
| 21583 |
ashik.ali |
82 |
|
| 21615 |
kshitij.so |
83 |
private String getVaildName(String name){
|
|
|
84 |
return name!=null?name:"";
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
private CustomItem createCustomLineItem(Object[] row){
|
|
|
88 |
LOGGER.info("row {}", Arrays.toString(row));
|
| 21583 |
ashik.ali |
89 |
CustomItem customItem = new CustomItem();
|
|
|
90 |
customItem.setItemId((int)row[0]);
|
|
|
91 |
CustomLineItem customLineItem = new CustomLineItem();
|
|
|
92 |
customLineItem.setBrand((String)row[1]);
|
|
|
93 |
customLineItem.setModelName((String)row[2]);
|
|
|
94 |
customLineItem.setModelNumber((String)row[3]);
|
|
|
95 |
customLineItem.setColor((String)row[4]);
|
|
|
96 |
customLineItem.setQuantity((float)row[5]);
|
|
|
97 |
customLineItem.setUnitPrice((float)row[6]);
|
| 21615 |
kshitij.so |
98 |
customLineItem.setDisplayName((getVaildName((String)row[1])+" "+getVaildName((String)row[2])+" "+getVaildName((String)row[3])+" "+getVaildName((String)row[4])).replaceAll("\\s+", " "));
|
| 21583 |
ashik.ali |
99 |
customItem.setItemDetail(customLineItem);
|
| 21615 |
kshitij.so |
100 |
customItem.setInvoiceNumber((String)row[9]);
|
|
|
101 |
customItem.setType(((ItemType)row[7]).toString());
|
| 21583 |
ashik.ali |
102 |
return customItem;
|
| 21582 |
kshitij.so |
103 |
}
|
| 21615 |
kshitij.so |
104 |
|
| 21555 |
kshitij.so |
105 |
}
|