Subversion Repositories SmartDukaan

Rev

Rev 16490 | Rev 18679 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 16490 Rev 18668
Line 63... Line 63...
63
	private String errorMsg = "";
63
	private String errorMsg = "";
64
	private String successMsg = "";
64
	private String successMsg = "";
65
	private List<Item> items;
65
	private List<Item> items;
66
	private List<LineItem> lineItems;
66
	private List<LineItem> lineItems;
67
	private String bulkScanUploadItem;
67
	private String bulkScanUploadItem;
-
 
68
	private String selectItemType;
68
	private File scanDataFile;
69
	private File scanDataFile;
69
	
70
	
70
	private String invoiceNumber;
71
	private String invoiceNumber;
71
	private Double freightCharges ;
72
	private Double freightCharges ;
72
	private String purchaseComments;
73
	private String purchaseComments;
Line 79... Line 80...
79
	private Long transferWarehouseId;
80
	private Long transferWarehouseId;
80
	private Warehouse warehouse;
81
	private Warehouse warehouse;
81
	private Warehouse thirdPartyWarehouse;
82
	private Warehouse thirdPartyWarehouse;
82
	
83
	
83
	private Map<Long, Double> unfulfilledMap = new HashMap<Long, Double>(); 
84
	private Map<Long, Double> unfulfilledMap = new HashMap<Long, Double>(); 
-
 
85
	private Map<Long, Item> nonserializedMap = new HashMap<Long, Item>();
-
 
86
	private Map<Long, Item> serializedMap = new HashMap<Long, Item>();
-
 
87
	
84
	
88
	
85
	
89
	
86
	public String show() {
90
	public String show() {
87
		resetLineItems();
91
		resetLineItems();
88
		setItemsFromPO();
92
		setItemsFromPO();
Line 296... Line 300...
296
			PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
300
			PurchaseOrder purchaseOrder = purchaseClient.getPurchaseOrder(poId);
297
			warehouseId = purchaseOrder.getWarehouseId();
301
			warehouseId = purchaseOrder.getWarehouseId();
298
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
302
			in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
299
 
303
 
300
			for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
304
			for (in.shop2020.purchase.LineItem lineItem : purchaseOrder.getLineitems()) {
301
				items.add(catalogClient.getItem(lineItem.getItemId()));
305
				Item it = catalogClient.getItem(lineItem.getItemId());
-
 
306
				if(it.getType()==ItemType.SERIALIZED){
-
 
307
					serializedMap.put(it.getId(), it);
-
 
308
				}else{
-
 
309
					nonserializedMap.put(it.getId(), it);
-
 
310
				}
-
 
311
				items.add(it);
302
				unfulfilledMap.put(lineItem.getItemId(), lineItem.getUnfulfilledQuantity());
312
				unfulfilledMap.put(lineItem.getItemId(), lineItem.getUnfulfilledQuantity());
303
			}
313
			}
304
 
314
 
305
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
315
			in.shop2020.model.v1.inventory.InventoryService.Client inventoryClient = new InventoryClient().getClient();
306
            thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
316
            thirdPartyWarehouse = inventoryClient.getWarehouse(warehouseId);
Line 313... Line 323...
313
			logger.error("Could not find items in PO with purchase: " + id, e);
323
			logger.error("Could not find items in PO with purchase: " + id, e);
314
		}
324
		}
315
	}
325
	}
316
	
326
	
317
	public String update() {
327
	public String update() {
-
 
328
		if(selectItemType.equalsIgnoreCase("SERIALIZED")){
318
		if(("-1").equalsIgnoreCase(bulkScanUploadItem)){
329
			if(("-1").equalsIgnoreCase(bulkScanUploadItem)){
319
			errorMsg = errorMsg +" <br> No Item Selected to Scan In";
330
				errorMsg = errorMsg +" <br> No Item Selected to Scan In";
320
			return show();
331
				return show();
-
 
332
			}
321
		}
333
		}
322
		
334
		
323
		File fileToCreate = getScanFileToRead();
335
		File fileToCreate = getScanFileToRead();
324
		Map<Long, String> correctRowsMap = new HashMap<Long, String>();
336
		Map<Long, String> correctRowsMap = new HashMap<Long, String>();
325
		Map<Long, String> errorRowsMap = new HashMap<Long, String>();		
337
		Map<Long, String> errorRowsMap = new HashMap<Long, String>();		
Line 330... Line 342...
330
		}
342
		}
