Subversion Repositories SmartDukaan

Rev

Rev 7811 | Rev 8049 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
679 chandransh 1
package in.shop2020.support.controllers;
2
 
4386 anupam.sin 3
import in.shop2020.logistics.DeliveryType;
4
import in.shop2020.logistics.LogisticsServiceException;
7792 anupam.sin 5
import in.shop2020.logistics.PickupStore;
4386 anupam.sin 6
import in.shop2020.logistics.Provider;
7792 anupam.sin 7
import in.shop2020.logistics.ProviderDetails;
5945 mandeep.dh 8
import in.shop2020.model.v1.inventory.InventoryServiceException;
9
import in.shop2020.model.v1.inventory.Warehouse;
4386 anupam.sin 10
import in.shop2020.model.v1.order.LineItem;
11
import in.shop2020.model.v1.order.Order;
12
import in.shop2020.model.v1.order.TransactionServiceException;
5945 mandeep.dh 13
import in.shop2020.support.models.AwbDetails;
3364 chandransh 14
import in.shop2020.support.utils.FileUtils;
3125 rajveer 15
import in.shop2020.thrift.clients.HelperClient;
5945 mandeep.dh 16
import in.shop2020.thrift.clients.InventoryClient;
4386 anupam.sin 17
import in.shop2020.thrift.clients.LogisticsClient;
18
import in.shop2020.thrift.clients.TransactionClient;
749 chandransh 19
import in.shop2020.utils.LogisticsUser;
679 chandransh 20
 
7792 anupam.sin 21
import java.io.BufferedReader;
679 chandransh 22
import java.io.ByteArrayOutputStream;
756 chandransh 23
import java.io.File;
7792 anupam.sin 24
import java.io.FileNotFoundException;
25
import java.io.FileReader;
679 chandransh 26
import java.io.IOException;
7792 anupam.sin 27
import java.text.ParseException;
28
import java.text.SimpleDateFormat;
4386 anupam.sin 29
import java.util.ArrayList;
679 chandransh 30
import java.util.Calendar;
4386 anupam.sin 31
import java.util.Date;
679 chandransh 32
import java.util.GregorianCalendar;
754 chandransh 33
import java.util.HashMap;
34
import java.util.List;
7792 anupam.sin 35
import java.util.Locale;
754 chandransh 36
import java.util.Map;
679 chandransh 37
 
1075 chandransh 38
import javax.servlet.ServletContext;
679 chandransh 39
import javax.servlet.ServletOutputStream;
40
import javax.servlet.http.HttpServletRequest;
41
import javax.servlet.http.HttpServletResponse;
749 chandransh 42
import javax.servlet.http.HttpSession;
679 chandransh 43
 
7811 anupam.sin 44
import org.apache.commons.lang.StringUtils;
7792 anupam.sin 45
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
46
import org.apache.poi.ss.usermodel.Cell;
47
import org.apache.poi.ss.usermodel.CellStyle;
48
import org.apache.poi.ss.usermodel.CreationHelper;
49
import org.apache.poi.ss.usermodel.Row;
50
import org.apache.poi.ss.usermodel.Sheet;
51
import org.apache.poi.ss.usermodel.Workbook;
679 chandransh 52
import org.apache.struts2.interceptor.ServletRequestAware;
53
import org.apache.struts2.interceptor.ServletResponseAware;
1075 chandransh 54
import org.apache.struts2.util.ServletContextAware;
4386 anupam.sin 55
import org.apache.thrift.TException;
56
import org.apache.thrift.transport.TTransportException;
3062 chandransh 57
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
679 chandransh 59
 
2904 chandransh 60
/**
61
 * Allows executives of courier companies to login and download courier details
62
 * report which they then use to upload into their database.
63
 * 
64
 * @author Chandranshu
65
 * 
66
 */
