Subversion Repositories SmartDukaan

Rev

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