Subversion Repositories SmartDukaan

Rev

Rev 7813 | Rev 8128 | 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());
5554 rajveer 303
	            if(order.isLogisticsCod()){
7792 anupam.sin 304
	                detailedAwb.setAmountToCollect("" + (order.getTotal_amount()-order.getGvAmount()-order.getAdvanceAmount()));
4604 anupam.sin 305
	            } else {
306
	                detailedAwb.setAmountToCollect("" + 0 );
307
	            }
7811 anupam.sin 308
 
309
	            if(order.getShipping_timestamp() > 0) {
310
    	            Date date = new Date(order.getShipping_timestamp());
311
    	            detailedAwb.setAwbDate(date.toString());
312
	            } else {
313
	                detailedAwb.setAwbDate("N/A");
314
	            }
8049 anupam.sin 315
 
316
	            if(order.getPickupStoreId() > 0) {
317
	                PickupStore store = lsc.getClient().getPickupStore(order.getPickupStoreId());
318
	                detailedAwb.setAddress1(store.getLine1());
319
	                detailedAwb.setAddress2(store.getLine2());
320
	                detailedAwb.setCity(store.getCity());
321
	                detailedAwb.setCustomerName("Spice Hotspot");
322
	                detailedAwb.setPhoneNumber("" + store.getPhone());
323
	                detailedAwb.setPinCode(store.getPin());
324
	                detailedAwb.setState(store.getState());
325
	            } else {
326
	                detailedAwb.setAddress1(order.getCustomer_address1());
327
	                detailedAwb.setAddress2(order.getCustomer_address2());
328
	                detailedAwb.setCity(order.getCustomer_city());
329
	                detailedAwb.setCustomerName(order.getCustomer_name());
330
	                detailedAwb.setPhoneNumber("" + order.getCustomer_mobilenumber());
331
	                detailedAwb.setPinCode(order.getCustomer_pincode());
332
	                detailedAwb.setState(order.getCustomer_state());
333
	            }
334
 
7792 anupam.sin 335
	            detailedAwb.setItemId("" + order.getLineitems().get(0).getItem_id());
4386 anupam.sin 336
	            detailedAwb.setOrderId("" + order.getId());
337
	            detailedAwb.setPacketWeight("" + order.getTotal_weight());
5554 rajveer 338
	            if(order.isLogisticsCod()){
4386 anupam.sin 339
	                detailedAwb.setPaymentMode("COD");
340
	            } else {
341
	                detailedAwb.setPaymentMode("Prepaid");
342
	            }
343
 
8049 anupam.sin 344
 
4386 anupam.sin 345
	            detailedAwb.setPickupLocation(warehouse.getLocation());
8049 anupam.sin 346
 
4386 anupam.sin 347
	            LineItem lineitem = order.getLineitems().get(0);
7792 anupam.sin 348
	            detailedAwb.setProductName(lineitem.getBrand() + " " 
349
	                                         + (lineitem.getModel_name() == null ? "" : lineitem.getModel_name()) + " " 
350
	                                         + (lineitem.getModel_number() == null ? "" : lineitem.getModel_number()) + " " 
351
	                                         + (lineitem.getColor() == null ? "" : lineitem.getColor()));
352
	            detailedAwb.setShipmentValue("" + (order.getTotal_amount()));
4386 anupam.sin 353
 
354
	            tempList.add(detailedAwb);
3105 chandransh 355
 
4386 anupam.sin 356
	        } catch (TTransportException e) {
357
	            setErrorMsg("Your request cannot be processed due to technical error. Please try later.");
358
	        } catch (TException e) {
359
	            setErrorMsg(e.getMessage());
360
	        } catch (TransactionServiceException e) {
361
	            setErrorMsg(e.getMessage());
362
	        } catch (LogisticsServiceException e) {
363
	            setErrorMsg(e.getMessage());
364
            } catch (InventoryServiceException e) {
365
                setErrorMsg(e.getMessage());
366
            }
367
	    }
7811 anupam.sin 368
	    setDetailedAWBs(tempList);
7792 anupam.sin 369
    }
370
 
371
 
