Subversion Repositories SmartDukaan

Rev

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

Rev 2785 Rev 3105
Line 35... Line 35...
35
import org.apache.poi.ss.usermodel.Row;
35
import org.apache.poi.ss.usermodel.Row;
36
import org.apache.poi.ss.usermodel.Sheet;
36
import org.apache.poi.ss.usermodel.Sheet;
37
import org.apache.poi.ss.usermodel.Workbook;
37
import org.apache.poi.ss.usermodel.Workbook;
38
import org.apache.poi.ss.util.CellRangeAddress;
38
import org.apache.poi.ss.util.CellRangeAddress;
39
import org.apache.thrift.TException;
39
import org.apache.thrift.TException;
-
 
40
import org.slf4j.Logger;
-
 
41
import org.slf4j.LoggerFactory;
40
 
42
 
41
public class PaymentDetailsGenerator {
43
public class PaymentDetailsGenerator {
-
 
44
    
-
 
45
    private static Logger logger = LoggerFactory.getLogger(PaymentDetailsGenerator.class);
-
 
46
    
42
    TransactionServiceClient tsc;
47
    TransactionServiceClient tsc;
43
    in.shop2020.model.v1.order.TransactionService.Client tClient;
48
    in.shop2020.model.v1.order.TransactionService.Client tClient;
44
 
49
 
45
    PaymentServiceClient psc;
50
    PaymentServiceClient psc;
46
    in.shop2020.payments.PaymentService.Client pClient;
51
    in.shop2020.payments.PaymentService.Client pClient;
Line 59... Line 64...
59
            pClient = psc.getClient();
64
            pClient = psc.getClient();
60
 
65
 
61
            usc = new UserContextServiceClient();
66
            usc = new UserContextServiceClient();
62
            uClient = usc.getClient();
67
            uClient = usc.getClient();
63
        } catch (Exception e) {
68
        } catch (Exception e) {
64
            e.printStackTrace();
69
            logger.error("Error establishing connection to one of txn, payment or user service", e);
65
        }
70
        }
66
    }
71
    }
67
 
72
 
