using Ease.Core.Model;


using System;
using System.Collections.Generic;
using System.Data;

namespace HRM.BO
{
    #region SalaryProcess
    public class SalaryProcess : AuditTrailBase
    {
        #region Constructor

        public SalaryProcess()
        {
            _salaryMonth = DateTime.MinValue;
            _processDate = DateTime.MinValue;
            _paymentDate = DateTime.MinValue;
            _monthEndDate = DateTime.MinValue;
            _workDays = 0;
            _isFinalized = false;
            _processCode = "";
            _remarks = "";
            _payrollTypeID = 0;
            _showInDesktop = false;
            _showInDesktopDate = DateTime.MinValue;
        }

        #endregion

        #region Properties

        #region Salary Month : DateTime

        private DateTime _salaryMonth;
        public DateTime SalaryMonth
        {
            get { return _salaryMonth; }
            set
            {
                
                _salaryMonth = value;
            }
        }

        #endregion

        #region processDate : DateTime

        private DateTime _processDate;
        public DateTime ProcessDate
        {
            get { return _processDate; }
            set
            {
                
                _processDate = value;
            }
        }

        #endregion

        #region paymentDate : System.DateTime

        private System.DateTime? _paymentDate;
        public System.DateTime? PaymentDate
        {
            get { return _paymentDate; }
            set
            {
                
                _paymentDate = value;
            }
        }

        #endregion

        #region workDays : int

        private int _workDays;
        public int WorkDays
        {
            get { return _workDays; }
            set
            {
                
                _workDays = value;
            }
        }

        #endregion

        #region isFinalized : bool

        private bool _isFinalized;
        public bool IsFinalized
        {
            get { return _isFinalized; }
            set
            {
                
                _isFinalized = value;
            }
        }

        #endregion

        #region payrollTypeID : int

        private int _payrollTypeID;
        public int PayrollTypeID
        {
            get { return _payrollTypeID; }
            set
            {
                
                _payrollTypeID = value;
            }
        }

        #endregion

        #region ProcessCode : string

        private string  _processCode;
        public string  ProcessCode
        {
            get { return _processCode; }
            set
            {
                
                _processCode = value;
            }
        }

        #endregion

        #region Remarks : string

        private string _remarks;
        public string Remarks
        {
            get { return _remarks; }
            set
            {
                
                _remarks = value;
            }
        }

        #endregion

        #region ShowInDesktop : int

        private bool _showInDesktop;
        public bool ShowInDesktops
        {
            get { return _showInDesktop; }
            set
            {
                
                _showInDesktop = value;
            }
        }

        #endregion

        #region ShowInDesktopDate : DateTime

        private DateTime _showInDesktopDate;
        public DateTime ShowInDesktopDate
        {
            get { return _showInDesktopDate; }
            set
            {
                
                _showInDesktopDate = value;
            }
        }

        #endregion

        #region MonthEndDate : System.DateTime

        private System.DateTime? _monthEndDate;
        public System.DateTime? MonthEndDate
        {
            get { return _monthEndDate; }
            set
            {
                
                _monthEndDate = value;
            }
        }



        #endregion

        public double EuroRate { get; set; }

        #region Service Factory ISalaryProcessService : ISalaryProcessService

        internal static ISalaryProcessService Service
        {
            get { return Services.Factory.CreateService<ISalaryProcessService>(typeof(ISalaryProcessService)); }
        }

        #endregion

        public int headCount { get; set; }
        #endregion

        //#region Functions

        //public static SalaryProcess Get(int nID)
        //{
        //    SalaryProcess oSalaryProcess = null;
        //    #region Cache Header
        //    oSalaryProcess = (SalaryProcess)_cache["Get", nID];
        //    if (oSalaryProcess != null)
        //        return oSalaryProcess;
        //    #endregion
        //    oSalaryProcess = SalaryProcess.Service.Get(nID);
        //    #region Cache Footer
        //    _cache.Add(oSalaryProcess, "Get", nID);
        //    #endregion
        //    return oSalaryProcess;
        //}

        //public static List<SalaryProcess> Get(DateTime dMonthDate)
        //{
        //    #region Cache Header

        //    List<SalaryProcess> salaryProcesss = _cache["Get", dMonthDate] as List<SalaryProcess>;
        //    if (salaryProcesss != null)
        //        return salaryProcesss;

        //    #endregion

        //    try
        //    {
        //        salaryProcesss = Service.Get(dMonthDate,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
        //    }
        //    catch (ServiceException e)
        //    {
        //        throw new Exception(e.Message, e);
        //    }

