Subversion Repositories SmartDukaan

Rev

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

Rev 3427 Rev 3449
Line 39... Line 39...
39
        } catch (TTransportException e) {
39
        } catch (TTransportException e) {
40
            logger.error("Error establishing connection to one of txn, payment or user service", e);
40
            logger.error("Error establishing connection to one of txn, payment or user service", e);
41
        }
41
        }
42
    }
42
    }
43
    
43
    
44
    public ByteArrayOutputStream generateCourierReconciliationReport(Date startDate, Date endDate, int providerId){
44
    public ByteArrayOutputStream generateCourierReconciliationReport(Date startDate, Date endDate, int providerId, boolean cod){
45
        ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
45
        ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
46
        in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
46
        in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
47
        
47
        
48
        List<Order> orders = null;
48
        List<Order> orders = null;
49
        try {
49
        try {
50
            orders = txnClient.getOrdersByShippingDate(startDate.getTime(), endDate.getTime(), providerId, -1);
50
            orders = txnClient.getOrdersByShippingDate(startDate.getTime(), endDate.getTime(), providerId, -1, cod);
51
        } catch (TException e) {
51
        } catch (TException e) {
52
            logger.error("Error getting information from one of the Thrift Services: ", e);
52
            logger.error("Error getting information from one of the Thrift Services: ", e);
53
            return baosXLS;
53
            return baosXLS;
54
        } catch (TransactionServiceException e) {
54
        } catch (TransactionServiceException e) {
55
            logger.error("Error getting orders from the transaction service: ", e);
55
            logger.error("Error getting orders from the transaction service: ", e);
Line 63... Line 63...
63
        dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yyyy"));
63
        dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yyyy"));
64
        
64
        
65
        CellStyle weightStyle = wb.createCellStyle();
65
        CellStyle weightStyle = wb.createCellStyle();
66
        weightStyle.setDataFormat(createHelper.createDataFormat().getFormat("0.000"));
66
        weightStyle.setDataFormat(createHelper.createDataFormat().getFormat("0.000"));
67
        
67
        
-
 
68
        createOutscannedOrdersSheet(orders, wb, dateCellStyle, weightStyle);
-
 
69
        createReturnedOrdersSheet(orders, wb, dateCellStyle, weightStyle);
-
 
70
        
-
 
71
        // Write the workbook to the output stream
-
 
72
        try {
-
 
73
            wb.write(baosXLS);
-
 
74
            baosXLS.close();
-
 
75
        } catch (IOException e) {
-
 
76
            logger.error("Exception while creating the Courier Details report", e);
-
 
77
        }
-
 
78
        
-
 
79
        return baosXLS;
-
 
80
    }
-
 
81
 
-
 
82
    /**
-
 
83
     * Creates a sheet named Outscanned Orders in the given workbook.
-
 
84
     * 
-
 
85
     * @param orders
-
 
86
     *            Outscanned orders to insert in the sheet.
-
 
87
     * @param wb
-
 
88
     *            Workbook to create the sheet in.
-
 
89
     * @param dateCellStyle
-
 
90
     *            Formatter for any date cells.
-
 
91
     * @param weightStyle
-
 
92
     *            Formatter for weight cells.
-
 
93
     */
-
 
94
    private void createOutscannedOrdersSheet(List<Order> orders, Workbook wb, CellStyle dateCellStyle, CellStyle weightStyle) {
68
        Sheet sheet = wb.createSheet("new sheet");
95
        Sheet sheet = wb.createSheet("Outscanned Orders");
69
        
96
        
70
        // Create the header row and put all the titles in it. Rows are 0 based.
97
        // Create the header row and put all the titles in it. Rows are 0 based.
71
        Row headerRow = sheet.createRow((short)0);
98
        Row headerRow = sheet.createRow((short)0);
72
        headerRow.createCell(0).setCellValue("AWB No");
99
        headerRow.createCell(0).setCellValue("AWB No");
73
        headerRow.createCell(1).setCellValue("Order Id");
100
        headerRow.createCell(1).setCellValue("Order Id");
Line 92... Line 119...
92
            weightCell.setCellValue(order.getTotal_weight());
119
            weightCell.setCellValue(order.getTotal_weight());
93
            weightCell.setCellStyle(weightStyle);
120
            weightCell.setCellStyle(weightStyle);
94
            
121
            
95
            contentRow.createCell(5).setCellValue(order.getTotal_amount());
122
            contentRow.createCell(5).setCellValue(order.getTotal_amount());
96
        }
123
        }
-
 
124
    }
-
 
125
 
-
 
126
    /**
-
 
127
     * Creates a sheet named Returned Orders in the given workbook.
-
 
128
     * 
-
 
129
     * @param orders
-
 
130
     *            Returned orders to insert in the sheet.
-
 
131
     * @param wb
-
 
132
     *            Workbook to create the sheet in.
-
 
133
     * @param dateCellStyle
-
 
134
     *            Formatter for any date cells.
-
 
135
     * @param weightStyle
-
 
136
     *            Formatter for weight cells.
-
 
137
     */
-
 
138
    private void createReturnedOrdersSheet(List<Order> orders, Workbook wb, CellStyle dateCellStyle, CellStyle weightStyle) {
-
 
139
        Sheet sheet = wb.createSheet("Returned Orders");
97
        
140
        
98
        // Write the workbook to the output stream
141
        // Create the header row and put all the titles in it. Rows are 0 based.
99
        try {
142
        Row headerRow = sheet.createRow((short)0);
-
 
143
        headerRow.createCell(0).setCellValue("Reference No");
100
            wb.write(baosXLS);
144
        headerRow.createCell(1).setCellValue("Order Id");
101
            baosXLS.close();
145
        headerRow.createCell(2).setCellValue("Return Date");
102
        } catch (IOException e) {
146
        headerRow.createCell(3).setCellValue("City");
103
            logger.error("Exception while creating the Courier Details report", e);
147
        headerRow.createCell(4).setCellValue("Packet Weight(in Kg)");
104
        }
148
        headerRow.createCell(5).setCellValue("Order Amount");
105
        
149
        
106
        return baosXLS;
150
        int serialNo = 0;
-
 
151
        for(Order order : orders){
-
 
152
            serialNo++;
-
 
153
            Row contentRow = sheet.createRow((short)serialNo);
-
 
154
            contentRow.createCell(0).setCellValue(order.getAirwaybill_no());
-
 
155
            contentRow.createCell(1).setCellValue(order.getId());
-
 
156
            Cell awbDateCell = contentRow.createCell(2);
-
 
157
            awbDateCell.setCellValue(new Date(order.getShipping_timestamp()));
-
 
158
            awbDateCell.setCellStyle(dateCellStyle);
-
 
159
            
-
 
160
            contentRow.createCell(3).setCellValue(getValueForEmptyString(order.getCustomer_city()));
-
 
161
            
-
 
162
            Cell weightCell = contentRow.createCell(4);
-
 
163
            weightCell.setCellValue(order.getTotal_weight());
-
 
164
            weightCell.setCellStyle(weightStyle);
-
 
165
            
-
 
166
            contentRow.createCell(5).setCellValue(order.getTotal_amount());
-
 
167
        }
107
    }
168
    }
