Subversion Repositories SmartDukaan

Rev

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

Rev 33827 Rev 33851
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
 
60
@Controller
62
@Controller
61
@Transactional(rollbackOn = Throwable.class)
63
@Transactional(rollbackOn = Throwable.class)
62
public class SDCreditController {
64
public class SDCreditController {
63
 
65
 
64
    @Autowired
66
    @Autowired
Line 607... Line 609...
607
 
609
 
608
        return "response";
610
        return "response";
609
 
611
 
610
    }
612
    }
611
 
613
 
-
 
614
 
-
 
615
//    adjusting loan for specific loan if loan is not adjusting and other loan is adjusting
-
 
616
 
-
 
617
    @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 {
-
 
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);
-
 
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();
-
 
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
 
-
 
658
        if (loanAmount > 0) {
-
 
659
            sdCreditService.createLoan(fofoId, loanAmount, 0, "Amount added for loan adjustment");
-
 
660
        }
-
 
661
 
-
 
662
 
-
 
663
        model.addAttribute("response1", mvcResponseSender.createResponseString(true));
-
 
664
 
-
 
665
        return "response";
-
 
666
 
-
 
667
    }
-
 
668
 
-
 
669
 
-
 
670
    private void sendUnholdEmail(List<Order> orders) throws Exception {
-
 
671
 
-
 
672
 
-
 
673
        orders.forEach(x -> x.setShipmentHold(false));
-
 
674
        orders = orders.stream().filter(x -> x.getRefundTimestamp() != null).collect(Collectors.toList());
-
 
675
        if (orders.size() > 0) {
-
 
676
 
-
 
677
            double totalAmount = orders.stream().collect(Collectors.summingDouble(x -> x.getTotalAmount()));
-
 
678
 
-
 
679
            List<String> authUserEmail = csService.getAuthUserIdByPartnerId(orders.get(0).getRetailerId()).stream().map(x -> x.getEmailId()).collect(Collectors.toList());
-
 
680
            authUserEmail.add("vinay.p@smartdukaan.com");
-
 
681
            authUserEmail.add("shivam.gupta@smartdukaan.com");
-
 
682
 
-
 
683
            String[] emailTo = authUserEmail.toArray(new String[authUserEmail.size()]);
-
 
684
 
-
 
685
            String[] ccTo = {"tarun.verma@smartdukaan.com", "kamini.sharma@smartdukaan.com"};
-
 
686
 
-
 
687
            String subject = "Dispatch held orders of - " + (orders.get(0).getRetailerName());
-
 
688
            String message = String.format("Dear Team, \n" + "kindly note the material for the " + orders.get(0).getRetailerName() + "of Rs." + totalAmount + "is unhold now and needs to be dispatched.");
-
 
689
            Utils.sendMailWithAttachments(mailSender, emailTo, ccTo, subject, message);
-
 
690
        }
-
 
691
 
-
 
692
 
-
 
693
    }
-
 
694
 
612
}
695
}
613
696