| 3381 |
chandransh |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.thrift.clients.WarehouseClient;
|
|
|
4 |
import in.shop2020.warehouse.ScanType;
|
|
|
5 |
import in.shop2020.warehouse.WarehouseServiceException;
|
|
|
6 |
import in.shop2020.warehouse.WarehouseService.Client;
|
|
|
7 |
|
|
|
8 |
import javax.servlet.ServletContext;
|
|
|
9 |
import javax.servlet.http.HttpServletRequest;
|
|
|
10 |
|
|
|
11 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
|
|
12 |
import org.apache.struts2.util.ServletContextAware;
|
|
|
13 |
import org.apache.thrift.TException;
|
|
|
14 |
import org.apache.thrift.transport.TTransportException;
|
|
|
15 |
import org.slf4j.Logger;
|
|
|
16 |
import org.slf4j.LoggerFactory;
|
|
|
17 |
|
|
|
18 |
public class PurchaseController implements ServletRequestAware, ServletContextAware {
|
|
|
19 |
|
|
|
20 |
private static Logger logger = LoggerFactory.getLogger(PurchaseController.class);
|
|
|
21 |
|
|
|
22 |
protected HttpServletRequest request;
|
|
|
23 |
private ServletContext context;
|
|
|
24 |
private String id;
|
|
|
25 |
private String errorMsg="";
|
|
|
26 |
|
|
|
27 |
private String purchaseOrderId;
|
|
|
28 |
|
|
|
29 |
public String editNew(){
|
|
|
30 |
purchaseOrderId = request.getParameter("poId");
|
|
|
31 |
return "new";
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
public String create(){
|
|
|
35 |
this.purchaseOrderId = request.getParameter("poId");
|
|
|
36 |
long poId = Long.parseLong(purchaseOrderId);
|
|
|
37 |
String invoiceNumber = request.getParameter("invoiceNo");
|
|
|
38 |
String fc = request.getParameter("freightCharges").trim();
|
|
|
39 |
double freightCharges = 0;
|
|
|
40 |
if(fc != null && !fc.isEmpty())
|
|
|
41 |
freightCharges = Double.parseDouble(fc);
|
|
|
42 |
try {
|
|
|
43 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
44 |
Client client = warehouseClient.getClient();
|
|
|
45 |
id = "" + client.startPurchase(poId, invoiceNumber, freightCharges);
|
|
|
46 |
} catch (TTransportException e) {
|
|
|
47 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
48 |
logger.error(errorMsg, e);
|
|
|
49 |
} catch (WarehouseServiceException e) {
|
|
|
50 |
errorMsg = "Error while scanning in the item";
|
|
|
51 |
logger.error(errorMsg, e);
|
|
|
52 |
} catch (TException e) {
|
|
|
53 |
errorMsg = "Error while scanning in the item";
|
|
|
54 |
logger.error(errorMsg, e);
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
if(errorMsg.isEmpty())
|
|
|
58 |
return "create";
|
|
|
59 |
else
|
|
|
60 |
return "new";
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
public String show(){
|
|
|
64 |
return "show";
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
public String update(){
|
|
|
68 |
long id = Long.parseLong(this.id);
|
|
|
69 |
String itemNumber = request.getParameter("itemNo");
|
|
|
70 |
String imeiNumber = request.getParameter("imeiNo");
|
|
|
71 |
|
|
|
72 |
try {
|
|
|
73 |
WarehouseClient warehouseClient = new WarehouseClient();
|
|
|
74 |
Client client = warehouseClient.getClient();
|
|
|
75 |
client.scanIn(id, itemNumber, imeiNumber, ScanType.PURCHASE);
|
|
|
76 |
} catch (TTransportException e) {
|
|
|
77 |
errorMsg = "Error while establishing connection to the warehouse server";
|
|
|
78 |
logger.error(errorMsg, e);
|
|
|
79 |
} catch (WarehouseServiceException e) {
|
|
|
80 |
errorMsg = "Error while scanning in the item";
|
|
|
81 |
logger.error(errorMsg, e);
|
|
|
82 |
} catch (TException e) {
|
|
|
83 |
errorMsg = "Error while scanning in the item";
|
|
|
84 |
logger.error(errorMsg, e);
|
|
|
85 |
}
|
|
|
86 |
return "show";
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
public void setId(String id){
|
|
|
90 |
this.id = id;
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
public String getId(){
|
|
|
94 |
return id;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
public String getErrorMessage(){
|
|
|
98 |
return errorMsg;
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
public String getPurchaseOrderId() {
|
|
|
102 |
return purchaseOrderId;
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
@Override
|
|
|
106 |
public void setServletRequest(HttpServletRequest request) {
|
|
|
107 |
this.request = request;
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
@Override
|
|
|
111 |
public void setServletContext(ServletContext context) {
|
|
|
112 |
this.context = context;
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
public String getServletContextPath() {
|
|
|
116 |
return context.getContextPath();
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
}
|