Subversion Repositories SmartDukaan

Rev

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

Rev 4801 Rev 5354
Line 35... Line 35...
35
import org.slf4j.Logger;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
36
import org.slf4j.LoggerFactory;
37
 
37
 
38
import in.shop2020.logistics.LogisticsServiceException;
38
import in.shop2020.logistics.LogisticsServiceException;
39
import in.shop2020.logistics.Provider;
39
import in.shop2020.logistics.Provider;
-
 
40
import in.shop2020.model.v1.order.LineItem;
40
import in.shop2020.model.v1.order.Order;
41
import in.shop2020.model.v1.order.Order;
41
import in.shop2020.model.v1.order.OrderStatus;
42
import in.shop2020.model.v1.order.OrderStatus;
42
import in.shop2020.model.v1.order.TransactionServiceException;
43
import in.shop2020.model.v1.order.TransactionServiceException;
43
import in.shop2020.support.utils.ReportsUtils;
44
import in.shop2020.support.utils.ReportsUtils;
44
import in.shop2020.thrift.clients.LogisticsClient;
45
import in.shop2020.thrift.clients.LogisticsClient;
Line 197... Line 198...
197
        affHeaderRow.createCell(4).setCellValue("Logistics Provider");
198
        affHeaderRow.createCell(4).setCellValue("Logistics Provider");
198
        affHeaderRow.createCell(5).setCellValue("Shipping Date");
199
        affHeaderRow.createCell(5).setCellValue("Shipping Date");
199
        affHeaderRow.createCell(6).setCellValue("Delivery Date");
200
        affHeaderRow.createCell(6).setCellValue("Delivery Date");
200
        affHeaderRow.createCell(7).setCellValue("Expected Delivery Date");
201
        affHeaderRow.createCell(7).setCellValue("Expected Delivery Date");
201
        affHeaderRow.createCell(8).setCellValue("Delay");
202
        affHeaderRow.createCell(8).setCellValue("Delay");
202
        affHeaderRow.createCell(9).setCellValue("Promised Delivery Date");
-
 
203
        affHeaderRow.createCell(10).setCellValue("Order Created Date");
-
 
204
        affHeaderRow.createCell(11).setCellValue("Promised Shipping Date");
-
 
205
        
203
        
-
 
204
        affHeaderRow.createCell(9).setCellValue("First Delivery Attempt");
-
 
205
        affHeaderRow.createCell(10).setCellValue("First Attempt Delay");
-
 
206
 
-
 
207
        affHeaderRow.createCell(11).setCellValue("Promised Delivery Date");
-
 
208
        affHeaderRow.createCell(12).setCellValue("Order Created Date");
-
 
209
        affHeaderRow.createCell(13).setCellValue("Promised Shipping Date");
-
 
210
        affHeaderRow.createCell(14).setCellValue("Return Receive Date");
-
 
211
        affHeaderRow.createCell(15).setCellValue("Product Name");
-
 
212
        affHeaderRow.createCell(16).setCellValue("AWB");
-
 
213
        
206
        for (int i=0; i<12 ;i++) {
214
        for (int i=0; i<17 ;i++) {
207
            affHeaderRow.getCell(i).setCellStyle(style);
215
            affHeaderRow.getCell(i).setCellStyle(style);
208
        }
216
        }
209
        
217
        
210
        Calendar deliveryTime = Calendar.getInstance();
-
 
211
        Calendar expectedDeliveryTime = Calendar.getInstance();
-
 
212
        long millisInDays = 24 * 60 * 60 * 1000;
-
 
