package main_package;

import java.io.Serializable;
import java.sql.Connection;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

@ManagedBean(name="printMemberRegForm")
@ViewScoped

public class PrintMemberRegFormBean implements Serializable
{   
	UserInfo selectedMember;
	private String centerId;
	private String centerName;
	private String centerCode;
	private String centerIdByCenterCode;
	String branchId;
	String centerIdWithBranchCodes;
	String branchCode;
	String companyName;
	boolean renCenterNameId=false;
	String religionName;
	boolean hideForDev;

	public PrintMemberRegFormBean() 
	{				
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		selectedMember=(UserInfo) ss.getAttribute("selecteduserForPrintRegForm");
		ss.getAttribute("branchId");
//	    String religion=	selectedMember.getReligion();
//	    religionName = DataBaseMethodsHemant.getReligionNameByReligionCode(religion);
//	    System.out.println("religion name afeter code fileters"+religionName);
		//System.out.println("member regision is:"+religion);
		
	    companyName=(String) ss.getAttribute("companyName");
	 	centerId=selectedMember.getCenterId();
	 	Connection conn= DataBaseConnection.JAVAConnection();
	 	DataBaseMethods db= new DataBaseMethods();
	 	DataBaseMethodsHemant dh = new DataBaseMethodsHemant();
	    String centerName =    db.centerNameCodeById(centerId,conn);
	    System.out.println("center name is by emter id"+centerName);
	    selectedMember.setCenterName(centerName);
	    centerCode=selectedMember.getCenterCode();
	    selectedMember.setReligionLabel(db.highMarkLabelByValue("Religion", selectedMember.getReligion(),conn));
	    
	    if(companyName!=null && companyName.equalsIgnoreCase("SUDERSHANA FINANCE"))
	    {
	    	System.out.println("condition hit");
		    List<String> centerIdWithBranchCode = dh.generateCenterFullCode(ss, conn, centerCode);
		    System.out.println("centerId with rbanch code is:"+centerIdWithBranchCode);
		    
		    if (centerIdWithBranchCode != null && !centerIdWithBranchCode.isEmpty()) 
		    {
		        // List has data
		        branchCode = centerIdWithBranchCode.get(0);
		        System.out.println("result branch code is:" + branchCode);

		        centerIdWithBranchCodes = centerIdWithBranchCode.get(1);
		        System.out.println("new centerId with branch code is: " + centerIdWithBranchCodes);

		        selectedMember.setCenterIdWithBranchCode(centerIdWithBranchCodes);
		        selectedMember.setBranchCode(branchCode);

		        System.out.println(" new centerId is:" + centerIdWithBranchCode);
		    }
		    else 
		    {
		        branchCode = null;
		        centerIdWithBranchCode = null;
		        renCenterNameId = false;
		    }		    
	    }
	    
	    else 
	    {
	    	System.out.println();
		    System.out.println("branchId");
	    }
	    
	    if("DEVKRIPA MICROFINANCE FOUNDATION".equalsIgnoreCase(companyName))
	    {
	    	hideForDev=true;
	    }
	    
	    else
	    {
	    	hideForDev=false;
	    }
	}
	
	public UserInfo getSelectedMember() {
		return selectedMember;
	}

	public void setSelectedMember(UserInfo selectedMember) {
		this.selectedMember = selectedMember;
	}

	public String getCenterId() {
		return centerId;
	}

	public void setCenterId(String centerId) {
		this.centerId = centerId;
	}



	public String getCenterName() {
		return centerName;
	}



	public void setCenterName(String centerName) {
		this.centerName = centerName;
	}

	public String getCenterCode() {
		return centerCode;
	}

	public void setCenterCode(String centerCode) {
		this.centerCode = centerCode;
	}

	public String getCenterIdByCenterCode() {
		return centerIdByCenterCode;
	}

	public void setCenterIdByCenterCode(String centerIdByCenterCode) {
		this.centerIdByCenterCode = centerIdByCenterCode;
	}

	public String getBranchId() {
		return branchId;
	}

	public void setBranchId(String branchId) {
		this.branchId = branchId;
	}

	public String getCenterIdWithBranchCodes() {
		return centerIdWithBranchCodes;
	}

	public void setCenterIdWithBranchCodes(String centerIdWithBranchCodes) {
		this.centerIdWithBranchCodes = centerIdWithBranchCodes;
	}

	public String getBranchCode() {
		return branchCode;
	}

	public void setBranchCode(String branchCode) {
		this.branchCode = branchCode;
	}

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public boolean isRenCenterNameId() {
		return renCenterNameId;
	}

	public void setRenCenterNameId(boolean renCenterNameId) {
		this.renCenterNameId = renCenterNameId;
	}

	public String getReligionName() {
		return religionName;
	}

	public void setReligionName(String religionName) {
		this.religionName = religionName;
	}

	public boolean isHideForDev() {
		return hideForDev;
	}

	public void setHideForDev(boolean hideForDev) {
		this.hideForDev = hideForDev;
	}

	
	
	
}
