package hrm_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
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;

import main_package.DataBaseConnection;
import main_package.DataBaseMethods;
import main_package.EmpInfo;
import main_package.EmployeeInfo;

@ManagedBean(name="offerLetterInAdvance")
@ViewScoped
public class OfferLetterInAdvanceBean implements Serializable
{
	EmpInfo selectedRow=new EmpInfo();
	int noticeDays;
	
	public void printDetail()
	{
		if(noticeDays==0)
		{
			noticeDays=30;
		}
		
		if(selectedRow.getDoj()!=null)
		{
			selectedRow.setStrDoj(new SimpleDateFormat("dd/MM/yyyy").format(selectedRow.getDoj()));
		}
		
		if(selectedRow.getDesignationId()!=null)
		{
			Connection conn=DataBaseConnection.JAVAConnection();
			selectedRow.setDesignation(new DataBaseMethods().hrmBasicNameById(selectedRow.getDesignationId(),conn));
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("selectedRow", selectedRow);
		ss.setAttribute("startDateHrm", new Date());
		ss.setAttribute("endDateHrm", new Date());
		ss.setAttribute("noticeDaysHrm", noticeDays);
		ss.setAttribute("ratingHrm", 5);
		ss.setAttribute("incrementHrm", 10);
		
		RequestContext.getCurrentInstance().execute("window.open('offerLetter.xhtml')");
		RequestContext.getCurrentInstance().execute("window.open('offerLetter2.xhtml')");
	}
	
	
	public EmpInfo getSelectedRow() {
		return selectedRow;
	}
	public void setSelectedRow(EmpInfo selectedRow) {
		this.selectedRow = selectedRow;
	}
	public int getNoticeDays() {
		return noticeDays;
	}
	public void setNoticeDays(int noticeDays) {
		this.noticeDays = noticeDays;
	}
	
}
