Subversion Repositories SmartDukaan

Rev

Rev 21617 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
11349 manish.sha 1
package in.shop2020.inventory.controllers;
2
 
3
import in.shop2020.model.v1.catalog.Item;
4
import in.shop2020.model.v1.catalog.ItemType;
5
import in.shop2020.model.v1.inventory.InventoryService;
6
import in.shop2020.model.v1.inventory.InventoryType;
7
import in.shop2020.model.v1.inventory.Warehouse;
8
import in.shop2020.model.v1.inventory.WarehouseType;
9
import in.shop2020.model.v1.order.LineItem;
10
import in.shop2020.purchase.PurchaseOrder;
11
import in.shop2020.purchase.PurchaseServiceException;
12
import in.shop2020.thrift.clients.CatalogClient;
13
import in.shop2020.thrift.clients.InventoryClient;
14
import in.shop2020.thrift.clients.PurchaseClient;
15
import in.shop2020.thrift.clients.WarehouseClient;
16
import in.shop2020.utils.ModelUtils;
17
import in.shop2020.warehouse.InventoryItem;
25631 amit.gupta 18
import in.shop2020.warehouse.Scan;
11349 manish.sha 19
import in.shop2020.warehouse.ScanType;
20
import in.shop2020.warehouse.WarehouseService;
21
import in.shop2020.warehouse.WarehouseService.Client;
22
 
23
import java.io.BufferedInputStream;
24
import java.io.BufferedReader;
25
import java.io.BufferedWriter;
26
import java.io.File;
27
import java.io.FileInputStream;
28
import java.io.FileReader;
29
import java.io.FileWriter;
30
import java.io.IOException;
31
import java.io.InputStream;
32
import java.util.ArrayList;
33
import java.util.HashMap;
34
import java.util.List;
35
import java.util.Map;
36
 
37
import javax.servlet.ServletContext;
38
import javax.servlet.ServletOutputStream;
39
 
40
import org.apache.commons.io.FileUtils;
41
import org.apache.commons.lang.StringUtils;
42
import org.apache.struts2.convention.annotation.Result;
43
import org.apache.struts2.convention.annotation.Results;
44
import org.apache.thrift.TException;
45
import org.apache.thrift.transport.TTransportException;
46
import org.slf4j.Logger;
47
import org.slf4j.LoggerFactory;
48
 
49
@SuppressWarnings("serial")
50
@Results({ @Result(name = "redirect", type = "redirectAction", params = {
51
		"actionName", "warehouse" }) })
