package report_package;

import java.io.Serializable;
import java.util.ArrayList;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import main_package.UserInfo;

@ManagedBean(name="printIncomeExpenseReport")
@ViewScoped

public class PrintIncomeExpenseReportBean implements Serializable
{
	private static final long serialVersionUID = 1L;
	ArrayList<UserInfo> finalList;
	String reportType,loanType,identity;
	boolean show1,show2,show3,showAmount,showOtherAmount;
	double tot,pen,totalIncome=0,totalExpense=0,totalAsset=0;
	int sz;
	
	@SuppressWarnings("unchecked")
	public PrintIncomeExpenseReportBean()
	{
		int i=1;
		sz=0;tot=0;pen=0;
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		finalList=(ArrayList<UserInfo>) ss.getAttribute("finalList");
		reportType=(String) ss.getAttribute("reportType");
		loanType=(String) ss.getAttribute("loanType");
		identity=(String) ss.getAttribute("identity");
		sz=finalList.size();
		showOtherAmount=false;showAmount=true;
		for(UserInfo ll:finalList)
		{
			ll.setSno(i++);
			tot=tot+(ll.getAmount());
			pen=pen+(ll.getPenalty());
			if(reportType.equals("Income_Expense"))
			{
				showOtherAmount=true;showAmount=false;
				if(ll.getReportType().equals("Income"))
				{
					totalIncome+=ll.getAmount();
				}
				else if(ll.getReportType().equals("Expense"))
				{
					//ll.setTotalAmount(ll.getAmount());
					//ll.setAmount(0);
					totalExpense+=ll.getTotalAmount();
				}
				else if(ll.getReportType().equals("Current Asset"))
				{
					//ll.setTotalAmount(ll.getAmount());
					//ll.setAmount(0);
					totalAsset+=ll.getTotalAmount();
				}
			}
		}
		
		if(/*identity.equals("All") ||*/ identity.equals("loan"))
		{
			show1=show2=show3=true;
			if(loanType.equals("personalloan"))
			{
				identity="Personal Loan";
			}
			else if(loanType.equals("propertyloan"))
			{
				identity="Property Loan";
			}
			else if(loanType.equals("vechicleloan"))
			{
				identity="Vehicle Loan";
			}
			else if(loanType.equals("grouploan"))
			{
				identity="Group Loan";
			}
		}
		if(identity.equals("All"))
		{
			show1=show2=show3=true;
		}
		else if(identity.equals("RD/FD"))
		{
			show2=show3=true;
			show1=false;
		}
		else if(identity.equals("Saving's Account"))
		{
			show1=show2=show3=false;
		}
	}
	
	public double getTot() {
		return tot;
	}
	public void setTot(double tot) {
		this.tot = tot;
	}
	public double getPen() {
		return pen;
	}
	public void setPen(double pen) {
		this.pen = pen;
	}
	public int getSz() {
		return sz;
	}
	public void setSz(int sz) {
		this.sz = sz;
	}
	public String getIdentity() {
		return identity;
	}
	public void setIdentity(String identity) {
		this.identity = identity;
	}
	public boolean isShow1() {
		return show1;
	}
	public void setShow1(boolean show1) {
		this.show1 = show1;
	}
	public boolean isShow2() {
		return show2;
	}
	public void setShow2(boolean show2) {
		this.show2 = show2;
	}
	public boolean isShow3() {
		return show3;
	}
	public void setShow3(boolean show3) {
		this.show3 = show3;
	}
	public ArrayList<UserInfo> getFinalList() {
		return finalList;
	}
	public void setFinalList(ArrayList<UserInfo> finalList) {
		this.finalList = finalList;
	}
	public String getReportType() {
		return reportType;
	}
	public void setReportType(String reportType) {
		this.reportType = reportType;
	}
	public String getLoanType() {
		return loanType;
	}
	public void setLoanType(String loanType) {
		this.loanType = loanType;
	}
	public boolean isShowAmount() {
		return showAmount;
	}
	public void setShowAmount(boolean showAmount) {
		this.showAmount = showAmount;
	}
	public boolean isShowOtherAmount() {
		return showOtherAmount;
	}
	public void setShowOtherAmount(boolean showOtherAmount) {
		this.showOtherAmount = showOtherAmount;
	}
	public double getTotalIncome() {
		return totalIncome;
	}
	public void setTotalIncome(double totalIncome) {
		this.totalIncome = totalIncome;
	}
	public double getTotalExpense() {
		return totalExpense;
	}
	public void setTotalExpense(double totalExpense) {
		this.totalExpense = totalExpense;
	}

	public double getTotalAsset() {
		return totalAsset;
	}

	public void setTotalAsset(double totalAsset) {
		this.totalAsset = totalAsset;
	}
	
}
