| Line 343... |
Line 343... |
| 343 |
if (scheme.getExpireTimestamp() != null) {
|
343 |
if (scheme.getExpireTimestamp() != null) {
|
| 344 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(),
|
344 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(),
|
| 345 |
"SCHM_1008");
|
345 |
"SCHM_1008");
|
| 346 |
}
|
346 |
}
|
| 347 |
scheme.setExpireTimestamp(LocalDateTime.now());
|
347 |
scheme.setExpireTimestamp(LocalDateTime.now());
|
| 348 |
if(expiryTime.isAfter(scheme.getEndDateTime())) {
|
348 |
if (expiryTime.isAfter(scheme.getEndDateTime())) {
|
| 349 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(),
|
349 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.EXPIRE_TIMESTAMP, scheme.getExpireTimestamp(),
|
| 350 |
"End Date cant be extended during expiry");
|
350 |
"End Date cant be extended during expiry");
|
| 351 |
}
|
351 |
}
|
| 352 |
scheme.setEndDateTime(expiryTime);
|
352 |
scheme.setEndDateTime(expiryTime);
|
| 353 |
schemeRepository.persist(scheme);
|
353 |
schemeRepository.persist(scheme);
|
| Line 405... |
Line 405... |
| 405 |
|
405 |
|
| 406 |
@Override
|
406 |
@Override
|
| 407 |
public void processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
|
407 |
public void processSchemeIn(int purchaseId, int retailerId) throws ProfitMandiBusinessException {
|
| 408 |
LOGGER.info("Trying to process SchemeIn with purchaseId [{}] and retailerId [{}]", purchaseId, retailerId);
|
408 |
LOGGER.info("Trying to process SchemeIn with purchaseId [{}] and retailerId [{}]", purchaseId, retailerId);
|
| 409 |
Purchase purchase = purchaseRepository.selectByIdAndFofoId(purchaseId, retailerId);
|
409 |
Purchase purchase = purchaseRepository.selectByIdAndFofoId(purchaseId, retailerId);
|
| 410 |
//TODO - SCHEME
|
410 |
// TODO - SCHEME
|
| 411 |
//PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId, YearMonth.from(purchase.getCreateTimestamp()));
|
411 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId,
|
| - |
|
412 |
YearMonth.from(purchase.getCreateTimestamp()));
|
| 412 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, purchase.getCreateTimestamp().toLocalDate());
|
413 |
// PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
|
| - |
|
414 |
// purchase.getCreateTimestamp().toLocalDate());
|
| 413 |
|
415 |
|
| 414 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN, partnerType,
|
416 |
List<Scheme> schemes = schemeRepository.selectActiveAll(Arrays.asList(SchemeType.IN), partnerType,
|
| 415 |
purchase.getCreateTimestamp(), false);
|
417 |
purchase.getCreateTimestamp(), false);
|
| 416 |
float totalCashback = 0;
|
418 |
float totalCashback = 0;
|
| 417 |
if (schemes.isEmpty()) {
|
419 |
if (schemes.isEmpty()) {
|
| 418 |
return;
|
420 |
return;
|
| 419 |
}
|
421 |
}
|
| Line 476... |
Line 478... |
| 476 |
purchaseRepository.persist(purchase);
|
478 |
purchaseRepository.persist(purchase);
|
| 477 |
}
|
479 |
}
|
| 478 |
}
|
480 |
}
|
| 479 |
|
481 |
|
| 480 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) {
|
482 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) {
|
| 481 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAll(inventoryItem.getId());
|
483 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllByType(scheme.getType(), inventoryItem.getId());
|
| 482 |
float amountToCredit = 0;
|
484 |
float actualCredit = 0;
|
| 483 |
if (schemeInOuts.stream().filter(x -> x.getRolledBackTimestamp() == null && x.getSchemeId()==scheme.getId()).collect(Collectors.toList())
|
485 |
if (sios.stream().filter(x -> x.getRolledBackTimestamp() == null && x.getSchemeId() == scheme.getId())
|
| - |
|
486 |
.collect(Collectors.toList()).size() == 0) {
|
| - |
|
487 |
|
| - |
|
488 |
float amountToCredit = this.getAmount(inventoryItem, scheme);
|
| - |
|
489 |
|
| - |
|
490 |
if (!scheme.getType().equals(SchemeType.IN) && sios.size() > 0) {
|
| - |
|
491 |
|
| 484 |
.size() == 0) {
|
492 |
if(sios.size() > 1) {
|
| - |
|
493 |
LOGGER.info("SAMESCHEMETYPE has already been credited twice for inventoryItem - {}", inventoryItem.getId());
|
| - |
|
494 |
return 0;
|
| - |
|
495 |
}
|
| - |
|
496 |
float amountCredited = (float) sios.stream().mapToDouble(e -> e.getAmount()).sum();
|
| - |
|
497 |
if(amountToCredit > amountCredited + 1f) {
|
| - |
|
498 |
for (SchemeInOut sio : sios) {
|
| - |
|
499 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
| - |
|
500 |
sio.setStatus(SchemePayoutStatus.REJECTED);
|
| - |
|
501 |
sio.setStatusDescription("Partner Category upgraded, new entry added");
|
| - |
|
502 |
}
|
| - |
|
503 |
actualCredit = amountToCredit - amountCredited;
|
| - |
|
504 |
} else {
|
| - |
|
505 |
return 0;
|
| - |
|
506 |
}
|
| - |
|
507 |
} else {
|
| - |
|
508 |
actualCredit = amountToCredit;
|
| - |
|
509 |
}
|
| - |
|
510 |
|
| 485 |
SchemeInOut schemeInOut = new SchemeInOut();
|
511 |
SchemeInOut schemeInOut = new SchemeInOut();
|
| 486 |
amountToCredit = this.getAmount(inventoryItem, scheme);
|
- |
|
| 487 |
schemeInOut.setSchemeId(scheme.getId());
|
512 |
schemeInOut.setSchemeId(scheme.getId());
|
| 488 |
schemeInOut.setInventoryItemId(inventoryItem.getId());
|
513 |
schemeInOut.setInventoryItemId(inventoryItem.getId());
|
| 489 |
schemeInOut.setAmount(amountToCredit);
|
514 |
schemeInOut.setAmount(amountToCredit);
|
| 490 |
schemeInOutRepository.persist(schemeInOut);
|
515 |
schemeInOutRepository.persist(schemeInOut);
|
| - |
|
516 |
|
| 491 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
517 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
| 492 |
schemeInOut.setStatus(SchemePayoutStatus.PENDING);
|
518 |
schemeInOut.setStatus(SchemePayoutStatus.PENDING);
|
| 493 |
schemeInOut.setStatusDescription("Activation pending for IMEI#" + inventoryItem.getSerialNumber());
|
519 |
schemeInOut.setStatusDescription("Activation pending for IMEI#" + inventoryItem.getSerialNumber());
|
| 494 |
return 0;
|
520 |
return 0;
|
| 495 |
} else if (scheme.getType().equals(SchemeType.INVESTMENT)) {
|
521 |
} else if (scheme.getType().equals(SchemeType.INVESTMENT)) {
|
| Line 498... |
Line 524... |
| 498 |
return 0;
|
524 |
return 0;
|
| 499 |
} else {
|
525 |
} else {
|
| 500 |
schemeInOut.setStatus(SchemePayoutStatus.CREDITED);
|
526 |
schemeInOut.setStatus(SchemePayoutStatus.CREDITED);
|
| 501 |
if (scheme.getType().equals(SchemeType.IN)) {
|
527 |
if (scheme.getType().equals(SchemeType.IN)) {
|
| 502 |
schemeInOut.setStatusDescription("Credited for GRN of IMEI#" + inventoryItem.getSerialNumber());
|
528 |
schemeInOut.setStatusDescription("Credited for GRN of IMEI#" + inventoryItem.getSerialNumber());
|
| 503 |
} else if(scheme.getType().equals(SchemeType.OUT) || scheme.getType().equals(SchemeType.CATEGORY)){
|
529 |
} else if (SchemeService.OUT_SCHEME_TYPES.contains(scheme.getType())) {
|
| 504 |
schemeInOut.setStatusDescription("Credited for sale of IMEI#" + inventoryItem.getSerialNumber());
|
530 |
schemeInOut.setStatusDescription("Credited for sale of IMEI#" + inventoryItem.getSerialNumber());
|
| 505 |
if(scheme.getType().equals(SchemeType.CATEGORY)) {
|
- |
|
| 506 |
|
- |
|
| 507 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllByType(SchemeType.CATEGORY, inventoryItem.getId());
|
- |
|
| 508 |
SchemeInOut sio = sios.stream().filter(x->x.getId()!=schemeInOut.getId()).findFirst().orElse(null);
|
- |
|
| 509 |
if(sio != null) {
|
- |
|
| 510 |
sio.setRolledBackTimestamp(LocalDateTime.now());
|
- |
|
| 511 |
sio.setStatus(SchemePayoutStatus.REJECTED);
|
- |
|
| 512 |
sio.setStatusDescription("Category upgraded, new entry added");
|
- |
|
| 513 |
amountToCredit -= sio.getAmount();
|
- |
|
| 514 |
schemeInOut.setStatusDescription("Category upgraded, higher margins credited for sale of IMEI#" + inventoryItem.getSerialNumber());
|
- |
|
| 515 |
}
|
- |
|
| 516 |
}
|
- |
|
| 517 |
|
- |
|
| 518 |
}
|
531 |
}
|
| 519 |
schemeInOut.setCreditTimestamp(LocalDateTime.now());
|
532 |
schemeInOut.setCreditTimestamp(LocalDateTime.now());
|
| 520 |
}
|
533 |
}
|
| 521 |
}
|
534 |
}
|
| 522 |
return amountToCredit;
|
535 |
return actualCredit;
|
| 523 |
}
|
536 |
}
|
| 524 |
|
537 |
|
| 525 |
// We are maintaining price drop after grn
|
538 |
// We are maintaining price drop after grn
|
| 526 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
539 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
| 527 |
float amount = 0;
|
540 |
float amount = 0;
|
| Line 563... |
Line 576... |
| 563 |
}
|
576 |
}
|
| 564 |
|
577 |
|
| 565 |
@Override
|
578 |
@Override
|
| 566 |
public void processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
|
579 |
public void processSchemeOut(int fofoOrderId, int retailerId) throws ProfitMandiBusinessException {
|
| 567 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(retailerId, fofoOrderId);
|
580 |
FofoOrder fofoOrder = fofoOrderRepository.selectByFofoIdAndOrderId(retailerId, fofoOrderId);
|
| 568 |
//Process only if order is not cancelled
|
581 |
// Process only if order is not cancelled
|
| 569 |
if(fofoOrder.getCancelledTimestamp()==null) {
|
582 |
if (fofoOrder.getCancelledTimestamp() == null) {
|
| 570 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, fofoOrder.getCreateTimestamp().toLocalDate());
|
583 |
// PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
|
| - |
|
584 |
// fofoOrder.getCreateTimestamp().toLocalDate());
|
| 571 |
//TODO - SCHEME
|
585 |
// TODO - SCHEME
|
| 572 |
//PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId, YearMonth.from(fofoOrder.getCreateTimestamp()));
|
586 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnMonth(retailerId,
|
| - |
|
587 |
YearMonth.from(fofoOrder.getCreateTimestamp()));
|
| 573 |
|
588 |
|
| 574 |
List<ScanRecord> scanRecords = scanRecordRepository.selectAllByOrderId(fofoOrderId);
|
589 |
List<ScanRecord> scanRecords = scanRecordRepository.selectAllByOrderId(fofoOrderId);
|
| 575 |
Set<Integer> inventoryItemIds = scanRecords.stream().map(x -> x.getInventoryItemId())
|
590 |
Set<Integer> inventoryItemIds = scanRecords.stream().map(x -> x.getInventoryItemId())
|
| 576 |
.collect(Collectors.toSet());
|
591 |
.collect(Collectors.toSet());
|
| 577 |
Set<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds).stream()
|
592 |
Set<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIds).stream()
|
| 578 |
.filter(x -> x.getSerialNumber() != null && !x.getSerialNumber().equals(""))
|
593 |
.filter(x -> x.getSerialNumber() != null && !x.getSerialNumber().equals(""))
|
| 579 |
.collect(Collectors.toSet());
|
594 |
.collect(Collectors.toSet());
|
| 580 |
if (inventoryItems.size() == 0) {
|
595 |
if (inventoryItems.size() == 0) {
|
| 581 |
return;
|
596 |
return;
|
| 582 |
}
|
597 |
}
|
| 583 |
Set<Integer> itemIds = inventoryItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
598 |
Set<Integer> itemIds = inventoryItems.stream().map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 584 |
|
599 |
|
| 585 |
//Remove Items that are eol now.
|
600 |
// Remove Items that are eol now.
|
| 586 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
601 |
Set<Integer> itemIdsSet = tagListingRepository.selectByItemIdsAndTagIds(itemIds, tagIds).stream()
|
| 587 |
.filter(x -> x.getEolDate() == null || x.getEolDate().isAfter(fofoOrder.getCreateTimestamp()))
|
602 |
.filter(x -> x.getEolDate() == null || x.getEolDate().isAfter(fofoOrder.getCreateTimestamp()))
|
| 588 |
.map(x -> x.getItemId()).collect(Collectors.toSet());
|
603 |
.map(x -> x.getItemId()).collect(Collectors.toSet());
|
| 589 |
// Only consider inventory items that were not returned
|
604 |
// Only consider inventory items that were not returned
|
| 590 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
605 |
inventoryItems = inventoryItems.stream().filter(x -> itemIdsSet.contains(x.getItemId()))
|
| 591 |
.collect(Collectors.toSet());
|
606 |
.collect(Collectors.toSet());
|
| 592 |
|
607 |
|
| 593 |
if (inventoryItems.size() == 0) {
|
608 |
if (inventoryItems.size() == 0) {
|
| 594 |
return;
|
609 |
return;
|
| 595 |
}
|
610 |
}
|
| 596 |
|
611 |
|
| 597 |
float totalCashback = 0;
|
612 |
float totalCashback = 0;
|
| 598 |
int count = 0;
|
613 |
int count = 0;
|
| - |
|
614 |
|
| - |
|
615 |
List<SchemeType> allOutSchemeTypes = new ArrayList<>();
|
| - |
|
616 |
allOutSchemeTypes.addAll(Arrays.asList(SchemeType.ACTIVATION, SchemeType.INVESTMENT));
|
| - |
|
617 |
allOutSchemeTypes.addAll(OUT_SCHEME_TYPES);
|
| 599 |
|
618 |
|
| 600 |
List<Scheme> allActiveSchemes = schemeRepository.selectActiveAll(SchemeType.OUT, partnerType,
|
619 |
List<Scheme> allActiveSchemes = schemeRepository.selectActiveAll(allOutSchemeTypes, partnerType,
|
| 601 |
fofoOrder.getCreateTimestamp(), false);
|
620 |
fofoOrder.getCreateTimestamp(), false);
|
| 602 |
allActiveSchemes.addAll(schemeRepository.selectActiveAll(SchemeType.ACTIVATION, partnerType,
|
- |
|
| 603 |
fofoOrder.getCreateTimestamp(), false));
|
- |
|
| 604 |
allActiveSchemes.addAll(schemeRepository.selectActiveAll(SchemeType.INVESTMENT, partnerType,
|
- |
|
| 605 |
fofoOrder.getCreateTimestamp(), false));
|
- |
|
| 606 |
allActiveSchemes.addAll(schemeRepository.selectActiveAll(SchemeType.CATEGORY, partnerType,
|
- |
|
| 607 |
fofoOrder.getCreateTimestamp(), false));
|
- |
|
| 608 |
|
621 |
|
| 609 |
for (InventoryItem inventoryItem : inventoryItems) {
|
622 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 610 |
float itemCashback = 0;
|
623 |
float itemCashback = 0;
|
| 611 |
Set<Integer> schemeIds = new HashSet<>(
|
624 |
Set<Integer> schemeIds = new HashSet<>(
|
| 612 |
schemeItemRepository.selectSchemeIdByItemId(inventoryItem.getItemId()));
|
625 |
schemeItemRepository.selectSchemeIdByItemId(inventoryItem.getItemId()));
|
| 613 |
allActiveSchemes = allActiveSchemes.stream().filter(x -> schemeIds.contains(x.getId()))
|
626 |
List<Scheme> itemActiveSchemes = allActiveSchemes.stream().filter(x -> schemeIds.contains(x.getId()))
|
| 614 |
.collect(Collectors.toList());
|
627 |
.collect(Collectors.toList());
|
| 615 |
for (Scheme scheme : allActiveSchemes) {
|
628 |
for (Scheme scheme : itemActiveSchemes) {
|
| 616 |
itemCashback += this.createSchemeInOut(scheme, inventoryItem);
|
629 |
itemCashback += this.createSchemeInOut(scheme, inventoryItem);
|
| 617 |
}
|
630 |
}
|
| 618 |
if (itemCashback > 0) {
|
631 |
if (itemCashback > 0) {
|
| 619 |
count++;
|
632 |
count++;
|
| 620 |
totalCashback += itemCashback;
|
633 |
totalCashback += itemCashback;
|
| 621 |
}
|
634 |
}
|
| 622 |
}
|
635 |
}
|
| 623 |
if (count > 0) {
|
636 |
if (count > 0) {
|
| - |
|
637 |
walletService.addAmountToWallet(
|
| 624 |
walletService.addAmountToWallet(retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT,
|
638 |
retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT, "Sales margin for invoice number "
|
| 625 |
"Sales margin for invoice number " + fofoOrder.getInvoiceNumber() + ". Total " + count + " pc(s)",
|
639 |
+ fofoOrder.getInvoiceNumber() + ". Total " + count + " pc(s)",
|
| 626 |
totalCashback, fofoOrder.getCreateTimestamp());
|
640 |
totalCashback, fofoOrder.getCreateTimestamp());
|
| 627 |
fofoOrder.setCashback(totalCashback);
|
641 |
fofoOrder.setCashback(totalCashback);
|
| 628 |
fofoOrderRepository.persist(fofoOrder);
|
642 |
fofoOrderRepository.persist(fofoOrder);
|
| 629 |
}
|
643 |
}
|
| 630 |
}
|
644 |
}
|
| Line 637... |
Line 651... |
| 637 |
float amountToRollback = 0;
|
651 |
float amountToRollback = 0;
|
| 638 |
List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
|
652 |
List<SchemeInOut> schemes = schemeInOutRepository.selectByInventoryItemIds(inventoryItemIdSet);
|
| 639 |
for (SchemeInOut schemeInOut : schemes) {
|
653 |
for (SchemeInOut schemeInOut : schemes) {
|
| 640 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
654 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
| 641 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
655 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| 642 |
if (schemeInOut.getStatus()==null || schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
656 |
if (schemeInOut.getStatus() == null || schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
| 643 |
amountToRollback += schemeInOut.getAmount();
|
657 |
amountToRollback += schemeInOut.getAmount();
|
| 644 |
}
|
658 |
}
|
| 645 |
schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
|
659 |
schemeInOut.setStatus(SchemePayoutStatus.REJECTED);
|
| 646 |
schemeInOut.setStatusDescription(rollbackReason);
|
660 |
schemeInOut.setStatusDescription(rollbackReason);
|
| 647 |
}
|
661 |
}
|
| Line 764... |
Line 778... |
| 764 |
}
|
778 |
}
|
| 765 |
|
779 |
|
| 766 |
@Override
|
780 |
@Override
|
| 767 |
// Always being called from cancel order means no SCHEME IN is considered
|
781 |
// Always being called from cancel order means no SCHEME IN is considered
|
| 768 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason,
|
782 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int reversalReference, String reversalReason,
|
| 769 |
SchemeType schemeType) throws ProfitMandiBusinessException {
|
783 |
List<SchemeType> schemeTypes) throws ProfitMandiBusinessException {
|
| 770 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItems.stream()
|
784 |
Map<Integer, InventoryItem> inventoryItemsMap = inventoryItems.stream()
|
| 771 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
785 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 772 |
LOGGER.info("inventoryItems" + inventoryItems);
|
786 |
LOGGER.info("inventoryItems" + inventoryItems);
|
| 773 |
|
787 |
|
| 774 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
788 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByInventoryItemIds(inventoryItemsMap.keySet());
|
| Line 781... |
Line 795... |
| 781 |
|
795 |
|
| 782 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size())
|
796 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds, 0, schemeIds.size())
|
| 783 |
.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
797 |
.stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 784 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
798 |
for (SchemeInOut schemeInOut : schemeInOuts) {
|
| 785 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
799 |
Scheme scheme = schemesMap.get(schemeInOut.getSchemeId());
|
| 786 |
if (scheme.getType().equals(schemeType)) {
|
800 |
if (schemeTypes.contains(scheme.getType())) {
|
| 787 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
801 |
if (schemeInOut.getRolledBackTimestamp() == null) {
|
| 788 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
802 |
schemeInOut.setRolledBackTimestamp(LocalDateTime.now());
|
| 789 |
if (schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
803 |
if (schemeInOut.getStatus().equals(SchemePayoutStatus.CREDITED)) {
|
| 790 |
amountToRollback += schemeInOut.getAmount();
|
804 |
amountToRollback += schemeInOut.getAmount();
|
| 791 |
}
|
805 |
}
|
| Line 795... |
Line 809... |
| 795 |
}
|
809 |
}
|
| 796 |
}
|
810 |
}
|
| 797 |
|
811 |
|
| 798 |
}
|
812 |
}
|
| 799 |
int fofoId = inventoryItems.get(0).getFofoId();
|
813 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| 800 |
WalletReferenceType walletReferenceType = schemeType.equals(SchemeType.OUT) || schemeType.equals(SchemeType.CATEGORY) ? WalletReferenceType.SCHEME_OUT
|
814 |
WalletReferenceType walletReferenceType = schemeTypes.containsAll(SchemeService.OUT_SCHEME_TYPES)
|
| - |
|
815 |
? WalletReferenceType.SCHEME_OUT
|
| 801 |
: schemeType.equals(SchemeType.INVESTMENT) ? WalletReferenceType.INVESTMENT_PAYOUT
|
816 |
: (schemeTypes.contains(SchemeType.ACTIVATION) ? WalletReferenceType.ACTIVATION_SCHEME
|
| 802 |
: WalletReferenceType.ACTIVATION_SCHEME;
|
817 |
: WalletReferenceType.INVESTMENT_PAYOUT);
|
| 803 |
if (amountToRollback > 0) {
|
818 |
if (amountToRollback > 0) {
|
| - |
|
819 |
// Mark appropriate reference of rollback investment margin
|
| - |
|
820 |
if (schemeTypes.contains(SchemeType.INVESTMENT)) {
|
| - |
|
821 |
reversalReference = Integer
|
| - |
|
822 |
.parseInt(FormattingUtils.getYearMonth(schemeInOuts.get(0).getCreditTimestamp()));
|
| 804 |
// TODO//
|
823 |
}
|
| 805 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, reversalReference, walletReferenceType,
|
824 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, reversalReference, walletReferenceType,
|
| 806 |
reversalReason, LocalDateTime.now());
|
825 |
reversalReason, LocalDateTime.now());
|
| 807 |
}
|
826 |
}
|
| 808 |
}
|
827 |
}
|
| 809 |
|
828 |
|
| Line 831... |
Line 850... |
| 831 |
@Override
|
850 |
@Override
|
| 832 |
@Cacheable(value = "itemSchemeCashback", cacheManager = "timeoutCacheManager")
|
851 |
@Cacheable(value = "itemSchemeCashback", cacheManager = "timeoutCacheManager")
|
| 833 |
public Map<Integer, Float> getItemSchemeCashBack() {
|
852 |
public Map<Integer, Float> getItemSchemeCashBack() {
|
| 834 |
Map<Integer, Float> itemCashbackMap = new HashMap<>();
|
853 |
Map<Integer, Float> itemCashbackMap = new HashMap<>();
|
| 835 |
Map<Integer, Scheme> cashbackSchemesMap = schemeRepository
|
854 |
Map<Integer, Scheme> cashbackSchemesMap = schemeRepository
|
| 836 |
.selectActiveAll(SchemeType.ACTIVATION, PartnerType.ALL, LocalDateTime.now(), true).stream()
|
855 |
.selectActiveAll(Arrays.asList(SchemeType.ACTIVATION), PartnerType.ALL, LocalDateTime.now(), true)
|
| 837 |
.filter(x -> x.getAmountType().equals(AmountType.FIXED))
|
856 |
.stream().filter(x -> x.getAmountType().equals(AmountType.FIXED))
|
| 838 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
857 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| 839 |
if (cashbackSchemesMap.size() > 0) {
|
858 |
if (cashbackSchemesMap.size() > 0) {
|
| 840 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(cashbackSchemesMap.keySet());
|
859 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(cashbackSchemesMap.keySet());
|
| 841 |
schemeItems.stream().forEach(x -> {
|
860 |
schemeItems.stream().forEach(x -> {
|
| 842 |
itemCashbackMap.put(x.getItemId(), cashbackSchemesMap.get(x.getSchemeId()).getAmount());
|
861 |
itemCashbackMap.put(x.getItemId(), cashbackSchemesMap.get(x.getSchemeId()).getAmount());
|