| 1194 |
chandransh |
1 |
package in.shop2020.support.controllers;
|
|
|
2 |
|
|
|
3 |
import in.shop2020.support.services.PendingOrdersGenerator;
|
|
|
4 |
|
|
|
5 |
import java.io.ByteArrayOutputStream;
|
|
|
6 |
import java.io.IOException;
|
|
|
7 |
import java.util.Calendar;
|
|
|
8 |
import java.util.GregorianCalendar;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.ServletOutputStream;
|
|
|
11 |
import javax.servlet.http.HttpServletResponse;
|
|
|
12 |
|
|
|
13 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
|
|
14 |
|
| 1884 |
chandransh |
15 |
public class PendingOrdersController implements ServletResponseAware {
|
| 1194 |
chandransh |
16 |
|
|
|
17 |
private String id;
|
|
|
18 |
|
|
|
19 |
private HttpServletResponse response;
|
|
|
20 |
|
|
|
21 |
public String show(){
|
|
|
22 |
try {
|
|
|
23 |
long warehouseId = Long.parseLong(getId());
|
|
|
24 |
response.setContentType("application/vnd.ms-excel");
|
|
|
25 |
|
|
|
26 |
PendingOrdersGenerator pendingOrdersGenerator = new PendingOrdersGenerator();
|
|
|
27 |
Calendar date = new GregorianCalendar();
|
|
|
28 |
int year = date.get(Calendar.YEAR);
|
|
|
29 |
int month = date.get(Calendar.MONTH) +1;
|
|
|
30 |
int day = date.get(Calendar.DAY_OF_MONTH);
|
|
|
31 |
response.setHeader("Content-disposition", "inline; filename=pending-orders-"+ warehouseId + "-"+year+"-"+ month+"-" + day +".xls" );
|
|
|
32 |
|
|
|
33 |
ServletOutputStream sos;
|
|
|
34 |
try {
|
|
|
35 |
ByteArrayOutputStream baos = pendingOrdersGenerator.generatePendingOrdersDetails(warehouseId);
|
|
|
36 |
sos = response.getOutputStream();
|
|
|
37 |
baos.writeTo(sos);
|
|
|
38 |
sos.flush();
|
|
|
39 |
} catch (IOException e) {
|
|
|
40 |
e.printStackTrace();
|
|
|
41 |
}
|
|
|
42 |
}catch(NumberFormatException nfe){
|
|
|
43 |
nfe.printStackTrace();
|
|
|
44 |
}
|
|
|
45 |
return null;
|
|
|
46 |
}
|
|
|
47 |
|
|
|
48 |
@Override
|
|
|
49 |
public void setServletResponse(HttpServletResponse response) {
|
|
|
50 |
this.response = response;
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
public String getId(){
|
|
|
54 |
return id;
|
|
|
55 |
}
|
|
|
56 |
|
|
|
57 |
public void setId(String id){
|
|
|
58 |
this.id = id;
|
|
|
59 |
}
|
|
|
60 |
}
|