52
		public class BulkPurchaseController extends BaseController {
53
	private static Logger logger = LoggerFactory.getLogger(BulkPurchaseController.class);
54
	private List<String> exceptionList = new ArrayList<String>();
55
	private static final int NUM_BULK__SCAN_ITEMS = 10;
11801 manish.sha 56
	private static final long DUMMY_VENDOR_ID = 40;
11349 manish.sha 57
 
58
	private ServletContext context;
59
	private String id="";
60
	private Long transferLotId;
61
	private String itemId;
62
	private String itemNo;
63
	private String errorMsg = "";
64
	private String successMsg = "";
65
	private List<Item> items;
66
	private List<LineItem> lineItems;
67
	private String bulkScanUploadItem;
18668 manish.sha 68
	private String selectItemType;
11349 manish.sha 69
	private File scanDataFile;
70
 
71
	private String invoiceNumber;
72
	private Double freightCharges ;
11801 manish.sha 73
	private String purchaseComments;
11349 manish.sha 74
	private Long poId;
75
	private String fileNameVal;
76
 
77
	private String purchaseId;
78
	private String purchaseOrderId;
79
	private Long warehouseId;
80
	private Long transferWarehouseId;
81
	private Warehouse warehouse;
11801 manish.sha 82
	private Warehouse thirdPartyWarehouse;
11349 manish.sha 83
 
84
	private Map<Long, Double> unfulfilledMap = new HashMap<Long, Double>(); 
18668 manish.sha 85
	private Map<Long, Item> nonserializedMap = new HashMap<Long, Item>();
86
	private Map<Long, Item> serializedMap = new HashMap<Long, Item>();
11349 manish.sha 87
 
88
 
18668 manish.sha 89
 
11349 manish.sha 90
	public String show() {
91
		resetLineItems();
92
		setItemsFromPO();
93
		return SHOW;
94
	}
95
 
96
	private void resetLineItems() {
97
		lineItems = new ArrayList<LineItem>();
98
 
99
		for (int i = 0; i < NUM_BULK__SCAN_ITEMS; i++) {
100
			LineItem lineItem = new LineItem();
101
			lineItem.setId(i);
102
			lineItem.setExtra_info("");
103
			lineItem.setSerial_number("");
104
			lineItem.setItem_number("");
105
			lineItem.setQuantity(1);
106
			lineItem.setItem_id(-1);
107
			lineItems.add(lineItem);
108
		}
109
	}
110
 
111
	public String create() {
112
		this.purchaseOrderId = request.getParameter("poId");
113
		poId = Long.parseLong(purchaseOrderId);
114
		invoiceNumber = request.getParameter("invoiceNumber");
115
		String fc = request.getParameter("freightCharges").trim();
116
		freightCharges = 0D;
117
		if(id == null ||StringUtils.isEmpty(id))
118
			id = "0";
119
		if (fc != null && !fc.isEmpty())
120
			freightCharges = Double.parseDouble(fc);
121
		return show();
122
		//return "create";
123
 
124
	}
125
 
126
	public boolean createPurchase(){
127
		try {
11801 manish.sha 128
			logger.info("poId="+poId+" invoiceNumber="+invoiceNumber+" freightCharges="+freightCharges+ " purchaseComments="+purchaseComments);
11349 manish.sha 129
			PurchaseClient purchaseClient = new PurchaseClient();
130
			in.shop2020.purchase.PurchaseService.Client client = purchaseClient
131
			.getClient();
11801 manish.sha 132
			id = "" + client.startPurchase(poId, invoiceNumber, freightCharges, purchaseComments);
11349 manish.sha 133
			logger.info("id = "+id);
134
		} catch (TTransportException e) {
135
			errorMsg = errorMsg + "<br> Error while establishing connection to the warehouse server";
136
			exceptionList.add("Error while establishing connection to the warehouse server");
137
			logger.error(errorMsg, e);
138
		} catch (TException e) {
139
			errorMsg = errorMsg+ "<br> Error while scanning in the item";
140
			exceptionList.add("Error while strating purchase");
141
			logger.error(errorMsg, e);
142
		} catch (PurchaseServiceException e) {
143
			errorMsg = errorMsg+ e.getMessage();
144
			exceptionList.add(e.getMessage());
145
			logger.error(errorMsg, e);
146
		}
147
 
148
		if (errorMsg.isEmpty())
149
			return true;
150
		else {
151
			addActionError(errorMsg);
152
			return false;
153
		}
154
	}
155
 
156
	public File getScanFileToRead(){
157
		File fileToCreate = null;
158
 
159
		if(scanDataFile!=null & fileNameVal !=null && !fileNameVal.isEmpty()){
160
 
161
			logger.info("File Name "+scanDataFile.getName());
162
			System.out.println("File Name "+scanDataFile.getName());
163
 
164
			logger.info("File Name Value "+fileNameVal);
165
			System.out.println("File Name Value "+fileNameVal);
166
			String fileName = fileNameVal;
167
			try {
168
				if(!fileName.substring(fileName.lastIndexOf(".")+1).equalsIgnoreCase("txt")){
169
					throw new Exception("File is not in expected TXT Format");
170
				}
171
				fileToCreate = new File("/tmp/", fileName);
172
 
173
				FileUtils.copyFile(this.scanDataFile, fileToCreate);
174
			} catch (Exception e) {
175
				logger.error("Error while writing file used to the local file system", e);
176
				errorMsg = e.getMessage();
177
				//addActionError(errorMsg);
178
				return null;
179
			}
180
		} else {
181
			errorMsg = errorMsg + "<br>Either No File Uploaded or file name is blank";
182
		}
183
		return fileToCreate;
184
	}
185
 
186
	public boolean transferLotCreate(PurchaseOrder po){
187
		String errMsg  = "";
188
		try{
189
			if(transferLotId==null || transferLotId==0) {
190
				if(transferWarehouseId!=null && transferWarehouseId!=0) {
191
					WarehouseClient warehouseClient = new WarehouseClient();
192
					Client client = warehouseClient.getClient();
193
					InventoryService.Client inventoryClient = new InventoryClient().getClient();
194
					Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0L).get(0);
195
					transferLotId = client.createTransferLot(po.getWarehouseId(), transferWarehouseId);
196
				}
197
			}
198
		} catch(Exception e){
199
			errMsg = "<br> Error while creating Transfer Lot due to : "+ e.getMessage();
200
		}
201
		if (errMsg.isEmpty()){
202
			return true;
203
		}
204
		else {
205
			errorMsg = errMsg;
206
			addActionError(errorMsg);
207
			return false;
208
		}
209
	}
