| Line 38... |
Line 38... |
| 38 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
38 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
39 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 40 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
40 |
import com.spice.profitmandi.dao.entity.fofo.ScanRecord;
|
| 41 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
41 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| 42 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
42 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| - |
|
43 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 43 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
44 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 44 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
45 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 45 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
46 |
import com.spice.profitmandi.dao.enumuration.fofo.ScanType;
|
| 46 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
47 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| 47 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
48 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| Line 55... |
Line 56... |
| 55 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
56 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 56 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
57 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 57 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
58 |
import com.spice.profitmandi.dao.repository.fofo.ScanRecordRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
59 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 59 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
60 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| - |
|
61 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 60 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
62 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 61 |
import com.spice.profitmandi.service.wallet.WalletService;
|
63 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 62 |
|
64 |
|
| 63 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
65 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 64 |
|
66 |
|
| Line 80... |
Line 82... |
| 80 |
@Autowired
|
82 |
@Autowired
|
| 81 |
private SessionFactory sessionFactory;
|
83 |
private SessionFactory sessionFactory;
|
| 82 |
|
84 |
|
| 83 |
@Autowired
|
85 |
@Autowired
|
| 84 |
private SchemeRepository schemeRepository;
|
86 |
private SchemeRepository schemeRepository;
|
| - |
|
87 |
|
| - |
|
88 |
@Autowired
|
| - |
|
89 |
private PriceDropRepository priceDropRepository;
|
| 85 |
|
90 |
|
| 86 |
@Autowired
|
91 |
@Autowired
|
| 87 |
private RoleManager roleManager;
|
92 |
private RoleManager roleManager;
|
| 88 |
|
93 |
|
| 89 |
@Autowired
|
94 |
@Autowired
|
| Line 440... |
Line 445... |
| 440 |
LOGGER.info("Items count for purchase id {} is {}", purchaseId, itemsCount);
|
445 |
LOGGER.info("Items count for purchase id {} is {}", purchaseId, itemsCount);
|
| 441 |
if (itemsCount > 0) {
|
446 |
if (itemsCount > 0) {
|
| 442 |
walletService.addAmountToWallet(retailerId, purchaseId, WalletReferenceType.SCHEME_IN,
|
447 |
walletService.addAmountToWallet(retailerId, purchaseId, WalletReferenceType.SCHEME_IN,
|
| 443 |
"Added for SCHEME IN against invoice " + purchase.getPurchaseReference() + " (total "
|
448 |
"Added for SCHEME IN against invoice " + purchase.getPurchaseReference() + " (total "
|
| 444 |
+ itemsCount + " pcs)",
|
449 |
+ itemsCount + " pcs)",
|
| 445 |
totalCashback);
|
450 |
totalCashback, purchase.getCreateTimestamp());
|
| 446 |
LOGGER.info("Added Rs.{} for SCHEME IN against invoice {} total pcs({}) {}", totalCashback,
|
451 |
LOGGER.info("Added Rs.{} for SCHEME IN against invoice {} total pcs({}) {}", totalCashback,
|
| 447 |
purchase.getPurchaseReference(), itemsCount);
|
452 |
purchase.getPurchaseReference(), itemsCount);
|
| 448 |
purchase.setCashback(purchase.getCashback() + totalCashback);
|
453 |
purchase.setCashback(purchase.getCashback() + totalCashback);
|
| 449 |
purchaseRepository.persist(purchase);
|
454 |
purchaseRepository.persist(purchase);
|
| 450 |
}
|
455 |
}
|
| Line 553... |
Line 558... |
| 553 |
}
|
558 |
}
|
| 554 |
}
|
559 |
}
|
| 555 |
if (count > 0) {
|
560 |
if (count > 0) {
|
| 556 |
walletService.addAmountToWallet(retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT,
|
561 |
walletService.addAmountToWallet(retailerId, fofoOrderId, WalletReferenceType.SCHEME_OUT,
|
| 557 |
"Sales margin for invoice number " + fofoOrder.getInvoiceNumber() + ". Total " + count + " pc(s)",
|
562 |
"Sales margin for invoice number " + fofoOrder.getInvoiceNumber() + ". Total " + count + " pc(s)",
|
| 558 |
totalCashback);
|
563 |
totalCashback, fofoOrder.getCreateTimestamp());
|
| 559 |
fofoOrder.setCashback(totalCashback);
|
564 |
fofoOrder.setCashback(totalCashback);
|
| 560 |
fofoOrderRepository.persist(fofoOrder);
|
565 |
fofoOrderRepository.persist(fofoOrder);
|
| 561 |
}
|
566 |
}
|
| 562 |
}
|
567 |
}
|
| 563 |
|
568 |
|
| Line 574... |
Line 579... |
| 574 |
amountToRollback += schemeInOut.getAmount();
|
579 |
amountToRollback += schemeInOut.getAmount();
|
| 575 |
}
|
580 |
}
|
| 576 |
}
|
581 |
}
|
| 577 |
if (amountToRollback > 0) {
|
582 |
if (amountToRollback > 0) {
|
| 578 |
int inventoryItemId = inventoryItemIds.get(0);
|
583 |
int inventoryItemId = inventoryItemIds.get(0);
|
| 579 |
Integer fofoId = inventoryItemRepository.selectById(inventoryItemId).getFofoId();
|
584 |
InventoryItem ii = inventoryItemRepository.selectById(inventoryItemId);
|
| - |
|
585 |
Purchase p = purchaseRepository.selectById(ii.getPurchaseId());
|
| - |
|
586 |
Integer fofoId = ii.getFofoId();
|
| - |
|
587 |
//TODO//
|
| 580 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, rollbackReference,
|
588 |
walletService.rollbackAmountFromWallet(fofoId, amountToRollback, rollbackReference,
|
| 581 |
WalletReferenceType.SCHEME_IN, rollbackReason);
|
589 |
WalletReferenceType.SCHEME_IN, rollbackReason, LocalDateTime.now());
|
| 582 |
}
|
590 |
}
|
| 583 |
}
|
591 |
}
|
| 584 |
|
592 |
|
| 585 |
@Override
|
593 |
@Override
|
| 586 |
public Map<String, Object> getSchemes(Set<Integer> roleIds, int offset, int limit)
|
594 |
public Map<String, Object> getSchemes(Set<Integer> roleIds, int offset, int limit)
|
| Line 620... |
Line 628... |
| 620 |
}
|
628 |
}
|
| 621 |
|
629 |
|
| 622 |
@Override
|
630 |
@Override
|
| 623 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int priceDropId, String reversalReason)
|
631 |
public void reverseSchemes(List<InventoryItem> inventoryItems, int priceDropId, String reversalReason)
|
| 624 |
throws ProfitMandiBusinessException {
|
632 |
throws ProfitMandiBusinessException {
|
| - |
|
633 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
| 625 |
Map<Integer, List<InventoryItem>> purchaseInventoryListMap = inventoryItems.stream()
|
634 |
Map<Integer, List<InventoryItem>> purchaseInventoryListMap = inventoryItems.stream()
|
| 626 |
.collect(Collectors.groupingBy(InventoryItem::getPurchaseId, Collectors.toList()));
|
635 |
.collect(Collectors.groupingBy(InventoryItem::getPurchaseId, Collectors.toList()));
|
| 627 |
|
636 |
|
| 628 |
for (Map.Entry<Integer, List<InventoryItem>> purchaseEntry : purchaseInventoryListMap.entrySet()) {
|
637 |
for (Map.Entry<Integer, List<InventoryItem>> purchaseEntry : purchaseInventoryListMap.entrySet()) {
|
| 629 |
float amountToCredit = 0;
|
638 |
float amountToCredit = 0;
|
| Line 664... |
Line 673... |
| 664 |
}
|
673 |
}
|
| 665 |
int fofoId = inventoryItems.get(0).getFofoId();
|
674 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| 666 |
if (amountToDebit > 0) {
|
675 |
if (amountToDebit > 0) {
|
| 667 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
676 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
| 668 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()),
|
677 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()),
|
| 669 |
-amountToDebit);
|
678 |
-amountToDebit, priceDrop.getAffectedOn());
|
| 670 |
}
|
679 |
}
|
| 671 |
if (amountToCredit > 0) {
|
680 |
if (amountToCredit > 0) {
|
| 672 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
681 |
walletService.addAmountToWallet(fofoId, purchaseId, WalletReferenceType.SCHEME_IN,
|
| 673 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()),
|
682 |
MessageFormat.format(reversalReason, purchaseInventoryItemList.size()),
|
| 674 |
amountToCredit);
|
683 |
amountToCredit, priceDrop.getAffectedOn());
|
| 675 |
}
|
684 |
}
|
| 676 |
}
|
685 |
}
|
| 677 |
}
|
686 |
}
|
| 678 |
|
687 |
|
| 679 |
@Override
|
688 |
@Override
|
| Line 698... |
Line 707... |
| 698 |
}
|
707 |
}
|
| 699 |
int fofoId = inventoryItems.get(0).getFofoId();
|
708 |
int fofoId = inventoryItems.get(0).getFofoId();
|
| 700 |
WalletReferenceType walletReferenceType = schemeType.equals(SchemeType.OUT) ? WalletReferenceType.SCHEME_OUT
|
709 |
WalletReferenceType walletReferenceType = schemeType.equals(SchemeType.OUT) ? WalletReferenceType.SCHEME_OUT
|
| 701 |
: WalletReferenceType.SCHEME_IN;
|
710 |
: WalletReferenceType.SCHEME_IN;
|
| 702 |
if (amount > 0) {
|
711 |
if (amount > 0) {
|
| - |
|
712 |
//TODO//
|
| 703 |
walletService.rollbackAmountFromWallet(fofoId, amount, reversalReference, walletReferenceType,
|
713 |
walletService.rollbackAmountFromWallet(fofoId, amount, reversalReference, walletReferenceType,
|
| 704 |
reversalReason);
|
714 |
reversalReason, LocalDateTime.now());
|
| 705 |
}
|
715 |
}
|
| 706 |
}
|
716 |
}
|
| 707 |
|
717 |
|
| 708 |
@Override
|
718 |
@Override
|
| 709 |
public double getTotalMargin(int itemId, PartnerType partnerType, LocalDateTime dateTime) {
|
719 |
public double getTotalMargin(int itemId, PartnerType partnerType, LocalDateTime dateTime) {
|