Subversion Repositories SmartDukaan

Rev

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

Rev 22250 Rev 22253
Line 368... Line 368...
368
				customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItem);
368
				customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItem);
369
			}
369
			}
370
			if(!itemIdQuantity.isEmpty()){
370
			if(!itemIdQuantity.isEmpty()){
371
				// if item quantity does not match with given serialnumbers size
371
				// if item quantity does not match with given serialnumbers size
372
				LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
372
				LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
-
 
373
				throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "");
373
				return "error";
374
				//return "error";
374
			}
375
			}
375
			try{
376
			try{
376
				this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
377
				this.validatePaymentOptionsAndTotalAmount(createOrderRequest.getPaymentOptions(), totalAmount);
377
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
378
			}catch(ProfitMandiBusinessException profitMandiBusinessException){
378
				LOGGER.error("Error occured while validating payment options : ", profitMandiBusinessException);
379
				LOGGER.error("Error occured while validating payment options : ", profitMandiBusinessException);
379
				return "error";
380
				throw profitMandiBusinessException;
380
			}
381
			}
381
			if(!lineItemPrice.isEmpty()){
382
			if(!lineItemPrice.isEmpty()){
382
				// given fofo line item price must be greater than zero
383
				// given fofo line item price must be greater than zero
383
				LOGGER.error("requested itemId's selling price must greater than 0");
384
				LOGGER.error("requested itemId's selling price must greater than 0");
384
				return "error";
385
				throw new ProfitMandiBusinessException(ProfitMandiConstants.PRICE, lineItemPrice, "");
385
			}
386
			}
386
	
387
	
387
			List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
388
			List<CurrentInventorySnapshot> currentInventorySnapshots = currentInventorySnapshotRepository.selectByFofoItemIds(fofoDetails.getFofoId(), itemIds);
388
			if(itemIds.size() != currentInventorySnapshots.size()){
389
			if(itemIds.size() != currentInventorySnapshots.size()){
389
				// error
390
				// error
Line 408... Line 409...
408
	
409
	
409
	
410
	
410
			if(!itemIdQuantityAvailabilities.isEmpty()){
411
			if(!itemIdQuantityAvailabilities.isEmpty()){
411
				// itemIdQuantity request is not valid
412
				// itemIdQuantity request is not valid
412
				LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
413
				LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
413
				return "error";
414
				throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities, "");
414
			}
415
			}
415
	
416
	
416
	
417
	
417
	
418
	
418
			//		Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
419
			//		Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
Line 535... Line 536...
535
			}
536
			}
536
	
537
	
537
			if(!invalidItemIdSerialNumbers.isEmpty()){
538
			if(!invalidItemIdSerialNumbers.isEmpty()){
538
				LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
539
				LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
539
				// itemId's are serialized you are saying these are not serialized
540
				// itemId's are serialized you are saying these are not serialized
540
				return "error";
541
				throw new ProfitMandiBusinessException("invalidItemIdSerialNumbers", invalidItemIdSerialNumbers, "");
541
			}
542
			}
542
	
543
	
543
			if(!itemIdSerialNumbers.isEmpty()){
544
			if(!itemIdSerialNumbers.isEmpty()){
544
				LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
545
				LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
545
				// itemId's are non serialized you are saying these are serialized
546
				// itemId's are non serialized you are saying these are serialized
546
				return "error";
547
				throw new ProfitMandiBusinessException("itemIdSerialNumbers", itemIdSerialNumbers, "");
547
			}
548
			}
548
	
549
	
549
			if(items.size() != itemIds.size()){
550
			if(items.size() != itemIds.size()){
550
				LOGGER.error("Requested ItemIds not found in catalog");
551
				LOGGER.error("Requested ItemIds not found in catalog");
551
				// invalid itemIds 
552
				// invalid itemIds 
552
				return "error";
553
				throw new ProfitMandiBusinessException("invalidItemIds", "", "");
553
			}
554
			}
554
	
555
	
555
			Map<Integer, List<InventoryItem>> inventoryItemsToBill = new HashMap<Integer,List<InventoryItem>>();
556
			Map<Integer, List<InventoryItem>> inventoryItemsToBill = new HashMap<Integer,List<InventoryItem>>();