213
        try {
218
        try {
214
            TransactionClient tc = new TransactionClient();
219
            TransactionClient tc = new TransactionClient();
215
            orders = tc.getClient().getAllOrders(rtoStatuses, startDate.getTime(), endDate.getTime(), 0);
220
            orders = tc.getClient().getAllOrders(rtoStatuses, startDate.getTime(), endDate.getTime(), 0);
216
        } catch (TransactionServiceException e) {
221
        } catch (TransactionServiceException e) {
217
            // TODO Auto-generated catch block
222
            // TODO Auto-generated catch block
Line 225... Line 230...
225
            boolean deliveryTimestampSet = false;
230
            boolean deliveryTimestampSet = false;
226
            long diffDays = -99;
231
            long diffDays = -99;
227
            
232
            
228
            if (order.getDelivery_timestamp() != 0) {
233
            if (order.getDelivery_timestamp() != 0) {
229
                deliveryTimestampSet = true;
234
                deliveryTimestampSet = true;
230
                deliveryTime.setTimeInMillis(order.getDelivery_timestamp());
-
 
231
                expectedDeliveryTime.setTimeInMillis(order.getExpected_delivery_time());
235
                diffDays = GetDelayinDays(order.getDelivery_timestamp(), order.getExpected_delivery_time());
232
                long deliveryTimeInMillis = deliveryTime.getTimeInMillis();
-
 
233
                long expectedDeliveryTimeInMillis = expectedDeliveryTime.getTimeInMillis();
-
 
234
                long diff = deliveryTimeInMillis - expectedDeliveryTimeInMillis;
-
 
235
                diffDays = diff / millisInDays;
-
 
236
            }
236
            }
-
 
237
            
237
            affSerialNo++;
238
            affSerialNo++;
238
            Row commContentRow = sheet1.createRow(affSerialNo);
239
            Row commContentRow = sheet1.createRow(affSerialNo);
239
            commContentRow.createCell(0).setCellValue(order.getId());
240
            commContentRow.createCell(0).setCellValue(order.getId());
240
            commContentRow.createCell(1).setCellValue(order.isCod() ? "COD" : "PREPAID");
241
            commContentRow.createCell(1).setCellValue(order.isCod() ? "COD" : "PREPAID");
241
            commContentRow.createCell(2).setCellValue(order.getCustomer_pincode());
242
            commContentRow.createCell(2).setCellValue(order.getCustomer_pincode());
Line 254... Line 255...
254
            if (diffDays == -99) {
255
            if (diffDays == -99) {
255
                commContentRow.createCell(8).setCellValue("N/A");
256
                commContentRow.createCell(8).setCellValue("N/A");
256
            } else {
257
            } else {
257
                commContentRow.createCell(8).setCellValue(diffDays);
258
                commContentRow.createCell(8).setCellValue(diffDays);
258
            }
259
            }
-
 
260
            
259
            commContentRow.createCell(9).setCellValue(new Date(order.getPromised_delivery_time()));
261
            commContentRow.createCell(9).setCellValue(new Date(order.getFirst_attempt_timestamp()));
260
            commContentRow.getCell(9).setCellStyle(dateCellStyle);
262
            commContentRow.getCell(9).setCellStyle(dateCellStyle);
-
 
263
            
-
 
264
            if (order.getFirst_attempt_timestamp() != 0) {
261
            commContentRow.createCell(10).setCellValue(new Date(order.getCreated_timestamp()));
265
                commContentRow.createCell(9).setCellValue(new Date(order.getFirst_attempt_timestamp()));
262
            commContentRow.getCell(10).setCellStyle(dateCellStyle);
266
                commContentRow.getCell(9).setCellStyle(dateCellStyle);
-
 
267
                
-
 
268
                diffDays = GetDelayinDays(order.getFirst_attempt_timestamp(), order.getExpected_delivery_time());
-
 
269
                commContentRow.createCell(10).setCellValue(diffDays);
-
 
270
            } else {
-
 
271
                commContentRow.createCell(9).setCellValue("N/A");
-
 
272
                commContentRow.createCell(10).setCellValue("N/A");
-
 
273
            }
-
 
274
            
263
            commContentRow.createCell(11).setCellValue(new Date(order.getPromised_shipping_time()));
275
            commContentRow.createCell(11).setCellValue(new Date(order.getPromised_delivery_time()));
264
            commContentRow.getCell(11).setCellStyle(dateCellStyle);
276
            commContentRow.getCell(11).setCellStyle(dateCellStyle);
-
 
277
            commContentRow.createCell(12).setCellValue(new Date(order.getCreated_timestamp()));
-
 
278
            commContentRow.getCell(12).setCellStyle(dateCellStyle);
-
 
279
            commContentRow.createCell(13).setCellValue(new Date(order.getPromised_shipping_time()));
-
 
280
            commContentRow.getCell(13).setCellStyle(dateCellStyle);
-
 
281
            commContentRow.createCell(14).setCellValue(new Date(order.getReceived_return_timestamp()));
-
 
282
            commContentRow.getCell(14).setCellStyle(dateCellStyle);
-
 
283
            
-
 
284
            List<LineItem> items = order.getLineitems();
-
 
285
            String product = items.get(0).getBrand() + " " + ((items.get(0).getModel_name() == null)? "" : items.get(0).getModel_name()) + " " + items.get(0).getModel_number();
-
 
286
            commContentRow.createCell(15).setCellValue(product);
-
 
287
            commContentRow.createCell(16).setCellValue(order.getAirwaybill_no());
265
        }
288
        }
266
        for (int i = 0; i<12; i++) {
289
        for (int i = 0; i<17; i++) {
267
            sheet1.autoSizeColumn(i);
290
            sheet1.autoSizeColumn(i);
268
        }
291
        }
