| Line 535... |
Line 535... |
| 535 |
purchase.getPurchaseReference(), itemsCount);
|
535 |
purchase.getPurchaseReference(), itemsCount);
|
| 536 |
}
|
536 |
}
|
| 537 |
|
537 |
|
| 538 |
}
|
538 |
}
|
| 539 |
|
539 |
|
| 540 |
public InventoryPayoutModel getPayouts(InventoryItem inventoryItem) {
|
540 |
public InventoryPayoutModel getPayouts(InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
| 541 |
double paidPercentage = 0d;
|
541 |
double paidPercentage = 0d;
|
| 542 |
double paidFixed = 0d;
|
542 |
double paidFixed = 0d;
|
| 543 |
double totalPaid = 0d;
|
543 |
double totalPaid = 0d;
|
| - |
|
544 |
double dp = Math.min(inventoryItem.getUnitPrice() - Math.max(0, inventoryItem.getPriceDropAmount()),
|
| - |
|
545 |
tagListingRepository.selectByItemId(inventoryItem.getItemId()).getSellingPrice());
|
| 544 |
|
546 |
|
| 545 |
List<SchemeInOut> sios = schemeInOutRepository.selectAll(inventoryItem.getId());
|
547 |
List<SchemeInOut> sios = schemeInOutRepository.selectAll(inventoryItem.getId());
|
| 546 |
List<SchemeInOut> paidSios = sios.stream().filter(x -> x.getRolledBackTimestamp() == null).filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED)).collect(Collectors.toList());
|
548 |
List<SchemeInOut> paidSios = sios.stream().filter(x -> x.getRolledBackTimestamp() == null).filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED)).collect(Collectors.toList());
|
| 547 |
if (paidSios.size() > 0) {
|
549 |
if (paidSios.size() > 0) {
|
| 548 |
List<Integer> schemeIds = sios.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
550 |
List<Integer> schemeIds = sios.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
| Line 583... |
Line 585... |
| 583 |
|
585 |
|
| 584 |
InventoryPayoutModel inventoryPayoutModel = new InventoryPayoutModel(inventoryItem.getId(), paidSios, offerPayouts);
|
586 |
InventoryPayoutModel inventoryPayoutModel = new InventoryPayoutModel(inventoryItem.getId(), paidSios, offerPayouts);
|
| 585 |
inventoryPayoutModel.setFixedAmount(paidFixed);
|
587 |
inventoryPayoutModel.setFixedAmount(paidFixed);
|
| 586 |
inventoryPayoutModel.setPaidAmount(totalPaid);
|
588 |
inventoryPayoutModel.setPaidAmount(totalPaid);
|
| 587 |
inventoryPayoutModel.setPercentageAmount(paidPercentage);
|
589 |
inventoryPayoutModel.setPercentageAmount(paidPercentage);
|
| - |
|
590 |
inventoryPayoutModel.setDp(dp);
|
| 588 |
return inventoryPayoutModel;
|
591 |
return inventoryPayoutModel;
|
| 589 |
}
|
592 |
}
|
| 590 |
|
593 |
|
| 591 |
// We are maintaining price drop after grn
|
594 |
// We are maintaining price drop after grn
|
| 592 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) throws ProfitMandiBusinessException {
|
595 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) throws ProfitMandiBusinessException {
|
| Line 707... |
Line 710... |
| 707 |
}
|
710 |
}
|
| 708 |
walletCredit += fixedRollout;
|
711 |
walletCredit += fixedRollout;
|
| 709 |
}
|
712 |
}
|
| 710 |
|
713 |
|
| 711 |
if (percentageToPay > 0) {
|
714 |
if (percentageToPay > 0) {
|
| 712 |
double effectiveDP = inventoryItem.getUnitPrice() - Math.max(0, inventoryItem.getPriceDropAmount()) - (inventoryPayoutModel.getFixedAmount() + fixedToPay);
|
715 |
double effectiveDP = inventoryPayoutModel.getDp() - (inventoryPayoutModel.getFixedAmount() + fixedToPay);
|
| 713 |
double totalPercentage = inventoryPayoutModel.getPercentageAmount() + percentageToPay;
|
716 |
double totalPercentage = inventoryPayoutModel.getPercentageAmount() + percentageToPay;
|
| 714 |
double percentageRollout = effectiveDP * (totalPercentage / (100 + totalPercentage) - (inventoryPayoutModel.getPercentageAmount() / (100 + inventoryPayoutModel.getPercentageAmount())));
|
717 |
double percentageRollout = effectiveDP * (totalPercentage / (100 + totalPercentage) - (inventoryPayoutModel.getPercentageAmount() / (100 + inventoryPayoutModel.getPercentageAmount())));
|
| 715 |
for (Map.Entry<SchemeSummaryModel, AmountModel> schemeSummaryModelAmountModelEntry : payoutSchemeSummaryModelMap.entrySet()) {
|
718 |
for (Map.Entry<SchemeSummaryModel, AmountModel> schemeSummaryModelAmountModelEntry : payoutSchemeSummaryModelMap.entrySet()) {
|
| 716 |
SchemeSummaryModel schemeSummaryModel = schemeSummaryModelAmountModelEntry.getKey();
|
719 |
SchemeSummaryModel schemeSummaryModel = schemeSummaryModelAmountModelEntry.getKey();
|
| 717 |
AmountModel amountModel = schemeSummaryModelAmountModelEntry.getValue();
|
720 |
AmountModel amountModel = schemeSummaryModelAmountModelEntry.getValue();
|
| Line 1234... |
Line 1237... |
| 1234 |
.selectBySerialNumbers(new ArrayList<>(serialNumberMap.keySet())).stream().collect(Collectors.toList());
|
1237 |
.selectBySerialNumbers(new ArrayList<>(serialNumberMap.keySet())).stream().collect(Collectors.toList());
|
| 1235 |
|
1238 |
|
| 1236 |
Map<String, ActivatedImei> activatedImeiMap = activatedImeis.stream()
|
1239 |
Map<String, ActivatedImei> activatedImeiMap = activatedImeis.stream()
|
| 1237 |
.collect(Collectors.toMap(x -> x.getSerialNumber().toLowerCase(), x -> x));
|
1240 |
.collect(Collectors.toMap(x -> x.getSerialNumber().toLowerCase(), x -> x));
|
| 1238 |
for (SchemeInOut pendingPayout : pendingPayouts) {
|
1241 |
for (SchemeInOut pendingPayout : pendingPayouts) {
|
| - |
|
1242 |
Scheme scheme = schemesMap.get(pendingPayout.getSchemeId());
|
| 1239 |
InventoryItem ii = inventoryItemMap.get(pendingPayout.getInventoryItemId());
|
1243 |
InventoryItem ii = inventoryItemMap.get(pendingPayout.getInventoryItemId());
|
| - |
|
1244 |
InventoryPayoutModel inventoryPayoutModel = this.getPayouts(ii);
|
| - |
|
1245 |
AmountModel amountModel = new AmountModel();
|
| - |
|
1246 |
amountModel.setAmount(scheme.getAmount());
|
| - |
|
1247 |
amountModel.setAmountType(scheme.getAmountType());
|
| - |
|
1248 |
double amountToRollout = this.getAmount(inventoryPayoutModel, amountModel);
|
| 1240 |
String serialNumber = ii.getSerialNumber().toLowerCase();
|
1249 |
String serialNumber = ii.getSerialNumber().toLowerCase();
|
| 1241 |
ActivatedImei activatedImei = activatedImeiMap.get(serialNumber);
|
1250 |
ActivatedImei activatedImei = activatedImeiMap.get(serialNumber);
|
| 1242 |
if (activatedImei == null) {
|
1251 |
if (activatedImei == null) {
|
| 1243 |
continue;
|
1252 |
continue;
|
| 1244 |
}
|
1253 |
}
|
| 1245 |
Scheme scheme = schemesMap.get(pendingPayout.getSchemeId());
|
- |
|
| 1246 |
if (scheme.isWithinRange(activatedImei.getActivationTimestamp())) {
|
1254 |
if (scheme.isWithinRange(activatedImei.getActivationTimestamp())) {
|
| 1247 |
int fofoId = ii.getFofoId();
|
1255 |
int fofoId = ii.getFofoId();
|
| 1248 |
// Get latest order Id
|
1256 |
// Get latest order Id
|
| 1249 |
int orderId = scanRecordRepository.selectByInventoryItemId(ii.getId()).stream()
|
1257 |
int orderId = scanRecordRepository.selectByInventoryItemId(ii.getId()).stream()
|
| 1250 |
.filter(x -> x.getOrderId() > 0)
|
1258 |
.filter(x -> x.getOrderId() > 0)
|
| 1251 |
.sorted(Comparator.comparing(ScanRecord::getCreateTimestamp).reversed()).findFirst().get()
|
1259 |
.sorted(Comparator.comparing(ScanRecord::getCreateTimestamp).reversed()).findFirst().get()
|
| 1252 |
.getOrderId();
|
1260 |
.getOrderId();
|
| 1253 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
1261 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
| 1254 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
1262 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
| 1255 |
walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.ACTIVATION_SCHEME,
|
1263 |
walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.ACTIVATION_SCHEME,
|
| 1256 |
"Activation margin for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, pendingPayout.getAmount(),
|
1264 |
"Activation margin for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, (float) amountToRollout,
|
| 1257 |
fofoOrder.getCreateTimestamp());
|
1265 |
fofoOrder.getCreateTimestamp());
|
| 1258 |
pendingPayout.setStatusDescription("Activation margin credited, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
1266 |
pendingPayout.setStatusDescription("Activation margin credited, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
| 1259 |
} else {
|
1267 |
} else {
|
| 1260 |
walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.SPECIAL_SUPPORT,
|
1268 |
walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.SPECIAL_SUPPORT,
|
| 1261 |
"Special Support for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, pendingPayout.getAmount(),
|
1269 |
"Special Support for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, (float) amountToRollout,
|
| 1262 |
fofoOrder.getCreateTimestamp());
|
1270 |
fofoOrder.getCreateTimestamp());
|
| 1263 |
pendingPayout.setStatusDescription("Special support credited, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
1271 |
pendingPayout.setStatusDescription("Special support credited, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
| 1264 |
}
|
1272 |
}
|
| 1265 |
pendingPayout.setCreditTimestamp(LocalDateTime.now());
|
1273 |
pendingPayout.setCreditTimestamp(LocalDateTime.now());
|
| 1266 |
pendingPayout.setStatus(SchemePayoutStatus.CREDITED);
|
1274 |
pendingPayout.setStatus(SchemePayoutStatus.CREDITED);
|
| Line 1272... |
Line 1280... |
| 1272 |
"Rejected, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
1280 |
"Rejected, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
| 1273 |
}
|
1281 |
}
|
| 1274 |
}
|
1282 |
}
|
| 1275 |
}
|
1283 |
}
|
| 1276 |
|
1284 |
|
| - |
|
1285 |
private double getAmount(InventoryPayoutModel inventoryPayoutModel, AmountModel amountModel) {
|
| - |
|
1286 |
double rollout = 0;
|
| - |
|
1287 |
if (amountModel.getAmountType().equals(AmountType.PERCENTAGE)) {
|
| - |
|
1288 |
double effectiveDp = inventoryPayoutModel.getDp() - inventoryPayoutModel.getFixedAmount();
|
| - |
|
1289 |
double totalPercentage = inventoryPayoutModel.getPercentageAmount() + amountModel.getAmount();
|
| - |
|
1290 |
rollout = effectiveDp * (totalPercentage / (100 + totalPercentage) - (inventoryPayoutModel.getPercentageAmount() / (100 + inventoryPayoutModel.getPercentageAmount())));
|
| - |
|
1291 |
} else {
|
| - |
|
1292 |
rollout = amountModel.getAmount() * (100 / (100 + inventoryPayoutModel.getPercentageAmount()));
|
| - |
|
1293 |
}
|
| - |
|
1294 |
return rollout;
|
| - |
|
1295 |
}
|
| - |
|
1296 |
|
| 1277 |
@Override
|
1297 |
@Override
|
| 1278 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
1298 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
| 1279 |
List<SchemesImeisModel> schemesImeisModels = schemeRepository.selectSelectUnpaidSchemes();
|
1299 |
List<SchemesImeisModel> schemesImeisModels = schemeRepository.selectSelectUnpaidSchemes();
|
| 1280 |
LOGGER.info("Total Size - " + schemesImeisModels.size());
|
1300 |
LOGGER.info("Total Size - " + schemesImeisModels.size());
|
| 1281 |
List<Integer> orderIds = schemesImeisModels.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
|
1301 |
List<Integer> orderIds = schemesImeisModels.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
|