Subversion Repositories SmartDukaan

Rev

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

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