Subversion Repositories SmartDukaan

Rev

Rev 12932 | Rev 13956 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7410 amar.kumar 1
package in.shop2020.inventory.controllers;
2
 
7452 amar.kumar 3
import in.shop2020.inventory.controllers.PurchaseController.ScanRecordType;
7410 amar.kumar 4
import in.shop2020.model.v1.catalog.CatalogService;
5
import in.shop2020.model.v1.catalog.CatalogServiceException;
6
import in.shop2020.model.v1.catalog.Item;
7
import in.shop2020.model.v1.catalog.ItemType;
7452 amar.kumar 8
import in.shop2020.model.v1.inventory.InventoryServiceException;
9
import in.shop2020.model.v1.inventory.Vendor;
7451 amar.kumar 10
import in.shop2020.model.v1.inventory.InventoryService.Client;
7410 amar.kumar 11
import in.shop2020.model.v1.inventory.Warehouse;
12
import in.shop2020.model.v1.inventory.WarehouseType;
13
import in.shop2020.model.v1.order.LineItem;
7452 amar.kumar 14
import in.shop2020.purchase.PurchaseReturn;
15
import in.shop2020.purchase.PurchaseServiceException;
7410 amar.kumar 16
import in.shop2020.thrift.clients.CatalogClient;
17
import in.shop2020.thrift.clients.InventoryClient;
7452 amar.kumar 18
import in.shop2020.thrift.clients.PurchaseClient;
7410 amar.kumar 19
import in.shop2020.thrift.clients.WarehouseClient;
20
import in.shop2020.warehouse.InventoryItem;
7452 amar.kumar 21
import in.shop2020.warehouse.Scan;
7410 amar.kumar 22
import in.shop2020.warehouse.ScanType;
23
import in.shop2020.warehouse.TransferLot;
10121 manish.sha 24
import in.shop2020.warehouse.TransferLotStatus;
7410 amar.kumar 25
import in.shop2020.warehouse.WarehouseService;
26
import in.shop2020.warehouse.WarehouseServiceException;
27
 
7451 amar.kumar 28
import java.io.BufferedInputStream;
29
import java.io.ByteArrayOutputStream;
30
import java.io.File;
31
import java.io.FileInputStream;
32
import java.io.FileNotFoundException;
33
import java.io.FileOutputStream;
34
import java.io.IOException;
35
import java.io.InputStream;
7452 amar.kumar 36
import java.text.DateFormat;
7410 amar.kumar 37
import java.text.ParseException;
38
import java.text.SimpleDateFormat;
39
import java.util.Calendar;
7451 amar.kumar 40
import java.util.Date;
7410 amar.kumar 41
import java.util.HashMap;
10121 manish.sha 42
import java.util.HashSet;
7452 amar.kumar 43
import java.util.Hashtable;
7410 amar.kumar 44
import java.util.List;
45
import java.util.Map;
46
import java.util.Map.Entry;
7452 amar.kumar 47
import java.util.Set;
48
import java.util.ArrayList;
7410 amar.kumar 49
 
7451 amar.kumar 50
import javax.servlet.ServletOutputStream;
51
 
52
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
53
import org.apache.poi.ss.usermodel.Row;
54
import org.apache.poi.ss.usermodel.Sheet;
55
import org.apache.poi.ss.usermodel.Workbook;
7410 amar.kumar 56
import org.apache.thrift.TException;
57
import org.apache.thrift.transport.TTransportException;
10121 manish.sha 58
import org.json.JSONObject;
7410 amar.kumar 59
import org.slf4j.Logger;
60
import org.slf4j.LoggerFactory;
61
 