210
 
211
	public File createErrorFile(List<String> errorList){
212
		try{
213
			String tmpDir = System.getProperty("java.io.tmpdir");
214
			File file = new File(tmpDir + "/ScanRecordResult.xls");
215
			BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(
216
					file));
217
			bufferedWriter.write(StringUtils.join(new String[] { "----Scan Response----"}, '\t'));
218
			//bufferedWriter.newLine();
219
			for(String record : errorList){
220
				bufferedWriter.newLine();
221
				bufferedWriter.write(StringUtils.join(new String[] { record }, '\t'));
222
			}
223
			bufferedWriter.close();
224
			return file;
225
		} catch (Exception e) {
226
			logger.error("Could not create file for Scan Record Result", e);
227
			return null;
228
		}
229
	}
230
 
231
	public void setResponseErrorFile(File errorFile) throws IOException{
232
		byte[] buffer = null;
233
		buffer = new byte[(int) errorFile.length()];
234
		InputStream input = null;
235
		try {
236
			int totalBytesRead = 0;
237
			input = new BufferedInputStream(new FileInputStream(errorFile));
238
			while (totalBytesRead < buffer.length) {
239
				int bytesRemaining = buffer.length - totalBytesRead;
240
				// input.read() returns -1, 0, or more :
241
					int bytesRead = input.read(buffer, totalBytesRead,
242
							bytesRemaining);
243
					if (bytesRead > 0) {
244
						totalBytesRead = totalBytesRead + bytesRead;
245
					}
246
			}
247
			/*
248
			 * the above style is a bit tricky: it places bytes into the
249
			 * 'buffer' array; 'buffer' is an output parameter; the while
250
			 * loop usually has a single iteration only.
251
			 */
252
		} finally {
253
			input.close();
254
		}
255
 
256
		response.setContentType("application/vnd.ms-excel");
257
		response.setHeader("Content-disposition", "inline; filename="
258
				+ errorFile.getName());
259
 
260
		ServletOutputStream sos = response.getOutputStream();
261
		sos.write(buffer);
262
		sos.flush();
263
	}
264
 
265
	public boolean checkForException() throws IOException{
266
		if(exceptionList!=null && exceptionList.size()>0){
267
			File errorFile = createErrorFile(exceptionList);
268
			if(errorFile.isFile()){
269
				setResponseErrorFile(errorFile);
270
				return false;
271
			}
272
		}
273
		return true;
274
	}
275
 