372
	public ByteArrayOutputStream generateAwbDetailsSheet(List<AwbDetails> awbDetailList) {
373
	    ByteArrayOutputStream baos = new ByteArrayOutputStream();;
374
	    Workbook wb = new HSSFWorkbook();
375
        CreationHelper createHelper = wb.getCreationHelper();
376
        Sheet sheet = wb.createSheet("Saholic - Data");
377
 
378
        CellStyle dateCellStyle = wb.createCellStyle();
379
        dateCellStyle.setDataFormat(createHelper.createDataFormat().getFormat("d/m/yyyy"));
380
 
381
        CellStyle weightStyle = wb.createCellStyle();
382
        weightStyle.setDataFormat(createHelper.createDataFormat().getFormat("0.000"));
383
 
384
        Row headerRow = sheet.createRow((short)0);
385
        headerRow.createCell(0).setCellValue("Airwaybill");
386
        headerRow.createCell(1).setCellValue("Type"); //Values : "COD" / "NONCOD"
387
        headerRow.createCell(2).setCellValue("Reference Number"); //OrderId
388
        headerRow.createCell(3).setCellValue("Sender / Store name"); //"Spice Online retail pvt ltd"
389
        headerRow.createCell(4).setCellValue("attention"); //Customer name
390
        headerRow.createCell(5).setCellValue("address1"); //Line 1
391
        headerRow.createCell(6).setCellValue("address2"); //Line 2
392
        headerRow.createCell(7).setCellValue("address3"); //city + state
393
        headerRow.createCell(8).setCellValue("pincode");
394
        headerRow.createCell(9).setCellValue("tel number"); //Empty
395
        headerRow.createCell(10).setCellValue("mobile number"); //Empty
396
        headerRow.createCell(11).setCellValue("Prod/SKU code");  //ItemId
397
        headerRow.createCell(12).setCellValue("contents"); //Product name
398
        headerRow.createCell(13).setCellValue("weight");  //In Kgs
399
        headerRow.createCell(14).setCellValue("Declared Value");  
400
        headerRow.createCell(15).setCellValue("Collectable Value");
401
        headerRow.createCell(16).setCellValue("Vendor Code");
402
        headerRow.createCell(17).setCellValue("Shipper Name");  
403
        headerRow.createCell(18).setCellValue("Return Address1");
404
        headerRow.createCell(19).setCellValue("Return Address2");
405
        headerRow.createCell(20).setCellValue("Return Address3");
406
        headerRow.createCell(21).setCellValue("Return Pin");
407
        headerRow.createCell(22).setCellValue("Length ( Cms )");
408
        headerRow.createCell(23).setCellValue("Bredth ( Cms )");
409
        headerRow.createCell(24).setCellValue("Height ( Cms )");
410
        headerRow.createCell(25).setCellValue("Pieces");       
411
        headerRow.createCell(26).setCellValue("Area_customer_code");
412
        headerRow.createCell(27).setCellValue("Handover Date ( DD/MM/YYYY )");
413
        headerRow.createCell(28).setCellValue("Handover Time ( 24 hrs format )");
414
 
415
        int serialNo = 0;
416
 
417
        for(AwbDetails awbDetail : awbDetailList) {
418
//          0  Airwaybill   1 Type    2 Reference Number  3 Sender / Store name 4 attention   5 address1    6 address2    7 address3    
419
//          8 pincode    9 tel number     10 mobile number   11 Prod/SKU code    12 contents    13 weight  
420
//          14 Declared Value   15 Collectable Value   
421
//          16 Vendor Code    17 Shipper Name    18 Return Address1    19 Return Address2    20 Return Address3     21 Return Pin  
422
//          22 Length ( Cms )   23 Bredth ( Cms )      24 Height ( Cms )  
423
//          25 Pieces  26 Area_customer_code  27 Handover Date ( DD/MM/YYYY )   28 Handover Time ( 24 hrs format )  
424
 
425
            serialNo++;
426
            Row contentRow = sheet.createRow((short)serialNo);
427
 
428
            contentRow.createCell(0).setCellValue(awbDetail.getAwbNumber());
429
            contentRow.createCell(1).setCellValue(awbDetail.getPaymentMode().equals("COD") ? "COD" : "NONCOD");
430
            contentRow.createCell(2).setCellValue(awbDetail.getOrderId());
431
            contentRow.createCell(3).setCellValue("Spice Online Retail Pvt Ltd");
432
            contentRow.createCell(4).setCellValue(awbDetail.getCustomerName());
433
            contentRow.createCell(5).setCellValue(awbDetail.getAddress1());
434
            contentRow.createCell(6).setCellValue(awbDetail.getAddress2());
435
            contentRow.createCell(7).setCellValue(awbDetail.getCity() + ", " + awbDetail.getState());
436
            contentRow.createCell(8).setCellValue(awbDetail.getPinCode());
437
            contentRow.createCell(9).setCellValue(awbDetail.getPhoneNumber());
438
            contentRow.createCell(10).setCellValue(awbDetail.getPhoneNumber());
439
            contentRow.createCell(11).setCellValue(awbDetail.getItemId());
440
            contentRow.createCell(12).setCellValue(awbDetail.getProductName());
441
            contentRow.createCell(13).setCellValue(awbDetail.getPacketWeight());
442
            contentRow.createCell(14).setCellValue(awbDetail.getShipmentValue());
443
            contentRow.createCell(15).setCellValue(awbDetail.getAmountToCollect());
444
            contentRow.createCell(16).setCellValue(awbDetail.getVendorCode());
445
            contentRow.createCell(17).setCellValue("Spice Online Retail Pvt Ltd");
446
            contentRow.createCell(18).setCellValue(awbDetail.getReturnAddress1());
447
            contentRow.createCell(19).setCellValue(awbDetail.getReturnAddress2());
448
            contentRow.createCell(20).setCellValue(awbDetail.getReturnAddress3());
449
            contentRow.createCell(21).setCellValue(awbDetail.getReturnPin());
450
            contentRow.createCell(22).setCellValue(CourierDetailsController.EMPTY_STRING);
451
            contentRow.createCell(23).setCellValue(CourierDetailsController.EMPTY_STRING);
452
            contentRow.createCell(24).setCellValue(CourierDetailsController.EMPTY_STRING);
453
            contentRow.createCell(25).setCellValue("1");
454
            contentRow.createCell(26).setCellValue(awbDetail.getAccountCode());
455
 
456
            Date date = null;
457
            SimpleDateFormat sdf4Date = new SimpleDateFormat("dd/MM/yyyy");                
458
            SimpleDateFormat sdf4Time = new SimpleDateFormat("HHmm");
459
 
7811 anupam.sin 460
            if(!awbDetail.getAwbDate().equals("N/A")) {
461
                try {
462
                    date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(awbDetail.getAwbDate());
463
                } catch (ParseException e) {
464
                    // TODO Auto-generated catch block
465
                    e.printStackTrace();
466
                }
467
                contentRow.createCell(27).setCellValue(sdf4Date.format(date));
468
                contentRow.createCell(28).setCellValue(sdf4Time.format(date));
469
            } else {
470
                contentRow.createCell(27).setCellValue("N/A");
471
                contentRow.createCell(28).setCellValue("N/A");
7792 anupam.sin 472
            }
473
 
474
 
7811 anupam.sin 475
 
7792 anupam.sin 476
            /**
477
             * According to javadoc of Date, Date.toString() converts a Date object to a String of the form:
478
             * 
479
                 dow mon dd hh:mm:ss zzz yyyy
480
 
481
            where:
482
 
483
             * dow is the day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
484
             * mon is the month (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec).
485
             * dd is the day of the month (01 through 31), as two decimal digits.
486
             * hh is the hour of the day (00 through 23), as two decimal digits.
487
             * mm is the minute within the hour (00 through 59), as two decimal digits.
488
             * ss is the second within the minute (00 through 61, as two decimal digits.
489
             * 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.
490
             * yyyy is the year, as four decimal digits. 
491
             * 
492
             * And we need to send this in format DD/MM/YYYY and time in HHMM
493
             */
494
        }
495
 
496
        try {
497
            wb.write(baos);
498
            baos.close();
499
        } catch (IOException e) {
500
            // TODO Auto-generated catch block
501
            e.printStackTrace();
502
        }
503
	    return baos;
4386 anupam.sin 504
	}
