| Line 373... |
Line 373... |
| 373 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
373 |
model.addAttribute("loginResponse", mvcResponseSender.createResponseString("RTLR_1009", false, "/login"));
|
| 374 |
return "response";
|
374 |
return "response";
|
| 375 |
}
|
375 |
}
|
| 376 |
Set<Integer> itemIds = new HashSet<>();
|
376 |
Set<Integer> itemIds = new HashSet<>();
|
| 377 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
377 |
Map<Integer, Integer> itemIdQuantity = new HashMap<>(); //this is for error
|
| 378 |
Map<Integer, CustomFofoLineItem> customFofoLineItemMap = new HashMap<>();
|
378 |
Map<Integer, List<CustomFofoLineItem>> customFofoLineItemMap = new HashMap<>();
|
| 379 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
379 |
Map<Integer, Float> lineItemPrice = new HashMap<>(); //this is for pricing error
|
| 380 |
|
380 |
|
| 381 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>(); //
|
381 |
Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>(); //
|
| 382 |
|
382 |
|
| 383 |
float totalAmount = 0;
|
383 |
float totalAmount = 0;
|
| Line 394... |
Line 394... |
| 394 |
if(serialNumberDetail.isInsurance() && serialNumberDetail.getAmount() > 0){
|
394 |
if(serialNumberDetail.isInsurance() && serialNumberDetail.getAmount() > 0){
|
| 395 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
395 |
totalAmount = totalAmount + serialNumberDetail.getAmount();
|
| 396 |
}
|
396 |
}
|
| 397 |
}
|
397 |
}
|
| 398 |
}
|
398 |
}
|
| - |
|
399 |
|
| - |
|
400 |
List<CustomFofoLineItem> customFofoLineItems;
|
| - |
|
401 |
if(customFofoLineItemMap.containsKey(customFofoLineItem.getItemId())) {
|
| - |
|
402 |
customFofoLineItems = customFofoLineItemMap.get(customFofoLineItem.getItemId());
|
| - |
|
403 |
} else {
|
| - |
|
404 |
customFofoLineItems = new ArrayList<>();
|
| - |
|
405 |
}
|
| 399 |
customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItem);
|
406 |
customFofoLineItemMap.put(customFofoLineItem.getItemId(), customFofoLineItems);
|
| - |
|
407 |
|
| 400 |
Set<String> serialNumbers;
|
408 |
Set<String> serialNumbers;
|
| 401 |
if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
409 |
if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
| 402 |
serialNumbers = new HashSet<>();
|
410 |
serialNumbers = new HashSet<>();
|
| 403 |
} else {
|
411 |
} else {
|
| 404 |
serialNumbers = itemIdSerialNumbers.get(customFofoLineItem.getItemId());
|
412 |
serialNumbers = itemIdSerialNumbers.get(customFofoLineItem.getItemId());
|
| Line 431... |
Line 439... |
| 431 |
// error
|
439 |
// error
|
| 432 |
}
|
440 |
}
|
| 433 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); //this is for error
|
441 |
List<ItemIdQuantityAvailability> itemIdQuantityAvailabilities = new ArrayList<>(); //this is for error
|
| 434 |
LOGGER.info("currentInventorySnapshots "+currentInventorySnapshots);
|
442 |
LOGGER.info("currentInventorySnapshots "+currentInventorySnapshots);
|
| 435 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
443 |
for(CurrentInventorySnapshot currentInventorySnapshot : currentInventorySnapshots){
|
| 436 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(currentInventorySnapshot.getId().getItemId());
|
444 |
List<CustomFofoLineItem> customFofoLineItems = customFofoLineItemMap.get(currentInventorySnapshot.getId().getItemId());
|
| 437 |
LOGGER.info("customFofoLineItem "+customFofoLineItem);
|
445 |
LOGGER.info("customFofoLineItems "+customFofoLineItems);
|
| - |
|
446 |
for (CustomFofoLineItem customFofoLineItem : customFofoLineItems) {
|
| 438 |
if(customFofoLineItem.getQuantity() > currentInventorySnapshot.getAvailability()){
|
447 |
if(customFofoLineItem.getQuantity() > currentInventorySnapshot.getAvailability()){
|
| 439 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
448 |
ItemIdQuantityAvailability itemIdQuantityAvailability = new ItemIdQuantityAvailability();
|
| 440 |
itemIdQuantityAvailability.setItemId(customFofoLineItem.getItemId());
|
449 |
itemIdQuantityAvailability.setItemId(customFofoLineItem.getItemId());
|
| 441 |
Quantity quantity = new Quantity();
|
450 |
Quantity quantity = new Quantity();
|
| 442 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
451 |
quantity.setAvailable(currentInventorySnapshot.getAvailability());
|
| 443 |
quantity.setRequested(customFofoLineItem.getQuantity());
|
452 |
quantity.setRequested(customFofoLineItem.getQuantity());
|
| 444 |
itemIdQuantityAvailability.setQuantity(quantity);
|
453 |
itemIdQuantityAvailability.setQuantity(quantity);
|
| 445 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
454 |
itemIdQuantityAvailabilities.add(itemIdQuantityAvailability);
|
| - |
|
455 |
}
|
| 446 |
}
|
456 |
}
|
| 447 |
|
457 |
|
| 448 |
}
|
458 |
}
|
| 449 |
|
459 |
|
| 450 |
|
460 |
|
| Line 454... |
Line 464... |
| 454 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
464 |
LOGGER.error("Requested quantities should not be greater than currently available quantities {}", itemIdQuantityAvailabilities);
|
| 455 |
throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities, "");
|
465 |
throw new ProfitMandiBusinessException("itemIdQuantityAvailabilities", itemIdQuantityAvailabilities, "");
|
| 456 |
}
|
466 |
}
|
| 457 |
|
467 |
|
| 458 |
|
468 |
|
| 459 |
|
- |
|
| 460 |
// Set<Integer> invalidItemIdSerialNumbers = new HashSet<>();
|
- |
|
| 461 |
// Map<Integer, Set<String>> itemIdSerialNumbers = new HashMap<>();
|
- |
|
| 462 |
// List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdItemIds(fofoDetails.getFofoId(), itemIds); //change it
|
- |
|
| 463 |
//
|
- |
|
| 464 |
// Map<Integer, Float> itemIdPriceDropAmount = new HashMap<>();
|
- |
|
| 465 |
//
|
- |
|
| 466 |
// for(InventoryItem inventoryItem : inventoryItems){
|
- |
|
| 467 |
// CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(inventoryItem.getItemId());
|
- |
|
| 468 |
// if(customFofoLineItem.getSerialNumbers().isEmpty()){
|
- |
|
| 469 |
// if(!(inventoryItem.getSerialNumber() == null && inventoryItem.getSerialNumber().equals(""))){
|
- |
|
| 470 |
// invalidItemIdSerialNumbers.add(inventoryItem.getItemId());
|
- |
|
| 471 |
// }
|
- |
|
| 472 |
// }
|
- |
|
| 473 |
// if(!customFofoLineItem.getSerialNumbers().isEmpty()){
|
- |
|
| 474 |
// if(!customFofoLineItem.getSerialNumbers().contains(inventoryItem.getSerialNumber())){
|
- |
|
| 475 |
// if(!itemIdSerialNumbers.containsKey(customFofoLineItem.getItemId())){
|
- |
|
| 476 |
// Set<String> serialNumbers = new HashSet<>();
|
- |
|
| 477 |
// serialNumbers.add(inventoryItem.getSerialNumber());
|
- |
|
| 478 |
// itemIdSerialNumbers.put(customFofoLineItem.getItemId(), serialNumbers);
|
- |
|
| 479 |
// }else{
|
- |
|
| 480 |
// itemIdSerialNumbers.get(customFofoLineItem.getItemId()).add(inventoryItem.getSerialNumber());
|
- |
|
| 481 |
// }
|
- |
|
| 482 |
// }
|
- |
|
| 483 |
// itemIdPriceDropAmount.put(inventoryItem.getItemId(), inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount());
|
- |
|
| 484 |
// }
|
- |
|
| 485 |
|
- |
|
| 486 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
469 |
Map<Integer, Item> itemMap = new HashMap<Integer, Item>();
|
| 487 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
470 |
List<Item> items = itemRepository.selectByIds(itemIds);
|
| 488 |
for (Item i : items){
|
471 |
for (Item i : items){
|
| 489 |
itemMap.put(i.getId(), i);
|
472 |
itemMap.put(i.getId(), i);
|
| 490 |
}
|
473 |
}
|
| Line 493... |
Line 476... |
| 493 |
Set<String> serialNumbers = new HashSet<>();
|
476 |
Set<String> serialNumbers = new HashSet<>();
|
| 494 |
Map<String, Float> insuranceSerialNumberItemPrice = new HashMap<>();
|
477 |
Map<String, Float> insuranceSerialNumberItemPrice = new HashMap<>();
|
| 495 |
Map<String, Float> insuranceSerialNumberSaleAmount = new HashMap<>();
|
478 |
Map<String, Float> insuranceSerialNumberSaleAmount = new HashMap<>();
|
| 496 |
Map<String, String> serialNumberModelName = new HashMap<>();
|
479 |
Map<String, String> serialNumberModelName = new HashMap<>();
|
| 497 |
Map<String, String> serialNumberBrand = new HashMap<>();
|
480 |
Map<String, String> serialNumberBrand = new HashMap<>();
|
| 498 |
Collection<CustomFofoLineItem> lineItemsValues = customFofoLineItemMap.values();
|
- |
|
| 499 |
for (CustomFofoLineItem cli : lineItemsValues){
|
481 |
for (CustomFofoLineItem cli : createOrderRequest.getFofoLineItems()){
|
| 500 |
|
- |
|
| 501 |
Item item = itemMap.get(cli.getItemId());
|
482 |
Item item = itemMap.get(cli.getItemId());
|
| 502 |
if (item.getType().equals(ItemType.SERIALIZED)){
|
483 |
if (item.getType().equals(ItemType.SERIALIZED)){
|
| 503 |
for (SerialNumberDetail serialNumberDetail : cli.getSerialNumberDetails()){
|
484 |
for (SerialNumberDetail serialNumberDetail : cli.getSerialNumberDetails()){
|
| 504 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
485 |
serialNumbers.add(serialNumberDetail.getSerialNumber());
|
| 505 |
if(serialNumberDetail.isInsurance()){
|
486 |
if(serialNumberDetail.isInsurance()){
|
| Line 560... |
Line 541... |
| 560 |
|
541 |
|
| 561 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
542 |
List<Integer> invalidItemIdSerialNumbers = new ArrayList<Integer>();
|
| 562 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|
543 |
List<Integer> itemIdNonSerializedSerialNumbers = new ArrayList<Integer>();
|
| 563 |
|
544 |
|
| 564 |
for (Item i : items){
|
545 |
for (Item i : items){
|
| 565 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
546 |
List<CustomFofoLineItem> customFofoLineItems = customFofoLineItemMap.get(i.getId());
|
| - |
|
547 |
for(CustomFofoLineItem customFofoLineItem: customFofoLineItems) {
|
| 566 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
548 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
| 567 |
if (customFofoLineItem ==null || customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
549 |
if (customFofoLineItem ==null || customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
| 568 |
invalidItemIdSerialNumbers.add(i.getId());
|
550 |
invalidItemIdSerialNumbers.add(i.getId());
|
| - |
|
551 |
}
|
| 569 |
}
|
552 |
}
|
| 570 |
}
|
- |
|
| 571 |
else{
|
553 |
else{
|
| 572 |
if (customFofoLineItem == null || !customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
554 |
if (customFofoLineItem == null || !customFofoLineItem.getSerialNumberDetails().isEmpty()){
|
| 573 |
itemIdNonSerializedSerialNumbers.add(i.getId());
|
555 |
itemIdNonSerializedSerialNumbers.add(i.getId());
|
| - |
|
556 |
}
|
| 574 |
}
|
557 |
}
|
| 575 |
}
|
558 |
}
|
| 576 |
}
|
559 |
}
|
| 577 |
|
560 |
|
| 578 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
561 |
if(!invalidItemIdSerialNumbers.isEmpty()){
|
| Line 597... |
Line 580... |
| 597 |
Map<Integer, Integer> inventoryItemQuantityUsed = new HashMap<>(); //to keep track of inventoryitem quanity used for scan records insertion
|
580 |
Map<Integer, Integer> inventoryItemQuantityUsed = new HashMap<>(); //to keep track of inventoryitem quanity used for scan records insertion
|
| 598 |
|
581 |
|
| 599 |
LOGGER.info("itemMap keys {}", itemMap.keySet());
|
582 |
LOGGER.info("itemMap keys {}", itemMap.keySet());
|
| 600 |
//Lets reduce quantity and decide what inventory items to use.
|
583 |
//Lets reduce quantity and decide what inventory items to use.
|
| 601 |
for (Item i : items){
|
584 |
for (Item i : items){
|
| 602 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(i.getId());
|
- |
|
| 603 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
585 |
if (i.getType().equals(ItemType.SERIALIZED)){
|
| 604 |
//TODO:handle null
|
586 |
//TODO:handle null
|
| 605 |
if (serializedInventoryItemMap.get(i.getId()) == null || customFofoLineItem.getSerialNumberDetails().size() != serializedInventoryItemMap.get(i.getId()).size()){
|
587 |
if (serializedInventoryItemMap.get(i.getId()) == null || customFofoLineItemMap.get(i.getId()).size() != serializedInventoryItemMap.get(i.getId()).size()){
|
| 606 |
//not enough serial numbers
|
588 |
//not enough serial numbers
|
| 607 |
//LOGGER.info("serialNumbers {}", serialNumbers);
|
589 |
//LOGGER.info("serialNumbers {}", serialNumbers);
|
| 608 |
LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
|
590 |
LOGGER.info("serializedInventoryItemMap {}", serializedInventoryItemMap);
|
| 609 |
LOGGER.info("itemId {}", i.getId());
|
591 |
LOGGER.info("itemId {}", i.getId());
|
| 610 |
LOGGER.error("not enough serial numbers");
|
592 |
LOGGER.error("not enough serial numbers");
|
| Line 617... |
Line 599... |
| 617 |
}
|
599 |
}
|
| 618 |
inventoryItemsToBill.put(i.getId(), inventoryItemsSerializedserialized);
|
600 |
inventoryItemsToBill.put(i.getId(), inventoryItemsSerializedserialized);
|
| 619 |
}
|
601 |
}
|
| 620 |
else{
|
602 |
else{
|
| 621 |
List<InventoryItem> inventoryItemsNonSerialized = nonSerializedInventoryItemMap.get(i.getId());
|
603 |
List<InventoryItem> inventoryItemsNonSerialized = nonSerializedInventoryItemMap.get(i.getId());
|
| 622 |
int quantityToBill = customFofoLineItem.getQuantity();
|
604 |
int quantityToBill = customFofoLineItemMap.get(i.getId()).get(0).getQuantity();
|
| 623 |
int totalLeft = quantityToBill;
|
605 |
int totalLeft = quantityToBill;
|
| 624 |
List<InventoryItem> inventoryItemsNonSerializedUsed = new ArrayList<InventoryItem>();
|
606 |
List<InventoryItem> inventoryItemsNonSerializedUsed = new ArrayList<InventoryItem>();
|
| 625 |
if (inventoryItemsNonSerialized!=null){
|
607 |
if (inventoryItemsNonSerialized!=null){
|
| 626 |
for (InventoryItem it : inventoryItemsNonSerialized){
|
608 |
for (InventoryItem it : inventoryItemsNonSerialized){
|
| 627 |
if (totalLeft > 0){
|
609 |
if (totalLeft > 0){
|
| Line 634... |
Line 616... |
| 634 |
}
|
616 |
}
|
| 635 |
}
|
617 |
}
|
| 636 |
|
618 |
|
| 637 |
if (totalLeft > 0){
|
619 |
if (totalLeft > 0){
|
| 638 |
//not enough quanity for non-serialized
|
620 |
//not enough quanity for non-serialized
|
| 639 |
System.out.println("not enough quanity for non-serialized");
|
621 |
LOGGER.error("not enough quanity for non-serialized");
|
| 640 |
throw new ProfitMandiBusinessException("notEnoughQuantityForNonSerialized", "", "");
|
622 |
throw new ProfitMandiBusinessException("notEnoughQuantityForNonSerialized", "", "");
|
| 641 |
}
|
623 |
}
|
| 642 |
inventoryItemsToBill.put(i.getId(), inventoryItemsNonSerializedUsed);
|
624 |
inventoryItemsToBill.put(i.getId(), inventoryItemsNonSerializedUsed);
|
| 643 |
}
|
625 |
}
|
| 644 |
}
|
626 |
}
|
| Line 646... |
Line 628... |
| 646 |
// mop price validation
|
628 |
// mop price validation
|
| 647 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
629 |
Map<Integer, Float> invalidMopItemIdPriceMap = new HashMap<>();
|
| 648 |
Map<Integer, Float> invalidDiscountAmountMap = new HashMap<>();
|
630 |
Map<Integer, Float> invalidDiscountAmountMap = new HashMap<>();
|
| 649 |
Map<Integer, PriceModel> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
631 |
Map<Integer, PriceModel> itemIdMopPriceMap = pricingService.getPurchasePriceMopPriceNotFound(itemIds, fofoDetails.getFofoId());
|
| 650 |
for(Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()){
|
632 |
for(Map.Entry<Integer, PriceModel> entry : itemIdMopPriceMap.entrySet()){
|
| 651 |
CustomFofoLineItem customFofoLineItem = customFofoLineItemMap.get(entry.getKey());
|
633 |
List<CustomFofoLineItem>customFofoLineItems = customFofoLineItemMap.get(entry.getKey());
|
| - |
|
634 |
for(CustomFofoLineItem customFofoLineItem : customFofoLineItems) {
|
| 652 |
if(entry.getValue().getPrice() < Float.MAX_VALUE && customFofoLineItem.getSellingPrice() < entry.getValue().getPrice()){
|
635 |
if(entry.getValue().getPrice() < Float.MAX_VALUE && customFofoLineItem.getSellingPrice() < entry.getValue().getPrice()){
|
| 653 |
invalidMopItemIdPriceMap.put(entry.getKey(), customFofoLineItem.getSellingPrice());
|
636 |
invalidMopItemIdPriceMap.put(entry.getKey(), customFofoLineItem.getSellingPrice());
|
| 654 |
}
|
637 |
}
|
| 655 |
if(entry.getValue().isMop() && customFofoLineItem.getDiscountAmount() > entry.getValue().getMaxDiscountAmount()){
|
638 |
if(entry.getValue().isMop() && customFofoLineItem.getDiscountAmount() > entry.getValue().getMaxDiscountAmount()){
|
| 656 |
invalidDiscountAmountMap.put(entry.getKey(), customFofoLineItem.getDiscountAmount());
|
639 |
invalidDiscountAmountMap.put(entry.getKey(), customFofoLineItem.getDiscountAmount());
|
| - |
|
640 |
}
|
| 657 |
}
|
641 |
}
|
| 658 |
}
|
642 |
}
|
| 659 |
|
643 |
|
| 660 |
if(!invalidMopItemIdPriceMap.isEmpty()){
|
644 |
if(!invalidMopItemIdPriceMap.isEmpty()){
|
| 661 |
LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}", invalidMopItemIdPriceMap, itemIdMopPriceMap);
|
645 |
LOGGER.error("Invalid itemIds selling prices{} should be greater than mop prices {}", invalidMopItemIdPriceMap, itemIdMopPriceMap);
|