package main_package;

import java.io.Serializable;
import java.text.DateFormatSymbols;
import java.text.ParseException;
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;

@ManagedBean(name = "salarySlip")
@ViewScoped

public class SalarySlipBean implements Serializable{
	
	String employeeCode, empName;
	public String funtion,employeeName,panNo,designation,pfNo,branch,uanNo,state,esicNo,bankName,bankAccNO,dateOfJoining,branchName,salaryMonth,salaryYear;
	public int fuelAmount,totalDays,workinDays,lopDays,basic,houseRentAllowance,specialAllowance,otherAllowance,arrear,incentive,totalEarning,pfAmount,esicAmount,totaldeduction,netSalary,arrearIncentive,othersDeduction;
	public String netSalaryInWord;
	public String city,department;
	
	DataBaseMethodTaheer dbmt = new DataBaseMethodTaheer();
	
	NumberToWord num =new NumberToWord();
	
	
	
	public SalarySlipBean() throws ParseException 
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
    	employeeCode = (String) ss.getAttribute("employeeCode");
		funtion= (String) ss.getAttribute("function" );
		city=(String) ss.getAttribute("city" );
		department= (String) ss.getAttribute("department" );
		employeeName = (String) ss.getAttribute("employeeName");
		empName = (String) ss.getAttribute("empName");
		panNo = (String) ss.getAttribute("panNo");
		designation = (String) ss.getAttribute("designation");
		pfNo = (String) ss.getAttribute("pfNo");
		branch = (String) ss.getAttribute("branch");
		uanNo = (String) ss.getAttribute("uanNo");
		state= (String) ss.getAttribute("state");
		esicNo = (String) ss.getAttribute("esicNo");
		bankName = (String) ss.getAttribute("bankName");
		bankAccNO = (String) ss.getAttribute("bankAccNo");
		dateOfJoining = (String) ss.getAttribute("dateOfJoining");

		// String dateOfJoining = (String) ss.getAttribute("dateOfJoining");
		String dateOfJoining = (String) ss.getAttribute("dateOfJoining");

		if (dateOfJoining != null && !dateOfJoining.trim().isEmpty()) 
		{
			dateOfJoining = dateOfJoining.trim();

			try 
		    {
				if (dateOfJoining.matches("\\d{8}")) 
				{
					System.out.println("Date already in required format: " + dateOfJoining);
		        }
				else if (dateOfJoining.matches("\\d{2}/\\d{2}/\\d{4}")) 
				{
					SimpleDateFormat inputFormat = new SimpleDateFormat("dd/MM/yyyy");
		            inputFormat.setLenient(false);

		            SimpleDateFormat outputFormat = new SimpleDateFormat("ddMMyyyy");

		            Date date = inputFormat.parse(dateOfJoining);
		            dateOfJoining = outputFormat.format(date);
		         }
		         else if (dateOfJoining.matches("\\d{4}-\\d{2}-\\d{2}")) 
		         {
		            SimpleDateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd");
		            inputFormat.setLenient(false);

		            SimpleDateFormat outputFormat = new SimpleDateFormat("ddMMyyyy");

		            Date date = inputFormat.parse(dateOfJoining);
		            dateOfJoining = outputFormat.format(date);
		         }

		         System.out.println("FINAL DATE OF JOINING = " + dateOfJoining);
		    } 
			catch (ParseException e) 
			{
				e.printStackTrace();
		    }
		}
		 
		totalDays = (int) ss.getAttribute("totalDays");
		workinDays = (int) ss.getAttribute("workingDays");
		lopDays = Integer.parseInt((String) ss.getAttribute("lopDays"));
		
		basic = (int) ss.getAttribute("basic");
		
		houseRentAllowance = (int) ss.getAttribute("houseRentAllowance");
		specialAllowance = (int) ss.getAttribute("specialAllowance");
		otherAllowance = (int) ss.getAttribute("otherAllowanace");
		totalEarning= (int) ss.getAttribute("grossSalary");
		pfAmount = (int) ss.getAttribute("totalPfDeduction");
		esicAmount= (int) ss.getAttribute("totalEsicDeduction");
		