7792 anupam.sin 505
 
4386 anupam.sin 506
 
3105 chandransh 507
    /**
4386 anupam.sin 508
	 * Sets the daysToSubtract to -2 and then invokes the standard show() handler.
509
	 * Should be used to view day before yesterday's courier details report.
510
	 * 
3105 chandransh 511
     * @return the same string tokens as show
512
     */
1075 chandransh 513
	public String dayBefore(){
514
		daysToSubtract = -2;
515
		return show();
516
	}
3105 chandransh 517
 
518
    /**
519
     * Sets the daysToSubtract to -1 and then invokes the standard show()
520
     * handler. Should be used to view yesterday's courier details report.
521
     * 
522
     * @return the same string tokens as show
523
     */
1075 chandransh 524
	public String yesterday(){
525
		daysToSubtract = -1;
526
		return show();
527
	}
3105 chandransh 528
 
529
    /**
530
     * Sets the daysToSubtract to 0 and then invokes the standard show()
531
     * handler. Should be used to view today's courier details report.
532
     * 
533
     * @return the same string tokens as show
534
     */
1075 chandransh 535
	public String today(){
536
		daysToSubtract = 0;
537
		return show();
538
	}
3364 chandransh 539
 
679 chandransh 540
	@Override
1075 chandransh 541
	public void setServletContext(ServletContext context) {
542
		this.context = context;
543
	}