269
    }
292
    }
270
    
293
    
271
    private void createDeliveredSheet(Workbook wb, 
294
    private void createDeliveredSheet(Workbook wb, 
Line 301... Line 324...
301
        affHeaderRow.createCell(4).setCellValue("Logistics Provider");
324
        affHeaderRow.createCell(4).setCellValue("Logistics Provider");
302
        affHeaderRow.createCell(5).setCellValue("Shipping Date");
325
        affHeaderRow.createCell(5).setCellValue("Shipping Date");
303
        affHeaderRow.createCell(6).setCellValue("Delivery Date");
326
        affHeaderRow.createCell(6).setCellValue("Delivery Date");
304
        affHeaderRow.createCell(7).setCellValue("Expected Delivery Date");
327
        affHeaderRow.createCell(7).setCellValue("Expected Delivery Date");
305
        affHeaderRow.createCell(8).setCellValue("Delay");
328
        affHeaderRow.createCell(8).setCellValue("Delay");
-
 
329
        
306
        affHeaderRow.createCell(9).setCellValue("Promised Delivery Date");
330
        affHeaderRow.createCell(9).setCellValue("First Delivery Attempt");
307
        affHeaderRow.createCell(10).setCellValue("Order Created Date");
331
        affHeaderRow.createCell(10).setCellValue("First Attempt Delay");
308
        affHeaderRow.createCell(11).setCellValue("Promised Shipping Date");
-
 
309
 
332
 
-
 
333
        
-
 
334
        affHeaderRow.createCell(11).setCellValue("Promised Delivery Date");
-
 
335
        affHeaderRow.createCell(12).setCellValue("Order Created Date");
-
 
336
        affHeaderRow.createCell(13).setCellValue("Promised Shipping Date");
-
 
337
        affHeaderRow.createCell(14).setCellValue("Product Name");
-
 
338
        affHeaderRow.createCell(15).setCellValue("AWB");
-
 
339
 
310
        for (int i=0; i<12 ;i++) {
340
        for (int i=0; i<16 ;i++) {
311
            affHeaderRow.getCell(i).setCellStyle(style);
341
            affHeaderRow.getCell(i).setCellStyle(style);
312
        }
342
        }
313
 
343
 
314
        Calendar deliveryTime = Calendar.getInstance();
-
 
315
        Calendar expectedDeliveryTime = Calendar.getInstance();
-
 
316
        long millisInDays = 24 * 60 * 60 * 1000;
-
 
317
        try {
344
        try {
318
            TransactionClient tc = new TransactionClient();
345
            TransactionClient tc = new TransactionClient();
319
            List<OrderStatus> deliveredStatuses = new ArrayList<OrderStatus>();
346
            List<OrderStatus> deliveredStatuses = new ArrayList<OrderStatus>();
320
            deliveredStatuses.add(OrderStatus.DELIVERY_SUCCESS);
347
            deliveredStatuses.add(OrderStatus.DELIVERY_SUCCESS);
321
            orders = tc.getClient().getAllOrders(deliveredStatuses, startDate.getTime(), endDate.getTime(), 0);
348
            orders = tc.getClient().getAllOrders(deliveredStatuses, startDate.getTime(), endDate.getTime(), 0);
Line 326... Line 353...
326
            // TODO Auto-generated catch block
353
            // TODO Auto-generated catch block
327
            e.printStackTrace();
354
            e.printStackTrace();
328
        }
355
        }
329
 
356
 
330
        for(Order order : orders) {
357
        for(Order order : orders) {
331
            deliveryTime.setTimeInMillis(order.getDelivery_timestamp());
-
 
332
            expectedDeliveryTime.setTimeInMillis(order.getExpected_delivery_time());
358
            long diffDays = GetDelayinDays(order.getDelivery_timestamp(), order.getExpected_delivery_time());
333
            long deliveryTimeInMillis = deliveryTime.getTimeInMillis();
-
 
334
            long expectedDeliveryTimeInMillis = expectedDeliveryTime.getTimeInMillis();
-
 
335
            long diff = deliveryTimeInMillis - expectedDeliveryTimeInMillis;
-
 
336
            long diffDays = diff / millisInDays;
-
 
337
            affSerialNo++;
359
            affSerialNo++;
338
            Row commContentRow = sheet2.createRow(affSerialNo);
360
            Row commContentRow = sheet2.createRow(affSerialNo);
339
            commContentRow.createCell(0).setCellValue(order.getId());
361
            commContentRow.createCell(0).setCellValue(order.getId());
340
            commContentRow.createCell(1).setCellValue(order.isCod() ? "COD" : "PREPAID");
362
            commContentRow.createCell(1).setCellValue(order.isCod() ? "COD" : "PREPAID");
341
            commContentRow.createCell(2).setCellValue(order.getCustomer_pincode());
363
            commContentRow.createCell(2).setCellValue(order.getCustomer_pincode());
Line 346... Line 368...
346
            commContentRow.createCell(6).setCellValue(new Date(order.getDelivery_timestamp()));
368
            commContentRow.createCell(6).setCellValue(new Date(order.getDelivery_timestamp()));
347
            commContentRow.getCell(6).setCellStyle(dateCellStyle);
369
            commContentRow.getCell(6).setCellStyle(dateCellStyle);
348
            commContentRow.createCell(7).setCellValue(new Date(order.getExpected_delivery_time()));
370
            commContentRow.createCell(7).setCellValue(new Date(order.getExpected_delivery_time()));
349
            commContentRow.getCell(7).setCellStyle(dateCellStyle);
371
            commContentRow.getCell(7).setCellStyle(dateCellStyle);
350
            commContentRow.createCell(8).setCellValue(diffDays);
372
            commContentRow.createCell(8).setCellValue(diffDays);
-
 
373
            
351
            commContentRow.createCell(9).setCellValue(new Date(order.getPromised_delivery_time()));
374
            commContentRow.createCell(9).setCellValue(new Date(order.getFirst_attempt_timestamp()));
352
            commContentRow.getCell(9).setCellStyle(dateCellStyle);
375
            commContentRow.getCell(9).setCellStyle(dateCellStyle);
-
 
376
            
353
            commContentRow.createCell(10).setCellValue(new Date(order.getCreated_timestamp()));
377
            diffDays = GetDelayinDays(order.getFirst_attempt_timestamp(), order.getExpected_delivery_time());
354
            commContentRow.getCell(10).setCellStyle(dateCellStyle);
378
            commContentRow.createCell(10).setCellValue(diffDays);
-
 
379
 
-
 
380
            
355
            commContentRow.createCell(11).setCellValue(new Date(order.getPromised_shipping_time()));
381
            commContentRow.createCell(11).setCellValue(new Date(order.getPromised_delivery_time()));
356
            commContentRow.getCell(11).setCellStyle(dateCellStyle);
382
            commContentRow.getCell(11).setCellStyle(dateCellStyle);
-
 
383
            commContentRow.createCell(12).setCellValue(new Date(order.getCreated_timestamp()));
-
 
384
            commContentRow.getCell(12).setCellStyle(dateCellStyle);
-
 
385
            commContentRow.createCell(13).setCellValue(new Date(order.getPromised_shipping_time()));
-
 
386
            commContentRow.getCell(13).setCellStyle(dateCellStyle);
-
 
387
            
-
 
388
            List<LineItem> items = order.getLineitems();
-
 
389
            String product = items.get(0).getBrand() + " " + items.get(0).getModel_name() + " " + items.get(0).getModel_number();
-
 
390
            
-
 
391
            commContentRow.createCell(14).setCellValue(product);
-
 
392
            commContentRow.createCell(15).setCellValue(order.getAirwaybill_no());
357
        }
393
        }
358
        for (int i = 0; i<12; i++) {
394
        for (int i = 0; i<16; i++) {
359
            sheet2.autoSizeColumn(i);
395
            sheet2.autoSizeColumn(i);
360
        }
396
        }
361
    }
397
    }
-
 
398
    
-
 
399
    long GetDelayinDays(long actualDate, long expectedDate) {
-
 
400
        
-
 
401
        Calendar actualTime = Calendar.getInstance();
-
 
402
        Calendar expectedTime = Calendar.getInstance();
-
 
403
        long millisInDays = 24 * 60 * 60 * 1000;
-
 
404
        
-
 
405
        actualTime.setTimeInMillis(actualDate);
-
 
406
        expectedTime.setTimeInMillis(expectedDate);
-
 
407
        
-
 
408
        long actualTimeInMillis = actualTime.getTimeInMillis();
-
 
409
        long expectedTimeInMillis = expectedTime.getTimeInMillis();
-
 
410
        long diff = actualTimeInMillis - expectedTimeInMillis;
-
 
411
        long diffDays = diff / millisInDays;
-
 
412
        
-
 
413
        return diffDays;
-
 
414
    }
362
 
415
 
363
    public List<OrderStatus> getRtoStatuses() {
416
    public List<OrderStatus> getRtoStatuses() {
364
        return rtoStatuses;
417
        return rtoStatuses;
365
    }
418
    }
366
 
419