| Line 54... |
Line 54... |
| 54 |
public String create() {
|
54 |
public String create() {
|
| 55 |
// Formatting Form input parameters
|
55 |
// Formatting Form input parameters
|
| 56 |
String startDateStr = request.getParameter("startDate");
|
56 |
String startDateStr = request.getParameter("startDate");
|
| 57 |
String endDateStr = request.getParameter("endDate");
|
57 |
String endDateStr = request.getParameter("endDate");
|
| 58 |
String providerIdStr = request.getParameter("providerId");
|
58 |
String providerIdStr = request.getParameter("providerId");
|
| - |
|
59 |
String payModeStr = request.getParameter("payMode");
|
| 59 |
int providerId = 1;
|
60 |
int providerId = 1;
|
| - |
|
61 |
boolean payMode = false;
|
| 60 |
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
|
62 |
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
|
| 61 |
Date startDate = null, endDate = null;
|
63 |
Date startDate = null, endDate = null;
|
| 62 |
try {
|
64 |
try {
|
| 63 |
startDate = df.parse(startDateStr);
|
65 |
startDate = df.parse(startDateStr);
|
| 64 |
endDate = df.parse(endDateStr);
|
66 |
endDate = df.parse(endDateStr);
|
| 65 |
Calendar cal = Calendar.getInstance();
|
67 |
Calendar cal = Calendar.getInstance();
|
| 66 |
cal.setTime(endDate);
|
68 |
cal.setTime(endDate);
|
| 67 |
cal.add(Calendar.DATE, 1);
|
69 |
cal.add(Calendar.DATE, 1);
|
| 68 |
endDate.setTime(cal.getTimeInMillis());
|
70 |
endDate.setTime(cal.getTimeInMillis());
|
| 69 |
providerId = Integer.parseInt(providerIdStr);
|
71 |
providerId = Integer.parseInt(providerIdStr);
|
| - |
|
72 |
payMode = Boolean.parseBoolean(payModeStr);
|
| 70 |
} catch (ParseException pe) {
|
73 |
} catch (ParseException pe) {
|
| 71 |
errorMsg = "Please enter start and end dates in format MM/dd/yyyy";
|
74 |
errorMsg = "Please enter start and end dates in format MM/dd/yyyy";
|
| 72 |
return "index";
|
75 |
return "index";
|
| 73 |
} catch (NumberFormatException nfe) {
|
76 |
} catch (NumberFormatException nfe) {
|
| 74 |
errorMsg = "Please select a provider";
|
77 |
errorMsg = "Please select a provider and a payment mode";
|
| 75 |
return "index";
|
78 |
return "index";
|
| 76 |
}
|
79 |
}
|
| 77 |
|
80 |
|
| 78 |
Provider provider = null;
|
81 |
Provider provider = null;
|
| 79 |
try {
|
82 |
try {
|
| Line 87... |
Line 90... |
| 87 |
logger.error("Error getting provider info from the logistics service: ", e);
|
90 |
logger.error("Error getting provider info from the logistics service: ", e);
|
| 88 |
return "index";
|
91 |
return "index";
|
| 89 |
}
|
92 |
}
|
| 90 |
|
93 |
|
| 91 |
CourierReconciliationGenerator crGenerator = new CourierReconciliationGenerator();
|
94 |
CourierReconciliationGenerator crGenerator = new CourierReconciliationGenerator();
|
| 92 |
ByteArrayOutputStream baos = crGenerator.generateCourierReconciliationReport(startDate, endDate, providerId);
|
95 |
ByteArrayOutputStream baos = crGenerator.generateCourierReconciliationReport(startDate, endDate, providerId, payMode);
|
| 93 |
|
96 |
|
| 94 |
if (baos == null) {
|
97 |
if (baos == null) {
|
| 95 |
errorMsg = "No output for given date range";
|
98 |
errorMsg = "No output for given date range";
|
| 96 |
return "index";
|
99 |
return "index";
|
| 97 |
}
|
100 |
}
|
| 98 |
|
101 |
|
| 99 |
// Preparing XLS file for output
|
102 |
// Preparing XLS file for output
|
| 100 |
response.setContentType("application/vnd.ms-excel");
|
103 |
response.setContentType("application/vnd.ms-excel");
|
| 101 |
response.setHeader("Content-disposition", "inline; filename=" + provider.getName() + "-courier-reconciliation-" + startDateStr + "-" + endDateStr + ".xls");
|
104 |
response.setHeader("Content-disposition", "inline; filename=" + provider.getName() + (payMode ? "-cod" : "-prepaid") + "-courier-reconciliation-" + startDateStr + "-" + endDateStr + ".xls");
|
| 102 |
|
105 |
|
| 103 |
ServletOutputStream sos;
|
106 |
ServletOutputStream sos;
|
| 104 |
try {
|
107 |
try {
|
| 105 |
sos = response.getOutputStream();
|
108 |
sos = response.getOutputStream();
|
| 106 |
baos.writeTo(sos);
|
109 |
baos.writeTo(sos);
|