Subversion Repositories SmartDukaan

Rev

Rev 21598 | Rev 21636 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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