21617 amit.gupta 276
	private void areValidSerializedItems(Map<String, LineItem> serialNumbersMap) throws Exception {
11349 manish.sha 277
		Client warehouseClient = new WarehouseClient().getClient();
21617 amit.gupta 278
		List<String> serialNumbers = new ArrayList<String>(serialNumbersMap.keySet());
279
		List<InventoryItem> inventoryItems = warehouseClient.getInventoryItemsBySerailNumbers(serialNumbers);
280
		for(InventoryItem inventoryItem : inventoryItems) {
281
			log.info("serialNumber -           --" + inventoryItem.getSerialNumber());
25631 amit.gupta 282
			if(inventoryItem.getLastScanType()!=ScanType.PURCHASE_RETURN && inventoryItem.getLastScanType()!=ScanType.DOA_REPLACED 
283
					&& !inventoryItem.getLastScanType().equals(ScanType.SALE)) {
21617 amit.gupta 284
				LineItem lineItem = serialNumbersMap.remove(inventoryItem.getSerialNumber());
285
				exceptionList.add("Item exist already : "+ lineItem.getSerial_number());
286
				continue;
287
			}    		
11349 manish.sha 288
		}
289
	}
290
 
291
	private void setItemsFromPO() {
292
		try {
293
			items = new ArrayList<Item>();
294
			in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
295
			//PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrderForPurchase(id);
296
			PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
297
			warehouseId = purchaseOrder.getWarehouseId();
298
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
299
 
300
			for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
18668 manish.sha 301
				Item it = catalogClient.getItem(lineItem.getItemId());
302
				if(it.getType()==ItemType.SERIALIZED){
303
					serializedMap.put(it.getId(), it);
304
				}else{
305
					nonserializedMap.put(it.getId(), it);
306
				}
307
				items.add(it);
11349 manish.sha 308
				unfulfilledMap.put(lineItem.getItemId(), lineItem.getUnfulfilledQuantity());
309
			}
310
 
311
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
11801 manish.sha 312
            thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
313
            if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
314
            	warehouse = thirdPartyWarehouse;
315
            } else {
316
            	warehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, purchaseOrder.getSupplierId(), warehouseId, warehouseId).get(0);
317
            }
11349 manish.sha 318
		} catch (Exception e) {
319
			logger.error("Could not find items in PO with purchase: " + id, e);
320
		}
321
	}
322
 