331
		
343
		
332
		ItemType itemType = ItemType.SERIALIZED;
344
		ItemType itemType = ItemType.SERIALIZED;
333
		setItemsFromPO();
345
		setItemsFromPO();
334
		lineItems = new ArrayList<LineItem>();
346
		lineItems = new ArrayList<LineItem>();
335
 
347
		
336
		if(fileToCreate.isFile()){
348
		if(fileToCreate.isFile()){
-
 
349
			
337
			try{
350
			try {
338
				in.shop2020.model.v1.catalog.CatalogService.Client catalogClient = new CatalogClient().getClient();
-
 
339
				Item item = catalogClient.getItem(Long.parseLong(bulkScanUploadItem));
-
 
340
 
-
 
341
				itemType = item.getType();
-
 
342
 
-
 
343
				in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
351
				in.shop2020.purchase.PurchaseService.Client purchaseClient = new PurchaseClient().getClient();
344
				PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
352
				PurchaseOrder po = purchaseClient.getPurchaseOrder(poId);
345
				List<in.shop2020.purchase.LineItem> poLineItems = po.getLineitems();
353
				List<in.shop2020.purchase.LineItem> poLineItems = po.getLineitems();
346
				in.shop2020.purchase.LineItem poLineItem = new in.shop2020.purchase.LineItem();
354
				in.shop2020.purchase.LineItem poLineItem = new in.shop2020.purchase.LineItem();
347
 
355
 
348
				for(in.shop2020.purchase.LineItem pItem : poLineItems){
-
 
349
					if(pItem.getItemId() == item.getId()){
-
 
350
						poLineItem = pItem;
-
 
351
						break;
-
 
352
					}
-
 
353
				}
-
 
354
 
-
 
355
				if(!transferLotCreate(po)){
356
				if(!transferLotCreate(po)){
356
					return create();
357
					return create();
357
				}
358
				}
358
 
359
				
359
				BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
360
				if(selectItemType.equalsIgnoreCase("SERIALIZED")){
360
				long line = 1;
-
 
361
				String strLine;
361
					Item item = serializedMap.get(Long.parseLong(bulkScanUploadItem));
362
				String[] values;
-
 
363
				while((strLine = br.readLine())!=null){
362
					itemType = item.getType();
364
					if(line==1){
363
					
365
						values = strLine.split("\t");						
364
					for(in.shop2020.purchase.LineItem pItem : poLineItems){
366
						if(values.length !=3){
365
						if(pItem.getItemId() == item.getId()){
367
							errorMsg = errorMsg + "<br> File contains Inappropriate Content ";
-
 
368
							addActionError(errorMsg);
366
							poLineItem = pItem;
369
							return create();
367
							break;
370
						}
368
						}
371
						line++;
-
 
372
						continue;
-
 
373
					}
369
					}
-
 
370
					
-
 
371
					BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
-
 
372
					long line = 1;
-
 
373
					String strLine;
-
 
374
					String[] values;
-
 
375
					while((strLine = br.readLine())!=null){
-
 
376
						if(line==1){
-
 
377
							values = strLine.split("\t");						
-
 
378
							if(values.length !=3){
-
 
379
								errorMsg = errorMsg + "<br> File contains Inappropriate Content ";
-
 
380
								addActionError(errorMsg);
-
 
381
								return create();
-
 
382
							}
-
 
383
							line++;
-
 
384
							continue;
-
 
385
						}
374
					values = strLine.split("\t");
386
						values = strLine.split("\t");
375
					for(String s : values){
387
						for(String s : values){
376
						logger.info("Row No "+line+" :"+s);
388
							logger.info("Row No "+line+" :"+s);
377
						System.out.println("Row No "+line+" :"+s);
389
							System.out.println("Row No "+line+" :"+s);
378
					}
390
						}
379
					LineItem lineItem = new LineItem();
391
						LineItem lineItem = new LineItem();
380
					lineItem.setId(line);
392
						lineItem.setId(line);
381
					lineItem.setItem_id(item.getId());
393
						lineItem.setItem_id(item.getId());
382
					lineItem.setBrand(item.getBrand());
394
						lineItem.setBrand(item.getBrand());
383
					lineItem.setColor(item.getColor());
395
						lineItem.setColor(item.getColor());
384
					lineItem.setModel_name(item.getModelName());
396
						lineItem.setModel_name(item.getModelName());
385
					lineItem.setModel_number(item.getModelNumber());
397
						lineItem.setModel_number(item.getModelNumber());
386
					lineItem.setProductGroup(item.getProductGroup());
398
						lineItem.setProductGroup(item.getProductGroup());
387
					lineItem.setNlc(poLineItem.getNlc());
399
						lineItem.setNlc(poLineItem.getNlc());
388
					lineItem.setTransfer_price(poLineItem.getUnitPrice());
400
						lineItem.setTransfer_price(poLineItem.getUnitPrice());
389
					lineItem.setUnit_price(poLineItem.getUnitPrice());
401
						lineItem.setUnit_price(poLineItem.getUnitPrice());
390
					if(itemType==ItemType.SERIALIZED){
402
						if(itemType==ItemType.SERIALIZED){
391
						if(StringUtils.isNotBlank(values[0]) && StringUtils.isNotEmpty(values[0])){
403
							if(StringUtils.isNotBlank(values[0]) && StringUtils.isNotEmpty(values[0])){
392
							if(StringUtils.isNotBlank(values[1]) && StringUtils.isNotEmpty(values[1])){
404
								if(StringUtils.isNotBlank(values[1]) && StringUtils.isNotEmpty(values[1])){
393
								lineItem.setItem_number(values[0].trim());
405
									lineItem.setItem_number(values[0].trim());
394
								lineItem.setSerial_number(values[1].trim());
406
									lineItem.setSerial_number(values[1].trim());
395
								lineItem.setQuantity(1);
407
									lineItem.setQuantity(1);
396
								correctRowsMap.put(line, "Entries are correct in the row");
408
									correctRowsMap.put(line, "Entries are correct in the row");
-
 
409
								}
-
 
410
								else{
-
 
411
									errorRowsMap.put(line, "Error: Serial Number Missing ");
-
 
412
									line++;
-
 
413
									continue;
-
 
414
								}
397
							}
415
							}
398
							else{
416
							else{
399
								errorRowsMap.put(line, "Error: Serial Number Missing ");
417
								errorRowsMap.put(line, "Error: Item Number Missing ");
400
								line++;
418
								line++;
401
								continue;
419
								continue;
402
							}
420
							}
403
						}
421
						}
-
 
422
 
-
 
423
						if(correctRowsMap.containsKey(line) && !errorRowsMap.containsKey(line)){
-
 
424
							lineItems.add(lineItem);
-
 
425
						}
-
 
426
 
-
 
427
						line++;
-
 
428
					}
-
 
429
					
-
 
430
					areValidSerializedItems();
-
 
431
					
404
						else{
432
				}else{
-
 
433
					
-
 
434
					BufferedReader br = new BufferedReader(new FileReader(fileToCreate));
-
 
435
					long line = 1;
-
 
436
					String strLine;
-
 
437
					String[] values;
-
 
438
					while((strLine = br.readLine())!=null){
-
 
439
						if(line==1){
-
 
440
							values = strLine.split("\t");						
-
 
441
							if(values.length !=4){
405
							errorRowsMap.put(line, "Error: Item Number Missing ");
442
								errorMsg = errorMsg + "<br> File contains Inappropriate Content ";
-
 
443
								addActionError(errorMsg);
-
 
444
								return create();
-
 
445
							}
406
							line++;
446
							line++;
407
							continue;
447
							continue;
408
						}
448
						}
-
 
449
						values = strLine.split("\t");
409
					}
450
						for(String s : values){
410
 
-
 
411
					if(itemType==ItemType.NON_SERIALIZED){
451
							logger.info("Row No "+line+" :"+s);
412
						if(StringUtils.isNotBlank(values[0]) && StringUtils.isNotEmpty(values[0])){
452
							System.out.println("Row No "+line+" :"+s);
-
 
453
						}
413
							lineItem.setItem_number(values[0].trim());
454
						Item item = nonserializedMap.get(Long.parseLong(values[0]));
414
							lineItem.setSerial_number("");
455
						itemType = item.getType();
-
 
456
						
415
							if(StringUtils.isNotBlank(values[2]) && StringUtils.isNumeric(values[2]) && Double.parseDouble(values[2]) > 0){
457
						for(in.shop2020.purchase.LineItem pItem : poLineItems){
416
								lineItem.setQuantity(Double.parseDouble(values[2].trim()));
458
							if(pItem.getItemId() == item.getId()){
417
								correctRowsMap.put(line, "Entries are correct in the row ");
459
								poLineItem = pItem;
-
 
460
								break;
418
							}
461
							}
-
 
462
						}
-
 
463
						LineItem lineItem = new LineItem();
-
 
464
						lineItem.setId(line);
-
 
465
						lineItem.setItem_id(item.getId());
-
 
466
						lineItem.setBrand(item.getBrand());
-
 
467
						lineItem.setColor(item.getColor());
-
 
468
						lineItem.setModel_name(item.getModelName());
-
 
469
						lineItem.setModel_number(item.getModelNumber());
-
 
470
						lineItem.setProductGroup(item.getProductGroup());
-
 
471
						lineItem.setNlc(poLineItem.getNlc());
-
 
472
						lineItem.setTransfer_price(poLineItem.getUnitPrice());
-
 
473
						lineItem.setUnit_price(poLineItem.getUnitPrice());
-
 
474
 
-
 
475
						if(itemType==ItemType.NON_SERIALIZED){
-
 
476
							if(StringUtils.isNotBlank(values[1]) && StringUtils.isNotEmpty(values[1])){
-
 
477
								lineItem.setItem_number(values[1].trim());
-
 
478
								lineItem.setSerial_number("");
-
 
479
								if(StringUtils.isNotBlank(values[3]) && StringUtils.isNumeric(values[3]) && Double.parseDouble(values[3]) > 0){
-
 
480
									lineItem.setQuantity(Double.parseDouble(values[3].trim()));
-
 
481
									correctRowsMap.put(line, "Entries are correct in the row ");
-
 
482
								}
419
							else{
483
								else{
420
								errorRowsMap.put(line, "Error: Invalid Item Quantity ");
484
									errorRowsMap.put(line, "Error: Invalid Item Quantity ");
-
 
485
									line++;
-
 
486
									continue;
-
 
487
								}
-
 
488
							} else{
-
 
489
								errorRowsMap.put(line, "Error: Item Number Missing ");
421
								line++;
490
								line++;
422
								continue;
491
								continue;
423
							}
492
							}
424
						} else{
493
 
425
							errorRowsMap.put(line, "Error: Item Number Missing ");
-
 
426
							line++;
-
 
427
							continue;
-
 
428
						}
494
						}
429
 
495
 
-
 
496
						if(correctRowsMap.containsKey(line) && !errorRowsMap.containsKey(line)){
-
 
497
							lineItems.add(lineItem);
430
					}
498
						}
431
 
499
 
432
					if(correctRowsMap.containsKey(line) && !errorRowsMap.containsKey(line)){
-
 
433
						lineItems.add(lineItem);
500
						line++;
434
					}
501
					}
435
 
-
 
436
					line++;
-
 
437
				}
502
				}
-
 
503
				
438
				if(correctRowsMap!=null && correctRowsMap.size()>0){
504
				if(correctRowsMap!=null && correctRowsMap.size()>0){
439
					if(errorRowsMap!=null && errorRowsMap.size()>0){
505
					if(errorRowsMap!=null && errorRowsMap.size()>0){
440
						for(Long row : errorRowsMap.keySet()){
506
						for(Long row : errorRowsMap.keySet()){
441
							exceptionList.add("At Row "+ row +" "+ errorRowsMap.get(row));
507
							exceptionList.add("At Row "+ row +" "+ errorRowsMap.get(row));
442
						}
508
						}
Line 447... Line 513...
447
					if(errorRowsMap!=null && errorRowsMap.size()>0){
513
					if(errorRowsMap!=null && errorRowsMap.size()>0){
448
						exceptionList.add("-- Data in uploaded sheet is Inappropriate --");
514
						exceptionList.add("-- Data in uploaded sheet is Inappropriate --");
449
					}
515
					}
450
				}
516
				}
451
				
517
				
452
				if(itemType==ItemType.SERIALIZED){
-
 
453
					areValidSerializedItems();
-
 
454
				}
-
 
455
				
-
 
456
				if(id == null || Long.parseLong(id)==0) {
518
				if(id == null || Long.parseLong(id)==0) {
457
					if(!createPurchase()) {
519
					if(!createPurchase()) {
458
						if(!checkForException()){
520
						if(!checkForException()){
459
							return create();
521
							return create();
460
						}
522
						}
461
					}
523
					}
462
				}		
524
				}
463
 
525
				
464
				WarehouseClient warehouseClient = new WarehouseClient();
526
				WarehouseClient warehouseClient = new WarehouseClient();
465
				Client client = warehouseClient.getClient();
527
				Client client = warehouseClient.getClient();
466
				InventoryService.Client inventoryClient = new InventoryClient().getClient();
528
				InventoryService.Client inventoryClient = new InventoryClient().getClient();
467
				boolean checkDirectScanWarehouse = false;
529
				boolean checkDirectScanWarehouse = false;
468
	            
530
	            
Line 494... Line 556...
494
	                }
556
	                }
495
					if(!client.isAlive()){
557
					if(!client.isAlive()){
496
						client = warehouseClient.getClient();
558
						client = warehouseClient.getClient();
497
					}
559
					}
498
					try{
560
					try{
499
						if(itemType==ItemType.SERIALIZED){
561
						if(lineItem.getSerial_number()!=null && !lineItem.getSerial_number().isEmpty()){
500
							if(lineItem.getExtra_info()!=null && "Item scanned already.".equalsIgnoreCase(lineItem.getExtra_info())){
562
							if(lineItem.getExtra_info()!=null && "Item scanned already.".equalsIgnoreCase(lineItem.getExtra_info())){
501
								continue;
563
								continue;
502
							}
564
							}
503
						}
565
						}
504
						client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
566
						client.scan(inventoryItem, ScanType.PURCHASE, new Double(lineItem.getQuantity()).longValue(), warehouseId, (transferLotId!=null)?transferLotId:0L);
Line 520... Line 582...
520
						return null;
582
						return null;
521
					} 
583
					} 
522
				}else{
584
				}else{
523
					successMsg = "Items scanned Successfully.<br>Check the unfulfilled Quantity for further details";
585
					successMsg = "Items scanned Successfully.<br>Check the unfulfilled Quantity for further details";
524
				}
586
				}
525
 
587
				
526
			} catch(Exception e){
588
			} catch (Exception e) {
527
				errorMsg = errorMsg + " <br> Error while scanning items";
589
				errorMsg = errorMsg + " <br> Error while scanning items";
528
				logger.error(errorMsg, e);
590
				logger.error(errorMsg, e);
-
 
591
				e.printStackTrace();
529
			}
592
			}
530
		}
593
		}
531
		return create();
594
		return create();
532
	}
595
	}
533
	
596