using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.Core; using Ease.Core.Model; using System.Data; namespace HRM.BO { #region OpiParameter public class OpiParameter : BasicBaseObject { #region Constructor public OpiParameter() { this.AvgMonth = 0; this.FlatAmount = 0.0; this.ProvisionAmount = 0.0; this.FromDate = DateTime.Now; this.ToDate = DateTime.Now; this.Gender = EnumGender.None; this.IsEarnedBasic = false; this.IsTaxable = false; this.IsConfirmed = false; this.IsWithException = false; this.IsIAApplicable = false; this.MinAmount = 0.0; this.MaxAmount = 0.0; this.IsFractionate= false; this.OpiParameterGrades = null; this.OpiParameterIndividuals = null; this.OpiPeriodicity = EnumOpiPeriodicity.OnceOff; this.PercentOfBasic = 0.0; this.PercentOfGross = 0.0; this.EntitleType = EnumEntitleType.Grade; this.OpiAvgPayType = EnumOpiAvgPayType.NONE; this.NoOfMonth = 0; this.Status = EnumStatus.Active; //PayrollTypeID = Payroll.BO.SystemInformation.CurrentSysInfo.PayrollTypeID; } #endregion #region Properties public EnumOpiType OpiType { get; set; } public double AmountToDistribute { get; set; } public int AvgMonth { get; set; } public double ProvisionAmount { get; set; } public double FlatAmount { get; set; } public double MinAmount { get; set; } public double MaxAmount { get; set; } public double GFFlatAmount { get; set; } public double GFPercentOfBasic { get; set; } public double GFPercentOfGross { get; set; } public DateTime FromDate { get; set; } public DateTime? ToDate { get; set; } public EnumGender Gender { get; set; } public bool IsActive { get; set; } public bool IsEarnedBasic { get; set; } public bool IsTaxable { get; set; } public bool IsConfirmed { get; set; } public bool IsFractionate { get; set; } public bool IsIAApplicable { get; set; } public bool IsWithException { get; set; } public int OpiItemID { get; set; } public EnumOpiPeriodicity OpiPeriodicity { get; set; } public double PercentOfBasic { get; set; } public double PercentOfGross { get; set; } public EnumEntitleType EntitleType { get; set; } #region isFlatAmount : bool public bool IsFlatAmount { get { if (FlatAmount != 0) { return true; } return false; } } #endregion public EnumOpiAvgPayType OpiAvgPayType { get; set; } public int OpiAvgPayItemID { get; set; } public int NoOfMonth { get; set; } public List OpiParameterGrades { get; set; } //#region OpiParameterGrades : List //private List _opiParameterGrades; //public List OpiParameterGrades //{ // get // { // if (_opiParameterGrades == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _opiParameterGrades = OpiParameter.GetGrades(this.ID); // } // return this._opiParameterGrades; // } // set // { // _opiParameterGrades = value; // } //} //#endregion public List OpiParameterIndividuals { get; set; } //#region OpiParameterIndividuals : List //private List _opiParameterIndividuals; //public List OpiParameterIndividuals //{ // get // { // if (_opiParameterIndividuals == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _opiParameterIndividuals = OpiParameterIndividual.GetByParameterID(this.ID); // } // else if (_opiParameterIndividuals == null) // { // _opiParameterIndividuals = new List(); // } // return this._opiParameterIndividuals; // } // set // { // _opiParameterIndividuals = value; // } //} //#endregion public OpiItem OpiItem { get; set; } //#region OpiItem : OpiItem //private OpiItem _opiItem; //public OpiItem OpiItem //{ // get // { // if (_opiItemID.Integer > 0 && _opiItem == null) // { // _opiItem = new OpiItem(); // _opiItem = OpiItem.Get(_opiItemID); // } // return this._opiItem; // } // set // { // _opiItem = value; // } //} //#endregion //#region NoOfAplicableEmp : int //private int _noOfemployee; //public int NoOfAplicableEmp //{ // get // { // if (_noOfemployee <= 0) // { // string gradeIDs = string.Empty; // foreach (OpiParameterGrade pGrade in this.OpiParameterGrades) // { // if (gradeIDs != string.Empty) // gradeIDs += "," + pGrade.GradeId.ToString(); // else // gradeIDs += pGrade.GradeId.ToString(); // } // SearchManager om = new SearchManager(EnumSearchFrom.Employee); // om.Parameter.Add(EnumSearchParameter.GradeID, EnumSQLOperator.In, EnumSearchObjDataType.String, gradeIDs); // om.Parameter.Add(EnumSearchParameter.Status, (int)EnumEmployeeStatus.Live); // //confirmed is selected // om.Parameter.Add(EnumSearchParameter.Confirm, true); // //if gender is selected // om.Parameter.Add(EnumSearchParameter.Gender, (int)EnumGender.Male); // List emps = om.Find(); // _noOfemployee = emps.Count; // } // return _noOfemployee; // } //} //#endregion #endregion //#region Functions //private int ApplicableEmp() //{ // int nApplEmp = 0; // //if (this.EntitleType == EnumEntitleType.Grade) // //{ // //} // return nApplEmp; //} //public OpiParameter Get(ID nOpiParameterID) //{ // OpiParameter oOpiParameter = null; // #region Cache Header // oOpiParameter = (OpiParameter)_cache["Get", nOpiParameterID]; // if (oOpiParameter != null) // return oOpiParameter; // #endregion // oOpiParameter = OpiParameter.Service.Get(nOpiParameterID,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // #region Cache Footer // _cache.Add(oOpiParameter, "Get", nOpiParameterID); // #endregion // return oOpiParameter; //} //public static List Get() //{ // #region Cache Header // List OpiParameters = _cache["Get"] as List; // if (OpiParameters != null) // return OpiParameters; // #endregion // try // { // OpiParameters = Service.Get(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(OpiParameters, "Get"); // #endregion // return OpiParameters; //} //public static List GetGrades(ID opiParameterID) //{ // #region Cache Header // List oGrades = _cache["Get", opiParameterID] as List; // if (oGrades != null) // return oGrades; // #endregion // try // { // oGrades = Service.GetGrades(opiParameterID,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(oGrades, "Get", opiParameterID); // #endregion // return oGrades; //} //public static List Get(EnumStatus status) //{ // #region Cache Header // List opiParameters = _cache["Get", status] as List; // if (opiParameters != null) // return opiParameters; // #endregion // try // { // opiParameters = Service.Get(status,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(opiParameters, "Get", status); // #endregion // return opiParameters; //} //public static List Get(EnumStatus status, EnumOpiType type) //{ // #region Cache Header // List opiParameters = _cache["Get", status, type] as List; // if (opiParameters != null) // return opiParameters; // #endregion // try // { // opiParameters = Service.Get(status, type,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(opiParameters, "Get", status, type); // #endregion // return opiParameters; //} //public ID Save() //{ // this.SetAuditTrailProperties(); // return OpiParameter.Service.Save(this); //} //public void Delete() //{ // OpiParameter.Service.Delete(this.ID,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); //} //#region Exception : ADParameterEmployee //private List _Exception = null; public List Exception { get; set; } //{ // get // { // if (_Exception == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _Exception = OpiParameterIndividual.GetIndividuals(this.ID, EnumOPIIndivdualType.Exception); // } // return this._Exception; // } //} //#endregion //#region NotApplicable : ADParameterEmployee //private List _NotApplicable = null; public List NotApplicable { get; set; } //{ // get // { // if (_NotApplicable == null && !this.ID.IsUnassigned && this.ID.Integer > 0) // { // _NotApplicable = OpiParameterIndividual.GetIndividuals(this.ID, EnumOPIIndivdualType.NotApplicable); // } // return this._NotApplicable; // } //} //#endregion //public static List GetApplicableParameters(Employee employee, // ID graId, List parameters) //{ // List applicableParams = parameters.FindAll(delegate(OpiParameter param) { return IsApplicable(param, graId, employee); }); // return applicableParams; //} //private static bool IsApplicable(OpiParameter param, ID graid, Employee employee) //{ // bool isApplicable = false; // foreach (OpiParameterGrade adgrade in param.OpiParameterGrades) // { // if (adgrade.GradeId.Integer == graid.Integer) // { // isApplicable = true; // } // } // if (!isApplicable) return false; // if (param.Gender != EnumGender.None // && param.Gender != employee.Gender) // { // return false; // } // //if (param.IsForConfirmOnly && !employee.IsConfirmed) // //{ // // return false; // //} // return true; //} ///// ///// ///// ///// ///// ///// ///// //public double GetGradeDefinedAmount(Employee employee, List gradeSalarires) //{ // double nAmount = 0; // foreach (EmployeeGradeSalary item in gradeSalarires) // { // nAmount = nAmount + this.GetGradeDefinedAmount(employee, item.BasicSalary, item.GrossSalary, item.FractionofFromTo); // } // return nAmount; //} //public double GetGradeDefinedAmount(Employee employee, EmployeeGradeSalary gradeSalary) //{ // return this.GetGradeDefinedAmount(employee, gradeSalary.BasicSalary, gradeSalary.GrossSalary, gradeSalary.FractionofFromTo); //} //public double GetGradeDefinedAmount(Employee employee, double basicSalary, // double grossSalary, double fractionate) //{ // OpiParameterIndividual opiIndividual = null; // double nAmount = 0.0; // switch (this.EntitleType) // { // case EnumEntitleType.Grade: // if (this.PercentOfBasic + this.GFPercentOfBasic+this.FlatAmount+this.GFFlatAmount > 0) // { // // if (this.PercentOfBasic > 0) // // //nAmount = basicSalary * this.PercentOfBasic / 100.0 + this.FlatAmount; // // if(this.IsFractionate) // // nAmount = nAmount + this.FlatAmount * fractionate + (basicSalary * this.PercentOfBasic * fractionate) / 100.0; // // else // // nAmount = nAmount + ((basicSalary * this.PercentOfBasic / 100.0) * fractionate); // //else if (this.PercentOfGross > 0) // // //nAmount = grossSalary * this.PercentOfGross / 100.0 + this.FlatAmount; // // if (this.IsFractionate) // // nAmount = nAmount + this.FlatAmount * fractionate + (basicSalary * this.PercentOfBasic * fractionate) / 100.0; // // else // // nAmount = nAmount + ((basicSalary * this.PercentOfBasic / 100.0) * fractionate); // //else // // nAmount = this.FlatAmount * fractionate; // if (this.IsFractionate) // { // if (employee.GrandFather != null) // { // if (employee.GrandFather.OPI) // { // nAmount = nAmount+this.GFFlatAmount + this.GFFlatAmount * fractionate + (basicSalary * this.GFPercentOfBasic * fractionate) / 100.0; // } // else // { // nAmount = nAmount+ this.FlatAmount * fractionate + (basicSalary * this.PercentOfBasic * fractionate) / 100.0; // } // } // else // { // nAmount = nAmount + this.FlatAmount * fractionate + (basicSalary * this.PercentOfBasic * fractionate) / 100.0; // } // } // else // { // if (employee.GrandFather != null) // { // if (employee.GrandFather.OPI) // { // nAmount = nAmount + this.GFFlatAmount + ((basicSalary * this.GFPercentOfBasic / 100.0) * fractionate); // } // else // { // nAmount = nAmount + this.FlatAmount + ((basicSalary * this.PercentOfBasic / 100.0) * fractionate); // } // } // else // { // nAmount = nAmount+ this.FlatAmount + ((basicSalary * this.PercentOfBasic / 100.0) * fractionate); // } // } // } // else if (this.PercentOfGross+this.GFPercentOfGross > 0) // //nAmount = grossSalary * this.PercentOfGross / 100.0 + this.FlatAmount; // if (this.IsFractionate) // { // if (employee.GrandFather != null) // { // if (employee.GrandFather.OPI) // { // nAmount = nAmount + this.GFFlatAmount * fractionate + (basicSalary * this.GFPercentOfBasic * fractionate) / 100.0; // } // else // { // nAmount = nAmount + this.FlatAmount * fractionate + (basicSalary * this.PercentOfBasic * fractionate) / 100.0; // } // } // else // { // nAmount = nAmount + this.FlatAmount * fractionate + (basicSalary * this.PercentOfBasic * fractionate) / 100.0; // } // } // else // { // if (employee.GrandFather != null) // { // if (employee.GrandFather.OPI) // { // nAmount = nAmount + ((basicSalary * this.GFPercentOfBasic / 100.0) * fractionate); // } // else // { // nAmount = nAmount + ((basicSalary * this.PercentOfBasic / 100.0) * fractionate); // } // } // else // { // nAmount = nAmount + ((basicSalary * this.PercentOfBasic / 100.0) * fractionate); // } // } // else // { // if (employee.GrandFather != null) // { // if (employee.GrandFather.OPI) // { // nAmount = this.GFFlatAmount * fractionate; // } // else // { // nAmount = this.FlatAmount * fractionate; // } // } // else // { // nAmount = this.FlatAmount * fractionate; // } // } // if (this.NotApplicable.Exists(delegate(OpiParameterIndividual adEmployee) { return adEmployee.EmployeeId.Integer == employee.ID.Integer; })) // { // nAmount = 0; // } // else // { // OpiParameterIndividual adEmp = this.Exception.Find(delegate(OpiParameterIndividual adEmployee) { return adEmployee.EmployeeId.Integer == employee.ID.Integer; }); // if (adEmp != null) // { // switch (adEmp.ValueType) // { // case EnumValueType.Amount: // nAmount = adEmp.Value; // break; // case EnumValueType.Other: // if (this.PercentOfBasic > 0) // nAmount = basicSalary * adEmp.Value / 100.0 * fractionate; //+ this.FlatAmount; // // nAmount = basicSalary * adEmp.Value / 100.0 + this.FlatAmount; // else if (this.PercentOfGross > 0) // { // nAmount = grossSalary * adEmp.Value / 100.0 * fractionate; //+ this.FlatAmount; // //nAmount = grossSalary * adEmp.Value / 100.0 + this.FlatAmount; // } // break; // } // } // } // //if (this.IsFlatAmount == true) nAmount = PayrollPayrollGlobalFunctions.Round(nAmount * fractionate); // //nAmount = PayrollPayrollGlobalFunctions.Round(nAmount * fractionate); // break; // case EnumEntitleType.Individual: // throw new ServiceException("You have choosed the wrong overloaded function to calculate" // + " Individual Allowance"); // } // if (this.MinAmount != 0 || this.MaxAmount != 0) // { // if (nAmount < this.MinAmount) // { // nAmount = this.MinAmount; // } // if (nAmount > this.MaxAmount) // { // nAmount = this.MaxAmount; // } // } // return nAmount; //} //public double GetIndividualAmount(Employee employee, DateTime fortheMonth, // OpiParameterIndividual ademployee) //{ // return GetIndividualAmount(employee, fortheMonth, // ademployee, employee.BasicSalary, employee.GrossSalary); //} //public double GetAmount(Employee oEmp) //{ // OpiParameterIndividual adEmp = null; // double nAmount = 0.0; // switch (this.EntitleType) // { // case EnumEntitleType.Grade: // if (this.PercentOfBasic > 0) // nAmount = oEmp.BasicSalary * this.PercentOfBasic / 100.0 + this.FlatAmount; // else if (this.PercentOfGross > 0) // nAmount = oEmp.GrossSalary * this.PercentOfBasic / 100.0 + this.FlatAmount; // else // nAmount = this.FlatAmount; // break; // case EnumEntitleType.Individual: // adEmp = OpiParameterIndividual.Service.Get(oEmp.ID, this.OpiItemID, this.ID); // if (adEmp != null) // nAmount = adEmp.Value; // else // { // if (this.PercentOfBasic > 0) // nAmount = oEmp.BasicSalary * this.PercentOfBasic / 100.0 + this.FlatAmount; // else if (this.PercentOfGross > 0) // nAmount = oEmp.GrossSalary * this.PercentOfBasic / 100.0 + this.FlatAmount; // else // nAmount = this.FlatAmount; // } // break; // } // if (this.MinAmount != 0 || this.MaxAmount != 0) // { // if (nAmount < this.MinAmount) // { // nAmount = this.MinAmount; // } // if (nAmount > this.MaxAmount) // { // nAmount = this.MaxAmount; // } // } // return nAmount; //} //public double GetIndividualAmount(Employee employee, DateTime fortheMonth, // OpiParameterIndividual ademployee, double basicSalary, double grossSalary) //{ // double nAmount = 0.0; // switch (this.EntitleType) // { // case EnumEntitleType.Grade: // throw new ServiceException("You have choosed the wrong overloaded function to calculate" // + " Grade defined Allowance"); // case EnumEntitleType.Individual: // if (ademployee.ArrearType == EnumArrearType.NotPresent) // { // DateTime fromDate = PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(SystemInformation.CurrentSysInfo.NextPayProcessDate); // DateTime toDate = SystemInformation.CurrentSysInfo.NextPayProcessDate; // if (ademployee.FromDate < PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(fortheMonth)) // fromDate = PayrollPayrollGlobalFunctions.PayrollFirstDateOfMonth(fortheMonth); // else fromDate=ademployee.FromDate; // if (ademployee.ToDate == null || ademployee.ToDate == DateTime.MinValue) // toDate = PayrollPayrollGlobalFunctions.PayrollLastDateOfMonth(fortheMonth); // else toDate = (DateTime)ademployee.ToDate ; // if (toDate > PayrollPayrollGlobalFunctions.PayrollLastDateOfMonth(fortheMonth)) // toDate = PayrollPayrollGlobalFunctions.PayrollLastDateOfMonth(fortheMonth); // if (ademployee.OpiPeriodicity != EnumOpiPeriodicity.OnceOff) // if (employee.EndOfContractDate != null || employee.EndOfContractDate != DateTime.MinValue) // if (employee.EndOfContractDate < toDate) // toDate = (DateTime)employee.EndOfContractDate; // if (ademployee.ValueType == EnumValueType.Other) // { // //while percent of basic then not required to do fractionate of date basis // //if(this.PercentOfBasic >0) // // nAmount = (basicSalary * ademployee.MonthlyAmount)/100 * PayrollPayrollGlobalFunctions.GetFraction(fromDate, toDate); // //else if (this.PercentOfGross>0) // // nAmount = (grossSalary * ademployee.MonthlyAmount)/100 * PayrollPayrollGlobalFunctions.GetFraction(fromDate, toDate); // if (this.PercentOfBasic > 0) // nAmount = (basicSalary * ademployee.Value) / 100 * PayrollPayrollGlobalFunctions.GetFraction(fromDate, toDate); // else if (this.PercentOfGross > 0) // nAmount = (grossSalary * ademployee.Value) / 100 * PayrollPayrollGlobalFunctions.GetFraction(fromDate, toDate); // } // else nAmount = ademployee.Value * PayrollPayrollGlobalFunctions.GetFraction(fromDate, toDate);//PayrollPayrollGlobalFunctions.GetFraction(fromDate, toDate); // } // else if (ademployee.ArrearType == EnumArrearType.ToCalculate) // { // if (ademployee.ValueType == EnumValueType.Other) // { // if (this.PercentOfBasic > 0) // nAmount = (basicSalary * ademployee.Value) / 100 * PayrollPayrollGlobalFunctions.GetFraction(ademployee.FromDate , (DateTime)ademployee.ToDate ); // else if (this.PercentOfGross > 0) // nAmount = (grossSalary * ademployee.Value) / 100 * PayrollPayrollGlobalFunctions.GetFraction(ademployee.FromDate , (DateTime)ademployee.ToDate ); // } // else nAmount = ademployee.Value * // PayrollPayrollGlobalFunctions.GetFraction(ademployee.FromDate , (DateTime)ademployee.ToDate); // } // break; // } // return nAmount; //} //public List ApplicableParameters(Employee emlpoyee, // OPIProcessDetail oprocdetail, List allOpiParameters, // List gradeSalaries) //{ // List oparameters = new List(); // foreach (EmployeeGradeSalary gs in gradeSalaries) // { // List lparameter = OpiParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allOpiParameters); // foreach (OpiParameter item in lparameter) // { // if (oparameters.Contains(item) == false) // oparameters.Add(item); // } // } // return oparameters; // //foreach (EmployeeGradeSalary gs in oprocdetail.ArrearGradeSalaries) // //{ // // List alparameter = OpiParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allOpiParameters); // // gs.OpiParameters = new List(); // // foreach (OpiParameter item in alparameter) // // gs.OpiParameters.Add(item); // //} // //foreach (EmployeeGradeSalary gs in oprocdetail.ArrearPaidGradeSalaries) // //{ // // List aplparameter = OpiParameter.GetApplicableParameters(emlpoyee, gs.GradeID, allOpiParameters); // // gs.OpiParameters = new List(); // // foreach (OpiParameter item in aplparameter) // // gs.OpiParameters.Add(item); // //} //} //public static List GetGrades() //{ // return OpiParameter.Service.GetGrades(SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); //} //internal static List Get(EnumStatus enumStatus, EnumOpiType enumOpiType, EnumEntitleType enumEntitleType) //{ // #region Cache Header // List opiitems = _cache["Get", enumStatus, enumOpiType, enumEntitleType] as List; // if (opiitems != null) // return opiitems; // #endregion // try // { // opiitems = Service.Get(enumStatus, enumOpiType, enumEntitleType,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(opiitems, "Get", enumStatus, enumOpiType, enumEntitleType); // #endregion // return opiitems; //} //internal static List Get(EnumStatus enumStatus,EnumEntitleType enumEntitleType) //{ // #region Cache Header // List opiitems = _cache["Get", enumStatus, enumEntitleType] as List; // if (opiitems != null) // return opiitems; // #endregion // try // { // opiitems = Service.Get(enumStatus, enumEntitleType,SystemInformation.CurrentSysInfo.PayrollTypeID.Integer); // } // catch (ServiceException e) // { // throw new Exception(e.Message, e); // } // #region Cache Footer // _cache.Add(opiitems, "Get", enumStatus, enumEntitleType); // #endregion // return opiitems; //} //#endregion //#region Service Factory //internal static IOpiParameterService Service //{ // get // { // return Services.Factory.CreateService(typeof(IOpiParameterService)); // } //} //#endregion public int PayrollTypeID { get; set; } } #endregion #region IOpiParameter Service public interface IOpiParameterService { OpiParameter Get(int id, int payrollTypeID); List Get(int payrollTypeID); List GetGrades(int opiParameterID, int payrollTypeID); List GetGrades(int payrollTypeID); List Get(EnumStatus status, int payrollTypeID); List Get(EnumStatus status, EnumOpiType type, int payrollTypeID); List Get(EnumStatus enumStatus, EnumOpiType enumOpiType, EnumEntitleType enumEntitleType, int payrollTypeID); List Get(EnumStatus enumStatus, EnumEntitleType enumEntitleType, int payrollTypeID); List GetUsedGrades(int opiItemID); int Save(OpiParameter oOpiParameter); void ChangeStatus(int id, EnumStatus enumStatus); void Delete(int id); } #endregion }