323
	public String update() {
18668 manish.sha 324
		if(selectItemType.equalsIgnoreCase("SERIALIZED")){
325
			if(("-1").equalsIgnoreCase(bulkScanUploadItem)){
326
				errorMsg = errorMsg +" <br> No Item Selected to Scan In";
327
				return show();
328
			}
11349 manish.sha 329
		}
330
 
331
		File fileToCreate = getScanFileToRead();
332
		Map<Long, String> correctRowsMap = new HashMap<Long, String>();
333
		Map<Long, String> errorRowsMap = new HashMap<Long, String>();		
334
 
335
		if(fileToCreate==null){
336
			errorMsg = errorMsg +" <br> No File to read";
337
			return create();
338
		}
339
 
340
		ItemType itemType = ItemType.SERIALIZED;
341
		setItemsFromPO();
342
		lineItems = new ArrayList<LineItem>();
18668 manish.sha 343
 
11349 manish.sha 344
		if(fileToCreate.isFile()){
18668 manish.sha 345
 
346
			try {
11349 manish.sha 347
				in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
348
				PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
349
				List<in.shop2020.purchase.LineItem> poLineItems = po.getLineitems();
350
				in.shop2020.purchase.LineItem poLineItem = new in.shop2020.purchase.LineItem();
351
 
21617 amit.gupta 352
				//Logic to create transfer lot pending yet
11349 manish.sha 353
				if(!transferLotCreate(po)){
354
					return create();
355
				}
18668 manish.sha 356
 
21617 amit.gupta 357
				Map<String, LineItem> serialNumbersMap = new HashMap<String, LineItem>();
18668 manish.sha 358
				if(selectItemType.equalsIgnoreCase("SERIALIZED")){
359
					Item item = serializedMap.get(Long.parseLong(bulkScanUploadItem));
360
					itemType = item.getType();
361
 
362
					for(in.shop2020.purchase.LineItem pItem : poLineItems){
363
						if(pItem.getItemId() == item.getId()){
364
							poLineItem = pItem;
21617 amit.gupta 365
							if (poLineItem.getUnfulfilledQuantity() == 0) {
366
								errorMsg = "Error occurred"
367
									+ "<br> Item uploaded is already fulfilled";
368
								addActionError(errorMsg);
369
								return create();
370
							}
18668 manish.sha 371
							break;
11349 manish.sha 372
						}
373
					}
18668 manish.sha 374
 
375
					BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
376
					long line = 1;
377
					String strLine;
378
					String[] values;
379
					while((strLine = br.readLine())!=null){
18681 manish.sha 380
						if(strLine.trim().isEmpty()){
381
							continue;
382
						}
18668 manish.sha 383
						if(line==1){
384
							values = strLine.split("\t");						
385
							if(values.length !=3){
386
								errorMsg = errorMsg + "<br> File contains Inappropriate Content ";
387
								addActionError(errorMsg);
388
								return create();
11349 manish.sha 389
							}
18668 manish.sha 390
							line++;
391
							continue;
21617 amit.gupta 392
							// Maximum upload for an item is 500
393
						} else if (line > 501) {
394
							errorMsg = "Error Occurred"
395
									+ "<br> Can process upto 500 records only";
396
							addActionError(errorMsg);
397
							return create();
398
						} else if (poLineItem.getUnfulfilledQuantity() < line - 1){
399
							errorMsg = "Error occurred"
400
								+ "<br> SerialNumbers uploaded should not be greater than unfulfilled Quantity";
401
							addActionError(errorMsg);
402
							return create();
18668 manish.sha 403
						}
404
						values = strLine.split("\t");
405
						LineItem lineItem = new LineItem();
406
						lineItem.setId(line);
407
						lineItem.setItem_id(item.getId());
408
						lineItem.setBrand(item.getBrand());
409
						lineItem.setColor(item.getColor());
410
						lineItem.setModel_name(item.getModelName());
411
						lineItem.setModel_number(item.getModelNumber());
412
						lineItem.setProductGroup(item.getProductGroup());
413
						lineItem.setNlc(poLineItem.getNlc());
414
						lineItem.setTransfer_price(poLineItem.getUnitPrice());
415
						lineItem.setUnit_price(poLineItem.getUnitPrice());
416
						if(itemType==ItemType.SERIALIZED){
417
							if(StringUtils.isNotBlank(values[0]) && StringUtils.isNotEmpty(values[0])){
418
								if(StringUtils.isNotBlank(values[1]) && StringUtils.isNotEmpty(values[1])){
419
									lineItem.setItem_number(values[0].trim());
420
									lineItem.setSerial_number(values[1].trim());
421
									lineItem.setQuantity(1);
21617 amit.gupta 422
									logger.info(serialNumbersMap.size() + " ------ " +  lineItem.getSerial_number());
423
									if (serialNumbersMap.containsKey(lineItem.getSerial_number())){
424
										errorRowsMap.put(line, "Error: Serial Number is duplicate in sheet");
425
										line++;
426
										continue;
427
									} else {
428
										serialNumbersMap.put(lineItem.getSerial_number(), lineItem);
429
										correctRowsMap.put(line, "Entries are correct in the row");
430
									}
18668 manish.sha 431
								}
432
								else{
433
									errorRowsMap.put(line, "Error: Serial Number Missing ");
434
									line++;
435
									continue;
436
								}
437
							}
11349 manish.sha 438
							else{
18668 manish.sha 439
								errorRowsMap.put(line, "Error: Item Number Missing ");
11349 manish.sha 440
								line++;
441
								continue;
442
							}
443
						}
18668 manish.sha 444
 
445
						if(correctRowsMap.containsKey(line) && !errorRowsMap.containsKey(line)){
446
							lineItems.add(lineItem);
447
						}
448
						line++;
449
					}
21617 amit.gupta 450
					areValidSerializedItems(serialNumbersMap);
451
				}
11349 manish.sha 452
 
21617 amit.gupta 453
				if(errorRowsMap!=null && errorRowsMap.size()>0){
454
					for(Long row : errorRowsMap.keySet()){
455
						exceptionList.add("At Row "+ row +" "+ errorRowsMap.get(row));
11349 manish.sha 456
					}
457
				}
21617 amit.gupta 458
				if(correctRowsMap.size()==0){
11349 manish.sha 459
					exceptionList.add("-- File Contains Zero Correct Records --");
460
					if(errorRowsMap!=null && errorRowsMap.size()>0){
461
						exceptionList.add("-- Data in uploaded sheet is Inappropriate --");
462
					}
463
				}
464
 
21617 amit.gupta 465
				if(!checkForException()) {
466
					return null;
467
				}
468
 
11349 manish.sha 469
				if(id == null || Long.parseLong(id)==0) {
470
					if(!createPurchase()) {
471
						if(!checkForException()){
472
							return create();
473
						}
474
					}
18668 manish.sha 475
				}
476
 
11349 manish.sha 477
				WarehouseClient warehouseClient = new WarehouseClient();
478
				Client client = warehouseClient.getClient();
16490 manish.sha 479
				InventoryService.Client inventoryClient = new InventoryClient().getClient();
11801 manish.sha 480
				boolean checkDirectScanWarehouse = false;
481
 
482
	            if(thirdPartyWarehouse.getVendor().getId()==DUMMY_VENDOR_ID && thirdPartyWarehouse.getInventoryType()==InventoryType.GOOD && thirdPartyWarehouse.getWarehouseType()==WarehouseType.OURS_THIRDPARTY){
483
	            	checkDirectScanWarehouse = true;
484
	            }
16490 manish.sha 485
 
486
	            long currentWarehouseId = 0;
487
	            if(!checkDirectScanWarehouse){
488
	            	Warehouse fulfilmentWarehouse = inventoryClient.getWarehouses(WarehouseType.OURS, InventoryType.GOOD, po.getSupplierId(), po.getWarehouseId(), 0).get(0);
489
	            	currentWarehouseId = fulfilmentWarehouse.getId();
490
	            }
21617 amit.gupta 491
	            List<InventoryItem> inventoryItems = new ArrayList<InventoryItem>();
11349 manish.sha 492
 
21617 amit.gupta 493
				for (LineItem lineItem : serialNumbersMap.values()) {
11349 manish.sha 494
					InventoryItem inventoryItem = new InventoryItem();
495
					inventoryItem.setItemId(lineItem.getItem_id());
496
					inventoryItem.setPurchaseId(Long.parseLong(id));
21617 amit.gupta 497
					inventoryItem.setCurrentQuantity(1);
11349 manish.sha 498
					inventoryItem.setItemNumber(lineItem.getItem_number());
499
					inventoryItem.setSerialNumber(lineItem.getSerial_number());
21617 amit.gupta 500
					log.info("inventory Item serial number --- " + lineItem.getSerial_number());
501
					inventoryItem.setInitialQuantity(1);
502
					inventoryItem.setLastScanType(ScanType.PURCHASE);
11801 manish.sha 503
	                if(checkDirectScanWarehouse){
504
	                	inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
505
	                	inventoryItem.setCurrentWarehouseId(po.getWarehouseId());
506
	                }else{
507
	                	inventoryItem.setPhysicalWarehouseId(po.getWarehouseId());
16490 manish.sha 508
	                	inventoryItem.setCurrentWarehouseId(currentWarehouseId);
11801 manish.sha 509
	                }
21617 amit.gupta 510
					inventoryItems.add(inventoryItem);				
11349 manish.sha 511
				}
21617 amit.gupta 512
 
513
				try{
514
					client.scanPurchaseBulk(inventoryItems);
11349 manish.sha 515
					successMsg = "Items scanned Successfully.<br>Check the unfulfilled Quantity for further details";
21617 amit.gupta 516
					addActionMessage(successMsg);
11349 manish.sha 517
				}
21617 amit.gupta 518
				catch(Exception e){
519
					addActionError("Error -  Could not scan in items due to " + e.getMessage());
520
				}
18668 manish.sha 521
			} catch (Exception e) {
11349 manish.sha 522
				errorMsg = errorMsg + " <br> Error while scanning items";
523
				logger.error(errorMsg, e);
18668 manish.sha 524
				e.printStackTrace();
11349 manish.sha 525
			}
526
		}
527
		return create();
528
	}
