package report_package;

import java.io.Serializable;
import java.sql.Connection;
import java.util.ArrayList;
import java.util.Date;

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.LoanInfo;

@ManagedBean(name="depositAccountStatement")
@ViewScoped

public class DepositAccountStatementBean implements Serializable
{
	String loanType, userId,dsaCode;
	boolean disDsa, showTable;
	Date searchDate=new Date();
	ArrayList<LoanInfo> list;
	DataBaseReportMethods dbmr=new DataBaseReportMethods();
	DataBaseMethods dbm=new DataBaseMethods();
	ArrayList<SelectItem> dsaList;
	int total;
	double totalAmountPaid, totalTillLeft, totalBalance;
	
	public DepositAccountStatementBean() 
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId = (int) ss.getAttribute("branchId");
		Connection conn=DataBaseConnection.JAVAConnection();
		userId=dbm.userId();
		dsaList=dbm.allDsaList(branchId,"",conn);
		if(dbm.userType().equals("employee"))
		{
			dsaCode=dbm.dsaCodeByEmpUserId(userId, conn);
			disDsa=true;
		}
		try {
			conn.close();
		} catch (Exception e) {
			// TODO: handle exception
		}
	}
	
	public void searchReport()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId = (int) ss.getAttribute("branchId");
		showTable=true;
		totalAmountPaid=totalTillLeft=totalBalance=0;
		list=dbmr.depositStatementReport(branchId,dsaCode ,loanType, searchDate);
		for(LoanInfo ll: list)
		{
			totalAmountPaid+=ll.getAmountPaid();
			totalTillLeft+=ll.getTillLeft();
			totalBalance+=ll.getBalance();
		}
		total=list.size();
	}

	public String getLoanType() {
		return loanType;
	}

	public void setLoanType(String loanType) {
		this.loanType = loanType;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getDsaCode() {
		return dsaCode;
	}

	public void setDsaCode(String dsaCode) {
		this.dsaCode = dsaCode;
	}

	public boolean isDisDsa() {
		return disDsa;
	}

	public void setDisDsa(boolean disDsa) {
		this.disDsa = disDsa;
	}

	public boolean isShowTable() {
		return showTable;
	}

	public void setShowTable(boolean showTable) {
		this.showTable = showTable;
	}

	public Date getSearchDate() {
		return searchDate;
	}

	public void setSearchDate(Date searchDate) {
		this.searchDate = searchDate;
	}

	public ArrayList<LoanInfo> getList() {
		return list;
	}

	public void setList(ArrayList<LoanInfo> list) {
		this.list = list;
	}

	public ArrayList<SelectItem> getDsaList() {
		return dsaList;
	}

	public void setDsaList(ArrayList<SelectItem> dsaList) {
		this.dsaList = dsaList;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public double getTotalAmountPaid() {
		return totalAmountPaid;
	}

	public void setTotalAmountPaid(double totalAmountPaid) {
		this.totalAmountPaid = totalAmountPaid;
	}

	public double getTotalTillLeft() {
		return totalTillLeft;
	}

	public void setTotalTillLeft(double totalTillLeft) {
		this.totalTillLeft = totalTillLeft;
	}

	public double getTotalBalance() {
		return totalBalance;
	}

	public void setTotalBalance(double totalBalance) {
		this.totalBalance = totalBalance;
	}
	
	
}