		branchName = (String) ss.getAttribute("branchNameEmp");
		salaryMonth= (String) ss.getAttribute("salaryMonth");
		int month =Integer.parseInt(salaryMonth) ;
		salaryMonth = new DateFormatSymbols().getMonths()[month - 1];
		salaryYear= (String) ss.getAttribute("salaryYear");
		arrear = (int) ss.getAttribute("arrear");
		arrearIncentive = (int) ss.getAttribute("arrearIncentive");
		incentive = (int) ss.getAttribute("incentive");
		othersDeduction =(int) ss.getAttribute("otherDeduction");
		totaldeduction =pfAmount+esicAmount+othersDeduction;
		netSalary = totalEarning-totaldeduction;
		fuelAmount=(int) ss.getAttribute("extraAmountForFuel");
		netSalaryInWord= num.convertNumberToWords(netSalary);
	}


	 
	public String getFuntion() {
		return funtion;
	}





	public void setFuntion(String funtion) {
		this.funtion = funtion;
	}





	public String getEmployeeName() {
		return employeeName;
	}





	public void setEmployeeName(String employeeName) {
		this.employeeName = employeeName;
	}





	public String getPanNo() {
		return panNo;
	}





	public void setPanNo(String panNo) {
		this.panNo = panNo;
	}





	public String getDesignation() {
		return designation;
	}





	public void setDesignation(String designation) {
		this.designation = designation;
	}





	public String getPfNo() {
		return pfNo;
	}





	public void setPfNo(String pfNo) {
		this.pfNo = pfNo;
	}





	public String getBranch() {
		return branch;
	}





	public void setBranch(String branch) {
		this.branch = branch;
	}





	public String getUanNo() {
		return uanNo;
	}





	public void setUanNo(String uanNo) {
		this.uanNo = uanNo;
	}





	public String getState() {
		return state;
	}





	public void setState(String state) {
		this.state = state;
	}





	public String getEsicNo() {
		return esicNo;
	}





	public void setEsicNo(String esicNo) {
		this.esicNo = esicNo;
	}





	public String getBankName() {
		return bankName;
	}





	public void setBankName(String bankName) {
		this.bankName = bankName;
	}





	public String getBankAccNO() {
		return bankAccNO;
	}





	public void setBankAccNO(String bankAccNO) {
		this.bankAccNO = bankAccNO;
	}





	public String getDateOfJoining() {
		return dateOfJoining;
	}





	public void setDateOfJoining(String dateOfJoining) {
		this.dateOfJoining = dateOfJoining;
	}





	



	public int getBasic() {
		return basic;
	}





	public void setBasic(int basic) {
		this.basic = basic;
	}





	public int getHouseRentAllowance() {
		return houseRentAllowance;
	}





	public void setHouseRentAllowance(int houseRentAllowance) {
		this.houseRentAllowance = houseRentAllowance;
	}





	public int getSpecialAllowance() {
		return specialAllowance;
	}





	public void setSpecialAllowance(int specialAllowance) {
		this.specialAllowance = specialAllowance;
	}





	public int getOtherAllowance() {
		return otherAllowance;
	}





	public void setOtherAllowance(int otherAllowance) {
		this.otherAllowance = otherAllowance;
	}





	public int getArrear() {
		return arrear;
	}





	public void setArrear(int arrear) {
		this.arrear = arrear;
	}





	public int getIncentive() {
		return incentive;
	}





	public void setIncentive(int incentive) {
		this.incentive = incentive;
	}





	public int getTotalEarning() {
		return totalEarning;
	}





	public void setTotalEarning(int totalEarning) {
		this.totalEarning = totalEarning;
	}





	public int getPfAmount() {
		return pfAmount;
	}





	public void setPfAmount(int pfAmount) {
		this.pfAmount = pfAmount;
	}





	public int getEsicAmount() {
		return esicAmount;
	}





	public void setEsicAmount(int esicAmount) {
		this.esicAmount = esicAmount;
	}





	public int getTotaldeduction() {
		return totaldeduction;
	}





	public void setTotaldeduction(int totaldeduction) {
		this.totaldeduction = totaldeduction;
	}





	public int getNetSalary() {
		return netSalary;
	}





	public void setNetSalary(int netSalary) {
		this.netSalary = netSalary;
	}





	public int getTotalDays() {
		return totalDays;
	}





	public void setTotalDays(int totalDays) {
		this.totalDays = totalDays;
	}





	public int getWorkinDays() {
		return workinDays;
	}





	public void setWorkinDays(int workinDays) {
		this.workinDays = workinDays;
	}





	public int getLopDays() {
		return lopDays;
	}





	public void setLopDays(int lopDays) {
		this.lopDays = lopDays;
	}





	public String getBranchName() {
		return branchName;
	}





	public void setBranchName(String branchName) {
		this.branchName = branchName;
	}





	public String getNetSalaryInWord() {
		return netSalaryInWord;
	}





	public void setNetSalaryInWord(String netSalaryInWord) {
		this.netSalaryInWord = netSalaryInWord;
	}





	public String getSalaryMonth() {
		return salaryMonth;
	}





	public void setSalaryMonth(String salaryMonth) {
		this.salaryMonth = salaryMonth;
	}





	public String getSalaryYear() {
		return salaryYear;
	}





	public void setSalaryYear(String salaryYear) {
		this.salaryYear = salaryYear;
	}





	public NumberToWord getNum() {
		return num;
	}





	public void setNum(NumberToWord num) {
		this.num = num;
	}








	public String getEmployeeCode() {
		return employeeCode;
	}








	public void setEmployeeCode(String employeeCode) {
		this.employeeCode = employeeCode;
	}








	public int getArrearIncentive() {
		return arrearIncentive;
	}








	public void setArrearIncentive(int arrearIncentive) {
		this.arrearIncentive = arrearIncentive;
	}








	public int getOthersDeduction() {
		return othersDeduction;
	}








	public void setOthersDeduction(int othersDeduction) {
		this.othersDeduction = othersDeduction;
	}








	public int getFuelAmount() {
		return fuelAmount;
	}








	public void setFuelAmount(int fuelAmount) {
		this.fuelAmount = fuelAmount;
	}








	public String getCity() {
		return city;
	}








	public void setCity(String city) {
		this.city = city;
	}








	public String getDepartment() {
		return department;
	}








	public void setDepartment(String department) {
		this.department = department;
	}








	public String getEmpName() {
		return empName;
	}








	public void setEmpName(String empName) {
		this.empName = empName;
	}
	
}
