package com.reallinkbilling.login;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
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 java.util.ArrayList;

import com.reallinkbilling.DAO.CustomerPaymentReminderDetailsDAO;
import com.reallinkbilling.utils.GetNotificationList;
import com.opensymphony.xwork2.ActionSupport;

public class HomeAction extends ActionSupport implements SessionAware{

	/**
	 * 
	 */
	private static final long serialVersionUID = -8903509517602329692L;
	private HttpSession session;
	private SessionMap<String,Object> sessionMap;  
	private String billDate;
	private String defaultValue;
	private Map<String,String> customerSearchOptionList = new HashMap<String,String>();
	private String customerSearchOption;
	
	private ArrayList<CustomerPaymentReminderDetailsDAO> customerPaymentReminderList =
	        new ArrayList<CustomerPaymentReminderDetailsDAO>();
	
	
	
	private String supplierSearchOption;
	
	
	private String employeeSearchOption;
	
	@Override
	public String execute() throws Exception {
		String result = "login";
		session=ServletActionContext.getRequest().getSession(false); 
		
	        if(session==null || session.getAttribute("login")==null){ 
	        	addActionMessage("Please Login First !!!");
	        	result = "login";
	        }  
	        else{
	        	
	        	customerSearchOptionList.put("BYNAME", "BY NAME");
	        	customerSearchOptionList.put("BYMOBILE", "BY MOBILE");
	        	customerSearchOptionList.put("BYADDRESS","BY ADDRESS");
				setCustomerSearchOption("BYNAME");
				setSupplierSearchOption("BYNAME");
				setEmployeeSearchOption("BYNAME");
				setDefaultValue("BYNAME");

	        	Date d = new Date();
	        	SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
	        	setBillDate(dateFormat.format(d));
	        	
	        	this.getSessionMap().remove("productList");
	        	this.getSessionMap().remove("billInformation");
	        	this.getSessionMap().remove("deletedProductList");
	        	this.getSessionMap().remove("purchaseProductList");
	        	this.getSessionMap().remove("purchaseInformation");
	        	this.getSessionMap().remove("finishedProductInfoList");
	        	this.getSessionMap().remove("deletedProductInfoList");
	        	this.getSessionMap().remove("figureList");
	        	this.getSessionMap().remove("rejectionList");
	        	this.getSessionMap().remove("challanInformation");
	          	this.getSessionMap().remove("challanToInvProductList");
	 	       

				this.getSessionMap().remove("quotationInformation");
				this.getSessionMap().remove("quotationProductList");
				this.getSessionMap().remove("proformaInformation");
				this.getSessionMap().remove("proformaProductList");
		        
				// Refresh Customer Payment Reminder Notifications
				ArrayList<CustomerPaymentReminderDetailsDAO> customerPaymentReminderList =
				        GetNotificationList.getCustPaymentReminderList(this.getSessionMap());

				this.getSessionMap().put("customerpaymentnotificationlist",
				        customerPaymentReminderList);
	        	
	        	result = SUCCESS;
	        }
	        
	        
	        return result;
	}

	public HttpSession getSession() {
		return session;
	}

	public void setSession(HttpSession session) {
		this.session = session;
	}

	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 String getBillDate() {
		return billDate;
	}

	public void setBillDate(String billDate) {
		this.billDate = billDate;
	}


	public Map<String, String> getCustomerSearchOptionList() {
		return customerSearchOptionList;
	}

	public void setCustomerSearchOptionList(Map<String, String> customerSearchOptionList) {
		this.customerSearchOptionList = customerSearchOptionList;
	}

	public String getCustomerSearchOption() {
		return customerSearchOption;
	}

	public void setCustomerSearchOption(String customerSearchOption) {
		this.customerSearchOption = customerSearchOption;
	}

	public String getDefaultValue() {
		return defaultValue;
	}

	public void setDefaultValue(String defaultValue) {
		this.defaultValue = defaultValue;
	}

	public String getSupplierSearchOption() {
		return supplierSearchOption;
	}

	public void setSupplierSearchOption(String supplierSearchOption) {
		this.supplierSearchOption = supplierSearchOption;
	}

	public String getEmployeeSearchOption() {
		return employeeSearchOption;
	}

	public void setEmployeeSearchOption(String employeeSearchOption) {
		this.employeeSearchOption = employeeSearchOption;
	}

	public ArrayList<CustomerPaymentReminderDetailsDAO> getCustomerPaymentReminderList() {
		return customerPaymentReminderList;
	}

	public void setCustomerPaymentReminderList(ArrayList<CustomerPaymentReminderDetailsDAO> customerPaymentReminderList) {
		this.customerPaymentReminderList = customerPaymentReminderList;
	}  
	
	
	
	
	
	

}
