| Line 372... |
Line 372... |
| 372 |
}
|
372 |
}
|
| 373 |
Set<Integer> itemIds = new HashSet<>();
|
373 |
Set<Integer> itemIds = new HashSet<>();
|
| 374 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
374 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
| 375 |
Map<Integer, CustomFofoLineItem> customFofoLineItemMap = new HashMap<>();
|
375 |
Map<Integer, CustomFofoLineItem> customFofoLineItemMap = new HashMap<>();
|
| 376 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
376 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
| - |
|
377 |
|
| - |
|
378 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>(); //
|
| - |
|
379 |
|
| 377 |
float totalAmount = 0;
|
380 |
float totalAmount = 0;
|
| 378 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
381 |
for(CustomFofoLineItem customFofoLineItem : createOrderRequest.getFofoLineItems()){
|
| 379 |
itemIds.add(customFofoLineItem.getItemId());
|
382 |
itemIds.add(customFofoLineItem.getItemId());
|
| 380 |
if(!customFofoLineItem.getSerialNumberDetails().isEmpty() && customFofoLineItem.getQuantity() != customFofoLineItem.getSerialNumberDetails().size()){
|
383 |
if(!customFofoLineItem.getSerialNumberDetails().isEmpty() && customFofoLineItem.getQuantity() != customFofoLineItem.getSerialNumberDetails().size()){
|
| 381 |
itemIdQuantity.put(customFofoLineItem.getItemId(), customFofoLineItem.getQuantity());
|
384 |
itemIdQuantity.put(customFofoLineItem.getItemId(), customFofoLineItem.getQuantity());
|
| Line 389... |
Line 392... |
| 389 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
392 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
| 390 |
}
|
393 |
}
|
| 391 |
}
|
394 |
}
|
| 392 |
}
|
395 |
}
|
| 393 |
customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItem);
|
396 |
customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItem);
|
| - |
|
397 |
if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
| - |
|
398 |
Set<String> serialNumbers = new HashSet<>();
|
| - |
|
399 |
for(SerialNumberDetail serialNumberDetail : customFofoLineItem.getSerialNumberDetails()){
|
| - |
|
400 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
| - |
|
401 |
}
|
| - |
|
402 |
|
| - |
|
403 |
itemIdSerialNumbers.put(customFofoLineItem.getItemId(), serialNumbers);
|
| - |
|
404 |
}
|
| 394 |
}
|
405 |
}
|
| 395 |
if(!itemIdQuantity.isEmpty()){
|
406 |
if(!itemIdQuantity.isEmpty()){
|
| 396 |
// if item quantity does not match with given serialnumbers size
|
407 |
// if item quantity does not match with given serialnumbers size
|
| 397 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
408 |
LOGGER.error("itemId's quantity should be equal to given serialnumber size {} ", itemIdQuantity);
|
| 398 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "");
|
409 |
throw new ProfitMandiBusinessException("itemIdQuantity", itemIdQuantity, "");
|
| Line 495... |
Line 506... |
| 495 |
}
|
506 |
}
|
| 496 |
}
|
507 |
}
|
| 497 |
else{
|
508 |
else{
|
| 498 |
nonSerializedItemIds.add(cli.getItemId());
|
509 |
nonSerializedItemIds.add(cli.getItemId());
|
| 499 |
}
|
510 |
}
|
| 500 |
|
- |
|
| 501 |
}
|
511 |
}
|
| 502 |
|
512 |
|
| 503 |
|
- |
|
| 504 |
Map<Integer, List<InventoryItem>> serializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
513 |
Map<Integer, List<InventoryItem>> serializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
| 505 |
Map<Integer, List<InventoryItem>> nonSerializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
514 |
Map<Integer, List<InventoryItem>> nonSerializedInventoryItemMap = new HashMap<Integer, List<InventoryItem>>();
|
| 506 |
Map<Integer, List<Float>> itemIdPriceDropAmount = new HashMap<>();
|
515 |
Map<Integer, List<Float>> itemIdPriceDropAmount = new HashMap<>();
|
| - |
|
516 |
//Map<String, Float> serialNumberItemPrice = new HashMap<>();
|
| 507 |
|
517 |
|
| 508 |
if (!serialNumbers.isEmpty()){
|
518 |
if (!serialNumbers.isEmpty()){
|
| 509 |
List<InventoryItem> serializedInventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoDetails.getFofoId(), serialNumbers);
|
519 |
List<InventoryItem> serializedInventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoDetails.getFofoId(), serialNumbers);
|
| 510 |
LOGGER.info("serializedInventoryItems {}", serializedInventoryItems);
|
520 |
LOGGER.info("serializedInventoryItems {}", serializedInventoryItems);
|
| 511 |
for (InventoryItem it : serializedInventoryItems){
|
521 |
for (InventoryItem it : serializedInventoryItems){
|
| 512 |
if (it.getGoodQuantity() == 1){
|
522 |
if (it.getGoodQuantity() == 1){
|
| Line 542... |
Line 552... |
| 542 |
}
|
552 |
}
|
| 543 |
}
|
553 |
}
|
| 544 |
}
|
554 |
}
|
| 545 |
|
555 |
|
| 546 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
556 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
| 547 |
List<Integer> itemIdSerialNumbers = new ArrayList<Integer>();
|
557 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|
| 548 |
|
558 |
|
| 549 |
for (Item i : items){
|
559 |
for (Item i : items){
|
| 550 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
560 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
| 551 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
561 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
| 552 |
if (customFofoLineItem ==null || customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
562 |
if (customFofoLineItem ==null || customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
| 553 |
invalidItemIdSerialNumbers.add(i.getId());
|
563 |
invalidItemIdSerialNumbers.add(i.getId());
|
| 554 |
}
|
564 |
}
|
| 555 |
}
|
565 |
}
|
| 556 |
else{
|
566 |
else{
|
| 557 |
if (customFofoLineItem == null || !customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
567 |
if (customFofoLineItem == null || !customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
| 558 |
itemIdSerialNumbers.add(i.getId());
|
568 |
itemIdNonSerializedSerialNumbers.add(i.getId());
|
| 559 |
}
|
569 |
}
|
| 560 |
}
|
570 |
}
|
| 561 |
}
|
571 |
}
|
| 562 |
|
572 |
|
| 563 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
573 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
| 564 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
574 |
LOGGER.error("Invalid itemId's serialNumbers {}", invalidItemIdSerialNumbers);
|
| 565 |
// itemId's are serialized you are saying these are not serialized
|
575 |
// itemId's are serialized you are saying these are not serialized
|
| 566 |
throw new ProfitMandiBusinessException("invalidItemIdSerialNumbers", invalidItemIdSerialNumbers, "");
|
576 |
throw new ProfitMandiBusinessException("invalidItemIdSerialNumbers", invalidItemIdSerialNumbers, "");
|
| 567 |
}
|
577 |
}
|
| 568 |
|
578 |
|
| 569 |
if(!itemIdSerialNumbers.isEmpty()){
|
579 |
if(!itemIdNonSerializedSerialNumbers.isEmpty()){
|
| 570 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdSerialNumbers);
|
580 |
LOGGER.error("Invalid itemId's serialNumbers {}", itemIdNonSerializedSerialNumbers);
|
| 571 |
// itemId's are non serialized you are saying these are serialized
|
581 |
// itemId's are non serialized you are saying these are serialized
|
| 572 |
throw new ProfitMandiBusinessException("itemIdSerialNumbers", itemIdSerialNumbers, "");
|
582 |
throw new ProfitMandiBusinessException("itemIdNonSerializedSerialNumbers", itemIdNonSerializedSerialNumbers, "");
|
| 573 |
}
|
583 |
}
|
| 574 |
|
584 |
|
| 575 |
if(items.size() != itemIds.size()){
|
585 |
if(items.size() != itemIds.size()){
|
| 576 |
LOGGER.error("Requested ItemIds not found in catalog");
|
586 |
LOGGER.error("Requested ItemIds not found in catalog");
|
| 577 |
// invalid itemIds
|
587 |
// invalid itemIds
|
| Line 820... |
Line 830... |
| 820 |
if(!invalidInsuranceSalePurchaseAmount.isEmpty()){
|
830 |
if(!invalidInsuranceSalePurchaseAmount.isEmpty()){
|
| 821 |
LOGGER.error("Invalid Insurance prices [{}], insurance sale amount can not be greater than than insurance max amount", invalidInsuranceSalePurchaseAmount);
|
831 |
LOGGER.error("Invalid Insurance prices [{}], insurance sale amount can not be greater than than insurance max amount", invalidInsuranceSalePurchaseAmount);
|
| 822 |
return "error";
|
832 |
return "error";
|
| 823 |
}
|
833 |
}
|
| 824 |
|
834 |
|
| - |
|
835 |
Map<Float, Float> invalidInsuranceMarginAmount = new HashMap<>();
|
| - |
|
836 |
|
| - |
|
837 |
for(Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()){
|
| - |
|
838 |
int itemId = this.getItemIdFromSerialNumber(itemIdSerialNumbers, entry.getKey());
|
| - |
|
839 |
float itemPurchasePrice = itemIdMopPriceMap.get(itemId);
|
| - |
|
840 |
float itemSellingPrice = entry.getValue();
|
| - |
|
841 |
float itemMargin = itemSellingPrice - itemPurchasePrice;
|
| - |
|
842 |
float insurancePurchasePrice = insurancePricesMap.get(entry.getValue()).getDealerPrice();
|
| - |
|
843 |
float insuranceSellingPrice = insuranceSerialNumberSaleAmount.get(entry.getKey());
|
| - |
|
844 |
float insuranceMargin = insuranceSellingPrice - insurancePurchasePrice;
|
| - |
|
845 |
|
| - |
|
846 |
if(insuranceMargin < (itemMargin * 30 / 100)){
|
| - |
|
847 |
invalidInsuranceMarginAmount.put(insuranceMargin, (itemMargin * 30 / 100));
|
| - |
|
848 |
}
|
| - |
|
849 |
}
|
| - |
|
850 |
|
| - |
|
851 |
if(!invalidInsuranceMarginAmount.isEmpty()){
|
| - |
|
852 |
LOGGER.error("insurance marging should be greater than equal to item profit margin insuranceMarginItemIdMargin {}", invalidInsuranceMarginAmount);
|
| - |
|
853 |
}
|
| - |
|
854 |
|
| 825 |
|
855 |
|
| 826 |
for(Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()){
|
856 |
for(Map.Entry<String, Float> entry : insuranceSerialNumberItemPrice.entrySet()){
|
| 827 |
PolicyNumberGenerationSequence policyNumberGenerationSequence = null;
|
857 |
PolicyNumberGenerationSequence policyNumberGenerationSequence = null;
|
| 828 |
try{
|
858 |
try{
|
| 829 |
policyNumberGenerationSequence = policyNumberGenerationSequenceRepository.select();
|
859 |
policyNumberGenerationSequence = policyNumberGenerationSequenceRepository.select();
|
| Line 885... |
Line 915... |
| 885 |
}
|
915 |
}
|
| 886 |
}
|
916 |
}
|
| 887 |
LOGGER.info("Order has been created successfully...");
|
917 |
LOGGER.info("Order has been created successfully...");
|
| 888 |
return "redirect:/get-order/?orderId="+fofoOrder.getId();
|
918 |
return "redirect:/get-order/?orderId="+fofoOrder.getId();
|
| 889 |
}
|
919 |
}
|
| - |
|
920 |
|
| - |
|
921 |
private int getItemIdFromSerialNumber(Map<Integer, Set<String>> itemIdSerialNumbers, String serialNumber){
|
| - |
|
922 |
for(Map.Entry<Integer, Set<String>> entry : itemIdSerialNumbers.entrySet()){
|
| - |
|
923 |
if(entry.getValue().contains(serialNumber)){
|
| - |
|
924 |
return entry.getKey();
|
| - |
|
925 |
}
|
| - |
|
926 |
}
|
| - |
|
927 |
return 0;
|
| - |
|
928 |
}
|
| 890 |
|
929 |
|
| 891 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
930 |
private CustomerAddress createCustomerAddress(CustomAddress customAddress){
|
| 892 |
CustomerAddress customerAddress = new CustomerAddress();
|
931 |
CustomerAddress customerAddress = new CustomerAddress();
|
| 893 |
customerAddress.setName(customAddress.getName());
|
932 |
customerAddress.setName(customAddress.getName());
|
| 894 |
customerAddress.setLine1(customAddress.getLine1());
|
933 |
customerAddress.setLine1(customAddress.getLine1());
|