544
 
545
	@Override
679 chandransh 546
	public void setServletResponse(HttpServletResponse response) {
547
		this.response  = response;
548
	}
549
 
550
	@Override
551
	public void setServletRequest(HttpServletRequest request) {
552
		this.request = request;
749 chandransh 553
		this.session = request.getSession();
679 chandransh 554
	}
555
 
749 chandransh 556
	public String getId(){
557
		return id;
558
	}
559
 
560
	public void setId(String id){
561
		this.id = id;
562
	}
563
 
564
	public String getSessionUserName(){
565
		return (String) session.getAttribute("username");
566
	}
3105 chandransh 567
 
568
    /**
569
     * Gets the list of all warehouses and maps the warehouse ids to their
570
     * display name.
571
     * 
572
     * @return the mapping of warehouse if to its display namee
573
     */
754 chandransh 574
	public Map<Long, String> getWarehouses(){
575
		Map<Long, String> warehouseMap = new HashMap<Long, String>();
576
		try{
5945 mandeep.dh 577
			InventoryClient isc = new InventoryClient();
578
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient= isc.getClient();
579
			List<Warehouse> warehouses = inventoryClient.getShippingLocations();
754 chandransh 580
			for(Warehouse warehouse : warehouses){
581
				warehouseMap.put(warehouse.getId(), warehouse.getDisplayName());
582
			}
583
		}catch(Exception e){
3105 chandransh 584
			logger.error("Error getting the list of warehouses", e);
754 chandransh 585
		}
586
		return warehouseMap;
587
	}
749 chandransh 588
 
1075 chandransh 589
	public String getServletContextPath(){
590
		return context.getContextPath();
591
	}
4386 anupam.sin 592
 
593
    public String getAwbNumbers() {
594
        return awbNumbers;
595
    }
596
 
597
    public void setAwbNumbers(String awbNumbers) {
598
        this.awbNumbers = awbNumbers;
599
    }
600
 
601
    public List<AwbDetails> getDetailedAWBs() {
602
        return detailedAWBs;
603
    }
604
 
605
    public void setDetailedAWBs(List<AwbDetails> detailedAWBs) {
606
        this.detailedAWBs = detailedAWBs;
607
    }
608
 
609
    public String getErrorMsg() {
610
        return errorMsg;
611
    }
612
 
613
    public void setErrorMsg(String errorMsg) {
614
        this.errorMsg = errorMsg;
615
    }
7792 anupam.sin 616
 
617
    public File getAwbFile() {
618
        return awbFile;
619
    }
620
 
621
    public void setAwbFile(File awbFile) {
622
        this.awbFile = awbFile;
623
    }
624
 
625
    public String getAwbFileContentType() {
626
        return awbFileContentType;
627
    }
628
 
629
    public void setAwbFileContentType(String awbFileContentType) {
630
        this.awbFileContentType = awbFileContentType;
631
    }
632
 
633
    public String getAwbFileFileName() {
634
        return awbFileFileName;
635
    }
636
 
637
    public void setAwbFileFileName(String awbFileFileName) {
638
        this.awbFileFileName = awbFileFileName;
639
    }
640
 
641
    public static void main(String[] args) {
642
//        CourierDetailsController cdc = new CourierDetailsController();
643
//        cdc.setAwbNumbers("4340987735");
644
//        String msg = cdc.getAwbDetails();
645
//        System.out.println(msg);
646
//        //58539182004
647
//        //43726980393
648
 
649
//        String string = "January 2, 2010";
650
//        Date date = null;
651
//        Calendar cal = Calendar.getInstance();
652
//        //cal.set(2014, 0, 20);
653
//        
654
//        try {
655
//            date = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy").parse(cal.getTime().toString());
656
//        } catch (ParseException e) {
657
//            // TODO Auto-generated catch block
658
//            e.printStackTrace();
659
//        }
660
//        SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");
661
//        System.out.println(sdf.format(date));
662
 
663
        String[] addresses = "fjdaks\n,24/1,hello".split(",+");
664
        System.out.println(addresses[0].trim());
665
        System.out.println(addresses[1]);
666
        System.out.println(addresses[2]);
667
    }
679 chandransh 668
}