Subversion Repositories SmartDukaan

Rev

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