Subversion Repositories SmartDukaan

Rev

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

Rev 23504 Rev 23509
Line 51... Line 51...
51
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
51
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
52
		if(amount > userWallet.getAmount()){
52
		if(amount > userWallet.getAmount()){
53
			LOGGER.error("Wallet Balance is insufficient!");
53
			LOGGER.error("Wallet Balance is insufficient!");
54
			throw new ProfitMandiBusinessException("balance", userWallet.getAmount(), "WLT_1000");
54
			throw new ProfitMandiBusinessException("balance", userWallet.getAmount(), "WLT_1000");
55
		}
55
		}
56
		userWallet.setAmount(userWallet.getAmount() - Float.valueOf(amount).intValue());
56
		userWallet.setAmount(userWallet.getAmount() - Math.round(amount));
57
		userWalletRepository.persist(userWallet);
57
		userWalletRepository.persist(userWallet);
58
		this.createUserWalletHistory(-amount, userWallet.getId(), referenceId, referenceType, description);
58
		this.createUserWalletHistory(-Math.round(amount), userWallet.getId(), referenceId, referenceType, description);
-
 
59
	}
-
 
60
	
-
 
61
 
-
 
62
	@Override
-
 
63
	public void rollbackAmountFromWallet(int retailerId, float amountToRollback, int rollbackReference, WalletReferenceType walletReferenceType,
-
 
64
			String rollbackReason) {
-
 
65
		UserWallet userWallet = this.getUserWallet(retailerId);
-
 
66
		userWallet.setAmount(userWallet.getAmount() - Math.round(amountToRollback));
-
 
67
		userWalletRepository.persist(userWallet);
-
 
68
		this.createUserWalletHistory(-Math.round(amountToRollback), userWallet.getId(), rollbackReference, walletReferenceType, rollbackReason);
-
 
69
		
59
	}
70
	}
60
	
71
	
61
	private void createUserWalletHistory(float amount, int walletId, int referenceId, WalletReferenceType referenceType, String description){
72
	private void createUserWalletHistory(float amount, int walletId, int referenceId, WalletReferenceType referenceType, String description){
62
		UserWalletHistory userWalletHistory = new UserWalletHistory();
73
		UserWalletHistory userWalletHistory = new UserWalletHistory();
63
		userWalletHistory.setWalletId(walletId);
74
		userWalletHistory.setWalletId(walletId);
Line 118... Line 129...
118
	public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType) throws ProfitMandiBusinessException{
129
	public boolean isExistWalletHistory(int retailerId, int referenceId, WalletReferenceType referenceType) throws ProfitMandiBusinessException{
119
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
130
		UserWallet userWallet = userWalletRepository.selectByRetailerId(retailerId);
120
		return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
131
		return userWalletHistoryRepository.isExist(userWallet.getId(), referenceType, referenceId);
121
	}
132
	}
122
 
133
 
-
 
134
	@Override
-
 
135
	public UserWallet getUserWallet(int retailerId) {
-
 
136
		try {
-
 
137
			return userWalletRepository.selectByRetailerId(retailerId);
-
 
138
		} catch(Exception e) {
-
 
139
			UserWallet uw = new UserWallet();
-
 
140
			uw.setAmount(0);
-
 
141
			uw.setRefundableAmount(0);
-
 
142
			uw.setUserId(retailerId);
-
 
143
			userWalletRepository.persist(uw);
-
 
144
			return uw;
-
 
145
		}
-
 
146
	}
-
 
147
 
123
}
148
}