| Line 29... |
Line 29... |
| 29 |
import com.spice.profitmandi.service.NotificationService;
|
29 |
import com.spice.profitmandi.service.NotificationService;
|
| 30 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
30 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 31 |
import com.spice.profitmandi.service.inventory.AgeingService;
|
31 |
import com.spice.profitmandi.service.inventory.AgeingService;
|
| 32 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
32 |
import com.spice.profitmandi.service.inventory.PurchaseService;
|
| 33 |
import com.spice.profitmandi.service.pricecircular.CatalogSummaryModel;
|
33 |
import com.spice.profitmandi.service.pricecircular.CatalogSummaryModel;
|
| - |
|
34 |
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
|
| 34 |
import com.spice.profitmandi.service.pricecircular.SchemeSummaryModel;
|
35 |
import com.spice.profitmandi.service.pricecircular.SchemeSummaryModel;
|
| 35 |
import com.spice.profitmandi.service.wallet.WalletService;
|
36 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 36 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
37 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 37 |
import org.apache.logging.log4j.LogManager;
|
38 |
import org.apache.logging.log4j.LogManager;
|
| 38 |
import org.apache.logging.log4j.Logger;
|
39 |
import org.apache.logging.log4j.Logger;
|
| Line 107... |
Line 108... |
| 107 |
@Autowired
|
108 |
@Autowired
|
| 108 |
private PurchaseRepository purchaseRepository;
|
109 |
private PurchaseRepository purchaseRepository;
|
| 109 |
@Autowired
|
110 |
@Autowired
|
| 110 |
private FofoOrderRepository fofoOrderRepository;
|
111 |
private FofoOrderRepository fofoOrderRepository;
|
| 111 |
|
112 |
|
| - |
|
113 |
@Autowired
|
| - |
|
114 |
private PriceCircularService priceCircularService;
|
| - |
|
115 |
|
| 112 |
@Override
|
116 |
@Override
|
| 113 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
117 |
public void saveScheme(int creatorId, CreateSchemeRequest createSchemeRequest) throws ProfitMandiBusinessException {
|
| 114 |
|
118 |
|
| 115 |
this.validateCreateSchemeRequest(createSchemeRequest);
|
119 |
this.validateCreateSchemeRequest(createSchemeRequest);
|
| 116 |
|
120 |
|
| Line 535... |
Line 539... |
| 535 |
purchase.getPurchaseReference(), itemsCount);
|
539 |
purchase.getPurchaseReference(), itemsCount);
|
| 536 |
}
|
540 |
}
|
| 537 |
|
541 |
|
| 538 |
}
|
542 |
}
|
| 539 |
|
543 |
|
| 540 |
public InventoryPayoutModel getPayouts(InventoryItem inventoryItem) throws ProfitMandiBusinessException {
|
- |
|
| 541 |
double paidPercentage = 0d;
|
- |
|
| 542 |
double paidFixed = 0d;
|
- |
|
| 543 |
double totalPaid = 0d;
|
- |
|
| 544 |
double dp = Math.min(inventoryItem.getUnitPrice() - Math.max(0, inventoryItem.getPriceDropAmount()),
|
- |
|
| 545 |
tagListingRepository.selectByItemId(inventoryItem.getItemId()).getSellingPrice());
|
- |
|
| 546 |
|
- |
|
| 547 |
List<SchemeInOut> sios = schemeInOutRepository.selectAll(inventoryItem.getId());
|
- |
|
| 548 |
List<SchemeInOut> paidSios = sios.stream().filter(x -> x.getRolledBackTimestamp() == null).filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED)).collect(Collectors.toList());
|
- |
|
| 549 |
if (paidSios.size() > 0) {
|
- |
|
| 550 |
List<Integer> schemeIds = sios.stream().map(x -> x.getSchemeId()).collect(Collectors.toList());
|
- |
|
| 551 |
Map<Integer, Scheme> schemesMap = schemeRepository.selectBySchemeIds(schemeIds).stream().collect(Collectors.toMap(x -> x.getId(), x -> x));
|
- |
|
| 552 |
for (SchemeInOut paidSio : paidSios) {
|
- |
|
| 553 |
Scheme scheme = schemesMap.get(paidSio.getSchemeId());
|
- |
|
| 554 |
paidSio.setScheme(scheme);
|
- |
|
| 555 |
if (scheme.getAmountType().equals(AmountType.PERCENTAGE)) {
|
- |
|
| 556 |
paidPercentage += scheme.getAmount();
|
- |
|
| 557 |
} else {
|
- |
|
| 558 |
paidFixed += scheme.getAmount();
|
- |
|
| 559 |
}
|
- |
|
| 560 |
totalPaid += paidSio.getAmount();
|
- |
|
| 561 |
}
|
- |
|
| 562 |
}
|
- |
|
| 563 |
|
- |
|
| 564 |
List<OfferPayout> offerPayouts = offerPayoutRepository.selectAllBySerialNumber(inventoryItem.getFofoId(), inventoryItem.getSerialNumber())
|
- |
|
| 565 |
.stream().filter(x -> x.getStatus().equals(SchemePayoutStatus.CREDITED)).collect(Collectors.toList());
|
- |
|
| 566 |
if (offerPayouts.size() > 0) {
|
- |
|
| 567 |
Map<Integer, List<OfferPayout>> offerPayoutMap = offerPayouts.stream().collect(Collectors.groupingBy(x -> (int) x.getOfferId()));
|
- |
|
| 568 |
Map<Integer, Integer> offerCriteriaMap = offerPayouts.stream().collect(Collectors.toMap(x -> (int) x.getOfferId(), x -> (int) x.getCriteriaId(), (u, v) -> u));
|
- |
|
| 569 |
List<TargetSlabEntity> targetSlabEntities = offerTargetSlabRepository.selectByOfferIds(new ArrayList<>(offerPayoutMap.keySet()));
|
- |
|
| 570 |
Map<Integer, TargetSlabEntity> offerIdTargetSlabMap = targetSlabEntities.stream().filter(x -> offerCriteriaMap.get(x.getOfferId()) == x.getItemCriteriaId())
|
- |
|
| 571 |
.collect(Collectors.toMap(x -> x.getOfferId(), x -> x, (u, v) -> u));
|
- |
|
| 572 |
for (Map.Entry<Integer, TargetSlabEntity> offerIdTargetSlabEntityEntry : offerIdTargetSlabMap.entrySet()) {
|
- |
|
| 573 |
int offerId = offerIdTargetSlabEntityEntry.getKey();
|
- |
|
| 574 |
TargetSlabEntity targetSlabEntity = offerIdTargetSlabEntityEntry.getValue();
|
- |
|
| 575 |
List<OfferPayout> payouts = offerPayoutMap.get(offerId);
|
- |
|
| 576 |
if (targetSlabEntity.getAmountType().equals(AmountType.PERCENTAGE)) {
|
- |
|
| 577 |
paidPercentage += payouts.stream().map(x -> x.getSlabAmount()).max(Comparator.comparing(Function.identity())).get();
|
- |
|
| 578 |
} else {
|
- |
|
| 579 |
paidFixed += payouts.stream().collect(Collectors.summingDouble(x -> x.getSlabAmount()));
|
- |
|
| 580 |
}
|
- |
|
| 581 |
totalPaid += payouts.stream().collect(Collectors.summingDouble(x -> x.getAmount()));
|
- |
|
| 582 |
|
- |
|
| 583 |
}
|
- |
|
| 584 |
}
|
- |
|
| 585 |
|
- |
|
| 586 |
InventoryPayoutModel inventoryPayoutModel = new InventoryPayoutModel(inventoryItem.getId(), paidSios, offerPayouts);
|
- |
|
| 587 |
inventoryPayoutModel.setFixedAmount(paidFixed);
|
- |
|
| 588 |
inventoryPayoutModel.setPaidAmount(totalPaid);
|
- |
|
| 589 |
inventoryPayoutModel.setPercentageAmount(paidPercentage);
|
- |
|
| 590 |
inventoryPayoutModel.setDp(dp);
|
- |
|
| 591 |
return inventoryPayoutModel;
|
- |
|
| 592 |
}
|
- |
|
| 593 |
|
544 |
|
| 594 |
// We are maintaining price drop after grn
|
545 |
// We are maintaining price drop after grn
|
| 595 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) throws ProfitMandiBusinessException {
|
546 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) throws ProfitMandiBusinessException {
|
| 596 |
if (BLOCKED_IMEIS.contains(inventoryItem.getSerialNumber())) {
|
547 |
if (BLOCKED_IMEIS.contains(inventoryItem.getSerialNumber())) {
|
| 597 |
return 0;
|
548 |
return 0;
|
| Line 628... |
Line 579... |
| 628 |
}
|
579 |
}
|
| 629 |
|
580 |
|
| 630 |
//Only in and activation margins are allowed to be rolled out more than twice
|
581 |
//Only in and activation margins are allowed to be rolled out more than twice
|
| 631 |
private float createSchemeInOut(List<SchemeSummaryModel> schemeSummaryModels, InventoryItem inventoryItem, PartnerType partnerType) throws ProfitMandiBusinessException {
|
582 |
private float createSchemeInOut(List<SchemeSummaryModel> schemeSummaryModels, InventoryItem inventoryItem, PartnerType partnerType) throws ProfitMandiBusinessException {
|
| 632 |
|
583 |
|
| 633 |
InventoryPayoutModel inventoryPayoutModel = this.getPayouts(inventoryItem);
|
584 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(inventoryItem);
|
| 634 |
//Get all schemes
|
585 |
//Get all schemes
|
| 635 |
List<SchemeSummaryModel> inventoryPayoutModelToProcess = schemeSummaryModels.stream().filter(x -> x.isProcess()).collect(Collectors.toList());
|
586 |
List<SchemeSummaryModel> inventoryPayoutModelToProcess = schemeSummaryModels.stream().filter(x -> x.isProcess()).collect(Collectors.toList());
|
| 636 |
float actualCredit = 0;
|
587 |
float actualCredit = 0;
|
| 637 |
|
588 |
|
| 638 |
List<SchemeInOut> sios = inventoryPayoutModel.getSchemePayouts();
|
589 |
List<SchemeInOut> sios = inventoryPayoutModel.getSchemePayouts();
|
| Line 1253... |
Line 1204... |
| 1253 |
.filter(x -> x.getOrderId() > 0)
|
1204 |
.filter(x -> x.getOrderId() > 0)
|
| 1254 |
.sorted(Comparator.comparing(ScanRecord::getCreateTimestamp).reversed()).findFirst().get()
|
1205 |
.sorted(Comparator.comparing(ScanRecord::getCreateTimestamp).reversed()).findFirst().get()
|
| 1255 |
.getOrderId();
|
1206 |
.getOrderId();
|
| 1256 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
1207 |
FofoOrder fofoOrder = fofoOrderRepository.selectByOrderId(orderId);
|
| 1257 |
|
1208 |
|
| 1258 |
InventoryPayoutModel inventoryPayoutModel = this.getPayouts(ii);
|
1209 |
InventoryPayoutModel inventoryPayoutModel = priceCircularService.getPayouts(ii);
|
| 1259 |
AmountModel amountModel = new AmountModel();
|
1210 |
AmountModel amountModel = new AmountModel();
|
| 1260 |
amountModel.setAmount(scheme.getAmount());
|
1211 |
amountModel.setAmount(scheme.getAmount());
|
| 1261 |
amountModel.setAmountType(scheme.getAmountType());
|
1212 |
amountModel.setAmountType(scheme.getAmountType());
|
| 1262 |
double amountToRollout = this.getAmount(inventoryPayoutModel, amountModel);
|
1213 |
double amountToRollout = inventoryPayoutModel.getRolloutAmount(amountModel);
|
| 1263 |
pendingPayout.setAmount((float)amountToRollout);
|
1214 |
pendingPayout.setAmount((float)amountToRollout);
|
| 1264 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
1215 |
if (scheme.getType().equals(SchemeType.ACTIVATION)) {
|
| 1265 |
walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.ACTIVATION_SCHEME,
|
1216 |
walletService.addAmountToWallet(fofoId, orderId, WalletReferenceType.ACTIVATION_SCHEME,
|
| 1266 |
"Activation margin for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, (float) amountToRollout,
|
1217 |
"Activation margin for " + ii.getItem().getItemDescriptionNoColor() + ", Imei - " + serialNumber, (float) amountToRollout,
|
| 1267 |
fofoOrder.getCreateTimestamp());
|
1218 |
fofoOrder.getCreateTimestamp());
|
| Line 1282... |
Line 1233... |
| 1282 |
"Rejected, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
1233 |
"Rejected, activated on " + FormattingUtils.formatDate(activatedImei.getActivationTimestamp()));
|
| 1283 |
}
|
1234 |
}
|
| 1284 |
}
|
1235 |
}
|
| 1285 |
}
|
1236 |
}
|
| 1286 |
|
1237 |
|
| 1287 |
private double getAmount(InventoryPayoutModel inventoryPayoutModel, AmountModel amountModel) {
|
- |
|
| 1288 |
double rollout = 0;
|
- |
|
| 1289 |
if (amountModel.getAmountType().equals(AmountType.PERCENTAGE)) {
|
- |
|
| 1290 |
double effectiveDp = inventoryPayoutModel.getDp() - inventoryPayoutModel.getFixedAmount();
|
- |
|
| 1291 |
double totalPercentage = inventoryPayoutModel.getPercentageAmount() + amountModel.getAmount();
|
- |
|
| 1292 |
rollout = effectiveDp * (totalPercentage / (100 + totalPercentage) - (inventoryPayoutModel.getPercentageAmount() / (100 + inventoryPayoutModel.getPercentageAmount())));
|
- |
|
| 1293 |
} else {
|
- |
|
| 1294 |
rollout = amountModel.getAmount() * (100 / (100 + inventoryPayoutModel.getPercentageAmount()));
|
- |
|
| 1295 |
}
|
- |
|
| 1296 |
return rollout;
|
- |
|
| 1297 |
}
|
- |
|
| 1298 |
|
- |
|
| 1299 |
@Override
|
1238 |
@Override
|
| 1300 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
1239 |
public void processActivatedImeisForSchemes() throws ProfitMandiBusinessException {
|
| 1301 |
List<SchemesImeisModel> schemesImeisModels = schemeRepository.selectSelectUnpaidSchemes();
|
1240 |
List<SchemesImeisModel> schemesImeisModels = schemeRepository.selectSelectUnpaidSchemes();
|
| 1302 |
LOGGER.info("Total Size - " + schemesImeisModels.size());
|
1241 |
LOGGER.info("Total Size - " + schemesImeisModels.size());
|
| 1303 |
List<Integer> orderIds = schemesImeisModels.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
|
1242 |
List<Integer> orderIds = schemesImeisModels.stream().map(x -> x.getOrderId()).collect(Collectors.toList());
|