| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.math.BigDecimal;
|
3 |
import java.math.BigDecimal;
|
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.Arrays;
|
- |
|
| 6 |
import java.util.List;
|
- |
|
| 7 |
|
5 |
|
| 8 |
import javax.servlet.http.HttpServletRequest;
|
6 |
import javax.servlet.http.HttpServletRequest;
|
| 9 |
|
7 |
|
| 10 |
import org.apache.logging.log4j.LogManager;
|
8 |
import org.apache.logging.log4j.LogManager;
|
| 11 |
import org.apache.logging.log4j.Logger;
|
9 |
import org.apache.logging.log4j.Logger;
|
| Line 34... |
Line 32... |
| 34 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
32 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 35 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
33 |
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
|
| 36 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
34 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 37 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
35 |
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
|
| 38 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
36 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
| 39 |
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
|
- |
|
| 40 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
37 |
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
|
| 41 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
38 |
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
39 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 43 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
40 |
import com.spice.profitmandi.service.transaction.SDCreditService;
|
| 44 |
import com.spice.profitmandi.service.wallet.WalletService;
|
41 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| Line 83... |
Line 80... |
| 83 |
SDCreditRequirementRepository sdCreditRequirementRepository;
|
80 |
SDCreditRequirementRepository sdCreditRequirementRepository;
|
| 84 |
|
81 |
|
| 85 |
@Autowired
|
82 |
@Autowired
|
| 86 |
LoanRepository loanRepository;
|
83 |
LoanRepository loanRepository;
|
| 87 |
|
84 |
|
| 88 |
@Autowired
|
- |
|
| 89 |
private LoanStatementRepository loanStatementRepository;
|
- |
|
| 90 |
|
- |
|
| 91 |
@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
85 |
@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 92 |
public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
|
86 |
public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
|
| 93 |
throws ProfitMandiBusinessException {
|
87 |
throws ProfitMandiBusinessException {
|
| 94 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
88 |
int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
|
| 95 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
89 |
int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
|
| Line 140... |
Line 134... |
| 140 |
}
|
134 |
}
|
| 141 |
} else if (gateway != null && gateway.equals(Gateway.SDDIRECT)) {
|
135 |
} else if (gateway != null && gateway.equals(Gateway.SDDIRECT)) {
|
| 142 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
|
136 |
CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
|
| 143 |
Gateway.SDDIRECT);
|
137 |
Gateway.SDDIRECT);
|
| 144 |
|
138 |
|
| 145 |
/*List<Loan> loans = loanRepository.selectActiveLoan(retailerId).stream()
|
139 |
com.spice.profitmandi.dao.model.CreditSummary creditSummary = sdCreditService.getCreditSummary(retailerId);
|
| 146 |
.filter(x -> x.getDueDate().isBefore(LocalDateTime.now())).collect(Collectors.toList());*/
|
- |
|
| 147 |
//TODO Amit - Bypass due date condition need to undo
|
- |
|
| 148 |
List<Loan> loans = Arrays.asList();
|
- |
|
| 149 |
|
140 |
|
| 150 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(retailerId);
|
141 |
SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(retailerId);
|
| 151 |
|
142 |
|
| 152 |
AccountStatusResponseOut accountStatusResponseOut = new AccountStatusResponseOut();
|
143 |
AccountStatusResponseOut accountStatusResponseOut = new AccountStatusResponseOut();
|
| 153 |
BigDecimal availability = BigDecimal.ZERO;
|
144 |
BigDecimal availability = BigDecimal.ZERO;
|
| Line 159... |
Line 150... |
| 159 |
log.info("availability {}", availability);
|
150 |
log.info("availability {}", availability);
|
| 160 |
accountStatusResponseOut.setBalanceAmount(availability);
|
151 |
accountStatusResponseOut.setBalanceAmount(availability);
|
| 161 |
|
152 |
|
| 162 |
}
|
153 |
}
|
| 163 |
|
154 |
|
| 164 |
if (availability.signum() == 1 && creditAccount.isActive() && loans.isEmpty()) {
|
155 |
if (availability.signum() == 1 && creditAccount.isActive() && creditSummary.getOverdueCount() == 0) {
|
| 165 |
accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
|
156 |
accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
|
| 166 |
accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
|
157 |
accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
|
| 167 |
accountStatusResponseOut.setPenalRateOfInterest(ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE);
|
158 |
accountStatusResponseOut.setPenalRateOfInterest(ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE);
|
| 168 |
accountStatusResponseOut.setCreditDays(sdCreditRequirement.getCreditDays());
|
159 |
accountStatusResponseOut.setCreditDays(sdCreditRequirement.getCreditDays());
|
| 169 |
} else {
|
160 |
} else {
|
| 170 |
accountStatusResponseOut.setStatus(EligibilityStatusEnum.IN_ELIGIBLE);
|
161 |
accountStatusResponseOut.setStatus(EligibilityStatusEnum.IN_ELIGIBLE);
|
| 171 |
String statusDescription = null;
|
162 |
String statusDescription = null;
|
| 172 |
if(!loans.isEmpty()) {
|
163 |
if (creditSummary.getOverdueCount() > 0) {
|
| 173 |
statusDescription = String.format("Due date have been exceeded for %d loans. Pls clear the overdues to utilize balance credit", loans.size());
|
164 |
statusDescription = String.format("Due date have been exceeded for %d loans. Pls clear the overdues to utilize balance credit", creditSummary.getOverdueCount());
|
| 174 |
}
|
165 |
}
|
| 175 |
accountStatusResponseOut.setStatusDescription(statusDescription);
|
166 |
accountStatusResponseOut.setStatusDescription(statusDescription);
|
| 176 |
}
|
167 |
}
|
| 177 |
return responseSender.ok(accountStatusResponseOut);
|
168 |
return responseSender.ok(accountStatusResponseOut);
|
| 178 |
}
|
169 |
}
|