Subversion Repositories SmartDukaan

Rev

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

Rev 7423 Rev 7427
Line 5... Line 5...
5
import in.shop2020.model.v1.order.LineItem;
5
import in.shop2020.model.v1.order.LineItem;
6
import in.shop2020.model.v1.order.Order;
6
import in.shop2020.model.v1.order.Order;
7
import in.shop2020.model.v1.order.OrderStatus;
7
import in.shop2020.model.v1.order.OrderStatus;
8
import in.shop2020.model.v1.order.RechargeOrderStatus;
8
import in.shop2020.model.v1.order.RechargeOrderStatus;
9
import in.shop2020.model.v1.order.RechargeTransaction;
9
import in.shop2020.model.v1.order.RechargeTransaction;
-
 
10
import in.shop2020.model.v1.order.StoreOrderCollection;
10
import in.shop2020.model.v1.order.StoreOrderDetail;
11
import in.shop2020.model.v1.order.StoreOrderDetail;
11
import in.shop2020.model.v1.order.TransactionService;
12
import in.shop2020.model.v1.order.TransactionService;
12
import in.shop2020.thrift.clients.HelperClient;
13
import in.shop2020.thrift.clients.HelperClient;
13
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.thrift.clients.TransactionClient;
14
import in.shop2020.utils.Mail;
15
import in.shop2020.utils.Mail;
Line 140... Line 141...
140
    public String getCollection() throws Exception{
141
    public String getCollection() throws Exception{
141
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
142
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
142
        if(loginStatus == null || !loginStatus.equals("TRUE")){
143
        if(loginStatus == null || !loginStatus.equals("TRUE")){
143
            return "authfail";
144
            return "authfail";
144
        }
145
        }
-
 
146
        
-
 
147
        long sDate = -1;
-
 
148
        long eDate = -1;
-
 
149
 
-
 
150
        if(dateselector.equals("1")) {
-
 
151
            sDate = new Date().getTime();
-
 
152
            eDate = sDate;
-
 
153
        }else if (dateselector.equals("2")) {
-
 
154
            sDate = new Date().getTime() - 86400*1000;
-
 
155
            eDate = sDate;
-
 
156
        }else {
-
 
157
            if(!(startDate.equals(""))) {
-
 
158
                sDate = dateFormatter.parse(startDate).getTime();
-
 
159
                startDate = dateFormatter.format(sDate);
-
 
160
            }
-
 
161
            if(!endDate.equals("")) {
-
 
162
                eDate = dateFormatter.parse(endDate).getTime();
-
 
163
                endDate = dateFormatter.format(eDate);
-
 
164
            }
-
 
165
        }
-
 
166
        
145
        long today = -1;
167
        long today = -1;
146
        today = new Date().getTime();
168
        today = new Date().getTime();
147
        List<OrderStatus> statuses = new ArrayList<OrderStatus>();
-
 
148
        statuses.add(OrderStatus.DELIVERY_SUCCESS);
-
 
149
        statuses.add(OrderStatus.SUBMITTED_FOR_PROCESSING);
-
 
150
        statuses.add(OrderStatus.ACCEPTED);
-
 
151
        statuses.add(OrderStatus.BILLED);
-
 
152
        
-
 
153
        List<Order> successfulOrders = tClient.getOrdersForStore(0, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), today, today, statuses);
-
 
154
        statuses.clear();
-
 
155
        statuses.add(OrderStatus.CANCELLED_ON_CUSTOMER_REQUEST);
-
 
156
        statuses.add(OrderStatus.CANCELLED_DUE_TO_LOW_INVENTORY);
-
 
157
        List<Order> refundedOrders = tClient.getOrdersForStore(0, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), today, today, statuses);
169
        List<StoreOrderCollection> collections = tClient.getCollectionsForStore(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), sDate, eDate);
158
        ByteArrayOutputStream baos = generateCollectionReport(successfulOrders, refundedOrders);
170
        ByteArrayOutputStream baos = generateCollectionReport(collections);
159
        response.setContentType("application/vnd.ms-excel");
171
        response.setContentType("application/vnd.ms-excel");
160
        String fileName = "collection-report";
