Subversion Repositories SmartDukaan

Rev

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

Rev 1631 Rev 1655
Line 21... Line 21...
21
import java.util.List;
21
import java.util.List;
22
 
22
 
23
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
23
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
24
import org.apache.poi.ss.usermodel.Cell;
24
import org.apache.poi.ss.usermodel.Cell;
25
import org.apache.poi.ss.usermodel.CellStyle;
25
import org.apache.poi.ss.usermodel.CellStyle;
-
 
26
import org.apache.poi.ss.usermodel.DataFormat;
26
import org.apache.poi.ss.usermodel.Font;
27
import org.apache.poi.ss.usermodel.Font;
27
import org.apache.poi.ss.usermodel.Row;
28
import org.apache.poi.ss.usermodel.Row;
28
import org.apache.poi.ss.usermodel.Sheet;
29
import org.apache.poi.ss.usermodel.Sheet;
29
import org.apache.poi.ss.usermodel.Workbook;
30
import org.apache.poi.ss.usermodel.Workbook;
30
import org.apache.poi.ss.util.CellRangeAddress;
31
import org.apache.poi.ss.util.CellRangeAddress;
Line 84... Line 85...
84
 
85
 
85
		Font font = wb.createFont();
86
		Font font = wb.createFont();
86
		font.setBoldweight(Font.BOLDWEIGHT_BOLD);
87
		font.setBoldweight(Font.BOLDWEIGHT_BOLD);
87
		CellStyle style = wb.createCellStyle();
88
		CellStyle style = wb.createCellStyle();
88
		style.setFont(font);
89
		style.setFont(font);
-
 
90
		
-
 
91
		CellStyle styleWT = wb.createCellStyle();
-
 
92
        styleWT.setWrapText(true);
-
 
93
        
-
 
94
        DataFormat format = wb.createDataFormat();
-
 
95
        CellStyle styleAmount = wb.createCellStyle();
-
 
96
        styleAmount.setDataFormat(format.getFormat("#,##0.00"));
89
 
97
 
90
		Sheet paymentSheet = wb.createSheet("Payment");
98
		Sheet paymentSheet = wb.createSheet("Payment");
91
		short paymentSerialNo = 0;
99
		short paymentSerialNo = 0;
92
 
100
 
93
		Row titleRow = paymentSheet.createRow(paymentSerialNo ++);
101
		Row titleRow = paymentSheet.createRow(paymentSerialNo ++);
Line 109... Line 117...
109
		headerRow.createCell(6).setCellValue("Transaction Time");
117
		headerRow.createCell(6).setCellValue("Transaction Time");
110
 
118
 
111
		headerRow.createCell(7).setCellValue("Customer Id");
119
		headerRow.createCell(7).setCellValue("Customer Id");
112
		headerRow.createCell(8).setCellValue("Name");
120
		headerRow.createCell(8).setCellValue("Name");
113
		headerRow.createCell(9).setCellValue("MobileNo");
121
		headerRow.createCell(9).setCellValue("MobileNo");
-
 
122
		headerRow.createCell(10).setCellValue("Address");
-
 
123
		headerRow.getCell(10).setCellStyle(styleWT);
114
		headerRow.createCell(10).setCellValue("Pincode");
124
		headerRow.createCell(11).setCellValue("Pincode");
115
		headerRow.createCell(11).setCellValue("City");
125
		headerRow.createCell(12).setCellValue("City");
116
		headerRow.createCell(12).setCellValue("State");
126
		headerRow.createCell(13).setCellValue("State");
117
		headerRow.createCell(13).setCellValue("Email");
127
		headerRow.createCell(14).setCellValue("Email");
-
 
128
 
118
		headerRow.createCell(14).setCellValue("Order Id");
129
		headerRow.createCell(15).setCellValue("Order Id");
119
		headerRow.createCell(15).setCellValue("Order Status");
130
		headerRow.createCell(16).setCellValue("Order Status");
120
		headerRow.createCell(16).setCellValue("Order Status Description");
131
		headerRow.createCell(17).setCellValue("Order Status Description");
121
 
132
 
122
		headerRow.createCell(17).setCellValue("Item Id");
133
		headerRow.createCell(18).setCellValue("Item Id");
123
		headerRow.createCell(18).setCellValue("Product Group");
134
		headerRow.createCell(19).setCellValue("Product Group");
124
		headerRow.createCell(19).setCellValue("Brand");
135
		headerRow.createCell(20).setCellValue("Brand");
125
		headerRow.createCell(20).setCellValue("Model Name");
136
		headerRow.createCell(21).setCellValue("Model Name");
126
		headerRow.createCell(21).setCellValue("Model Number");
137
		headerRow.createCell(22).setCellValue("Model Number");
