Subversion Repositories SmartDukaan

Rev

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

Rev 33851 Rev 33852
Line 55... Line 55...
55
import java.time.LocalTime;
55
import java.time.LocalTime;
56
import java.util.*;
56
import java.util.*;
57
import java.util.Map.Entry;
57
import java.util.Map.Entry;
58
import java.util.stream.Collectors;
58
import java.util.stream.Collectors;
59
 
59
 
60
import static java.util.stream.Collectors.toList;
-
 
61
 
-
 
62
@Controller
60
@Controller
63
@Transactional(rollbackOn = Throwable.class)
61
@Transactional(rollbackOn = Throwable.class)
64
public class SDCreditController {
62
public class SDCreditController {
65
 
63
 
66
    @Autowired
64
    @Autowired
Line 612... Line 610...
612
    }
610
    }
613
 
611
 
614
 
612
 
615
//    adjusting loan for specific loan if loan is not adjusting and other loan is adjusting
613
//    adjusting loan for specific loan if loan is not adjusting and other loan is adjusting
616
 
614
 
617
    @RequestMapping(value = "/settle/loan", method = RequestMethod.POST)
615
    @RequestMapping(value = "/settle-loan", method = RequestMethod.POST)
618
    public String settleAndCreateLoanById(HttpServletRequest request, @RequestParam int loanId, @RequestParam int fofoId, @RequestParam(defaultValue = "0") int loanAmount, Model model) throws Exception {
616
    public String settleAndCreateLoanById(HttpServletRequest request, @RequestParam int loanId, @RequestParam int fofoId, Model model) throws Exception {
619
        List<Loan> blockedLoans = loanRepository.selectAllActiveLoan().stream().filter(x -> x.getFreeDays() >= 365).collect(toList());
-
 
620
        List<Loan> loans = loanRepository.selectAllActiveLoan().stream().filter(x -> x.getFreeDays() < 365).collect(toList());
-
 
621
        //Settle blocked loans only when normal loans are settled
-
 
622
        loans.addAll(blockedLoans);
-
 
623
 
-
 
624
        Loan specificLoan = loanRepository.selectByLoanId(loanId);
617
        Loan loan = loanRepository.selectByLoanId(loanId);
625
        loans.add(0, specificLoan);
-
 
626
 
-
 
627
        if (!loans.isEmpty()) {
-
 
628
 
-
 
629
            for (Loan loan : loans) {
-
 
630
                double settledAmount = sdCreditService.settleLoan(loan);
-
 
631
 
-
 
632
                List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectHoldSanctionByFofoId(loan.getFofoId());
-
 
633
                for (SanctionRequest sanctionRequest : sanctionRequests) {
-
 
634
 
-
 
635
                    List<Order> orders = orderRepository.selectAllByTransactionId(sanctionRequest.getTransactionId());
-
 
636
                    if (orders.size() == 0) {
-
 
637
                        LOGGER.info("Could not find orders - for Sanction Request {}", sanctionRequest);
-
 
638
                        continue;
-
 
639
                    }
-
 
640
 
-
 
641
                    if (settledAmount >= sanctionRequest.getPendingAmount().doubleValue()) {
-
 
642
                        settledAmount -= sanctionRequest.getPendingAmount().doubleValue();
618
        double loanAmount = loan.getPendingAmount().doubleValue();
643
                        sanctionRequest.setPendingAmount(BigDecimal.valueOf(0));
-
 
644
                        this.sendUnholdEmail(orders);
-
 
645
                    } else {
-
 
646
                        double pendinAmount = sanctionRequest.getPendingAmount().doubleValue() - settledAmount;
-
 
647
                        System.out.println("Pending Amount - " + pendinAmount);
-
 
648
                        sanctionRequest.setPendingAmount(BigDecimal.valueOf(pendinAmount));
-
 
649
                        break;
-
 
650
 
-
 
651
                    }
-
 
652
 
-
 
653
                }
-
 
654
            }
-
 
655
 
-
 
656
        }
-
 
657
 
619
 
658
        if (loanAmount > 0) {
620
        if (loanAmount > 0) {
659
            sdCreditService.createLoan(fofoId, loanAmount, 0, "Amount added for loan adjustment");
621
            sdCreditService.createLoan(fofoId, loanAmount, 0, "Amount added for loan adjustment");
-
 
622
            sdCreditService.settleLoan(loan);
660
        }
623
        }
661
 
624
 
662
 
625
 
663
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
626
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
664
 
627