556
			Map<Integer, Integer> inventoryItemQuantityUsed = new HashMap<>(); //to keep track of inventoryitem quanity used for scan records insertion
557
			Map<Integer, Integer> inventoryItemQuantityUsed = new HashMap<>(); //to keep track of inventoryitem quanity used for scan records insertion
557
	
558
	
Line 565... Line 566...
565
						//not enough serial numbers
566
						//not enough serial numbers
566
						//LOGGER.info("serialNumbers {}", serialNumbers);
567
						//LOGGER.info("serialNumbers {}", serialNumbers);
567
						LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
568
						LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
568
						LOGGER.info("itemId {}", i.getId());
569
						LOGGER.info("itemId {}", i.getId());
569
						LOGGER.error("not enough serial numbers");
570
						LOGGER.error("not enough serial numbers");
570
						return "error";
571
						throw new ProfitMandiBusinessException("notEnoughSerialNumbers", "", "");
571
					}
572
					}
572
					List<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(i.getId());
573
					List<InventoryItem> inventoryItemsSerializedserialized = serializedInventoryItemMap.get(i.getId());
573
					for (InventoryItem it : inventoryItemsSerializedserialized){
574
					for (InventoryItem it : inventoryItemsSerializedserialized){
574
						it.setGoodQuantity(0);
575
						it.setGoodQuantity(0);
575
						inventoryItemQuantityUsed.put(it.getId(), 1);
576
						inventoryItemQuantityUsed.put(it.getId(), 1);
Line 594... Line 595...
594
					}
595
					}
595
					
596
					
596
					if (totalLeft > 0){
597
					if (totalLeft > 0){
597
						//not enough quanity for non-serialized
598
						//not enough quanity for non-serialized
598
						System.out.println("not enough quanity for non-serialized");
599
						System.out.println("not enough quanity for non-serialized");
599
						return "error";
600
						throw new ProfitMandiBusinessException("notEnoughQuantityForNonSerialized", "", "");
600
					}
601
					}
601
					inventoryItemsToBill.put(i.getId(), inventoryItemsNonSerializedUsed);
602
					inventoryItemsToBill.put(i.getId(), inventoryItemsNonSerializedUsed);
602
				}
603
				}
603
			}
604
			}
604
			
605
			
605
			// mop price validation
606
			// mop price validation
606
			Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
607
			Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
607
			Map<Integer, Float> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
608
			Map<Integer, Float> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
608
			for(Map.Entry<Integer, Float> entry : itemIdMopPriceMap.entrySet()){
609
			for(Map.Entry<Integer, Float> entry : itemIdMopPriceMap.entrySet()){
609
				CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(entry.getKey());
610
				CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(entry.getKey());
610
				if(customFofoLineItem.getSellingPrice() < entry.getValue()){
611
				if(entry.getValue() < Float.MAX_VALUE && customFofoLineItem.getSellingPrice() < entry.getValue()){
611
					invalidMopItemIdPriceMap.put(entry.getKey(), customFofoLineItem.getSellingPrice());
612
					invalidMopItemIdPriceMap.put(entry.getKey(), customFofoLineItem.getSellingPrice());
612
				}
613
				}
613
			}
614
			}
614
			
615
			
615
			if(!invalidMopItemIdPriceMap.isEmpty()){
616
			if(!invalidMopItemIdPriceMap.isEmpty()){
616
				LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}", invalidMopItemIdPriceMap, itemIdMopPriceMap);
617
				LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}", invalidMopItemIdPriceMap, itemIdMopPriceMap);
617
				return "error";
618
				throw new ProfitMandiBusinessException("invalidMopItemIdPrice", invalidMopItemIdPriceMap, "");
618
			}
619
			}
619
	
620
	
620
			InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
621
			InvoiceNumberGenerationSequence invoiceNumberGenerationSequence = null;
621
			try{
622
			try{
622
				invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoDetails.getFofoId());
623
				invoiceNumberGenerationSequence = invoiceNumberGenerationSequenceRepository.selectByFofoId(fofoDetails.getFofoId());
Line 632... Line 633...
632
	
633
	
633
			CustomCustomer customCustomer = createOrderRequest.getCustomer();
634
			CustomCustomer customCustomer = createOrderRequest.getCustomer();
634
	
635
	
635
			if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
636
			if(!StringUtils.isValidEmailAddress(customCustomer.getEmailId())){
636
				LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
637
				LOGGER.error("invalid customer emailId {} ", customCustomer.getEmailId());
637
				return "error";
638
				throw new ProfitMandiBusinessException(ProfitMandiConstants.EMAIL_ID, customCustomer.getEmailId(), "");
638
			}
639
			}
