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.servlet.http.HttpSession;

import org.primefaces.context.RequestContext;

@ManagedBean(name = "viewPersonaCloseLoan")
@ViewScoped
public class ViewPersonalCloseLoanBean implements Serializable 
{
	DataBaseMethods obj=new DataBaseMethods();
	private static final long serialVersionUID = 1L;
	ArrayList<LoanInfo> pList,sList,cList;
	LoanInfo selectedLoan;
	
	public ViewPersonalCloseLoanBean()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId = (int) ss.getAttribute("branchId");
		Connection con= DataBaseConnection.JAVAConnection();
		pList = obj.personalCloseLoanList(branchId,con);
		sList=obj.personalActiveLoanList(branchId,con);
		cList= obj.personalPendingLoanList(branchId,con);
		
		try {
			con.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public String viewPersonalLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedLoan", selectedLoan);
		ss.setAttribute("pageName", "editViewPersonalLoan.xhtml");
		return "viewPersonalLoan";
	}
	
	public void printSanctionLoan()
    {
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        ss.setAttribute("selectedLoan",selectedLoan);
        RequestContext.getCurrentInstance().execute("window.open('printFormatOfSanctionNote.xhtml')");
    }
	
	public String editPersonalLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedLoan", selectedLoan);
		return "editPersonalLoan";
	}
	
	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 ArrayList<LoanInfo> getsList() {
		return sList;
	}

	public void setsList(ArrayList<LoanInfo> sList) {
		this.sList = sList;
	}

	public ArrayList<LoanInfo> getcList() {
		return cList;
	}

	public void setcList(ArrayList<LoanInfo> cList) {
		this.cList = cList;
	}
	
}
