package com.reallinkbilling.jspRedirect;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.reallinkbilling.cipher.EncryptionDecryption;
import com.reallinkbilling.utils.GetAccountListForDrCr;
import com.reallinkbilling.utils.GetSupplierDebtAmountById;
import com.reallinkbilling.utils.GetSupplierNameById;
import com.reallinkbilling.utils.GetTypeOfPaymentList;

public class AddSuppPaymentDetailsJsp  extends ActionSupport implements SessionAware{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = 7347721420936177311L;
	private HttpSession session;
	private String key;
	private String paymentDate;
	private String supplierId;
	private String supplierName;
	private String supplierMobile;
	private String debtAmount;
	private SessionMap<String,Object> sessionMap;

	private Map<String,String> accountList = new LinkedHashMap<String,String>();
	private List<String> paymentTypeList = new ArrayList<String>();
	
	public String execute(){
		
		String result = "login";
		session=ServletActionContext.getRequest().getSession(false); 
		 
	        if(session==null || session.getAttribute("login")==null){ 
	        	addActionMessage("Please Login First !!!");
	        	result = "login";
	        }  
	        else{
	        	DecimalFormat df = new DecimalFormat("#.##");
	        	Date d = new Date();
	        	SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
	        	
	        	setPaymentDate(dateFormat.format(d));
	        	
	        	String supplierId = EncryptionDecryption.decrypt(key);
	        	
	        	this.setSupplierName(GetSupplierNameById.getSupplierNameById(supplierId, this.getSessionMap()));
	        	this.setDebtAmount(df.format(GetSupplierDebtAmountById.getSupplierDebtAmount(supplierId, this.getSessionMap())));
	        	this.setAccountList(GetAccountListForDrCr.getAccountList(this.getSessionMap())); 
	        	this.setPaymentTypeList(GetTypeOfPaymentList.getTypeOfPaymentList());
	        	
	        	result = SUCCESS;
        }
        
        return result;
}


public HttpSession getSession() {
	return session;
}


public void setSession(HttpSession session) {
	this.session = session;
}


public String getKey() {
	return key;
}


public void setKey(String key) {
	this.key = key;
}


public String getPaymentDate() {
	return paymentDate;
}


public void setPaymentDate(String paymentDate) {
	this.paymentDate = paymentDate;
}


public String getSupplierId() {
	return supplierId;
}


public void setSupplierId(String supplierId) {
	this.supplierId = supplierId;
}


public String getSupplierName() {
	return supplierName;
}


public void setSupplierName(String supplierName) {
	this.supplierName = supplierName;
}


public String getSupplierMobile() {
	return supplierMobile;
}


public void setSupplierMobile(String supplierMobile) {
	this.supplierMobile = supplierMobile;
}


public String getDebtAmount() {
	return debtAmount;
}


public void setDebtAmount(String debtAmount) {
	this.debtAmount = debtAmount;
}


public static long getSerialversionuid() {
	return serialVersionUID;
}
public SessionMap<String, Object> getSessionMap() {
	return sessionMap;
}

public void setSessionMap(SessionMap<String, Object> sessionMap) {
	this.sessionMap = sessionMap;
}


public void setSession(Map<String, Object> map) {  
    sessionMap=(SessionMap<String, Object>)map;  
}


public Map<String, String> getAccountList() {
	return accountList;
}


public void setAccountList(Map<String, String> accountList) {
	this.accountList = accountList;
}


public List<String> getPaymentTypeList() {
	return paymentTypeList;
}


public void setPaymentTypeList(List<String> paymentTypeList) {
	this.paymentTypeList = paymentTypeList;
}




}
