Subversion Repositories SmartDukaan

Rev

Rev 7410 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
6322 amar.kumar 1
package in.shop2020.inventory.controllers;
2
 
6388 amar.kumar 3
import java.text.DateFormat;
6322 amar.kumar 4
import java.text.ParseException;
5
import java.text.SimpleDateFormat;
6
import java.util.Calendar;
7
import java.util.Date;
8
import java.util.List;
9
 
10
import org.apache.thrift.TException;
11
import org.apache.thrift.transport.TTransportException;
12
 
13
import in.shop2020.thrift.clients.WarehouseClient;
14
import in.shop2020.warehouse.InventoryItem;
15
import in.shop2020.warehouse.Scan;
16
import in.shop2020.warehouse.ScanType;
17
import in.shop2020.warehouse.WarehouseService;
18
import in.shop2020.warehouse.WarehouseService.Client;
19
 
20
public class ScanRecordController extends BaseController{
21
 
22
	private String filterTypeSelector;
23
    private String toDate;
24
    private String fromDate;
25
    private String searchNumber;
7711 amar.kumar 26
    private SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
6388 amar.kumar 27
 
28
	private List<Scan> scans;
6322 amar.kumar 29
	public String index() {
30
		if(filterTypeSelector!=null ||filterTypeSelector!=null ||fromDate!=null){
31
			try {
32
			return search();
33
			} catch(Exception e) {
34
				addActionError("Error while fetching Scan Records");
35
				return INDEX;
36
			}
37
		}else {
38
        return INDEX;
39
		}
40
    }
41
 
42
	public String search() throws ParseException, TException {
43
		try {
44
 
45
			Client warehouseClient = new WarehouseClient().getClient();
46
			if(filterTypeSelector.equals("itemId")) {
47
				Date fromDate = formatter.parse(this.fromDate);
48
				Date toDate = formatter.parse(this.toDate);
49
				Long itemId = Long.parseLong(searchNumber);
50
				scans = warehouseClient.getInventoryScansForItem(itemId, 
51
						fromDate.getTime(), toDate.getTime());
52
			} else if(filterTypeSelector.equals("serialNumber")) {
7410 amar.kumar 53
				scans = warehouseClient.getScanRecordsForSerialNumber(searchNumber);
6322 amar.kumar 54
			}
55
			else 
56
				return INDEX;
57
		} catch (TTransportException e) {
58
			// TODO Auto-generated catch block
59
			e.printStackTrace();
60
		}
61
		return INDEX;
62
	}
63
 
7711 amar.kumar 64
	public String getDateTime(long milliseconds) {
65
        Calendar cal = Calendar.getInstance();
66
        cal.setTimeInMillis(milliseconds);
67
        return formatter.format(cal.getTime());
68
    }
69
 
6322 amar.kumar 70
	public String getFilterTypeSelector() {
71
		return filterTypeSelector;
72
	}
73
 
74
	public void setFilterTypeSelector(String filterTypeSelector) {
75
		this.filterTypeSelector = filterTypeSelector;
76
	}
77
 
78
	public String getToDate() {
79
		return toDate;
80
	}
81
 
82
	public void setToDate(String toDate) {
83
		this.toDate = toDate;
84
	}
85
 
86
	public String getFromDate() {
87
		return fromDate;
88
	}
89
 
90
	public void setFromDate(String fromDate) {
91
		this.fromDate = fromDate;
92
	}
93
 
94
	public String getSearchNumber() {
95
		return searchNumber;
96
	}
97
 
98
	public void setSearchNumber(String searchNumber) {
99
		this.searchNumber = searchNumber;
100
	}
101
 
102
	public List<Scan> getScans() {
103
		return scans;
104
	}
105
 
106
	public void setScans(List<Scan> scans) {
107
		this.scans = scans;
108
	}
109
}