679 chandransh 67
public class CourierDetailsController implements ServletResponseAware,
1075 chandransh 68
		ServletRequestAware, ServletContextAware {
3062 chandransh 69
 
70
    private static Logger logger = LoggerFactory.getLogger(CourierDetailsController.class);
71
 
7792 anupam.sin 72
    private static final String EMPTY_STRING = "-";
73
 
749 chandransh 74
	private String id;
1075 chandransh 75
	private int daysToSubtract;
756 chandransh 76
 
77
	//FIXME: Read this configuration from the config client
78
	private String courierDetailsPath = "/CourierDetailReports";
79
 
1075 chandransh 80
	private ServletContext context;
679 chandransh 81
	private HttpServletRequest request;
82
	private HttpServletResponse response;
749 chandransh 83
	private HttpSession session;
679 chandransh 84
 
4386 anupam.sin 85
    private String awbNumbers;
86
    private List<AwbDetails> detailedAWBs;
87
 
88
    private String errorMsg = "";
7792 anupam.sin 89
 
90
    private File awbFile;
91
    private String awbFileContentType;
92
    private String awbFileFileName;
4386 anupam.sin 93
 
749 chandransh 94
	public String index(){
95
		if(getSessionUserName()==null)
96
			return "authfail";
97
		else
98
			return "authsuccess";
99
	}
100
 
101
	// Handler for POST /courier-details
102
	public String create(){
103
		String username = request.getParameter("username");
104
		String password = request.getParameter("password");
105
		try{
3125 rajveer 106
			HelperClient helperServiceClient = new HelperClient();
749 chandransh 107
			in.shop2020.utils.HelperService.Client client = helperServiceClient.getClient();
108
			LogisticsUser user = client.authenticateLogisticsUser(username, password);
109
			session.setAttribute("username", user.getUsername());
110
			session.setAttribute("providerId", Long.valueOf(user.getProviderId()));
111
		}catch(Exception e){
3105 chandransh 112
			logger.error("Error authenticating the user " + username, e);
749 chandransh 113
			return "authfail";
114
		}
115
		return "authsuccess";
679 chandransh 116
	}
117
 
749 chandransh 118
	// Handler for GET /courier-details/<warehouseId>
119
	public String show(){
120
		try {
121
			long warehouseId = Long.parseLong(getId());
4209 rajveer 122
			if(warehouseId == 1){
123
				warehouseId = 0;
124
			}
749 chandransh 125
			long providerId = ((Long)session.getAttribute("providerId")).longValue();
3062 chandransh 126
			boolean isCod;
127
			try {
128
	            isCod = Boolean.parseBoolean(request.getParameter("isCod"));
129
	        } catch (Exception e) {
130
	            isCod = false;
131
	        }
3105 chandransh 132
			logger.info("Download request for " + (isCod ? "COD" : "Prepaid") + " Courier Details report of warehouse Id: " + warehouseId + " and provider Id:" + providerId);
749 chandransh 133
 
3062 chandransh 134
			String deliveryType = "prepaid";
135
			if(isCod)
136
			    deliveryType = "cod";
137
 
749 chandransh 138
			response.setContentType("application/vnd.ms-excel");
139
 
140
			Calendar date = new GregorianCalendar();
1075 chandransh 141
			date.add(Calendar.DAY_OF_MONTH, daysToSubtract);
749 chandransh 142
			int year = date.get(Calendar.YEAR);
7792 anupam.sin 143
			int month = date.get(Calendar.MONTH) + 1;
749 chandransh 144
			int day = date.get(Calendar.DAY_OF_MONTH);
3062 chandransh 145
			String fileName = courierDetailsPath + "/courier-details-" + deliveryType + "-" + warehouseId + "-" + providerId + "-" + year + "-" + month + "-" + day +".xls";
146
			response.setHeader("Content-disposition", "inline; filename=courier-details-" + deliveryType + "-" + warehouseId + "-" + providerId + "-" + year + "-"+ month + "-" + day +".xls" );
749 chandransh 147
 
148
			ServletOutputStream sos;
149
			try {
756 chandransh 150
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
3364 chandransh 151
				baos.write(FileUtils.getBytesFromFile(new File(fileName)));
749 chandransh 152
				sos = response.getOutputStream();
153
				baos.writeTo(sos);
154
				sos.flush();
155
			} catch (IOException e) {
3062 chandransh 156
				logger.error("Unable to stream the courier details report", e);
749 chandransh 157
			}	
158
			return "authsuccess";
159
		}catch(NumberFormatException nfe){
3062 chandransh 160
			logger.error("Unable to parse the warehouse id", nfe);
749 chandransh 161
		}
162
		return "authfail";
163
	}
4386 anupam.sin 164
 
165
	/**
7792 anupam.sin 166
	 * Use this method to view details of a given awb number
4386 anupam.sin 167
	 */
7792 anupam.sin 168
	public String viewAwbDetails() {
4386 anupam.sin 169
	    if(awbNumbers.isEmpty()) {
170
	        setErrorMsg("Field cannot be empty");
171
	        return "info";
172
	    }
7792 anupam.sin 173
	    String [] awbArray = awbNumbers.split(",");
174
	    createAwbDetailList(awbArray);
175
	    return "info";
176
	}
177
 
178
	/**
179
     * Use this method to download details of given comma separated list of awb numbers
180
     */
181
 
182
	public String getAwbDetails() {
183
	    if(awbNumbers.isEmpty()) {
184
            setErrorMsg("Field cannot be empty");
185
            return "info";
186
        }
187
        String [] awbArray = awbNumbers.split(",");
188
        createAwbDetailList(awbArray);
189
        ByteArrayOutputStream baos = generateAwbDetailsSheet(this.detailedAWBs);
190
        response.setContentType("application/vnd.ms-excel");
191
        response.setHeader("Content-disposition", "inline; filename=awbDetails-" + Calendar.getInstance().getTime().toString() + ".xls");
192
        ServletOutputStream sos;
193
        try {
194
            sos = response.getOutputStream();
195
            baos.writeTo(sos);
196
            sos.flush();
197
        } catch (IOException e) {
198
            logger.error("Encountered error while sending invoice response: ", e);
199
        }
200
        return "info";
201
    }
202
 
203
	/**
204
     * Use this method to download details of given list of awb numbers uploaded in a text file
205
     */
206
 
207
	public String getAwbDetailsByFile() {
208
	    if(awbFile == null) {
209
	        return null;
210
	    }
211
 
212
	    List<String> awbList = new ArrayList<String>();
213
 
214
	    try {
215
	        BufferedReader in = new BufferedReader(new FileReader(awbFile));
216
	        String line;
217
	        while((line = in.readLine()) != null) {
218
	            awbList.add(line.trim());
219
	        }
220
	    } catch (FileNotFoundException e1) {
221
	        logger.error("File not found", e1);
222
	        return null;
223
	    } catch (IOException e) {
224
	        logger.error("Unable to read file", e);
225
	        return null;
226
	    }
227
 
228
	    String[] awbArray  = awbList.toArray(new String [awbList.size()]);
229
	    createAwbDetailList(awbArray);
230
 
231
	    ByteArrayOutputStream baos = generateAwbDetailsSheet(this.detailedAWBs);
232
	    response.setContentType("application/vnd.ms-excel");
233
        response.setHeader("Content-disposition", "inline; filename=awbDetails-" + Calendar.getInstance().getTime().toString() + ".xls");
234
	    ServletOutputStream sos;
235
	    try {
236
	        sos = response.getOutputStream();
237
	        baos.writeTo(sos);
238
	        sos.flush();
239
	    } catch (IOException e) {
240
	        logger.error("Encountered error while sending invoice response: ", e);
241
	    }
242
	    return "info";
243
	}
244
 
245
    private void createAwbDetailList(String[] awbArray) {
246
        Order order = null;
4386 anupam.sin 247
	    List<AwbDetails> tempList = new ArrayList<AwbDetails>() ;
248
	    for(String awbNumber : awbArray) {
249
	        try {
250
	            LogisticsClient lsc = new LogisticsClient();
251
	            TransactionClient tsc = new TransactionClient();
5945 mandeep.dh 252
	            InventoryClient isc = new InventoryClient();
253
	            in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = isc.getClient();
4386 anupam.sin 254
	            in.shop2020.model.v1.order.TransactionService.Client txnClient = tsc.getClient();
255
	            in.shop2020.logistics.LogisticsService.Client logisticsClient = lsc.getClient();
256
 
257
	            /*
258
	             * Get required stuff
259
	             * FIXME: Reduce service calls 
260
	             */
7813 anupam.sin 261
	            logger.info("Session : " + session);
262
	            logger.info("provider Id : " + ((Long)session.getAttribute("providerId")).longValue());
4391 anupam.sin 263
	            Provider provider = logisticsClient.getProvider(((Long)session.getAttribute("providerId")).longValue());
4386 anupam.sin 264
	            order = txnClient.getOrderForAwb(awbNumber);
265
	            Warehouse warehouse = inventoryClient.getWarehouse(order.getWarehouse_id());
266
 
7792 anupam.sin 267
	            String accountNo = "";
4386 anupam.sin 268
 
7792 anupam.sin 269
	            DeliveryType dt =  DeliveryType.PREPAID;
270
	            if (order.isLogisticsCod()) {
271
	                dt = DeliveryType.COD;
272
	            }
273
 
274
	            for (ProviderDetails detail : provider.getDetails()) {
275
	                if(in.shop2020.model.v1.inventory.WarehouseLocation.findByValue((int) detail.getLogisticLocation()) == warehouse.getLogisticsLocation() && detail.getDeliveryType() == dt) {
276
	                    accountNo = detail.getAccountNo();
277
	                }
278
	            }
279
 
4386 anupam.sin 280
	            AwbDetails detailedAwb = new AwbDetails();
281
 
7792 anupam.sin 282
	            String[] addresses = warehouse.getLocation().split(",+");
283
 
7811 anupam.sin 284
	            detailedAwb.setReturnAddress1((addresses[0].trim() + ", " + addresses[1].trim()).replace("\n", ", "));
285
	            detailedAwb.setReturnAddress2((addresses[2].trim() + (addresses.length > 3 ? ", " + addresses[3].trim() : "")).replace("\n", ", "));
286
 
287
	            String line3 = "";
288
	            if(addresses.length > 4) {
289
	                for(int i = 4; i<addresses.length; i++) {
290
	                    line3 += addresses[i] + ", ";
291
	                }
7792 anupam.sin 292
	            }
293
 
7811 anupam.sin 294
	            if(StringUtils.isNotEmpty(line3)) {
295
	                detailedAwb.setReturnAddress3(line3.trim().replace("\n", ", "));
296
	            } else {
297
	                detailedAwb.setReturnAddress3(EMPTY_STRING);
298
	            }
7792 anupam.sin 299
	            detailedAwb.setReturnPin(warehouse.getPincode());
4386 anupam.sin 300
	            detailedAwb.setAwbNumber(awbNumber);
301
	            detailedAwb.setAccountCode(accountNo);
7792 anupam.sin 302
	            detailedAwb.setVendorCode((int) order.getWarehouse_id());
4386 anupam.sin 303
	            detailedAwb.setAddress1(order.getCustomer_address1());
304
	            detailedAwb.setAddress2(order.getCustomer_address2());
5554 rajveer 305
	            if(order.isLogisticsCod()){
7792 anupam.sin 306
	                detailedAwb.setAmountToCollect("" + (order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()));
4604 anupam.sin 307
	            } else {
308
	                detailedAwb.setAmountToCollect("" + 0 );
309
	            }
7811 anupam.sin 310
 
311
	            if(order.getShipping_timestamp() > 0) {
312
    	            Date date = new Date(order.getShipping_timestamp());
313
    	            detailedAwb.setAwbDate(date.toString());
314
	            } else {
315
	                detailedAwb.setAwbDate("N/A");
316
	            }
4386 anupam.sin 317
	            detailedAwb.setCity(order.getCustomer_city());
318
	            detailedAwb.setCustomerName(order.getCustomer_name());
7792 anupam.sin 319
	            detailedAwb.setItemId("" + order.getLineitems().get(0).getItem_id());
4386 anupam.sin 320
	            detailedAwb.setOrderId("" + order.getId());
321
	            detailedAwb.setPacketWeight("" + order.getTotal_weight());
5554 rajveer 322
	            if(order.isLogisticsCod()){
4386 anupam.sin 323
	                detailedAwb.setPaymentMode("COD");
324
	            } else {
325
	                detailedAwb.setPaymentMode("Prepaid");
326
	            }
327
 
328
	            detailedAwb.setPhoneNumber("" + order.getCustomer_mobilenumber());
329
	            detailedAwb.setPickupLocation(warehouse.getLocation());
330
	            detailedAwb.setPinCode(order.getCustomer_pincode());
331
	            LineItem lineitem = order.getLineitems().get(0);
7792 anupam.sin 332
	            detailedAwb.setProductName(lineitem.getBrand() + " " 
333
	                                         + (lineitem.getModel_name() == null ? "" : lineitem.getModel_name()) + " " 
334
	                                         + (lineitem.getModel_number() == null ? "" : lineitem.getModel_number()) + " " 
335
	                                         + (lineitem.getColor() == null ? "" : lineitem.getColor()));
336
	            detailedAwb.setShipmentValue("" + (order.getTotal_amount()));
4386 anupam.sin 337
	            detailedAwb.setState(order.getCustomer_state());
338
 
339
	            tempList.add(detailedAwb);
3105 chandransh 340
 
4386 anupam.sin 341
	        } catch (TTransportException e) {
342
	            setErrorMsg("Your request cannot be processed due to technical error. Please try later.");
343
	        } catch (TException e) {
344
	            setErrorMsg(e.getMessage());
345
	        } catch (TransactionServiceException e) {
346
	            setErrorMsg(e.getMessage());
347
	        } catch (LogisticsServiceException e) {
348
	            setErrorMsg(e.getMessage());
349
            } catch (InventoryServiceException e) {
350
                setErrorMsg(e.getMessage());
351
            }
352
	    }
7811 anupam.sin 353
	    setDetailedAWBs(tempList);
7792 anupam.sin 354
    }
355
 
356
 
357
	public ByteArrayOutputStream generateAwbDetailsSheet(List<AwbDetails> awbDetailList) {
358
	    ByteArrayOutputStream baos = new ByteArrayOutputStream();;
359
	    Workbook wb = new HSSFWorkbook();
360
        CreationHelper createHelper = wb.getCreationHelper();
361
        Sheet sheet = wb.createSheet("Saholic - Data");
362
 
363
        CellStyle dateCellStyle = wb.createCellStyle();
364
        dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yyyy"));
365
 
366
        CellStyle weightStyle = wb.createCellStyle();
367
        weightStyle.setDataFormat(createHelper.createDataFormat().getFormat("0.000"));
368
 
369
        Row headerRow = sheet.createRow((short)0);
370
        headerRow.createCell(0).setCellValue("Airwaybill");
371
        headerRow.createCell(1).setCellValue("Type"); //Values : "COD" / "NONCOD"
372
        headerRow.createCell(2).setCellValue("Reference Number"); //OrderId
373
        headerRow.createCell(3).setCellValue("Sender / Store name"); //"Spice Online retail pvt ltd"
374
        headerRow.createCell(4).setCellValue("attention"); //Customer name
375
        headerRow.createCell(5).setCellValue("address1"); //Line 1
376
        headerRow.createCell(6).setCellValue("address2"); //Line 2
377
        headerRow.createCell(7).setCellValue("address3"); //city + state
378
        headerRow.createCell(8).setCellValue("pincode");
379
        headerRow.createCell(9).setCellValue("tel number"); //Empty
380
        headerRow.createCell(10).setCellValue("mobile number"); //Empty
381
        headerRow.createCell(11).setCellValue("Prod/SKU code");  //ItemId
382
        headerRow.createCell(12).setCellValue("contents"); //Product name
383
        headerRow.createCell(13).setCellValue("weight");  //In Kgs
384
        headerRow.createCell(14).setCellValue("Declared Value");  
385
        headerRow.createCell(15).setCellValue("Collectable Value");
386
        headerRow.createCell(16).setCellValue("Vendor Code");
387
        headerRow.createCell(17).setCellValue("Shipper Name");  
388
        headerRow.createCell(18).setCellValue("Return Address1");
389
        headerRow.createCell(19).setCellValue("Return Address2");
390
        headerRow.createCell(20).setCellValue("Return Address3");
391
        headerRow.createCell(21).setCellValue("Return Pin");
392
        headerRow.createCell(22).setCellValue("Length ( Cms )");
393
        headerRow.createCell(23).setCellValue("Bredth ( Cms )");
394
        headerRow.createCell(24).setCellValue("Height ( Cms )");
395
        headerRow.createCell(25).setCellValue("Pieces");       
396
        headerRow.createCell(26).setCellValue("Area_customer_code");
397
        headerRow.createCell(27).setCellValue("Handover Date ( DD/MM/YYYY )");
398
        headerRow.createCell(28).setCellValue("Handover Time ( 24 hrs format )");
399
 
400
        int serialNo = 0;
401
 
402
        for(AwbDetails awbDetail : awbDetailList) {
403
//          0  Airwaybill   1 Type    2 Reference Number  3 Sender / Store name 4 attention   5 address1    6 address2    7 address3    
404
//          8 pincode    9 tel number     10 mobile number   11 Prod/SKU code    12 contents    13 weight  
405
//          14 Declared Value   15 Collectable Value   
406
//          16 Vendor Code    17 Shipper Name    18 Return Address1    19 Return Address2    20 Return Address3     21 Return Pin  
407
//          22 Length ( Cms )   23 Bredth ( Cms )      24 Height ( Cms )  
408
//          25 Pieces  26 Area_customer_code  27 Handover Date ( DD/MM/YYYY )   28 Handover Time ( 24 hrs format )  
409
 
410
            serialNo++;
411
            Row contentRow = sheet.createRow((short)serialNo);
412
 
413
            contentRow.createCell(0).setCellValue(awbDetail.getAwbNumber());
414
            contentRow.createCell(1).setCellValue(awbDetail.getPaymentMode().equals("COD") ? "COD" : "NONCOD");
415
            contentRow.createCell(2).setCellValue(awbDetail.getOrderId());
416
            contentRow.createCell(3).setCellValue("Spice Online Retail Pvt Ltd");
417
            contentRow.createCell(4).setCellValue(awbDetail.getCustomerName());
418
            contentRow.createCell(5).setCellValue(awbDetail.getAddress1());
419
            contentRow.createCell(6).setCellValue(awbDetail.getAddress2());
420
            contentRow.createCell(7).setCellValue(awbDetail.getCity() + ", " + awbDetail.getState());
421
            contentRow.createCell(8).setCellValue(awbDetail.getPinCode());
422
            contentRow.createCell(9).setCellValue(awbDetail.getPhoneNumber());
423
            contentRow.createCell(10).setCellValue(awbDetail.getPhoneNumber());
424
            contentRow.createCell(11).setCellValue(awbDetail.getItemId());
425
            contentRow.createCell(12).setCellValue(awbDetail.getProductName());
426
            contentRow.createCell(13).setCellValue(awbDetail.getPacketWeight());
427
            contentRow.createCell(14).setCellValue(awbDetail.getShipmentValue());
428
            contentRow.createCell(15).setCellValue(awbDetail.getAmountToCollect());
429
            contentRow.createCell(16).setCellValue(awbDetail.getVendorCode());
430
            contentRow.createCell(17).setCellValue("Spice Online Retail Pvt Ltd");
431
            contentRow.createCell(18).setCellValue(awbDetail.getReturnAddress1());
432
            contentRow.createCell(19).setCellValue(awbDetail.getReturnAddress2());
433
            contentRow.createCell(20).setCellValue(awbDetail.getReturnAddress3());
434
            contentRow.createCell(21).setCellValue(awbDetail.getReturnPin());
435
            contentRow.createCell(22).setCellValue(CourierDetailsController.EMPTY_STRING);
436
            contentRow.createCell(23).setCellValue(CourierDetailsController.EMPTY_STRING);
437
            contentRow.createCell(24).setCellValue(CourierDetailsController.EMPTY_STRING);
438
            contentRow.createCell(25).setCellValue("1");
439
            contentRow.createCell(26).setCellValue(awbDetail.getAccountCode());
440
 
441
            Date date = null;
442
            SimpleDateFormat sdf4Date = new SimpleDateFormat("dd/MM/yyyy");                
443
            SimpleDateFormat sdf4Time = new SimpleDateFormat("HHmm");
444
 
7811 anupam.sin 445
            if(!awbDetail.getAwbDate().equals("N/A")) {
446
                try {
447
                    date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(awbDetail.getAwbDate());
448
                } catch (ParseException e) {
449
                    // TODO Auto-generated catch block
450
                    e.printStackTrace();
451
                }
452
                contentRow.createCell(27).setCellValue(sdf4Date.format(date));
453
                contentRow.createCell(28).setCellValue(sdf4Time.format(date));
454
            } else {
455
                contentRow.createCell(27).setCellValue("N/A");
456
                contentRow.createCell(28).setCellValue("N/A");
7792 anupam.sin 457
            }
458
 
459
 
7811 anupam.sin 460
 
7792 anupam.sin 461
            /**
462
             * According to javadoc of Date, Date.toString() converts a Date object to a String of the form:
463
             * 
464
                 dow mon dd hh:mm:ss zzz yyyy
465
 
466
            where:
467
 
468
             * dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
469
             * mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
470
             * dd is the day of the month (01 through 31), as two decimal digits.
471
             * hh is the hour of the day (00 through 23), as two decimal digits.
472
             * mm is the minute within the hour (00 through 59), as two decimal digits.
473
             * ss is the second within the minute (00 through 61, as two decimal digits.
474
             * zzz is the time zone (and may reflect daylight saving time). Standard time zone abbreviations include those recognized by the method parse. If time zone information is not available, then zzz is empty - that is, it consists of no characters at all.
475
             * yyyy is the year, as four decimal digits. 
476
             * 
477
             * And we need to send this in format DD/MM/YYYY and time in HHMM
478
             */
479
        }
480
 
481
        try {
482
            wb.write(baos);
483
            baos.close();
484
        } catch (IOException e) {
485
            // TODO Auto-generated catch block
486
            e.printStackTrace();
487
        }
488
	    return baos;
4386 anupam.sin 489
	}
7792 anupam.sin 490
 
4386 anupam.sin 491
 
3105 chandransh 492
    /**
4386 anupam.sin 493
	 * Sets the daysToSubtract to -2 and then invokes the standard show() handler.
494
	 * Should be used to view day before yesterday's courier details report.
495
	 * 
3105 chandransh 496
     * @return the same string tokens as show
497
     */
1075 chandransh 498
	public String dayBefore(){
499
		daysToSubtract = -2;
500
		return show();
501
	}
3105 chandransh 502
 
503
    /**
504
     * Sets the daysToSubtract to -1 and then invokes the standard show()
505
     * handler. Should be used to view yesterday's courier details report.
506
     * 
507
     * @return the same string tokens as show
508
     */
1075 chandransh 509
	public String yesterday(){
510
		daysToSubtract = -1;
511
		return show();
512
	}
3105 chandransh 513
 
514
    /**
515
     * Sets the daysToSubtract to 0 and then invokes the standard show()
516
     * handler. Should be used to view today's courier details report.
517
     * 
518
     * @return the same string tokens as show
519
     */
1075 chandransh 520
	public String today(){
521
		daysToSubtract = 0;
522
		return show();
523
	}
3364 chandransh 524
 
679 chandransh 525
	@Override
1075 chandransh 526
	public void setServletContext(ServletContext context) {
527
		this.context = context;
528
	}
529
 
530
	@Override
679 chandransh 531
	public void setServletResponse(HttpServletResponse response) {
532
		this.response  = response;
533
	}
534
 
535
	@Override
536
	public void setServletRequest(HttpServletRequest request) {
537
		this.request = request;
749 chandransh 538
		this.session = request.getSession();
679 chandransh 539
	}
540
 
749 chandransh 541
	public String getId(){
542
		return id;
543
	}
544
 
545
	public void setId(String id){
546
		this.id = id;
547
	}
548
 
549
	public String getSessionUserName(){
550
		return (String) session.getAttribute("username");
551
	}
3105 chandransh 552
 
553
    /**
554
     * Gets the list of all warehouses and maps the warehouse ids to their
555
     * display name.
556
     * 
557
     * @return the mapping of warehouse if to its display namee
558
     */
754 chandransh 559
	public Map<Long, String> getWarehouses(){
560
		Map<Long, String> warehouseMap = new HashMap<Long, String>();
561
		try{
5945 mandeep.dh 562
			InventoryClient isc = new InventoryClient();
563
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient= isc.getClient();
564
			List<Warehouse> warehouses = inventoryClient.getShippingLocations();
754 chandransh 565
			for(Warehouse warehouse : warehouses){
566
				warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
567
			}
568
		}catch(Exception e){
3105 chandransh 569
			logger.error("Error getting the list of warehouses", e);
754 chandransh 570
		}
571
		return warehouseMap;
572
	}
749 chandransh 573
 
1075 chandransh 574
	public String getServletContextPath(){
575
		return context.getContextPath();
576
	}
4386 anupam.sin 577
 
578
    public String getAwbNumbers() {
579
        return awbNumbers;
580
    }
581
 
582
    public void setAwbNumbers(String awbNumbers) {
583
        this.awbNumbers = awbNumbers;
584
    }
585
 
586
    public List<AwbDetails> getDetailedAWBs() {
587
        return detailedAWBs;
588
    }
589
 
590
    public void setDetailedAWBs(List<AwbDetails> detailedAWBs) {
591
        this.detailedAWBs = detailedAWBs;
592
    }
593
 
594
    public String getErrorMsg() {
595
        return errorMsg;
596
    }
597
 
598
    public void setErrorMsg(String errorMsg) {
599
        this.errorMsg = errorMsg;
600
    }
7792 anupam.sin 601
 
602
    public File getAwbFile() {
603
        return awbFile;
604
    }
605
 
606
    public void setAwbFile(File awbFile) {
607
        this.awbFile = awbFile;
608
    }
609
 
610
    public String getAwbFileContentType() {
611
        return awbFileContentType;
612
    }
613
 
614
    public void setAwbFileContentType(String awbFileContentType) {
615
        this.awbFileContentType = awbFileContentType;
616
    }
617
 
618
    public String getAwbFileFileName() {
619
        return awbFileFileName;
620
    }
621
 
622
    public void setAwbFileFileName(String awbFileFileName) {
623
        this.awbFileFileName = awbFileFileName;
624
    }
625
 
626
    public static void main(String[] args) {
627
//        CourierDetailsController cdc = new CourierDetailsController();
628
//        cdc.setAwbNumbers("4340987735");
629
//        String msg = cdc.getAwbDetails();
630
//        System.out.println(msg);
631
//        //58539182004
632
//        //43726980393
633
 
634
//        String string = "January 2, 2010";
635
//        Date date = null;
636
//        Calendar cal = Calendar.getInstance();
637
//        //cal.set(2014, 0, 20);
638
//        
639
//        try {
640
//            date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(cal.getTime().toString());
641
//        } catch (ParseException e) {
642
//            // TODO Auto-generated catch block
643
//            e.printStackTrace();
644
//        }
645
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
646
//        System.out.println(sdf.format(date));
647
 
648
        String[] addresses = "fjdaks\n,24/1,hello".split(",+");
649
        System.out.println(addresses[0].trim());
650
        System.out.println(addresses[1]);
651
        System.out.println(addresses[2]);
652
    }
679 chandransh 653
}