Subversion Repositories SmartDukaan

Rev

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