127
		headerRow.createCell(22).setCellValue("Quantity");
138
		headerRow.createCell(23).setCellValue("Qty");
128
 
139
		
-
 
140
		paymentSheet.setColumnWidth(10, 256*35); // set width of address column to 35 characters
129
		List<Order> orders;
141
		List<Order> orders;
130
		long txnId;
142
		long txnId;
131
		Row contentRow;
143
		Row contentRow;
132
		Calendar calendar = Calendar.getInstance();
144
		Calendar calendar = Calendar.getInstance();
133
		DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
145
		DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
Line 136... Line 148...
136
				paymentSerialNo++;
148
				paymentSerialNo++;
137
				contentRow = paymentSheet.createRow(paymentSerialNo);
149
				contentRow = paymentSheet.createRow(paymentSerialNo);
138
				contentRow.createCell(0).setCellValue(payment.getPaymentId());
150
				contentRow.createCell(0).setCellValue(payment.getPaymentId());
139
				contentRow.createCell(1).setCellValue(payment.getMerchantTxnId());
151
				contentRow.createCell(1).setCellValue(payment.getMerchantTxnId());
140
				contentRow.createCell(2).setCellValue(payment.getAmount());
152
				contentRow.createCell(2).setCellValue(payment.getAmount());
-
 
153
				contentRow.getCell(2).setCellStyle(styleAmount);
141
				contentRow.createCell(3).setCellValue(payment.getStatus().name());
154
				contentRow.createCell(3).setCellValue(payment.getStatus().name());
142
				contentRow.createCell(4).setCellValue(payment.getDescription());
155
				contentRow.createCell(4).setCellValue(payment.getDescription());
143
				contentRow.createCell(5).setCellValue(payment.getReferenceCode());
156
				contentRow.createCell(5).setCellValue(payment.getReferenceCode());
144
				calendar.setTimeInMillis(payment.getInitTimestamp());
157
				calendar.setTimeInMillis(payment.getInitTimestamp());
145
				contentRow.createCell(6).setCellValue(formatter.format(calendar.getTime()));
158
				contentRow.createCell(6).setCellValue(formatter.format(calendar.getTime()));
146
 
159
 
147
				txnId = tClient.getTransaction(payment.getMerchantTxnId()).getId();
160
				txnId = tClient.getTransaction(payment.getMerchantTxnId()).getId();
148
				orders = tClient.getOrdersForTransaction(txnId, payment.getUserId());
161
				orders = tClient.getOrdersForTransaction(txnId, payment.getUserId());
149
				List<LineItem> lineItems;
162
				List<LineItem> lineItems;
150
 
163
				
-
 
164
				String address = "";
-
 
165
				float rowHeight = paymentSheet.getDefaultRowHeightInPoints();
