Subversion Repositories SmartDukaan

Rev

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

Rev 32871 Rev 33172
Line 10... Line 10...
10
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
10
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
11
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
11
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
12
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
12
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
13
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
13
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
14
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
14
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
-
 
15
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
15
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
16
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
16
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
17
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
17
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
18
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
18
import com.spice.profitmandi.service.NotificationService;
19
import com.spice.profitmandi.service.NotificationService;
19
import com.spice.profitmandi.service.PartnerInvestmentService;
20
import com.spice.profitmandi.service.PartnerInvestmentService;
Line 41... Line 42...
41
    @Autowired
42
    @Autowired
42
    PartnerInvestmentService partnerInvestmentService;
43
    PartnerInvestmentService partnerInvestmentService;
43
    private boolean underMaintainance = false;
44
    private boolean underMaintainance = false;
44
    @Autowired
45
    @Autowired
45
    private UserAccountRepository userAccountRepository;
46
    private UserAccountRepository userAccountRepository;
46
    @Autowired
47
 
47
    private WalletService walletService;
-
 
48
    @Autowired
48
    @Autowired
49
    private UserWalletRepository userWalletRepository;
49
    private UserWalletRepository userWalletRepository;
50
    @Autowired
50
    @Autowired
51
    private FofoStoreRepository fofoStoreRepository;
51
    private FofoStoreRepository fofoStoreRepository;
52
    @Autowired
52
    @Autowired
53
    private UserWalletHistoryRepository userWalletHistoryRepository;
53
    private UserWalletHistoryRepository userWalletHistoryRepository;
54
    @Autowired
54
    @Autowired
55
    private NotificationService notificationService;
55
    private NotificationService notificationService;
56
 
56
 
-
 
57
    @Autowired
-
 
58
    RetailerRepository retailerRepository;
-
 
59
 
57
    @Override
60
    @Override
58
    public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
61
    public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
59
                                  String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
62
                                  String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
60
        if (Math.round(amount) == 0)
63
        if (Math.round(amount) == 0)
61
            return;
64
            return;
62
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
65
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
63
        int walletAmount = walletService.getWalletAmount(retailerId);
66
        int walletAmount = this.getWalletAmount(retailerId);
64
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
67
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
65
        userWallet.setAmount(walletAmount + Math.round(amount));
68
        userWallet.setAmount(walletAmount + Math.round(amount));
66
        if (amount > 0) {
69
        if (amount > 0) {
67
            notificationService.sendNotification(retailerId, "walletcredit", MessageType.wallet, "Rs." + FormattingUtils.formatDecimal(amount) + " credited in SD Wallet", description);
70
            notificationService.sendNotification(retailerId, "walletcredit", MessageType.wallet, "Rs." + FormattingUtils.formatDecimal(amount) + " credited in SD Wallet", description);
68
        }
71
        }
Line 78... Line 81...
78
            throw inactivepbse;
81
            throw inactivepbse;
79
        }
82
        }
80
        if (amount == 0)
83
        if (amount == 0)
81
            return;
84
            return;
82
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
85
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
83
        int walletAmount = walletService.getWalletAmount(retailerId);
86
        int walletAmount = this.getWalletAmount(retailerId);
84
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
87
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
85
        if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > 2 && Math.floor(amount) > walletAmount) {
88
        if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > 2 && Math.floor(amount) > walletAmount) {
86
            LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}", Math.floor(amount), walletAmount);
89
            LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}", Math.floor(amount), walletAmount);
87
            throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
90
            throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
88
        }
91
        }
Line 100... Line 103...
100
            throw inactivepbse;
103
            throw inactivepbse;
101
        }
104
        }
102
        if (amount == 0)
105
        if (amount == 0)
103
            return;
106
            return;
104
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
107
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
105
        int walletAmount = walletService.getWalletAmount(retailerId);
108
        int walletAmount = this.getWalletAmount(retailerId);
106
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
109
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
107
        if (!forced && amount > 2 && amount > walletAmount) {
110
        if (!forced && amount > 2 && amount > walletAmount) {
108
            LOGGER.error("Wallet Balance is insufficient!");
111
            LOGGER.error("Wallet Balance is insufficient!");
109
            throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
112
            throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
110
        }
113
        }
Line 116... Line 119...
116
    public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
119
    public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference,
117
                                         WalletReferenceType walletReferenceType, String rollbackReason, LocalDateTime businessTime) throws ProfitMandiBusinessException {
120
                                         WalletReferenceType walletReferenceType, String rollbackReason, LocalDateTime businessTime) throws ProfitMandiBusinessException {
118
 
121
 
119
        if (amountToRollback == 0)
122
        if (amountToRollback == 0)
120
            return;
123
            return;
121
        int walletAmount = walletService.getWalletAmount(retailerId);
124
        int walletAmount = this.getWalletAmount(retailerId);
122
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
125
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
123
        List<UserWalletHistory> uwh = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(rollbackReference, walletReferenceType)
126
        List<UserWalletHistory> uwh = userWalletHistoryRepository.selectAllByreferenceIdandreferenceType(rollbackReference, walletReferenceType)
124
                .stream().filter(x -> x.getWalletId() == userWallet.getId()).collect(Collectors.toList());
127
                .stream().filter(x -> x.getWalletId() == userWallet.getId()).collect(Collectors.toList());
125
        if (uwh.size() == 0) {
128
        if (uwh.size() == 0) {
126
            LOGGER.info("Retailer with id {} dont have valid reference {} and reference type {}",
129
            LOGGER.info("Retailer with id {} dont have valid reference {} and reference type {}",
Line 279... Line 282...
279
 
282
 
280
        List<UserWalletHistory> all_entries = userWalletHistoryRepository
283
        List<UserWalletHistory> all_entries = userWalletHistoryRepository
281
                .selectAllByreferenceIdandreferenceType(transactionId, walletReferenceType);
284
                .selectAllByreferenceIdandreferenceType(transactionId, walletReferenceType);
282
 
285
 
283
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
286
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
284
        int walletAmount = walletService.getWalletAmount(retailerId);
287
        int walletAmount = this.getWalletAmount(retailerId);
285
        LOGGER.info("userWallet" + userWallet);
288
        LOGGER.info("userWallet" + userWallet);
286
        int max_eligible_credit_amount = 0;
289
        int max_eligible_credit_amount = 0;
287
 
290
 
288
        LOGGER.info("all_entries {}", all_entries);
291
        LOGGER.info("all_entries {}", all_entries);
289
        for (UserWalletHistory history : all_entries) {
292
        for (UserWalletHistory history : all_entries) {