62
public class TransferLotController extends BaseController{
63
 
64
	/**
65
	 * 
66
	 */
67
	private static final long serialVersionUID = 3052114881399915348L;
68
 
69
	private Long id;
70
	private TransferLot transferLot;
71
	private List<TransferLot>transferLots;
72
	private String remoteTransferRefNumber;
73
	private String fromDate;
74
	private String toDate;
75
	private String errorMessage = "";
76
	private Calendar transferLotFromDate;
77
	private Calendar transferLotToDate;
78
	private Long originWarehouseId;
79
	private List<LineItem> lineItems;
80
	private Long destinationWarehouseId;
10121 manish.sha 81
	private String inventoryItemsString;
82
	private JSONObject jsonTransferLotItemData = null;
83
	private String inventoryItemsLength;
84
	private String transferLotReceiveType;
7410 amar.kumar 85
 
86
	private String output;
87
	private static Map<Long, Warehouse> warehouseMap;
88
 
89
	private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
90
 
10121 manish.sha 91
	private static long totalItemsSizeInTransferLot;
92
	private static boolean isCompleteTransferAvailable = false;
7410 amar.kumar 93
    private static Logger logger = LoggerFactory.getLogger(TransferLotController.class);
94
 
95
    static {
96
		warehouseMap = new HashMap<Long, Warehouse>();
97
		InventoryClient inventoryServiceClient;
98
		try {
99
			inventoryServiceClient = new InventoryClient();
100
	        Client inventoryClient = inventoryServiceClient.getClient();
101
	        List<Warehouse> warehouses;
102
			warehouses = inventoryClient.getAllWarehouses(true);
103
	        for(Warehouse warehouse : warehouses){
104
	        	warehouseMap.put(warehouse.getId(), warehouse);
105
	        }
106
		} catch (TTransportException e) {
107
			logger.error("Error in populating warehouse map", e);
108
		} catch (TException e) {
109
			logger.error("Error in populating warehouse map", e);
110
		} catch (InventoryServiceException isex) {
111
			logger.error("Error in populating warehouse map", isex);
112
		}
113
	}
114
 
115
	public String index(){
116
		if(warehouseMap==null||warehouseMap.size()<1){
7448 amar.kumar 117
			fetchWarehouseMap();
7410 amar.kumar 118
		}
119
		try{
120
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
121
			transferLotFromDate = Calendar.getInstance();
122
			transferLotToDate = Calendar.getInstance();
123
			if(fromDate==null) {
11769 manish.sha 124
				transferLotFromDate.add(Calendar.MONTH, -12);
7410 amar.kumar 125
			} else {
126
				transferLotFromDate.setTime(formatter.parse(fromDate));
127
				if(toDate!=null) {
128
					transferLotToDate.setTime(formatter.parse(toDate));
129
				}
130
			}
13940 manish.sha 131
			List<TransferLot> allTransferLots = warehouseClient.getTransferLotsByDate(transferLotFromDate.getTimeInMillis(), transferLotToDate.getTimeInMillis());
132
			for(TransferLot transferLot: allTransferLots){
133
				if(transferLot.getStatus()!=TransferLotStatus.TRANSFER_COMPLETE){
134
					transferLots.add(transferLot);
135
				}
136
			}
137
			//transferLots = warehouseClient.getTransferLotsByDate(transferLotFromDate.getTimeInMillis(), transferLotToDate.getTimeInMillis());
7410 amar.kumar 138
		} catch(TException e){
139
			logger.error("Error in getting transfer lots", e);
140
		} catch(ParseException pex) {
141
			logger.error("Error in parsing time", pex);
142
		} catch(WarehouseServiceException wsex) {
143
			logger.error("Error in getting transfer lots", wsex);
144
		}
145
		return INDEX;
146
	}
147
 
7448 amar.kumar 148
    private void fetchWarehouseMap() {
149
    	warehouseMap = new HashMap<Long, Warehouse>();
150
		InventoryClient inventoryServiceClient;
151
		try {
152
			inventoryServiceClient = new InventoryClient();
153
	        Client inventoryClient = inventoryServiceClient.getClient();
154
	        List<Warehouse> warehouses;
155
			warehouses = inventoryClient.getAllWarehouses(true);
156
	        for(Warehouse warehouse : warehouses){
157
	        	warehouseMap.put(warehouse.getId(), warehouse);
158
	        }
159
		} catch (TTransportException e) {
160
			logger.error("Error in populating warehouse map", e);
161
		} catch (TException e) {
162
			logger.error("Error in populating warehouse map", e);
163
		} catch (InventoryServiceException isex) {
164
			logger.error("Error in populating warehouse map", isex);
165
		}
166
	}
167
 
168
	public String create() {
7410 amar.kumar 169
    	originWarehouseId = Long.parseLong(request.getParameter("originWarehouseId"));
170
    	destinationWarehouseId = Long.parseLong(request.getParameter("destinationWarehouseId"));
171
    	try {
172
	    	WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
173
	        id = warehouseClient.createTransferLot(originWarehouseId, destinationWarehouseId);
174
    	} catch (TException tex) {
175
    		logger.error("Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId, tex);
176
    		errorMessage = "Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId;
177
    	} catch (WarehouseServiceException wex) {
178
    		logger.error("Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId, wex);
179
    		errorMessage = "Error in creating transferlot between warehouseId " + originWarehouseId + " and " + destinationWarehouseId;
180
    	}
181
        return show();
182
    }
183
 
184
	public String show(){
185
		resetLineItems();
186
		return SHOW;
187
	}
188
	public String update() {
189
		try {
190
			if(!areValidScans()){
191
				errorMessage = "Invalid Scans";
192
				return show();
193
			}
194
			if(id == null || id==0) {
195
	            	errorMessage = "No transferLot-Id selected for Transfer";
196
	        		return "new";
197
	        }
198
			List<InventoryItem> inventoryItems = new ArrayList<InventoryItem>();
199
			CatalogService.Client catalogClient = new CatalogClient().getClient();
200
			for (LineItem lineItem : lineItems) {
201
                if (lineItem.getItem_id() == 0) {
202
                    continue;
203
                }
204
                InventoryItem inventoryItem = new InventoryItem();
205
                inventoryItem.setItemId(lineItem.getItem_id());
206
                inventoryItem.setCurrentQuantity(new Double(lineItem.getQuantity()).longValue());
207
                inventoryItem.setItemNumber(lineItem.getItem_number());
208
                if(catalogClient.getItem(lineItem.getItem_id()).getType()==ItemType.SERIALIZED) {
209
                	inventoryItem.setSerialNumber(lineItem.getSerial_number());
210
                }
211
                inventoryItems.add(inventoryItem);
212
            }
213
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
7448 amar.kumar 214
			warehouseClient.scanForTransferOut(inventoryItems, ScanType.WAREHOUSE_TRANSFER_OUT, id);
7410 amar.kumar 215
		} catch (TTransportException e) {
216
            errorMessage = "Error while establishing connection to the warehouse server";
217
            logger.error(errorMessage, e);
218
        } catch (WarehouseServiceException e) {
219
        	errorMessage = e.getMessage();
220
            logger.error(errorMessage, e);
221
        } catch (TException e) {
222
        	errorMessage = "Error while scanning in the item";
223
            logger.error(errorMessage, e);
224
        } catch (CatalogServiceException csex) {
225
        	errorMessage = "Error while getting the serialized details of item";
226
            logger.error(errorMessage, csex);
227
        }
228
        return show();
229
	}
230
 
231
	public String editNew(){
232
		return "new";
233
	}
234
 
235
	private boolean areValidScans() throws NumberFormatException, TException {
236
        boolean areValidScans = true;
237
        return areValidScans;
238
	}
239
 
240
	private void resetLineItems() {
241
        lineItems = new ArrayList<LineItem>();
242
 
243
        for (int i = 0; i < 11; i++) {
244
            LineItem lineItem = new LineItem();
245
            lineItem.setId(i);
246
            lineItem.setExtra_info("");
247
            lineItem.setSerial_number("");
248
            lineItem.setItem_number("");
249
            lineItem.setQuantity(1);
250
            lineItem.setItem_id(-1);
251
            lineItems.add(lineItem);
252
        }
253
    }
254
 
255
	public String getTransferLotItems() {
256
		try {
257
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
258
			Map<Long, Long> transferLotItems = warehouseClient.getItemsInTransferLot(id);
259
			CatalogService.Client catalogClient = new CatalogClient().getClient();
260
			String transferLotItemDiv = "<div id = 'transfer-lot-item-list-div' align='center'><table id = 'transfer-lot-item-list-table'><tr><th>Item</th><th>Quantity</th></tr>";
261
			for(Long itemId : transferLotItems.keySet()){
262
				Item item = catalogClient.getItem(itemId);
263
				transferLotItemDiv = transferLotItemDiv + "<tr><td>" + item.getBrand() + " " + item.getModelName() + " " + item.getModelNumber() + " " + item.getColor();
264
				transferLotItemDiv = transferLotItemDiv  + "</td><td>" + transferLotItems.get(itemId) +"</td></tr>";
265
			}
266
			transferLotItemDiv = transferLotItemDiv + "</table></div>";
267
			setOutput(transferLotItemDiv);
268
		} catch (TException tex) {
7451 amar.kumar 269
			logger.error("Error in getting transfer lot items",tex);
7410 amar.kumar 270
		} catch (CatalogServiceException csex) {
7451 amar.kumar 271
			logger.error("Error in getting transfer lot items",csex);
7410 amar.kumar 272
		}
273
		return OUTPUT;
274
	}
10121 manish.sha 275
 
276
	public String getTransferLotItemsForMarkReceive(){
277
		try{
278
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
279
			List<InventoryItem> inventoryItems = warehouseClient.getTransferLotItemsForMarkReceive(id, ScanType.WAREHOUSE_TRANSFER_OUT);
280
			CatalogService.Client catalogClient = new CatalogClient().getClient();
281
			Set<Long> itemIdSet = new HashSet<Long>();
282
			Map<Long,Map<String,String>> itemDataMap = new HashMap<Long,Map<String,String>>();
283
			Map<String,List<Map<String,String>>> jsonDataMap = new HashMap<String,List<Map<String,String>>>();
284
			List<Map<String,String>> jsonDataList = new ArrayList<Map<String,String>>();
285
			//long quantity = 0;
286
			for(InventoryItem item : inventoryItems){
287
				itemIdSet.add(item.getItemId());
288
			}
289
			for(Long id : itemIdSet){
290
				Item catalogItem = catalogClient.getItem(id);
291
				Map<String,String> itemdetailsMap = new HashMap<String,String>();
292
				itemdetailsMap.put("Name", catalogItem.getBrand() + " " + catalogItem.getModelName() + " " + catalogItem.getModelNumber() + " " + catalogItem.getColor());
293
				itemdetailsMap.put("Type", catalogItem.getType().name());
294
				itemDataMap.put(id,itemdetailsMap);
295
			}
296
			for(InventoryItem item : inventoryItems){
297
				Map<String,String> dataMap = new HashMap<String,String>();
298
				ItemType type = ItemType.valueOf(itemDataMap.get(item.getItemId()).get("Type"));
299
				dataMap.put("ItemId",item.getId()+"");
300
				if(ItemType.SERIALIZED == type){
301
					dataMap.put("ItemDetail",itemDataMap.get(item.getItemId()).get("Name") +"-"+ item.getSerialNumber()+"-Units("+item.getInitialQuantity()+")");
302
				}
303
				else{
12932 manish.sha 304
					dataMap.put("ItemDetail",itemDataMap.get(item.getItemId()).get("Name") +"-"+ item.getItemNumber()+"-Units("+item.getCurrentQuantity()+")");
10121 manish.sha 305
				}
306
				TransferLotStatus transferLotStatus = item.getTransferStatus();
307
				if(TransferLotStatus.IN_TRANSIT == transferLotStatus){
308
					dataMap.put("ItemStatus","Enabled");
309
				}
310
				else{
311
					dataMap.put("ItemStatus","Disabled");
312
				}
313
				//quantity = quantity + item.getInitialQuantity();
314
				jsonDataList.add(dataMap);
315
 
316
			}
317
			totalItemsSizeInTransferLot= inventoryItems.size();
318
			jsonDataMap.put("TransferLotItemData", jsonDataList);
319
 
320
			setJsonTransferLotItemData(new JSONObject(jsonDataMap));
321
 
322
		} catch(Exception e){
323
			logger.error("Error While getting Transfer Lot Items for Mark Receive",e);
324
		}
325
		return OUTPUT;
326
	}
7410 amar.kumar 327
 
328
	public String markTransferLotAsReceived() throws Exception {
329
		try{
330
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
331
			warehouseClient.markItemsAsReceivedForTransferLot(id);
332
			warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
333
		} catch(TException e){
334
			logger.error("Error in marking transfer lot as received",e);
335
			throw new Exception("Error in marking transfer lot as received");
336
		} catch(WarehouseServiceException wsex) {
337
			logger.error("Error in marking transfer lot as received",wsex);
338
			throw new Exception("Error in marking transfer lot as received");
339
		}
340
		return INDEX;
341
	}
342
 
10121 manish.sha 343
	public String markTransferLotAsReceivedPartial() throws Exception {
344
		try{
345
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
346
			TransferLot transferLot = warehouseClient.getTransferLot(id);
347
			if(transferLot.getTransitCompletionReferenceNumber()!=null && !("").equalsIgnoreCase(transferLot.getTransitCompletionReferenceNumber())){
348
				remoteTransferRefNumber = transferLot.getTransitCompletionReferenceNumber()+":"+remoteTransferRefNumber;
349
			}
350
			if("complete".equalsIgnoreCase(transferLotReceiveType)){
351
 
352
				System.out.println("In Transfer Complete Block");				
353
 
354
				if (TransferLotStatus.IN_TRANSIT.equals(transferLot.getStatus())){
355
					if(!warehouseClient.isAlive()){
356
						warehouseClient = new WarehouseClient().getClient();
357
					}
358
					warehouseClient.markItemsAsReceivedForTransferLot(id);
359
					warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
360
				}
361
				if (TransferLotStatus.PARTIAL_TRANSFER.equals(transferLot.getStatus())){
362
					String[] inventoryItemsArr = inventoryItemsString.split(",");
363
					//System.out.println("inventoryItemsArr Length... "+inventoryItemsArr.length);
364
 
365
					List<InventoryItem> inventoryItemList = new ArrayList<InventoryItem>();
366
					for(String inventItemStr : inventoryItemsArr){
367
						if(!warehouseClient.isAlive()){
368
							warehouseClient = new WarehouseClient().getClient();
369
						}
370
						InventoryItem item = warehouseClient.getInventoryItemFromId(Long.parseLong(inventItemStr));
371
						inventoryItemList.add(item);
372
					}
373
					if(!warehouseClient.isAlive()){
374
						warehouseClient = new WarehouseClient().getClient();
375
					}
376
					warehouseClient.markItemsAsReceivedForTransferLotPartial(inventoryItemList,id);
377
					warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
378
				}
379
			}
380
			else{
381
				List<InventoryItem> inventoryItemsScannedIn = warehouseClient.getTransferLotItemsForMarkReceive(id,ScanType.WAREHOUSE_TRANSFER_IN);
382
				System.out.println("totalItemsSizeInTransferLot....."+totalItemsSizeInTransferLot);
383
				int totalItemsSizeScannedIn = inventoryItemsScannedIn.size();
384
				int totalItemsSizeToBeScanIn = Integer.parseInt(inventoryItemsLength);
385
				System.out.println("totalItemsSizeScannedIn....."+totalItemsSizeScannedIn);
386
				System.out.println("totalItemsSizeToBeScanIn....."+totalItemsSizeToBeScanIn);
387
 
388
				String[] inventoryItemsArr = inventoryItemsString.split(",");
389
				System.out.println("inventoryItemsArr Length... "+inventoryItemsArr.length);
390
 
391
				List<InventoryItem> inventoryItemList = new ArrayList<InventoryItem>();
392
				for(String inventItemStr : inventoryItemsArr){
393
					if(!warehouseClient.isAlive()){
394
						warehouseClient = new WarehouseClient().getClient();
395
					}
396
					InventoryItem item = warehouseClient.getInventoryItemFromId(Long.parseLong(inventItemStr));
397
					inventoryItemList.add(item);
398
				}
399
				if(totalItemsSizeToBeScanIn==totalItemsSizeInTransferLot){
400
					System.out.println("Transfer Complete");
401
					if(!warehouseClient.isAlive()){
402
						warehouseClient = new WarehouseClient().getClient();
403
					}
404
					warehouseClient.markItemsAsReceivedForTransferLot(id);
405
					warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
406
				}
407
				if(totalItemsSizeInTransferLot== (totalItemsSizeScannedIn + totalItemsSizeToBeScanIn)){
408
					System.out.println("Transfer Complete.... from Partial");
409
					if(!warehouseClient.isAlive()){
410
						warehouseClient = new WarehouseClient().getClient();
411
					}
412
					warehouseClient.markItemsAsReceivedForTransferLotPartial(inventoryItemList,id);
413
					warehouseClient.markTransferLotAsReceived(id, remoteTransferRefNumber);
414
				}
415
				if(totalItemsSizeToBeScanIn<totalItemsSizeInTransferLot){
416
					System.out.println("Items and Transfer Lot Partial");
417
					if(!warehouseClient.isAlive()){
418
						warehouseClient = new WarehouseClient().getClient();
419
					}
420
					warehouseClient.markItemsAsReceivedForTransferLotPartial(inventoryItemList,id);
421
					warehouseClient.markTransferLotAsReceivedPartial(id, remoteTransferRefNumber);
422
				}
423
			}			
424
 
425
		} catch(Exception e){
426
			logger.error("Error in marking transfer lot as received",e);
427
			throw new Exception("Error in marking transfer lot as received");
428
		}
429
		return INDEX;
430
	}
431
 
7451 amar.kumar 432
	public void downloadFBASheet() {
433
		try {
434
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
435
			Map<Long, Long> transferLotItems = warehouseClient.getItemsInTransferLot(id);
436
 
7588 amar.kumar 437
			File fbaSheetFile = new File("transfer-lot-"+id+"-sheet_"+new Date() + ".xls");
7451 amar.kumar 438
			FileOutputStream fStream = null;
439
			try {
440
				fStream = new FileOutputStream(fbaSheetFile);
441
			} catch (FileNotFoundException e1) {
442
				logger.error(e1.getMessage());
443
			}
444
	    	ByteArrayOutputStream baosXLS = new ByteArrayOutputStream();
445
		    Workbook wb = new HSSFWorkbook();
446
		    Sheet fbaSheet = wb.createSheet("FBA Sheet");
447
 
448
		    Row merchantShipmentName = fbaSheet.createRow((short)0);
449
		    merchantShipmentName.createCell(0).setCellValue("MerchantShipmentName");
450
		    Row labelPrepPreference = fbaSheet.createRow((short)1);
451
		    labelPrepPreference.createCell(0).setCellValue("LabelPrepPreference");
452
		    Row addressName = fbaSheet.createRow((short)2);
453
		    addressName.createCell(0).setCellValue("AddressName");
454
		    Row addressFieldOne = fbaSheet.createRow((short)3);
455
		    addressFieldOne.createCell(0).setCellValue("AddressFieldOne");
456
		    Row addressFieldTwo = fbaSheet.createRow((short)4);
457
		    addressFieldTwo.createCell(0).setCellValue("AddressFieldTwo");
458
		    Row addressCity = fbaSheet.createRow((short)5);
459
		    addressCity.createCell(0).setCellValue("AddressCity");
460
		    Row addressCountryCode = fbaSheet.createRow((short)6);
461
		    addressCountryCode.createCell(0).setCellValue("AddressCountryCode");
462
		    Row addressStateOrRegion = fbaSheet.createRow((short)7);
463
		    addressStateOrRegion.createCell(0).setCellValue("AddressStateOrRegion");
464
		    Row addressPostalCode = fbaSheet.createRow((short)8);
465
		    addressPostalCode.createCell(0).setCellValue("AddressPostalCode");
466
		    Row addressDistrict = fbaSheet.createRow((short)9);
467
		    addressDistrict.createCell(0).setCellValue("AddressDistrict");
468
 
469
		    Row blankRow = fbaSheet.createRow((short)10);
470
		    //blankRow.createCell(0).setCellValue("AddressPostalCode");
471
 
472
		    Row skuHeaders = fbaSheet.createRow((short)11);
473
		    skuHeaders.createCell(0).setCellValue("MerchantSKU");
474
		    skuHeaders.createCell(1).setCellValue("Quantity");
475
 
476
		    int rowCount = 12;
477
		    for(Entry<Long, Long> itemQuantity : transferLotItems.entrySet()) {
478
		    	Row newRow = fbaSheet.createRow((short)rowCount);
479
		    	newRow.createCell(0).setCellValue("FBA"+itemQuantity.getKey());
480
			    newRow.createCell(1).setCellValue(itemQuantity.getValue());
481
			    rowCount++;
482
		    }
483
 
484
		    try {
485
			    wb.write(baosXLS);
486
			    baosXLS.close();
487
			    baosXLS.writeTo(fStream);
488
			    fStream.flush();
489
				fStream.close();
490
		    } catch(IOException e) {
491
		    	//TODO
492
		    }
493
		    byte[] buffer = null;
494
            buffer = new byte[(int) fbaSheetFile.length()];
495
            InputStream input = null;
496
            try {
497
                int totalBytesRead = 0;
498
                input = new BufferedInputStream(new FileInputStream(fbaSheetFile));
499
                while (totalBytesRead < buffer.length) {
500
                    int bytesRemaining = buffer.length - totalBytesRead;
501
                    // input.read() returns -1, 0, or more :
502
                    int bytesRead = input.read(buffer, totalBytesRead,
503
                            bytesRemaining);
504
                    if (bytesRead > 0) {
505
                        totalBytesRead = totalBytesRead + bytesRead;
506
                    }
507
                }
508
 
509
                 /* the above style is a bit tricky: it places bytes into the
510
                 * 'buffer' array; 'buffer' is an output parameter; the while
511
                 * loop usually has a single iteration only.*/
512
 
513
            } finally {
514
                input.close();
515
            }
516
 
517
            response.setContentType("application/vnd.ms-excel");
7588 amar.kumar 518
            response.setHeader("Content-disposition", "attachment; filename="
7451 amar.kumar 519
                    + fbaSheetFile.getName());
520
 
521
            ServletOutputStream sos = response.getOutputStream();
522
            sos.write(buffer);
523
            sos.flush();
524
 
525
		} catch (TException tex) {
526
			logger.error("Error in generating fba sheet for transfer Lot Id " + id,tex);
527
		}  catch (FileNotFoundException fnfex) {
528
			logger.error("Error in generating fba sheet for transfer Lot Id " + id,fnfex);
529
		} catch (IOException ioex) {
530
			logger.error("Error in generating fba sheet for transfer Lot Id " + id,ioex);
531
		}
532
 
533
	}
534
 
7410 amar.kumar 535
	public String getWarehouseName(Long warehouseId){
536
		return warehouseMap.get(warehouseId).getDisplayName();
537
	}
538
 
539
	public boolean isTransferReceivable(TransferLot transferLot) {
540
		if(warehouseMap.get(transferLot.getDestinationWarehouseId()).getWarehouseType()==WarehouseType.OURS_THIRDPARTY||
541
				warehouseMap.get(transferLot.getDestinationWarehouseId()).getWarehouseType()==WarehouseType.THIRD_PARTY) {
542
			return false;
543
		} else {
544
			return true;
545
		}
546
	}
547
 
548
 
549
 
550
 
551
	public String getDateTime(long milliseconds) {
552
        Calendar cal = Calendar.getInstance();
553
        cal.setTimeInMillis(milliseconds);
554
        return formatter.format(cal.getTime());
555
    }
556
 
557
	public static void setWarehouseMap(Map<Long, Warehouse> warehouseMap) {
558
		TransferLotController.warehouseMap = warehouseMap;
559
	}
560
 
561
	public TransferLot getTransferLot() {
562
		return transferLot;
563
	}
564
 
565
	public void setTransferLot(TransferLot transferLot) {
566
		this.transferLot = transferLot;
567
	}
568
 
569
	public List<TransferLot> getTransferLots() {
570
		return transferLots;
571
	}
572
 
573
	public void setTransferLots(List<TransferLot> transferLots) {
574
		this.transferLots = transferLots;
575
	}
576
 
577
	public String getRemoteTransferRefNumber() {
578
		return remoteTransferRefNumber;
579
	}
580
 
581
	public void setRemoteTransferRefNumber(String remoteTransferRefNumber) {
582
		this.remoteTransferRefNumber = remoteTransferRefNumber;
583
	}
584
 
585
	public Long getId() {
586
		return id;
587
	}
588
 
589
	public void setId(Long id) {
590
		this.id = id;
591
	}
592
 
593
	public String getOutput() {
594
		return output;
595
	}
596
 
597
	public void setOutput(String output) {
598
		this.output = output;
599
	}
600
 
601
	public Long getOriginWarehouseId() {
602
		return originWarehouseId;
603
	}
604
 
605
	public void setOriginWarehouseId(Long originWarehouseId) {
606
		this.originWarehouseId = originWarehouseId;
607
	}
608
 
609
	public Long getDestinationWarehouseId() {
610
		return destinationWarehouseId;
611
	}
612
 
613
	public void setDestinationWarehouseId(Long destinationWarehouseId) {
614
		this.destinationWarehouseId = destinationWarehouseId;
615
	}
616
 
617
	public String getErrorMessage() {
618
		return errorMessage;
619
	}
620
 
621
	public void setErrorMsg(String errorMessage) {
622
		this.errorMessage = errorMessage;
623
	}
624
 
625
	public List<LineItem> getLineItems() {
626
		return lineItems;
627
	}
628
 
629
	public void setLineItems(List<LineItem> lineItems) {
630
		this.lineItems = lineItems;
631
	}
10121 manish.sha 632
 
633
	public JSONObject getJsonTransferLotItemData() {
634
		return jsonTransferLotItemData;
635
	}
636
 
637
	public void setJsonTransferLotItemData(JSONObject jsonTransferLotItemData) {
638
		this.jsonTransferLotItemData = jsonTransferLotItemData;
639
	}
640
 
641
	public String getInventoryItemsString() {
642
		return inventoryItemsString;
643
	}
644
 
645
	public void setInventoryItemsString(String inventoryItemsString) {
646
		this.inventoryItemsString = inventoryItemsString;
647
	}
648
 
649
	public String getInventoryItemsLength() {
650
		return inventoryItemsLength;
651
	}
652
 
653
	public void setInventoryItemsLength(String inventoryItemsLength) {
654
		this.inventoryItemsLength = inventoryItemsLength;
655
	}
656
 
657
	public String getTransferLotReceiveType() {
658
		return transferLotReceiveType;
659
	}
660
 
661
	public void setTransferLotReceiveType(String transferLotReceiveType) {
662
		this.transferLotReceiveType = transferLotReceiveType;
663
	}
664
 
7410 amar.kumar 665
}