151
				if(orders != null && !orders.isEmpty()) {
166
				if(orders != null && !orders.isEmpty()) {
152
					contentRow.createCell(7).setCellValue(orders.get(0).getCustomer_id());
167
					contentRow.createCell(7).setCellValue(orders.get(0).getCustomer_id());
153
					contentRow.createCell(8).setCellValue(orders.get(0).getCustomer_name());
168
					contentRow.createCell(8).setCellValue(orders.get(0).getCustomer_name());
154
					contentRow.createCell(9).setCellValue(orders.get(0).getCustomer_mobilenumber());
169
					contentRow.createCell(9).setCellValue(orders.get(0).getCustomer_mobilenumber());
-
 
170
					address = orders.get(0).getCustomer_address1() + ", " + orders.get(0).getCustomer_address2();
-
 
171
					contentRow.createCell(10).setCellValue(address);
-
 
172
					contentRow.getCell(10).setCellStyle(styleWT);
-
 
173
					int maxLength = Math.max(address.length(), paymentSheet.getDefaultColumnWidth());
-
 
174
				    contentRow.setHeightInPoints((maxLength / 35 + 1) * rowHeight);  // Set Row Height
155
					contentRow.createCell(10).setCellValue(orders.get(0).getCustomer_pincode());
175
					contentRow.createCell(11).setCellValue(orders.get(0).getCustomer_pincode());
156
					contentRow.createCell(11).setCellValue(orders.get(0).getCustomer_city());
176
					contentRow.createCell(12).setCellValue(orders.get(0).getCustomer_city());
157
					contentRow.createCell(12).setCellValue(orders.get(0).getCustomer_state());
177
					contentRow.createCell(13).setCellValue(orders.get(0).getCustomer_state());
158
					contentRow.createCell(13).setCellValue(orders.get(0).getCustomer_email());		
178
					contentRow.createCell(14).setCellValue(orders.get(0).getCustomer_email());		
159
 
179
 
160
					for(Order o : orders) {
180
					for(Order o : orders) {
161
						paymentSerialNo++;
181
						paymentSerialNo++;
162
						contentRow = paymentSheet.createRow(paymentSerialNo);
182
						contentRow = paymentSheet.createRow(paymentSerialNo);
163
 
183
 
164
						contentRow.createCell(14).setCellValue(o.getId());
184
						contentRow.createCell(15).setCellValue(o.getId());
165
						contentRow.createCell(15).setCellValue(o.getStatus().name());
185
						contentRow.createCell(16).setCellValue(o.getStatus().name());
166
						contentRow.createCell(16).setCellValue(o.getStatusDescription());
186
						contentRow.createCell(17).setCellValue(o.getStatusDescription());
167
 
187
 
168
						lineItems = tClient.getLineItemsForOrder(o.getId());
188
						lineItems = tClient.getLineItemsForOrder(o.getId());
169
						for(LineItem i : lineItems) {
189
						for(LineItem i : lineItems) {
170
							/*Right now there can be only one line item in an order.
190
							/*Right now there can be only one line item in an order.
171
					  So putting line item details in the same row as order details. Commenting below 2 lines for this.*/
191
					  So putting line item details in the same row as order details. Commenting below 2 lines for this.*/
172
							//paymentSerialNo++;
192
							//paymentSerialNo++;
173
							//contentRow = paymentSheet.createRow(paymentSerialNo);
193
							//contentRow = paymentSheet.createRow(paymentSerialNo);
174
 
194
 
175
							contentRow.createCell(17).setCellValue(i.getId());
195
							contentRow.createCell(18).setCellValue(i.getId());
176
							contentRow.createCell(18).setCellValue(i.getProductGroup());
196
							contentRow.createCell(19).setCellValue(i.getProductGroup());
177
							contentRow.createCell(19).setCellValue(i.getBrand());
197
							contentRow.createCell(20).setCellValue(i.getBrand());
178
							contentRow.createCell(20).setCellValue(i.getModel_name());
198
							contentRow.createCell(21).setCellValue(i.getModel_name());
179
							contentRow.createCell(21).setCellValue(i.getModel_number());
199
							contentRow.createCell(22).setCellValue(i.getModel_number());
180
							contentRow.createCell(22).setCellValue(i.getQuantity());
200
							contentRow.createCell(23).setCellValue(i.getQuantity());
181
						}
201
						}
182
					}
202
					}
183
				}
203
				}
184
			} catch (TransactionServiceException e) {
204
			} catch (TransactionServiceException e) {
185
				e.printStackTrace();
205
				e.printStackTrace();
Line 196... Line 216...
196
		paymentSheet.autoSizeColumn(5);
216
		paymentSheet.autoSizeColumn(5);
197
		paymentSheet.autoSizeColumn(6);
217
		paymentSheet.autoSizeColumn(6);
198
		paymentSheet.autoSizeColumn(7);
218
		paymentSheet.autoSizeColumn(7);
199
		paymentSheet.autoSizeColumn(8);
219
		paymentSheet.autoSizeColumn(8);
200
		paymentSheet.autoSizeColumn(9);
220
		paymentSheet.autoSizeColumn(9);
201
		paymentSheet.autoSizeColumn(10);
-
 
202
		paymentSheet.autoSizeColumn(11);
221
		paymentSheet.autoSizeColumn(11);
203
		paymentSheet.autoSizeColumn(12);
222
		paymentSheet.autoSizeColumn(12);
204
		paymentSheet.autoSizeColumn(13);
223
		paymentSheet.autoSizeColumn(13);
205
		paymentSheet.autoSizeColumn(14);
224
		paymentSheet.autoSizeColumn(14);
206
		paymentSheet.autoSizeColumn(15);
225
		paymentSheet.autoSizeColumn(15);
Line 209... Line 228...
209
		paymentSheet.autoSizeColumn(18);
228
		paymentSheet.autoSizeColumn(18);
210
		paymentSheet.autoSizeColumn(19);
229
		paymentSheet.autoSizeColumn(19);
211
		paymentSheet.autoSizeColumn(20);
230
		paymentSheet.autoSizeColumn(20);
212
		paymentSheet.autoSizeColumn(21);
231
		paymentSheet.autoSizeColumn(21);
213
		paymentSheet.autoSizeColumn(22);
232
		paymentSheet.autoSizeColumn(22);
-
 
233
		paymentSheet.autoSizeColumn(23);
214
 
234
 
215
		// Write the workbook to the output stream
235
		// Write the workbook to the output stream
216
		try {
236
		try {
217
			wb.write(baosXLS);
237
			wb.write(baosXLS);
218
			baosXLS.close();
238
			baosXLS.close();