Subversion Repositories SmartDukaan

Rev

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

Rev 34575 Rev 34674
Line 10... Line 10...
10
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
10
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
11
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
11
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
12
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
12
import com.spice.profitmandi.dao.entity.transaction.ManualPaymentType;
13
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
13
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
14
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
14
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
-
 
15
import com.spice.profitmandi.dao.entity.user.User;
15
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
16
import com.spice.profitmandi.dao.enumuration.dtr.AccountType;
16
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
17
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
17
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
18
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
18
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
19
import com.spice.profitmandi.dao.repository.catalog.ManualPaymentRequestRepository;
19
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
20
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
Line 21... Line 22...
21
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
22
import com.spice.profitmandi.dao.repository.dtr.RetailerRepository;
22
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
23
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
23
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
24
import com.spice.profitmandi.dao.repository.transaction.UserWalletHistoryRepository;
24
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
25
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
25
import com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository;
26
import com.spice.profitmandi.dao.repository.user.StoreTimelinetbRepository;
-
 
27
import com.spice.profitmandi.dao.repository.user.UserRepository;
26
import com.spice.profitmandi.service.NotificationService;
28
import com.spice.profitmandi.service.NotificationService;
27
import com.spice.profitmandi.service.PartnerInvestmentService;
29
import com.spice.profitmandi.service.PartnerInvestmentService;
28
import com.spice.profitmandi.service.order.OrderService;
30
import com.spice.profitmandi.service.order.OrderService;
29
import com.spice.profitmandi.service.user.RetailerService;
31
import com.spice.profitmandi.service.user.RetailerService;
30
import com.spice.profitmandi.service.user.StoreTimelineTatService;
32
import com.spice.profitmandi.service.user.StoreTimelineTatService;
Line 77... Line 79...
77
    @Autowired
79
    @Autowired
78
    StoreTimelineTatService storeTimelineTatService;
80
    StoreTimelineTatService storeTimelineTatService;
79
    @Autowired
81
    @Autowired
80
    StoreTimelinetbRepository storeTimelinetbRepository;
82
    StoreTimelinetbRepository storeTimelinetbRepository;
81
 
83
 
-
 
84
    @Autowired
-
 
85
    UserRepository userRepository;
-
 
86
 
82
    @Override
87
    @Override
83
    public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
88
    public void addAmountToWallet(int retailerId, int referenceId, WalletReferenceType referenceType,
84
                                  String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
89
                                  String description, float amount, LocalDateTime businessTime) throws ProfitMandiBusinessException {
85
        if (Math.round(amount) == 0)
90
        if (Math.round(amount) == 0)
86
            return;
91
            return;
Line 106... Line 111...
106
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
111
        UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
107
        int walletAmount = this.getWalletAmount(retailerId);
112
        int walletAmount = this.getWalletAmount(retailerId);
108
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
113
        // userWallet = userWalletRepository.selectByIdForUpdate(userWallet.getId());
109
        if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && Math.floor(amount) > walletAmount) {
114
        if (!WalletReferenceType.DAMAGE_PROTECTION.equals(referenceType) && amount > ProfitMandiConstants.MAX_NEGATIVE_WALLET_VALUE && Math.floor(amount) > walletAmount) {
110
            LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}, for retailer - {}", Math.floor(amount), walletAmount, retailerId);
115
            LOGGER.error("Wallet Balance is insufficient!, needed - {}, wallet has - {}, for retailer - {}", Math.floor(amount), walletAmount, retailerId);
-
 
116
            User user = userRepository.selectById(retailerId);
111
            throw new ProfitMandiBusinessException("balance", walletAmount, "WLT_1000");
117
            throw new ProfitMandiBusinessException(user.getName(), walletAmount, "WLT_1000");
112
        }
118
        }
113
        userWallet.setAmount(walletAmount - Math.round(amount));
119
        userWallet.setAmount(walletAmount - Math.round(amount));
114
        userWalletRepository.persist(userWallet);
120
        userWalletRepository.persist(userWallet);
115
        this.createUserWalletHistory(-Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
121
        this.createUserWalletHistory(-Math.round(amount), userWallet.getId(), referenceId, referenceType, description, businessTime);
116
    }
122
    }