| Line 17... |
Line 17... |
| 17 |
import org.springframework.ui.Model;
|
17 |
import org.springframework.ui.Model;
|
| 18 |
import org.springframework.web.bind.annotation.RequestMapping;
|
18 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 19 |
import org.springframework.web.bind.annotation.RequestMethod;
|
19 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 20 |
import org.springframework.web.bind.annotation.RequestParam;
|
20 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 21 |
|
21 |
|
| - |
|
22 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 22 |
import com.spice.profitmandi.common.model.CustomItem;
|
23 |
import com.spice.profitmandi.common.model.CustomItem;
|
| 23 |
import com.spice.profitmandi.common.model.CustomLineItem;
|
24 |
import com.spice.profitmandi.common.model.CustomLineItem;
|
| 24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| - |
|
26 |
import com.spice.profitmandi.dao.entity.Purchase;
|
| 25 |
import com.spice.profitmandi.dao.model.ItemIdSum;
|
27 |
import com.spice.profitmandi.dao.model.ItemIdSum;
|
| 26 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
28 |
import com.spice.profitmandi.dao.repository.InventoryItemRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.OrderRepository;
|
29 |
import com.spice.profitmandi.dao.repository.OrderRepository;
|
| - |
|
30 |
import com.spice.profitmandi.dao.repository.PurchaseRepository;
|
| 28 |
import com.spice.profitmandi.web.model.FofoDetails;
|
31 |
import com.spice.profitmandi.web.model.FofoDetails;
|
| 29 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
32 |
import com.spice.profitmandi.web.util.CookiesFetcher;
|
| 30 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
33 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 31 |
|
34 |
|
| 32 |
import in.shop2020.model.v1.catalog.ItemType;
|
35 |
import in.shop2020.model.v1.catalog.ItemType;
|
| Line 34... |
Line 37... |
| 34 |
@Controller
|
37 |
@Controller
|
| 35 |
@Transactional
|
38 |
@Transactional
|
| 36 |
public class PurchaseController {
|
39 |
public class PurchaseController {
|
| 37 |
|
40 |
|
| 38 |
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);
|
41 |
private static final Logger LOGGER = LoggerFactory.getLogger(PurchaseController.class);
|
| 39 |
|
42 |
|
| 40 |
@Autowired
|
43 |
@Autowired
|
| 41 |
OrderRepository orderRepository;
|
44 |
OrderRepository orderRepository;
|
| 42 |
|
45 |
|
| 43 |
@Autowired
|
46 |
@Autowired
|
| 44 |
InventoryItemRepository inventoryItemRepository;
|
47 |
InventoryItemRepository inventoryItemRepository;
|
| - |
|
48 |
|
| - |
|
49 |
@Autowired
|
| - |
|
50 |
PurchaseRepository purchaseRepository;
|
| 45 |
|
51 |
|
| 46 |
@Autowired
|
52 |
@Autowired
|
| 47 |
MVCResponseSender mvcResponseSender;
|
53 |
MVCResponseSender mvcResponseSender;
|
| 48 |
|
54 |
|
| 49 |
@Autowired
|
55 |
@Autowired
|
| 50 |
CookiesFetcher cookiesFetcher;
|
56 |
CookiesFetcher cookiesFetcher;
|
| 51 |
|
57 |
|
| 52 |
@RequestMapping(value = "/purchase", method = RequestMethod.POST)
|
58 |
@RequestMapping(value = "/purchase", method = RequestMethod.POST)
|
| 53 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws Throwable{
|
59 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.AIRWAY_BILL_OR_INVOICE_NUMBER) String airwayBillOrInvoiceNumber, Model model) throws Throwable{
|
| - |
|
60 |
|
| 54 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
61 |
FofoDetails fofoDetails = cookiesFetcher.getCookiesObject(request);
|
| 55 |
List<Object[]> rows = orderRepository.selectByAirwayBillOrInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
62 |
List<Object[]> rows = orderRepository.selectByAirwayBillOrInvoiceNumber(airwayBillOrInvoiceNumber, fofoDetails.getFofoId());
|
| 56 |
Set<Integer> itemIds = new HashSet<>();
|
63 |
Set<Integer> itemIds = new HashSet<>();
|
| 57 |
String invoiceNumber = null;
|
64 |
String invoiceNumber = null;
|
| 58 |
for(Object[] row : rows){
|
65 |
for(Object[] row : rows){
|
| - |
|
66 |
LOGGER.info("row {}", Arrays.toString(row));
|
| 59 |
itemIds.add((int)row[0]);
|
67 |
itemIds.add((int)row[0]);
|
| 60 |
invoiceNumber = (String)row[9];
|
68 |
invoiceNumber = (String)row[9];
|
| 61 |
}
|
69 |
}
|
| - |
|
70 |
List<ItemIdSum> itemIdSums = new ArrayList<ItemIdSum>();
|
| - |
|
71 |
try{
|
| - |
|
72 |
Purchase purchase = purchaseRepository.selectByPurchaseReference(invoiceNumber);
|
| - |
|
73 |
if (purchase.getFofoId() == fofoDetails.getFofoId()){
|
| 62 |
List<ItemIdSum> itemIdSums = inventoryItemRepository.selectScannedCount(itemIds, fofoDetails.getFofoId(), invoiceNumber);
|
74 |
itemIdSums = inventoryItemRepository.selectScannedCount(itemIds, fofoDetails.getFofoId(), purchase.getId());
|
| - |
|
75 |
}
|
| - |
|
76 |
}
|
| - |
|
77 |
catch(ProfitMandiBusinessException e){
|
| - |
|
78 |
//Not to worry.No purchase exists
|
| - |
|
79 |
}
|
| 63 |
LOGGER.info("itemIdSums : {}", itemIdSums);
|
80 |
LOGGER.info("itemIdSums : {}", itemIdSums);
|
| 64 |
List<CustomItem> customItems = new ArrayList<>();
|
81 |
List<CustomItem> customItems = new ArrayList<>();
|
| 65 |
for(Object[] row : rows){
|
82 |
for(Object[] row : rows){
|
| 66 |
CustomItem customItem = this.createCustomLineItem(row);
|
83 |
CustomItem customItem = this.createCustomLineItem(row);
|
| 67 |
for(ItemIdSum itemIdSum : itemIdSums){
|
84 |
for(ItemIdSum itemIdSum : itemIdSums){
|
| Line 75... |
Line 92... |
| 75 |
model.addAttribute("customItems", customItems);
|
92 |
model.addAttribute("customItems", customItems);
|
| 76 |
model.addAttribute("invoiceNumber",invoiceNumber);
|
93 |
model.addAttribute("invoiceNumber",invoiceNumber);
|
| 77 |
model.addAttribute("airwayBillOrInvoiceNumber",airwayBillOrInvoiceNumber);
|
94 |
model.addAttribute("airwayBillOrInvoiceNumber",airwayBillOrInvoiceNumber);
|
| 78 |
return "purchase";
|
95 |
return "purchase";
|
| 79 |
}
|
96 |
}
|
| 80 |
|
97 |
|
| 81 |
@RequestMapping(value = "/purchase", method = RequestMethod.GET)
|
98 |
@RequestMapping(value = "/purchase", method = RequestMethod.GET)
|
| 82 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request) throws Exception{
|
99 |
public String orderByAirwayBillOrInvoiceNumber(HttpServletRequest request) throws Exception{
|
| 83 |
return "purchase";
|
100 |
return "purchase";
|
| 84 |
}
|
101 |
}
|
| 85 |
|
102 |
|
| 86 |
private String getVaildName(String name){
|
103 |
private String getVaildName(String name){
|
| 87 |
return name!=null?name:"";
|
104 |
return name!=null?name:"";
|
| 88 |
}
|
105 |
}
|
| 89 |
|
106 |
|
| 90 |
private CustomItem createCustomLineItem(Object[] row){
|
107 |
private CustomItem createCustomLineItem(Object[] row){
|
| 91 |
LOGGER.info("row {}", Arrays.toString(row));
|
108 |
LOGGER.info("row {}", Arrays.toString(row));
|
| 92 |
CustomItem customItem = new CustomItem();
|
109 |
CustomItem customItem = new CustomItem();
|
| 93 |
customItem.setItemId((int)row[0]);
|
110 |
customItem.setItemId((int)row[0]);
|