639
	
640
	
640
			if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
641
			if(!StringUtils.isValidMobile(customCustomer.getMobileNumber())){
641
				LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
642
				LOGGER.error("invalid customer mobileNumber {} ", customCustomer.getMobileNumber());
642
				return "error";
643
				throw new ProfitMandiBusinessException(ProfitMandiConstants.MOBILE_NUMBER, customCustomer.getMobileNumber(), "");
643
			}
644
			}
644
			
645
			
645
			boolean insurance = false;
646
			boolean insurance = false;
646
			for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
647
			for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
647
				for(SerialNumberDetail serialNumberDetail : customFofoLineItem.getSerialNumberDetails()){
648
				for(SerialNumberDetail serialNumberDetail : customFofoLineItem.getSerialNumberDetails()){
Line 657... Line 658...
657
			if(insurance){
658
			if(insurance){
658
				try{
659
				try{
659
					customerDateOfBirth = StringUtils.toDate(createOrderRequest.getCustomerDateOfBirth());
660
					customerDateOfBirth = StringUtils.toDate(createOrderRequest.getCustomerDateOfBirth());
660
				}catch(DateTimeException dateTimeException){
661
				}catch(DateTimeException dateTimeException){
661
					LOGGER.error("Unable to parse dateOfBirth", dateTimeException);
662
					LOGGER.error("Unable to parse dateOfBirth", dateTimeException);
662
					return "error";
663
					throw new ProfitMandiBusinessException("dateOfBirth", createOrderRequest.getCustomerDateOfBirth(), "");
663
				}
664
				}
664
			}
665
			}
665
			
666
			
666
			Customer customer = null;
667
			Customer customer = null;
667
			try{
668
			try{
Line 753... Line 754...
753
					}
754
					}
754
				}
755
				}
755
				List<InventoryItem> inventoryItems = inventoryItemsToBill.get(fofoLineItem.getItemId());
756
				List<InventoryItem> inventoryItems = inventoryItemsToBill.get(fofoLineItem.getItemId());
756
				for(InventoryItem inventoryItem : inventoryItems){
757
				for(InventoryItem inventoryItem : inventoryItems){
757
					inventoryItem.setLastScanType(ScanType.SALE);
758
					inventoryItem.setLastScanType(ScanType.SALE);
758
					try{
-
 
759
						inventoryItemRepository.persist(inventoryItem);
759
					inventoryItemRepository.persist(inventoryItem);
760
					}catch (Exception e) {
-
 
761
						LOGGER.error("Unable to persist InventoryItem : ", e);
-
 
762
					}
-
 
763
						ScanRecord scanRecord = new ScanRecord();
760
					ScanRecord scanRecord = new ScanRecord();
764
					scanRecord.setInventoryItemId(inventoryItem.getId());
761
					scanRecord.setInventoryItemId(inventoryItem.getId());
765
					scanRecord.setFofoId(fofoDetails.getFofoId());
762
					scanRecord.setFofoId(fofoDetails.getFofoId());
766
					//correct this
763
					//correct this
767
					scanRecord.setQuantity(inventoryItemQuantityUsed.get(inventoryItem.getId()));
764
					scanRecord.setQuantity(inventoryItemQuantityUsed.get(inventoryItem.getId()));
768
					scanRecord.setType(ScanType.SALE);
765
					scanRecord.setType(ScanType.SALE);
769
					try{
-
 
770
						scanRecordRepository.persist(scanRecord);
766
					scanRecordRepository.persist(scanRecord);
771
					}catch(Exception exception){
-
 
772
						LOGGER.error("Unable to persist scanRecord", exception);
-
 
773
					}
-
 
774
				}
767
				}
775
			}
768
			}
776
			
769
			
777
			// insurance calculation is insurance flag is enabled
770
			// insurance calculation is insurance flag is enabled
778
			if(!insuranceSerialNumberItemPrice.isEmpty()){
771
			if(!insuranceSerialNumberItemPrice.isEmpty()){