172
        String fileName = "collection-report";
161
        String todayDate = df4Filename.format(new Date(today));
173
        String todayDate = df4Filename.format(new Date(today));
162
        fileName = fileName + "-" + todayDate;
174
        fileName = fileName + "-" + todayDate;
163
        fileName = fileName + ".xls";
175
        fileName = fileName + ".xls";
Line 172... Line 184...
172
        }
184
        }
173
        return null;
185
        return null;
174
        
186
        
175
    }
187
    }
176
    
188
    
177
    private ByteArrayOutputStream generateCollectionReport(List<Order> successfulOrders,
189
    private ByteArrayOutputStream generateCollectionReport(List<StoreOrderCollection> collections) {
178
                                                            List<Order> refundedOrders) {
-
 
179
        ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
190
        ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
180
        Workbook wb = new HSSFWorkbook();
191
        Workbook wb = new HSSFWorkbook();
181
        Sheet reportSheet = wb.createSheet("Recharge Report");
192
        Sheet reportSheet = wb.createSheet("Collection Report");
182
        Row reportSheetHeader = reportSheet.createRow((short)0);
193
        Row reportSheetHeader = reportSheet.createRow((short)0);
183
        reportSheetHeader.createCell(0).setCellValue("Order ID");
194
        reportSheetHeader.createCell(0).setCellValue("Order ID");
184
        reportSheetHeader.createCell(1).setCellValue("Order Date");
195
        reportSheetHeader.createCell(1).setCellValue("Date");
185
        reportSheetHeader.createCell(2).setCellValue("Product");
196
        reportSheetHeader.createCell(2).setCellValue("Product");
186
        reportSheetHeader.createCell(3).setCellValue("Status");
197
        reportSheetHeader.createCell(3).setCellValue("Collection Type");
187
        reportSheetHeader.createCell(4).setCellValue("Refund Date");
198
        reportSheetHeader.createCell(4).setCellValue("Amount");
188
        reportSheetHeader.createCell(5).setCellValue("Order Value");
199
        reportSheetHeader.createCell(5).setCellValue("Cash");
189
        reportSheetHeader.createCell(6).setCellValue("Collected Amount");
200
        reportSheetHeader.createCell(6).setCellValue("Card");
190
        
201
        
191
        int serialNo = 0;
-
 
192
        
202
        
193
        for(Order order : successfulOrders) {
-
 
194
            serialNo++;
-
 
195
            Row contentRow = reportSheet.createRow((short)serialNo);
-
 
196
            contentRow.createCell(0).setCellValue(order.getId());
-
 
197
            contentRow.createCell(1).setCellValue(formatter.format(new Date(order.getCreated_timestamp())));
-
 
198
            contentRow.createCell(2).setCellValue(getProductName(order.getLineitems().get(0)));
-
 
199
            contentRow.createCell(3).setCellValue(order.getStatusDescription());
-
 
200
            contentRow.createCell(4).setCellValue("N/A");
-
 
201
            contentRow.createCell(5).setCellValue(order.getTotal_amount());
-
 
202
            contentRow.createCell(6).setCellValue(order.getAdvanceAmount());
-
 
203
        }
-
 
204
        
203
        
-
 
204
        int serialNo = 0;
-
 
205
        
205
        for(Order order : refundedOrders) {
206
        for(StoreOrderCollection collection : collections) {
206
            serialNo++;
207
            serialNo++;
207
            Row contentRow = reportSheet.createRow((short)serialNo);
208
            Row contentRow = reportSheet.createRow((short)serialNo);
208
            contentRow.createCell(0).setCellValue(order.getId());
209
            contentRow.createCell(0).setCellValue(collection.getOrderId());
209
            contentRow.createCell(1).setCellValue(formatter.format(new Date(order.getCreated_timestamp())));
210
            contentRow.createCell(1).setCellValue(formatter.format(new Date(collection.getPushedAt())));
210
            contentRow.createCell(2).setCellValue(getProductName(order.getLineitems().get(0)));
211
            contentRow.createCell(2).setCellValue(collection.getProductName());
211
            contentRow.createCell(3).setCellValue(order.getStatusDescription());
212
            contentRow.createCell(3).setCellValue(collection.getCollectionType());
212
            contentRow.createCell(4).setCellValue(formatter.format(new Date(order.getRefund_timestamp())));
213
            contentRow.createCell(4).setCellValue(collection.getAdvanceAmount());
213
            contentRow.createCell(5).setCellValue(order.getTotal_amount());
214
            contentRow.createCell(5).setCellValue(collection.getCash());
214
            contentRow.createCell(6).setCellValue(-order.getAdvanceAmount());
215
            contentRow.createCell(6).setCellValue(collection.getCard());
215
        }
216
        }
216
        
-
 
217
        try {
217
        try {
218
            wb.write(baosXLS);
218
            wb.write(baosXLS);
219
        } catch (IOException e) {
219
        } catch (IOException e) {
220
            // TODO Auto-generated catch block
220
            // TODO Auto-generated catch block
221
            e.printStackTrace();
221
            e.printStackTrace();
Line 225... Line 225...
225
 
225
 
226
    
226
    
227
    public String create() throws Exception{
227
    public String create() throws Exception{
228
        long sDate = -1;
228
        long sDate = -1;
229
        long eDate = -1;
229
        long eDate = -1;
230
        RechargeOrderStatus st = null;
-
 
231
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
230
        String loginStatus = (String) request.getSession().getAttribute("LOGGED_IN");
232
        if(loginStatus == null || !loginStatus.equals("TRUE")){
231
        if(loginStatus == null || !loginStatus.equals("TRUE")){
233
            return "authfail";
232
            return "authfail";
234
        }
233
        }
235
        if(dateselector.equals("1")) {
234
        if(dateselector.equals("1")) {
Line 246... Line 245...
246
            if(!endDate.equals("")) {
245
            if(!endDate.equals("")) {
247
                eDate = dateFormatter.parse(endDate).getTime();
246
                eDate = dateFormatter.parse(endDate).getTime();
248
                endDate = dateFormatter.format(sDate);
247
                endDate = dateFormatter.format(sDate);
249
            }
248
            }
250
        }
249
        }
251
        if(!status.equals("-1")){
250
            
252
            st = RechargeOrderStatus.findByValue(Integer.parseInt(status));
251
        List<OrderStatus> statuses = new ArrayList<OrderStatus>();
253
        }
252
        statuses.add(OrderStatus.DELIVERY_SUCCESS);
-
 
253
        orders = tClient.getOrdersForStore(0, Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), sDate, eDate, statuses);
254
 
254
 
255
        ByteArrayOutputStream baos = generateReport(tClient.getRechargeTrans(Long.parseLong((String) request.getSession().getAttribute("STORE_ID")), sDate, eDate, st));
255
        ByteArrayOutputStream baos = generateReport(orders);
256
        
256
        
257
        response.setContentType("application/vnd.ms-excel");
257
        response.setContentType("application/vnd.ms-excel");
258
        String st1 = "ALL";
-
 
259
        if(st!=null){
-
 
260
            st1 = st.name();
-
 
261
        }
-
 
262
        String fileName = st1 + "-recharge-report";
258
        String fileName = "sales-report";
263
        if (!startDate.equals("")) {
259
        if (!startDate.equals("")) {
264
            fileName = fileName + "-" + startDate.replaceAll("\\\\", "_") ;
260
            fileName = fileName + "-" + startDate.replaceAll("\\\\", "_") ;
265
        }
261
        }
266
        if (!endDate.equals("")) {
262
        if (!endDate.equals("")) {
267
            fileName = fileName + "-" + endDate.replaceAll("\\\\", "_") ;
263
            fileName = fileName + "-" + endDate.replaceAll("\\\\", "_") ;
Line 278... Line 274...
278
        }
274
        }
279
        return "index";
275
        return "index";
280
    }
276
    }
281
    
277
    
282
        
278
        
283
    private ByteArrayOutputStream generateReport(
279
    private ByteArrayOutputStream generateReport(List<Order> orders) {
284
            List<RechargeTransaction> rechargeTrans) {
-
 
285
ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
-
 
286
        
280
        
-
 
281
        ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
287
        Workbook wb = new HSSFWorkbook();
282
        Workbook wb = new HSSFWorkbook();
288
        
-
 
289
        Sheet reportSheet = wb.createSheet("Recharge Report");
283
        Sheet reportSheet = wb.createSheet("Recharge Report");
290
        
284
 
291
        Row reportSheetHeader = reportSheet.createRow((short)0);
285
        Row reportSheetHeader = reportSheet.createRow((short)0);
292
        reportSheetHeader.createCell(0).setCellValue("Order ID");
286
        reportSheetHeader.createCell(0).setCellValue("Order ID");
293
        reportSheetHeader.createCell(1).setCellValue("Order Date");
287
        reportSheetHeader.createCell(1).setCellValue("Order Date");
294
        reportSheetHeader.createCell(2).setCellValue("Operator");
-
 
295
        reportSheetHeader.createCell(3).setCellValue("Device");
288
        reportSheetHeader.createCell(2).setCellValue("Product");
296
        reportSheetHeader.createCell(4).setCellValue("Status");
289
        reportSheetHeader.createCell(3).setCellValue("Status");
297
        reportSheetHeader.createCell(5).setCellValue("Recharge Amount");
-
 
298
        reportSheetHeader.createCell(6).setCellValue("Discount");
-
 
299
        reportSheetHeader.createCell(7).setCellValue("Net Amount");
290
        reportSheetHeader.createCell(4).setCellValue("Order Amount");
300
        reportSheetHeader.createCell(8).setCellValue("Type");
291
        reportSheetHeader.createCell(5).setCellValue("Advance");
301
        reportSheetHeader.createCell(9).setCellValue("Pay Method");
-
 
302
        reportSheetHeader.createCell(10).setCellValue("Refund Date");
-
 
303
        
292
        
304
        int serialNo = 0;
293
        int serialNo = 0;
305
        
294
        
306
        for(RechargeTransaction transaction : rechargeTrans) {
295
        for(Order order : orders) {
307
            serialNo++;
296
            serialNo++;
308
            Row contentRow = reportSheet.createRow((short)serialNo);
297
            Row contentRow = reportSheet.createRow((short)serialNo);
309
            contentRow.createCell(0).setCellValue(transaction.getId());
298
            contentRow.createCell(0).setCellValue(order.getId());
310
            contentRow.createCell(1).setCellValue(formatter.format(new Date(transaction.getTransactionTime())));
299
            contentRow.createCell(1).setCellValue(formatter.format(new Date(order.getCreated_timestamp())));
311
//            contentRow.createCell(2).setCellValue(getOperatorName(transaction.getOperatorId()));
300
            contentRow.createCell(2).setCellValue(getProductName(order.getLineitems().get(0)));
312
            contentRow.createCell(3).setCellValue(transaction.getDeviceNum());
-
 
313
            contentRow.createCell(4).setCellValue(transaction.getStatus().name());
301
            contentRow.createCell(3).setCellValue(order.getStatusDescription());
314
            contentRow.createCell(5).setCellValue(transaction.getAmount());
302
            contentRow.createCell(4).setCellValue(order.getTotal_amount());
315
            contentRow.createCell(6).setCellValue(transaction.getDiscount());
-
 
316
            contentRow.createCell(7).setCellValue(transaction.getPaymentAmount());
303
            contentRow.createCell(5).setCellValue(order.getAdvanceAmount());
317
            contentRow.createCell(8).setCellValue(transaction.isIsFrc() ? "FRC" : "Normal");
-
 
318
            contentRow.createCell(9).setCellValue(transaction.getPayMethod().name());
-
 
319
            if(transaction.getStatus() == RechargeOrderStatus.RECHARGE_FAILED_REFUNDED) {
-
 
320
                contentRow.createCell(10).setCellValue(transaction.getResponseTime());
-
 
321
            } else {
-
 
322
                contentRow.createCell(10).setCellValue("N/A");
-
 
323
            }
-
 
324
        }
304
        }
325
        try {
305
        try {
326
            wb.write(baosXLS);
306
            wb.write(baosXLS);
327
        } catch (IOException e) {
307
        } catch (IOException e) {
328
            // TODO Auto-generated catch block
308
            // TODO Auto-generated catch block