public Sal_UnusualAllowanceModel Post([Bind]Sal_UnusualAllowanceModel model) { var hrService = new Hre_ProfileServices(); var UnusualAllowanceServices = new Sal_UnusualAllowanceServices(); string status = string.Empty; #region Validate string message = string.Empty; var checkValidate = false; //kiểm tra xem có phải là đang create ở trang chi tiết nv ko if (model.IsGeneralProfile != null && model.IsGeneralProfile == true) { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDGeneralProfile", ref message); if (!checkValidate) { model.ActionStatus = message; return model; } ActionService service = new ActionService(UserLogin); return service.UpdateOrCreate<Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model); } else { if (!string.IsNullOrEmpty(model.OrgStructureIDs)) { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDOrg", ref message); } else { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualED", ref message); } if (!checkValidate) { model.ActionStatus = message; return model; } if (!string.IsNullOrEmpty(model.OrgStructureIDs)) { List<Guid> listGuid = new List<Guid>(); if (model.ProfileIDExclusion != null) { var listStr = model.ProfileIDExclusion.Split(','); if (listStr[0] != "") { foreach (var item in listStr) { listGuid.Add(Guid.Parse(item)); } } } List<object> listObj = new List<object>(); listObj.Add(model.OrgStructureID); listObj.Add(string.Empty); listObj.Add(string.Empty); var lstProfile = hrService.GetData<Hre_ProfileIdEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).Select(s => s.ID).ToList(); if (listGuid != null) { lstProfile = lstProfile.Where(s => !listGuid.Contains(s)).ToList(); } List<Sal_UnusualAllowanceEntity> lstUnusualAllowance = new List<Sal_UnusualAllowanceEntity>(); foreach (var i in lstProfile) { Sal_UnusualAllowanceEntity item = new Sal_UnusualAllowanceEntity(); item = model.Copy<Sal_UnusualAllowanceEntity>(); item.ProfileID = i; lstUnusualAllowance.Add(item); } model.ActionStatus = UnusualAllowanceServices.Add(lstUnusualAllowance); return model; } else { string[] listProfile = model.ProfileIDs.Split(','); List<Sal_UnusualAllowanceEntity> lstUnusualAllowance = new List<Sal_UnusualAllowanceEntity>(); foreach (var i in listProfile) { Sal_UnusualAllowanceEntity item = new Sal_UnusualAllowanceEntity(); item = model.Copy<Sal_UnusualAllowanceEntity>(); item.ProfileID = Guid.Parse(i); lstUnusualAllowance.Add(item); } model.ActionStatus = UnusualAllowanceServices.Add(lstUnusualAllowance); return model; } } #endregion }
public DataTable GetReportEvalutionData(int year, Guid? _TimesGetDataID, string orgStructureID, bool _IsCreateTemplate, DateTime? _dateStart, DateTime? _dateEnd, DateTime? _dateFrom, DateTime? _dateTo, Guid? _JobTitleID, Guid? _PositionID, Guid? _WorkPlaceID, Guid? _RankID,string userLogin) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); DataTable table = CreateReportEvalutionSchema(_dateFrom, _dateTo, userLogin); if (_IsCreateTemplate) return table; string status = string.Empty; List<Eva_EvalutionDataEntity> lstEvalutionDataEntity = new List<Eva_EvalutionDataEntity>(); DateTime _datetime = new DateTime(year, 01, 01); //Ngay goc DateTime datetimeNode = _dateEnd.Value; List<object> paraEvalutionData = new List<object>(); paraEvalutionData.AddRange(new object[17]); paraEvalutionData[0] = orgStructureID; paraEvalutionData[1] = year; paraEvalutionData[2] = _datetime; //paraEvalutionData[3] = time; paraEvalutionData[10] = _TimesGetDataID; paraEvalutionData[11] = _JobTitleID; paraEvalutionData[12] = _PositionID; paraEvalutionData[13] = _WorkPlaceID; paraEvalutionData[14] = _RankID; paraEvalutionData[15] = 1; paraEvalutionData[16] = int.MaxValue - 1; var evaServiceEvalutionData = new Eva_EvalutionDataServices(); //chi danh gia nhung nv ngay vao lam <= ngay goc var lstEvalutionData = evaServiceEvalutionData.GetData<Eva_EvalutionDataEntity>(paraEvalutionData, ConstantSql.hrm_eva_getdata_EvalutionData, userLogin, ref status); Guid[] lstSalaryClassIDs = null; Guid[] lstProfielIds = null; if (lstEvalutionData != null) { lstSalaryClassIDs = lstEvalutionData.Where(s => s.SalaryClassID != null).Select(s => s.SalaryClassID.Value).Distinct().ToArray(); lstProfielIds = lstEvalutionData.Where(s => s.ProfileID != null).Select(s => s.ProfileID.Value).Distinct().ToArray(); } #region luong co ban List<object> paraBasicSalary = new List<object>(); paraBasicSalary.AddRange(new object[10]); DateTime _dateMin = DateTime.MinValue; paraBasicSalary[2] = orgStructureID; paraBasicSalary[3] = _dateMin; paraBasicSalary[4] = datetimeNode; paraBasicSalary[5] = _dateMin; paraBasicSalary[6] = datetimeNode; paraBasicSalary[8] = 1; paraBasicSalary[9] = int.MaxValue - 1; var salServiceBasicSalary = new Sal_BasicSalaryServices(); var lstBasicSalary = salServiceBasicSalary.GetData<Sal_BasicSalaryEntity>(paraBasicSalary, ConstantSql.hrm_sal_sp_get_BasicPayroll, userLogin, ref status); if (lstBasicSalary != null && lstProfielIds != null) lstBasicSalary = lstBasicSalary.Where(s => lstProfielIds.Contains(s.ProfileID)).ToList(); List<object> paraSalaryRank = new List<object>(); paraSalaryRank.AddRange(new object[4]); paraSalaryRank[2] = 1; paraSalaryRank[3] = int.MaxValue; var catServiceSalaryRank = new Cat_SalaryRankServices(); var lstSalaryRank = catServiceSalaryRank.GetData<Cat_SalaryRankEntity>(paraSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, userLogin, ref status); if (lstSalaryRank != null && lstSalaryClassIDs != null) lstSalaryRank = lstSalaryRank.Where(s => s.DateOfEffect <= datetimeNode && lstSalaryClassIDs.Contains(s.SalaryClassID.Value)).ToList(); #endregion #region phu cap List<object> paraUnusualAllowance = new List<object>(); paraUnusualAllowance.AddRange(new object[9]); paraBasicSalary[3] = _dateMin; paraBasicSalary[4] = datetimeNode; paraUnusualAllowance[7] = 1; paraUnusualAllowance[8] = int.MaxValue - 1; var salServiceUnusualAllowance = new Sal_UnusualAllowanceServices(); var lstUnusualAllowance = salServiceUnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(paraUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualED, userLogin, ref status); List<Guid> lstUnusualAllowanceIDs = null; if (lstUnusualAllowance != null) { //lstUnusualAllowance = lstUnusualAllowance.Where(s => s.MonthEnd <= datetimeNode || (s.MonthStart <= datetimeNode && s.MonthEnd == null)).ToList(); lstUnusualAllowanceIDs = lstUnusualAllowance.Where(s => s.UnusualEDTypeID != null).Select(s => s.UnusualEDTypeID.Value).Distinct().ToList(); } #endregion #region loai phu cap List<object> paraUnusualAllowanceCfg = new List<object>(); paraUnusualAllowanceCfg.AddRange(new object[6]); paraUnusualAllowanceCfg[4] = 1; paraUnusualAllowanceCfg[5] = int.MaxValue - 1; var catServiceUnusualAllowanceCfg = new Cat_UnusualAllowanceCfgServices(); var lstUnusualAllowanceCfg = catServiceUnusualAllowanceCfg.GetData<Cat_UnusualAllowanceCfgEntity>(paraUnusualAllowanceCfg, ConstantSql.hrm_cat_sp_get_UnusualAllowanceCfg, userLogin, ref status); if (lstUnusualAllowanceCfg != null && lstUnusualAllowanceIDs != null) lstUnusualAllowanceCfg = lstUnusualAllowanceCfg.Where(s => lstUnusualAllowanceIDs.Contains(s.ID)).ToList(); #endregion #region lay lich su danh gia List<Eva_PerformanceEntity> lstPerformance = null; int _yearFrom = DateTime.MinValue.Year; int _yearTo = DateTime.MinValue.Year; if (_dateFrom != null && _dateTo != null) { _yearFrom = _dateFrom.Value.Year; _yearTo = _dateTo.Value.Year; var evaServicePerformance = new Eva_PerformanceServices(); List<object> paraPerformance = new List<object>(); paraPerformance.AddRange(new object[20]); paraPerformance[2] = orgStructureID; paraPerformance[18] = 1; paraPerformance[19] = int.MaxValue - 1; lstPerformance = evaServicePerformance.GetData<Eva_PerformanceEntity>(paraPerformance, ConstantSql.hrm_eva_sp_get_PerformanceGeneral, userLogin, ref status); if (lstPerformance != null) lstPerformance = lstPerformance.Where(s => s.YearEvaluation != null).ToList(); if (lstPerformance.Count != 0) lstPerformance = lstPerformance.Where(s => s.YearEvaluation.Value.Year >= _yearFrom && s.YearEvaluation.Value.Year <= _yearTo).ToList(); } #endregion DateTime dateFirstKi = _dateStart.Value; foreach (var item in lstEvalutionData) { DataRow row = table.NewRow(); #region thong tin nhan vien row[Eva_ReportEvalutionDataEntity.FieldNames.CodeEmp] = item.CodeEmp; row[Eva_ReportEvalutionDataEntity.FieldNames.ProfileName] = item.ProfileName; row[Eva_ReportEvalutionDataEntity.FieldNames.E_DEPARTMENT] = item.E_DEPARTMENT; row[Eva_ReportEvalutionDataEntity.FieldNames.E_DIVISION] = item.E_DIVISION; row[Eva_ReportEvalutionDataEntity.FieldNames.E_SECTION] = item.E_SECTION; row[Eva_ReportEvalutionDataEntity.FieldNames.E_TEAM] = item.E_TEAM; row[Eva_ReportEvalutionDataEntity.FieldNames.E_UNIT] = item.E_UNIT; row[Eva_ReportEvalutionDataEntity.FieldNames.GroupCode] = item.CostCentreCode; row[Eva_ReportEvalutionDataEntity.FieldNames.LocationByGroupCode] = item.WorkPlaceCode; row[Eva_ReportEvalutionDataEntity.FieldNames.ReportEvalutionDataNode] = datetimeNode; #endregion #region tham nien if (item.DateOfBirth != null) row[Eva_ReportEvalutionDataEntity.FieldNames.Age] = DateTime.Today.Year - item.DateOfBirth.Value.Year; if (item.DateHire != null) { row[Eva_ReportEvalutionDataEntity.FieldNames.Entering] = item.DateHire; double dayServiceYear; dayServiceYear = datetimeNode.Subtract(item.DateHire.Value).TotalDays; double _TotalYear = dayServiceYear / 360; double _tempYear = 0; if (_TotalYear > 0) { string[] parts = _TotalYear.ToString().Split('.'); double _intMonth = double.Parse(parts[0]); if (parts.Length > 1) { double _modMonth = double.Parse("0." + parts[1]) * 12; if (_modMonth >= 10) { _tempYear = _intMonth + (_modMonth / 100); } else { _tempYear = _intMonth + (_modMonth / 10); } } row[Eva_ReportEvalutionDataEntity.FieldNames.ServiceYear] = String.Format("{0:0.0}", _tempYear); ; } if (item.DateHire.Value > dateFirstKi) { if (_TotalYear > 0) row[Eva_ReportEvalutionDataEntity.FieldNames.ServiceYearKi] = String.Format("{0:0.0}", _tempYear); } else { row[Eva_ReportEvalutionDataEntity.FieldNames.ServiceYearKi] = 1.0; } } #endregion var objBasicSalary = lstBasicSalary.Where(s => s.ProfileID == item.ProfileID).FirstOrDefault(); if (objBasicSalary != null) row[Eva_ReportEvalutionDataEntity.FieldNames.BasicSalary] = double.Parse(objBasicSalary.GrossAmount); row[Eva_ReportEvalutionDataEntity.FieldNames.Rank] = item.SalaryClassName; row[Eva_ReportEvalutionDataEntity.FieldNames.QualificationAbilitytitle] = item.AbilityTitleVNI; if (item.SalaryClassID != null) { var objSalaryRank = lstSalaryRank.Where(s => s.SalaryClassID == item.SalaryClassID).FirstOrDefault(); if (objSalaryRank != null) row[Eva_ReportEvalutionDataEntity.FieldNames.RankZone] = objSalaryRank.SalaryRankName; } row[Eva_ReportEvalutionDataEntity.FieldNames.JobTitle] = item.JobTitleName; Guid[] lstUnusualAllowanceProfileCfgIds = null; if (lstUnusualAllowance != null) { lstUnusualAllowance = lstUnusualAllowance.Where(s => s.ProfileID == item.ProfileID && s.UnusualEDTypeID != null).ToList(); lstUnusualAllowanceProfileCfgIds = lstUnusualAllowance.Select(s => s.UnusualEDTypeID.Value).ToArray(); } if (lstUnusualAllowanceCfg != null && lstUnusualAllowanceProfileCfgIds != null) lstUnusualAllowanceCfg = lstUnusualAllowanceCfg.Where(s => lstUnusualAllowanceProfileCfgIds.Contains(s.ID)).ToList(); double? totalUnusualAllowance = 0; if (lstUnusualAllowanceCfg != null) { foreach (var itemUnusualAllowanceCfg in lstUnusualAllowanceCfg) { var objUnusualAllowance = lstUnusualAllowance.Where(s => s.UnusualEDTypeID == itemUnusualAllowanceCfg.ID).OrderByDescending(s => s.MonthEnd).FirstOrDefault(); if (objUnusualAllowance != null) { row[itemUnusualAllowanceCfg.Code] = objUnusualAllowance.Amount; totalUnusualAllowance += objUnusualAllowance.Amount; } } } #region lich su danh gia if (_dateFrom != null && _dateTo != null && lstPerformance != null) { _yearFrom = _dateFrom.Value.Year; _yearTo = _dateTo.Value.Year; var lstPerformanceProfile = lstPerformance.Where(s => s.ProfileID == item.ProfileID).OrderByDescending(s => s.YearEvaluation).ToList(); if (lstPerformanceProfile.Count != 0) { while (_yearTo >= _yearFrom) { var objPerformanceFirst = lstPerformanceProfile.Where(s => s.YearEvaluation.Value.Year == _yearTo).OrderByDescending(s => s.YearEvaluation).FirstOrDefault(); _yearTo -= 1; var objPerformance = lstPerformanceProfile.Where(s => s.YearEvaluation.Value.Year == _yearTo).OrderByDescending(s => s.YearEvaluation).FirstOrDefault(); int _yeartemp = _yearTo + 1; if (objPerformanceFirst != null && objPerformanceFirst.Level1Name != null) { if (objPerformanceFirst.RankID != null && objPerformance != null && objPerformance.Level1Name != null && objPerformance.RankID != null) { if (objPerformanceFirst.RankID != objPerformance.RankID) { row["Year" + _yeartemp] = "(" + objPerformanceFirst.Level1Name + ")"; row["Year" + _yearTo] = "(" + objPerformance.Level1Name + ")"; _yearTo -= 1; while (_yearTo >= _yearFrom) { var objPerformanceYear = lstPerformanceProfile.Where(s => s.YearEvaluation.Value.Year == _yearTo).OrderByDescending(s => s.YearEvaluation).FirstOrDefault(); if (objPerformanceYear != null && objPerformanceYear.Level1Name != null) row["Year" + _yearTo] = "(" + objPerformanceYear.Level1Name + ")"; _yearTo -= 1; } } else { row["Year" + _yeartemp] = objPerformanceFirst.Level1Name; } } else { row["Year" + _yeartemp] = objPerformanceFirst.Level1Name; } } } } row[Eva_ReportEvalutionDataEntity.FieldNames.HistoryDateFrom] = _dateFrom.Value.ToShortDateString(); } #endregion if (totalUnusualAllowance > 0) row[Eva_ReportEvalutionDataEntity.FieldNames.TotalSalaryAllowance] = totalUnusualAllowance; if (item.Year != null) row[Eva_ReportEvalutionDataEntity.FieldNames.Year] = item.Year; //if (item.Time !=null) // row[Eva_ReportEvalutionDataEntity.FieldNames.Time] = item.Time; #region lan danh gia if (item.TimeEvalutionData != null) row[Eva_ReportEvalutionDataEntity.FieldNames.TimeEvalutionData] = item.TimeEvalutionData; if (item.TimeEvalutionDataCode != null) row[Eva_ReportEvalutionDataEntity.FieldNames.TimeEvalutionDataCode] = item.TimeEvalutionDataCode; #endregion #region C1->C32 if (item.C1 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C1] = item.C1; if (item.C2 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C2] = item.C2; if (item.C3 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C3] = item.C3; if (item.C4 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C4] = item.C4; if (item.C5 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C5] = item.C5; if (item.C6 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C6] = item.C6; if (item.C7 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C7] = item.C7; if (item.C8 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C8] = item.C8; if (item.C9 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C9] = item.C9; if (item.C10 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C10] = item.C10; if (item.C11 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C11] = item.C11; if (item.C12 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C12] = item.C12; if (item.C13 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C13] = item.C13; if (item.C14 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C14] = item.C14; if (item.C15 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C15] = item.C15; if (item.C16 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C16] = item.C16; if (item.C17 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C17] = item.C17; if (item.C18 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C18] = item.C18; if (item.C19 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C19] = item.C19; if (item.C20 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C20] = item.C20; if (item.C21 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C21] = item.C21; if (item.C22 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C22] = item.C22; if (item.C23 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C23] = item.C23; if (item.C24 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C24] = item.C24; if (item.C25 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C25] = item.C25; if (item.C26 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C26] = item.C26; if (item.C27 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C27] = item.C27; if (item.C28 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C28] = item.C28; if (item.C29 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C29] = item.C29; if (item.C30 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C30] = item.C30; if (item.C31 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C31] = item.C31; if (item.C32 != null) row[Eva_ReportEvalutionDataEntity.FieldNames.C32] = item.C32; #endregion #region Bo sung //int _tempC1 = 0; //int _TempC2 = 0; //int _tempC3 = 0; //int _tempC4 = 0; //int _tempC5 = 0; //int _tempC6 = 0; //int _tempC7 = 0; //int _tempC8 = 0; //int _tempC9 = 0; //#region TotalC1C2 //if (item.C1 != null) // _tempC1 = item.C1.Value; //if (item.C2 != null) // _TempC2 = item.C2.Value; //if (item.C1 != null || item.C2 != null) // row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC1C2] = _tempC1 + _TempC2; //#endregion //#region TotalC3C4C5C6C7 //if (item.C3 != null) // _tempC3 = item.C3.Value; //if (item.C4 != null) // _tempC4 = item.C4.Value; //if (item.C5 != null) // _tempC5 = item.C5.Value; //if (item.C6 != null) // _tempC6 = item.C6.Value; //if (item.C7 != null) // _tempC7 = item.C7.Value; //if (item.C3 != null || item.C4 != null || item.C5 != null || item.C6 != null || item.C7 != null) // row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC3C4C5C6C7] = _tempC3 + _tempC4 + _tempC5 + _tempC6 + _tempC7; //#endregion //#region TotalC1C2C3C4C5C6C7 //if (item.C1 != null || item.C2 != null || item.C3 != null || item.C4 != null || item.C5 != null || item.C6 != null || item.C7 != null) // row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC1C2C3C4C5C6C7] = _tempC1 + _TempC2 + _tempC3 + _tempC4 + _tempC5 + _tempC6 + _tempC7; //#endregion //#region TotalC8C9 //if (item.C8 != null) // _tempC8 = item.C8.Value; //if (item.C9 != null) // _tempC9 = item.C9.Value; //if (item.C8 != null || item.C9 != null) // row[Eva_ReportEvalutionDataEntity.FieldNames.TotalC8C9] = _tempC8 + _tempC9; //#endregion #endregion #region thoi gian danh gia row[Eva_ReportEvalutionDataEntity.FieldNames.DateStart] = _dateStart; row[Eva_ReportEvalutionDataEntity.FieldNames.DateEnd] = _dateEnd; #endregion table.Rows.Add(row); } return table.ConfigTable(); // #endregion } }
// DELETE api/<controller> public void Delete(Guid ID) { var service = new Sal_UnusualAllowanceServices(); var result = service.Remove<Sal_UnusualAllowanceEntity>(ID); }
public Sal_UnusualAllowanceModel Post([Bind]Sal_UnusualAllowanceModel model) { #region Validate string message = string.Empty; string status = string.Empty; ActionService service = new ActionService(UserLogin); var checkValidate=true; checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew", "Sal_UnusualAllowance", ref message); if (!checkValidate) { model.ActionStatus = message; return model; } if(model != null && model.UnusualEDTypeID !=null) { var entity = service.GetByIdUseStore<Cat_UnusualAllowanceCfgEntity>(model.UnusualEDTypeID.Value, ConstantSql.hrm_cat_sp_get_UnusualAllowanceCfgId, ref status); if (entity != null && entity.Code != null) { if (entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEE" || entity.Code.Replace(" ", "") == "HOSPITALOFEMPLOYEEMORETHANONEMONTH") { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew2", "Sal_UnusualAllowance", ref message); } else { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew1", "Sal_UnusualAllowance", ref message); } if (!checkValidate) { model.ActionStatus = message; return model; } if (entity.Code.Replace(" ", "") == "BIRTHOFACHILD" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEECHILD" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEESPOUSE" || entity.Code.Replace(" ", "") == "FUNERALOFPARENT") { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo1And2", "Sal_UnusualAllowance", ref message); if(checkValidate == false) { checkValidate = true; //lay thong tin cua quan he var objRelativesModel = service.GetData<Hre_RelativesModel>(Common.DotNetToOracle(model.RelativeID.ToString()), ConstantSql.hrm_hr_sp_get_RelativesById, ref status).FirstOrDefault(); var checkValidateRelatives = true; if (objRelativesModel != null) { //lay all nguoi than cua nv do Hre_RelativesServices hreServiveRelative = new Hre_RelativesServices(); var lstRelativeByProfileId = hreServiveRelative.GetRelativeByProfileId(model.ProfileID).ToList(); if (lstRelativeByProfileId.Count>0) { //if (model.ID == Guid.Empty) // objRelativesModel.ID = Guid.Empty; var lstDuplicateRelativeByProfileID=lstRelativeByProfileId. Where(s=>s.ProfileID==objRelativesModel.ProfileID && s.RelativeName==objRelativesModel.RelativeName && s.YearOfBirth==objRelativesModel.YearOfBirth).ToList(); if(lstDuplicateRelativeByProfileID.Count>0) checkValidateRelatives=false; } // checkValidateRelatives = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_RelativesModel>(objRelativesModel, "Hre_Relativesinfo1And2", "Hre_Relatives", ref message); } if (checkValidateRelatives == false) { model.ActionStatus = message; return model; } } } else if (entity.Code.Replace(" ", "")=="HOSPITALOFEMPLOYEEMORETHANONEMONTH") { Sal_ReportService salService = new Sal_ReportService(); int _daysInMonth = System.DateTime.DaysInMonth(model.DateOccur.Value.Year, model.DateOccur.Value.Month); DateTime _datestart = new DateTime(model.DateOccur.Value.Year, model.DateOccur.Value.Month, 1); DateTime _dateend = new DateTime(model.DateOccur.Value.Year, model.DateOccur.Value.Month, _daysInMonth); //List<object> paraUnusualAllowance = new List<object>(); //paraUnusualAllowance.AddRange(new object[7]); //paraUnusualAllowance[2] = model.UnusualEDTypeID; //paraUnusualAllowance[3] = _datestart; //paraUnusualAllowance[4] = _dateend; //paraUnusualAllowance[5] = 1; //paraUnusualAllowance[6] = int.MaxValue; Sal_UnusualAllowanceServices salServiceUnusualAllowance = new Sal_UnusualAllowanceServices(); //var lstUnusualAllowance = salServiceUnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(paraUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualAllowanceFilialWedding, ref status); var lstUnusualAllowance = salServiceUnusualAllowance.GetUnusualAllowanceByUnusualEDTypeIDAndDateOccur(model.ProfileID,model.UnusualEDTypeID, _datestart, _dateend); if (lstUnusualAllowance != null) { //lstUnusualAllowance = lstUnusualAllowance.Where(s => s.ProfileID == model.ProfileID).ToList(); if ((lstUnusualAllowance.Count > 0 && model.ID == Guid.Empty) || (lstUnusualAllowance.Count > 1 && model.ID != Guid.Empty)) { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo3", "Sal_UnusualAllowance", ref message); if (!checkValidate) { model.ActionStatus = message; return model; } } } } else if (entity.Code.Replace(" ", "") == "MARRIAGEOFEMPLOYEE" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEE") { checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo5And6And7", "Sal_UnusualAllowance", ref message); } } } if (!checkValidate) { model.ActionStatus = message; return model; } #endregion return service.UpdateOrCreate<Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model); }
public ActionResult ExportProfileListByTemplate([DataSourceRequest] DataSourceRequest request, Hre_ProfileActiveSearchModel model) { //if(model.ExportId == Guid.Empty) //{ // return null; //} var actionService = new ActionService(UserLogin); string status = string.Empty; var profileServices = new Hre_ProfileServices(); bool isGroup = profileServices.IsGroupByOrgProfileQuit(); var isDataTable = false; object obj = new Hre_ProfileModel(); var result = GetListData<Hre_ProfileModel, Hre_ProfileEntity, Hre_ProfileActiveSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ProfileActive, ref status); if (isGroup == true) { var rptServices = new Hre_ReportServices(); var orgServices = new Cat_OrgStructureServices(); var lstObjOrg = new List<object>(); lstObjOrg.Add(null); lstObjOrg.Add(null); lstObjOrg.Add(null); lstObjOrg.Add(1); lstObjOrg.Add(int.MaxValue - 1); var lstOrg = actionService.GetData<Cat_OrgStructureEntity>(lstObjOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, ref status).ToList(); var orgTypeService = new Cat_OrgStructureTypeServices(); var lstObjOrgType = new List<object>(); lstObjOrgType.Add(null); lstObjOrgType.Add(null); lstObjOrgType.Add(1); lstObjOrgType.Add(int.MaxValue - 1); var lstOrgType = actionService.GetData<Cat_OrgStructureTypeEntity>(lstObjOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, ref status).ToList(); result = GetListData<Hre_ProfileModel, Hre_ProfileEntity, Hre_ProfileActiveSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ProfileActive, ref status); DataTable table = new DataTable("Hre_ProfileModel"); table.Columns.Add("CodeEmp"); table.Columns.Add("ProfileName"); table.Columns.Add("FirstName"); table.Columns.Add("NameFamily"); table.Columns.Add("Channel"); table.Columns.Add("Region"); table.Columns.Add("Area"); table.Columns.Add("IDNo"); table.Columns.Add("IDDateOfIssue", typeof(DateTime)); table.Columns.Add("IDPlaceOfIssue"); table.Columns.Add("DateOfBirth", typeof(DateTime)); table.Columns.Add("PlaceOfBirth"); table.Columns.Add("Gender"); table.Columns.Add("MarriageStatus"); table.Columns.Add("NationalityName"); table.Columns.Add("ReligionName"); table.Columns.Add("EthnicGroupName"); table.Columns.Add("Email"); table.Columns.Add("CellPhone"); table.Columns.Add("CodeTax"); table.Columns.Add("TDistrictName"); table.Columns.Add("PDistrictName"); table.Columns.Add("JobTitleName"); table.Columns.Add("DateHire", typeof(DateTime)); table.Columns.Add("ContractNo"); table.Columns.Add("DateStartContract"); table.Columns.Add("DateEndContract"); table.Columns.Add("ContractTypeName"); table.Columns.Add("TimesOfContract"); table.Columns.Add("Notes"); table.Columns.Add("TAddress"); table.Columns.Add("PAddress"); table.Columns.Add("BasicSalary", typeof(double)); var salaryServices = new Sal_BasicSalaryServices(); var objSalary = new List<object>(); objSalary.AddRange(new object[10]); objSalary[8] = 1; objSalary[9] = int.MaxValue - 1; var lstBasicSalary = actionService.GetData<Sal_BasicSalaryEntity>(objSalary, ConstantSql.hrm_sal_sp_get_BasicPayroll, ref status).ToList(); var unuServices = new Sal_UnusualAllowanceServices(); var objUnu = new List<object>(); objUnu.AddRange(new object[9]); objUnu[7] = 1; objUnu[8] = int.MaxValue - 1; var lstUnu = actionService.GetData<Sal_UnusualAllowanceEntity>(objUnu, ConstantSql.hrm_sal_sp_get_UnusualED, ref status).ToList(); foreach (var item in result) { var basicSalaryEntity = lstBasicSalary.Where(s => s.ProfileID == item.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault(); var lstUnuByProfileID = lstUnu.Where(s => s.ProfileID == item.ID).ToList(); var orgName = new List<string>(); if (item.OrgStructureID != null) { orgName = rptServices.GetParentOrgName(lstOrg, lstOrgType, item.OrgStructureID); if (orgName.Count < 3) { orgName.Insert(0, string.Empty); if (orgName.Count < 3) { orgName.Insert(0, string.Empty); } } } var lstObjPayroll = new List<object>(); lstObjPayroll.Add(item.ID); lstObjPayroll.Add(null); lstObjPayroll.Add(null); lstObjPayroll.Add(null); lstObjPayroll.Add(1); lstObjPayroll.Add(int.MaxValue - 1); var payrollTableByProfileID = actionService.GetData<Sal_PayrollTableItemEntity>(lstObjPayroll, ConstantSql.hrm_sal_sp_get_PayrollTableItemByProfile, ref status).OrderByDescending(s => s.DateCreate); var lstObjContract = new List<object>(); lstObjContract.Add(item.ID); var lstContract = actionService.GetData<Hre_ContractEntity>(lstObjContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status).OrderBy(s => s.DateCreate).ToList(); var lstObjRelative = new List<object>(); lstObjRelative.Add(item.ID); lstObjRelative.Add(1); lstObjRelative.Add(Int32.MaxValue - 1); var lstDependant = actionService.GetData<Hre_DependantEntity>(lstObjRelative, ConstantSql.hrm_hr_sp_get_DependantByProfileId, ref status).ToList(); DataRow dr = table.NewRow(); dr["CodeEmp"] = item.CodeEmp; dr["ProfileName"] = item.ProfileName; dr["FirstName"] = item.FirstName; dr["NameFamily"] = item.NameFamily; if (orgName.Count > 0) { dr["Channel"] = orgName[2]; dr["Region"] = orgName[1]; dr["Area"] = orgName[0]; } dr["IDNo"] = item.IDNo; if (item.IDDateOfIssue != null) { dr["IDDateOfIssue"] = item.IDDateOfIssue.Value; } dr["IDPlaceOfIssue"] = item.IDPlaceOfIssue; if (item.DateOfBirth != null) { dr["DateOfBirth"] = item.DateOfBirth; } dr["Gender"] = item.Gender; if (item.Gender == EnumDropDown.Gender.E_FEMALE.ToString()) { dr["Gender"] = "Nữ"; } if (item.Gender == EnumDropDown.Gender.E_MALE.ToString()) { dr["Gender"] = "Nam"; } dr["MarriageStatus"] = item.MarriageStatus; dr["NationalityName"] = item.NationalityName; dr["ReligionName"] = item.ReligionName; dr["EthnicGroupName"] = item.EthnicGroupName; dr["Email"] = item.Email; dr["CellPhone"] = item.Cellphone; dr["CodeTax"] = item.CodeTax; dr["TDistrictName"] = item.TDistrictName; dr["PDistrictName"] = item.PDistrictName; dr["JobTitleName"] = item.JobTitleName; dr["Notes"] = item.Notes; dr["TAddress"] = item.TAddress; dr["PAddress"] = item.PAddress; if (basicSalaryEntity != null) { dr["BasicSalary"] = double.Parse(basicSalaryEntity.GrossAmount); } if (item.DateHire != null) { dr["DateHire"] = item.DateHire.Value; } //if (payrollTableByProfileID != null) //{ // foreach (var payroll in payrollTableByProfileID) // { // Double value = 0; // if (!table.Columns.Contains(payroll.Code)) // { // table.Columns.Add(payroll.Code, typeof(Double)); // } // if (table.Columns.Contains(payroll.Code)) // { // if (payroll.ValueType == typeof(Double).Name) // { // Double.TryParse(payroll.Value, out value); // } // dr[payroll.Code] = value; // } // } //} if (lstContract != null && lstContract.Count > 0) { var contractEntity = lstContract.FirstOrDefault(); dr["TimesOfContract"] = lstContract.Count; dr["ContractNo"] = contractEntity.ContractNo; dr["ContractTypeName"] = contractEntity.ContractTypeName; dr["DateStartContract"] = contractEntity.DateStart; if (contractEntity.DateEnd != null) { dr["DateStartContract"] = contractEntity.DateEnd.Value; } } if (lstUnuByProfileID.Count > 0 && lstUnuByProfileID != null) { foreach (var unu in lstUnuByProfileID) { var titleName = unu.UnusualEDTypeCode + "|" + unu.UnusualAllowanceCfgName; if (!table.Columns.Contains(titleName)) { table.Columns.Add(titleName); } if (table.Columns.Contains(titleName)) { dr[titleName] = unu.Amount; } } } if (lstDependant.Count > 0 && lstDependant != null) { foreach (var dependant in lstDependant) { var titleName = dependant.DependantName + "|" + dependant.RelativeTypeName; if (!table.Columns.Contains(titleName)) { table.Columns.Add(titleName); } if (table.Columns.Contains(titleName)) { dr[titleName] = dependant.DependantName; } } } table.Rows.Add(dr); } if (model.IsCreateTemplateForDynamicGrid) { obj = result; isDataTable = false; } if (model != null && model.IsCreateTemplate) { var path = Common.GetPath("Templates"); ExportService exportService = new ExportService(); ConfigExport cfgExport = new ConfigExport() { Object = table, FileName = "Hre_ProfileModel", OutPutPath = path, // HeaderInfo = listHeaderInfo, DownloadPath = Hrm_Main_Web + "Templates", IsDataTable = true }; var str = exportService.CreateTemplate(cfgExport); return Json(str); } if (model.ExportId != Guid.Empty) { var fullPath = ExportService.Export(model.ExportId, table, null, model.ExportType); return Json(fullPath); } return Json(result.ToDataSourceResult(request)); } if (model.IsCreateTemplateForDynamicGrid) { obj = result; isDataTable = false; } if (model != null && model.IsCreateTemplate) { var path = Common.GetPath("Templates"); ExportService exportService = new ExportService(); ConfigExport cfgExport = new ConfigExport() { Object = obj, FileName = "Hre_ProfileModel", OutPutPath = path, // HeaderInfo = listHeaderInfo, DownloadPath = Hrm_Main_Web + "Templates", IsDataTable = isDataTable }; var str = exportService.CreateTemplate(cfgExport); return Json(str); } if (model.ExportId != Guid.Empty) { var fullPath = ExportService.Export(model.ExportId, result, null, model.ExportType); return Json(fullPath); } return Json(result.ToDataSourceResult(request)); }
public void ComputeBonusUnusualAllowance_Progress(Guid AsynTaskID, Sal_UnusualAllowanceEntity model, bool AllowanceEvaluationYear = false) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork) new UnitOfWork(context); var repoSys_AsynTask = new CustomBaseRepository <Sys_AsynTask>(unitOfWork); var repoCat_Element = new CustomBaseRepository <Cat_Element>(unitOfWork); var repoCat_UnusualAllowanceCfg = new CustomBaseRepository <Cat_UnusualAllowanceCfg>(unitOfWork); var repoUnusualAllowance = new CustomBaseRepository <Sal_UnusualAllowance>(unitOfWork); Sys_AsynTask asynTask = repoSys_AsynTask.GetById(AsynTaskID); Sal_ComputePayrollServices CumputePayrollServices = new Sal_ComputePayrollServices(); List <object> listModel = new List <object>(); string status = string.Empty; Sal_ComputePayrollServices Services = new Sal_ComputePayrollServices(); List <Sal_UnusualAllowanceEntity> ListResult = new List <Sal_UnusualAllowanceEntity>(); List <ElementFormula> listElementFormula = new List <ElementFormula>(); Sal_UnusualAllowanceServices UnusualAllowanceServices = new Sal_UnusualAllowanceServices(); Att_CutOffDurationEntity CutOffDuration = new Att_CutOffDurationEntity(); if (model.MonthEnd != null) { CutOffDuration.MonthYear = model.MonthStart.Value; CutOffDuration.DateStart = model.MonthStart.Value; CutOffDuration.DateEnd = model.MonthEnd.Value; } else { CutOffDuration.MonthYear = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateStart = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateEnd = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1).AddMonths(1).AddDays(-1); } List <Hre_ProfileEntity> ListProfile = new List <Hre_ProfileEntity>(); if (model.OrgStructureIDs != null && model.OrgStructureIDs != string.Empty) { listModel = new List <object>(); listModel.AddRange(new object[18]); listModel[2] = model.OrgStructureIDs; listModel[16] = 1; listModel[17] = Int32.MaxValue - 1; ListProfile = GetData <Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, ref status); if (model.ExProfileIDs != null) { string[] ExProfile = model.ExProfileIDs.Split(','); ListProfile = ListProfile.Where(m => ExProfile.Contains(m.ID.ToString())).ToList(); } } else if (model.ProfileIDs != null && model.ProfileIDs != string.Empty) { ListProfile = GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status); } //lọc profile theo workplace if (model.WorkingPlaceID != null) { string[] listWorkPlare = model.WorkingPlaceID.Split(','); ListProfile = ListProfile.Where(m => listWorkPlare.Contains(m.WorkPlaceID.ToString())).ToList(); } List <Cat_UnusualAllowanceCfg> listUnusualAllowanceCfg = new List <Cat_UnusualAllowanceCfg>(); listUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); #region Delete các phụ cấp trong năm đã có List <Sal_UnusualAllowance> listUnusualAllowance = repoUnusualAllowance.FindBy(m => m.IsDelete != true && m.MonthStart != null && model.MonthStart != null && m.MonthStart.Value.Year == model.MonthStart.Value.Year && m.Status != WorkHistoryStatus.E_APPROVED.ToString()).ToList(); //nếu là tính phép năm sức khỏe tốt thì delete thêm loại GoodHealth if (AllowanceEvaluationYear) { var _tmp = listUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); listUnusualAllowance = listUnusualAllowance.Where(m => (m.UnusualEDTypeID == model.UnusualEDTypeID || m.UnusualEDTypeID == _tmp.ID) && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } else { listUnusualAllowance = listUnusualAllowance.Where(m => m.UnusualEDTypeID == model.UnusualEDTypeID && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } //update isdelete is true listUnusualAllowance.ForEach(m => m.IsDelete = true); #endregion //Cat_ElementEntity ElementItem = repoCat_Element.GetById((Guid)model.Element).Copy<Cat_ElementEntity>(); Cat_ElementEntity ElementItem = repoCat_Element.FindBy(m => m.ID == (Guid)model.Element).FirstOrDefault().Copy <Cat_ElementEntity>(); ComputePayrollDataModel TotalData = Services.GetDataForComputeSalary(CutOffDuration); List <Cat_ElementEntity> listElementAll = new List <Cat_ElementEntity>(); listElementAll = TotalData.listElement_All; #region Xử lý cho tính phép năm, sức khỏe tốt List <Cat_UnusualAllowanceCfg> ListUnusualAllowanceCfg = new List <Cat_UnusualAllowanceCfg>(); Cat_UnusualAllowanceCfg PaidLeave = null; Cat_UnusualAllowanceCfg GoodHealth = null; ElementFormula FormulaValue = new ElementFormula(); if (AllowanceEvaluationYear) { ListUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); PaidLeave = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "PaidLeave"); GoodHealth = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); } #endregion foreach (var profile in ListProfile) { if (AllowanceEvaluationYear) { #region Tính Công Thức try { listElementFormula = new List <ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate <Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary <Guid, ValueCount>()); } catch { listElementFormula = null; continue; } #endregion if (PaidLeave != null) { //lưu phần tử TienBuPhepNam Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = PaidLeave.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienPhepNam").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } if (GoodHealth != null) { //lưu phần tử TienSucKhoe Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = GoodHealth.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienSucKhoe").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } } else { Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = model.UnusualEDTypeID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; try { listElementFormula = new List <ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate <Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary <Guid, ValueCount>()); FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == ElementItem.ElementCode.ReplaceSpace()).FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); } catch { UnusualAllowance.Amount = 0; UnusualAllowance.Notes = "Không tính được công thức - Lỗi: " + TotalData.Status; } repoUnusualAllowance.Add(UnusualAllowance); } if (ListProfile.IndexOf(profile) % 10 == 0) { asynTask.PercentComplete = (double)(ListProfile.IndexOf(profile) + 1) / (double)ListProfile.Count; unitOfWork.SaveChanges(); } } asynTask.PercentComplete = 1; unitOfWork.SaveChanges(); } }
public DataTable GetCompareUnusualAllowance(DateTime dateFrom, DateTime dateTo, string orderNmber, Guid? workplaceID, string statusProfile, string UserLogin, bool IsCreateTeamplate) { DataTable tb = CreateCompareUnusualAllowanceSchema(); using (var context = new VnrHrmDataContext()) { var monthSub = dateFrom.AddMonths(-1); string status = string.Empty; var profileServices = new Hre_ProfileServices(); var objProfile = new List<object>(); objProfile.Add(orderNmber); objProfile.Add(null); objProfile.Add(null); var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status); if (workplaceID != null) { lstProfile = lstProfile.Where(s => s.WorkPlaceID != null && s.WorkPlaceID.Value == workplaceID.Value).ToList(); } string _statusAll = EnumDropDown.StatusEmployee.E_ALL.ToString(); if (!string.IsNullOrEmpty(statusProfile) && statusProfile != _statusAll) { lstProfile = lstProfile.Where(s => s.Status == statusProfile).ToList(); } var lstProfileID = lstProfile.Select(s => s.ID).ToList(); var UnusCfgServices = new Cat_UnusualAllowanceCfgServices(); var objUnuCfg = new List<object>(); objUnuCfg.Add(null); objUnuCfg.Add(null); objUnuCfg.Add(null); objUnuCfg.Add(null); objUnuCfg.Add(1); objUnuCfg.Add(int.MaxValue - 1); var lstUnuCfg = UnusCfgServices.GetData<Cat_UnusualAllowanceCfgEntity>(objUnuCfg, ConstantSql.hrm_cat_sp_get_UnusualAllowanceCfg, UserLogin, ref status).Where(m => m.Type == EnumDropDown.UnusualEDType.E_UNUSUALALLOWANCE.ToString()).ToList(); var unuServices = new Sal_UnusualAllowanceServices(); var objUnu = new List<object>(); objUnu.AddRange(new object[9]); objUnu[7] = 1; objUnu[8] = int.MaxValue - 1; var lstUnu = unuServices.GetData<Sal_UnusualAllowanceEntity>(objUnu, ConstantSql.hrm_sal_sp_get_UnusualED, UserLogin, ref status); var pastDateFrom = dateFrom.AddMonths(-1); var pastDateTo = dateTo.AddMonths(-1); foreach (var item in lstUnuCfg) { DataRow dr = tb.NewRow(); dr[Sal_CompareUnusualAllowanceEntity.FieldNames.UnusualAllowanceCfgName] = item.UnusualAllowanceCfgName; var earing = EnumDropDown.EDType.E_EARNING.ToString(); var deduction = EnumDropDown.EDType.E_DEDUCTION.ToString(); var lstUnuByTypeID = lstUnu.Where(s => s.UnusualEDTypeID == item.ID && lstProfileID.Contains(s.ProfileID)).ToList(); var lstPastEaring = lstUnuByTypeID.Where(s => s.EDTypeCfg == earing && s.MonthStart >= pastDateFrom && s.MonthEnd <= pastDateTo).ToList(); var lstLastEaring = lstUnuByTypeID.Where(s => s.EDTypeCfg == earing && s.MonthStart >= dateFrom && s.MonthEnd <= dateTo).ToList(); var lstPastDeduction = lstUnuByTypeID.Where(s => s.EDTypeCfg == deduction && s.MonthStart >= pastDateFrom && s.MonthEnd <= pastDateTo).ToList(); var lstLastDeduction = lstUnuByTypeID.Where(s => s.EDTypeCfg == deduction && s.MonthStart >= dateFrom && s.MonthEnd <= dateTo).ToList(); if (tb.Columns.Contains("EEARING1")) { if (lstPastEaring.Count > 0) dr[Sal_CompareUnusualAllowanceEntity.FieldNames.EEARING1] = lstPastEaring.Sum(s => s.Amount); } if (tb.Columns.Contains("EEARING2")) { if (lstLastEaring.Count > 0) dr[Sal_CompareUnusualAllowanceEntity.FieldNames.EEARING2] = lstLastEaring.Sum(s => s.Amount); } if (tb.Columns.Contains("EDEDUCTION1")) { if (lstPastDeduction.Count > 0) dr[Sal_CompareUnusualAllowanceEntity.FieldNames.EDEDUCTION1] = lstPastDeduction.Sum(s => s.Amount); } if (tb.Columns.Contains("EDEDUCTION1")) { if (lstLastDeduction.Count > 0) dr[Sal_CompareUnusualAllowanceEntity.FieldNames.EDEDUCTION2] = lstLastDeduction.Sum(s => s.Amount); } tb.Rows.Add(dr); } return tb.ConfigTable(true); } }
public DataTable GetReportHaveChildUsunual(string orderNumberOrg, DateTime? dateFrom, DateTime? dateTo, string UserLogin, bool IsCreateTemplate) { DataTable table = CreateReportHaveChildUsunualSchema(); if (IsCreateTemplate) { return table; } using (var context = new VnrHrmDataContext()) { string status = string.Empty; var unitOfWork = (IUnitOfWork)(new UnitOfWork(context)); var orgTypeServices = new Cat_OrgStructureTypeServices(); var objOrgType = new List<object>(); objOrgType.Add(null); objOrgType.Add(null); objOrgType.Add(1); objOrgType.Add(int.MaxValue - 1); var lstOrgType = orgTypeServices.GetData<Cat_OrgStructureTypeEntity>(objOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, UserLogin, ref status).ToList(); var orgServices = new Cat_OrgStructureServices(); var objOrg = new List<object>(); objOrg.Add(null); objOrg.Add(null); objOrg.Add(null); objOrg.Add(1); objOrg.Add(int.MaxValue - 1); var lstOrg = orgServices.GetData<Cat_OrgStructureEntity>(objOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, UserLogin, ref status).ToList(); //if (lstOrgType != null) //{ // lstOrg = lstOrg.Where(s => s.OrgStructureTypeID != null && s.OrgStructureTypeID == lstOrgType.ID).ToList(); //} var lstOrgNumber = lstOrg.Select(s => s.OrderNumber).ToList(); var strOrderNumber = string.Join(",", lstOrgNumber); var profileServices = new Hre_ProfileServices(); var objProfile = new List<object>(); objProfile.Add(strOrderNumber); objProfile.Add(null); objProfile.Add(null); var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList(); var relativeServices = new Hre_RelativesServices(); var objRelative = new List<object>(); objRelative.AddRange(new object[11]); objRelative[9] = 1; objRelative[10] = int.MaxValue - 1; var lstRelatives = relativeServices.GetData<Hre_RelativesEntity>(objRelative, ConstantSql.hrm_hr_sp_get_Relatives, UserLogin, ref status).ToList(); var repoCat_OrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork); var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork); var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null).ToList(); var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList(); var UnusualAllowance = new Sal_UnusualAllowanceServices(); var objUnusualAllowance = new List<object>(); objUnusualAllowance.AddRange(new object[7]); objUnusualAllowance[3] = dateFrom; objUnusualAllowance[4] = dateTo; objUnusualAllowance[5] = 1; objUnusualAllowance[6] = int.MaxValue - 1; List<Sal_UnusualAllowanceEntity> listUnusualAllowance = UnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(objUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualEDChildCare, UserLogin, ref status); //lọc nhân viên có hưởng phụ cấp con nhỏ lstProfile = lstProfile.Where(m => listUnusualAllowance.Any(t => t.ProfileID == m.ID)).ToList(); foreach (var item in lstProfile) { DataRow dr = table.NewRow(); var lstRelativeByProfileID = lstRelatives.Where(s => s.ProfileID == item.ID).ToList(); if (lstRelativeByProfileID.Count == 0) { continue; } Guid? orgId = item.OrgStructureID; var unit = LibraryService.GetNearestParent(orgId, OrgUnit.E_UNIT, orgs, orgTypes); var division = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes); var department = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes); var section = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes); dr[Sal_ReportHaveChildUsunualEntity.FieldNames.CodeEmp] = item.CodeEmp; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.ProfileName] = item.ProfileName; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_UNIT] = item.E_UNIT; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_DIVISION] = item.E_DIVISION; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_DEPARTMENT] = item.E_DEPARTMENT; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_TEAM] = item.E_TEAM; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_SECTION] = item.E_SECTION; if (lstRelativeByProfileID.Count > 0) { var count = 0; foreach (var relative in lstRelativeByProfileID) { var _tmp = new DateTime(); count++; if (count == 11) { break; } if (relative.YearOfBirth != null) { var strYearOfBirth = relative.YearOfBirth.Split('/'); var newYOB = new DateTime(int.Parse(strYearOfBirth[2]), int.Parse(strYearOfBirth[1]), int.Parse(strYearOfBirth[0])); var dateCheck = DateTime.Now; var age = (dateCheck.Subtract(_tmp).TotalDays / 30) / 12; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.RelativeName + count] = relative.RelativeName; dr[Sal_ReportHaveChildUsunualEntity.FieldNames.DateBorn + count] = newYOB; } } } table.Rows.Add(dr); } return table.ConfigTable(true); } }
public void ComputeBonusUnusualAllowance_Progress(Guid AsynTaskID, Sal_UnusualAllowanceEntity model, bool AllowanceEvaluationYear = false) { using (var context = new VnrHrmDataContext()) { var unitOfWork = (IUnitOfWork)new UnitOfWork(context); var repoSys_AsynTask = new CustomBaseRepository<Sys_AsynTask>(unitOfWork); var repoCat_Element = new CustomBaseRepository<Cat_Element>(unitOfWork); var repoCat_UnusualAllowanceCfg = new CustomBaseRepository<Cat_UnusualAllowanceCfg>(unitOfWork); var repoUnusualAllowance = new CustomBaseRepository<Sal_UnusualAllowance>(unitOfWork); Sys_AsynTask asynTask = repoSys_AsynTask.GetById(AsynTaskID); Sal_ComputePayrollServices CumputePayrollServices = new Sal_ComputePayrollServices(); List<object> listModel = new List<object>(); string status = string.Empty; Sal_ComputePayrollServices Services = new Sal_ComputePayrollServices(); List<Sal_UnusualAllowanceEntity> ListResult = new List<Sal_UnusualAllowanceEntity>(); List<ElementFormula> listElementFormula = new List<ElementFormula>(); Sal_UnusualAllowanceServices UnusualAllowanceServices = new Sal_UnusualAllowanceServices(); Att_CutOffDurationEntity CutOffDuration = new Att_CutOffDurationEntity(); if (model.MonthEnd != null) { CutOffDuration.MonthYear = model.MonthStart.Value; CutOffDuration.DateStart = model.MonthStart.Value; CutOffDuration.DateEnd = model.MonthEnd.Value; } else { CutOffDuration.MonthYear = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateStart = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1); CutOffDuration.DateEnd = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1).AddMonths(1).AddDays(-1); } List<Hre_ProfileEntity> ListProfile = new List<Hre_ProfileEntity>(); if (model.OrgStructureIDs != null && model.OrgStructureIDs != string.Empty) { listModel = new List<object>(); listModel.AddRange(new object[18]); listModel[2] = model.OrgStructureIDs; listModel[16] = 1; listModel[17] = Int32.MaxValue - 1; ListProfile = GetData<Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, ref status); if (model.ExProfileIDs != null) { string[] ExProfile = model.ExProfileIDs.Split(','); ListProfile = ListProfile.Where(m => ExProfile.Contains(m.ID.ToString())).ToList(); } } else if (model.ProfileIDs != null && model.ProfileIDs != string.Empty) { ListProfile = GetData<Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status); } //lọc profile theo workplace if (model.WorkingPlaceID != null) { string[] listWorkPlare = model.WorkingPlaceID.Split(','); ListProfile = ListProfile.Where(m => listWorkPlare.Contains(m.WorkPlaceID.ToString())).ToList(); } List<Cat_UnusualAllowanceCfg> listUnusualAllowanceCfg = new List<Cat_UnusualAllowanceCfg>(); listUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); #region Delete các phụ cấp trong năm đã có List<Sal_UnusualAllowance> listUnusualAllowance = repoUnusualAllowance.FindBy(m => m.IsDelete != true && m.MonthStart != null && model.MonthStart != null && m.MonthStart.Value.Year == model.MonthStart.Value.Year && m.Status != WorkHistoryStatus.E_APPROVED.ToString()).ToList(); //nếu là tính phép năm sức khỏe tốt thì delete thêm loại GoodHealth if (AllowanceEvaluationYear) { var _tmp = listUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); listUnusualAllowance = listUnusualAllowance.Where(m => (m.UnusualEDTypeID == model.UnusualEDTypeID || m.UnusualEDTypeID == _tmp.ID) && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } else { listUnusualAllowance = listUnusualAllowance.Where(m => m.UnusualEDTypeID == model.UnusualEDTypeID && ListProfile.Any(t => t.ID == m.ProfileID)).ToList(); } //update isdelete is true listUnusualAllowance.ForEach(m => m.IsDelete = true); #endregion //Cat_ElementEntity ElementItem = repoCat_Element.GetById((Guid)model.Element).Copy<Cat_ElementEntity>(); Cat_ElementEntity ElementItem = repoCat_Element.FindBy(m => m.ID == (Guid)model.Element).FirstOrDefault().Copy<Cat_ElementEntity>(); ComputePayrollDataModel TotalData = Services.GetDataForComputeSalary(CutOffDuration); List<Cat_ElementEntity> listElementAll = new List<Cat_ElementEntity>(); listElementAll = TotalData.listElement_All; #region Xử lý cho tính phép năm, sức khỏe tốt List<Cat_UnusualAllowanceCfg> ListUnusualAllowanceCfg = new List<Cat_UnusualAllowanceCfg>(); Cat_UnusualAllowanceCfg PaidLeave = null; Cat_UnusualAllowanceCfg GoodHealth = null; ElementFormula FormulaValue = new ElementFormula(); if (AllowanceEvaluationYear) { ListUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList(); PaidLeave = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "PaidLeave"); GoodHealth = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth"); } #endregion foreach (var profile in ListProfile) { if (AllowanceEvaluationYear) { #region Tính Công Thức try { listElementFormula = new List<ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate<Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary<Guid, ValueCount>()); } catch { listElementFormula = null; continue; } #endregion if (PaidLeave != null) { //lưu phần tử TienBuPhepNam Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = PaidLeave.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienPhepNam").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } if (GoodHealth != null) { //lưu phần tử TienSucKhoe Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = GoodHealth.ID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienSucKhoe").FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); repoUnusualAllowance.Add(UnusualAllowance); } } else { Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance(); UnusualAllowance.ID = Guid.NewGuid(); UnusualAllowance.ProfileID = profile.ID; UnusualAllowance.UnusualEDTypeID = model.UnusualEDTypeID; UnusualAllowance.MonthStart = CutOffDuration.DateStart; UnusualAllowance.MonthEnd = CutOffDuration.DateEnd; UnusualAllowance.Type = EnumDropDown.EDType.E_EARNING.ToString(); UnusualAllowance.CurrencyID = model.CurrencyID; try { listElementFormula = new List<ElementFormula>(); TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate<Cat_ElementEntity>(); listElementFormula = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary<Guid, ValueCount>()); FormulaValue = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == ElementItem.ElementCode.ReplaceSpace()).FirstOrDefault(); UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0"); } catch { UnusualAllowance.Amount = 0; UnusualAllowance.Notes = "Không tính được công thức - Lỗi: " + TotalData.Status; } repoUnusualAllowance.Add(UnusualAllowance); } if (ListProfile.IndexOf(profile) % 10 == 0) { asynTask.PercentComplete = (double)(ListProfile.IndexOf(profile) + 1) / (double)ListProfile.Count; unitOfWork.SaveChanges(); } } asynTask.PercentComplete = 1; unitOfWork.SaveChanges(); } }