| 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;
|
| 21636 |
ashik.ali |
15 |
import org.springframework.transaction.annotation.Transactional;
|
| 21574 |
ashik.ali |
16 |
import org.springframework.ui.Model;
|
| 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 |
|
| 21640 |
kshitij.so |
21 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 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;
|
| 21728 |
ashik.ali |
25 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 21636 |
ashik.ali |
26 |
import com.spice.profitmandi.dao.model.ItemIdSum;
|
| 21728 |
ashik.ali |
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;
|
| 21574 |
ashik.ali |
30 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 21582 |
kshitij.so |
31 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
| 21574 |
ashik.ali |
32 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 21555 |
kshitij.so |
33 |
|
| 21583 |
ashik.ali |
34 |
import in.shop2020.model.v1.catalog.ItemType;
|
|
|
35 |
|
| 21555 |
kshitij.so |
36 |
@Controller
|
| 21636 |
ashik.ali |
37 |
@Transactional
|
| 21582 |
kshitij.so |
38 |
public class PurchaseController {
|
| 21555 |
kshitij.so |
39 |
|
| 21582 |
kshitij.so |
40 |
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);
|
| 21640 |
kshitij.so |
41 |
|
| 21574 |
ashik.ali |
42 |
@Autowired
|
|
|
43 |
OrderRepository orderRepository;
|
| 21640 |
kshitij.so |
44 |
|
| 21574 |
ashik.ali |
45 |
@Autowired
|
| 21583 |
ashik.ali |
46 |
InventoryItemRepository inventoryItemRepository;
|
| 21640 |
kshitij.so |
47 |
|
| 21582 |
kshitij.so |
48 |
@Autowired
|
| 21640 |
kshitij.so |
49 |
PurchaseRepository purchaseRepository;
|
|
|
50 |
|
|
|
51 |
@Autowired
|
| 21574 |
ashik.ali |
52 |
MVCResponseSender mvcResponseSender;
|
| 21640 |
kshitij.so |
53 |
|
| 21583 |
ashik.ali |
54 |
@Autowired
|
|
|
55 |
CookiesFetcher cookiesFetcher;
|
| 21640 |
kshitij.so |
56 |
|
| 21591 |
kshitij.so |
57 |
@RequestMapping(value = "/purchase", method = RequestMethod.POST)
|
| 21587 |
kshitij.so |
58 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws Throwable{
|
| 21640 |
kshitij.so |
59 |
|
| 21582 |
kshitij.so |
60 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 21583 |
ashik.ali |
61 |
List<Object[]> rows = orderRepository.selectByAirwayBillOrInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
|
|
62 |
Set<Integer> itemIds = new HashSet<>();
|
|
|
63 |
String invoiceNumber = null;
|
|
|
64 |
for(Object[] row : rows){
|
| 21640 |
kshitij.so |
65 |
LOGGER.info("row {}", Arrays.toString(row));
|
| 21583 |
ashik.ali |
66 |
itemIds.add((int)row[0]);
|
|
|
67 |
invoiceNumber = (String)row[9];
|
|
|
68 |
}
|
| 21640 |
kshitij.so |
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());
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
catch(ProfitMandiBusinessException e){
|
|
|
77 |
//Not to worry.No purchase exists
|
|
|
78 |
}
|
| 21636 |
ashik.ali |
79 |
LOGGER.info("itemIdSums : {}", itemIdSums);
|
| 21583 |
ashik.ali |
80 |
List<CustomItem> customItems = new ArrayList<>();
|
| 21615 |
kshitij.so |
81 |
for(Object[] row : rows){
|
|
|
82 |
CustomItem customItem = this.createCustomLineItem(row);
|
| 21636 |
ashik.ali |
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);
|
| 21583 |
ashik.ali |
87 |
}
|
|
|
88 |
}
|
| 21615 |
kshitij.so |
89 |
customItems.add(customItem);
|
| 21583 |
ashik.ali |
90 |
}
|
|
|
91 |
model.addAttribute("customItems", customItems);
|
| 21615 |
kshitij.so |
92 |
model.addAttribute("invoiceNumber",invoiceNumber);
|
|
|
93 |
model.addAttribute("airwayBillOrInvoiceNumber",airwayBillOrInvoiceNumber);
|
| 21587 |
kshitij.so |
94 |
return "purchase";
|
| 21555 |
kshitij.so |
95 |
}
|
| 21640 |
kshitij.so |
96 |
|
| 21587 |
kshitij.so |
97 |
@RequestMapping(value = "/purchase", method = RequestMethod.GET)
|
|
|
98 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request) throws Exception{
|
|
|
99 |
return "purchase";
|
|
|
100 |
}
|
| 21615 |
kshitij.so |
101 |
|
| 21640 |
kshitij.so |
102 |
private String getVaildName(String name){
|
|
|
103 |
return name!=null?name:"";
|
|
|
104 |
}
|
|
|
105 |
|
| 21615 |
kshitij.so |
106 |
private CustomItem createCustomLineItem(Object[] row){
|
|
|
107 |
LOGGER.info("row {}", Arrays.toString(row));
|
| 21583 |
ashik.ali |
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]);
|
| 21636 |
ashik.ali |
114 |
customLineItem.setUnitPrice((float)row[6]);
|
| 21583 |
ashik.ali |
115 |
customLineItem.setColor((String)row[4]);
|
|
|
116 |
customLineItem.setQuantity((float)row[5]);
|
| 21615 |
kshitij.so |
117 |
customLineItem.setDisplayName((getVaildName((String)row[1])+" "+getVaildName((String)row[2])+" "+getVaildName((String)row[3])+" "+getVaildName((String)row[4])).replaceAll("\\s+", " "));
|
| 21583 |
ashik.ali |
118 |
customItem.setItemDetail(customLineItem);
|
| 21615 |
kshitij.so |
119 |
customItem.setInvoiceNumber((String)row[9]);
|
|
|
120 |
customItem.setType(((ItemType)row[7]).toString());
|
| 21583 |
ashik.ali |
121 |
return customItem;
|
| 21582 |
kshitij.so |
122 |
}
|
| 21636 |
ashik.ali |
123 |
}
|