Subversion Repositories SmartDukaan

Rev

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

Rev 35824 Rev 35914
Line 37... Line 37...
37
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
37
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
38
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
38
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
39
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
39
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
40
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
40
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
41
import com.spice.profitmandi.service.transaction.SDCreditService;
41
import com.spice.profitmandi.service.transaction.SDCreditService;
-
 
42
import com.spice.profitmandi.service.transaction.SDCreditServiceImpl;
42
import com.spice.profitmandi.service.wallet.WalletService;
43
import com.spice.profitmandi.service.wallet.WalletService;
43
 
44
 
44
@Controller
45
@Controller
45
@Transactional(rollbackFor = Throwable.class)
46
@Transactional(rollbackFor = Throwable.class)
46
public class GatewayController {
47
public class GatewayController {
Line 79... Line 80...
79
 
80
 
80
	@Autowired
81
	@Autowired
81
	SDCreditRequirementRepository sdCreditRequirementRepository;
82
	SDCreditRequirementRepository sdCreditRequirementRepository;
82
 
83
 
83
	@Autowired
84
	@Autowired
-
 
85
	com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService partnerTypeChangeService;
-
 
86
 
-
 
87
	@Autowired
84
	LoanRepository loanRepository;
88
	LoanRepository loanRepository;
85
 
89
 
86
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
90
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
87
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
91
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
88
			throws ProfitMandiBusinessException {
92
			throws ProfitMandiBusinessException {
Line 139... Line 143...
139
 
143
 
140
			com.spice.profitmandi.dao.model.CreditSummary creditSummary = sdCreditService.getCreditSummary(retailerId);
144
			com.spice.profitmandi.dao.model.CreditSummary creditSummary = sdCreditService.getCreditSummary(retailerId);
141
 
145
 
142
			SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(retailerId);
146
			SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(retailerId);
143
 
147
 
-
 
148
			// Resolve effective credit days based on partner type (Diamond/Platinum=20, others=15)
-
 
149
			com.spice.profitmandi.dao.entity.fofo.PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(retailerId, java.time.LocalDate.now());
-
 
150
			int effectiveCreditDays = (partnerType == com.spice.profitmandi.dao.entity.fofo.PartnerType.DIAMOND || partnerType == com.spice.profitmandi.dao.entity.fofo.PartnerType.PLATINUM)
-
 
151
					? ProfitMandiConstants.PREMIUM_TIER1_DAYS : ProfitMandiConstants.DEFAULT_TIER1_DAYS;
-
 
152
 
144
			AccountStatusResponseOut accountStatusResponseOut = new AccountStatusResponseOut();
153
			AccountStatusResponseOut accountStatusResponseOut = new AccountStatusResponseOut();
145
			BigDecimal availability = BigDecimal.ZERO;
154
			BigDecimal availability = BigDecimal.ZERO;
146
			if (creditAccount != null) {
155
			if (creditAccount != null) {
147
 
156
 
148
				availability = sdCreditService.getAvailableAmount(retailerId);
157
				availability = sdCreditService.getAvailableAmount(retailerId);
Line 155... Line 164...
155
 
164
 
156
			if (availability.signum() == 1 && creditAccount.isActive() && creditSummary.getOverdueCount() == 0) {
165
			if (availability.signum() == 1 && creditAccount.isActive() && creditSummary.getOverdueCount() == 0) {
157
				accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
166
				accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
158
				accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
167
				accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
159
				accountStatusResponseOut.setPenalRateOfInterest(ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE);
168
				accountStatusResponseOut.setPenalRateOfInterest(ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE);
160
				accountStatusResponseOut.setCreditDays(sdCreditRequirement.getCreditDays());
169
				accountStatusResponseOut.setCreditDays(effectiveCreditDays);
161
			} else if (creditAccount != null && creditAccount.isActive() && creditSummary.getOverdueCount() > 0) {
170
			} else if (creditAccount != null && creditAccount.isActive() && creditSummary.getOverdueCount() > 0) {
162
				CreditSummary orderSummary = sdCreditService.getCreditSummaryForOrder(retailerId, 0);
171
				CreditSummary orderSummary = sdCreditService.getCreditSummaryForOrder(retailerId, 0);
163
				if (orderSummary.isCanPlaceOrder() && availability.signum() == 1) {
172
				if (orderSummary.isCanPlaceOrder() && availability.signum() == 1) {
164
					// Exception partner or has fresh money — allow ordering
173
					// Exception partner or has fresh money — allow ordering
165
					accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
174
					accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
166
					accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
175
					accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
167
					accountStatusResponseOut.setPenalRateOfInterest(ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE);
176
					accountStatusResponseOut.setPenalRateOfInterest(ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE);
168
					accountStatusResponseOut.setCreditDays(sdCreditRequirement.getCreditDays());
177
					accountStatusResponseOut.setCreditDays(effectiveCreditDays);
169
					if (orderSummary.getFreshMoneyAvailable() > 0) {
178
					if (orderSummary.getFreshMoneyAvailable() > 0) {
170
						BigDecimal effectiveLimit = availability.min(BigDecimal.valueOf(orderSummary.getFreshMoneyAvailable()));
179
						BigDecimal effectiveLimit = availability.min(BigDecimal.valueOf(orderSummary.getFreshMoneyAvailable()));
171
						accountStatusResponseOut.setBalanceAmount(effectiveLimit);
180
						accountStatusResponseOut.setBalanceAmount(effectiveLimit);
172
						accountStatusResponseOut.setStatusDescription(String.format(
181
						accountStatusResponseOut.setStatusDescription(String.format(
173
								"%d loan(s) overdue. Purchase restricted up to Rs. %.0f",
182
								"%d loan(s) overdue. Purchase restricted up to Rs. %.0f",
Line 180... Line 189...
180
							creditSummary.getOverdueCount()));
189
							creditSummary.getOverdueCount()));
181
				}
190
				}
182
			} else {
191
			} else {
183
				accountStatusResponseOut.setStatus(EligibilityStatusEnum.IN_ELIGIBLE);
192
				accountStatusResponseOut.setStatus(EligibilityStatusEnum.IN_ELIGIBLE);
184
			}
193
			}
-
 
194
			if (sdCreditRequirement != null) {
-
 
195
				accountStatusResponseOut.setOverdueRateOfInterest(ProfitMandiConstants.TIER2_INTEREST_RATE);
-
 
196
				accountStatusResponseOut.setFreeDays(sdCreditRequirement.getFreeDays());
-
 
197
				accountStatusResponseOut.setCreditTerms(SDCreditServiceImpl.buildCreditTerms(
-
 
198
						sdCreditRequirement.getInterestRate(),
-
 
199
						ProfitMandiConstants.TIER2_INTEREST_RATE,
-
 
200
						ProfitMandiConstants.NEW_DELAYED_INTEREST_RATE,
-
 
201
						effectiveCreditDays));
-
 
202
			}
185
			return responseSender.ok(accountStatusResponseOut);
203
			return responseSender.ok(accountStatusResponseOut);
186
		}
204
		}
187
 
205
 
188
		else {
206
		else {
189
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
207
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");