| Line 31... |
Line 31... |
| 31 |
|
31 |
|
| 32 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
32 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 33 |
import org.apache.poi.ss.usermodel.Row;
|
33 |
import org.apache.poi.ss.usermodel.Row;
|
| 34 |
import org.apache.poi.ss.usermodel.Sheet;
|
34 |
import org.apache.poi.ss.usermodel.Sheet;
|
| 35 |
import org.apache.poi.ss.usermodel.Workbook;
|
35 |
import org.apache.poi.ss.usermodel.Workbook;
|
| 36 |
import org.apache.struts2.interceptor.ServletRequestAware;
|
- |
|
| 37 |
import org.apache.struts2.interceptor.ServletResponseAware;
|
- |
|
| 38 |
import org.apache.struts2.util.ServletContextAware;
|
36 |
import org.apache.thrift.meta_data.SetMetaData;
|
| 39 |
import org.slf4j.Logger;
|
37 |
import org.slf4j.Logger;
|
| 40 |
import org.slf4j.LoggerFactory;
|
38 |
import org.slf4j.LoggerFactory;
|
| 41 |
|
39 |
|
| 42 |
|
- |
|
| 43 |
|
- |
|
| 44 |
public class ReportController extends BaseController {
|
40 |
public class ReportController extends BaseController {
|
| 45 |
|
41 |
|
| 46 |
/**
|
42 |
/**
|
| 47 |
*
|
43 |
*
|
| 48 |
*/
|
44 |
*/
|
| Line 70... |
Line 66... |
| 70 |
|
66 |
|
| 71 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
67 |
private final DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
| 72 |
private final DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
|
68 |
private final DateFormat dateFormatter = new SimpleDateFormat("dd/MM/yyyy");
|
| 73 |
private final DateFormat df4Filename = new SimpleDateFormat("EEE_dd_MMM");
|
69 |
private final DateFormat df4Filename = new SimpleDateFormat("EEE_dd_MMM");
|
| 74 |
|
70 |
|
| - |
|
71 |
private String returnType;
|
| 75 |
private List<Order> orders = null;
|
72 |
private List<Order> orders = null;
|
| 76 |
private List<Order> searchResult = null;
|
73 |
private List<Order> searchResult = null;
|
| - |
|
74 |
private Long orderId;
|
| 77 |
|
75 |
|
| 78 |
private boolean showReprintColumn = false;
|
76 |
private boolean showReprintColumn = false;
|
| 79 |
|
77 |
|
| 80 |
public ReportController(){
|
78 |
public ReportController(){
|
| 81 |
try {
|
79 |
try {
|
| Line 114... |
Line 112... |
| 114 |
logger.error("Unable to get all Transactions for today", e);
|
112 |
logger.error("Unable to get all Transactions for today", e);
|
| 115 |
}
|
113 |
}
|
| 116 |
return "index";
|
114 |
return "index";
|
| 117 |
}
|
115 |
}
|
| 118 |
|
116 |
|
| 119 |
public String search() throws Exception {
|
117 |
public String search() {
|
| 120 |
// String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
118 |
// String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
|
| 121 |
// if(loginStatus == null || !loginStatus.equals("TRUE")){
|
119 |
// if(loginStatus == null || !loginStatus.equals("TRUE")){
|
| 122 |
// return "authfail";
|
120 |
// return "authfail";
|
| 123 |
// }
|
121 |
// }
|
| 124 |
if(number != null) {
|
122 |
if(number != null) {
|
| Line 143... |
Line 141... |
| 143 |
// }
|
141 |
// }
|
| 144 |
long today = -1;
|
142 |
long today = -1;
|
| 145 |
today = new Date().getTime();
|
143 |
today = new Date().getTime();
|
| 146 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
144 |
List<OrderStatus> statuses = new ArrayList<OrderStatus>();
|
| 147 |
statuses.add(OrderStatus.DELIVERY_SUCCESS);
|
145 |
statuses.add(OrderStatus.DELIVERY_SUCCESS);
|
| 148 |
orders = tClient.getOrdersForStore(0, 1, today, today, statuses);
|
146 |
List<Order> successfulOrders = tClient.getOrdersForStore(0, 1, today, today, statuses);
|
| - |
|
147 |
statuses.clear();
|
| 149 |
List<RechargeTransaction> successfulRecharges = tClient.getRechargeTrans(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), today, today, RechargeOrderStatus.RECHARGE_SUCCESSFUL);
|
148 |
statuses.add(OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST);
|
| - |
|
149 |
statuses.add(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
|
| 150 |
List<RechargeTransaction> refundedRecharges = tClient.getRechargeTrans(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), today, today, RechargeOrderStatus.RECHARGE_FAILED_REFUNDED);
|
150 |
List<Order> refundedOrders = tClient.getOrdersForStore(0, 1, today, today, statuses);
|
| 151 |
ByteArrayOutputStream baos = generateCollectionReport(successfulRecharges, refundedRecharges);
|
151 |
ByteArrayOutputStream baos = generateCollectionReport(successfulOrders, refundedOrders);
|
| 152 |
response.setContentType("application/vnd.ms-excel");
|
152 |
response.setContentType("application/vnd.ms-excel");
|
| 153 |
String fileName = "collection-report";
|
153 |
String fileName = "collection-report";
|
| 154 |
String todayDate = df4Filename.format(new Date(today));
|
154 |
String todayDate = df4Filename.format(new Date(today));
|
| 155 |
fileName = fileName + "-" + todayDate;
|
155 |
fileName = fileName + "-" + todayDate;
|
| 156 |
fileName = fileName + ".xls";
|
156 |
fileName = fileName + ".xls";
|
| Line 165... |
Line 165... |
| 165 |
}
|
165 |
}
|
| 166 |
return null;
|
166 |
return null;
|
| 167 |
|
167 |
|
| 168 |
}
|
168 |
}
|
| 169 |
|
169 |
|
| 170 |
private ByteArrayOutputStream generateCollectionReport(List<RechargeTransaction> successfulRecharges,
|
170 |
private ByteArrayOutputStream generateCollectionReport(List<Order> successfulOrders,
|
| 171 |
List<RechargeTransaction> refundedRecharges) {
|
171 |
List<Order> refundedOrders) {
|
| 172 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
172 |
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
|
| 173 |
Workbook wb = new HSSFWorkbook();
|
173 |
Workbook wb = new HSSFWorkbook();
|
| 174 |
Sheet reportSheet = wb.createSheet("Recharge Report");
|
174 |
Sheet reportSheet = wb.createSheet("Recharge Report");
|
| 175 |
Row reportSheetHeader = reportSheet.createRow((short)0);
|
175 |
Row reportSheetHeader = reportSheet.createRow((short)0);
|
| 176 |
reportSheetHeader.createCell(0).setCellValue("Order ID");
|
176 |
reportSheetHeader.createCell(0).setCellValue("Order ID");
|
| 177 |
reportSheetHeader.createCell(1).setCellValue("Order Date");
|
177 |
reportSheetHeader.createCell(1).setCellValue("Order Date");
|
| 178 |
reportSheetHeader.createCell(2).setCellValue("Operator");
|
178 |
reportSheetHeader.createCell(2).setCellValue("Product");
|
| 179 |
reportSheetHeader.createCell(3).setCellValue("Device Number");
|
- |
|
| 180 |
reportSheetHeader.createCell(4).setCellValue("Status");
|
179 |
reportSheetHeader.createCell(3).setCellValue("Status");
|
| 181 |
reportSheetHeader.createCell(5).setCellValue("Pay Method");
|
- |
|
| 182 |
reportSheetHeader.createCell(6).setCellValue("Refund Date");
|
180 |
reportSheetHeader.createCell(4).setCellValue("Refund Date");
|
| 183 |
reportSheetHeader.createCell(7).setCellValue("Type");
|
- |
|
| 184 |
reportSheetHeader.createCell(8).setCellValue("Total Amount");
|
181 |
reportSheetHeader.createCell(5).setCellValue("Total Amount");
|
| 185 |
reportSheetHeader.createCell(9).setCellValue("Discount");
|
- |
|
| 186 |
reportSheetHeader.createCell(10).setCellValue("Net Amount");
|
- |
|
| 187 |
|
182 |
|
| 188 |
int serialNo = 0;
|
183 |
int serialNo = 0;
|
| 189 |
|
184 |
|
| 190 |
for(RechargeTransaction transaction : successfulRecharges) {
|
185 |
for(Order order : successfulOrders) {
|
| 191 |
serialNo++;
|
186 |
serialNo++;
|
| 192 |
Row contentRow = reportSheet.createRow((short)serialNo);
|
187 |
Row contentRow = reportSheet.createRow((short)serialNo);
|
| 193 |
contentRow.createCell(0).setCellValue(transaction.getId());
|
188 |
contentRow.createCell(0).setCellValue(order.getId());
|
| 194 |
contentRow.createCell(1).setCellValue(formatter.format(new Date(transaction.getTransactionTime())));
|
189 |
contentRow.createCell(1).setCellValue(formatter.format(new Date(order.getCreated_timestamp())));
|
| 195 |
// contentRow.createCell(2).setCellValue(getOperatorName(transaction.getOperatorId()));
|
190 |
contentRow.createCell(2).setCellValue(getProductName(order.getLineitems().get(0)));
|
| 196 |
contentRow.createCell(3).setCellValue(transaction.getDeviceNum());
|
- |
|
| 197 |
contentRow.createCell(4).setCellValue(transaction.getStatus().name());
|
191 |
contentRow.createCell(3).setCellValue(order.getStatusDescription());
|
| 198 |
contentRow.createCell(5).setCellValue(transaction.getPayMethod().name());
|
- |
|
| 199 |
contentRow.createCell(6).setCellValue("N/A");
|
192 |
contentRow.createCell(4).setCellValue("N/A");
|
| 200 |
contentRow.createCell(7).setCellValue(transaction.isIsFrc() ? "FRC" : "Normal");
|
- |
|
| 201 |
contentRow.createCell(8).setCellValue(transaction.getAmount());
|
193 |
contentRow.createCell(5).setCellValue(order.getTotal_amount());
|
| 202 |
contentRow.createCell(9).setCellValue(transaction.getDiscount());
|
- |
|
| 203 |
contentRow.createCell(10).setCellValue(transaction.getPaymentAmount());
|
- |
|
| 204 |
}
|
194 |
}
|
| 205 |
|
195 |
|
| 206 |
for(RechargeTransaction transaction : refundedRecharges) {
|
196 |
for(Order order : refundedOrders) {
|
| 207 |
serialNo++;
|
197 |
serialNo++;
|
| 208 |
Row contentRow = reportSheet.createRow((short)serialNo);
|
198 |
Row contentRow = reportSheet.createRow((short)serialNo);
|
| 209 |
contentRow.createCell(0).setCellValue(transaction.getId());
|
199 |
contentRow.createCell(0).setCellValue(order.getId());
|
| 210 |
contentRow.createCell(1).setCellValue(formatter.format(new Date(transaction.getTransactionTime())));
|
200 |
contentRow.createCell(1).setCellValue(formatter.format(new Date(order.getCreated_timestamp())));
|
| 211 |
// contentRow.createCell(2).setCellValue(getOperatorName(transaction.getOperatorId()));
|
201 |
contentRow.createCell(2).setCellValue(getProductName(order.getLineitems().get(0)));
|
| 212 |
contentRow.createCell(3).setCellValue(transaction.getDeviceNum());
|
- |
|
| 213 |
contentRow.createCell(4).setCellValue(transaction.getStatus().name());
|
202 |
contentRow.createCell(3).setCellValue(order.getStatusDescription());
|
| 214 |
contentRow.createCell(5).setCellValue(transaction.getPayMethod().name());
|
- |
|
| 215 |
contentRow.createCell(6).setCellValue(formatter.format(new Date(transaction.getResponseTime())));
|
203 |
contentRow.createCell(4).setCellValue(formatter.format(new Date(order.getRefund_timestamp())));
|
| 216 |
contentRow.createCell(7).setCellValue(transaction.isIsFrc() ? "FRC" : "Normal");
|
- |
|
| 217 |
contentRow.createCell(8).setCellValue(transaction.getAmount());
|
204 |
contentRow.createCell(5).setCellValue(order.getTotal_amount());
|
| 218 |
contentRow.createCell(9).setCellValue(transaction.getDiscount());
|
- |
|
| 219 |
contentRow.createCell(10).setCellValue(transaction.getPaymentAmount());
|
- |
|
| 220 |
}
|
205 |
}
|
| 221 |
|
206 |
|
| 222 |
try {
|
207 |
try {
|
| 223 |
wb.write(baosXLS);
|
208 |
wb.write(baosXLS);
|
| 224 |
} catch (IOException e) {
|
209 |
} catch (IOException e) {
|
| Line 410... |
Line 395... |
| 410 |
public String getDateTime(long milliseconds) {
|
395 |
public String getDateTime(long milliseconds) {
|
| 411 |
Calendar cal = Calendar.getInstance();
|
396 |
Calendar cal = Calendar.getInstance();
|
| 412 |
cal.setTimeInMillis(milliseconds);
|
397 |
cal.setTimeInMillis(milliseconds);
|
| 413 |
return formatter.format(cal.getTime());
|
398 |
return formatter.format(cal.getTime());
|
| 414 |
}
|
399 |
}
|
| - |
|
400 |
|
| - |
|
401 |
public String cancelRequest() {
|
| - |
|
402 |
try{
|
| - |
|
403 |
TransactionClient tcl = new TransactionClient();
|
| - |
|
404 |
tcl.getClient().markOrderCancellationRequestReceived(orderId);
|
| - |
|
405 |
} catch (Exception e) {
|
| - |
|
406 |
logger.error("Could not mark order as cancellation requested for id : " + orderId.toString(), e);
|
| - |
|
407 |
setSearchError("Request failed. Try again or call customer care.");
|
| - |
|
408 |
}
|
| - |
|
409 |
number = orderId;
|
| - |
|
410 |
return search();
|
| - |
|
411 |
}
|
| - |
|
412 |
|
| - |
|
413 |
public String requestReturn() {
|
| - |
|
414 |
try{
|
| - |
|
415 |
TransactionClient tcl = new TransactionClient();
|
| - |
|
416 |
if(returnType.equals("doa")) {
|
| - |
|
417 |
tcl.getClient().markOrderDoaRequestReceived(orderId);
|
| - |
|
418 |
} else if(returnType.equals("return")) {
|
| - |
|
419 |
tcl.getClient().markOrderReturnRequestReceived(orderId);
|
| - |
|
420 |
} else {
|
| - |
|
421 |
setSearchError("Error in requesting return. Try Again.");
|
| - |
|
422 |
}
|
| - |
|
423 |
} catch (Exception e) {
|
| - |
|
424 |
logger.error("Could not mark order as return requested for id : " + orderId.toString(), e);
|
| - |
|
425 |
setSearchError("Request failed. Try again or call customer care.");
|
| - |
|
426 |
}
|
| - |
|
427 |
number = orderId;
|
| - |
|
428 |
return search();
|
| - |
|
429 |
}
|
| 415 |
|
430 |
|
| 416 |
public List<Order> getOrders(){
|
431 |
public List<Order> getOrders(){
|
| 417 |
return orders;
|
432 |
return orders;
|
| 418 |
}
|
433 |
}
|
| 419 |
|
434 |
|
| Line 527... |
Line 542... |
| 527 |
|
542 |
|
| 528 |
|
543 |
|
| 529 |
public String getPasswordGeneration() {
|
544 |
public String getPasswordGeneration() {
|
| 530 |
return passwordGeneration;
|
545 |
return passwordGeneration;
|
| 531 |
}
|
546 |
}
|
| - |
|
547 |
|
| - |
|
548 |
|
| - |
|
549 |
public void setOrderId(Long orderId) {
|
| - |
|
550 |
this.orderId = orderId;
|
| - |
|
551 |
}
|
| - |
|
552 |
|
| - |
|
553 |
|
| - |
|
554 |
public Long getOrderId() {
|
| - |
|
555 |
return orderId;
|
| - |
|
556 |
}
|
| - |
|
557 |
|
| - |
|
558 |
|
| - |
|
559 |
public void setReturnType(String returnType) {
|
| - |
|
560 |
this.returnType = returnType;
|
| - |
|
561 |
}
|
| - |
|
562 |
|
| - |
|
563 |
|
| - |
|
564 |
public String getReturnType() {
|
| - |
|
565 |
return returnType;
|
| - |
|
566 |
}
|
| 532 |
|
567 |
|
| 533 |
|
568 |
|
| 534 |
|
569 |
|
| 535 |
}
|
570 |
}
|
| 536 |
|
571 |
|