package report_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

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 main_package.DataBaseConnection;
import main_package.DataBaseMethods;
import main_package.DataBaseMethodsHemant;
import other_package.ReportInfo;

@ManagedBean(name="branchAnalysisReport")
@ViewScoped
public class BranchAnalysisReportBean implements Serializable
{
	Date startDate, endDate;
	ArrayList<ReportInfo> list;
	int branchId;
	String branchUserId;
	DataBaseMethodsHemant dbmh= new DataBaseMethodsHemant();
	List<SelectItem> branchList = new ArrayList<SelectItem>();
	boolean disAll;
	String userType;
	
	public BranchAnalysisReportBean() 
	{
		Connection conn=DataBaseConnection.JAVAConnection();
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchUserId = (String) ss.getAttribute("branchUserId");
		branchList = new DataBaseMethods().branchList(branchUserId,conn);
		startDate=new Date();
		endDate=new Date();
		startDate.setDate(1);
		String cc=(String) ss.getAttribute("companyName");

		userType= (String) ss.getAttribute("type");

	    disAll= dbmh.disAllByCompanyNameUserType(userType,cc);

		
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
    
	public void searchData()
	{
		list=new DataBaseReportMethods().branchAnalysisReport(startDate,endDate, branchId);
	}

	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 ArrayList<ReportInfo> getList() {
		return list;
	}

	public void setList(ArrayList<ReportInfo> list) {
		this.list = list;
	}

	public int getBranchId() {
		return branchId;
	}

	public void setBranchId(int branchId) {
		this.branchId = branchId;
	}

	public List<SelectItem> getBranchList() {
		return branchList;
	}

	public void setBranchList(List<SelectItem> branchList) {
		this.branchList = branchList;
	}

	public boolean isDisAll() {
		return disAll;
	}

	public void setDisAll(boolean disAll) {
		this.disAll = disAll;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}
}
