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 main_package.HeaderBean;
import other_package.ReportInfo;

@ManagedBean(name="businessPerformanceReport")
@ViewScoped

public class BusinessPerformanceReportBean implements Serializable
{
	Date startDate, endDate;
	ArrayList<ReportInfo> list;
	String dsaCode, branchUserId;
	ArrayList<SelectItem> dsaList;
	int frequency, branchId;
	List<SelectItem> branchList = new ArrayList<SelectItem>();
	DataBaseReportMethods dbmr=new DataBaseReportMethods();
	DataBaseMethods dbm=new DataBaseMethods();
	String userType;
	boolean disAll;
	DataBaseMethodsHemant dbmh= new DataBaseMethodsHemant();

	
	public BusinessPerformanceReportBean() 
	{   
		Connection conn=DataBaseConnection.JAVAConnection();
		HttpSession ss =(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchId =(int) ss.getAttribute("branchId");
		String cc=(String) ss.getAttribute("companyName");
		HeaderBean db= new HeaderBean();
        String companyNameIs= db.getCompanyName();
        System.out.println("hhhhhhhhhhhh"+companyNameIs);
		branchUserId = (String) ss.getAttribute("branchUserId");
		
		branchList = new DataBaseMethods().branchList(branchUserId,conn);
		startDate=new Date();
		endDate=new Date();
		startDate.setDate(1);
		//userType= db.getUserType();
		//System.out.println("in constructon usertype is:"+userType);
		userType= (String) ss.getAttribute("type");
	    disAll= dbmh.disAllByCompanyNameUserType(userType,cc);

		dsaList=dbm.allDsaList(branchId,"",conn);

		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void searchData()
	{
		list=dbmr.businessPerformanceReportBetweenDate(startDate, endDate, frequency, dsaCode, 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 String getDsaCode() {
		return dsaCode;
	}

	public void setDsaCode(String dsaCode) {
		this.dsaCode = dsaCode;
	}

	public ArrayList<SelectItem> getDsaList() {
		return dsaList;
	}

	public void setDsaList(ArrayList<SelectItem> dsaList) {
		this.dsaList = dsaList;
	}

	public int getFrequency() {
		return frequency;
	}

	public void setFrequency(int frequency) {
		this.frequency = frequency;
	}

	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 String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public boolean isDisAll() {
		return disAll;
	}

	public void setDisAll(boolean disAll) {
		this.disAll = disAll;
	}
	
	
}
