using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ease.CoreV35.Model; namespace Payroll.BO { [Serializable] public class GrossDefination : AuditTrailBase { public GrossDefination() { _salaryComponentType = EnumSalaryComponent.Basic; _componentID = null; } #region Property SalaryComponentType : int private EnumSalaryComponent _salaryComponentType; public EnumSalaryComponent SalaryComponentType { get { return _salaryComponentType; } set { base.OnPropertyChange("SalaryComponentType", (short)_salaryComponentType, (short)value); _salaryComponentType = value; } } #endregion Property SalaryComponentType : int #region Property BenefitDefinationType : int private EnumBenefitDefinationType _benefitDefinationType; public EnumBenefitDefinationType BenefitDefinationType { get { return _benefitDefinationType; } set { base.OnPropertyChange("BenefitDefinationType", (short)_benefitDefinationType, (short)value); _benefitDefinationType = value; } } #endregion Property BenefitDefinationType : int #region Property ComponentID : ID private ID _componentID; public ID ComponentID { get { return _componentID; } set { base.OnPropertyChange("ComponentID", _componentID, value); _componentID = value; } } #endregion Property ComponentID : ID #region Property Quantity : int private int _quantity; public int Quantity { get { return _quantity; } set { base.OnPropertyChange("Quantity", (short)_quantity, (int)value); _quantity = value; } } #endregion Property Quantity : int #region Property Description : string private string _description; public string Description { get { return _description; } set { base.OnPropertyChange("Description", _description, (string)value); _description = value; } } #endregion Property Quantity : int #region Service Factory IGrossDefinationService : IGrossDefinationService internal static IGrossDefinationService Service { get { return Services.Factory.CreateService(typeof(IGrossDefinationService)); } } #endregion Service Factory IGrossDefinationService : IGrossDefinationService #region Save Methods public void Save() { try { GrossDefination.Service.Save(this); } catch (Exception e) { if (e.InnerException == null) { throw new Exception(e.Message); } else { throw new Exception(e.Message, e.InnerException); } } } #endregion Save Methods #region Get Methods public GrossDefination Get(ID id) { GrossDefination grossDefination = new GrossDefination(); try { grossDefination = GrossDefination.Service.Get(id); } catch (Exception e) { if (e.InnerException == null) { throw new Exception(e.Message); } else { throw new Exception(e.Message, e.InnerException); } } return grossDefination; } public static ObjectsTemplate Get() { ObjectsTemplate grossDefinationColl = new ObjectsTemplate(); try { grossDefinationColl = GrossDefination.Service.Get(); } catch (Exception e) { if (e.InnerException == null) { throw new Exception(e.Message); } else { throw new Exception(e.Message, e.InnerException); } } return grossDefinationColl; } public static ObjectsTemplate Get(EnumBenefitDefinationType definationType) { ObjectsTemplate grossDefinationColl = new ObjectsTemplate(); try { grossDefinationColl = GrossDefination.Service.Get(definationType); } catch (Exception e) { if (e.InnerException == null) { throw new Exception(e.Message); } else { throw new Exception(e.Message, e.InnerException); } } return grossDefinationColl; } #endregion Get Methods #region Delete Methods public void Delete(ID id) { GrossDefination.Service.Delete(id); } #endregion Delete Methods /// /// Return the gross amount of the employee /// /// /// public double GetGross(Employee oemployee) { ObjectsTemplate grossDefinations = GrossDefination.Get(); ObjectsTemplate adparamters = ADParameter.Get(EnumStatus.Regardless, EnumAllowOrDeduct.Allowance); ObjectsTemplate bonusParamters = BonusParameter.Get(EnumStatus.Regardless); ObjectsTemplate bonuses = Bonus.Get(EnumStatus.Regardless); double GrossAmount = 0; foreach (GrossDefination gd in grossDefinations) { switch (gd.SalaryComponentType) { case EnumSalaryComponent.Basic: // basic salary is monthly, so we are multipliying by 12 GrossAmount = GrossAmount + oemployee.BasicSalary * 12; break; case EnumSalaryComponent.Allowance: ADParameter param = ADParameter.GetApplicableParameter( oemployee, oemployee.GradeID, adparamters, gd.ComponentID); if (param == null) continue; switch (param.Periodicity) { case EnumPeriodicity.Monthly: // Allowance is monthly, so we are multipliying by 12 GrossAmount = GrossAmount + param.CalculateAmount(oemployee) * 12; break; case EnumPeriodicity.OneOff: // allowance is onceoff and paid once in year GrossAmount = GrossAmount + param.CalculateAmount(oemployee); break; case EnumPeriodicity.RegardLess: case EnumPeriodicity.Schedule: case EnumPeriodicity.Periodic: break; default: break; } break; case EnumSalaryComponent.Bonus: // annual bonus , so we are not multipling 12 BonusParameter bparamter = BonusParameter.ApplicableParameters(bonusParamters, oemployee, gd.ComponentID); if (bparamter != null) { BonusCalculator ocal = new BonusCalculator(); GrossAmount = GrossAmount + 3 * oemployee.BasicSalary; //ocal.GeneralAmount(odetail.Employee, bparamter, opiMonth); } break; default: break; } } return GrossAmount; } /// /// Return the gross amount of the multiple employees /// /// /// public Dictionary GetGross(ObjectsTemplate oemployees) { ObjectsTemplate grossDefinations = GrossDefination.Get(); ObjectsTemplate adparamters = ADParameter.Get(EnumStatus.Regardless, EnumAllowOrDeduct.Allowance); ObjectsTemplate bonusParamters = BonusParameter.Get(EnumStatus.Regardless); ObjectsTemplate bonuses = Bonus.Get(EnumStatus.Regardless); double GrossAmount = 0; Dictionary empGross = new Dictionary(); foreach (Employee oemployee in oemployees) { GrossAmount = 0; foreach (GrossDefination gd in grossDefinations) { #region switch case switch (gd.SalaryComponentType) { case EnumSalaryComponent.Basic: // basic salary is monthly, so we are multipliying by 12 GrossAmount = GrossAmount + oemployee.BasicSalary * 12; break; case EnumSalaryComponent.Allowance: ADParameter param = ADParameter.GetApplicableParameter( oemployee, oemployee.GradeID, adparamters, gd.ComponentID); if (param == null) continue; switch (param.Periodicity) { case EnumPeriodicity.Monthly: // Allowance is monthly, so we are multipliying by 12 GrossAmount = GrossAmount + param.CalculateAmount(oemployee) * 12; break; case EnumPeriodicity.OneOff: // allowance is onceoff and paid once in year, so we are multipliying by 12 GrossAmount = GrossAmount + param.CalculateAmount(oemployee); break; case EnumPeriodicity.RegardLess: case EnumPeriodicity.Schedule: case EnumPeriodicity.Periodic: break; default: break; } break; case EnumSalaryComponent.Bonus: // annual bonus , so we are not multipling 12 BonusParameter bparamter = BonusParameter.ApplicableParameters(bonusParamters, oemployee, gd.ComponentID); if (bparamter != null) { BonusCalculator ocal = new BonusCalculator(); GrossAmount = GrossAmount + 3 * oemployee.BasicSalary; //ocal.GeneralAmount(odetail.Employee, bparamter, opiMonth); } break; default: break; } #endregion switch case } empGross.Add(oemployee.ID.Integer, GrossAmount); } return empGross; } } public interface IGrossDefinationService { GrossDefination Get(ID id); ObjectsTemplate Get(); ObjectsTemplate Get(EnumBenefitDefinationType definationType); void Save(GrossDefination grossDefination); void Delete(ID id); } }