| Line 57... |
Line 57... |
| 57 |
import javax.persistence.criteria.Predicate;
|
57 |
import javax.persistence.criteria.Predicate;
|
| 58 |
import javax.persistence.criteria.Root;
|
58 |
import javax.persistence.criteria.Root;
|
| 59 |
import java.text.MessageFormat;
|
59 |
import java.text.MessageFormat;
|
| 60 |
import java.time.LocalDate;
|
60 |
import java.time.LocalDate;
|
| 61 |
import java.time.LocalDateTime;
|
61 |
import java.time.LocalDateTime;
|
| 62 |
import java.time.LocalTime;
|
- |
|
| 63 |
import java.time.YearMonth;
|
62 |
import java.time.YearMonth;
|
| 64 |
import java.util.*;
|
63 |
import java.util.*;
|
| 65 |
import java.util.stream.Collectors;
|
64 |
import java.util.stream.Collectors;
|
| 66 |
|
65 |
|
| 67 |
@Component
|
66 |
@Component
|
| Line 600... |
Line 599... |
| 600 |
|
599 |
|
| 601 |
double percentageToPay = 0d;
|
600 |
double percentageToPay = 0d;
|
| 602 |
double fixedToPay = 0d;
|
601 |
double fixedToPay = 0d;
|
| 603 |
Map<SchemeSummaryModel, AmountModel> payoutSchemeSummaryModelMap = new HashMap<>();
|
602 |
Map<SchemeSummaryModel, AmountModel> payoutSchemeSummaryModelMap = new HashMap<>();
|
| 604 |
for (SchemeSummaryModel schemeSummaryModelToProcess : inventoryPayoutModelToProcess) {
|
603 |
for (SchemeSummaryModel schemeSummaryModelToProcess : inventoryPayoutModelToProcess) {
|
| 605 |
if (paidSchemesMap.containsKey(schemeSummaryModelToProcess.getSchemeId()) || pendingSchemesMap.containsKey(schemeSummaryModelToProcess.getSchemeId())) continue;
|
604 |
if (paidSchemesMap.containsKey(schemeSummaryModelToProcess.getSchemeId()) || pendingSchemesMap.containsKey(schemeSummaryModelToProcess.getSchemeId()))
|
| - |
|
605 |
continue;
|
| 606 |
//If different type but on higher side provide the higher margin
|
606 |
//If different type but on higher side provide the higher margin
|
| 607 |
if (Arrays.asList(SchemeType.ACTIVATION, SchemeType.SPECIAL_SUPPORT).contains(schemeSummaryModelToProcess.getSchemeType())) {
|
607 |
if (Arrays.asList(SchemeType.ACTIVATION, SchemeType.SPECIAL_SUPPORT).contains(schemeSummaryModelToProcess.getSchemeType())) {
|
| 608 |
Scheme scheme = schemeRepository.selectById(schemeSummaryModelToProcess.getSchemeId());
|
608 |
Scheme scheme = schemeRepository.selectById(schemeSummaryModelToProcess.getSchemeId());
|
| 609 |
//Create only if the activation if the activation date is not known
|
609 |
//Create only if the activation if the activation date is not known
|
| 610 |
ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(inventoryItem.getSerialNumber());
|
610 |
ActivatedImei activatedImei = activatedImeiRepository.selectBySerialNumber(inventoryItem.getSerialNumber());
|
| 611 |
if(activatedImei == null || activatedImei.getActivationTimestamp()==null) {
|
611 |
if (activatedImei == null || activatedImei.getActivationTimestamp() == null) {
|
| 612 |
SchemeInOut sio = new SchemeInOut();
|
612 |
SchemeInOut sio = new SchemeInOut();
|
| 613 |
sio.setAmount(0);
|
613 |
sio.setAmount(0);
|
| 614 |
sio.setInventoryItemId(inventoryItem.getId());
|
614 |
sio.setInventoryItemId(inventoryItem.getId());
|
| 615 |
sio.setSchemeId(schemeSummaryModelToProcess.getSchemeId());
|
615 |
sio.setSchemeId(schemeSummaryModelToProcess.getSchemeId());
|
| 616 |
sio.setStatusDescription("Activation pending for IMEI#" + inventoryItem.getSerialNumber());
|
616 |
sio.setStatusDescription("Activation pending for IMEI#" + inventoryItem.getSerialNumber());
|
| Line 1055... |
Line 1055... |
| 1055 |
Query<Double> query = session.createQuery(criteriaQuery);
|
1055 |
Query<Double> query = session.createQuery(criteriaQuery);
|
| 1056 |
return query.getSingleResult() + ProfitMandiConstants.SCHEME_INVESTMENT_MARGIN;
|
1056 |
return query.getSingleResult() + ProfitMandiConstants.SCHEME_INVESTMENT_MARGIN;
|
| 1057 |
|
1057 |
|
| 1058 |
}
|
1058 |
}
|
| 1059 |
|
1059 |
|
| - |
|
1060 |
|
| 1060 |
@Override
|
1061 |
@Override
|
| 1061 |
@Cacheable(value = "itemSchemeCashback", cacheManager = "timeoutCacheManager")
|
- |
|
| 1062 |
public Map<Integer, Float> getCatalogSchemeCashBack() {
|
1062 |
public Map<Integer, Float> getCatalogSchemeCashBack(int fofoId, List<Integer> catalogIds) {
|
| 1063 |
Map<Integer, Float> itemCashbackMap = new HashMap<>();
|
- |
|
| 1064 |
Map<Integer, Scheme> cashbackSchemesMap = schemeRepository
|
1063 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId, LocalDate.now());
|
| 1065 |
.selectActiveAll(Arrays.asList(SchemeType.ACTIVATION, SchemeType.SPECIAL_SUPPORT, SchemeType.SELLOUT), PartnerType.ALL, LocalDate.now(), false)
|
1064 |
Map<CatalogSummaryModel, List<SchemeSummaryModel>> catalogModelMap = tagListingRepository.getModelSchemesByCatalogIdsAndType(fofoId, partnerType, catalogIds, LocalDate.now().atStartOfDay());
|
| - |
|
1065 |
|
| 1066 |
.stream().filter(x -> x.getAmountType().equals(AmountType.FIXED))
|
1066 |
Map<Integer, Float> catalogCashbackMap = new HashMap<>();
|
| 1067 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
1067 |
for (Map.Entry<CatalogSummaryModel, List<SchemeSummaryModel>> catalogSummaryModelListEntry : catalogModelMap.entrySet()) {
|
| 1068 |
if (cashbackSchemesMap.size() > 0) {
|
1068 |
int catalogItemId = catalogSummaryModelListEntry.getKey().getCatalogId();
|
| 1069 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(cashbackSchemesMap.keySet());
|
1069 |
List<SchemeSummaryModel> schemeSummaryModels = catalogSummaryModelListEntry.getValue();
|
| - |
|
1070 |
|
| 1070 |
schemeItems.stream().forEach(x -> {
|
1071 |
float totalCashback = schemeSummaryModels.stream()
|
| 1071 |
float cashbackAmount = cashbackSchemesMap.get(x.getSchemeId()).getAmount();
|
1072 |
.filter(x -> Arrays.asList(SchemeType.ACTIVATION, SchemeType.SPECIAL_SUPPORT, SchemeType.SELLOUT).contains(x.getSchemeType())
|
| 1072 |
if (!itemCashbackMap.containsKey(x.getCatalogId())) {
|
1073 |
&& x.getAmountType().equals(AmountType.FIXED))
|
| 1073 |
itemCashbackMap.put(x.getCatalogId(), cashbackAmount);
|
1074 |
.collect(Collectors.summingDouble(x -> x.getAmount())).floatValue();
|
| 1074 |
} else {
|
- |
|
| 1075 |
itemCashbackMap.put(x.getCatalogId(), itemCashbackMap.get(x.getCatalogId()) + cashbackAmount);
|
1075 |
catalogCashbackMap.put(catalogItemId, totalCashback);
|
| 1076 |
}
|
- |
|
| 1077 |
});
|
- |
|
| 1078 |
}
|
1076 |
}
|
| 1079 |
// A107FD Model needs to removed
|
- |
|
| 1080 |
itemCashbackMap.remove(30211);
|
- |
|
| 1081 |
itemCashbackMap.remove(30212);
|
- |
|
| 1082 |
itemCashbackMap.remove(30213);
|
- |
|
| 1083 |
itemCashbackMap.remove(30756);
|
- |
|
| 1084 |
return itemCashbackMap;
|
1077 |
return catalogCashbackMap;
|
| 1085 |
}
|
1078 |
}
|
| 1086 |
|
1079 |
|
| 1087 |
@Override
|
1080 |
@Override
|
| 1088 |
public List<Scheme> selectSchemeByPartnerTypeFofoId(PartnerType partnerType, LocalDate onDate, int catalogId,
|
1081 |
public List<Scheme> selectSchemeByPartnerTypeFofoId(PartnerType partnerType, LocalDate onDate, int catalogId,
|
| 1089 |
int fofoId, int offset, int limit) throws ProfitMandiBusinessException {
|
1082 |
int fofoId, int offset, int limit) throws ProfitMandiBusinessException {
|
| Line 1258... |
Line 1251... |
| 1258 |
List<Scheme> supportSchemes = schemes.stream().filter(x -> Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.ACTIVATION).contains(x.getType())).collect(Collectors.toList());
|
1251 |
List<Scheme> supportSchemes = schemes.stream().filter(x -> Arrays.asList(SchemeType.SPECIAL_SUPPORT, SchemeType.ACTIVATION).contains(x.getType())).collect(Collectors.toList());
|
| 1259 |
if (supportSchemes.size() > 0) {
|
1252 |
if (supportSchemes.size() > 0) {
|
| 1260 |
List<SchemeSummaryModel> schemeSummaryModels = new ArrayList<>();
|
1253 |
List<SchemeSummaryModel> schemeSummaryModels = new ArrayList<>();
|
| 1261 |
for (Scheme scheme : supportSchemes) {
|
1254 |
for (Scheme scheme : supportSchemes) {
|
| 1262 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByScheme(scheme.getId(), inventoryItem.getId());
|
1255 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectByScheme(scheme.getId(), inventoryItem.getId());
|
| 1263 |
if(schemeInOuts.stream().filter(x->Arrays.asList(SchemePayoutStatus.CREDITED, SchemePayoutStatus.PENDING).contains(x.getStatus())).count() > 0) {
|
1256 |
if (schemeInOuts.stream().filter(x -> Arrays.asList(SchemePayoutStatus.CREDITED, SchemePayoutStatus.PENDING).contains(x.getStatus())).count() > 0) {
|
| 1264 |
continue;
|
1257 |
continue;
|
| 1265 |
}
|
1258 |
}
|
| 1266 |
SchemeInOut sio = new SchemeInOut();
|
1259 |
SchemeInOut sio = new SchemeInOut();
|
| 1267 |
sio.setAmount(0);
|
1260 |
sio.setAmount(0);
|
| 1268 |
sio.setInventoryItemId(inventoryItem.getId());
|
1261 |
sio.setInventoryItemId(inventoryItem.getId());
|