108
    
169
    
109
    private String getValueForEmptyString(String s){
170
    private String getValueForEmptyString(String s){
110
        if(s==null || s.equals(""))
171
        if(s==null || s.equals(""))
111
            return "-";
172
            return "-";
Line 129... Line 190...
129
 
190
 
130
        CourierReconciliationGenerator crg = new CourierReconciliationGenerator();
191
        CourierReconciliationGenerator crg = new CourierReconciliationGenerator();
131
        try {
192
        try {
132
            String userHome = System.getProperty("user.home");
193
            String userHome = System.getProperty("user.home");
133
            FileOutputStream f = new FileOutputStream(userHome + "/courier-reconciliation-report.xls");
194
            FileOutputStream f = new FileOutputStream(userHome + "/courier-reconciliation-report.xls");
134
            ByteArrayOutputStream baosXLS = crg.generateCourierReconciliationReport(startDate, endDate, 1);
195
            ByteArrayOutputStream baosXLS = crg.generateCourierReconciliationReport(startDate, endDate, 1, false);
135
            baosXLS.writeTo(f);
196
            baosXLS.writeTo(f);
136
            f.close();
197
            f.close();
137
        } catch (FileNotFoundException e) {
198
        } catch (FileNotFoundException e) {
138
            logger.error("Error creating payment details report", e);
199
            logger.error("Error creating payment details report", e);
139
        } catch (IOException e) {
200
        } catch (IOException e) {