| Line 3... |
Line 3... |
| 3 |
import in.shop2020.model.v1.order.LineItem;
|
3 |
import in.shop2020.model.v1.order.LineItem;
|
| 4 |
import in.shop2020.model.v1.order.Order;
|
4 |
import in.shop2020.model.v1.order.Order;
|
| 5 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
5 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 6 |
import in.shop2020.payments.Payment;
|
6 |
import in.shop2020.payments.Payment;
|
| 7 |
import in.shop2020.payments.PaymentException;
|
7 |
import in.shop2020.payments.PaymentException;
|
| - |
|
8 |
import in.shop2020.payments.PaymentGateway;
|
| 8 |
import in.shop2020.payments.PaymentStatus;
|
9 |
import in.shop2020.payments.PaymentStatus;
|
| 9 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
10 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
| 10 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
11 |
import in.shop2020.thrift.clients.TransactionServiceClient;
|
| - |
|
12 |
import in.shop2020.thrift.clients.UserContextServiceClient;
|
| 11 |
|
13 |
|
| 12 |
import java.io.ByteArrayOutputStream;
|
14 |
import java.io.ByteArrayOutputStream;
|
| 13 |
import java.io.FileNotFoundException;
|
15 |
import java.io.FileNotFoundException;
|
| 14 |
import java.io.FileOutputStream;
|
16 |
import java.io.FileOutputStream;
|
| 15 |
import java.io.IOException;
|
17 |
import java.io.IOException;
|
| 16 |
import java.text.DateFormat;
|
18 |
import java.text.DateFormat;
|
| 17 |
import java.text.ParseException;
|
19 |
import java.text.ParseException;
|
| 18 |
import java.text.SimpleDateFormat;
|
20 |
import java.text.SimpleDateFormat;
|
| 19 |
import java.util.Calendar;
|
21 |
import java.util.Calendar;
|
| 20 |
import java.util.Date;
|
22 |
import java.util.Date;
|
| - |
|
23 |
import java.util.HashMap;
|
| 21 |
import java.util.List;
|
24 |
import java.util.List;
|
| - |
|
25 |
import java.util.Map;
|
| 22 |
|
26 |
|
| 23 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
27 |
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
| 24 |
import org.apache.poi.ss.usermodel.Cell;
|
28 |
import org.apache.poi.ss.usermodel.Cell;
|
| 25 |
import org.apache.poi.ss.usermodel.CellStyle;
|
29 |
import org.apache.poi.ss.usermodel.CellStyle;
|
| 26 |
import org.apache.poi.ss.usermodel.DataFormat;
|
30 |
import org.apache.poi.ss.usermodel.DataFormat;
|
| Line 36... |
Line 40... |
| 36 |
in.shop2020.model.v1.order.TransactionService.Client tClient;
|
40 |
in.shop2020.model.v1.order.TransactionService.Client tClient;
|
| 37 |
|
41 |
|
| 38 |
PaymentServiceClient psc;
|
42 |
PaymentServiceClient psc;
|
| 39 |
in.shop2020.payments.PaymentService.Client pClient;
|
43 |
in.shop2020.payments.PaymentService.Client pClient;
|
| 40 |
|
44 |
|
| - |
|
45 |
UserContextServiceClient usc;
|
| - |
|
46 |
in.shop2020.model.v1.user.UserContextService.Client uClient;
|
| - |
|
47 |
|
| - |
|
48 |
Map<Long, PaymentGateway> gateWays = new HashMap<Long, PaymentGateway>(3);
|
| - |
|
49 |
|
| 41 |
public PaymentDetailsGenerator() {
|
50 |
public PaymentDetailsGenerator() {
|
| 42 |
try {
|
51 |
try {
|
| 43 |
tsc = new TransactionServiceClient();
|
52 |
tsc = new TransactionServiceClient();
|
| 44 |
tClient = tsc.getClient();
|
53 |
tClient = tsc.getClient();
|
| - |
|
54 |
|
| 45 |
psc = new PaymentServiceClient();
|
55 |
psc = new PaymentServiceClient();
|
| 46 |
pClient = psc.getClient();
|
56 |
pClient = psc.getClient();
|
| - |
|
57 |
|
| - |
|
58 |
usc = new UserContextServiceClient();
|
| - |
|
59 |
uClient = usc.getClient();
|
| 47 |
} catch (Exception e) {
|
60 |
} catch (Exception e) {
|
| 48 |
e.printStackTrace();
|
61 |
e.printStackTrace();
|
| 49 |
}
|
62 |
}
|
| 50 |
}
|
63 |
}
|
| 51 |
|
64 |
|
| Line 64... |
Line 77... |
| 64 |
// as FAILED or INIT and for gateway Id = 1 (HDFC)
|
77 |
// as FAILED or INIT and for gateway Id = 1 (HDFC)
|
| 65 |
List<Payment> payments = null;
|
78 |
List<Payment> payments = null;
|
| 66 |
List<Payment> pendingPayments = null;
|
79 |
List<Payment> pendingPayments = null;
|
| 67 |
try {
|
80 |
try {
|
| 68 |
if(status == 0) {
|
81 |
if(status == 0) {
|
| 69 |
payments = pClient.getPayments(startDate.getTime(), endDate.getTime(), PaymentStatus.SUCCESS, 1);
|
82 |
payments = pClient.getPayments(startDate.getTime(), endDate.getTime(), PaymentStatus.SUCCESS, 0);
|
| 70 |
} else {
|
83 |
} else {
|
| 71 |
payments = pClient.getPayments(startDate.getTime(), endDate.getTime(), PaymentStatus.FAILED, 1);
|
84 |
payments = pClient.getPayments(startDate.getTime(), endDate.getTime(), PaymentStatus.FAILED, 0);
|
| 72 |
pendingPayments = pClient.getPayments(startDate.getTime(), endDate.getTime(), PaymentStatus.INIT, 1);
|
85 |
pendingPayments = pClient.getPayments(startDate.getTime(), endDate.getTime(), PaymentStatus.INIT, 0);
|
| 73 |
if (payments != null && pendingPayments != null) {
|
86 |
if (payments != null && pendingPayments != null) {
|
| 74 |
payments.addAll(pendingPayments);
|
87 |
payments.addAll(pendingPayments);
|
| 75 |
} else if (pendingPayments != null){
|
88 |
} else if (pendingPayments != null){
|
| 76 |
payments = pendingPayments;
|
89 |
payments = pendingPayments;
|
| 77 |
}
|
90 |
}
|
| Line 121... |
Line 134... |
| 121 |
|
134 |
|
| 122 |
paymentSheet.createRow(paymentSerialNo++);
|
135 |
paymentSheet.createRow(paymentSerialNo++);
|
| 123 |
|
136 |
|
| 124 |
Row headerRow = paymentSheet.createRow(paymentSerialNo++);
|
137 |
Row headerRow = paymentSheet.createRow(paymentSerialNo++);
|
| 125 |
headerRow.createCell(0).setCellValue("Payment Id");
|
138 |
headerRow.createCell(0).setCellValue("Payment Id");
|
| - |
|
139 |
headerRow.createCell(1).setCellValue("Gateway");
|
| 126 |
headerRow.createCell(1).setCellValue("Txn Id");
|
140 |
headerRow.createCell(2).setCellValue("Txn Id");
|
| 127 |
headerRow.createCell(2).setCellValue("Amount");
|
141 |
headerRow.createCell(3).setCellValue("Amount");
|
| 128 |
headerRow.createCell(3).setCellValue("Payment Status");
|
142 |
headerRow.createCell(4).setCellValue("Payment Status");
|
| 129 |
headerRow.createCell(4).setCellValue("Payment Status Description");
|
143 |
headerRow.createCell(5).setCellValue("Payment Status Description");
|
| 130 |
headerRow.createCell(5).setCellValue("Reference Code");
|
144 |
headerRow.createCell(6).setCellValue("Reference Code");
|
| 131 |
headerRow.createCell(6).setCellValue("Transaction Time");
|
145 |
headerRow.createCell(7).setCellValue("Transaction Time");
|
| 132 |
|
146 |
|
| 133 |
headerRow.createCell(7).setCellValue("Customer Id");
|
147 |
headerRow.createCell(8).setCellValue("Customer Id");
|
| 134 |
headerRow.createCell(8).setCellValue("Name");
|
148 |
headerRow.createCell(9).setCellValue("Name");
|
| 135 |
headerRow.createCell(9).setCellValue("MobileNo");
|
149 |
headerRow.createCell(10).setCellValue("MobileNo");
|
| 136 |
headerRow.createCell(10).setCellValue("Address");
|
150 |
headerRow.createCell(11).setCellValue("Address");
|
| 137 |
headerRow.getCell(10).setCellStyle(styleWT);
|
151 |
headerRow.getCell(11).setCellStyle(styleWT);
|
| 138 |
headerRow.createCell(11).setCellValue("Pincode");
|
152 |
headerRow.createCell(12).setCellValue("Pincode");
|
| 139 |
headerRow.createCell(12).setCellValue("City");
|
153 |
headerRow.createCell(13).setCellValue("City");
|
| 140 |
headerRow.createCell(13).setCellValue("State");
|
154 |
headerRow.createCell(14).setCellValue("State");
|
| 141 |
headerRow.createCell(14).setCellValue("Email");
|
155 |
headerRow.createCell(15).setCellValue("Email");
|
| 142 |
|
156 |
|
| 143 |
headerRow.createCell(15).setCellValue("Order Id");
|
157 |
headerRow.createCell(16).setCellValue("Order Id");
|
| 144 |
headerRow.createCell(16).setCellValue("Order Status");
|
158 |
headerRow.createCell(17).setCellValue("Order Status");
|
| 145 |
headerRow.createCell(17).setCellValue("Order Status Description");
|
159 |
headerRow.createCell(18).setCellValue("Order Status Description");
|
| 146 |
|
160 |
|
| 147 |
headerRow.createCell(18).setCellValue("Item Id");
|
161 |
headerRow.createCell(19).setCellValue("Item Id");
|
| 148 |
headerRow.createCell(19).setCellValue("Product Group");
|
162 |
headerRow.createCell(20).setCellValue("Product Group");
|
| 149 |
headerRow.createCell(20).setCellValue("Brand");
|
163 |
headerRow.createCell(21).setCellValue("Brand");
|
| 150 |
headerRow.createCell(21).setCellValue("Model Name");
|
164 |
headerRow.createCell(22).setCellValue("Model Name");
|
| 151 |
headerRow.createCell(22).setCellValue("Model Number");
|
165 |
headerRow.createCell(23).setCellValue("Model Number");
|
| 152 |
headerRow.createCell(23).setCellValue("Qty");
|
166 |
headerRow.createCell(24).setCellValue("Qty");
|
| 153 |
|
167 |
|
| 154 |
int addrColWidth = 35;
|
168 |
int addrColWidth = 35;
|
| 155 |
paymentSheet.setColumnWidth(10, 256 * addrColWidth); // set width of address column to 35 characters
|
169 |
paymentSheet.setColumnWidth(10, 256 * addrColWidth); // set width of address column to 35 characters
|
| 156 |
List<Order> orders;
|
170 |
List<Order> orders;
|
| 157 |
long txnId;
|
171 |
long txnId;
|
| Line 161... |
Line 175... |
| 161 |
for (Payment payment : payments) {
|
175 |
for (Payment payment : payments) {
|
| 162 |
try {
|
176 |
try {
|
| 163 |
paymentSerialNo++;
|
177 |
paymentSerialNo++;
|
| 164 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
178 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
| 165 |
contentRow.createCell(0).setCellValue(payment.getPaymentId());
|
179 |
contentRow.createCell(0).setCellValue(payment.getPaymentId());
|
| - |
|
180 |
|
| - |
|
181 |
/*PaymentGateway gateway = gateWays.get(payment.getGatewayId());
|
| - |
|
182 |
if(gateway == null) {
|
| - |
|
183 |
try {
|
| - |
|
184 |
gateway = pClient.getPaymentGateway(payment.getGatewayId());
|
| - |
|
185 |
gateWays.put(payment.getGatewayId(), gateway);
|
| - |
|
186 |
} catch (PaymentException e) {
|
| - |
|
187 |
e.printStackTrace();
|
| - |
|
188 |
}
|
| - |
|
189 |
}*/
|
| - |
|
190 |
contentRow.createCell(1).setCellValue(payment.getGatewayId());
|
| - |
|
191 |
|
| 166 |
contentRow.createCell(1).setCellValue(payment.getMerchantTxnId());
|
192 |
contentRow.createCell(2).setCellValue(payment.getMerchantTxnId());
|
| 167 |
contentRow.createCell(2).setCellValue(payment.getAmount());
|
193 |
contentRow.createCell(3).setCellValue(payment.getAmount());
|
| 168 |
contentRow.getCell(2).setCellStyle(styleAmount);
|
194 |
contentRow.getCell(3).setCellStyle(styleAmount);
|
| 169 |
contentRow.createCell(3).setCellValue(payment.getStatus().name());
|
195 |
contentRow.createCell(4).setCellValue(payment.getStatus().name());
|
| 170 |
contentRow.createCell(4).setCellValue(payment.getDescription());
|
196 |
contentRow.createCell(5).setCellValue(payment.getDescription());
|
| 171 |
contentRow.createCell(5).setCellValue(payment.getReferenceCode());
|
197 |
contentRow.createCell(6).setCellValue(payment.getReferenceCode());
|
| 172 |
calendar.setTimeInMillis(payment.getInitTimestamp());
|
198 |
calendar.setTimeInMillis(payment.getInitTimestamp());
|
| 173 |
contentRow.createCell(6).setCellValue(formatter.format(calendar.getTime()));
|
199 |
contentRow.createCell(7).setCellValue(formatter.format(calendar.getTime()));
|
| 174 |
|
200 |
|
| 175 |
txnId = tClient.getTransaction(payment.getMerchantTxnId()).getId();
|
201 |
txnId = tClient.getTransaction(payment.getMerchantTxnId()).getId();
|
| 176 |
orders = tClient.getOrdersForTransaction(txnId, payment.getUserId());
|
202 |
orders = tClient.getOrdersForTransaction(txnId, payment.getUserId());
|
| 177 |
List<LineItem> lineItems;
|
203 |
List<LineItem> lineItems;
|
| 178 |
|
204 |
|
| 179 |
String address = "";
|
205 |
String address = "";
|
| 180 |
float rowHeight = paymentSheet.getDefaultRowHeightInPoints();
|
206 |
float rowHeight = paymentSheet.getDefaultRowHeightInPoints();
|
| 181 |
if (orders == null || orders.isEmpty()) {
|
207 |
if (orders == null || orders.isEmpty()) {
|
| 182 |
continue;
|
208 |
continue;
|
| 183 |
}
|
209 |
}
|
| 184 |
contentRow.createCell(7).setCellValue(orders.get(0).getCustomer_id());
|
210 |
contentRow.createCell(8).setCellValue(orders.get(0).getCustomer_id());
|
| 185 |
contentRow.createCell(8).setCellValue(orders.get(0).getCustomer_name());
|
211 |
contentRow.createCell(9).setCellValue(orders.get(0).getCustomer_name());
|
| 186 |
contentRow.createCell(9).setCellValue(orders.get(0).getCustomer_mobilenumber());
|
212 |
contentRow.createCell(10).setCellValue(orders.get(0).getCustomer_mobilenumber());
|
| 187 |
address = orders.get(0).getCustomer_address1() + ", " + orders.get(0).getCustomer_address2();
|
213 |
address = orders.get(0).getCustomer_address1() + ", " + orders.get(0).getCustomer_address2();
|
| 188 |
contentRow.createCell(10).setCellValue(address);
|
214 |
contentRow.createCell(11).setCellValue(address);
|
| 189 |
contentRow.getCell(10).setCellStyle(styleWT);
|
215 |
contentRow.getCell(11).setCellStyle(styleWT);
|
| 190 |
int maxLength = Math.max(address.length(), paymentSheet.getDefaultColumnWidth());
|
216 |
int maxLength = Math.max(address.length(), paymentSheet.getDefaultColumnWidth());
|
| 191 |
contentRow.setHeightInPoints((maxLength / addrColWidth + 1) * rowHeight); // Setting Row Height
|
217 |
contentRow.setHeightInPoints((maxLength / addrColWidth + 1) * rowHeight); // Setting Row Height
|
| 192 |
contentRow.createCell(11).setCellValue(orders.get(0).getCustomer_pincode());
|
218 |
contentRow.createCell(12).setCellValue(orders.get(0).getCustomer_pincode());
|
| 193 |
contentRow.createCell(12).setCellValue(orders.get(0).getCustomer_city());
|
219 |
contentRow.createCell(13).setCellValue(orders.get(0).getCustomer_city());
|
| 194 |
contentRow.createCell(13).setCellValue(orders.get(0).getCustomer_state());
|
220 |
contentRow.createCell(14).setCellValue(orders.get(0).getCustomer_state());
|
| 195 |
contentRow.createCell(14).setCellValue(orders.get(0).getCustomer_email());
|
221 |
contentRow.createCell(15).setCellValue(orders.get(0).getCustomer_email());
|
| 196 |
|
222 |
|
| 197 |
for (Order o : orders) {
|
223 |
for (Order o : orders) {
|
| 198 |
paymentSerialNo++;
|
224 |
paymentSerialNo++;
|
| 199 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
225 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
| 200 |
|
226 |
|
| 201 |
contentRow.createCell(15).setCellValue(o.getId());
|
227 |
contentRow.createCell(16).setCellValue(o.getId());
|
| 202 |
contentRow.createCell(16).setCellValue(o.getStatus().name());
|
228 |
contentRow.createCell(17).setCellValue(o.getStatus().name());
|
| 203 |
contentRow.createCell(17).setCellValue(o.getStatusDescription());
|
229 |
contentRow.createCell(18).setCellValue(o.getStatusDescription());
|
| 204 |
|
230 |
|
| 205 |
lineItems = tClient.getLineItemsForOrder(o.getId());
|
231 |
lineItems = tClient.getLineItemsForOrder(o.getId());
|
| 206 |
for (LineItem i : lineItems) {
|
232 |
for (LineItem i : lineItems) {
|
| 207 |
/*
|
233 |
/*
|
| 208 |
* Right now there can be only one line item in an
|
234 |
* Right now there can be only one line item in an
|
| Line 212... |
Line 238... |
| 212 |
*/
|
238 |
*/
|
| 213 |
// paymentSerialNo++;
|
239 |
// paymentSerialNo++;
|
| 214 |
// contentRow =
|
240 |
// contentRow =
|
| 215 |
// paymentSheet.createRow(paymentSerialNo);
|
241 |
// paymentSheet.createRow(paymentSerialNo);
|
| 216 |
|
242 |
|
| 217 |
contentRow.createCell(18).setCellValue(i.getId());
|
243 |
contentRow.createCell(19).setCellValue(i.getId());
|
| 218 |
contentRow.createCell(19).setCellValue(i.getProductGroup());
|
244 |
contentRow.createCell(20).setCellValue(i.getProductGroup());
|
| 219 |
contentRow.createCell(20).setCellValue(i.getBrand());
|
245 |
contentRow.createCell(21).setCellValue(i.getBrand());
|
| 220 |
contentRow.createCell(21).setCellValue(i.getModel_name());
|
246 |
contentRow.createCell(22).setCellValue(i.getModel_name());
|
| 221 |
contentRow.createCell(22).setCellValue(i.getModel_number());
|
247 |
contentRow.createCell(23).setCellValue(i.getModel_number());
|
| 222 |
contentRow.createCell(23).setCellValue(i.getQuantity());
|
248 |
contentRow.createCell(24).setCellValue(i.getQuantity());
|
| 223 |
}
|
249 |
}
|
| 224 |
}
|
250 |
}
|
| 225 |
} catch (TransactionServiceException e) {
|
251 |
} catch (TransactionServiceException e) {
|
| 226 |
e.printStackTrace();
|
252 |
e.printStackTrace();
|
| 227 |
} catch (TException e) {
|
253 |
} catch (TException e) {
|
| 228 |
e.printStackTrace();
|
254 |
e.printStackTrace();
|
| 229 |
}
|
255 |
}
|
| 230 |
}
|
256 |
}
|
| 231 |
|
257 |
|
| 232 |
for (int i = 0; i <= 23; i++) {
|
258 |
for (int i = 0; i <= 24; i++) {
|
| 233 |
if (i == 10) // Address Column is of fixed size with wrap text style
|
259 |
if (i == 11) // Address Column is of fixed size with wrap text style
|
| 234 |
continue;
|
260 |
continue;
|
| 235 |
paymentSheet.autoSizeColumn(i);
|
261 |
paymentSheet.autoSizeColumn(i);
|
| 236 |
}
|
262 |
}
|
| 237 |
|
263 |
|
| 238 |
// Write the workbook to the output stream
|
264 |
// Write the workbook to the output stream
|