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 javax.swing.text.AbstractDocument.BranchElement;

import org.primefaces.context.RequestContext;

@ViewScoped
@ManagedBean(name="manageBusinessLoan")
public class ManageBusinessLoanBean implements Serializable
{
	DataBaseMethods obj=new DataBaseMethods();
	private static final long serialVersionUID = 1L;
	ArrayList<LoanInfo> pList,activeLoanList,closeLoanList;
	LoanInfo selectedLoan;
	String searchType;
	ArrayList<SelectItem> freqList;
	
	public ManageBusinessLoanBean()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId =(int) ss.getAttribute("branchId");
		Connection conn=DataBaseConnection.JAVAConnection();
		freqList=obj.frequencySelectItemListFormLoanTable(branchId,"business_loan",conn);
		pList = obj.businessLoanList(branchId,"All");
		
		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.personalLoanList(branchId,searchType, "All");
	}
	
	public void viewPersonalLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedLoan", selectedLoan);
		ss.setAttribute("pageName", "manageBusinessLoan.xhtml");
		
		RequestContext.getCurrentInstance().execute("window.open('viewBusinessLoan.xhtml')");
	}
	
	public void printSanctionLoan()
    {
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
        ss.setAttribute("selectedLoan",selectedLoan);
        RequestContext.getCurrentInstance().execute("window.open('printFormatOfSanctionNote.xhtml')");
    }
	
	public void editPersonalLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedLoan", selectedLoan);
		
		RequestContext.getCurrentInstance().execute("window.open('editBusinessLoan.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;
	}
}