68
    /**
73
    /**
69
     * This method is used in PaymentDetailsController.
74
     * This method is used in PaymentDetailsController.
Line 91... Line 96...
91
                } else if (pendingPayments != null){
96
                } else if (pendingPayments != null){
92
                    payments = pendingPayments;
97
                    payments = pendingPayments;
93
                }
98
                }
94
            }
99
            }
95
        } catch (PaymentException e) {
100
        } catch (PaymentException e) {
96
            e.printStackTrace();
101
            logger.error("Error in payment service while getting payments", e);
97
        } catch (TException e) {
102
        } catch (TException e) {
98
            e.printStackTrace();
103
            logger.error("Error getting info from payment service", e);
99
        }
104
        }
100
        if (payments == null || payments.isEmpty()) {
105
        if (payments == null || payments.isEmpty()) {
101
            return null;
106
            return null;
102
        }
107
        }
103
 
108
 
Line 203... Line 208...
203
                if(gateway == null) {
208
                if(gateway == null) {
204
                    try {
209
                    try {
205
                        gateway = pClient.getPaymentGateway(payment.getGatewayId());
210
                        gateway = pClient.getPaymentGateway(payment.getGatewayId());
206
                        gateWays.put(payment.getGatewayId(), gateway);
211
                        gateWays.put(payment.getGatewayId(), gateway);
207
                    } catch (Exception e) {
212
                    } catch (Exception e) {
208
                        e.printStackTrace();
213
                        logger.error("Error gerring payment gateway info from payment service", e);
209
                    }
214
                    }
210
                }
215
                }
211
                contentRow.createCell(GATEWAY).setCellValue(gateway != null ? gateway.getName() : payment.getGatewayId()+"");
216
                contentRow.createCell(GATEWAY).setCellValue(gateway != null ? gateway.getName() : payment.getGatewayId()+"");
212
                //contentRow.createCell(GATEWAY).setCellValue(payment.getGatewayId());
217
                //contentRow.createCell(GATEWAY).setCellValue(payment.getGatewayId());
213
                
218
                
Line 296... Line 301...
296
                        contentRow.createCell(MOD_NUM).setCellValue(i.getModel_number());
301
                        contentRow.createCell(MOD_NUM).setCellValue(i.getModel_number());
297
                        contentRow.createCell(QTY).setCellValue(i.getQuantity());
302
                        contentRow.createCell(QTY).setCellValue(i.getQuantity());
298
                    }
303
                    }
299
                }
304
                }
300
            } catch (TransactionServiceException e) {
305
            } catch (TransactionServiceException e) {
301
                e.printStackTrace();
306
                logger.error("Error in transaction service while getting orders", e);
302
            } catch (TException e) {
307
            } catch (TException e) {
303
                e.printStackTrace();
308
                logger.error("Error getting info from transaction service", e);
304
            }
309
            }
305
        }
310
        }
306
 
311
 
307
        for (int i = 0; i <= QTY; i++) {
312
        for (int i = 0; i <= QTY; i++) {
308
            if (i == PAYMENT_METHOD || i == PAY_STATUS_DESC || i == ADDR) // Address Column is of fixed size with wrap text style
313
            if (i == PAYMENT_METHOD || i == PAY_STATUS_DESC || i == ADDR) // Address Column is of fixed size with wrap text style
Line 313... Line 318...
313
        // Write the workbook to the output stream
318
        // Write the workbook to the output stream
314
        try {
319
        try {
315
            wb.write(baosXLS);
320
            wb.write(baosXLS);
316
            baosXLS.close();
321
            baosXLS.close();
317
        } catch (IOException e) {
322
        } catch (IOException e) {
318
            e.printStackTrace();
323
            logger.error("Error while streaming payment details report", e);
319
        }
324
        }
320
        return baosXLS;
325
        return baosXLS;
321
    }
326
    }
322
    
327
    
323
    public String getPaymentMethod(List<Attribute> paymentAttributes) {
328
    public String getPaymentMethod(List<Attribute> paymentAttributes) {
Line 343... Line 348...
343
            Calendar cal = Calendar.getInstance();
348
            Calendar cal = Calendar.getInstance();
344
            cal.setTime(endDate);
349
            cal.setTime(endDate);
345
            cal.add(Calendar.DATE, 1);
350
            cal.add(Calendar.DATE, 1);
346
            endDate.setTime(cal.getTimeInMillis());
351
            endDate.setTime(cal.getTimeInMillis());
347
        } catch (ParseException pe) {
352
        } catch (ParseException pe) {
348
            pe.printStackTrace();
353
            logger.error("Error parsing the supplied date", pe);
349
        }
354
        }
350
        PaymentDetailsGenerator pdg = new PaymentDetailsGenerator();
355
        PaymentDetailsGenerator pdg = new PaymentDetailsGenerator();
351
        try {
356
        try {
352
            String userHome = System.getProperty("user.home");
357
            String userHome = System.getProperty("user.home");
353
            FileOutputStream f = new FileOutputStream(userHome + "/payment-details-report.xls");
358
            FileOutputStream f = new FileOutputStream(userHome + "/payment-details-report.xls");
354
            ByteArrayOutputStream baosXLS = pdg.generatePaymentDetailsReport(startDate, endDate, 1);
359
            ByteArrayOutputStream baosXLS = pdg.generatePaymentDetailsReport(startDate, endDate, 1);
355
            baosXLS.writeTo(f);
360
            baosXLS.writeTo(f);
356
            f.close();
361
            f.close();
357
        } catch (FileNotFoundException e) {
362
        } catch (FileNotFoundException e) {
358
            e.printStackTrace();
363
            logger.error("Error creating payment details report", e);
359
        } catch (IOException e) {
364
        } catch (IOException e) {
360
            e.printStackTrace();
365
            logger.error("IO error while creating payment details report", e);
361
        }
366
        }
362
        System.out.println("Successfully generated the payment details report");
367
        System.out.println("Successfully generated the payment details report");
363
    }
368
    }
364
}
369
}