using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35; using Ease.CoreV35.Model; using Ease.CoreV35.Caching; using System.Data.Linq.Mapping; using System.Data; using Ease.CoreV35.Utility; namespace Payroll.BO { #region OPIProcess [Serializable] public class OPIProcess : BasicBaseObject { #region Cache Store private static Cache _cache = new Cache(typeof(OPIProcess)); #endregion OPIProcessDetailItem oProcessDetailItem = null; #region Constructor public OPIProcess() { _oPIMonth = DateTime.Today; _processDate = DateTime.Today; _oPIProcessDetails = null; } #endregion #region Properties #region OPIMonth : DateTime private DateTime _oPIMonth; public DateTime OPIMonth { get { return _oPIMonth; } set { base.OnPropertyChange("opimonth", _oPIMonth, value); _oPIMonth = value; } } #endregion #region ProcessDate : DateTime private DateTime _processDate; public DateTime ProcessDate { get { return _processDate; } set { base.OnPropertyChange("processdate", _processDate, value); _processDate = value; } } #endregion #region IsApproved : bool private bool _isApproved; public bool IsApproved { get { return _isApproved; } set { _isApproved = value; } } #endregion #region OPIProcessDetail : ObjectsTemplate private ObjectsTemplate _oPIProcessDetails; public ObjectsTemplate OPIProcessDetails { get { if (_oPIProcessDetails == null && !this.ID.IsUnassigned && this.ID.Integer > 0) { _oPIProcessDetails = GetProcessDetails(this.ID); } return this._oPIProcessDetails; } set { _oPIProcessDetails = value; } } #endregion #region Service Factory IOPIProcessService : IOPIProcessService internal static IOPIProcessService Service { get { return Services.Factory.CreateService(typeof(IOPIProcessService)); } } #endregion #endregion #region Functions public static OPIProcess Get(ID nOPIProcessID) { OPIProcess oOPIProcess = null; #region Cache Header oOPIProcess = (OPIProcess)_cache["Get", nOPIProcessID]; if (oOPIProcess != null) return oOPIProcess; #endregion oOPIProcess = OPIProcess.Service.Get2(nOPIProcessID, SystemInformation.CurrentSysInfo.PayrollTypeID); #region Cache Footer _cache.Add(oOPIProcess, "Get", nOPIProcessID); #endregion return oOPIProcess; } public static ObjectsTemplate Get() { #region Cache Header ObjectsTemplate oOPIProcesss = _cache["Get"] as ObjectsTemplate; if (oOPIProcesss != null) return oOPIProcesss; #endregion try { oOPIProcesss = Service.Get3(SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oOPIProcesss, "Get"); #endregion return oOPIProcesss; } public static ObjectsTemplate Get(DateTime dOPIMonth) { #region Cache Header ObjectsTemplate oProcesss = _cache["Get", dOPIMonth] as ObjectsTemplate; if (oProcesss != null) return oProcesss; #endregion try { oProcesss = Service.Get4(dOPIMonth, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oProcesss, "Get", dOPIMonth); #endregion return oProcesss; } public static ObjectsTemplate GetProcessDetails(ID opiProcessID) { #region Cache Header ObjectsTemplate oProcessDetails = _cache["GetProcessDetails", opiProcessID] as ObjectsTemplate; if (oProcessDetails != null) return oProcessDetails; #endregion try { oProcessDetails = Service.GetProcessDetails(opiProcessID, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oProcessDetails, "GetProcessDetails", opiProcessID); #endregion return oProcessDetails; } public static ObjectsTemplate GetProcessDetailWithItems(ID opiProcessID) { #region Cache Header ObjectsTemplate oProcessDetails = _cache["GetProcessDetailWithItems", opiProcessID] as ObjectsTemplate; if (oProcessDetails != null) return oProcessDetails; #endregion try { oProcessDetails = Service.GetProcessDetailWithItems(opiProcessID, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oProcessDetails, "GetProcessDetailWithItems", opiProcessID); #endregion return oProcessDetails; } public static ObjectsTemplate GetProcessDetailItems(ID nProcessDetailID) { #region Cache Header ObjectsTemplate oProcessDetailItems = _cache["GetProcessDetailItems", nProcessDetailID] as ObjectsTemplate; if (oProcessDetailItems != null) return oProcessDetailItems; #endregion try { oProcessDetailItems = Service.GetProcessDetailItems(nProcessDetailID, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oProcessDetailItems, "GetProcessDetailItems", nProcessDetailID); #endregion return oProcessDetailItems; } public static ObjectsTemplate GetProcessDetails(DateTime processMonth) { ObjectsTemplate oProcessDetailItems = null; try { oProcessDetailItems = Service.GetProcessDetails(processMonth, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } return oProcessDetailItems; } public static OPIProcessDetail GetDetail(ID employeeID, DateTime processMonth) { OPIProcessDetail oProcessDetail = null; try { oProcessDetail = Service.GetDetail(employeeID, processMonth, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } return oProcessDetail; } public static double GetProvisionAmountByEmpID(ID nEmpID) { return OPIProcess.Service.GetProvisionAmountByEmpID(nEmpID); } public static double GetPrevMonthAmount(ID nEmpID, ID nOPIItemID, DateTime dFromOpiMonth, DateTime dToOpiMonth) { return OPIProcess.Service.GetPrevMonthAmount(nEmpID, nOPIItemID, dFromOpiMonth, dToOpiMonth); } public static DataSet GetOPIRegister(string sOPIItemID, DateTime dOPIMonth, string sEmpID) { DataSet ds = null; try { ds = Service.GetOPIRegister(sOPIItemID, dOPIMonth, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetDetailOtherPayrollItems(string sOPIItemID, DateTime dOPIMonth, string sEmpID) { DataSet ds = null; try { ds = Service.GetDetailOtherPayrollItems(sOPIItemID, dOPIMonth, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetOPITotalValueRegister(DateTime dFromOPIMonth, DateTime dToOPIMonth, int nOPIItemID, string sEmpID) { DataSet ds = null; try { ds = Service.GetOPITotalValueRegister(dFromOPIMonth, dToOPIMonth, nOPIItemID, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetDataSetOfOPIRegister(string sSearch) { DataSet dsOPIRegister = null; dsOPIRegister = OPIProcess.Service.GetDataSetOfOPIRegister(sSearch); return dsOPIRegister; } public ID Save() { this.SetAuditTrailProperties(); return OPIProcess.Service.Save(this, SystemInformation.CurrentSysInfo.PayrollTypeID); } public static ID UpdateOnlyProcess(OPIProcess oProcess) { oProcess.SetAuditTrailProperties(); return OPIProcess.Service.UpdateOnlyProcess(oProcess, SystemInformation.CurrentSysInfo.PayrollTypeID); } public static void Save(OPIProcess oProcess, ObjectsTemplate oPDetails) { oProcess.SetAuditTrailProperties(); OPIProcess.Service.Save(oProcess, oPDetails, SystemInformation.CurrentSysInfo.PayrollTypeID); } public void Delete() { OPIProcess.Service.Delete(this.ID, SystemInformation.CurrentSysInfo.PayrollTypeID); } public static void Undo(DateTime opiMonth) { OPIProcess.Service.Undo(opiMonth, SystemInformation.CurrentSysInfo.PayrollTypeID); } public void UpdateOPIDetail(ObjectsTemplate oItems) { OPIProcess.Service.UpdateDetail(oItems, SystemInformation.CurrentSysInfo.PayrollTypeID); } #endregion public static ObjectsTemplate GetOPiProcessItems(DateTime dateTime) { #region Cache Header ObjectsTemplate oProcessDetailItems = _cache["GetOPiProcessItems", dateTime] as ObjectsTemplate; if (oProcessDetailItems != null) return oProcessDetailItems; #endregion try { oProcessDetailItems = Service.GetOPiProcessItems(dateTime, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oProcessDetailItems, "GetOPiProcessItems", dateTime); #endregion return oProcessDetailItems; } public static ObjectsTemplate GetLastMonthItems(int nEmployeeID) { #region Cache Header ObjectsTemplate oOPIProcessDetailItems = _cache["GetLastMonthItems", nEmployeeID] as ObjectsTemplate; if (oOPIProcessDetailItems != null) return oOPIProcessDetailItems; #endregion try { oOPIProcessDetailItems = Service.GetLastMonthItems(nEmployeeID, SystemInformation.CurrentSysInfo.PayrollTypeID); } catch (ServiceException e) { throw new Exception(e.Message, e); } #region Cache Footer _cache.Add(oOPIProcessDetailItems, "GetLastMonthItems", nEmployeeID); #endregion return oOPIProcessDetailItems; } public static DataSet GetEmpOPIPaySlip(DateTime _SalaryMonth, string sEmpID) { DataSet ds = null; try { ds = Service.GetEmpOPIPaySlip(_SalaryMonth, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static double GetAmountOnRange(Employee employee, DateTime fromDate, DateTime toDate, int opiID, int parameterid) { double fractionMonthAmount = 0; double amount = 0; if (Ease.CoreV35.Utility.Global.DateFunctions.DateDiff("m", GlobalFunctions.FirstDateOfMonth(fromDate), GlobalFunctions.LastDateOfMonth(toDate)) > 2) { amount = OPIProcess.Service.GetPrevMonthAmount(employee.ID, ID.FromInteger(opiID), GlobalFunctions.FirstDateOfMonth(fromDate.AddMonths(1)), GlobalFunctions.LastDateOfMonth(toDate.AddMonths(-1))); } bool dataNotFound = false; if (fromDate != Global.DateFunctions.FirstDateOfMonth(fromDate)) { EmployeeGradeSalary oge = EmployeeGradeSalary.Get(employee.ID, fromDate, EnumArrearType.NotPresent); if (oge != null) { OpiParameter op = OpiParameter.Service.Get(ID.FromInteger(parameterid)); if (op != null) { oge.FractionofFromTo = GlobalFunctions.GetFraction(oge.EffectDate, (DateTime)oge.TillDate); fractionMonthAmount = op.GetGradeDefinedAmount(employee, oge.BasicSalary, oge.GrossSalary, oge.FractionofFromTo); fractionMonthAmount = fractionMonthAmount * GlobalFunctions.GetFractinalOfMonth(fromDate); dataNotFound = true; } } } if (dataNotFound == false) { fractionMonthAmount = OPIProcess.Service.GetPrevMonthAmount(employee.ID, ID.FromInteger(opiID), GlobalFunctions.FirstDateOfMonth(fromDate), GlobalFunctions.LastDateOfMonth(fromDate)); } if (Global.DateFunctions.FirstDateOfMonth(fromDate) != GlobalFunctions.FirstDateOfMonth(toDate)) // if cross two month { fractionMonthAmount = fractionMonthAmount + OPIProcess.Service.GetPrevMonthAmount(employee.ID, ID.FromInteger(opiID), GlobalFunctions.FirstDateOfMonth(toDate), GlobalFunctions.LastDateOfMonth(toDate)) * GlobalFunctions.GetFractinalOfTillDate(toDate); } return amount = amount + fractionMonthAmount; } public static DataSet GetIDLCOPIRegister(DateTime dOPIMonth, string sEmpID) { DataSet ds = null; try { ds = Service.GetIDLCOPIRegister( dOPIMonth, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetItemWiseOPI(DateTime dFromOPIMonth, int opiItemID, string sEmpID) { DataSet ds = null; try { ds = Service.GetItemWiseOPI(dFromOPIMonth,opiItemID,sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetManagersOPI(DateTime dtFromOPI, DateTime dtToOPI, int opiItemID, string sEmpID) { DataSet ds = null; try { ds = Service.GetManagersOPI(dtFromOPI,dtToOPI, opiItemID, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static DataSet GetOPIRegister(string sOPIItemID, DateTime dOPIMonth, DateTime dOPIMonth2, string sEmpID) { DataSet ds = null; try { ds = Service.GetOPIRegister(sOPIItemID, dOPIMonth, dOPIMonth2, sEmpID); } catch (Exception e) { throw new Exception(e.Message, e); } return ds; } public static OPIProcess Get(DateTime fromdate, ID empiD) { OPIProcess oOPIProcess = null; #region Cache Header oOPIProcess = (OPIProcess)_cache["Get", fromdate, empiD]; if (oOPIProcess != null) return oOPIProcess; #endregion oOPIProcess = OPIProcess.Service.Get(fromdate, empiD); #region Cache Footer _cache.Add(oOPIProcess, "Get", fromdate, empiD); #endregion return oOPIProcess; } public static DateTime? GetLastPaidOPIMonth(int empID) { return OPIProcess.Service.GetLastPaidOPIMonth(empID); } } #endregion #region IOPIProcess Service public interface IOPIProcessService { OPIProcess Get2(ID id, ID payrollTypeID); ObjectsTemplate Get3(ID payrollTypeID); ObjectsTemplate Get4(DateTime dOPIMonth, ID payrollTypeID); ObjectsTemplate GetProcessDetailWithItems(ID opiProcessID, ID payrollTypeID); ObjectsTemplate GetProcessDetails(ID opiProcessID, ID payrollTypeID); ObjectsTemplate GetProcessDetails(DateTime processMonth, ID payrollTypeID); ObjectsTemplate GetProcessDetailItems(ID nProcessDetailID, ID payrollTypeID); OPIProcessDetail GetDetail(ID employeeID, DateTime OpiMonth, ID payrollTypeID); double GetProvisionAmountByEmpID(ID nEmpID); double GetPrevMonthAmount(ID nEmpID, ID nOPIItemID, DateTime dFromOpiMonth, DateTime dToOpiMonth); DataSet GetDataSetOfOPIRegister(string sSearch); DataSet GetOPIRegister(string sOPIItemID, DateTime dOPIMonth, string sEmpID); DataSet GetOPITotalValueRegister(DateTime dFromOpiMonth, DateTime dToOpiMonth, int nOPIItemID, string sEmpID); ID Save(OPIProcess item, ID payrollTypeID); ID UpdateOnlyProcess(OPIProcess oProcess, ID payrollTypeID); void Save(OPIProcess oProcess, ObjectsTemplate oPDetails, ID payrollTypeID); void Delete(ID id, ID payrollTypeID); void Undo(DateTime OpiMonth, ID payrollTypeID); void UpdateDetail(ObjectsTemplate oOPIDetails, ID payrollTypeID); DataSet GetDetailOtherPayrollItems(string sOPIItemID, DateTime dOPIMonth, string sEmpID); ObjectsTemplate GetOPiProcessItems(DateTime dateTime, ID payrollTypeID); ObjectsTemplate GetLastMonthItems(int nEmployeeID, ID payrollTypeID); DataSet GetEmpOPIPaySlip(DateTime _SalaryMonth, string sEmpID); DataSet GetIDLCOPIRegister(DateTime dOPIMonth, string sEmpID); DataSet GetItemWiseOPI(DateTime dFromOPIMonth, int opiItemID, string sEmpID); DataSet GetManagersOPI(DateTime dtFromOPI, DateTime dtToOPI, int opiItemID, string sEmpID); OPIProcess Get(DateTime fromdate, ID empiD); DateTime? GetLastPaidOPIMonth(int empID); DataSet GetOPIRegister(string sOPIItemID, DateTime dOPIMonth, DateTime dOPIMonth2, string sEmpID); } #endregion }