package report_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
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.CenterInfo;
import main_package.DataBaseConnection;
import main_package.DataBaseMethods;
import main_package.UserInfo;

@ManagedBean(name="printCombineCdsReport")
@ViewScoped
public class PrintCombineCdsReportBean implements Serializable
{
	Date searchDate=new Date();
	String frequency, center, centerName, strSearchDate, dayOfWeek;
	ArrayList<UserInfo> list;
	double totalLoan, totalRd, totalAmount;
	boolean show, showCenter;
	CenterInfo selectedCenter;
	
	public PrintCombineCdsReportBean()
	{
		Connection conn=DataBaseConnection.JAVAConnection();
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		list=(ArrayList<UserInfo>) ss.getAttribute("cdsList");
		center=(String) ss.getAttribute("cdsCenter");
		frequency=(String) ss.getAttribute("cdsFrequency");
		searchDate=(Date) ss.getAttribute("cdsSearchDate");
		
		if(list.size()>0)
		{
			strSearchDate=new SimpleDateFormat("dd/MMM/yyyy").format(searchDate);
			dayOfWeek=new SimpleDateFormat("EE").format(searchDate);
			show=true;
			totalLoan=totalRd=totalAmount=0;
			for(UserInfo uu: list)
			{
				totalAmount+=uu.getTotalLoanRdEmiAmtDue();
				totalLoan+=uu.getLoanEmiAmtDue();
				totalRd+=uu.getRdEmiAmtDue();
			}
			
			if(center.equalsIgnoreCase("all"))
			{
				showCenter=true;
				centerName=center;
			}
			else
			{
				showCenter=false;
				//centerName=new DataBaseMethods().centerNameById(center, conn);
				selectedCenter=new DataBaseMethods().selectedCenterInfo(center);
			}
		}
		else
		{
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("No Record Found!!!"));
		}
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	
	
	public Date getSearchDate() {
		return searchDate;
	}

	public void setSearchDate(Date searchDate) {
		this.searchDate = searchDate;
	}

	public String getFrequency() {
		return frequency;
	}

	public void setFrequency(String frequency) {
		this.frequency = frequency;
	}

	public ArrayList<UserInfo> getList() {
		return list;
	}

	public void setList(ArrayList<UserInfo> list) {
		this.list = list;
	}

	public double getTotalLoan() {
		return totalLoan;
	}

	public void setTotalLoan(double totalLoan) {
		this.totalLoan = totalLoan;
	}

	public double getTotalRd() {
		return totalRd;
	}

	public void setTotalRd(double totalRd) {
		this.totalRd = totalRd;
	}

	public double getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(double totalAmount) {
		this.totalAmount = totalAmount;
	}

	public boolean isShow() {
		return show;
	}

	public void setShow(boolean show) {
		this.show = show;
	}

	public String getCenter() {
		return center;
	}

	public void setCenter(String center) {
		this.center = center;
	}

	public String getCenterName() {
		return centerName;
	}

	public void setCenterName(String centerName) {
		this.centerName = centerName;
	}

	public boolean isShowCenter() {
		return showCenter;
	}

	public void setShowCenter(boolean showCenter) {
		this.showCenter = showCenter;
	}



	public String getStrSearchDate() {
		return strSearchDate;
	}



	public void setStrSearchDate(String strSearchDate) {
		this.strSearchDate = strSearchDate;
	}



	public CenterInfo getSelectedCenter() {
		return selectedCenter;
	}



	public void setSelectedCenter(CenterInfo selectedCenter) {
		this.selectedCenter = selectedCenter;
	}



	public String getDayOfWeek() {
		return dayOfWeek;
	}



	public void setDayOfWeek(String dayOfWeek) {
		this.dayOfWeek = dayOfWeek;
	}
	
}
