Subversion Repositories SmartDukaan

Rev

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