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