Subversion Repositories SmartDukaan

Rev

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

Rev 33821 Rev 33828
Line 3709... Line 3709...
3709
            throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(), "Invalid LoanId");
3709
            throw new ProfitMandiBusinessException("loanstament", loanStatement.getLoanId(), "Invalid LoanId");
3710
        }
3710
        }
3711
    }
3711
    }
3712
 
3712
 
3713
    public void loanSettlement() throws Exception {
3713
    public void loanSettlement() throws Exception {
-
 
3714
        List<Integer> loanIds = Arrays.asList(21217,21220,21222);
3714
        List<Loan> blockedLoans = loanRepository.selectAllActiveLoan().stream().filter(x -> x.getFreeDays() >= 365).collect(toList());
3715
        List<Loan> blockedLoans = loanRepository.selectAllActiveLoan().stream().filter(x -> x.getFreeDays() >= 365).collect(toList());
3715
        List<Loan> loans = loanRepository.selectAllActiveLoan().stream().filter(x -> x.getFreeDays() < 365).collect(toList());
3716
        List<Loan> loans = loanRepository.selectAllActiveLoan().stream().filter(x -> x.getFreeDays() < 365).collect(toList());
3716
        //Settle blocked loans only when normal loans are settled
3717
        //Settle blocked loans only when normal loans are settled
3717
        loans.addAll(blockedLoans);
-
 
3718
        //TODO:Remove this code
-
 
3719
        Loan specificLoan = loanRepository.selectByLoanId(20230);
-
 
3720
        loans.add(0, specificLoan);
-
 
3721
        //TODO:Upto here
-
 
3722
        if (!loans.isEmpty()) {
-
 
3723
 
-
 
3724
            for (Loan loan : loans) {
-
 
3725
                double settledAmount = sdCreditService.settleLoan(loan);
-
 
3726
 
-
 
3727
                List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectHoldSanctionByFofoId(loan.getFofoId());
-
 
3728
                for (SanctionRequest sanctionRequest : sanctionRequests) {
-
 
3729
 
-
 
3730
                    List<Order> orders = orderRepository.selectAllByTransactionId(sanctionRequest.getTransactionId());
-
 
3731
                    if (orders.size() == 0) {
-
 
3732
                        LOGGER.info("Could not find orders - for Sanction Request {}", sanctionRequest);
-
 
3733
                        continue;
-
 
3734
                    }
-
 
3735
 
3718
 
-
 
3719
        for(int loanid : loanIds){
-
 
3720
            loans.addAll(blockedLoans);
-
 
3721
            //TODO:Remove this code
-
 
3722
            Loan specificLoan = loanRepository.selectByLoanId(loanid);
-
 
3723
            loans.add(0, specificLoan);
-
 
3724
            //TODO:Upto here
-
 
3725
            if (!loans.isEmpty()) {
-
 
3726
 
-
 
3727
                for (Loan loan : loans) {
-
 
3728
                    double settledAmount = sdCreditService.settleLoan(loan);
-
 
3729
 
-
 
3730
                    List<SanctionRequest> sanctionRequests = sanctionRequestRepository.selectHoldSanctionByFofoId(loan.getFofoId());
-
 
3731
                    for (SanctionRequest sanctionRequest : sanctionRequests) {
-
 
3732
 
-
 
3733
                        List<Order> orders = orderRepository.selectAllByTransactionId(sanctionRequest.getTransactionId());
-
 
3734
                        if (orders.size() == 0) {
-
 
3735
                            LOGGER.info("Could not find orders - for Sanction Request {}", sanctionRequest);
-
 
3736
                            continue;
-
 
3737
                        }
-
 
3738
 
3736
                    if (settledAmount >= sanctionRequest.getPendingAmount().doubleValue()) {
3739
                        if (settledAmount >= sanctionRequest.getPendingAmount().doubleValue()) {
3737
                        settledAmount -= sanctionRequest.getPendingAmount().doubleValue();
3740
                            settledAmount -= sanctionRequest.getPendingAmount().doubleValue();
3738
                        sanctionRequest.setPendingAmount(BigDecimal.valueOf(0));
3741
                            sanctionRequest.setPendingAmount(BigDecimal.valueOf(0));
3739
                        this.sendUnholdEmail(orders);
3742
                            this.sendUnholdEmail(orders);
3740
                    } else {
3743
                        } else {
3741
                        double pendinAmount = sanctionRequest.getPendingAmount().doubleValue() - settledAmount;
3744
                            double pendinAmount = sanctionRequest.getPendingAmount().doubleValue() - settledAmount;
3742
                        System.out.println("Pending Amount - " + pendinAmount);
3745
                            System.out.println("Pending Amount - " + pendinAmount);
3743
                        sanctionRequest.setPendingAmount(BigDecimal.valueOf(pendinAmount));
3746
                            sanctionRequest.setPendingAmount(BigDecimal.valueOf(pendinAmount));
3744
                        break;
3747
                            break;
3745
 
3748
 
3746
                    }
3749
                        }
3747
 
3750
 
-
 
3751
                    }
3748
                }
3752
                }
3749
            }
-
 
3750
 
3753
 
-
 
3754
            }
3751
        }
3755
        }
3752
 
3756
 
3753
 
3757
 
-
 
3758
 
3754
    }
3759
    }
3755
 
3760
 
3756
 
3761
 
3757
    private void sendUnholdEmail(List<Order> orders) throws Exception {
3762
    private void sendUnholdEmail(List<Order> orders) throws Exception {
3758
 
3763