package main_package;

import java.io.Serializable;


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.servlet.http.HttpSession;

import org.primefaces.context.RequestContext;



@ManagedBean(name ="profitLoss2")
@ViewScoped
public class ProfitAndLoss2Bean implements Serializable {
   
	private static final long serialVersionUID = 1L;
	
	DataBaseMethodRahul dbr = new DataBaseMethodRahul();
	
	ArrayList<ProfitAndLoss2Info> pffI,pfEp ;
	Date proDate;
	double totalExpence,totalIncome,totalProfit;
	
	
	public void ProfitAndLoss2() {
		
	 pfEp = dbr.profitAndLossListSunlog();
	 pffI = dbr.profitAndLossListSunlogIncome();
	 
	 dbr.selectExpense(pfEp, null, serialVersionUID, proDate);
	 dbr.selectIncome(pffI, proDate);
	 
	 for(ProfitAndLoss2Info li:pfEp)
	 {
		 totalExpence+=li.getIndirectExpenseAmount();
	 }
	 for(ProfitAndLoss2Info ii:pffI)
	 {
		 totalIncome+=ii.getIndirectIncomeAmount();
	 }
	 
	 totalProfit=totalIncome-totalExpence;
		
		
	}
	public void print()
	{

		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
		ss.setAttribute("pffI", pffI);
		ss.setAttribute("pfEp", pfEp);
		
		ss.setAttribute("totalExpence", totalExpence);
		ss.setAttribute("totalIncome", totalIncome);
		RequestContext.getCurrentInstance().execute("window.open('profitAndLoss2Print.xhtml')");
	}

	public ArrayList<ProfitAndLoss2Info> getPffI() {
		return pffI;
	}

	public void setPffI(ArrayList<ProfitAndLoss2Info> pffI) {
		this.pffI = pffI;
	}

	public ArrayList<ProfitAndLoss2Info> getPfEp() {
		return pfEp;
	}

	public void setPfEp(ArrayList<ProfitAndLoss2Info> pfEp) {
		this.pfEp = pfEp;
	}
	public Date getProDate() {
		return proDate;
	}
	public void setProDate(Date proDate) {
		this.proDate = proDate;
	}
	public double getTotalExpence() {
		return totalExpence;
	}
	public void setTotalExpence(double totalExpence) {
		this.totalExpence = totalExpence;
	}
	public double getTotalIncome() {
		return totalIncome;
	}
	public void setTotalIncome(double totalIncome) {
		this.totalIncome = totalIncome;
	}
	public double getTotalProfit() {
		return totalProfit;
	}
	public void setTotalProfit(double totalProfit) {
		this.totalProfit = totalProfit;
	}

}
