package main_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;

import org.primefaces.context.RequestContext;

@ViewScoped
@ManagedBean(name="manageSecureLoan")
public class ManageSecureLoanBean implements Serializable
{
	DataBaseMethods obj=new DataBaseMethods();
	private static final long serialVersionUID = 1L;
	ArrayList<LoanInfo> pList,activeLoanList,closeLoanList;
	LoanInfo selectedLoan; 
	DataBaseMethodsHemant dbmh= new DataBaseMethodsHemant();
	String searchType, dsaCode, loanSearchType, searchLoan, userId,securityType; 
	ArrayList<SelectItem> freqList, dsaList, loanList,loanSecurityList; 
	boolean printOne, printTwo, printThree, printFour, printFive, printSix, printSeven, printEight, printNine, printTenth, printEleventh,printTwelth, showBtn, disDsa,showData;
	boolean printMob1,printMob2,showMobile;
	boolean printVehicleLoan;
	DbYashwant dby = new DbYashwant();
	
	DataBaseMethodTaheer dbmt= new DataBaseMethodTaheer();
	String companyName;
     
	
	
	public ManageSecureLoanBean()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId =(int) ss.getAttribute("branchId");
		Connection conn=DataBaseConnection.JAVAConnection();
		dsaList=obj.allDsaList(branchId,"",conn);
		freqList=obj.frequencySelectItemListFormLoanTable(branchId,"secure_loan",conn);
	     companyName = 	dbmt.companyNameByBranchId(branchId);
		//pList = obj.secureLoanList(branchId,"All");
		userId=obj.userId();
		loanSecurityList = dby.secureLoanSecurityList(conn);
		String empDataStatus=obj.checkSMessageApiDetailFromTable("employee_wise_data", "",conn);
		if(obj.userType().equals("employee") && empDataStatus.equalsIgnoreCase("active"))
		{
			dsaCode=obj.dsaCodeByEmpUserId(userId, conn);
			if(companyName.equalsIgnoreCase("SUDERSHANA FINANCE"))
			{
				disDsa=false;
			}
			else 
			{
				disDsa=true;

			}
			
		}
		
	
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void searchData()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId =(int) ss.getAttribute("branchId");
		pList = obj.secureLoanList(branchId,dsaCode, loanSearchType, searchType, searchLoan,securityType);
		showData=true;
		
