package main_package;
import java.io.Serializable;
import java.sql.Connection;
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;

@ManagedBean(name="collectionByDateBean")
@ViewScoped

public class CollectionAnalysisByDateBean implements Serializable
{
	private static final long serialVersionUID = 1L;
	
	int changeBranch;
	int searchBase;
    
    String loanType,searchType;
    String searchDate ;
    
    Date startDate=new Date(),endDate=new Date();
    
    boolean show,value;
	
    ArrayList<CollectionInfo> list;
    
	DataBaseMethods db = new DataBaseMethods();
    DataBaseMethodsRaviK dbr = new DataBaseMethodsRaviK();
    
    SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy");    
	    
    
    
    public void searchReport()
   	{	
    	searchDate = sdf.format(startDate);
    	
   		Connection conn = DataBaseConnection.JAVAConnection();
   	    try
   	    {   
   	    	list = dbr.report(loanType, startDate, searchBase);
		   
   	        if (list != null && !list.isEmpty())
   	        {
   	            show = true;

   	            FacesContext.getCurrentInstance().addMessage(null,
   	                    new FacesMessage(FacesMessage.SEVERITY_INFO,"Record Found Successfully", ""));
   	        }
   	        else
   	        {
   	            show = false;

   	            FacesContext.getCurrentInstance().addMessage(null,
   	                    new FacesMessage(FacesMessage.SEVERITY_WARN,"No Record Found",""));
   	        }
   	    }
   	    catch (Exception e)
   	    {
   	        e.printStackTrace();

   	        FacesContext.getCurrentInstance().addMessage(null,
   	                new FacesMessage(FacesMessage.SEVERITY_ERROR,"Something went wrong",""));
   	    }
   	    finally
   	    {
   	        try
   	        {
   	            if (conn != null)
   	            {
   	                conn.close();
   	            }
   	        }
   	        catch (Exception e)
   	        {
   	            e.printStackTrace();
   	        }
   	    }
   	}

    

	public int getChangeBranch() {
		return changeBranch;
	}


	public void setChangeBranch(int changeBranch) {
		this.changeBranch = changeBranch;
	}


	public boolean isShow() {
		return show;
	}


	public void setShow(boolean show) {
		this.show = show;
	}


	public boolean isValue() {
		return value;
	}


	public void setValue(boolean value) {
		this.value = value;
	}


	public String getLoanType() {
		return loanType;
	}


	public void setLoanType(String loanType) {
		this.loanType = loanType;
	}


	public String getSearchType() {
		return searchType;
	}


	public void setSearchType(String searchType) {
		this.searchType = searchType;
	}


	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 DataBaseMethods getDb() {
		return db;
	}


	public void setDb(DataBaseMethods db) {
		this.db = db;
	}


	public DataBaseMethodsRaviK getDbr() {
		return dbr;
	}


	public void setDbr(DataBaseMethodsRaviK dbr) {
		this.dbr = dbr;
	}



	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	public String getInterestHeaderDate() {
	    if(endDate != null) {
	        return new SimpleDateFormat("dd/MM/yyyy").format(startDate);
	    }
	    return "";
	}


	public SimpleDateFormat getSdf() {
		return sdf;
	}


	public void setSdf(SimpleDateFormat sdf) {
		this.sdf = sdf;
	}


	public String getSearchDate() {
		return searchDate;
	}


	public void setSearchDate(String searchDate) {
		this.searchDate = searchDate;
	}

	public void setSearchBase(int searchBase) {
		this.searchBase = searchBase;
	}


	public int getSearchBase() {
		return searchBase;
	}


	public ArrayList<CollectionInfo> getList() {
		return list;
	}


	public void setList(ArrayList<CollectionInfo> list) {
		this.list = list;
	}
    
}