Subversion Repositories SmartDukaan

Rev

Rev 1514 | Rev 1738 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1514 Rev 1608
Line 4... Line 4...
4
import in.shop2020.model.v1.order.Order;
4
import in.shop2020.model.v1.order.Order;
5
import in.shop2020.model.v1.order.Transaction;
5
import in.shop2020.model.v1.order.Transaction;
6
import in.shop2020.model.v1.order.TransactionServiceException;
6
import in.shop2020.model.v1.order.TransactionServiceException;
7
import in.shop2020.model.v1.user.Address;
7
import in.shop2020.model.v1.user.Address;
8
import in.shop2020.model.v1.user.User;
8
import in.shop2020.model.v1.user.User;
-
 
9
import in.shop2020.model.v1.user.UserCommunication;
-
 
10
import in.shop2020.model.v1.user.UserContextException;
9
import in.shop2020.model.v1.user.UserContextService.Client;
11
import in.shop2020.model.v1.user.UserContextService.Client;
10
import in.shop2020.payments.Payment;
12
import in.shop2020.payments.Payment;
11
import in.shop2020.thrift.clients.PaymentServiceClient;
13
import in.shop2020.thrift.clients.PaymentServiceClient;
12
import in.shop2020.thrift.clients.TransactionServiceClient;
14
import in.shop2020.thrift.clients.TransactionServiceClient;
13
import in.shop2020.thrift.clients.UserContextServiceClient;
15
import in.shop2020.thrift.clients.UserContextServiceClient;
Line 18... Line 20...
18
import java.io.UnsupportedEncodingException;
20
import java.io.UnsupportedEncodingException;
19
import java.security.Principal;
21
import java.security.Principal;
20
import java.text.DateFormat;
22
import java.text.DateFormat;
21
import java.text.ParseException;
23
import java.text.ParseException;
22
import java.text.SimpleDateFormat;
24
import java.text.SimpleDateFormat;
23
import java.util.ArrayList;
25
import java.util.Collections;
24
import java.util.Date;
26
import java.util.Date;
25
import java.util.Enumeration;
27
import java.util.Enumeration;
-
 
28
import java.util.HashMap;
26
import java.util.List;
29
import java.util.List;
27
import java.util.Locale;
30
import java.util.Locale;
28
import java.util.Map;
31
import java.util.Map;
29
 
32
 
30
import javax.servlet.RequestDispatcher;
33
import javax.servlet.RequestDispatcher;
Line 43... Line 46...
43
import org.apache.poi.ss.usermodel.Sheet;
46
import org.apache.poi.ss.usermodel.Sheet;
44
import org.apache.poi.ss.usermodel.Workbook;
47
import org.apache.poi.ss.usermodel.Workbook;
45
import org.apache.poi.ss.util.CellRangeAddress;
48
import org.apache.poi.ss.util.CellRangeAddress;
46
import org.apache.struts2.interceptor.ServletRequestAware;
49
import org.apache.struts2.interceptor.ServletRequestAware;
47
import org.apache.struts2.interceptor.ServletResponseAware;
50
import org.apache.struts2.interceptor.ServletResponseAware;
-
 
51
import org.apache.thrift.TException;
48
 
52
 
