| Line 1... |
Line 1... |
| 1 |
package in.shop2020.support.services;
|
1 |
package in.shop2020.support.services;
|
| 2 |
|
2 |
|
| 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.Attribute;
|
| - |
|
7 |
import in.shop2020.payments.Constants;
|
| 6 |
import in.shop2020.payments.Payment;
|
8 |
import in.shop2020.payments.Payment;
|
| 7 |
import in.shop2020.payments.PaymentException;
|
9 |
import in.shop2020.payments.PaymentException;
|
| 8 |
import in.shop2020.payments.PaymentGateway;
|
10 |
import in.shop2020.payments.PaymentGateway;
|
| 9 |
import in.shop2020.payments.PaymentStatus;
|
11 |
import in.shop2020.payments.PaymentStatus;
|
| 10 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
12 |
import in.shop2020.thrift.clients.PaymentServiceClient;
|
| Line 132... |
Line 134... |
| 132 |
|
134 |
|
| 133 |
paymentSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
|
135 |
paymentSheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 6));
|
| 134 |
|
136 |
|
| 135 |
paymentSheet.createRow(paymentSerialNo++);
|
137 |
paymentSheet.createRow(paymentSerialNo++);
|
| 136 |
|
138 |
|
| - |
|
139 |
final int S_NO = 0, PAYMENT_ID = 1, GATEWAY = 2, PAYMENT_METHOD = 3, TXN_ID = 4, AMOUNT = 5, PAY_STATUS = 6,
|
| - |
|
140 |
PAY_STATUS_DESC = 7, TXN_STATUS = 8, REF_CODE = 9, TXN_TIME = 10, CUST_ID = 11, NAME = 12,
|
| - |
|
141 |
MOB_NO = 13, ADDR = 14, PINCODE = 15, CITY = 16, STATE = 17, EMAIL = 18, ORDER_ID = 19, ORDER_STATUS = 20,
|
| - |
|
142 |
ORDER_STATUS_DESC = 21, ITEM_ID = 22, PROD_GRP = 23, BRAND = 24, MOD_NAME = 25, MOD_NUM = 26, QTY = 27;
|
| - |
|
143 |
|
| 137 |
Row headerRow = paymentSheet.createRow(paymentSerialNo++);
|
144 |
Row headerRow = paymentSheet.createRow(paymentSerialNo++);
|
| - |
|
145 |
headerRow.createCell(S_NO).setCellValue("S.No");
|
| 138 |
headerRow.createCell(0).setCellValue("Payment Id");
|
146 |
headerRow.createCell(PAYMENT_ID).setCellValue("Payment Id");
|
| 139 |
headerRow.createCell(1).setCellValue("Gateway");
|
147 |
headerRow.createCell(GATEWAY).setCellValue("Gateway");
|
| - |
|
148 |
headerRow.createCell(PAYMENT_METHOD).setCellValue("Payment Method");
|
| - |
|
149 |
headerRow.getCell(PAYMENT_METHOD).setCellStyle(styleWT);
|
| - |
|
150 |
|
| 140 |
headerRow.createCell(2).setCellValue("Txn Id");
|
151 |
headerRow.createCell(TXN_ID).setCellValue("Txn Id");
|
| 141 |
headerRow.createCell(3).setCellValue("Amount");
|
152 |
headerRow.createCell(AMOUNT).setCellValue("Amount");
|
| 142 |
headerRow.createCell(4).setCellValue("Payment Status");
|
153 |
headerRow.createCell(PAY_STATUS).setCellValue("Payment Status");
|
| 143 |
headerRow.createCell(5).setCellValue("Payment Status Description");
|
154 |
headerRow.createCell(PAY_STATUS_DESC).setCellValue("Payment Status Description");
|
| - |
|
155 |
headerRow.getCell(PAY_STATUS_DESC).setCellStyle(styleWT);
|
| 144 |
headerRow.createCell(6).setCellValue("Gateway Txn Status");
|
156 |
headerRow.createCell(TXN_STATUS).setCellValue("Gateway Txn Status");
|
| 145 |
headerRow.createCell(7).setCellValue("Reference Code");
|
157 |
headerRow.createCell(REF_CODE).setCellValue("Reference Code");
|
| 146 |
headerRow.createCell(8).setCellValue("Transaction Time");
|
158 |
headerRow.createCell(TXN_TIME).setCellValue("Transaction Time");
|
| 147 |
|
159 |
|
| 148 |
headerRow.createCell(9).setCellValue("Customer Id");
|
160 |
headerRow.createCell(CUST_ID).setCellValue("Customer Id");
|
| 149 |
headerRow.createCell(10).setCellValue("Name");
|
161 |
headerRow.createCell(NAME).setCellValue("Name");
|
| 150 |
headerRow.createCell(11).setCellValue("MobileNo");
|
162 |
headerRow.createCell(MOB_NO).setCellValue("MobileNo");
|
| 151 |
headerRow.createCell(12).setCellValue("Address");
|
163 |
headerRow.createCell(ADDR).setCellValue("Address");
|
| 152 |
headerRow.getCell(12).setCellStyle(styleWT);
|
164 |
headerRow.getCell(ADDR).setCellStyle(styleWT);
|
| 153 |
headerRow.createCell(13).setCellValue("Pincode");
|
165 |
headerRow.createCell(PINCODE).setCellValue("Pincode");
|
| 154 |
headerRow.createCell(14).setCellValue("City");
|
166 |
headerRow.createCell(CITY).setCellValue("City");
|
| 155 |
headerRow.createCell(15).setCellValue("State");
|
167 |
headerRow.createCell(STATE).setCellValue("State");
|
| 156 |
headerRow.createCell(16).setCellValue("Email");
|
168 |
headerRow.createCell(EMAIL).setCellValue("Login Email");
|
| 157 |
|
169 |
|
| 158 |
headerRow.createCell(17).setCellValue("Order Id");
|
170 |
headerRow.createCell(ORDER_ID).setCellValue("Order Id");
|
| 159 |
headerRow.createCell(18).setCellValue("Order Status");
|
171 |
headerRow.createCell(ORDER_STATUS).setCellValue("Order Status");
|
| 160 |
headerRow.createCell(19).setCellValue("Order Status Description");
|
172 |
headerRow.createCell(ORDER_STATUS_DESC).setCellValue("Order Status Description");
|
| 161 |
|
173 |
|
| 162 |
headerRow.createCell(20).setCellValue("Item Id");
|
174 |
headerRow.createCell(ITEM_ID).setCellValue("Item Id");
|
| 163 |
headerRow.createCell(21).setCellValue("Product Group");
|
175 |
headerRow.createCell(PROD_GRP).setCellValue("Product Group");
|
| 164 |
headerRow.createCell(22).setCellValue("Brand");
|
176 |
headerRow.createCell(BRAND).setCellValue("Brand");
|
| 165 |
headerRow.createCell(23).setCellValue("Model Name");
|
177 |
headerRow.createCell(MOD_NAME).setCellValue("Model Name");
|
| 166 |
headerRow.createCell(24).setCellValue("Model Number");
|
178 |
headerRow.createCell(MOD_NUM).setCellValue("Model Number");
|
| 167 |
headerRow.createCell(25).setCellValue("Qty");
|
179 |
headerRow.createCell(QTY).setCellValue("Qty");
|
| 168 |
|
180 |
|
| 169 |
int addrColWidth = 35;
|
181 |
int paymethodColWidth = 25, statusDescWidth = 25, addrColWidth = 35;
|
| - |
|
182 |
paymentSheet.setColumnWidth(PAYMENT_METHOD, 256 * paymethodColWidth); // set width of payment method column
|
| - |
|
183 |
paymentSheet.setColumnWidth(PAY_STATUS_DESC, 256 * statusDescWidth); // set width of payment status description column
|
| 170 |
paymentSheet.setColumnWidth(12, 256 * addrColWidth); // set width of address column to 35 characters
|
184 |
paymentSheet.setColumnWidth(ADDR, 256 * addrColWidth); // set width of address column
|
| 171 |
List<Order> orders;
|
185 |
List<Order> orders;
|
| 172 |
long txnId;
|
186 |
long txnId;
|
| 173 |
Row contentRow;
|
187 |
Row contentRow;
|
| 174 |
Calendar calendar = Calendar.getInstance();
|
188 |
Calendar calendar = Calendar.getInstance();
|
| 175 |
DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
189 |
DateFormat formatter = new SimpleDateFormat("EEE, dd-MMM-yyyy hh:mm a");
|
| - |
|
190 |
float rowHeight = paymentSheet.getDefaultRowHeightInPoints();
|
| - |
|
191 |
int sNo = 0;
|
| 176 |
for (Payment payment : payments) {
|
192 |
for (Payment payment : payments) {
|
| - |
|
193 |
float newRowHeight = paymentSheet.getDefaultRowHeightInPoints();;
|
| 177 |
try {
|
194 |
try {
|
| 178 |
paymentSerialNo++;
|
195 |
paymentSerialNo++;
|
| 179 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
196 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
| - |
|
197 |
sNo++;
|
| - |
|
198 |
contentRow.createCell(S_NO).setCellValue(sNo);
|
| 180 |
contentRow.createCell(0).setCellValue(payment.getPaymentId());
|
199 |
contentRow.createCell(PAYMENT_ID).setCellValue(payment.getPaymentId());
|
| 181 |
|
200 |
|
| 182 |
/*PaymentGateway gateway = gateWays.get(payment.getGatewayId());
|
201 |
PaymentGateway gateway = gateWays.get(payment.getGatewayId());
|
| 183 |
if(gateway == null) {
|
202 |
if(gateway == null) {
|
| 184 |
try {
|
203 |
try {
|
| 185 |
gateway = pClient.getPaymentGateway(payment.getGatewayId());
|
204 |
gateway = pClient.getPaymentGateway(payment.getGatewayId());
|
| 186 |
gateWays.put(payment.getGatewayId(), gateway);
|
205 |
gateWays.put(payment.getGatewayId(), gateway);
|
| 187 |
} catch (PaymentException e) {
|
206 |
} catch (PaymentException e) {
|
| 188 |
e.printStackTrace();
|
207 |
e.printStackTrace();
|
| 189 |
}
|
208 |
}
|
| 190 |
}
|
209 |
}
|
| 191 |
contentRow.createCell(1).setCellValue(gateway != null ? gateway.getName() : payment.getGatewayId()+"");*/
|
210 |
contentRow.createCell(GATEWAY).setCellValue(gateway != null ? gateway.getName() : payment.getGatewayId()+"");
|
| 192 |
contentRow.createCell(1).setCellValue(payment.getGatewayId());
|
211 |
//contentRow.createCell(GATEWAY).setCellValue(payment.getGatewayId());
|
| 193 |
|
212 |
|
| - |
|
213 |
String paymentMethod = getPaymentMethod(payment.getAttributes());
|
| - |
|
214 |
contentRow.createCell(PAYMENT_METHOD).setCellValue(paymentMethod);
|
| - |
|
215 |
contentRow.getCell(PAYMENT_METHOD).setCellStyle(styleWT);
|
| - |
|
216 |
|
| - |
|
217 |
if(paymentMethod.length() > paymethodColWidth) {
|
| - |
|
218 |
newRowHeight = Math.max(newRowHeight, (paymentMethod.length() / paymethodColWidth + 1) * rowHeight);
|
| - |
|
219 |
}
|
| - |
|
220 |
|
| 194 |
contentRow.createCell(2).setCellValue(payment.getMerchantTxnId());
|
221 |
contentRow.createCell(TXN_ID).setCellValue(payment.getMerchantTxnId());
|
| 195 |
contentRow.createCell(3).setCellValue(payment.getAmount());
|
222 |
contentRow.createCell(AMOUNT).setCellValue(payment.getAmount());
|
| 196 |
contentRow.getCell(3).setCellStyle(styleAmount);
|
223 |
contentRow.getCell(AMOUNT).setCellStyle(styleAmount);
|
| 197 |
contentRow.createCell(4).setCellValue(payment.getStatus().name());
|
224 |
contentRow.createCell(PAY_STATUS).setCellValue(payment.getStatus().name());
|
| - |
|
225 |
String desc = payment.getDescription();
|
| 198 |
contentRow.createCell(5).setCellValue(payment.getDescription());
|
226 |
contentRow.createCell(PAY_STATUS_DESC).setCellValue(desc);
|
| - |
|
227 |
contentRow.getCell(PAY_STATUS_DESC).setCellStyle(styleWT);
|
| - |
|
228 |
if(desc != null && desc.length() > statusDescWidth) {
|
| - |
|
229 |
newRowHeight = Math.max(newRowHeight, (desc.length() / statusDescWidth + 1) * rowHeight);
|
| - |
|
230 |
}
|
| - |
|
231 |
|
| 199 |
contentRow.createCell(6).setCellValue(payment.getGatewayTxnStatus());
|
232 |
contentRow.createCell(TXN_STATUS).setCellValue(payment.getGatewayTxnStatus());
|
| 200 |
contentRow.createCell(7).setCellValue(payment.getReferenceCode());
|
233 |
contentRow.createCell(REF_CODE).setCellValue(payment.getReferenceCode());
|
| 201 |
calendar.setTimeInMillis(payment.getInitTimestamp());
|
234 |
calendar.setTimeInMillis(payment.getInitTimestamp());
|
| 202 |
contentRow.createCell(8).setCellValue(formatter.format(calendar.getTime()));
|
235 |
contentRow.createCell(TXN_TIME).setCellValue(formatter.format(calendar.getTime()));
|
| 203 |
|
236 |
|
| 204 |
txnId = tClient.getTransaction(payment.getMerchantTxnId()).getId();
|
237 |
txnId = tClient.getTransaction(payment.getMerchantTxnId()).getId();
|
| 205 |
orders = tClient.getOrdersForTransaction(txnId, payment.getUserId());
|
238 |
orders = tClient.getOrdersForTransaction(txnId, payment.getUserId());
|
| 206 |
List<LineItem> lineItems;
|
239 |
List<LineItem> lineItems;
|
| 207 |
|
240 |
|
| 208 |
String address = "";
|
241 |
String address = "";
|
| 209 |
float rowHeight = paymentSheet.getDefaultRowHeightInPoints();
|
242 |
|
| 210 |
if (orders == null || orders.isEmpty()) {
|
243 |
if (orders == null || orders.isEmpty()) {
|
| 211 |
continue;
|
244 |
continue;
|
| 212 |
}
|
245 |
}
|
| 213 |
contentRow.createCell(9).setCellValue(orders.get(0).getCustomer_id());
|
246 |
contentRow.createCell(CUST_ID).setCellValue(orders.get(0).getCustomer_id());
|
| 214 |
contentRow.createCell(10).setCellValue(orders.get(0).getCustomer_name());
|
247 |
contentRow.createCell(NAME).setCellValue(orders.get(0).getCustomer_name());
|
| 215 |
contentRow.createCell(11).setCellValue(orders.get(0).getCustomer_mobilenumber());
|
248 |
contentRow.createCell(MOB_NO).setCellValue(orders.get(0).getCustomer_mobilenumber());
|
| 216 |
address = orders.get(0).getCustomer_address1() + ", " + orders.get(0).getCustomer_address2();
|
249 |
address = orders.get(0).getCustomer_address1() + ", " + orders.get(0).getCustomer_address2();
|
| 217 |
contentRow.createCell(12).setCellValue(address);
|
250 |
contentRow.createCell(ADDR).setCellValue(address);
|
| 218 |
contentRow.getCell(12).setCellStyle(styleWT);
|
251 |
contentRow.getCell(ADDR).setCellStyle(styleWT);
|
| - |
|
252 |
|
| - |
|
253 |
if(address.length() > addrColWidth) {
|
| 219 |
int maxLength = Math.max(address.length(), paymentSheet.getDefaultColumnWidth());
|
254 |
newRowHeight = Math.max(newRowHeight, (address.length() / addrColWidth + 1) * rowHeight);
|
| - |
|
255 |
}
|
| 220 |
contentRow.setHeightInPoints((maxLength / addrColWidth + 1) * rowHeight); // Setting Row Height
|
256 |
contentRow.setHeightInPoints(newRowHeight);
|
| - |
|
257 |
|
| 221 |
contentRow.createCell(13).setCellValue(orders.get(0).getCustomer_pincode());
|
258 |
contentRow.createCell(PINCODE).setCellValue(orders.get(0).getCustomer_pincode());
|
| 222 |
contentRow.createCell(14).setCellValue(orders.get(0).getCustomer_city());
|
259 |
contentRow.createCell(CITY).setCellValue(orders.get(0).getCustomer_city());
|
| 223 |
contentRow.createCell(15).setCellValue(orders.get(0).getCustomer_state());
|
260 |
contentRow.createCell(STATE).setCellValue(orders.get(0).getCustomer_state());
|
| 224 |
contentRow.createCell(16).setCellValue(orders.get(0).getCustomer_email());
|
261 |
contentRow.createCell(EMAIL).setCellValue(orders.get(0).getCustomer_email());
|
| 225 |
|
262 |
|
| - |
|
263 |
boolean firstOrder = true;
|
| 226 |
for (Order o : orders) {
|
264 |
for (Order o : orders) {
|
| - |
|
265 |
if(firstOrder) {
|
| - |
|
266 |
firstOrder = false;
|
| - |
|
267 |
} else {
|
| 227 |
paymentSerialNo++;
|
268 |
paymentSerialNo++;
|
| 228 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
269 |
contentRow = paymentSheet.createRow(paymentSerialNo);
|
| - |
|
270 |
}
|
| 229 |
|
271 |
|
| 230 |
contentRow.createCell(17).setCellValue(o.getId());
|
272 |
contentRow.createCell(ORDER_ID).setCellValue(o.getId());
|
| 231 |
contentRow.createCell(18).setCellValue(o.getStatus().name());
|
273 |
contentRow.createCell(ORDER_STATUS).setCellValue(o.getStatus().name());
|
| 232 |
contentRow.createCell(19).setCellValue(o.getStatusDescription());
|
274 |
contentRow.createCell(ORDER_STATUS_DESC).setCellValue(o.getStatusDescription());
|
| 233 |
|
275 |
|
| 234 |
lineItems = tClient.getLineItemsForOrder(o.getId());
|
276 |
lineItems = tClient.getLineItemsForOrder(o.getId());
|
| 235 |
for (LineItem i : lineItems) {
|
277 |
for (LineItem i : lineItems) {
|
| 236 |
/*
|
278 |
/*
|
| 237 |
* Right now there can be only one line item in an
|
279 |
* Right now there can be only one line item in an
|
| Line 241... |
Line 283... |
| 241 |
*/
|
283 |
*/
|
| 242 |
// paymentSerialNo++;
|
284 |
// paymentSerialNo++;
|
| 243 |
// contentRow =
|
285 |
// contentRow =
|
| 244 |
// paymentSheet.createRow(paymentSerialNo);
|
286 |
// paymentSheet.createRow(paymentSerialNo);
|
| 245 |
|
287 |
|
| 246 |
contentRow.createCell(20).setCellValue(i.getId());
|
288 |
contentRow.createCell(ITEM_ID).setCellValue(i.getId());
|
| 247 |
contentRow.createCell(21).setCellValue(i.getProductGroup());
|
289 |
contentRow.createCell(PROD_GRP).setCellValue(i.getProductGroup());
|
| 248 |
contentRow.createCell(22).setCellValue(i.getBrand());
|
290 |
contentRow.createCell(BRAND).setCellValue(i.getBrand());
|
| 249 |
contentRow.createCell(23).setCellValue(i.getModel_name());
|
291 |
contentRow.createCell(MOD_NAME).setCellValue(i.getModel_name());
|
| 250 |
contentRow.createCell(24).setCellValue(i.getModel_number());
|
292 |
contentRow.createCell(MOD_NUM).setCellValue(i.getModel_number());
|
| 251 |
contentRow.createCell(25).setCellValue(i.getQuantity());
|
293 |
contentRow.createCell(QTY).setCellValue(i.getQuantity());
|
| 252 |
}
|
294 |
}
|
| 253 |
}
|
295 |
}
|
| 254 |
} catch (TransactionServiceException e) {
|
296 |
} catch (TransactionServiceException e) {
|
| 255 |
e.printStackTrace();
|
297 |
e.printStackTrace();
|
| 256 |
} catch (TException e) {
|
298 |
} catch (TException e) {
|
| 257 |
e.printStackTrace();
|
299 |
e.printStackTrace();
|
| 258 |
}
|
300 |
}
|
| 259 |
}
|
301 |
}
|
| 260 |
|
302 |
|
| 261 |
for (int i = 0; i <= 25; i++) {
|
303 |
for (int i = 0; i <= QTY; i++) {
|
| 262 |
if (i == 12) // Address Column is of fixed size with wrap text style
|
304 |
if (i == PAYMENT_METHOD || i == PAY_STATUS_DESC || i == ADDR) // Address Column is of fixed size with wrap text style
|
| 263 |
continue;
|
305 |
continue;
|
| 264 |
paymentSheet.autoSizeColumn(i);
|
306 |
paymentSheet.autoSizeColumn(i);
|
| 265 |
}
|
307 |
}
|
| 266 |
|
308 |
|
| 267 |
// Write the workbook to the output stream
|
309 |
// Write the workbook to the output stream
|
| Line 271... |
Line 313... |
| 271 |
} catch (IOException e) {
|
313 |
} catch (IOException e) {
|
| 272 |
e.printStackTrace();
|
314 |
e.printStackTrace();
|
| 273 |
}
|
315 |
}
|
| 274 |
return baosXLS;
|
316 |
return baosXLS;
|
| 275 |
}
|
317 |
}
|
| 276 |
|
318 |
|
| - |
|
319 |
public String getPaymentMethod(List<Attribute> paymentAttributes) {
|
| - |
|
320 |
String paymentMethod = null;
|
| - |
|
321 |
if(paymentAttributes == null || paymentAttributes.isEmpty()) {
|
| - |
|
322 |
return "N/A";
|
| - |
|
323 |
}
|
| - |
|
324 |
for(Attribute a : paymentAttributes) {
|
| - |
|
325 |
if("payMethod".equals(a.getName())) {
|
| - |
|
326 |
paymentMethod = Constants.PAYMENT_METHOD.get(a.getValue());
|
| - |
|
327 |
break;
|
| - |
|
328 |
}
|
| - |
|
329 |
}
|
| - |
|
330 |
return paymentMethod != null ? paymentMethod : "N/A";
|
| - |
|
331 |
}
|
| - |
|
332 |
|
| 277 |
public static void main(String[] args) {
|
333 |
public static void main(String[] args) {
|
| 278 |
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
|
334 |
DateFormat df = new SimpleDateFormat("MM/dd/yyyy");
|
| 279 |
Date startDate = null, endDate = null;
|
335 |
Date startDate = null, endDate = null;
|
| 280 |
try {
|
336 |
try {
|
| 281 |
startDate = df.parse("01/01/2011");
|
337 |
startDate = df.parse("01/01/2011");
|