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="businessReport")
@ViewScoped
public class BusinessReportBean 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();
	DataBaseMethodsHemant dbmh= new DataBaseMethodsHemant();
	boolean disAll;
	String userType;
	
	public BusinessReportBean() 
	{
		Connection conn=DataBaseConnection.JAVAConnection();
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchId =(int) ss.getAttribute("branchId");
		branchUserId = (String) ss.getAttribute("branchUserId");
		branchList = new DataBaseMethods().branchList(branchUserId,conn);
		String cc=(String) ss.getAttribute("companyName");

		startDate=new Date();
		endDate=new Date();
		startDate.setDate(1);
		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.businessReportBetweenDate(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 String getBranchUserId() {
		return branchUserId;
	}

	public void setBranchUserId(String branchUserId) {
		this.branchUserId = branchUserId;
	}

	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;
	}
}
