| Line 421... |
Line 421... |
| 421 |
for (Map.Entry<InventoryItem, Set<Scheme>> allInventoryItemSchemesEntry : allInventoryItemSchemesMap
|
421 |
for (Map.Entry<InventoryItem, Set<Scheme>> allInventoryItemSchemesEntry : allInventoryItemSchemesMap
|
| 422 |
.entrySet()) {
|
422 |
.entrySet()) {
|
| 423 |
float inventoryItemCashback = 0;
|
423 |
float inventoryItemCashback = 0;
|
| 424 |
for (Scheme scheme : allInventoryItemSchemesEntry.getValue()) {
|
424 |
for (Scheme scheme : allInventoryItemSchemesEntry.getValue()) {
|
| 425 |
InventoryItem inventoryItem = allInventoryItemSchemesEntry.getKey();
|
425 |
InventoryItem inventoryItem = allInventoryItemSchemesEntry.getKey();
|
| 426 |
float cashback = this.createSchemeInOut(scheme, inventoryItem);
|
426 |
float cashback = this.createSchemeInOut(scheme, inventoryItem, partnerType);
|
| 427 |
inventoryItemCashback += cashback;
|
427 |
inventoryItemCashback += cashback;
|
| 428 |
}
|
428 |
}
|
| 429 |
if (inventoryItemCashback > 0) {
|
429 |
if (inventoryItemCashback > 0) {
|
| 430 |
totalCashback += inventoryItemCashback;
|
430 |
totalCashback += inventoryItemCashback;
|
| 431 |
itemsCount++;
|
431 |
itemsCount++;
|
| Line 458... |
Line 458... |
| 458 |
scheme.setCreatedBy(creatorId);
|
458 |
scheme.setCreatedBy(creatorId);
|
| 459 |
scheme.setCashback(createSchemeRequest.isCashback());
|
459 |
scheme.setCashback(createSchemeRequest.isCashback());
|
| 460 |
return scheme;
|
460 |
return scheme;
|
| 461 |
}
|
461 |
}
|
| 462 |
|
462 |
|
| - |
|
463 |
|
| 463 |
//Only in and activation margins are allowed to be rolled out more than twice
|
464 |
//Only in and activation margins are allowed to be rolled out more than twice
|
| 464 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
465 |
private float createSchemeInOut(Scheme scheme, InventoryItem inventoryItem, PartnerType partnerType) throws ProfitMandiBusinessException {
|
| 465 |
LOGGER.info("Scheme === {}", scheme);
|
466 |
LOGGER.info("Scheme === {}", scheme);
|
| 466 |
if ((scheme.getId() == 411 || scheme.getId() == 612) && inventoryItem.getCreateTimestamp().isAfter(LocalDate.of(2021, 12, 1).atStartOfDay())) {
|
467 |
if ((scheme.getId() == 411 || scheme.getId() == 612) && inventoryItem.getCreateTimestamp().isAfter(LocalDate.of(2021, 12, 1).atStartOfDay())) {
|
| 467 |
return 0;
|
468 |
return 0;
|
| 468 |
}
|
469 |
}
|
| 469 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllByType(scheme.getType(), inventoryItem.getId());
|
470 |
List<SchemeInOut> sios = schemeInOutRepository.selectAllByType(scheme.getType(), inventoryItem.getId());
|
| Line 508... |
Line 509... |
| 508 |
|
509 |
|
| 509 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
510 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
| 510 |
schemeInOut.setStatus(SchemePayoutStatus.PENDING);
|
511 |
schemeInOut.setStatus(SchemePayoutStatus.PENDING);
|
| 511 |
schemeInOut.setStatusDescription("Activation pending for IMEI#" + inventoryItem.getSerialNumber());
|
512 |
schemeInOut.setStatusDescription("Activation pending for IMEI#" + inventoryItem.getSerialNumber());
|
| 512 |
return 0;
|
513 |
return 0;
|
| 513 |
} else if (scheme.getType().equals(SchemeType.INVESTMENT)) {
|
514 |
} else if (scheme.getType().equals(SchemeType.INVESTMENT) && !PartnerType.BRONZE.equals(partnerType)) {
|
| 514 |
schemeInOut.setStatus(SchemePayoutStatus.PENDING);
|
515 |
schemeInOut.setStatus(SchemePayoutStatus.PENDING);
|
| 515 |
schemeInOut.setStatusDescription("Subject to investment days maintained");
|
516 |
schemeInOut.setStatusDescription("Subject to investment days maintained");
|
| 516 |
return 0;
|
517 |
return 0;
|
| 517 |
} else {
|
518 |
} else {
|
| 518 |
schemeInOut.setStatus(SchemePayoutStatus.CREDITED);
|
519 |
schemeInOut.setStatus(SchemePayoutStatus.CREDITED);
|
| 519 |
schemeInOut.setCreditTimestamp(LocalDateTime.now());
|
520 |
schemeInOut.setCreditTimestamp(LocalDateTime.now());
|
| 520 |
if (scheme.getType().equals(SchemeType.IN)) {
|
521 |
if (scheme.getType().equals(SchemeType.IN)) {
|
| 521 |
schemeInOut.setStatusDescription("Credited for GRN of IMEI#" + inventoryItem.getSerialNumber());
|
522 |
schemeInOut.setStatusDescription("Credited for GRN of IMEI#" + inventoryItem.getSerialNumber());
|
| 522 |
} else if (SchemeService.OUT_SCHEME_TYPES.contains(scheme.getType())) {
|
523 |
} else if (SchemeType.INVESTMENT.equals(scheme.getType()) || SchemeService.OUT_SCHEME_TYPES.contains(scheme.getType())) {
|
| 523 |
schemeInOut.setStatusDescription("Credited for sale of IMEI#" + inventoryItem.getSerialNumber());
|
524 |
schemeInOut.setStatusDescription("Credited for sale of IMEI#" + inventoryItem.getSerialNumber());
|
| 524 |
}
|
525 |
}
|
| 525 |
}
|
526 |
}
|
| 526 |
}
|
527 |
}
|
| 527 |
return actualCredit;
|
528 |
return actualCredit;
|
| Line 623... |
Line 624... |
| 623 |
.collect(Collectors.toList());
|
624 |
.collect(Collectors.toList());
|
| 624 |
List<Scheme> supportSchemes = itemActiveSchemes.stream().filter(x -> Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.ACTIVATION, SchemeType.SELLOUT).contains(x.getType())).collect(Collectors.toList());
|
625 |
List<Scheme> supportSchemes = itemActiveSchemes.stream().filter(x -> Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.ACTIVATION, SchemeType.SELLOUT).contains(x.getType())).collect(Collectors.toList());
|
| 625 |
itemActiveSchemes = itemActiveSchemes.stream().filter(x -> !Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.ACTIVATION, SchemeType.SELLOUT).contains(x.getType())).collect(Collectors.toList());
|
626 |
itemActiveSchemes = itemActiveSchemes.stream().filter(x -> !Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.ACTIVATION, SchemeType.SELLOUT).contains(x.getType())).collect(Collectors.toList());
|
| 626 |
for (Scheme scheme : itemActiveSchemes) {
|
627 |
for (Scheme scheme : itemActiveSchemes) {
|
| 627 |
LOGGER.info("Scheme ==== {}", scheme);
|
628 |
LOGGER.info("Scheme ==== {}", scheme);
|
| 628 |
itemCashback += this.createSchemeInOut(scheme, inventoryItem);
|
629 |
itemCashback += this.createSchemeInOut(scheme, inventoryItem, partnerType);
|
| 629 |
}
|
630 |
}
|
| 630 |
if (supportSchemes.size() > 0) {
|
631 |
if (supportSchemes.size() > 0) {
|
| 631 |
this.processSpecialSupport(fofoOrder, supportSchemes, inventoryItem, partnerType, fofoOrder.getCreateTimestamp());
|
632 |
this.processSpecialSupport(fofoOrder, supportSchemes, inventoryItem, partnerType, fofoOrder.getCreateTimestamp());
|
| 632 |
}
|
633 |
}
|
| 633 |
LOGGER.info("itemCashback ==== {}", itemCashback);
|
634 |
LOGGER.info("itemCashback ==== {}", itemCashback);
|