
package main_package;

import java.io.Serializable;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

@ManagedBean(name="cashFlow")
@ViewScoped
 
public class CashInOutFlowBean implements Serializable
{
	String transactionType,pay,option,debitCategory,creditCategory,loanCategory,liability, empPayCat;
	boolean renderOption=false,renderPay=false,renderDebit=false,renderCredit=false,renderLoan=false,renderButton=false,renderLiability=false;
	boolean showSub;
	
	public void checkTransactionType()
	{
		if(transactionType.equals("debit"))
		{
			renderDebit=true;
			renderCredit=false;
			renderButton=true;
		}
		else if(transactionType.equals("credit"))
		{
			renderCredit=true;
			renderDebit=false;
			renderButton=true;
		}
	}
	
	public void checkDebitCategory()
	{
		if(debitCategory.equals("Pay_Liabilities_Dr_rd") || debitCategory.equals("Pay_Liabilities_Dr_fd"))
		{
			renderOption=true;
			showSub=false;
		}
		else if(debitCategory.equals("emp_pay_deduct_sub"))
		{
			showSub=true;
			renderPay=false;
		}
		else
		{
			renderPay=false;
			showSub=false;
		}
	}
	
	public String checkLoanCategory()
	{
		if(loanCategory.equals("personalloan"))
		{
			return "personalLoan"; 
		}
		else if(loanCategory.equals("propertyloan"))
		{
			return "PropertyLoan";
		}
		else if(loanCategory.equals("vechicleloan"))
		{
			return "vehicleLoan";
		}
		else if(loanCategory.equals("grouploan"))
		{
			return "groupLoan";
		}
		
		return "";
	}
	
	public String proceed()
	{
		if(renderDebit==true)
		{
			if(debitCategory.equals("curr_Asst_Loan_Dr"))
			{
				return "debitLoan";
			}
			else if(debitCategory.equals("curr_Asst_Bank_Dr"))
			{
				return "addDebitCurrentAssetBank"; 
			}
			else if(debitCategory.equals("Fixed_Deposit_Dr") || debitCategory.equals("Fixed_Asset_Dr") || debitCategory.equals("Other_Dr"))
			{
				HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
				ss.setAttribute("expenseCategory",debitCategory);
				return "addExpense";
			}
			else if(debitCategory.equals("instant_loan"))
			{
				return "instantLoan";
			}
			else if(debitCategory.equals("return_instant_borrow"))
			{
				return "returnInstantBorrow";
			}
			else if(debitCategory.equals("emp_sal_pay"))
			{
				return "employeeSalaryPayout";
			}
			else if(debitCategory.equals("emp_pay_deduct_sub"))
			{
				HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
				ss.setAttribute("payCat",empPayCat);
				
				return "employeePayDeductSubmission";
			}
			else if(debitCategory.equals("tds_sub"))
			{
				return "tdsSubmission.xhtml";
			}
			else if(debitCategory.equals("return_dsa_comm"))
			{
				return "returnDSAComm";
			}
			else
			{
				if((debitCategory.equals("Pay_Liabilities_Dr_rd") || debitCategory.equals("Pay_Liabilities_Dr_fd")) && option.equals("return"))
				{
					return "maturedRD";
				}
				else if((debitCategory.equals("Pay_Liabilities_Dr_rd") || debitCategory.equals("Pay_Liabilities_Dr_fd")) && option.equals("close"))
				{
					return "closeSchemePage";
				}
				else if(debitCategory.equals("Pay_Liabilities_Dr_sv"))
				{
					return "userWithdrawl";
				}
				
			}
			
		}
		else if(renderCredit==true)
		{
			 if(creditCategory.equals("fdr_Interest_Cr") || creditCategory.equals("Fixed_Deposit_Cr") || creditCategory.equals("Other_Cr")||creditCategory.equals("Liability_Cr"))
			 {
				 //renderLoan=true;
				 HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
				 ss.setAttribute("incomeCategory",creditCategory);
				 return "addIncome";
			 }
			 else if(creditCategory.equals("Fixed_Asset_Cr"))
			 {
				 return "fixedAssetSale";
			 }
			 else if(creditCategory.equals("Loan_EMI_Cr"))
			 {
				 return "payLoanEMI";
			 }
			 else if(creditCategory.equals("direct_bank_deposit"))
			 {
				 return "directBankDeposit";
			 }
			 else if(creditCategory.equals("curr_Asst_Bank_Cr"))
			 {
				 return "addCreditCurrentAssetBank";
			 }
			 else if(creditCategory.equals("Get_Liabilities_Cr_Rd") || creditCategory.equals("Get_Liabilities_Cr_Fd"))
			 {
				 return "paymentReceipt"; 
			}
			 else if(creditCategory.equals("Get_Liabilities_Cr_Sv"))
			 {
				 return "userDeposit";
			 }
			 else if(creditCategory.equals("instant_borrow"))
				{
					return "instantBorrow";
				}
				else if(creditCategory.equals("return_instant_loan"))
				{
					return "returnInstantLoan";
				}
		}
		
		/*if(renderLoan==true)
		{
			if(loanCategory.equals("personalloan"))
			{
				return "personalLoan"; 
			}
			else if(loanCategory.equals("propertyloan"))
			{
				return "PropertyLoan";
			}
			else if(loanCategory.equals("vechicleloan"))
			{
				return "vehicleLoan";
			}
			else if(loanCategory.equals("grouploan"))
			{
				return "groupLoan";
			}
		}*/
		return "";
	}
	
	
	//Method For Menu Bar
	
	public String addExpense()
	{
		debitCategory="Other_Dr";
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("expenseCategory",debitCategory);
		
		return "addExpense";
	}
	
	public String addAssets()
	{
		debitCategory="Fixed_Asset_Dr";
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("expenseCategory",debitCategory);
		
		return "addExpense";
	}
	
	public String addIncome()
	{
		creditCategory="Other_Cr";
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("incomeCategory",creditCategory);
		
		return "addIncome";
	}

	public String addDeposit()
	{
		creditCategory="Get_Liabilities_Cr_Sv";
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("expenseCategory",creditCategory);
		
		return "userDeposit.xhtml";
	}
	
	public String addWithdrawl()
	{
		debitCategory="Pay_Liabilities_Dr_sv";
		HttpSession ss=(HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(false);
		ss.setAttribute("expenseCategory",debitCategory);
		
		return "userWithdrawl.xhtml";
	}
	
	public String getTransactionType() {
		return transactionType;
	}

	public void setTransactionType(String transactionType) {
		this.transactionType = transactionType;
	}

	public String getPay() {
		return pay;
	}

	public void setPay(String pay) {
		this.pay = pay;
	}

	public String getOption() {
		return option;
	}

	public void setOption(String option) {
		this.option = option;
	}

	public boolean isRenderOption() {
		return renderOption;
	}

	public void setRenderOption(boolean renderOption) {
		this.renderOption = renderOption;
	}

	public boolean isRenderPay() {
		return renderPay;
	}

	public void setRenderPay(boolean renderPay) {
		this.renderPay = renderPay;
	}

	public String getDebitCategory() {
		return debitCategory;
	}

	public void setDebitCategory(String debitCategory) {
		this.debitCategory = debitCategory;
	}

	public String getCreditCategory() {
		return creditCategory;
	}

	public void setCreditCategory(String creditCategory) {
		this.creditCategory = creditCategory;
	}

	public String getLoanCategory() {
		return loanCategory;
	}

	public void setLoanCategory(String loanCategory) {
		this.loanCategory = loanCategory;
	}

	public boolean isRenderDebit() {
		return renderDebit;
	}

	public void setRenderDebit(boolean renderDebit) {
		this.renderDebit = renderDebit;
	}

	public boolean isRenderCredit() {
		return renderCredit;
	}

	public void setRenderCredit(boolean renderCredit) {
		this.renderCredit = renderCredit;
	}

	public boolean isRenderLoan() {
		return renderLoan;
	}

	public void setRenderLoan(boolean renderLoan) {
		this.renderLoan = renderLoan;
	}

	public boolean isRenderButton() {
		return renderButton;
	}

	public void setRenderButton(boolean renderButton) {
		this.renderButton = renderButton;
	}

	public boolean isRenderLiability() {
		return renderLiability;
	}

	public void setRenderLiability(boolean renderLiability) {
		this.renderLiability = renderLiability;
	}

	public String getLiability() {
		return liability;
	}

	public void setLiability(String liability) {
		this.liability = liability;
	}

	public boolean isShowSub() {
		return showSub;
	}

	public void setShowSub(boolean showSub) {
		this.showSub = showSub;
	}

	public String getEmpPayCat() {
		return empPayCat;
	}

	public void setEmpPayCat(String empPayCat) {
		this.empPayCat = empPayCat;
	}
	
	
}