        //    #region Cache Footer

        //    _cache.Add(salaryProcesss, "Get", dMonthDate);

        //    #endregion

        //    return salaryProcesss;
        //}
        
        //public static List<SalaryProcess> Get()
        //{
        //    #region Cache Header

        //    List<SalaryProcess> salaryProcesss = _cache["Get"] as List<SalaryProcess>;
        //    if (salaryProcesss != null)
        //        return salaryProcesss;

        //    #endregion

        //    try
        //    {
        //        salaryProcesss = Service.Get(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
        //    }
        //    catch (ServiceException e)
        //    {
        //        throw new Exception(e.Message, e);
        //    }

        //    #region Cache Footer

        //    _cache.Add(salaryProcesss, "Get");

        //    #endregion

        //    return salaryProcesss;
        //}

        //public static List<SalaryProcess> GetSP()
        //{
        //    #region Cache Header

        //    List<SalaryProcess> salaryProcesss = _cache["Get"] as List<SalaryProcess>;
        //    if (salaryProcesss != null)
        //        return salaryProcesss;

        //    #endregion

        //    try
        //    {
        //        salaryProcesss = Service.GetSP();
        //    }
        //    catch (ServiceException e)
        //    {
        //        throw new Exception(e.Message, e);
        //    }

        //    #region Cache Footer

        //    _cache.Add(salaryProcesss, "GetSP");

        //    #endregion

        //    return salaryProcesss;
        //}

        //public bool GetBySMonth(DateTime dSMonth)
        //{
        //    bool bShowInDesktop;
        //    bShowInDesktop = SalaryProcess.Service.GetBySMonth(dSMonth,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer);
        //    return bShowInDesktop;
        //}

        //public int Save()
        //{
        //    return SalaryProcess.Service.Save(this);
        //}

        //public void SetAuditTraiProperty()
        //{
        //    base.SetAuditTrailProperties();
        //}

        //public void Delete()
        //{
        //    SalaryProcess.Service.Delete(this.ID);
        //}

        //public void UndoSalary() 
        //{
        //    SalaryProcess.Service.UndoSalary(this.ID);
        //}

        //public static void UndoMonthlySalaryByIDs(string ids)
        //{
        //    SalaryProcess.Service.UndoMonthlySalaryByIDs(ids);
        //}

        //public static void UndoMonthlySalaryByEmpIDs(string ids,DateTime salaryMonth)
        //{
        //    SalaryProcess.Service.UndoMonthlySalaryByEmpIDs(ids, salaryMonth);
        //}

        //public void Update(SalaryProcess oSProcess)
        //{
        //    this.SetAuditTraiProperty();
        //    SalaryProcess.Service.Update(oSProcess);
        //}

        //public void SPApprove(SalaryProcess oSProcess)
        //{
        //    SalaryProcess.Service.SPApprove(oSProcess);
        //}

        //public static List<SalaryProcess> GetAllProcess()
        //{
        //    List<SalaryProcess> salaryProcesss = new List<SalaryProcess> ();
        //    salaryProcesss = SalaryProcess.Service.GetAllProcess(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer, SystemInformation.CurrentSysInfo.NextPayProcessDate);
        //    return salaryProcesss;
        //}

        //#endregion
    }
    #endregion

    #region ISalaryProcess Service

    public interface ISalaryProcessService
    {

        bool GetBySMonth(DateTime sMonth, int payrollTypeID);

        List<SalaryProcessStatus> SalaryProcess(SalaryProcess item, List<Employee> employees);
        int Save(SalaryProcess item);
        void Delete(int id);
        bool IsSalaryprocessed(DateTime salarymonth, int payrollTypeID);
        void UndoSalary(int id);
        void UndoMonthlySalaryByIDs(string ids);
        void UndoMonthlySalaryByEmpIDs(string ids, DateTime salaryMonth);
        void ApproveSalary(DateTime salaryMonth, int payrollTypeID);
        void Update(SalaryProcess oSProcess);
        void SPApprove(SalaryProcess oSProcess);
        List<SalaryProcess> Get(DateTime dMonthDate, int payrollTypeID);
        List<SalaryProcess> GetUnApprovedSalaries(DateTime dMonthDate, int payrollTypeID);
       
        void MonthEnd(int userid, DateTime salaryMonth, int payrollTypeID, DateTime paymentDate);

        List<SalaryProcess> GetAllProcess(int payrollTypeID, DateTime nextPayProcessDate);
    }

    #endregion
}