package basic_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
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 main_package.DataBaseConnection;
import main_package.DataBaseMethods;
import main_package.LoanInfo;
import report_package.DataBaseReportMethods;

@ViewScoped
@ManagedBean(name="printBulkLoanReceipt")
public class PrintBulkLoanReceiptBean implements Serializable
{
	ArrayList<LoanInfo> payLoanEmiList;
	Date payDate;
	int totalAmount;
	String loanTypeLabel, selectedCenter, centerName, payDateStr, amountInwords;
	
	public PrintBulkLoanReceiptBean() 
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		
		payLoanEmiList=(ArrayList<LoanInfo>) ss.getAttribute("printPayLoanEmiList");
		payDate=(Date) ss.getAttribute("printDate");
		loanTypeLabel=(String) ss.getAttribute("printLoanType");
		selectedCenter=(String) ss.getAttribute("printCenter");
		
		Connection conn=DataBaseConnection.JAVAConnection();
		
		payDateStr=new SimpleDateFormat("dd/MMM/yyyy").format(payDate);
		centerName=new DataBaseMethods().centerNameCodeById(selectedCenter, conn);
		
		totalAmount=0;
		for(LoanInfo ll: payLoanEmiList)
		{
			totalAmount+=ll.getPaidAmount();
		}
		
		amountInwords=new DataBaseReportMethods().numberToWords(totalAmount).toUpperCase();
		
		try {
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public ArrayList<LoanInfo> getPayLoanEmiList() {
		return payLoanEmiList;
	}

	public void setPayLoanEmiList(ArrayList<LoanInfo> payLoanEmiList) {
		this.payLoanEmiList = payLoanEmiList;
	}

	public String getLoanTypeLabel() {
		return loanTypeLabel;
	}

	public void setLoanTypeLabel(String loanTypeLabel) {
		this.loanTypeLabel = loanTypeLabel;
	}

	public String getCenterName() {
		return centerName;
	}

	public void setCenterName(String centerName) {
		this.centerName = centerName;
	}

	public String getPayDateStr() {
		return payDateStr;
	}

	public void setPayDateStr(String payDateStr) {
		this.payDateStr = payDateStr;
	}

	public int getTotalAmount() {
		return totalAmount;
	}

	public void setTotalAmount(int totalAmount) {
		this.totalAmount = totalAmount;
	}

	public String getAmountInwords() {
		return amountInwords;
	}

	public void setAmountInwords(String amountInwords) {
		this.amountInwords = amountInwords;
	}
}
