Subversion Repositories SmartDukaan

Rev

Rev 33547 | Rev 33848 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33547 Rev 33845
Line 4... Line 4...
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
4
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
5
import com.spice.profitmandi.common.model.ProfitMandiConstants;
5
import com.spice.profitmandi.common.model.ProfitMandiConstants;
6
import com.spice.profitmandi.common.util.FormattingUtils;
6
import com.spice.profitmandi.common.util.FormattingUtils;
7
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
7
import com.spice.profitmandi.dao.entity.dtr.UserAccount;
8
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
8
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
9
import com.spice.profitmandi.dao.entity.fofo.PartnerOnBoardingPanel;
9
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
10
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
10
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
11
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
11
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
12
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
12
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
13
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
13
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
14
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
14
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
15
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
16
import com.spice.profitmandi.dao.repository.dtr.PartnerOnBoardingPanelRepository;
15
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
17
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
16
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
18
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
17
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
19
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
18
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
20
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
21
import com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository;
19
import com.spice.profitmandi.service.NotificationService;
22
import com.spice.profitmandi.service.NotificationService;
20
import com.spice.profitmandi.service.PartnerInvestmentService;
23
import com.spice.profitmandi.service.PartnerInvestmentService;
-
 
24
import com.spice.profitmandi.service.user.StoreTimelineTatService;
21
import in.shop2020.model.v1.order.WalletReferenceType;
25
import in.shop2020.model.v1.order.WalletReferenceType;
22
import org.apache.logging.log4j.LogManager;
26
import org.apache.logging.log4j.LogManager;
23
import org.apache.logging.log4j.Logger;
27
import org.apache.logging.log4j.Logger;
24
import org.springframework.beans.factory.annotation.Autowired;
28
import org.springframework.beans.factory.annotation.Autowired;
25
import org.springframework.stereotype.Component;
29
import org.springframework.stereotype.Component;
Line 53... Line 57...
53
    @Autowired
57
    @Autowired
54
    private NotificationService notificationService;
58
    private NotificationService notificationService;
55
 
59
 
56
    @Autowired
60
    @Autowired
57
    RetailerRepository retailerRepository;
61
    RetailerRepository retailerRepository;
-
 
62
    @Autowired
-
 
63
    PartnerOnBoardingPanelRepository partnerOnBoardingPanelRepository;
-
 
64
    @Autowired
-
 
65
    StoreTimelineTatService storeTimelineTatService;
-
 
66
    @Autowired
-
 
67
    StoreTimelinetbRepository storeTimelinetbRepository;
58
 
68
 
59
    @Override
69
    @Override
60
    public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
70
    public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
61
                                  String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
71
                                  String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
62
        if (Math.round(amount) == 0)
72
        if (Math.round(amount) == 0)
63
            return;
73
            return;
64
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
74
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
65
        int walletAmount = this.getWalletAmount(retailerId);
75
        int walletAmount = this.getWalletAmount(retailerId);
66
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
-
 
67
        userWallet.setAmount(walletAmount + Math.round(amount));
76
        userWallet.setAmount(walletAmount + Math.round(amount));
68
        if (amount > 0) {
77
        if (amount > 0) {
69
            notificationService.sendNotification(retailerId, "walletcredit", MessageType.wallet, "Rs." + FormattingUtils.formatDecimal(amount) + " credited in SD Wallet", description);
78
            notificationService.sendNotification(retailerId, "walletcredit", MessageType.wallet, "Rs." + FormattingUtils.formatDecimal(amount) + " credited in SD Wallet", description);
70
        }
79
        }
71
        this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
80
        this.createUserWalletHistory(Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
-
 
81
        this.checkFullStockPayment(userWallet.getId(), retailerId);
-
 
82
    }
-
 
83
 
-
 
84
    private void checkFullStockPayment(int walletId, int retailerId) throws ProfitMandiBusinessException {
-
 
85
        List<UserWalletHistory> userWalletHistories = userWalletHistoryRepository.selectByWalletIdAndReferenceType(walletId, WalletReferenceType.ADVANCE_AMOUNT);
-
 
86
        long totalAdvanceAmount = userWalletHistories.stream().mapToLong(x -> x.getAmount()).sum();
-
 
87
        LOGGER.info("totalAdvanceAmount - " + totalAdvanceAmount);
-
 
88
        if (totalAdvanceAmount >= ProfitMandiConstants.MIN_FULL_STOCK_PAYMENT) {
-
 
89
            PartnerOnBoardingPanel pop = partnerOnBoardingPanelRepository.selectByCode(fofoStoreRepository.selectByRetailerId(retailerId).getCode());
-
 
90
            storeTimelineTatService.onFullPaymentReceived(pop.getId());
-
 
91
        }
72
    }
92
    }
73
 
93
 
74
    @Override
94
    @Override
75
    public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
95
    public void consumeAmountFromWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
76
                                        String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
96
                                        String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {