package main_package;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;

import org.primefaces.context.RequestContext;

@ManagedBean(name="tdsDeduction")
@ViewScoped
public class TdsDeductionBean implements Serializable
{
	ArrayList<UserInfo> rdFdList,particularList, tdsList;
	ArrayList<InstallmentInfo> paidInstallmentList,interestList;
	ArrayList<InstallmentInfo>finalList,lastList, tdsIntrestList;
	String type,panCard;
	int selectYear;
	double tdsValue, tdsPercent, total;
	Date tdyDate,standard,date1,date2,date3,date4,date5,date6,date7,date8,startDate=new Date(),endDate=new Date();
	Timestamp tdydt,stndrd,dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
	boolean renderRDFDButton,renderSVButton,renderLoanButton, showTable;
	ArrayList<SelectItem> yearList, typeList=new ArrayList<>();
	DataBaseMethods db=new DataBaseMethods();
	int branchId;
	
	public TdsDeductionBean() 
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchId = (int) ss.getAttribute("branchId");
		Connection conn=DataBaseConnection.JAVAConnection();
		startDate.setDate(1);
		startDate.setMonth(3);
		
		endDate.setDate(31);
		endDate.setMonth(2);
		
		
		SelectItem ss1=new SelectItem();
		
		ss1.setLabel("Saving Account");
		ss1.setValue("SV");
		
		typeList.add(ss1);
		
		String tdsType=db.checkTdsBasis(branchId,conn);
		if(tdsType.equals("yearly"))
		{
			SelectItem ss4=new SelectItem();
			ss4.setLabel("DD");
			ss4.setValue("DD");
			typeList.add(ss4);
			
			SelectItem ss2=new SelectItem();
			ss2.setLabel("RD");
			ss2.setValue("RD");
			typeList.add(ss2);
			
			SelectItem ss3=new SelectItem();
			
			ss3.setLabel("FD");
			ss3.setValue("FD");
			
			typeList.add(ss3);
		}
		
		
		yearList=new ArrayList<SelectItem>();
		for(int i=2015;i<=2020;i++)
		{
			SelectItem item=new SelectItem();
			item.setLabel(String.valueOf(i));
			item.setValue(i);
			
			yearList.add(item);
		}
		
		//rdFdList=db.showUser();
	}
	
	
	
	public void view()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchId = (int) ss.getAttribute("branchId");
		boolean check=new DataBaseAutoCompAndDuplicate().checkTdsDeduction(branchId,selectYear);
		if(check==false)
		{
			startDate.setYear(selectYear-1901);
			endDate.setYear(selectYear-1900);
			System.out.println(startDate+"==="+endDate);
			total=0;
			tdsList=new ArrayList<>();
			rdFdList=db.showFDUser(branchId);
			int count=1;
			for(UserInfo uu: rdFdList)
			{
				double intrest=0, days=0;
				if(uu.getOffice_date().before(startDate))
				{
					if(uu.getMaturity_date().before(endDate))
					{
						days = (int) ((uu.getMaturity_date().getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
					}
					else
					{
						days = (int) ((endDate.getTime() - startDate.getTime()) / (1000 * 60 * 60 * 24));
					}
				}
				else
				{
					if(uu.getMaturity_date().before(endDate))
					{
						days = (int) ((uu.getMaturity_date().getTime() - uu.getOffice_date().getTime()) / (1000 * 60 * 60 * 24));
					}
					else
					{
						days = (int) ((endDate.getTime() - uu.getOffice_date().getTime()) / (1000 * 60 * 60 * 24));
					}
				}
				days=days+1;
				intrest=(uu.getInstallment_amount()*uu.getInterest()*days)/36500;
				System.out.println(" Fd No. : "+uu.getUser_no()+" Days: "+days+" Intrest: "+intrest);
				
				
				if(intrest>=10000)
				{
					total+=intrest;
					UserInfo uu1=new UserInfo();
					
					uu1.setSno(count++);
					uu1.setUser_no(uu.getUser_no());
					uu1.setInterest(Double.parseDouble(new DecimalFormat("##.##").format(intrest)));
					uu1.setMaturity_date(uu.getMaturity_date());
					
					if(uu.getMaturity_date().after(endDate))
					{
						uu1.setPayoutDate(endDate);
					}
					else
					{
						uu1.setPayoutDate(uu.getMaturity_date());
					}
					
					uu1.setStrPayOutDate(new SimpleDateFormat("dd/MM/yyyy").format(uu1.getPayoutDate()));
					
					tdsList.add(uu1);
				}
			}
			
			total=Double.parseDouble(new DecimalFormat("##.##").format(total));
			if(tdsList.size()>0)
			{
				showTable=true;
			}
			else
			{
				showTable=false;
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("No Record Found!!!"));
			}
		}
		else
		{
			showTable=false;
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("TDS Already Deduct for Selected Year !!! Please Check TDS Report."));
		}
	}
	
	
	
	public String tdsDeduct()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchId = (int) ss.getAttribute("branchId");
		for(UserInfo ff: tdsList)
		{
			String shno="";
			if(type.equals("RD") || type.equals("FD"))
			{
				shno=db.shareHolderNoByRdFdNo(ff.getUser_no());
			}
			else if(type.equals("SV"))
			{
				shno=db.shareHolderNoBySavingAccountNO(ff.getUser_no());
			}
			
			panCard=db.findShareholderPanCardNo(shno);
			if(panCard.equals(""))
			{
				tdsPercent=db.tdsPercentFormTable("no");
			}
			else
			{
				tdsPercent=db.tdsPercentFormTable("yes");
			}
			tdsValue=(ff.getInterest()*tdsPercent)/100;
			tdsValue=Double.parseDouble(new DecimalFormat("##.##").format(tdsValue));
			if(tdsValue>0)
			{
				if(ff.getMaturity_date().before(endDate))
				{
					db.insertTdsDeductionDetail(ff.getUser_no(), ff.getMaturity_date(), tdsValue,type, selectYear, tdsPercent,branchId);
				}
				else
				{
					db.insertTdsDeductionDetail(ff.getUser_no(), endDate, tdsValue,type, selectYear, tdsPercent,branchId);
				}
			
			}
		}
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("TDS Deduction Sucessfully."));
		
		return "userBlockDashboard.xhtml";
	}
	
	public void checkLiabilityType()
	{
		if(type.equals("SV"))
		{
			renderLoanButton=false;
			renderRDFDButton=false;
			renderSVButton=true;
		}
		else if(type.equals("loan"))
		{
			renderLoanButton=true;
			renderRDFDButton=false;
			renderSVButton=false;
		}
		else
		{
			renderLoanButton=false;
			renderRDFDButton=true;
			renderSVButton=false;
		}
	}
	
	public void viewSavingsReport()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		branchId = (int) ss.getAttribute("branchId");
		startDate.setYear(selectYear-1901);
		endDate.setYear(selectYear-1900);
		
		total=0;
		finalList=new ArrayList<>();
		lastList=new ArrayList<>();
		
		if(startDate==null || endDate==null)
		{
			lastList=db.interestListOfCustomerDeposit(branchId);
		}
		else if(startDate.after(endDate))
		{
			lastList=new ArrayList<>();
			finalList=new ArrayList<>();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Please enter dates properly!"));
		}
		else
		{
			Timestamp start=new Timestamp(startDate.getTime());
			Timestamp end=new Timestamp(endDate.getTime());
			lastList=db.interestListOfCustomerDeposit(branchId,start,end);
		}
		
		int k=0;
		for(InstallmentInfo tt : lastList)
		{
			tt.setSno(++k);
			total+=tt.getInterest();
		}
		total=Double.parseDouble(new DecimalFormat("##.##").format(total));
		
	//	createTdsIntrestList();
		
	}
	
	public void print()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("list",lastList);
		ss.setAttribute("total",total);
		ss.setAttribute("type",type);
		RequestContext.getCurrentInstance().execute("window.open('printLiabilitiesReport.xhtml')");
		
	}


	public ArrayList<InstallmentInfo> getFinalList() {
		return finalList;
	}

	public void setFinalList(ArrayList<InstallmentInfo> finalList) {
		this.finalList = finalList;
	}
	
	public ArrayList<InstallmentInfo> getInterestList() {
		return interestList;
	}

	public void setInterestList(ArrayList<InstallmentInfo> interestList) {
		this.interestList = interestList;
	}

	public ArrayList<InstallmentInfo> getPaidInstallmentList() {
		return paidInstallmentList;
	}

	public void setPaidInstallmentList(ArrayList<InstallmentInfo> paidInstallmentList) {
		this.paidInstallmentList = paidInstallmentList;
	}

	public ArrayList<UserInfo> getParticularList() {
		return particularList;
	}

	public void setParticularList(ArrayList<UserInfo> particularList) {
		this.particularList = particularList;
	}

	public ArrayList<UserInfo> getRdFdList() {
		return rdFdList;
	}

	public void setRdFdList(ArrayList<UserInfo> rdFdList) {
		this.rdFdList = rdFdList;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public boolean isRenderRDFDButton() {
		return renderRDFDButton;
	}

	public void setRenderRDFDButton(boolean renderRDFDButton) {
		this.renderRDFDButton = renderRDFDButton;
	}

	public boolean isRenderSVButton() {
		return renderSVButton;
	}

	public void setRenderSVButton(boolean renderSVButton) {
		this.renderSVButton = renderSVButton;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public boolean isRenderLoanButton() {
		return renderLoanButton;
	}

	public void setRenderLoanButton(boolean renderLoanButton) {
		this.renderLoanButton = renderLoanButton;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public ArrayList<InstallmentInfo> getLastList() {
		return lastList;
	}

	public void setLastList(ArrayList<InstallmentInfo> lastList) {
		this.lastList = lastList;
	}

	

	public ArrayList<SelectItem> getYearList() {
		return yearList;
	}

	public void setYearList(ArrayList<SelectItem> yearList) {
		this.yearList = yearList;
	}

	public int getSelectYear() {
		return selectYear;
	}

	public void setSelectYear(int selectYear) {
		this.selectYear = selectYear;
	}

	public ArrayList<SelectItem> getTypeList() {
		return typeList;
	}

	public void setTypeList(ArrayList<SelectItem> typeList) {
		this.typeList = typeList;
	}

	public ArrayList<InstallmentInfo> getTdsIntrestList() {
		return tdsIntrestList;
	}

	public void setTdsIntrestList(ArrayList<InstallmentInfo> tdsIntrestList) {
		this.tdsIntrestList = tdsIntrestList;
	}

	public boolean isShowTable() {
		return showTable;
	}

	public void setShowTable(boolean showTable) {
		this.showTable = showTable;
	}



	public ArrayList<UserInfo> getTdsList() {
		return tdsList;
	}



	public void setTdsList(ArrayList<UserInfo> tdsList) {
		this.tdsList = tdsList;
	}
	
	
}




















/////////  TDS Deduction Old Method


/*package finance;

import java.io.Serializable;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpSession;

import org.primefaces.context.RequestContext;

@ManagedBean(name="tdsDeduction")
@ViewScoped
public class TdsDeductionBean implements Serializable
{
	ArrayList<UserInfo> rdFdList,particularList;
	ArrayList<InstallmentInfo> paidInstallmentList,interestList;
	ArrayList<InstallmentInfo>finalList,lastList, tdsIntrestList;
	String type,panCard;
	int selectYear;
	double tdsValue, tdsPercent;
	Date tdyDate,standard,date1,date2,date3,date4,date5,date6,date7,date8,startDate=new Date(),endDate=new Date();
	Timestamp tdydt,stndrd,dt1,dt2,dt3,dt4,dt5,dt6,dt7,dt8;
	boolean renderRDFDButton,renderSVButton,renderLoanButton, showTable;
	ArrayList<SelectItem> yearList, typeList=new ArrayList<>();
 	
	public TdsDeductionBean() 
	{
		
		startDate.setDate(1);
		startDate.setMonth(4);
		
		endDate.setDate(31);
		endDate.setMonth(2);
		
		
		SelectItem ss1=new SelectItem();
		
		ss1.setLabel("Saving Account");
		ss1.setValue("SV");
		
		typeList.add(ss1);
		
		String tdsType=db.checkTdsBasis();
		if(tdsType.equals("yearly"))
		{
			SelectItem ss2=new SelectItem();
			
			ss2.setLabel("RD");
			ss2.setValue("RD");
			
			typeList.add(ss2);
			
			SelectItem ss3=new SelectItem();
			
			ss3.setLabel("FD");
			ss3.setValue("FD");
			
			typeList.add(ss3);
		}
		
		
		yearList=new ArrayList<SelectItem>();
		for(int i=2015;i<=2020;i++)
		{
			SelectItem item=new SelectItem();
			item.setLabel(String.valueOf(i));
			item.setValue(i);
			
			yearList.add(item);
		}
		
		
		startDate.setMonth(startDate.getMonth()-1);
		
		
		
		date1=new Date();date2=new Date();
		date3=new Date();date4=new Date();
		date5=new Date();date6=new Date();
		date7=new Date();date8=new Date();
		
		dt1=new Timestamp(date1.getTime());dt2=new Timestamp(date2.getTime());
		dt3=new Timestamp(date3.getTime());dt4=new Timestamp(date4.getTime());
		dt5=new Timestamp(date5.getTime());dt6=new Timestamp(date6.getTime());
		dt7=new Timestamp(date7.getTime());dt8=new Timestamp(date8.getTime());
		

		standard=new Date();
		tdyDate=new Date();
		tdydt=new Timestamp(tdyDate.getTime());
		tdydt.setHours(0);tdydt.setMinutes(0);tdydt.setSeconds(0);tdydt.setNanos(0);
		
		System.out.println("tdy : "+tdydt);
		
		stndrd=new Timestamp(standard.getTime());
		stndrd.setDate(30);
		stndrd.setMonth(5);
		stndrd.setYear(tdydt.getYear());
		stndrd.setHours(0);stndrd.setMinutes(0);stndrd.setSeconds(0);stndrd.setNanos(0);
		
		dt1.setDate(1);
		dt1.setMonth(3);
		dt1.setHours(0);dt1.setMinutes(0);dt1.setSeconds(0);dt1.setNanos(0);
		
		dt2.setDate(30);
		dt2.setMonth(5);
		dt2.setHours(0);dt2.setMinutes(0);dt2.setSeconds(0);dt2.setNanos(0);

		dt3.setDate(1);
		dt3.setMonth(6);
		dt3.setHours(0);dt3.setMinutes(0);dt3.setSeconds(0);dt3.setNanos(0);

		dt4.setDate(30);
		dt4.setMonth(8);
		dt4.setHours(0);dt4.setMinutes(0);dt4.setSeconds(0);dt4.setNanos(0);

		dt5.setDate(1);
		dt5.setMonth(9);
		dt5.setHours(0);dt5.setMinutes(0);dt5.setSeconds(0);dt5.setNanos(0);

		dt6.setDate(31);
		dt6.setMonth(11);
		dt6.setHours(0);dt6.setMinutes(0);dt6.setSeconds(0);dt6.setNanos(0);

		dt7.setDate(1);
		dt7.setMonth(0);
		dt7.setHours(0);dt7.setMinutes(0);dt7.setSeconds(0);dt7.setNanos(0);

		dt8.setDate(31);
		dt8.setMonth(2);
		dt8.setHours(0);dt8.setMinutes(0);dt8.setSeconds(0);dt8.setNanos(0);

		
		rdFdList=db.showUser();
	}
	
	public String tdsDeduct()
	{
		for(InstallmentInfo ff: tdsIntrestList)
		{
			String shno="";
			if(type.equals("RD") || type.equals("FD"))
			{
				shno=db.shareHolderNoByRdFdNo(ff.getUser_no());
			}
			else if(type.equals("SV"))
			{
				shno=db.shareHolderNoBySavingAccountNO(ff.getUser_no());
			}
			
			panCard=db.findShareholderPanCardNo(shno);
			if(panCard.equals(""))
			{
				tdsPercent=db.tdsPercentFormTable("no");
			}
			else
			{
				tdsPercent=db.tdsPercentFormTable("yes");
			}
			tdsValue=(ff.getInterest()*tdsPercent)/100;
			tdsValue=Double.parseDouble(new DecimalFormat("##.##").format(tdsValue));
			if(tdsValue>0)
			{
				System.out.println(endDate);
				db.insertTdsDeductionDetail(ff.getUser_no(), endDate, tdsValue,type);
			}
		}
		FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("TDS Deduction Sucessfully."));
		
		return "userBlockDashboard.xhtml";
	}
	
	public void checkLiabilityType()
	{
		if(type.equals("SV"))
		{
			renderLoanButton=false;
			renderRDFDButton=false;
			renderSVButton=true;
		}
		else if(type.equals("loan"))
		{
			renderLoanButton=true;
			renderRDFDButton=false;
			renderSVButton=false;
		}
		else
		{
			renderLoanButton=false;
			renderRDFDButton=true;
			renderSVButton=false;
		}
	}
	
	public void viewSavingsReport()
	{
		
		startDate.setYear(selectYear-1901);
		endDate.setYear(selectYear-1900);
		System.out.println(startDate);
		
		total=0;
		finalList=new ArrayList<>();
		lastList=new ArrayList<>();

		if(startDate==null || endDate==null)
		{
			lastList=db.interestListOfCustomerDeposit();
		}
		else if(startDate.after(endDate))
		{
			lastList=new ArrayList<>();
			finalList=new ArrayList<>();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Please enter dates properly!"));
		}
		else
		{
			Timestamp start=new Timestamp(startDate.getTime());
			Timestamp end=new Timestamp(endDate.getTime());
			lastList=db.interestListOfCustomerDeposit(start,end);
		}
		
		int k=0;
		for(InstallmentInfo tt : lastList)
		{
			tt.setSno(++k);
			total+=tt.getInterest();
		}
		total=Double.parseDouble(new DecimalFormat("##.##").format(total));
		
		createTdsIntrestList();
		
	}
	
	public void viewLoanReport()
	{
		total=0;
		finalList=new ArrayList<>();
		lastList=new ArrayList<>();

		if(startDate==null || endDate==null)
		{
			lastList=db.interestListOfLoanPayment();
		}
		else if(startDate.after(endDate))
		{
			lastList=new ArrayList<>();
			finalList=new ArrayList<>();
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Please enter dates properly!"));
		}
		else
		{
			Timestamp start=new Timestamp(startDate.getTime());
			Timestamp end=new Timestamp(endDate.getTime());
			lastList=db.interestListOfLoanPayment(start,end);
		}
		
		int k=0;
		for(InstallmentInfo tt : lastList)
		{
			tt.setSno(++k);
			total+=tt.getInterest();
		}
		total=Double.parseDouble(new DecimalFormat("##.##").format(total));
	}
	
	double total=0;
	public void view()
	{
		startDate.setYear(selectYear-1901);
		endDate.setYear(selectYear-1900);
		System.out.println(startDate);
		
		total=0;
		interestList=new ArrayList<>();
		particularList=new ArrayList<>();
		paidInstallmentList=new ArrayList<>();
		finalList=new ArrayList<>();
		lastList=new ArrayList<>();

		boolean intfirst=false,intsecond=false,intthird=false,intfourth=false;
		for(UserInfo info : rdFdList)
		{
			UserInfo ii=new UserInfo();
			if(info.getScheme_type().equals(type))
			{
				ii.setScheme_type(info.getScheme_type());
				ii.setUser_no(info.getUser_no());
				ii.setOffice_date(info.getOffice_date());
				ii.setFirst_applicantName(info.getFirst_applicantName());
				ii.setInstallment_amount(info.getInstallment_amount());
				ii.setStrMatDate(info.getStrMatDate());
				
				particularList.add(ii);
				
			}
		}
		for(UserInfo uu : particularList)
		{
			
			paidInstallmentList=db.showInstallment(uu.getUser_no());
			if(paidInstallmentList!=null)
			{
				for(InstallmentInfo ll : paidInstallmentList)
				{
					InstallmentInfo oo=new InstallmentInfo();
					if(ll.getStatus().equals("Paid"))
					{
						oo.setUser_no(ll.getUser_no());
						oo.setCalc_interest(ll.getCalc_interest());
						oo.setOffice_date(uu.getOffice_date());
						oo.setStatus(ll.getStatus());
						oo.setInstlmntDate(ll.getInstlmntDate());
						oo.setIns_date(ll.getIns_date()); 
						interestList.add(oo);
					}
					
				}
			}
			
		}
		int i=0;
		int j=0;
		int year=0;
		for(InstallmentInfo ff : interestList)
		{
			String usercode="";
			
			
			double interest1=0,interest2=0,interest3=0,interest4=0;
			InstallmentInfo ss=new InstallmentInfo();
			Timestamp insdt=new Timestamp(ff.getInstlmntDate().getTime());

			if(i>0)
			{
				usercode=interestList.get(i-1).getUser_no();
			}
			
			if(!(usercode.equals(ff.getUser_no())))
			{
				j=0;
			}
			
			if(j==0)
			{
				year=ff.getOffice_date().getYear();
			}
			
			dt1.setYear(year);dt2.setYear(year);dt3.setYear(year);
			dt4.setYear(year);dt5.setYear(year);dt6.setYear(year);
			dt7.setYear(year);dt8.setYear(year);
			
			if((insdt.equals(dt1) || insdt.after(dt1)) && (insdt.equals(dt2) || insdt.before(dt2)))
			{
				
				if(intfirst==false || !(usercode.equals(ff.getUser_no())))
				{
				
					for(InstallmentInfo rr : interestList)
					{
				
						Timestamp insdt1=new Timestamp(rr.getInstlmntDate().getTime());
						if((ff.getUser_no().equals(rr.getUser_no()) && (insdt1.equals(dt1) || insdt1.after(dt1)) && (insdt1.equals(dt2) || insdt1.before(dt2)) ))
						{
							interest1=interest1+rr.getCalc_interest();
						}
					}

					intsecond=false;
					intfirst=true;
					intthird=false;
					intfourth=false;
					
					ss.setUser_no(ff.getUser_no());
					ss.setPayoutDate(dt2);
					ss.setInterest(interest1);
					ss.setStrPayOutDate(new SimpleDateFormat("dd/MM/yyyy").format(ss.getPayoutDate()));
				}
				
				
			}
			else if((insdt.equals(dt3) || insdt.after(dt3)) && (insdt.equals(dt4) || insdt.before(dt4)))
			{
				if(intsecond==false || !(usercode.equals(ff.getUser_no())))
				{
					for(InstallmentInfo rr : interestList)
					{
				
						Timestamp insdt1=new Timestamp(rr.getInstlmntDate().getTime());
						if((ff.getUser_no().equals(rr.getUser_no()) && (insdt1.equals(dt3) || insdt1.after(dt3)) && (insdt1.equals(dt4) || insdt1.before(dt4)) ))
						{
							interest2=interest2+rr.getCalc_interest();
						}
					}
					
					intsecond=true;
					intfirst=false;
					intthird=false;
					intfourth=false;
					
					ss.setUser_no(ff.getUser_no());
					ss.setPayoutDate(dt4);
					ss.setInterest(interest2);
					ss.setStrPayOutDate(new SimpleDateFormat("dd/MM/yyyy").format(ss.getPayoutDate()));

				}

			}
			else if((insdt.equals(dt5) || insdt.after(dt5)) && (insdt.equals(dt6) || insdt.before(dt6)))
			{	
				if(intthird==false || !(usercode.equals(ff.getUser_no())))
				{
					for(InstallmentInfo rr : interestList)
					{
				
						Timestamp insdt1=new Timestamp(rr.getInstlmntDate().getTime());
						if((ff.getUser_no().equals(rr.getUser_no()) && (insdt1.equals(dt5) || insdt1.after(dt5)) && (insdt1.equals(dt6) || insdt1.before(dt6)) ))
						{
							interest3=interest3+rr.getCalc_interest();
						}
					}
					
					intsecond=false;
					intfirst=false;
					intthird=true;
					intfourth=false;
					
					ss.setUser_no(ff.getUser_no());
					ss.setPayoutDate(dt6);
					ss.setInterest(interest3);
					ss.setStrPayOutDate(new SimpleDateFormat("dd/MM/yyyy").format(ss.getPayoutDate()));

				}
				year++;

			}
			else if((insdt.equals(dt7) || insdt.after(dt7)) && (insdt.equals(dt8) || insdt.before(dt8)))
			{
				if(intfourth==false || !(usercode.equals(ff.getUser_no())))
				{
					for(InstallmentInfo rr : interestList)
					{
				
						Timestamp insdt1=new Timestamp(rr.getInstlmntDate().getTime());
						if((ff.getUser_no().equals(rr.getUser_no()) && (insdt1.equals(dt7) || insdt1.after(dt7)) && (insdt1.equals(dt8) || insdt1.before(dt8)) ))
						{
							interest4=interest4+rr.getCalc_interest();
						}
					}
					
					intsecond=false;
					intfirst=false;
					intthird=false;
					intfourth=true;
					
					ss.setUser_no(ff.getUser_no());
					ss.setPayoutDate(dt8);
					ss.setInterest(interest4);
					ss.setStrPayOutDate(new SimpleDateFormat("dd/MM/yyyy").format(ss.getPayoutDate()));

				}

			}
				
			//****
			i++;j++;
			if(startDate==null || endDate==null)
			{
				if(ss.getInterest()>0 && (ss.getPayoutDate().before(tdydt) || ss.getPayoutDate().equals(tdydt)))
				{
					lastList.add(ss);
				}
			}
			else if(startDate.after(endDate))
			{
				lastList=new ArrayList<>();
				finalList=new ArrayList<>();
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("Please enter dates properly!"));
				break;
			}
			else
			{
				Timestamp start=new Timestamp(startDate.getTime());
				Timestamp end=new Timestamp(endDate.getTime());
				if(ss.getInterest()>0 && (ss.getPayoutDate().after(start) || ss.getPayoutDate().equals(start)) && (ss.getPayoutDate().before(end) || ss.getPayoutDate().equals(end)))
				{
					
					lastList.add(ss);
							
				}
				
				
			}
			
		}
		
		int r=0;
		for(InstallmentInfo rr : lastList)
		{
			rr.setSno(++r);
			total+=rr.getInterest();
		}
		total=Double.parseDouble(new DecimalFormat("##.##").format(total));
		
		
		createTdsIntrestList();
		
		
	}
	
	
	public void createTdsIntrestList()
	{
		boolean check=db.checkTdsDeductionDuplicacy(type, endDate);
		if(check==true)
		{
			showTable=false;
			FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("TDS On "+type+" Already Deduct For The Selected Year!!!"));
		}
		else
		{
			ArrayList<InstallmentInfo> tempList=new ArrayList<>();
			tdsIntrestList=new ArrayList<>();
			boolean chk=true;
			double iamt = 0;
			String accNo="";
			int n=0;
			for(int m=0; m<lastList.size();m++)
			{
				if(chk==true)
				{
					chk=false;
					accNo=lastList.get(m).getUser_no();
				}
				
				if(accNo.equals(lastList.get(m).getUser_no()))
				{
					iamt+=lastList.get(m).getInterest();
				}
				else
				{
					iamt=Double.parseDouble(new DecimalFormat("##.##").format(iamt));
					tdsIntrestList.add(lastList.get(m-1));
					tdsIntrestList.get(n).setInterest(iamt);
					tdsIntrestList.get(n).setSno(n+1);
					
					iamt=0;
					n=n+1;
					
					accNo=lastList.get(m).getUser_no();
					iamt+=lastList.get(m).getInterest();
				}
				
				if(m==lastList.size()-1)
				{
					System.out.println(m+"====="+lastList.size());
					
					iamt=Double.parseDouble(new DecimalFormat("##.##").format(iamt));
					tdsIntrestList.add(lastList.get(m));
					tdsIntrestList.get(n).setInterest(iamt);
					tdsIntrestList.get(n).setSno(n+1);
				}
			}
			
			
			if(tdsIntrestList.size()>0)
			{
				for(InstallmentInfo ff: tdsIntrestList)
				{
					if(ff.getInterest()>=10000)
					{
						tempList.add(ff);
					}
				}
			}
			
			tdsIntrestList=new ArrayList<>();
			tdsIntrestList=tempList;
			for(int x=0;x<tdsIntrestList.size();x++)
			{
				tdsIntrestList.get(x).setSno(x+1);
			}
			
			if(tdsIntrestList.size()>0)
			{
				showTable=true;
			}
			else
			{
				showTable=false;
				FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("No Record Found!!!"));
			}
			
			tempList=new ArrayList<>();
		}
		
	}
	
	public void print()
	{
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("list",lastList);
		ss.setAttribute("total",total);
		ss.setAttribute("type",type);
		RequestContext.getCurrentInstance().execute("window.open('printLiabilitiesReport.xhtml')");
		
	}


	public ArrayList<InstallmentInfo> getFinalList() {
		return finalList;
	}

	public void setFinalList(ArrayList<InstallmentInfo> finalList) {
		this.finalList = finalList;
	}
	
	public ArrayList<InstallmentInfo> getInterestList() {
		return interestList;
	}

	public void setInterestList(ArrayList<InstallmentInfo> interestList) {
		this.interestList = interestList;
	}

	public ArrayList<InstallmentInfo> getPaidInstallmentList() {
		return paidInstallmentList;
	}

	public void setPaidInstallmentList(ArrayList<InstallmentInfo> paidInstallmentList) {
		this.paidInstallmentList = paidInstallmentList;
	}

	public ArrayList<UserInfo> getParticularList() {
		return particularList;
	}

	public void setParticularList(ArrayList<UserInfo> particularList) {
		this.particularList = particularList;
	}

	public ArrayList<UserInfo> getRdFdList() {
		return rdFdList;
	}

	public void setRdFdList(ArrayList<UserInfo> rdFdList) {
		this.rdFdList = rdFdList;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public double getTotal() {
		return total;
	}

	public void setTotal(double total) {
		this.total = total;
	}

	public boolean isRenderRDFDButton() {
		return renderRDFDButton;
	}

	public void setRenderRDFDButton(boolean renderRDFDButton) {
		this.renderRDFDButton = renderRDFDButton;
	}

	public boolean isRenderSVButton() {
		return renderSVButton;
	}

	public void setRenderSVButton(boolean renderSVButton) {
		this.renderSVButton = renderSVButton;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public boolean isRenderLoanButton() {
		return renderLoanButton;
	}

	public void setRenderLoanButton(boolean renderLoanButton) {
		this.renderLoanButton = renderLoanButton;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}

	public ArrayList<InstallmentInfo> getLastList() {
		return lastList;
	}

	public void setLastList(ArrayList<InstallmentInfo> lastList) {
		this.lastList = lastList;
	}

	

	public ArrayList<SelectItem> getYearList() {
		return yearList;
	}

	public void setYearList(ArrayList<SelectItem> yearList) {
		this.yearList = yearList;
	}

	public int getSelectYear() {
		return selectYear;
	}

	public void setSelectYear(int selectYear) {
		this.selectYear = selectYear;
	}

	public ArrayList<SelectItem> getTypeList() {
		return typeList;
	}

	public void setTypeList(ArrayList<SelectItem> typeList) {
		this.typeList = typeList;
	}

	public ArrayList<InstallmentInfo> getTdsIntrestList() {
		return tdsIntrestList;
	}

	public void setTdsIntrestList(ArrayList<InstallmentInfo> tdsIntrestList) {
		this.tdsIntrestList = tdsIntrestList;
	}

	public boolean isShowTable() {
		return showTable;
	}

	public void setShowTable(boolean showTable) {
		this.showTable = showTable;
	}
	
	
}
*/