		if(searchType.equalsIgnoreCase("14"))
		{
			showMobile = true;
		}
		else
		{
			showMobile= false;
		}
	}
	
	public void freqWiseLoanList()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId =(int) ss.getAttribute("branchId");
		Connection conn=DataBaseConnection.JAVAConnection();
		showBtn=true;
		loanList=obj.loanNoListFreqWise(searchType,"secure_loan",branchId,conn);	
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void viewSecureLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedLoan", selectedLoan);
		ss.setAttribute("pageName", "manageSecureLoan.xhtml");
		
		RequestContext.getCurrentInstance().execute("window.open('viewSecureLoan.xhtml')");
	}
	
	public void printSanctionLoan()
    {
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        ss.setAttribute("selectedLoan",selectedLoan);
        
        if(printOne==true)
        {
        	 RequestContext.getCurrentInstance().execute("window.open('printFormatOfSanctionNote.xhtml')");
        }
        
        if(printTwo==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printSanctionLetter.xhtml')");
        }
        
        if(printThree==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printRepaymentSchedule.xhtml')");
        }
        
        if(printFour==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printRepayment.xhtml')");
        }
        
        if(printFive==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printDpn.xhtml')");
        }
        
        if(printSix==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printAgreementForm.xhtml')");
        }
        
        if(printSeven==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printDisbursementLetter.xhtml')");
        }
        
        if(printEight==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printDpnHindi.xhtml')");
        }
        
        if(printNine==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printWelcomeLetter.xhtml')");
        }
        
        if(printTenth==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printLoanApplicationForm.xhtml')");
            
            UserInfo selecteduser=new UserInfo();
            selecteduser=obj.allShareHoldersForView(selectedLoan.getShareHolderNo(), selecteduser);
            selecteduser=obj.allShareHoldersForView(selecteduser.getShareHolderNo(),selecteduser);
    		ss.setAttribute("selecteduserForPrintRegForm",selecteduser);
        }
        
        if(printEleventh==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printLoanForm.xhtml')");
        }
        if(printTwelth==true)
        {
        	 
        	 if(securityType.equalsIgnoreCase("14")||securityType.equalsIgnoreCase("15"))
        	 {
            	 RequestContext.getCurrentInstance().execute("window.open('printMobileAggrementIII.xhtml')");
 
        	 }else {
             	RequestContext.getCurrentInstance().execute("window.open('printGoldLoanFormat.xhtml')");

        	 }
        }
        
        if(printMob1==true)
        {
            RequestContext.getCurrentInstance().execute("window.open('printMobileAgreement.xhtml')");
            RequestContext.getCurrentInstance().execute("window.open('printMobileAgreementII.xhtml')");
           
        }
        
        if (printVehicleLoan == true) {
			
     	   ss.setAttribute("selectedLoan", selectedLoan);
     	
     	 RequestContext.getCurrentInstance().execute("window.open('printFormateRKFinanceVehicleLoan.xhtml')");
     	
		}
       
    }
	
	public void editSecureLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedLoan", selectedLoan);
		
		RequestContext.getCurrentInstance().execute("window.open('editSecureLoan.xhtml')");
	}
	
	public void printAgreementForm()
    {
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        ss.setAttribute("selectedLoan",selectedLoan);
        RequestContext.getCurrentInstance().execute("window.open('printAgreementForm.xhtml')");
    }
	

	public LoanInfo getSelectedLoan() {
		return selectedLoan;
	}
	public void setSelectedLoan(LoanInfo selectedLoan) {
		this.selectedLoan = selectedLoan;
	}
	public ArrayList<LoanInfo> getpList() {
		return pList;
	}
	public void setpList(ArrayList<LoanInfo> pList) {
		this.pList = pList;
	}

	public String getSearchType() {
		return searchType;
	}

	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	public ArrayList<SelectItem> getFreqList() {
		return freqList;
	}

	public void setFreqList(ArrayList<SelectItem> freqList) {
		this.freqList = freqList;
	}

	public boolean isPrintOne() {
		return printOne;
	}

	public void setPrintOne(boolean printOne) {
		this.printOne = printOne;
	}

	public boolean isPrintTwo() {
		return printTwo;
	}

	public void setPrintTwo(boolean printTwo) {
		this.printTwo = printTwo;
	}

	public boolean isPrintThree() {
		return printThree;
	}

	public void setPrintThree(boolean printThree) {
		this.printThree = printThree;
	}

	public boolean isPrintFour() {
		return printFour;
	}

	public void setPrintFour(boolean printFour) {
		this.printFour = printFour;
	}

	public boolean isPrintFive() {
		return printFive;
	}

	public void setPrintFive(boolean printFive) {
		this.printFive = printFive;
	}

	public boolean isPrintSix() {
		return printSix;
	}

	public void setPrintSix(boolean printSix) {
		this.printSix = printSix;
	}

	public boolean isPrintSeven() {
		return printSeven;
	}

	public void setPrintSeven(boolean printSeven) {
		this.printSeven = printSeven;
	}

	public boolean isPrintEight() {
		return printEight;
	}

	public void setPrintEight(boolean printEight) {
		this.printEight = printEight;
	}

	public boolean isPrintNine() {
		return printNine;
	}

	public void setPrintNine(boolean printNine) {
		this.printNine = printNine;
	}

	public boolean isPrintTenth() {
		return printTenth;
	}

	public void setPrintTenth(boolean printTenth) {
		this.printTenth = printTenth;
	}

	public boolean isPrintEleventh() {
		return printEleventh;
	}

	public void setPrintEleventh(boolean printEleventh) {
		this.printEleventh = printEleventh;
	}

	public String getDsaCode() {
		return dsaCode;
	}

	public void setDsaCode(String dsaCode) {
		this.dsaCode = dsaCode;
	}

	public String getLoanSearchType() {
		return loanSearchType;
	}

	public void setLoanSearchType(String loanSearchType) {
		this.loanSearchType = loanSearchType;
	}

	public String getSearchLoan() {
		return searchLoan;
	}

	public void setSearchLoan(String searchLoan) {
		this.searchLoan = searchLoan;
	}

	public ArrayList<SelectItem> getDsaList() {
		return dsaList;
	}

	public void setDsaList(ArrayList<SelectItem> dsaList) {
		this.dsaList = dsaList;
	}

	public boolean isShowBtn() {
		return showBtn;
	}

	public void setShowBtn(boolean showBtn) {
		this.showBtn = showBtn;
	}

	public ArrayList<SelectItem> getLoanList() {
		return loanList;
	}

	public void setLoanList(ArrayList<SelectItem> loanList) {
		this.loanList = loanList;
	}

	public boolean isDisDsa() {
		return disDsa;
	}

	public void setDisDsa(boolean disDsa) {
		this.disDsa = disDsa;
	}

	public boolean isShowData() {
		return showData;
	}

	public void setShowData(boolean showData) {
		this.showData = showData;
	}

	public ArrayList<SelectItem> getLoanSecurityList() {
		return loanSecurityList;
	}

	public void setLoanSecurityList(ArrayList<SelectItem> loanSecurityList) {
		this.loanSecurityList = loanSecurityList;
	}

	public String getSecurityType() {
		return securityType;
	}

	public void setSecurityType(String securityType) {
		this.securityType = securityType;
	}

	public boolean isPrintTwelth() {
		return printTwelth;
	}

	public void setPrintTwelth(boolean printTwelth) {
		this.printTwelth = printTwelth;
	}

	public boolean isPrintMob1() {
		return printMob1;
	}

	public void setPrintMob1(boolean printMob1) {
		this.printMob1 = printMob1;
	}

	public boolean isPrintMob2() {
		return printMob2;
	}

	public void setPrintMob2(boolean printMob2) {
		this.printMob2 = printMob2;
	}

	public boolean isShowMobile() {
		return showMobile;
	}

	public void setShowMobile(boolean showMobile) {
		this.showMobile = showMobile;
	}

	public boolean isPrintVehicleLoan() {
		return printVehicleLoan;
	}

	public void setPrintVehicleLoan(boolean printVehicleLoan) {
		this.printVehicleLoan = printVehicleLoan;
	}
}
