package report_package;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import main_package.DataBaseMethods;
import main_package.LoanInfo;

import org.primefaces.context.RequestContext;

@ManagedBean(name="reportForROC")
@ViewScoped
public class ReportForROCBean implements Serializable
{
	Date startDate=new Date(), endDate=new Date();
	String searchType,labelName,eDate,selectionLoanInterestType;
	boolean showData;
	int totalEntry,interestRate;
	ArrayList<LoanInfo> list;
	DataBaseReportMethods dbmr=new DataBaseReportMethods();
	boolean renderForLoanReport=false,renderForDepositReport=false;
	SimpleDateFormat dd=new SimpleDateFormat("dd-MM-yyyy");
	public void searchData()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId = (int) ss.getAttribute("branchId");
		int i=1;
		eDate=dd.format(endDate);
		if(searchType.equalsIgnoreCase("Personal Loan") || searchType.equalsIgnoreCase("group Loan"))
		{
			showData=false;
			RequestContext context = RequestContext.getCurrentInstance();
			context.execute("PF('dlg2').show();");
		
		}
		else
		{
			list=dbmr.reportGenerateForRoc(branchId,startDate, endDate, searchType,interestRate,selectionLoanInterestType);
			if(list.size()>0)
			{
				for(LoanInfo ll:list)
				{
					ll.setSno(i++);
				}
				totalEntry=list.size();
				showData=true; 
				labelName="";
				renderForLoanReport=true;
				renderForDepositReport=false;
			}
			else
			{
				showData=false;
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("No Record Found"));
			}
		}
	}

	
	
	public void searchForLoan()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId = (int) ss.getAttribute("branchId");
		int i=1;
		if(interestRate > 0 )
		{
			list=dbmr.reportGenerateForRoc(branchId,startDate, endDate, searchType,interestRate,selectionLoanInterestType);
			if(list.size()>0)
			{
				for(LoanInfo ll:list)
				{
					ll.setSno(i++);
				}
				totalEntry=list.size();
				showData=true;
				labelName="Loan";
				renderForLoanReport=false;
				renderForDepositReport=true;
			}
			else
			{
				showData=false;
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("No Record Found"));
			}
		}
	}
	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public String getSearchType() {
		return searchType;
	}

	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}

	public boolean isShowData() {
		return showData;
	}

	public void setShowData(boolean showData) {
		this.showData = showData;
	}

	public int getTotalEntry() {
		return totalEntry;
	}

	public void setTotalEntry(int totalEntry) {
		this.totalEntry = totalEntry;
	}

	public ArrayList<LoanInfo> getList() {
		return list;
	}

	public void setList(ArrayList<LoanInfo> list) {
		this.list = list;
	}

	public int getInterestRate() {
		return interestRate;
	}

	public void setInterestRate(int interestRate) {
		this.interestRate = interestRate;
	}

	public boolean isRenderForLoanReport() {
		return renderForLoanReport;
	}

	public void setRenderForLoanReport(boolean renderForLoanReport) {
		this.renderForLoanReport = renderForLoanReport;
	}

	public boolean isRenderForDepositReport() {
		return renderForDepositReport;
	}

	public void setRenderForDepositReport(boolean renderForDepositReport) {
		this.renderForDepositReport = renderForDepositReport;
	}

	public String getLabelName() {
		return labelName;
	}

	public void setLabelName(String labelName) {
		this.labelName = labelName;
	}

	public String geteDate() {
		return eDate;
	}

	public void seteDate(String eDate) {
		this.eDate = eDate;
	}



	public String getSelectionLoanInterestType() {
		return selectionLoanInterestType;
	}



	public void setSelectionLoanInterestType(String selectionLoanInterestType) {
		this.selectionLoanInterestType = selectionLoanInterestType;
	}
	
	
}
