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