| Line 21... |
Line 21... |
| 21 |
import org.hibernate.Session;
|
21 |
import org.hibernate.Session;
|
| 22 |
import org.hibernate.SessionFactory;
|
22 |
import org.hibernate.SessionFactory;
|
| 23 |
import org.hibernate.query.Query;
|
23 |
import org.hibernate.query.Query;
|
| 24 |
import org.springframework.beans.factory.annotation.Autowired;
|
24 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 25 |
import org.springframework.beans.factory.annotation.Qualifier;
|
25 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| - |
|
26 |
import org.springframework.cache.annotation.Cacheable;
|
| 26 |
import org.springframework.stereotype.Component;
|
27 |
import org.springframework.stereotype.Component;
|
| 27 |
|
28 |
|
| 28 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
29 |
import com.spice.profitmandi.common.enumuration.ItemType;
|
| 29 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
31 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| Line 82... |
Line 83... |
| 82 |
@Autowired
|
83 |
@Autowired
|
| 83 |
private SessionFactory sessionFactory;
|
84 |
private SessionFactory sessionFactory;
|
| 84 |
|
85 |
|
| 85 |
@Autowired
|
86 |
@Autowired
|
| 86 |
private SchemeRepository schemeRepository;
|
87 |
private SchemeRepository schemeRepository;
|
| 87 |
|
88 |
|
| 88 |
@Autowired
|
89 |
@Autowired
|
| 89 |
private PriceDropRepository priceDropRepository;
|
90 |
private PriceDropRepository priceDropRepository;
|
| 90 |
|
91 |
|
| 91 |
@Autowired
|
92 |
@Autowired
|
| 92 |
private RoleManager roleManager;
|
93 |
private RoleManager roleManager;
|
| Line 395... |
Line 396... |
| 395 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
|
396 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId,
|
| 396 |
purchase.getCreateTimestamp().toLocalDate());
|
397 |
purchase.getCreateTimestamp().toLocalDate());
|
| 397 |
LOGGER.info("purchase is completed = {}", (purchase.getCompleteTimestamp() != null));
|
398 |
LOGGER.info("purchase is completed = {}", (purchase.getCompleteTimestamp() != null));
|
| 398 |
if (purchase.getCompleteTimestamp() != null) {
|
399 |
if (purchase.getCompleteTimestamp() != null) {
|
| 399 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN, partnerType,
|
400 |
List<Scheme> schemes = schemeRepository.selectActiveAll(SchemeType.IN, partnerType,
|
| 400 |
purchase.getCompleteTimestamp());
|
401 |
purchase.getCompleteTimestamp(), false);
|
| 401 |
float totalCashback = 0;
|
402 |
float totalCashback = 0;
|
| 402 |
if (schemes.isEmpty()) {
|
403 |
if (schemes.isEmpty()) {
|
| 403 |
return;
|
404 |
return;
|
| 404 |
}
|
405 |
}
|
| 405 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
406 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByPurchaseId(purchaseId);
|
| Line 443... |
Line 444... |
| 443 |
}
|
444 |
}
|
| 444 |
}
|
445 |
}
|
| 445 |
|
446 |
|
| 446 |
LOGGER.info("Items count for purchase id {} is {}", purchaseId, itemsCount);
|
447 |
LOGGER.info("Items count for purchase id {} is {}", purchaseId, itemsCount);
|
| 447 |
if (itemsCount > 0) {
|
448 |
if (itemsCount > 0) {
|
| 448 |
walletService.addAmountToWallet(retailerId, purchaseId, WalletReferenceType.SCHEME_IN,
|
449 |
walletService.addAmountToWallet(
|
| 449 |
"Added for SCHEME IN against invoice " + purchase.getPurchaseReference() + " (total "
|
450 |
retailerId, purchaseId, WalletReferenceType.SCHEME_IN, "Added for SCHEME IN against invoice "
|
| 450 |
+ itemsCount + " pcs)",
|
451 |
+ purchase.getPurchaseReference() + " (total " + itemsCount + " pcs)",
|
| 451 |
totalCashback, purchase.getCreateTimestamp());
|
452 |
totalCashback, purchase.getCreateTimestamp());
|
| 452 |
LOGGER.info("Added Rs.{} for SCHEME IN against invoice {} total pcs({}) {}", totalCashback,
|
453 |
LOGGER.info("Added Rs.{} for SCHEME IN against invoice {} total pcs({}) {}", totalCashback,
|
| 453 |
purchase.getPurchaseReference(), itemsCount);
|
454 |
purchase.getPurchaseReference(), itemsCount);
|
| 454 |
purchase.setCashback(purchase.getCashback() + totalCashback);
|
455 |
purchase.setCashback(purchase.getCashback() + totalCashback);
|
| 455 |
purchaseRepository.persist(purchase);
|
456 |
purchaseRepository.persist(purchase);
|
| Line 475... |
Line 476... |
| 475 |
// We are maintaining price drop after grn
|
476 |
// We are maintaining price drop after grn
|
| 476 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
477 |
private float getAmount(InventoryItem inventoryItem, Scheme scheme) {
|
| 477 |
float amount = 0;
|
478 |
float amount = 0;
|
| 478 |
float dpForCalc = 0;
|
479 |
float dpForCalc = 0;
|
| 479 |
float taxableSellingPrice = 0;
|
480 |
float taxableSellingPrice = 0;
|
| - |
|
481 |
// float totalTaxRate = inventoryItem.getIgstRate() +
|
| 480 |
//float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
482 |
// inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
| 481 |
//Hardcoding it to 18%
|
483 |
// Hardcoding it to 18%
|
| 482 |
float totalTaxRate = 18f;
|
484 |
float totalTaxRate = 18f;
|
| - |
|
485 |
// float totalTaxRate = inventoryItem.getIgstRate() +
|
| 483 |
//float totalTaxRate = inventoryItem.getIgstRate() + inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
486 |
// inventoryItem.getSgstRate() + inventoryItem.getCgstRate();
|
| 484 |
if (scheme.getAmountType() == AmountType.PERCENTAGE) {
|
487 |
if (scheme.getAmountType() == AmountType.PERCENTAGE) {
|
| 485 |
if (scheme.getType().equals(SchemeType.IN)) {
|
488 |
if (scheme.getType().equals(SchemeType.IN)) {
|
| 486 |
dpForCalc = inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount();
|
489 |
dpForCalc = inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount();
|
| 487 |
} else {
|
490 |
} else {
|
| 488 |
try {
|
491 |
try {
|
| 489 |
dpForCalc = Math.min(inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount(),
|
492 |
dpForCalc = Math.min(inventoryItem.getUnitPrice() - inventoryItem.getPriceDropAmount(),
|
| 490 |
tagListingRepository.selectByItemId(inventoryItem.getItemId()).getSellingPrice());
|
493 |
tagListingRepository.selectByItemId(inventoryItem.getItemId()).getSellingPrice());
|
| 491 |
} catch (Exception e) {
|
494 |
} catch (Exception e) {
|
| 492 |
LOGGER.info("Could not find tag Listing entry in {}", inventoryItem.getItemId());
|
495 |
LOGGER.info("Could not find tag Listing entry in {}", inventoryItem.getItemId());
|
| 493 |
e.printStackTrace();
|
496 |
e.printStackTrace();
|
| 494 |
}
|
497 |
}
|
| Line 530... |
Line 533... |
| 530 |
|
533 |
|
| 531 |
float totalCashback = 0;
|
534 |
float totalCashback = 0;
|
| 532 |
int count = 0;
|
535 |
int count = 0;
|
| 533 |
|
536 |
|
| 534 |
Set<Scheme> allFixedSchemes = schemeRepository
|
537 |
Set<Scheme> allFixedSchemes = schemeRepository
|
| 535 |
.selectActiveAll(SchemeType.OUT, partnerType, fofoOrder.getCreateTimestamp()).stream()
|
538 |
.selectActiveAll(SchemeType.OUT, partnerType, fofoOrder.getCreateTimestamp(), false).stream()
|
| 536 |
.filter(scheme -> scheme.getAmountType().equals(AmountType.FIXED)).collect(Collectors.toSet());
|
539 |
.filter(scheme -> scheme.getAmountType().equals(AmountType.FIXED)).collect(Collectors.toSet());
|
| 537 |
|
540 |
|
| 538 |
for (InventoryItem inventoryItem : inventoryItems) {
|
541 |
for (InventoryItem inventoryItem : inventoryItems) {
|
| 539 |
float itemCashback = 0;
|
542 |
float itemCashback = 0;
|
| 540 |
Purchase purchase = purchaseRepository.selectByIdAndFofoId(inventoryItem.getPurchaseId(), retailerId);
|
543 |
Purchase purchase = purchaseRepository.selectByIdAndFofoId(inventoryItem.getPurchaseId(), retailerId);
|
| Line 543... |
Line 546... |
| 543 |
List<Scheme> schemes = null;
|
546 |
List<Scheme> schemes = null;
|
| 544 |
if (purchase.getCompleteTimestamp() == null) {
|
547 |
if (purchase.getCompleteTimestamp() == null) {
|
| 545 |
continue;
|
548 |
continue;
|
| 546 |
}
|
549 |
}
|
| 547 |
if (purchase.getCompleteTimestamp().isAfter(LocalDate.of(2019, 9, 1).atStartOfDay())) {
|
550 |
if (purchase.getCompleteTimestamp().isAfter(LocalDate.of(2019, 9, 1).atStartOfDay())) {
|
| 548 |
schemes = schemeRepository.selectActiveAll(SchemeType.OUT, partnerType, fofoOrder.getCreateTimestamp());
|
551 |
schemes = schemeRepository.selectActiveAll(SchemeType.OUT, partnerType, fofoOrder.getCreateTimestamp(),
|
| - |
|
552 |
false);
|
| 549 |
} else {
|
553 |
} else {
|
| 550 |
schemes = schemeRepository.selectActiveAll(SchemeType.OUT, partnerType,
|
554 |
schemes = schemeRepository.selectActiveAll(SchemeType.OUT, partnerType, purchase.getCompleteTimestamp(),
|
| 551 |
purchase.getCompleteTimestamp());
|
555 |
false);
|
| 552 |
}
|
556 |
}
|
| 553 |
Set<Scheme> schemesSet = schemes.stream().filter(x -> x.getAmountType().equals(AmountType.PERCENTAGE))
|
557 |
Set<Scheme> schemesSet = schemes.stream().filter(x -> x.getAmountType().equals(AmountType.PERCENTAGE))
|
| 554 |
.collect(Collectors.toSet());
|
558 |
.collect(Collectors.toSet());
|
| 555 |
schemesSet.addAll(allFixedSchemes);
|
559 |
schemesSet.addAll(allFixedSchemes);
|
| 556 |
schemesSet = schemesSet.stream().filter(x -> schemeIds.contains(x.getId())).collect(Collectors.toSet());
|
560 |
schemesSet = schemesSet.stream().filter(x -> schemeIds.contains(x.getId())).collect(Collectors.toSet());
|
| Line 587... |
Line 591... |
| 587 |
if (amountToRollback > 0) {
|
591 |
if (amountToRollback > 0) {
|
| 588 |
int inventoryItemId = inventoryItemIds.get(0);
|
592 |
int inventoryItemId = inventoryItemIds.get(0);
|
| 589 |
InventoryItem ii = inventoryItemRepository.selectById(inventoryItemId);
|
593 |
InventoryItem ii = inventoryItemRepository.selectById(inventoryItemId);
|
| 590 |
Purchase p = purchaseRepository.selectById(ii.getPurchaseId());
|
594 |
Purchase p = purchaseRepository.selectById(ii.getPurchaseId());
|
| 591 |
Integer fofoId = ii.getFofoId();
|
595 |
Integer fofoId = ii.getFofoId();
|
| 592 |
//TODO//
|
596 |
// TODO//
|
| 593 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, rollbackReference,
|
597 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, rollbackReference,
|
| 594 |
WalletReferenceType.SCHEME_IN, rollbackReason, LocalDateTime.now());
|
598 |
WalletReferenceType.SCHEME_IN, rollbackReason, LocalDateTime.now());
|
| 595 |
}
|
599 |
}
|
| 596 |
}
|
600 |
}
|
| 597 |
|
601 |
|
| Line 676... |
Line 680... |
| 676 |
|
680 |
|
| 677 |
}
|
681 |
}
|
| 678 |
}
|
682 |
}
|
| 679 |
int fofoId = inventoryItems.get(0).getFofoId();
|
683 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| 680 |
if (amountToDebit > 0) {
|
684 |
if (amountToDebit > 0) {
|
| 681 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
685 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
| 682 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()),
|
686 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()), -amountToDebit,
|
| 683 |
-amountToDebit, priceDrop.getAffectedOn());
|
687 |
priceDrop.getAffectedOn());
|
| 684 |
}
|
688 |
}
|
| 685 |
if (amountToCredit > 0) {
|
689 |
if (amountToCredit > 0) {
|
| 686 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
690 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
| 687 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()),
|
691 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()), amountToCredit,
|
| 688 |
amountToCredit, priceDrop.getAffectedOn());
|
692 |
priceDrop.getAffectedOn());
|
| 689 |
}
|
693 |
}
|
| 690 |
}
|
694 |
}
|
| 691 |
}
|
695 |
}
|
| 692 |
|
696 |
|
| 693 |
@Override
|
697 |
@Override
|
| Line 712... |
Line 716... |
| 712 |
}
|
716 |
}
|
| 713 |
int fofoId = inventoryItems.get(0).getFofoId();
|
717 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| 714 |
WalletReferenceType walletReferenceType = schemeType.equals(SchemeType.OUT) ? WalletReferenceType.SCHEME_OUT
|
718 |
WalletReferenceType walletReferenceType = schemeType.equals(SchemeType.OUT) ? WalletReferenceType.SCHEME_OUT
|
| 715 |
: WalletReferenceType.SCHEME_IN;
|
719 |
: WalletReferenceType.SCHEME_IN;
|
| 716 |
if (amount > 0) {
|
720 |
if (amount > 0) {
|
| 717 |
//TODO//
|
721 |
// TODO//
|
| 718 |
walletService.rollbackAmountFromWallet(fofoId, amount, reversalReference, walletReferenceType,
|
722 |
walletService.rollbackAmountFromWallet(fofoId, amount, reversalReference, walletReferenceType,
|
| 719 |
reversalReason, LocalDateTime.now());
|
723 |
reversalReason, LocalDateTime.now());
|
| 720 |
}
|
724 |
}
|
| 721 |
}
|
725 |
}
|
| 722 |
|
726 |
|
| Line 739... |
Line 743... |
| 739 |
Query<Double> query = session.createQuery(criteriaQuery);
|
743 |
Query<Double> query = session.createQuery(criteriaQuery);
|
| 740 |
return query.getSingleResult() + ProfitMandiConstants.SCHEME_INVESTMENT_MARGIN;
|
744 |
return query.getSingleResult() + ProfitMandiConstants.SCHEME_INVESTMENT_MARGIN;
|
| 741 |
|
745 |
|
| 742 |
}
|
746 |
}
|
| 743 |
|
747 |
|
| - |
|
748 |
@Override
|
| - |
|
749 |
@Cacheable(value = "itemSchemeCashback", cacheManager = "timeoutCacheManager")
|
| - |
|
750 |
public Map<Integer, Float> getItemSchemeCashBack() {
|
| - |
|
751 |
Map<Integer, Float> itemCashbackMap = new HashMap<>();
|
| - |
|
752 |
Map<Integer, Scheme> cashbackSchemesMap = schemeRepository
|
| - |
|
753 |
.selectActiveAll(SchemeType.OUT, PartnerType.ALL, LocalDateTime.now(), true).stream()
|
| - |
|
754 |
.filter(x -> x.getAmountType().equals(AmountType.FIXED))
|
| - |
|
755 |
.collect(Collectors.toMap(x -> x.getId(), x -> x));
|
| - |
|
756 |
List<SchemeItem> schemeItems = schemeItemRepository.selectBySchemeIds(cashbackSchemesMap.keySet());
|
| - |
|
757 |
schemeItems.stream().forEach(x -> {
|
| - |
|
758 |
itemCashbackMap.put(x.getItemId(), cashbackSchemesMap.get(x.getItemId()).getAmount());
|
| - |
|
759 |
});
|
| - |
|
760 |
|
| - |
|
761 |
return itemCashbackMap;
|
| - |
|
762 |
}
|
| - |
|
763 |
|
| 744 |
/*
|
764 |
/*
|
| 745 |
* @Override public void updateSchmesForModel(int catalogId) throws
|
765 |
* @Override public void updateSchmesForModel(int catalogId) throws
|
| 746 |
* ProfitMandiBusinessException { List<Item> items =
|
766 |
* ProfitMandiBusinessException { List<Item> items =
|
| 747 |
* itemRepository.selectAllByCatalogItemId(catalogId); Map<Integer, Scheme>
|
767 |
* itemRepository.selectAllByCatalogItemId(catalogId); Map<Integer, Scheme>
|
| 748 |
* schemes = schemeRepository .selectAllByItemIds(items.stream().map(x ->
|
768 |
* schemes = schemeRepository .selectAllByItemIds(items.stream().map(x ->
|