21617 amit.gupta 529
 
11349 manish.sha 530
	public String destroy() {
531
		long id = Long.parseLong(this.id);
532
 
533
		try {
534
			PurchaseClient warehouseClient = new PurchaseClient();
535
			in.shop2020.purchase.PurchaseService.Client client = warehouseClient
536
			.getClient();
537
			client.closePurchase(id);
538
		} catch (TTransportException e) {
539
			errorMsg = errorMsg + "<br> Error while establishing connection to the warehouse server";
540
			logger.error(errorMsg, e);
541
		} catch (TException e) {
542
			errorMsg = errorMsg + "<br> Error while scanning in the item";
543
			logger.error(errorMsg, e);
544
		} catch (PurchaseServiceException e) {
545
			errorMsg = errorMsg + e.getMessage();
546
			logger.error(errorMsg, e);
547
		}
548
		return "redirect";
549
	}
550
 
551
	public List<Warehouse> getAllowedDestinationWarehousesForTransfer(long originWarehouseId){
552
		try {
553
			WarehouseService.Client warehouseClient = new WarehouseClient().getClient();
554
			List<Long> allowedWarehouseIds = warehouseClient.getAllowedDestinationWarehousesForTransfer(originWarehouseId);
555
			List<Warehouse> allowedWarehouses = new ArrayList<Warehouse>();
556
			InventoryService.Client inventoryClient = new InventoryClient().getClient();
557
			for(Long allowedWarehouseId : allowedWarehouseIds) {
558
				allowedWarehouses.add(inventoryClient.getWarehouse(allowedWarehouseId));
559
			}
560
			return allowedWarehouses;
561
		} catch(Exception e) {
562
			logger.error("Error while getting all destination warehouses for warehouseId " + warehouseId, e);
563
			return new ArrayList<Warehouse>();
564
		}
565
	}
