Subversion Repositories SmartDukaan

Rev

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