49
public class UserOrdersController implements ServletResponseAware, ServletRequestAware{
53
public class UserOrdersController implements ServletResponseAware, ServletRequestAware{
50
 
54
 
-
 
55
	private static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("dd/MM/yyyy HH:mm");
-
 
56
		
51
	private HttpServletRequest request;
57
	private HttpServletRequest request;
52
	private HttpServletResponse response;
58
	private HttpServletResponse response;
53
	
59
	
54
	private String errorMsg = "";
60
	private String errorMsg = "";
55
	
61
	
Line 88... Line 94...
88
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
94
			UserContextServiceClient userContextServiceClient = new UserContextServiceClient();
89
			Client userClient = userContextServiceClient.getClient();
95
			Client userClient = userContextServiceClient.getClient();
90
			
96
			
91
			PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
97
			PaymentServiceClient paymentServiceClient = new PaymentServiceClient();
92
			in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
98
			in.shop2020.payments.PaymentService.Client paymentClient = paymentServiceClient.getClient();
93
			
99
 
94
			User user = null;
100
			User user = null;
95
			if (email != null && !email.isEmpty()) {
101
			if (email != null && !email.isEmpty()) {
96
				user = userClient.getUserByEmail(email);
102
				user = userClient.getUserByEmail(email);
97
				if(user.getUserId() == -1){
103
				if(user.getUserId() == -1){
98
				    errorMsg = "No user for this id.";
104
				    errorMsg = "No user for this id.";
Line 111... Line 117...
111
			if (user == null) {
117
			if (user == null) {
112
				errorMsg = "Could not find user.";
118
				errorMsg = "Could not find user.";
113
				return "report";
119
				return "report";
114
			}
120
			}
115
 
121
 
-
 
122
			//Retrieving all user communications
-
 
123
			List<UserCommunication> userCommunications = userClient.getUserCommunicationByUser(user.getUserId());
116
			List <Transaction> transactions = new ArrayList<Transaction>();
124
			List<UserCommunication> allCommunications = userClient.getAllUserCommunications();
117
 
125
			
118
			//Retrieving all the transactions
126
			//Retrieving all the transactions
119
			transactions.addAll(transactionClient.getTransactionsForCustomer(user.getUserId(), 0, (new Date()).getTime(), null));
127
			List <Transaction> transactions = transactionClient.getTransactionsForCustomer(user.getUserId(), 0, (new Date()).getTime(), null);
-
 
128
			Collections.reverse(transactions);
-
 
129
 
120
			System.out.println("Total number of Transaction: " + transactions.size());
130
			System.out.println("Total number of Transaction: " + transactions.size());
121
			
131
			
122
			List <Payment> payments = new ArrayList<Payment>();
-
 
123
			//Retrieving all the payments 
132
			//Retrieving all the payments 
124
			payments.addAll(paymentClient.getPaymentsForUser(user.getUserId(), 0,
133
			List <Payment> payments = paymentClient.getPaymentsForUser(user.getUserId(), 0,
125
						(new Date()).getTime(), null, 0));
134
					(new Date()).getTime(), null, 0);
-
 
135
			
-
 
136
			Map<Long, Payment> txnIdToPaymentMap = new HashMap<Long, Payment>();
-
 
137
			for(Payment payment : payments) {
-
 
138
				txnIdToPaymentMap.put(payment.getMerchantTxnId(), payment);
-
 
139
			}
-
 
140
			
126
			// Preparing XLS file for output
141
			// Preparing XLS file for output
127
			response.setContentType("application/vnd.ms-excel");
142
			response.setContentType("application/vnd.ms-excel");
128
			
143
			
129
			response.setHeader("Content-disposition", "inline; filename=user-orders" + ".xls");
144
			response.setHeader("Content-disposition", "inline; filename=user-orders" + ".xls");
130
			
145
			
131
			ServletOutputStream sos;
146
			ServletOutputStream sos;
132
			try {
147
			try {
133
				ByteArrayOutputStream baos = getSpreadSheetData(user, transactions, payments);
148
				ByteArrayOutputStream baos = getSpreadSheetData(user,
-
 
149
						transactions, txnIdToPaymentMap, userCommunications,
-
 
150
						allCommunications, userClient);
134
				sos = response.getOutputStream();
151
				sos = response.getOutputStream();
135
				baos.writeTo(sos);
152
				baos.writeTo(sos);
136
				sos.flush();
153
				sos.flush();
137
			} catch (IOException e) {
154
			} catch (IOException e) {
138
				errorMsg = "Failed to write to response.";
155
				errorMsg = "Failed to write to response.";
Line 151... Line 168...
151
		}
168
		}
152
		return "report";
169
		return "report";
153
	}
170
	}
154
	
171
	
155
	// Prepares the XLS worksheet object and fills in the data with proper formatting
172
	// Prepares the XLS worksheet object and fills in the data with proper formatting
156
	private ByteArrayOutputStream getSpreadSheetData(User user, List<Transaction> transactions, List<Payment> payments)	{
173
	private ByteArrayOutputStream getSpreadSheetData(User user,
-
 
174
			List<Transaction> transactions,
-
 
175
			Map<Long, Payment> txnIdToPaymentMap,
-
 
176
			List<UserCommunication> userCommunications,
-
 
177
			List<UserCommunication> allCommunications, Client userClient) 
-
 
178
	{
157
		ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
179
	    ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
158
 
180
 
159
		DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
-
 
160
		
-
 
161
	    Workbook wb = new HSSFWorkbook();
181
		Workbook wb = new HSSFWorkbook();
162
	    
182
	    
163
	    Font font = wb.createFont();
183
	    Font font = wb.createFont();
164
	    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
184
	    font.setBoldweight(Font.BOLDWEIGHT_BOLD);
165
	    CellStyle style = wb.createCellStyle();
185
	    CellStyle style = wb.createCellStyle();
166
	    style.setFont(font);
186
	    style.setFont(font);
167
	    
187
	    
168
	    createUserSheet(user, wb, style);
188
	    createUserSheet(user, userCommunications, wb, style);
169
	    createTransactionSheet(transactions, wb, style, dateFormat);
189
	    createTransactionSheet(transactions, txnIdToPaymentMap, wb, style);
170
	    createPaymentSheet(payments, wb, style, dateFormat);
190
	    createAllUserCommunicationSheet(allCommunications, userClient, wb, style);
171
	        	
191
	        	
172
		// Write the workbook to the output stream
192
		// Write the workbook to the output stream
173
		try {
193
		try {
174
			wb.write(baosXLS);
194
			wb.write(baosXLS);
175
			baosXLS.close();
195
			baosXLS.close();
Line 177... Line 197...
177
			e.printStackTrace();
197
			e.printStackTrace();
178
		}		
198
		}		
179
		return baosXLS;
199
		return baosXLS;
180
	}
200
	}
181
	
201
	
182
	private void createPaymentSheet(List<Payment> payments, Workbook wb,
202
	private void createAllUserCommunicationSheet(
-
 
203
			List<UserCommunication> allCommunications, 
-
 
204
			Client userClient,
-
 
205
			Workbook wb, 
183
			CellStyle style, DateFormat dateFormat) 
206
			CellStyle style) 
184
	{
207
	{
185
		// PAYMENT SHEET
208
		// USER COMMUNICATION SHEET
186
	    Sheet paymentSheet = wb.createSheet("Payment");
209
	    Sheet commSheet = wb.createSheet("All Users Communications");
187
	    short paymentSerialNo = 0;
210
	    short commSerialNo = 0;
188
 
211
 
189
	    Row orderTitleRow = paymentSheet.createRow(paymentSerialNo ++);
212
	    Row commTitleRow = commSheet.createRow(commSerialNo ++);
190
	    Cell orderTitleCell = orderTitleRow.createCell(0);
213
	    Cell commTitleCell = commTitleRow.createCell(0);
191
	    orderTitleCell.setCellValue("User Payments");
214
	    commTitleCell.setCellValue("All Users Communications");
192
	    orderTitleCell.setCellStyle(style);
215
	    commTitleCell.setCellStyle(style);
193
	    
-
 
194
	    paymentSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
-
 
195
	    
216
	    
196
	    paymentSheet.createRow(paymentSerialNo ++);
217
	    commSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
197
	    
218
	    
-
 
219
	    commSheet.createRow(commSerialNo ++);
-
 
220
		
198
	    Row orderHeaderRow = paymentSheet.createRow(paymentSerialNo ++);
221
	    Row commHeaderRow = commSheet.createRow(commSerialNo++);
199
	    orderHeaderRow.createCell(0).setCellValue("Transaction Id");
222
	    commHeaderRow.createCell(0).setCellValue("User Email");
200
	    orderHeaderRow.createCell(1).setCellValue("Payment Id");
223
	    commHeaderRow.createCell(1).setCellValue("User Name");
201
	    orderHeaderRow.createCell(2).setCellValue("Payment Status");
224
	    commHeaderRow.createCell(2).setCellValue("Communication Email");
202
	    orderHeaderRow.createCell(3).setCellValue("Gateway Payment Id");
225
	    commHeaderRow.createCell(3).setCellValue("Date of Birth");
203
	    orderHeaderRow.createCell(4).setCellValue("Gateway Transaction Date");
226
	    commHeaderRow.createCell(4).setCellValue("Mobile Number");
204
	    orderHeaderRow.createCell(5).setCellValue("Gateway Txn Id");
227
	    commHeaderRow.createCell(5).setCellValue("User Id");
205
	    orderHeaderRow.createCell(6).setCellValue("Gateway Txn Status");
228
	    commHeaderRow.createCell(6).setCellValue("Sex");
206
	    orderHeaderRow.createCell(7).setCellValue("Reference Code");
229
	    commHeaderRow.createCell(7).setCellValue("Order Id");
-
 
230
	    commHeaderRow.createCell(8).setCellValue("Communication Type");
207
	    orderHeaderRow.createCell(8).setCellValue("Gateway Id");
231
	    commHeaderRow.createCell(9).setCellValue("AirwayBill No");
208
	    orderHeaderRow.createCell(9).setCellValue("Amount");
232
	    commHeaderRow.createCell(10).setCellValue("TimeStamp");
-
 
233
	    commHeaderRow.createCell(11).setCellValue("Product Name");
209
	    orderHeaderRow.createCell(10).setCellValue("Description");
234
	    commHeaderRow.createCell(12).setCellValue("Reply To");
210
	    orderHeaderRow.createCell(11).setCellValue("Auth Code");
235
	    commHeaderRow.createCell(13).setCellValue("Subject");
211
	    orderHeaderRow.createCell(12).setCellValue("Error Code");
236
	    commHeaderRow.createCell(14).setCellValue("Message");
212
 
237
	    
213
		for (Payment payment : payments) {
238
		for( UserCommunication userComm : allCommunications) {
214
			paymentSerialNo++;
239
			commSerialNo++;
215
			Row contentRow = paymentSheet.createRow(paymentSerialNo);
240
			Row commContentRow = commSheet.createRow(commSerialNo);
216
 
241
			
-
 
242
			try {
-
 
243
				User user = userClient.getUserById(userComm.getUserId());
-
 
244
				if (user.getUserId() == -1) {
217
			contentRow.createCell(0).setCellValue(payment.getMerchantTxnId());
245
					commContentRow.createCell(0).setCellValue(user.getEmail());
218
			contentRow.createCell(1).setCellValue(payment.getPaymentId());
246
					commContentRow.createCell(1).setCellValue(user.getName());
219
			contentRow.createCell(2).setCellValue(payment.getStatus().name());
247
					commContentRow.createCell(2).setCellValue(user.getCommunicationEmail());
220
			contentRow.createCell(3)
248
					commContentRow.createCell(3).setCellValue(user.getDateOfBirth());
-
 
249
					commContentRow.createCell(4).setCellValue(user.getMobileNumber());
221
					.setCellValue(payment.getGatewayPaymentId());
250
					commContentRow.createCell(5).setCellValue(user.getUserId());
-
 
251
					if (user.getSex() != null) {
222
			contentRow.createCell(4).setCellValue(payment.getGatewayTxnDate());
252
						commContentRow.createCell(6).setCellValue(user.getSex().name());
-
 
253
					}
-
 
254
				}
-
 
255
			} catch (UserContextException e) {
-
 
256
				e.printStackTrace();
-
 
257
			} catch (TException e) {
-
 
258
				e.printStackTrace();
-
 
259
			}
223
			contentRow.createCell(5).setCellValue(payment.getGatewayTxnId());
260
			commContentRow.createCell(7).setCellValue(userComm.getOrderId());
-
 
261
			if (userComm.getCommunicationType() != null) {
224
			contentRow.createCell(6)
262
				commContentRow.createCell(8).setCellValue(
225
					.setCellValue(payment.getGatewayTxnStatus());
263
						userComm.getCommunicationType().name());
-
 
264
			}
226
			contentRow.createCell(7).setCellValue(payment.getReferenceCode());
265
			commContentRow.createCell(9).setCellValue(userComm.getAirwaybillNo());
227
			contentRow.createCell(8).setCellValue(payment.getGatewayId());
266
			commContentRow.createCell(10).setCellValue(DATE_TIME_FORMAT.format(userComm.getCommunication_timestamp()));
228
			contentRow.createCell(9).setCellValue(payment.getAmount());
267
			commContentRow.createCell(11).setCellValue(userComm.getProductName());
229
			contentRow.createCell(10).setCellValue(payment.getDescription());
268
			commContentRow.createCell(12).setCellValue(userComm.getReplyTo());
230
			contentRow.createCell(11).setCellValue(payment.getAuthCode());
269
			commContentRow.createCell(13).setCellValue(userComm.getSubject());
231
			contentRow.createCell(12).setCellValue(payment.getErrorCode());
270
			commContentRow.createCell(14).setCellValue(userComm.getMessage());
232
		}
271
		}
233
	}
272
	}
234
 
273
 
235
	private void createTransactionSheet(List<Transaction> transactions, Workbook wb, CellStyle style, DateFormat dateFormat) {
274
	private void createTransactionSheet(List<Transaction> transactions, Map<Long, Payment> txnIdToPaymentMap, Workbook wb, CellStyle style) {
236
		// TRANSACTION SHEET
275
		// TRANSACTION SHEET
237
	    Sheet transactionSheet = wb.createSheet("Transaction");
276
	    Sheet transactionSheet = wb.createSheet("Transactions and Payments");
238
	    short transactionSerialNo = 0;
277
	    short transactionSerialNo = 0;
239
 
278
 
240
	    Row orderTitleRow = transactionSheet.createRow(transactionSerialNo ++);
279
	    Row orderTitleRow = transactionSheet.createRow(transactionSerialNo ++);
241
	    Cell orderTitleCell = orderTitleRow.createCell(0);
280
	    Cell orderTitleCell = orderTitleRow.createCell(0);
242
	    orderTitleCell.setCellValue("User Transactions");
281
	    orderTitleCell.setCellValue("User Transactions and Payments");
243
	    orderTitleCell.setCellStyle(style);
282
	    orderTitleCell.setCellStyle(style);
244
	    
283
	    
245
	    transactionSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
284
	    transactionSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
246
	    
285
	    
247
	    transactionSheet.createRow(transactionSerialNo ++);
286
	    transactionSheet.createRow(transactionSerialNo ++);
Line 252... Line 291...
252
	    orderHeaderRow.createCell(2).setCellValue("Transaction Status");
291
	    orderHeaderRow.createCell(2).setCellValue("Transaction Status");
253
	    orderHeaderRow.createCell(3).setCellValue("Order Id");
292
	    orderHeaderRow.createCell(3).setCellValue("Order Id");
254
	    orderHeaderRow.createCell(4).setCellValue("Billing Number");
293
	    orderHeaderRow.createCell(4).setCellValue("Billing Number");
255
	    orderHeaderRow.createCell(5).setCellValue("Billing Date");
294
	    orderHeaderRow.createCell(5).setCellValue("Billing Date");
256
	    orderHeaderRow.createCell(6).setCellValue("Order Status");
295
	    orderHeaderRow.createCell(6).setCellValue("Order Status");
-
 
296
	    
257
	    orderHeaderRow.createCell(7).setCellValue("Brand");
297
	    orderHeaderRow.createCell(7).setCellValue("Brand");
258
	    orderHeaderRow.createCell(8).setCellValue("Model Name");
298
	    orderHeaderRow.createCell(8).setCellValue("Model Name");
259
	    orderHeaderRow.createCell(9).setCellValue("Model Number");
299
	    orderHeaderRow.createCell(9).setCellValue("Model Number");
260
	    orderHeaderRow.createCell(10).setCellValue("Color");
300
	    orderHeaderRow.createCell(10).setCellValue("Color");
261
	    orderHeaderRow.createCell(11).setCellValue("Quantity");
301
	    orderHeaderRow.createCell(11).setCellValue("Quantity");
262
	    orderHeaderRow.createCell(12).setCellValue("Unit Price");
302
	    orderHeaderRow.createCell(12).setCellValue("Unit Price");
263
	    orderHeaderRow.createCell(13).setCellValue("Total Price");
303
	    orderHeaderRow.createCell(13).setCellValue("Total Price");
-
 
304
	    
264
	    orderHeaderRow.createCell(14).setCellValue("User Id");
305
	    orderHeaderRow.createCell(14).setCellValue("User Id");
265
	    orderHeaderRow.createCell(15).setCellValue("Name");
306
	    orderHeaderRow.createCell(15).setCellValue("Name");
266
	    orderHeaderRow.createCell(16).setCellValue("Address1");
307
	    orderHeaderRow.createCell(16).setCellValue("Address1");
267
	    orderHeaderRow.createCell(17).setCellValue("Address2");
308
	    orderHeaderRow.createCell(17).setCellValue("Address2");
268
	    orderHeaderRow.createCell(17).setCellValue("City");
309
	    orderHeaderRow.createCell(17).setCellValue("City");
269
	    orderHeaderRow.createCell(19).setCellValue("State");
310
	    orderHeaderRow.createCell(19).setCellValue("State");
270
	    orderHeaderRow.createCell(20).setCellValue("Pin Code");
311
	    orderHeaderRow.createCell(20).setCellValue("Pin Code");
271
	    orderHeaderRow.createCell(21).setCellValue("Mobile Number");
312
	    orderHeaderRow.createCell(21).setCellValue("Mobile Number");
272
	    orderHeaderRow.createCell(22).setCellValue("email");
313
	    orderHeaderRow.createCell(22).setCellValue("email");
-
 
314
	    
273
	    orderHeaderRow.createCell(23).setCellValue("Airway Bill No.");
315
	    orderHeaderRow.createCell(23).setCellValue("Airway Bill No.");
274
	    orderHeaderRow.createCell(24).setCellValue("Billed By");
316
	    orderHeaderRow.createCell(24).setCellValue("Billed By");
275
	    orderHeaderRow.createCell(25).setCellValue("Receiver");
317
	    orderHeaderRow.createCell(25).setCellValue("Receiver");
276
	    orderHeaderRow.createCell(26).setCellValue("Tracking Id");
318
	    orderHeaderRow.createCell(26).setCellValue("Tracking Id");
277
	    orderHeaderRow.createCell(27).setCellValue("Accepted Timestamp");
319
	    orderHeaderRow.createCell(27).setCellValue("Accepted Timestamp");
278
	    orderHeaderRow.createCell(28).setCellValue("Delivery Timestamp");
320
	    orderHeaderRow.createCell(28).setCellValue("Delivery Timestamp");
279
	    orderHeaderRow.createCell(29).setCellValue("Expected Delivery Time");
321
	    orderHeaderRow.createCell(29).setCellValue("Expected Delivery Time");
-
 
322
	    
-
 
323
	    orderHeaderRow.createCell(30).setCellValue("Payment Id");
-
 
324
	    orderHeaderRow.createCell(31).setCellValue("Payment Status");
-
 
325
	    orderHeaderRow.createCell(32).setCellValue("Gateway Payment Id");
-
 
326
	    orderHeaderRow.createCell(33).setCellValue("Gateway Transaction Date");
-
 
327
	    orderHeaderRow.createCell(34).setCellValue("Gateway Txn Id");
-
 
328
	    orderHeaderRow.createCell(35).setCellValue("Gateway Txn Status");
-
 
329
	    orderHeaderRow.createCell(36).setCellValue("Reference Code");
-
 
330
	    orderHeaderRow.createCell(37).setCellValue("Gateway Id");
-
 
331
	    orderHeaderRow.createCell(38).setCellValue("Amount");
-
 
332
	    orderHeaderRow.createCell(39).setCellValue("Description");
-
 
333
	    orderHeaderRow.createCell(40).setCellValue("Auth Code");
-
 
334
	    orderHeaderRow.createCell(41).setCellValue("Error Code");
280
 
335
 
281
	    for(Transaction transaction : transactions)	{
336
	    for(Transaction transaction : transactions)	{
282
	    	List<Order> orders = transaction.getOrders();
337
	    	List<Order> orders = transaction.getOrders();
283
	    	Date transactionDate = new Date(transaction.getCreatedOn());
338
	    	Date transactionDate = new Date(transaction.getCreatedOn());
284
	    	long transactionId = transaction.getId();
339
	    	long transactionId = transaction.getId();
285
	    	String transactionStatus = transaction.getStatusDescription();
340
	    	String transactionStatus = transaction.getStatusDescription();
286
	    	for(Order order : orders)	{
341
	    	for(Order order : orders)	{
287
		    	transactionSerialNo ++;
342
		    	transactionSerialNo ++;
288
		    	Row contentRow = transactionSheet.createRow(transactionSerialNo);
343
		    	Row contentRow = transactionSheet.createRow(transactionSerialNo);
289
			    LineItem lineItem = order.getLineitems().get(0);
344
			    LineItem lineItem = order.getLineitems().get(0);
-
 
345
			    Payment payment = txnIdToPaymentMap.get(transactionId);
290
			    
346
			    
291
			    contentRow.createCell(0).setCellValue(transactionId);
347
			    contentRow.createCell(0).setCellValue(transactionId);
292
			    contentRow.createCell(1).setCellValue(dateFormat.format(transactionDate));
348
			    contentRow.createCell(1).setCellValue(DATE_TIME_FORMAT.format(transactionDate));
293
			    contentRow.createCell(2).setCellValue(transactionStatus);
349
			    contentRow.createCell(2).setCellValue(transactionStatus);
294
			    contentRow.createCell(3).setCellValue(order.getId());
350
			    contentRow.createCell(3).setCellValue(order.getId());
295
			    contentRow.createCell(4).setCellValue(order.getInvoice_number());
351
			    contentRow.createCell(4).setCellValue(order.getInvoice_number());
296
			    contentRow.createCell(5).setCellValue(dateFormat.format(new Date(order.getBilling_timestamp())));
352
			    contentRow.createCell(5).setCellValue(DATE_TIME_FORMAT.format(new Date(order.getBilling_timestamp())));
297
			    contentRow.createCell(6).setCellValue(order.getStatusDescription());
353
			    contentRow.createCell(6).setCellValue(order.getStatusDescription());
-
 
354
			    
298
			    contentRow.createCell(7).setCellValue(getValueForEmptyString(lineItem.getBrand()));
355
			    contentRow.createCell(7).setCellValue(getValueForEmptyString(lineItem.getBrand()));
299
			    contentRow.createCell(8).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
356
			    contentRow.createCell(8).setCellValue(getValueForEmptyString(lineItem.getModel_name()));
300
			    contentRow.createCell(9).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
357
			    contentRow.createCell(9).setCellValue(getValueForEmptyString(lineItem.getModel_number()));
301
			    contentRow.createCell(10).setCellValue(getValueForEmptyString(lineItem.getColor()));
358
			    contentRow.createCell(10).setCellValue(getValueForEmptyString(lineItem.getColor()));
302
			    contentRow.createCell(11).setCellValue(lineItem.getQuantity());
359
			    contentRow.createCell(11).setCellValue(lineItem.getQuantity());
303
			    contentRow.createCell(12).setCellValue(lineItem.getUnit_price());
360
			    contentRow.createCell(12).setCellValue(lineItem.getUnit_price());
304
			    contentRow.createCell(13).setCellValue(lineItem.getTotal_price());
361
			    contentRow.createCell(13).setCellValue(lineItem.getTotal_price());
-
 
362
			    
305
			    contentRow.createCell(14).setCellValue(order.getCustomer_id());
363
			    contentRow.createCell(14).setCellValue(order.getCustomer_id());
306
			    contentRow.createCell(15).setCellValue(order.getCustomer_name());
364
			    contentRow.createCell(15).setCellValue(order.getCustomer_name());
307
			    contentRow.createCell(16).setCellValue(order.getCustomer_address1());
365
			    contentRow.createCell(16).setCellValue(order.getCustomer_address1());
308
			    contentRow.createCell(17).setCellValue(order.getCustomer_address2());
366
			    contentRow.createCell(17).setCellValue(order.getCustomer_address2());
309
			    contentRow.createCell(18).setCellValue(order.getCustomer_city());
367
			    contentRow.createCell(18).setCellValue(order.getCustomer_city());
310
			    contentRow.createCell(19).setCellValue(order.getCustomer_state());
368
			    contentRow.createCell(19).setCellValue(order.getCustomer_state());
311
			    contentRow.createCell(20).setCellValue(order.getCustomer_pincode());
369
			    contentRow.createCell(20).setCellValue(order.getCustomer_pincode());
312
			    contentRow.createCell(21).setCellValue(order.getCustomer_mobilenumber());
370
			    contentRow.createCell(21).setCellValue(order.getCustomer_mobilenumber());
313
			    contentRow.createCell(22).setCellValue(order.getCustomer_email());
371
			    contentRow.createCell(22).setCellValue(order.getCustomer_email());
-
 
372
			    
314
			    contentRow.createCell(23).setCellValue(order.getAirwaybill_no());
373
			    contentRow.createCell(23).setCellValue(order.getAirwaybill_no());
315
			    contentRow.createCell(24).setCellValue(order.getBilled_by());
374
			    contentRow.createCell(24).setCellValue(order.getBilled_by());
316
			    contentRow.createCell(25).setCellValue(order.getReceiver());
375
			    contentRow.createCell(25).setCellValue(order.getReceiver());
317
			    contentRow.createCell(26).setCellValue(order.getTracking_id());
376
			    contentRow.createCell(26).setCellValue(order.getTracking_id());
318
			    contentRow.createCell(27).setCellValue(dateFormat.format(new Date(order.getAccepted_timestamp())));
377
			    contentRow.createCell(27).setCellValue(DATE_TIME_FORMAT.format(new Date(order.getAccepted_timestamp())));
319
			    contentRow.createCell(28).setCellValue(dateFormat.format(new Date(order.getDelivery_timestamp())));
378
			    contentRow.createCell(28).setCellValue(DATE_TIME_FORMAT.format(new Date(order.getDelivery_timestamp())));
320
			    contentRow.createCell(29).setCellValue(dateFormat.format(new Date(order.getExpected_delivery_time())));
379
			    contentRow.createCell(29).setCellValue(DATE_TIME_FORMAT.format(new Date(order.getExpected_delivery_time())));
-
 
380
			    
-
 
381
				if (payment != null) {
-
 
382
					contentRow.createCell(30).setCellValue(payment.getPaymentId());
-
 
383
					contentRow.createCell(31).setCellValue(payment.getStatus().name());
-
 
384
					contentRow.createCell(32).setCellValue(payment.getGatewayPaymentId());
-
 
385
					contentRow.createCell(33).setCellValue(payment.getGatewayTxnDate());
-
 
386
					contentRow.createCell(34).setCellValue(payment.getGatewayTxnId());
-
 
387
					contentRow.createCell(35).setCellValue(payment.getGatewayTxnStatus());
-
 
388
					contentRow.createCell(36).setCellValue(payment.getReferenceCode());
-
 
389
					contentRow.createCell(37).setCellValue(payment.getGatewayId());
-
 
390
					contentRow.createCell(38).setCellValue(payment.getAmount());
-
 
391
					contentRow.createCell(39).setCellValue(payment.getDescription());
-
 
392
					contentRow.createCell(40).setCellValue(payment.getAuthCode());
-
 
393
					contentRow.createCell(41).setCellValue(payment.getErrorCode());
-
 
394
				}
321
		    }
395
		    }
322
	    }
396
	    }
323
	}
397
	}
324
 
398
 
325
	private String getValueForEmptyString(String s){
399
	private String getValueForEmptyString(String s){
Line 327... Line 401...
327
			return "-";
401
			return "-";
328
		else
402
		else
329
			return s; 
403
			return s; 
330
	}
404
	}
331
	
405
	
332
	private void createUserSheet(User user, Workbook wb, CellStyle style) {
406
	private void createUserSheet(User user, List<UserCommunication> userCommunications, Workbook wb, CellStyle style) {
333
	    Sheet userSheet = wb.createSheet("User");
407
	    Sheet userSheet = wb.createSheet("User");
334
	    short userSerialNo = 0;
408
	    short userSerialNo = 0;
335
    	// Create the header row and put all the titles in it. Rows are 0 based.
409
    	// Create the header row and put all the titles in it. Rows are 0 based.
336
	    
410
	    
337
	    Row titleRow = userSheet.createRow(userSerialNo++);
411
	    Row titleRow = userSheet.createRow(userSerialNo++);
Line 404... Line 478...
404
					userSerialNo, 0, 6));
478
					userSerialNo, 0, 6));
405
			userContentRow.createCell(0).setCellValue("Other Addresses");
479
			userContentRow.createCell(0).setCellValue("Other Addresses");
406
 
480
 
407
			for (Address address : user.getAddresses()) {
481
			for (Address address : user.getAddresses()) {
408
				if (user.getDefaultAddressId() != address.getId()) {
482
				if (user.getDefaultAddressId() != address.getId()) {
409
 
-
 
410
					userSerialNo++;
483
					userSerialNo++;
411
					userContentRow = userSheet.createRow(userSerialNo);
484
					userContentRow = userSheet.createRow(userSerialNo);
412
					userContentRow.createCell(0)
485
					userContentRow.createCell(0)
413
							.setCellValue(address.getName());
486
							.setCellValue(address.getName());
414
					userContentRow.createCell(1).setCellValue(
487
					userContentRow.createCell(1).setCellValue(
Line 422... Line 495...
422
					userContentRow.createCell(5).setCellValue(address.getPin());
495
					userContentRow.createCell(5).setCellValue(address.getPin());
423
					userContentRow.createCell(6).setCellValue(
496
					userContentRow.createCell(6).setCellValue(
424
							address.getPhone());
497
							address.getPhone());
425
				}
498
				}
426
			}
499
			}
427
		}
-
 
428
	}
-
 
429
	
-
 
430
	public static void main(String[] args){
-
 
431
		UserOrdersController usc = new UserOrdersController();
-
 
432
		usc.request = new HttpServletRequest() {
-
 
433
			
-
 
434
			@Override
-
 
435
			public void setCharacterEncoding(String arg0)
-
 
436
					throws UnsupportedEncodingException {
-
 
437
				// TODO Auto-generated method stub
-
 
438
				
-
 
439
			}
-
 
440
			
-
 
441
			@Override
-
 
442
			public void setAttribute(String arg0, Object arg1) {
-
 
443
				// TODO Auto-generated method stub
-
 
444
				
-
 
445
			}
-
 
446
			
-
 
447
			@Override
-
 
448
			public void removeAttribute(String arg0) {
-
 
449
				// TODO Auto-generated method stub
-
 
450
				
-
 
451
			}
-
 
452
			
-
 
453
			@Override
-
 
454
			public boolean isSecure() {
-
 
455
				// TODO Auto-generated method stub
-
 
456
				return false;
-
 
457
			}
-
 
458
			
-
 
459
			@Override
-
 
460
			public int getServerPort() {
-
 
461
				// TODO Auto-generated method stub
-
 
462
				return 0;
-
 
463
			}
-
 
464
			
-
 
465
			@Override
-
 
466
			public String getServerName() {
-
 
467
				// TODO Auto-generated method stub
-
 
468
				return null;
-
 
469
			}
-
 
470
			
-
 
471
			@Override
-
 
472
			public String getScheme() {
-
 
473
				// TODO Auto-generated method stub
-
 
474
				return null;
-
 
475
			}
-
 
476
			
-
 
477
			@Override
-
 
478
			public RequestDispatcher getRequestDispatcher(String arg0) {
-
 
479
				// TODO Auto-generated method stub
-
 
480
				return null;
-
 
481
			}
-
 
482
			
-
 
483
			@Override
-
 
484
			public int getRemotePort() {
-
 
485
				// TODO Auto-generated method stub
-
 
486
				return 0;
-
 
487
			}
-
 
488
			
-
 
489
			@Override
-
 
490
			public String getRemoteHost() {
-
 
491
				// TODO Auto-generated method stub
-
 
492
				return null;
-
 
493
			}
-
 
494
			
-
 
495
			@Override
-
 
496
			public String getRemoteAddr() {
-
 
497
				// TODO Auto-generated method stub
-
 
498
				return null;
-
 
499
			}
-
 
500
			
-
 
501
			@Override
-
 
502
			public String getRealPath(String arg0) {
-
 
503
				// TODO Auto-generated method stub
-
 
504
				return null;
-
 
505
			}
-
 
506
			
-
 
507
			@Override
-
 
508
			public BufferedReader getReader() throws IOException {
-
 
509
				// TODO Auto-generated method stub
-
 
510
				return null;
-
 
511
			}
-
 
512
			
-
 
513
			@Override
-
 
514
			public String getProtocol() {
-
 
515
				// TODO Auto-generated method stub
-
 
516
				return null;
-
 
517
			}
-
 
518
			
-
 
519
			@Override
-
 
520
			public String[] getParameterValues(String arg0) {
-
 
521
				// TODO Auto-generated method stub
-
 
522
				return null;
-
 
523
			}
-
 
524
			
-
 
525
			@Override
-
 
526
			public Enumeration getParameterNames() {
-
 
527
				// TODO Auto-generated method stub
-
 
528
				return null;
-
 
529
			}
-
 
530
			
-
 
531
			@Override
-
 
532
			public Map getParameterMap() {
-
 
533
				// TODO Auto-generated method stub
-
 
534
				return null;
-
 
535
			}
-
 
536
			
-
 
537
			@Override
-
 
538
			public String getParameter(String arg0) {
-
 
539
				return "test@test.com";
-
 
540
			}
-
 
541
			
-
 
542
			@Override
-
 
543
			public Enumeration getLocales() {
-
 
544
				// TODO Auto-generated method stub
-
 
545
				return null;
-
 
546
			}
-
 
547
			
-
 
548
			@Override
-
 
549
			public Locale getLocale() {
-
 
550
				// TODO Auto-generated method stub
-
 
551
				return null;
-
 
552
			}
-
 
553
			
-
 
554
			@Override
-
 
555
			public int getLocalPort() {
-
 
556
				// TODO Auto-generated method stub
-
 
557
				return 0;
-
 
558
			}
-
 
559
			
-
 
560
			@Override
-
 
561
			public String getLocalName() {
-
 
562
				// TODO Auto-generated method stub
-
 
563
				return null;
-
 
564
			}
-
 
565
			
-
 
566
			@Override
-
 
567
			public String getLocalAddr() {
-
 
568
				// TODO Auto-generated method stub
-
 
569
				return null;
-
 
570
			}
-
 
571
			
-
 
572
			@Override
-
 
573
			public ServletInputStream getInputStream() throws IOException {
-
 
574
				// TODO Auto-generated method stub
-
 
575
				return null;
-
 
576
			}
-
 
577
			
-
 
578
			@Override
-
 
579
			public String getContentType() {
-
 
580
				// TODO Auto-generated method stub
-
 
581
				return null;
-
 
582
			}
-
 
583
			
-
 
584
			@Override
-
 
585
			public int getContentLength() {
-
 
586
				// TODO Auto-generated method stub
-
 
587
				return 0;
-
 
588
			}
-
 
589
			
-
 
590
			@Override
-
 
591
			public String getCharacterEncoding() {
-
 
592
				// TODO Auto-generated method stub
-
 
593
				return null;
-
 
594
			}
-
 
595
			
-
 
596
			@Override
-
 
597
			public Enumeration getAttributeNames() {
-
 
598
				// TODO Auto-generated method stub
-
 
599
				return null;
-
 
600
			}
-
 
601
			
-
 
602
			@Override
-
 
603
			public Object getAttribute(String arg0) {
-
 
604
				// TODO Auto-generated method stub
-
 
605
				return null;
-
 
606
			}
-
 
607
			
-
 
608
			@Override
-
 
609
			public boolean isUserInRole(String arg0) {
-
 
610
				// TODO Auto-generated method stub
-
 
611
				return false;
-
 
612
			}
-
 
613
			
-
 
614
			@Override
-
 
615
			public boolean isRequestedSessionIdValid() {
-
 
616
				// TODO Auto-generated method stub
-
 
617
				return false;
-
 
618
			}
-
 
619
			
-
 
620
			@Override
-
 
621
			public boolean isRequestedSessionIdFromUrl() {
-
 
622
				// TODO Auto-generated method stub
-
 
623
				return false;
-
 
624
			}
-
 
625
			
-
 
626
			@Override
-
 
627
			public boolean isRequestedSessionIdFromURL() {
-
 
628
				// TODO Auto-generated method stub
-
 
629
				return false;
-
 
630
			}
-
 
631
			
-
 
632
			@Override
-
 
633
			public boolean isRequestedSessionIdFromCookie() {
-
 
634
				// TODO Auto-generated method stub
-
 
635
				return false;
-
 
636
			}
-
 
637
			
-
 
638
			@Override
-
 
639
			public Principal getUserPrincipal() {
-
 
640
				// TODO Auto-generated method stub
-
 
641
				return null;
-
 
642
			}
-
 
643
			
-
 
644
			@Override
-
 
645
			public HttpSession getSession(boolean arg0) {
-
 
646
				// TODO Auto-generated method stub
-
 
647
				return null;
-
 
648
			}
-
 
649
			
-
 
650
			@Override
-
 
651
			public HttpSession getSession() {
-
 
652
				// TODO Auto-generated method stub
-
 
653
				return null;
-
 
654
			}
-
 
655
			
-
 
656
			@Override
-
 
657
			public String getServletPath() {
-
 
658
				// TODO Auto-generated method stub
-
 
659
				return null;
-
 
660
			}
-
 
661
			
500
			
662
			@Override
-
 
663
			public String getRequestedSessionId() {
-
 
664
				// TODO Auto-generated method stub
-
 
665
				return null;
-
 
666
			}
-
 
667
			
-
 
668
			@Override
-
 
669
			public StringBuffer getRequestURL() {
-
 
670
				// TODO Auto-generated method stub
-
 
671
				return null;
-
 
672
			}
-
 
673
			
-
 
674
			@Override
-
 
675
			public String getRequestURI() {
-
 
676
				// TODO Auto-generated method stub
-
 
677
				return null;
-
 
678
			}
-
 
679
			
-
 
680
			@Override
-
 
681
			public String getRemoteUser() {
-
 
682
				// TODO Auto-generated method stub
-
 
683
				return null;
-
 
684
			}
-
 
685
			
-
 
686
			@Override
-
 
687
			public String getQueryString() {
-
 
688
				// TODO Auto-generated method stub
-
 
689
				return null;
-
 
690
			}
-
 
691
			
-
 
692
			@Override
-
 
693
			public String getPathTranslated() {
-
 
694
				// TODO Auto-generated method stub
-
 
695
				return null;
-
 
696
			}
-
 
697
			
-
 
698
			@Override
-
 
699
			public String getPathInfo() {
-
 
700
				// TODO Auto-generated method stub
-
 
701
				return null;
-
 
702
			}
-
 
703
			
-
 
704
			@Override
-
 
705
			public String getMethod() {
-
 
706
				// TODO Auto-generated method stub
-
 
707
				return null;
-
 
708
			}
-
 
709
			
-
 
710
			@Override
-
 
711
			public int getIntHeader(String arg0) {
-
 
712
				// TODO Auto-generated method stub
-
 
713
				return 0;
-
 
714
			}
-
 
715
			
-
 
716
			@Override
-
 
717
			public Enumeration getHeaders(String arg0) {
-
 
718
				// TODO Auto-generated method stub
-
 
719
				return null;
-
 
720
			}
-
 
721
			
501
			
722
			@Override
502
			userSerialNo+=2;
723
			public Enumeration getHeaderNames() {
503
			userContentRow = userSheet.createRow(userSerialNo);
724
				// TODO Auto-generated method stub
504
			userSheet.addMergedRegion(new CellRangeAddress(userSerialNo,
725
				return null;
505
					userSerialNo, 0, 6));
726
			}
-
 
727
			
-
 
-
 
506
			userContentRow.createCell(0).setCellValue("User Communication");
728
			@Override
507
			userSerialNo++;
729
			public String getHeader(String arg0) {
508
			Row commHeaderRow = userSheet.createRow(userSerialNo);
730
				// TODO Auto-generated method stub
509
		    commHeaderRow.createCell(0).setCellValue("Order Id");
731
				return null;
510
		    commHeaderRow.createCell(1).setCellValue("Communication Type");
732
			}
-
 
733
			
-
 
734
			@Override
-
 
735
			public long getDateHeader(String arg0) {
511
		    commHeaderRow.createCell(2).setCellValue("AirwayBill No");
736
				// TODO Auto-generated method stub
512
		    commHeaderRow.createCell(3).setCellValue("TimeStamp");
737
				return 0;
513
		    commHeaderRow.createCell(4).setCellValue("Product Name");
738
			}
-
 
739
			
-
 
740
			@Override
-
 
741
			public Cookie[] getCookies() {
514
		    commHeaderRow.createCell(5).setCellValue("Reply To");
742
				// TODO Auto-generated method stub
515
		    commHeaderRow.createCell(6).setCellValue("Subject");
743
				return null;
516
		    commHeaderRow.createCell(7).setCellValue("Message");
744
			}
517
		    
745
			
-
 
-
 
518
			for( UserCommunication userComm : userCommunications) {
746
			@Override
519
				userSerialNo++;
747
			public String getContextPath() {
520
				userContentRow = userSheet.createRow(userSerialNo);
748
				// TODO Auto-generated method stub
521
				userContentRow.createCell(0).setCellValue(userComm.getOrderId());
749
				return null;
522
				if (userComm.getCommunicationType() != null) {
-
 
523
					userContentRow.createCell(1).setCellValue(userComm.getCommunicationType().name());
750
			}
524
				}
751
			
-
 
-
 
525
				userContentRow.createCell(2).setCellValue(userComm.getAirwaybillNo());
-
 
526
				userContentRow.createCell(3).setCellValue(DATE_TIME_FORMAT.format(userComm.getCommunication_timestamp()));
752
			@Override
527
				userContentRow.createCell(4).setCellValue(userComm.getProductName());
753
			public String getAuthType() {
528
				userContentRow.createCell(5).setCellValue(userComm.getReplyTo());
754
				// TODO Auto-generated method stub
529
				userContentRow.createCell(6).setCellValue(userComm.getSubject());
755
				return null;
530
				userContentRow.createCell(7).setCellValue(userComm.getMessage());
756
			}
531
			}
757
		};
532
		}
758
		usc.create();
-
 
759
	}
533
	}
760
 
534
	
761
	public String getErrorMsg() {
535
	public String getErrorMsg() {
762
		return errorMsg;
536
		return errorMsg;
763
	}
537
	}
764
}
538
}
765
 
-
 
766
539