566
 
567
	public boolean isItemScannedIn(long id){
568
		if(unfulfilledMap.get(id)> 0){
569
			return true;
570
		}
571
		return false;
572
	}
573
 
574
	public String getName(Item item){
575
		return ModelUtils.extractProductNameFromItem(item);
576
	}
577
 
578
	public void setId(String id) {
579
		this.id = id;
580
	}
581
 
582
	public String getId() {
583
		return id;
584
	}
585
 
586
	public String getErrorMessage() {
587
		return errorMsg;
588
	}
589
 
590
	public String getPurchaseOrderId() {
591
		return purchaseOrderId;
592
	}
593
 
594
	public String getServletContextPath() {
595
		return context.getContextPath();
596
	}
597
 
598
	public String getItemId() {
599
		return itemId;
600
	}
601
 
602
	public void setItemId(String itemId) {
603
		this.itemId = itemId;
604
	}
605
 
606
	public String getItemNo() {
607
		return itemNo;
608
	}
609
 
610
	public void setItemNo(String itemNo) {
611
		this.itemNo = itemNo;
612
	}
613
 
614
	public List<Item> getItems() {
615
		return items;
616
	}
617
 
618
	public void setItems(List<Item> items) {
619
		this.items = items;
620
	}
621
 
622
	public List<LineItem> getLineItems() {
623
		return lineItems;
624
	}
