package main_package;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;


@ManagedBean(name="ptpBean")
@ViewScoped

public class PtpBean  implements Serializable {
	
	
	 List<String> nameList;
	 String loanType,loanNo,remark,userId;
	 DbYashwant dby = new DbYashwant();
	 Date ptpDate;
	 int emiNo,branchId;
	 
	 public PtpBean()
	 {
		 ptpDate = new Date();
	 }
	 
	public List<String> completeLoanNo(String name)
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		int branchId = (int) ss.getAttribute("branchId");
		if(loanType!=null)
		{
			nameList=new DataBaseAutoCompAndDuplicate().showLoanNoByLoanType(branchId,name,loanType);
		}
		else
		{
			FacesContext.getCurrentInstance().addMessage(null,new FacesMessage("Please Select Loan Type First"));
		}
		return nameList;
	}
	
	
	public void selectEmi()
	{
		emiNo = dby.selectEmiNo(loanType, loanNo);
	}

	
	public void addPtp()
	{
		
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		 branchId =(int) ss.getAttribute("branchId");
		 userId=(String) ss.getAttribute("username");
		 
		int i = dby.AddPtp(ptpDate,loanNo,loanType,emiNo,remark,userId,branchId);
		if(i>0)
		{
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Ptp Query Added Sucessfully "));

		}
	}
	
	
	

	public List<String> getNameList() {
		return nameList;
	}


	public void setNameList(List<String> nameList) {
		this.nameList = nameList;
	}


	public String getLoanType() {
		return loanType;
	}


	public void setLoanType(String loanType) {
		this.loanType = loanType;
	}







	public String getLoanNo() {
		return loanNo;
	}







	public void setLoanNo(String loanNo) {
		this.loanNo = loanNo;
	}







	public String getRemark() {
		return remark;
	}







	public void setRemark(String remark) {
		this.remark = remark;
	}









	public String getUserId() {
		return userId;
	}







	public void setUserId(String userId) {
		this.userId = userId;
	}







	public Date getPtpDate() {
		return ptpDate;
	}







	public void setPtpDate(Date ptpDate) {
		this.ptpDate = ptpDate;
	}

	public int getEmiNo() {
		return emiNo;
	}

	public void setEmiNo(int emiNo) {
		this.emiNo = emiNo;
	}





	
	
	
	

}