625
 
626
	public void setLineItems(List<LineItem> lineItems) {
627
		this.lineItems = lineItems;
628
	}
629
 
630
	public Warehouse getWarehouse() {
631
		return warehouse;
632
	}
633
 
634
	public String getInvoiceNumber() {
635
		return invoiceNumber;
636
	}
637
 
638
	public void setInvoiceNumber(String invoiceNumber) {
639
		this.invoiceNumber = invoiceNumber;
640
	}
641
 
642
	public Double getFreightCharges() {
643
		return freightCharges;
644
	}
645
 
646
	public void setFreightCharges(Double freightCharges) {
647
		this.freightCharges = freightCharges;
648
	}
649
 
650
	public Long getPoId() {
651
		return poId;
652
	}
653
 
654
	public void setPoId(Long poId) {
655
		this.poId = poId;
656
	}
657
 
658
	public Long getWarehouseId() {
659
		return warehouseId;
660
	}
661
 
662
	public void setWarehouseId(Long warehouseId) {
663
		this.warehouseId = warehouseId;
664
	}
665
 
666
	public Long getTransferWarehouseId() {
667
		return transferWarehouseId;
668
	}
669
 
670
	public void setTransferWarehouseId(Long transferWarehouseId) {
671
		this.transferWarehouseId = transferWarehouseId;
672
	}
673
 
674
	public Long getTransferLotId() {
675
		return transferLotId;
676
	}
677
 
678
	public void setTransferLotId(Long transferLotId) {
679
		this.transferLotId = transferLotId;
680
	}
681
 
682
	public String getBulkScanUploadItem() {
683
		return bulkScanUploadItem;
684
	}
685
 
686
	public void setBulkScanUploadItem(String bulkScanUploadItem) {
687
		this.bulkScanUploadItem = bulkScanUploadItem;
688
	}
689
 
18679 manish.sha 690
	public String getSelectItemType() {
691
		return selectItemType;
692
	}
693
 
694
	public void setSelectItemType(String selectItemType) {
695
		this.selectItemType = selectItemType;
696
	}
697
 
11349 manish.sha 698
	public File getScanDataFile() {
699
		return scanDataFile;
700
	}
701
 
702
	public void setScanDataFile(File scanDataFile) {
703
		this.scanDataFile = scanDataFile;
704
	}
705
 
706
	public String getPurchaseId() {
707
		return purchaseId;
708
	}
709
 
710
	public void setPurchaseId(String purchaseId) {
711
		this.purchaseId = purchaseId;
712
	}
713
 
714
	public String getFileNameVal() {
715
		return fileNameVal;
716
	}
717
 
718
	public void setFileNameVal(String fileNameVal) {
719
		this.fileNameVal = fileNameVal;
720
	}
721
 
722
	public String getSuccessMsg() {
723
		return successMsg;
724
	}
725
 
726
	public void setSuccessMsg(String successMsg) {
727
		this.successMsg = successMsg;
728
	}
729
 
11801 manish.sha 730
	public String getPurchaseComments() {
731
		return purchaseComments;
732
	}
733
 
734
	public void setPurchaseComments(String purchaseComments) {
735
		this.purchaseComments = purchaseComments;
736
	}
737
 
738
	public Warehouse getThirdPartyWarehouse() {
739
		return thirdPartyWarehouse;
740
	}
741
 
742
	public void setThirdPartyWarehouse(Warehouse thirdPartyWarehouse) {
743
		this.thirdPartyWarehouse = thirdPartyWarehouse;
744
	}
11349 manish.sha 745
}