Пример #1
0
 /// <summary>
 /// [Tho.Bui] - Xóa hoặc chuyển đổi trạng thái Quốc Gia(Cat_Country) sang IsDelete
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Sal_BasicSalaryModel DeleteOrRemove(string id)
 {
     
     if (id != string.Empty)
     {
         var listID = id.Split(',').ToList();
         foreach (var i in listID)
         {
             Sal_BasicSalaryServices service = new Sal_BasicSalaryServices();
             var result = service.Remove<Sal_BasicSalaryEntity>(Common.ConvertToGuid(i));
         }
     }
     return new Sal_BasicSalaryModel();
 }
Пример #2
0
        public void AddAdjustmentSuggestionForBasicSalary(List <Sal_AdjustmentSuggestionEntity> lstAdjust, DateTime dateOfEffect, string UserLogin)
        {
            var           salaryServices = new Sal_BasicSalaryServices();
            BaseService   service        = new BaseService();
            string        ConfigHre      = AppConfig.HRM_HRE_CONFIG.ToString();
            string        status         = string.Empty;
            List <object> lstOb          = new List <object>();

            lstOb.Add(ConfigHre);
            lstOb.Add(null);
            lstOb.Add(null);
            var    config         = GetData <Sys_AllSettingEntity>(lstOb, ConstantSql.hrm_sys_sp_get_AllSetting, UserLogin, ref status);
            string defaultcur     = null;
            string valueConfig    = AppConfig.HRM_HRE_CONFIG_DEFAULTCURRENCY.ToString();
            var    currencyEntity = new Cat_CurrencyEntity();

            if (config != null)
            {
                defaultcur = config.Where(s => s.Name == valueConfig).Select(s => s.Value1).FirstOrDefault().ToString();
                List <object> listObjCurrency = new List <object>();
                listObjCurrency.Add(null);
                listObjCurrency.Add(defaultcur);
                listObjCurrency.Add(1);
                listObjCurrency.Add(Int32.MaxValue - 1);
                currencyEntity = service.GetData <Cat_CurrencyEntity>(listObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, UserLogin, ref status).FirstOrDefault();
            }
            if (lstAdjust.Count > 0)
            {
                var lstBasicSalary    = new List <Sal_BasicSalaryEntity>();
                var lstBasicSalaryAdd = new List <Sal_BasicSalaryEntity>();
                lstBasicSalary = lstAdjust.Translate <Sal_BasicSalaryEntity>();
                foreach (var item in lstBasicSalary)
                {
                    item.ID           = Guid.Empty;
                    item.CurrencyID   = currencyEntity.ID;
                    item.DateOfEffect = dateOfEffect;
                    item.ClassRateID  = item.ClassRateID;
                    item.RankRateID   = item.RankRateID;
                    item.Status       = EnumDropDown.Sal_BasicSalaryStatus.E_WATTING_APPROVED.ToString();
                    lstBasicSalaryAdd.Add(item);
                }
                salaryServices.Add(lstBasicSalaryAdd);
            }
        }
Пример #3
0
        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
            }
        }
        public Hre_AppendixContractModel Post([Bind]Hre_AppendixContractModel model)
        {
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_AppendixContractModel>(model, "Hre_AppendixContract", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            #endregion
            if (model.AppendixCreateBasicSalary == true)
            {
                Sal_BasicSalaryServices salaryservices = new Sal_BasicSalaryServices();
                Sal_BasicSalaryEntity basicSalaryBycontract = new Sal_BasicSalaryEntity();

                basicSalaryBycontract.ProfileID = model.ProfileID.Value;
                basicSalaryBycontract.GrossAmount = model.Salary != null ? model.Salary.ToString() : "0";
                basicSalaryBycontract.CurrencyID = model.CurenncyID != null ? model.CurenncyID.Value : Guid.Empty;
                basicSalaryBycontract.PersonalRate = model.PersonalRate;
                if (model.DateofEffect != null)
                {
                    basicSalaryBycontract.DateOfEffect = model.DateofEffect.Value;
                }

                basicSalaryBycontract.InsuranceAmount = model.InsuranceAmount != null ? model.InsuranceAmount.Value : 0;
                basicSalaryBycontract.CurrencyID1 = model.CurenncyID1;

                basicSalaryBycontract.ClassRateID = model.ClassRateID;
                basicSalaryBycontract.RankRateID = model.RankRateID;

                basicSalaryBycontract.AllowanceType1ID = model.AllowanceID1;
                basicSalaryBycontract.AllowanceAmount1 = model.Allowance1;
                basicSalaryBycontract.CurrencyID2 = model.CurenncyID2;

                basicSalaryBycontract.AllowanceType2ID = model.AllowanceID2;
                basicSalaryBycontract.AllowanceAmount2 = model.Allowance2;
                basicSalaryBycontract.CurrencyID3 = model.CurenncyID3;

                basicSalaryBycontract.AllowanceType3ID = model.AllowanceID3;
                basicSalaryBycontract.AllowanceAmount3 = model.Allowance3;
                basicSalaryBycontract.CurrencyID4 = model.CurenncyIDSalary;

                salaryservices.Add(basicSalaryBycontract);

            }
            var status = string.Empty;
            var contractServices = new Hre_ContractServices();

            var contractEntity = contractServices.GetData<Hre_ContractEntity>(model.ProfileID, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
            if (contractEntity != null)
            {
                model.ContractID = contractEntity.ID;
            }
            else {
                model.ActionStatus = ConstantMessages.WarningProfileHaveNotContract.ToString().TranslateString();
                return model;
            }
         
            ActionService service = new ActionService(UserLogin);
            return service.UpdateOrCreate<Hre_AppendixContractEntity, Hre_AppendixContractModel>(model, model.UserID);
        }
Пример #5
0
        public ActionResult SaveContractAndSaslary(DateTime? dateStart, DateTime? dateEnd, string orgStructureID, string contractTypeID, string RankDetailForNextContract, List<Guid> selectedIds, string statusContract, bool IsEvaluation)
        {
            var hrService = new Hre_ProfileServices();
            string message = string.Empty;
            var actionService = new ActionService(UserLogin);
            string status = string.Empty;
            var lstObjProfile = new List<object>();
            lstObjProfile.AddRange(new object[16]);
            lstObjProfile[14] = 1;
            lstObjProfile[15] = int.MaxValue - 1;
            var lstProfile = actionService.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_Profile, ref status).ToList();

            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjSalaryRank = new List<object>();
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(1);
            lstObjSalaryRank.Add(int.MaxValue - 1);
            var lstSalaryRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();
            var contractServices = new Hre_ContractServices();
            var lisobjContract = new List<object>();
            string strIDs = string.Empty;
            foreach (var item in selectedIds)
            {
                strIDs += Common.DotNetToOracle(item.ToString()) + ",";
            }
            if (strIDs.IndexOf(",") > 0)
                strIDs = strIDs.Substring(0, strIDs.Length - 1);
            lisobjContract.Add(strIDs);
            var lstContractByProfileID = actionService.GetData<Hre_ContractEntity>(lisobjContract, ConstantSql.hrm_hr_sp_get_ContractsByListId, ref status).ToList();
            var workhistoryService = new Hre_WorkHistoryServices();
            var lstObjWorkhistory = new List<object>();
            lstObjWorkhistory.AddRange(new object[17]);
            lstObjWorkhistory[15] = 1;
            lstObjWorkhistory[16] = int.MaxValue - 1;
            var lstWorkhistory = actionService.GetData<Hre_WorkHistoryEntity>(lstObjWorkhistory, ConstantSql.hrm_hr_sp_get_WorkHistory, ref status).ToList();

            var basicSalaryService = new Sal_BasicSalaryServices();

            var attGradeService = new Att_GradeServices();
            var lstObjAttGrade = new List<object>();
            lstObjAttGrade.AddRange(new object[6]);
            lstObjAttGrade[4] = 1;
            lstObjAttGrade[5] = int.MaxValue - 1;
            var lstAttGrade = actionService.GetData<Att_GradeEntity>(lstObjAttGrade, ConstantSql.hrm_att_sp_get_Att_Grade, ref status).ToList();

            var gradeService = new Sal_GradeServices();
            var lstObjSalGrade = new List<object>();
            lstObjSalGrade.AddRange(new object[7]);
            lstObjSalGrade[5] = 1;
            lstObjSalGrade[6] = int.MaxValue - 1;
            var lstSalGrade = actionService.GetData<Sal_GradeEntity>(lstObjSalGrade, ConstantSql.hrm_sal_sp_get_Sal_Grade, ref status).ToList();

            var gradePayrollService = new Cat_GradePayrollServices();
            var lstObjGradePayroll = new List<object>();
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(1);
            lstObjGradePayroll.Add(int.MaxValue - 1);
            var lstGradePayroll = actionService.GetData<Cat_GradePayrollEntity>(lstObjGradePayroll, ConstantSql.hrm_cat_sp_get_GradePayroll, ref status).ToList();

            var gradeAttService = new Cat_GradeAttendanceServices();
            var lstObjGradeAtt = new List<object>();
            lstObjGradeAtt.AddRange(new object[10]);
            lstObjGradeAtt[8] = 1;
            lstObjGradeAtt[9] = int.MaxValue - 1;
            var lstGradeAtt = actionService.GetData<Cat_GradeAttendanceEntity>(lstObjGradeAtt, ConstantSql.hrm_cat_sp_get_Cat_GradeAttendance, ref status).ToList();

            var currencyServices = new Cat_CurrencyServices();
            var lstObjCurrency = new List<object>();
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(1);
            lstObjCurrency.Add(int.MaxValue - 1);
            var lstCurrency = actionService.GetData<Cat_CurrencyEntity>(lstObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, ref status).ToList();
            var lstCurrencyNew = lstCurrency.Where(s => s.CurrencyName == "VND").FirstOrDefault();

            var contractTypeService = new Cat_ContractTypeServices();
            var lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(int.MaxValue - 1);
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var insuranceConfigServices = new Cat_InsuranceConfigServices();
            var objInsuranceConfig = new List<object>();
            objInsuranceConfig.Add(1);
            objInsuranceConfig.Add(int.MaxValue - 1);
            var lstInsuranceConfig = actionService.GetData<Cat_InsuranceConfigEntity>(objInsuranceConfig, ConstantSql.hrm_cat_sp_get_InsuranceConfig, ref status).ToList();

            var insuranceServices = new Sal_InsuranceSalaryServices();
            var objInsurance = new List<object>();
            objInsurance.AddRange(new object[9]);
            objInsurance[7] = 1;
            objInsurance[8] = int.MaxValue - 1;
            var lstInsurance = actionService.GetData<Sal_InsuranceSalaryEntity>(objInsurance, ConstantSql.hrm_sal_sp_get_InsuranceSalary, ref status).ToList();

            foreach (var item in lstContractByProfileID)
            {
                var contractTypeEntity = new Cat_ContractTypeEntity();
                var objContract = new List<object>();
                objContract.Add(item.ProfileID);
                var lstContractIdByProfileID = actionService.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
                var listIdContract = string.Empty;
                if (lstContractIdByProfileID != null)
                {
                    listIdContract = string.Join(",", lstContractIdByProfileID.Select(d => d.ContractTypeID));
                }

                var profile = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();

                if (item.NextContractTypeID != null)
                {
                    contractTypeEntity = lstContractType.Where(s => item.NextContractTypeID.Value == s.ID).FirstOrDefault();
                }
                else
                {
                    message = ConstantMessages.WarningContractHaveNotNextContract.ToString().TranslateString();
                    return Json(message, JsonRequestBehavior.AllowGet);
                    // contractTypeEntity = lstContractType.Where(s => Guid.Parse(Common.DotNetToOracle(item.ContractNextID.ToString())) == s.ID).FirstOrDefault();
                }


                var workingHistoryEntity = lstWorkhistory.Where(s => s.ProfileID == item.ProfileID).FirstOrDefault();
                var objSalGrade = new List<object>();
                objSalGrade.Add(item.ProfileID);
                objSalGrade.Add(null);
                objSalGrade.Add(1);
                objSalGrade.Add(int.MaxValue - 1);
                var salGradeByProfileIDEntity = actionService.GetData<Sal_GradeEntity>(objSalGrade, ConstantSql.hrm_sal_sp_get_GradeAndAllownaceByProId, ref status).FirstOrDefault();
                var objAttGrade = new List<object>();
                objAttGrade.Add(item.ProfileID);
                objAttGrade.Add(null);
                objAttGrade.Add(1);
                objAttGrade.Add(int.MaxValue - 1);
                var attGradeByProfileIDEntity = actionService.GetData<Att_GradeEntity>(objAttGrade, ConstantSql.hrm_att_sp_get_GradeAttendanceByProIdCutID, ref status).FirstOrDefault();

                if (contractTypeEntity == null)
                {
                    continue;
                }

                if (item.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
                {
                    if (item.ContractEvaType == EnumDropDown.ContractEvaType.E_EXPIRED_APPRENTICE.ToString())
                    {

                        //chưa tìm dc cách xử lý nên hard code 
                        var lstSalaryRankNew = new Cat_SalaryRankEntity();
                        // var lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        if (item.RankDetailForNextContract != null)
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        }
                        else
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankRateID != null && s.ID == item.RankRateID.Value).FirstOrDefault();
                        }

                        #region Xử lý Hre_Contract
                        if (item.TypeOfPass == EnumDropDown.TypeOfPass.E_SIGNED_NEXTCONTRACT.ToString())
                        {
                            int month = 0;
                            if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                            {
                                month = (int)contractTypeEntity.ValueTime.Value;
                                if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                                {
                                    month = month * 12;
                                }
                                contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                                //chưa tìm dc cách xử lý nên hard code 
                                //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                                var contractEntity = new Hre_ContractEntity
                                {
                                    //   ContractNo = getContractNo(item, item.DateSigned),
                                    ProfileID = item.ProfileID,
                                    ProfileName = item.ProfileName,
                                    DateStart = item.DateEnd.Value.AddDays(1),
                                    DateSigned = item.DateEnd.Value.AddDays(1),
                                    JobTitleID = item.JobTitleID,
                                    PositionID = item.PositionID,
                                    DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                    Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                    RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                    ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                    SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                    ContractTypeID = contractTypeEntity.ID
                                };

                                if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                                {
                                    contractEntity = SetNewDateEndContract(contractEntity);
                                }

                                if (item.DateEndNextContract != null)
                                {
                                    contractEntity.DateEnd = item.DateEndNextContract.Value;
                                }
                                if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                                {
                                    return Json(contractEntity, JsonRequestBehavior.AllowGet);
                                }
                                message = contractServices.Add(contractEntity);
                            }
                            else
                            {
                                contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                                //chưa tìm dc cách xử lý nên hard code 
                                //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                                var contractEntity = new Hre_ContractEntity
                                {
                                    //  ContractNo = getContractNo(item, item.DateSigned),
                                    ProfileID = item.ProfileID,
                                    ProfileName = item.ProfileName,
                                    DateStart = item.DateEnd.Value.AddDays(1),
                                    DateSigned = item.DateEnd.Value.AddDays(1),
                                    JobTitleID = item.JobTitleID,
                                    PositionID = item.PositionID,
                                    //   DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                    Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                    RankRateID = lstSalaryRankNew == null ? item.RankRateID : lstSalaryRankNew.ID,
                                    ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                    SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                    ContractTypeID = contractTypeEntity.ID
                                };

                                if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                                {
                                    contractEntity = SetNewDateEndContract(contractEntity);
                                }
                                if (item.DateEndNextContract != null)
                                {
                                    contractEntity.DateEnd = item.DateEndNextContract.Value;
                                }
                                if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                                {
                                    return Json(contractEntity, JsonRequestBehavior.AllowGet);
                                }
                                message = contractServices.Add(contractEntity);
                            }
                        }

                        #endregion

                        #region Xử Lý Sal_BasicSalary
                        var salaryEntity = new Sal_BasicSalaryEntity
                        {
                            ProfileID = item.ProfileID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                            DateOfEffect = item.DateEnd.Value.AddDays(1),
                            CurrencyID = lstCurrencyNew.ID,
                            Note = item.Remark


                        };
                        message = basicSalaryService.Add(salaryEntity);

                        #endregion

                        #region Xử Lý Hre_Profile
                        var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                        profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;

                        hrService.Edit(profileEntity);

                        if (workingHistoryEntity != null)
                        {
                            if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                            {
                                var workhistoryEntity = new Hre_WorkHistoryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    DateEffective = item.DateEnd.Value.AddDays(1)
                                };
                                message = workhistoryService.Add(workhistoryEntity);
                            }

                        }
                        else
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = item.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = item.DateEnd.Value.AddDays(1)
                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }

                        #endregion

                        #region Sal_Grade
                        var lstGradeByProfileID = lstSalGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (salGradeByProfileIDEntity != null)
                        {
                            if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                            {
                                var gradeEntity = new Sal_GradeEntity
                                {
                                    //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                    MonthStart = item.DateEnd.Value.AddDays(1)
                                };
                                message = gradeService.Add(gradeEntity);
                            }

                        }
                        else
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = item.DateEnd.Value.AddDays(1)
                            };
                            message = gradeService.Add(gradeEntity);
                        }

                        #endregion

                        #region Att_Grade
                        var lstAttGradeByProfileID = lstAttGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (attGradeByProfileIDEntity != null)
                        {
                            if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                            {
                                var gradeAttEntity = new Att_GradeEntity
                                {
                                    // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradeAttendanceID = lstAttGradeByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                    MonthStart = item.DateEnd.Value.AddDays(1)
                                };
                                message = attGradeService.Add(gradeAttEntity);
                            }
                        }
                        else
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = item.DateEnd.Value.AddDays(1)
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }


                        #endregion

                        #region Xử Lý Lương BHXH
                        if (contractTypeEntity.NoneTypeInsuarance == true)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = item.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = item.DateEnd.Value.AddDays(1),
                                IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                                IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                                IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                                CurrencyID = lstCurrencyNew.ID
                            };
                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                                insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                                insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }


                        }

                        if (contractTypeEntity.NoneTypeInsuarance == false)
                        {

                            var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            if (insuranceConfigEntity != null)
                            {
                                var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                                var insuranceEntity = new Sal_InsuranceSalaryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                    DateEffect = item.DateEnd.Value.AddDays(1),
                                    IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                    IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                    IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                    CurrencyID = lstCurrencyNew.ID
                                };

                                if (insuranceEntityByProfileID != null)
                                {
                                    insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                    insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                    insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                    insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                    message = insuranceServices.Edit(insuranceEntityByProfileID);
                                }
                                else
                                {
                                    message = insuranceServices.Add(insuranceEntity);
                                }

                            }
                        }
                        #endregion

                        //  return Json(message, JsonRequestBehavior.AllowGet);
                    }

                    if (item.ContractEvaType == EnumDropDown.ContractEvaType.E_ANNUAL_EVALUATION.ToString() && item.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
                    {

                        var lstSalaryRankNew = new Cat_SalaryRankEntity();
                        // var lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        if (item.RankDetailForNextContract != null)
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankDetailForNextContract != null && s.ID == item.RankDetailForNextContract.Value).FirstOrDefault();
                        }
                        else
                        {
                            lstSalaryRankNew = lstSalaryRank.Where(s => item.RankRateID != null && s.ID == item.RankRateID.Value).FirstOrDefault();
                        }

                        #region Xử lý Hre_Contract
                        int month = 0;
                        if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                        {
                            month = (int)contractTypeEntity.ValueTime.Value;
                            if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                            {
                                month = month * 12;
                            }
                            contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 

                            var contractEntity = new Hre_ContractEntity
                            {
                                // ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = item.ProfileID,
                                ProfileName = item.ProfileName,
                                DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                                DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                                JobTitleID = item.JobTitleID,
                                PositionID = item.PositionID,
                                DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID
                            };

                            if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                            {
                                contractEntity = SetNewDateEndContract(contractEntity);
                            }
                            if (item.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = item.DateEndNextContract.Value;
                            }
                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {
                                return Json(contractEntity, JsonRequestBehavior.AllowGet);
                            }
                            message = contractServices.Add(contractEntity);
                        }
                        else
                        {
                            contractTypeEntity.DateStart = item.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 

                            var contractEntity = new Hre_ContractEntity
                            {
                                // ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = item.ProfileID,
                                ProfileName = item.ProfileName,
                                DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                                DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                                JobTitleID = item.JobTitleID,
                                PositionID = item.PositionID,
                                // DateEnd = null,
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID
                            };

                            if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                            {
                                contractEntity = SetNewDateEndContract(contractEntity);
                            }

                            if (item.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = item.DateEndNextContract.Value;
                            }
                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {

                                return Json(contractEntity, JsonRequestBehavior.AllowGet);
                            }
                            message = contractServices.Add(contractEntity);
                        }
                        #endregion

                        #region Xử Lý Sal_BasicSalary
                        var salaryEntity = new Sal_BasicSalaryEntity
                        {
                            ProfileID = item.ProfileID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                            DateOfEffect = new DateTime(DateTime.Now.Year, 6, 1),
                            CurrencyID = lstCurrencyNew.ID,
                            Note = item.Remark

                        };
                        message = basicSalaryService.Add(salaryEntity);

                        #endregion

                        #region Xử Lý Hre_Profile
                        var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                        profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;
                        message = hrService.Edit(profileEntity);

                        if (workingHistoryEntity != null)
                        {
                            if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                            {
                                var workhistoryEntity = new Hre_WorkHistoryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                    DateEffective = new DateTime(DateTime.Now.Year, 6, 1)
                                };
                                message = workhistoryService.Add(workhistoryEntity);
                            }

                        }
                        else
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = item.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }
                        #endregion

                        #region Sal_Grade
                        var lstGradeByProfileID = lstSalGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (salGradeByProfileIDEntity != null)
                        {
                            if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                            {
                                var gradeEntity = new Sal_GradeEntity
                                {
                                    //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                    MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                                };
                                message = gradeService.Add(gradeEntity);
                            }
                        }
                        else
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //  ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = gradeService.Add(gradeEntity);
                        }


                        #endregion

                        #region Att_Grade
                        var lstAttGradeByProfileID = lstAttGrade.Where(s => item.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                        var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                        if (attGradeByProfileIDEntity != null)
                        {
                            if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                            {
                                var gradeAttEntity = new Att_GradeEntity
                                {
                                    //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                    ProfileID = item.ProfileID,
                                    GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                    MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                                };
                                message = attGradeService.Add(gradeAttEntity);
                            }
                        }
                        else
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = item.ProfileID,
                                GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }


                        #endregion

                        #region Xử Lý Lương BHXH
                        if (contractTypeEntity.NoneTypeInsuarance == true)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = item.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = item.DateEnd.Value.AddDays(1),
                                IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                                IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                                IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                                CurrencyID = lstCurrencyNew.ID
                            };

                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                                insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                                insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }
                        }
                        if (contractTypeEntity.NoneTypeInsuarance == false)
                        {
                            var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            if (insuranceConfigEntity != null)
                            {
                                var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == item.ProfileID && s.DateEffect == item.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                                var insuranceEntity = new Sal_InsuranceSalaryEntity
                                {
                                    ProfileID = item.ProfileID,
                                    InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                    DateEffect = item.DateEnd.Value.AddDays(1),
                                    IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                    IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                    IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                    CurrencyID = lstCurrencyNew.ID
                                };
                                if (insuranceEntityByProfileID != null)
                                {
                                    insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                    insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                    insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                    insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                    message = insuranceServices.Edit(insuranceEntityByProfileID);
                                }
                                else
                                {
                                    message = insuranceServices.Add(insuranceEntity);
                                }
                            }
                        }
                        #endregion

                    }
                }
            }
            return Json(message, JsonRequestBehavior.AllowGet);
            //   return null;
        }
Пример #6
0
        public ActionResult SaveContractAndBasicSalary([Bind]Hre_ContractModel model)
        {
            #region Validate

            string message_Error = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ContractModel>(model, "Hre_Contract", ref message_Error);
            if (!checkValidate)
            {
                model.ActionStatus = message_Error;
                return Json(message_Error, JsonRequestBehavior.AllowGet);
            }

            #endregion
            string status = string.Empty;
            Guid convertProfileID = Guid.Empty;
            var insuranceServices = new Sal_InsuranceSalaryServices();
            string message = string.Empty;
            List<Guid> lstProfileID = new List<Guid>();
            var ContractServices = new Hre_ContractServices();

            if (model.ProfileIDs != null && model.ProfileIDs.IndexOf(',') > 1)
            {
                var lstID = model.ProfileIDs.Split(',');
                for (int i = 0; i < lstID.Length; i++)
                {
                    convertProfileID = Common.ConvertToGuid(lstID[i]);
                    lstProfileID.Add(convertProfileID);
                }
            }
            else
            {
                convertProfileID = Common.ConvertToGuid(model.ProfileIDs);
                lstProfileID.Add(convertProfileID);
            }
            List<object> lstObjProfile = new List<object>();
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(null);
            lstObjProfile.Add(1);
            lstObjProfile.Add(int.MaxValue - 1);
            var actionService = new ActionService(UserLogin);
            var lstProfile = actionService.GetData<Hre_ProfileEntity>(lstObjProfile, ConstantSql.hrm_hr_sp_get_ProfileAll, ref status).ToList();
            lstProfile = lstProfile.Where(s => lstProfileID.Contains(s.ID) && s.IsDelete == null).ToList();

            var contractTypeService = new Cat_ContractTypeServices();
            var lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(int.MaxValue - 1);
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            foreach (var profile in lstProfile)
            {
                model.ProfileID = profile.ID;
                var contractTypeEntity = lstContractType.Where(s => s.ID == model.ContractTypeID).FirstOrDefault();
                #region Xử Lý Lương BHXH

                if (contractTypeEntity != null && contractTypeEntity.NoneTypeInsuarance == true)
                {
                    var insuranceEntity = new Sal_InsuranceSalaryEntity
                    {
                        ProfileID = model.ProfileID,
                        InsuranceAmount = model.InsuranceAmount,
                        DateEffect = model.DateStart,
                        IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                        IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                        IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                        CurrencyID = model.CurenncyID1
                    };
                    message = insuranceServices.Add(insuranceEntity);
                }
                #endregion
                if (model.CreateBasicSalary == true)
                {
                    Sal_BasicSalaryServices salaryservices = new Sal_BasicSalaryServices();
                    Sal_BasicSalaryEntity basicSalaryBycontract = new Sal_BasicSalaryEntity();

                    basicSalaryBycontract.ProfileID = profile.ID;
                    basicSalaryBycontract.GrossAmount = model.Salary != null ? model.Salary.ToString() : "0";
                    basicSalaryBycontract.CurrencyID = model.CurenncyID != null ? model.CurenncyID.Value : Guid.Empty;
                    basicSalaryBycontract.PersonalRate = model.PersonalRate;
                    basicSalaryBycontract.DateOfEffect = model.DateStart;

                    basicSalaryBycontract.InsuranceAmount = model.InsuranceAmount != null ? model.InsuranceAmount.Value : 0;
                    basicSalaryBycontract.CurrencyID1 = model.CurenncyID1;

                    basicSalaryBycontract.ClassRateID = model.ClassRateID;
                    basicSalaryBycontract.RankRateID = model.RankRateID;

                    basicSalaryBycontract.AllowanceType1ID = model.AllowanceID1;
                    basicSalaryBycontract.AllowanceAmount1 = model.Allowance1;
                    basicSalaryBycontract.CurrencyID2 = model.CurenncyID2;

                    basicSalaryBycontract.AllowanceType2ID = model.AllowanceID2;
                    basicSalaryBycontract.AllowanceAmount2 = model.Allowance2;
                    basicSalaryBycontract.CurrencyID3 = model.CurenncyID3;

                    basicSalaryBycontract.AllowanceType3ID = model.AllowanceID3;
                    basicSalaryBycontract.AllowanceAmount3 = model.Allowance3;
                    basicSalaryBycontract.CurrencyID4 = model.CurenncyIDSalary;

                    salaryservices.Add(basicSalaryBycontract);

                }

                if (model.BasicSalaryForPerson == true)
                {
                    List<object> listObj = new List<object>();
                    listObj.Add(1);
                    listObj.Add(1000);
                    var BasicSalaryServices = new Sal_BasicSalaryServices();
                    var lstBasicSalary = actionService.GetData<Sal_BasicSalaryEntity>(listObj, ConstantSql.hrm_sal_sp_get_BasicPayrollGetAll, ref status).Where(s => s.ProfileID == profile.ID && s.DateOfEffect != null).FirstOrDefault();
                    Hre_ContractEntity contractgetNo = new Hre_ContractEntity();
                    model.CopyData(contractgetNo);
                    Hre_ContractEntity contract = new Hre_ContractEntity
                    {
                        ID = model.ID,
                        Allowance = model.Allowance,
                        Allowance1 = model.Allowance1,
                        Allowance3 = model.Allowance3,
                        Allowance2 = model.Allowance2,
                        Allowance4 = model.Allowance4,
                        AllowanceID1 = lstBasicSalary.AllowanceType1ID,
                        AllowanceID2 = lstBasicSalary.AllowanceType2ID,
                        AllowanceID3 = lstBasicSalary.AllowanceType3ID,
                        AllowanceID4 = lstBasicSalary.AllowanceType4ID,
                        ClassRateID = lstBasicSalary.ClassRateID,
                        Code = model.Code,
                        CodeEmp = model.CodeEmp,
                        //ContractNo = getContractNo(contractgetNo, contractgetNo.DateSigned),
                        ContractTypeID = model.ContractTypeID,
                        CurenncyID = lstBasicSalary.CurrencyID,
                        CurenncyID1 = lstBasicSalary.CurrencyID1,
                        CurenncyID2 = lstBasicSalary.CurrencyID2,
                        CurenncyID3 = lstBasicSalary.CurrencyID3,
                        CurenncyID4 = lstBasicSalary.CurrencyID4,
                        CurenncyID5 = lstBasicSalary.CurrencyID5,
                        CurenncyIDSalary = model.CurenncyIDSalary,
                        CurenncyInsName = model.CurenncyInsName,
                        CurenncyOAllowanceName = model.CurenncyOAllowanceName,
                        CurrencySalName = model.CurrencySalName,
                        DateAuthorize = model.DateAuthorize,
                        DateCreate = model.DateCreate,
                        DateUpdate = DateTime.Now,
                        DateEnd = model.DateEnd,
                        DateSigned = model.DateSigned,
                        DateStart = model.DateStart,
                        FollowNo = model.FollowNo,
                        FormPaySalary = model.FormPaySalary,
                        HourWorkInMonth = model.HourWorkInMonth,
                        InsuranceAmount = model.InsuranceAmount,
                        IPCreate = model.IPCreate,
                        IPUpdate = model.IPUpdate,
                        JobTitleID = model.JobTitleID,
                        PersonalRate = model.PersonalRate,
                        PositionID = model.PositionID,
                        ProfileID = model.ProfileID,
                        ProfileSingID = model.ProfileSingID,
                        ProfileName = model.ProfileName,
                        ProfileSingName = model.ProfileSingName,
                        QualificationID = model.QualificationID,
                        RankRateID = lstBasicSalary.RankRateID,
                        Salary = lstBasicSalary == null ? (double?)null : Convert.ToDouble(lstBasicSalary.GrossAmount),
                        SalaryClassTypeID = lstBasicSalary.ClassRateID,
                        ServerCreate = model.ServerCreate,
                        ServerUpdate = model.ServerUpdate,
                        WorkPlaceID = model.WorkPlaceID,
                    };
                    if (contract.ID == Guid.Empty)
                    {
                        contract.ActionStatus = ContractServices.Add(contract);
                    }
                    else
                    {
                        contract.ActionStatus = ContractServices.Edit(contract);
                    }

                    return Json(contract, JsonRequestBehavior.AllowGet);
                }

                Hre_ContractEntity contractgetNoGetBasicSalary = new Hre_ContractEntity();
                model.CopyData(contractgetNoGetBasicSalary);
                Hre_ContractEntity contractNoGetBasicSalary = new Hre_ContractEntity
                {
                    ID = model.ID,
                    Allowance = model.Allowance,
                    Allowance1 = model.Allowance1,
                    Allowance3 = model.Allowance3,
                    Allowance2 = model.Allowance2,
                    Allowance4 = model.Allowance4,
                    AllowanceID1 = model.AllowanceID1,
                    AllowanceID2 = model.AllowanceID2,
                    AllowanceID3 = model.AllowanceID3,
                    AllowanceID4 = model.AllowanceID4,
                    ClassRateID = model.ClassRateID,
                    ClassRateName = model.ClassRateName,
                    Code = model.Code,
                    CodeEmp = model.CodeEmp,
                    // ContractNo = getContractNo(contractgetNoGetBasicSalary, contractgetNoGetBasicSalary.DateSigned),
                    ContractTypeID = model.ContractTypeID,
                    CurenncyID = model.CurenncyID,
                    CurenncyID1 = model.CurenncyID1,
                    CurenncyID2 = model.CurenncyID2,
                    CurenncyID3 = model.CurenncyID3,
                    CurenncyID4 = model.CurenncyID4,
                    CurenncyID5 = model.CurenncyID5,
                    CurenncyIDSalary = model.CurenncyIDSalary,
                    CurenncyInsName = model.CurenncyInsName,
                    CurenncyOAllowanceName = model.CurenncyOAllowanceName,
                    CurrencySalName = model.CurrencySalName,
                    DateAuthorize = model.DateAuthorize,
                    DateCreate = model.DateCreate,
                    DateEnd = model.DateEnd,
                    DateSigned = model.DateSigned,
                    DateStart = model.DateStart,
                    DateUpdate = DateTime.Now,
                    FollowNo = model.FollowNo,
                    FormPaySalary = model.FormPaySalary,
                    HourWorkInMonth = model.HourWorkInMonth,
                    InsuranceAmount = model.InsuranceAmount,
                    IPCreate = model.IPCreate,
                    IPUpdate = model.IPUpdate,
                    JobTitleID = model.JobTitleID,
                    PersonalRate = model.PersonalRate,
                    PositionID = model.PositionID,
                    ProfileID = model.ProfileID,
                    ProfileSingID = model.ProfileSingID,
                    ProfileName = model.ProfileName,
                    ProfileSingName = model.ProfileSingName,
                    QualificationID = model.QualificationID,
                    RankRateID = model.RankRateID,
                    Salary = model.Salary,
                    SalaryClassTypeID = model.SalaryClassTypeID,
                    ServerCreate = model.ServerCreate,
                    ServerUpdate = model.ServerUpdate,
                    WorkPlaceID = model.WorkPlaceID,
                };

                if (contractNoGetBasicSalary.ID == Guid.Empty)
                {
                    contractNoGetBasicSalary.ActionStatus = ContractServices.Add(contractNoGetBasicSalary);
                }
                else
                {
                    contractNoGetBasicSalary.ActionStatus = ContractServices.Edit(contractNoGetBasicSalary);
                }

                return Json(contractNoGetBasicSalary, JsonRequestBehavior.AllowGet);
            }
            return Json(message, JsonRequestBehavior.AllowGet);
        }
Пример #7
0
        public ActionResult SaveProfileIDs([Bind]Hre_ContractModel model)
        {
            #region Validate

            string message_Error = string.Empty;

            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ContractModel>(model, "Hre_Contract", ref message_Error);
            if (!checkValidate)
            {
                model.ActionStatus = message_Error;
                return Json(message_Error, JsonRequestBehavior.AllowGet);
            }
            if (model.ContractEvaType == "E_ANNUAL_EVALUATION")
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ContractModel>(model, "EvaContractinfo", "Hre_Contract", ref message_Error);
                if (!checkValidate)
                {
                    model.ActionStatus = message_Error;
                    return Json(message_Error, JsonRequestBehavior.AllowGet);
                }
            }

            #endregion
            string status = string.Empty;
            Guid convertProfileID = Guid.Empty;
            string message = string.Empty;
            List<Guid> lstProfileID = new List<Guid>();
            var insuranceServices = new Sal_InsuranceSalaryServices();
            var ContractServices = new Hre_ContractServices();
            var hrService = new Hre_ProfileServices();
            var actionService = new ActionService(UserLogin);
            if (model.ID == Guid.Empty)
            {
                model.DateExtend = model.DateEnd;
            }

            if (model.ProfileIDs != null && model.ProfileIDs.IndexOf(',') > 1)
            {
                var lstID = model.ProfileIDs.Split(',');
                for (int i = 0; i < lstID.Length; i++)
                {
                    convertProfileID = Common.ConvertToGuid(lstID[i]);
                    lstProfileID.Add(convertProfileID);
                }
            }

            else
            {
                convertProfileID = Common.ConvertToGuid(model.ProfileIDs);
                lstProfileID.Add(convertProfileID);
            }

            var lstProfile = new List<Hre_ProfileEntity>();
            if (model.ProfileIDs != null)
            {
                lstProfile = actionService.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status).ToList();
            }
            if (!string.IsNullOrEmpty(model.OrgStructureIDs))
            {
                List<Guid> listGuid = new List<Guid>();
                if (model.ProfileIDs != null)
                {
                    var listStr = model.ProfileIDs.Split(',');

                    if (listStr[0] != "")
                    {

                        foreach (var item in listStr)
                        {
                            listGuid.Add(Guid.Parse(item));
                        }
                    }
                }
                string strIDs = string.Empty;
                List<object> listObj = new List<object>();
                listObj.Add(model.OrgStructureIDs);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var lstProfileids = actionService.GetData<Hre_ProfileIdEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, ref status).Select(s => s.ID).ToList();
                if (listGuid != null)
                {
                    lstProfileids = lstProfileids.Where(s => !listGuid.Contains(s)).ToList();

                    foreach (var item in lstProfileids)
                    {
                        strIDs += Common.DotNetToOracle(item.ToString()) + ",";
                    }
                    if (strIDs.IndexOf(",") > 0)
                        strIDs = strIDs.Substring(0, strIDs.Length - 1);
                    var lstProfileadd = actionService.GetData<Hre_ProfileEntity>(strIDs, ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status);
                    lstProfile.AddRange(lstProfileadd);
                }
                if (lstProfileids.Count == 0 && model.ProfileID == Guid.Empty)
                {
                    model.ActionStatus = ConstantDisplay.HRM_Common_NotEmployee.TranslateString();
                    return Json(model.ActionStatus, JsonRequestBehavior.AllowGet);
                    lstProfile = lstProfile.Where(s => lstProfileids.Contains(s.ID)).ToList();
                }
            }

            var contractTypeService = new Cat_ContractTypeServices();
            var lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(int.MaxValue - 1);
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var insuranceConfigServices = new Cat_InsuranceConfigServices();
            var objInsuranceConfig = new List<object>();
            objInsuranceConfig.Add(1);
            objInsuranceConfig.Add(int.MaxValue - 1);
            var lstInsuranceConfig = actionService.GetData<Cat_InsuranceConfigEntity>(objInsuranceConfig, ConstantSql.hrm_cat_sp_get_InsuranceConfig, ref status).ToList();

            foreach (var profile in lstProfile)
            {
                model.ProfileID = profile.ID;
                var objContract = new List<object>();
                objContract.Add(model.ProfileID);
                var lstContractByProfileID = actionService.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
                var contractTypeEntity = lstContractType.Where(s => s.ID == model.ContractTypeID).FirstOrDefault();
                #region Xử Lý Lương BHXH

                if (contractTypeEntity != null && contractTypeEntity.NoneTypeInsuarance == true)
                {
                    var insuranceEntity = new Sal_InsuranceSalaryEntity
                    {
                        ProfileID = model.ProfileID,
                        InsuranceAmount = model.InsuranceAmount,
                        DateEffect = model.DateStart,
                        IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                        IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                        IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                        CurrencyID = model.CurenncyID1
                    };
                    message = insuranceServices.Add(insuranceEntity);
                }
                if (contractTypeEntity != null && contractTypeEntity.NoneTypeInsuarance == false)
                {
                    var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID == model.ContractTypeID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                    if (insuranceConfigEntity != null)
                    {
                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = model.ProfileID,
                            InsuranceAmount = model.InsuranceAmount,
                            DateEffect = model.DateStart,
                            IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                            IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                            IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                            CurrencyID = model.CurenncyID1
                        };
                        message = insuranceServices.Add(insuranceEntity);
                    }
                }
                #endregion
                if (model.CreateBasicSalary == true)
                {
                    Sal_BasicSalaryServices salaryservices = new Sal_BasicSalaryServices();
                    Sal_BasicSalaryEntity basicSalaryBycontract = new Sal_BasicSalaryEntity();

                    basicSalaryBycontract.ProfileID = profile.ID;
                    basicSalaryBycontract.GrossAmount = model.Salary != null ? model.Salary.ToString() : "0";
                    basicSalaryBycontract.CurrencyID = model.CurenncyID != null ? model.CurenncyID.Value : Guid.Empty;
                    basicSalaryBycontract.PersonalRate = model.PersonalRate;
                    basicSalaryBycontract.DateOfEffect = model.DateStart;

                    basicSalaryBycontract.InsuranceAmount = model.InsuranceAmount != null ? model.InsuranceAmount.Value : 0;
                    basicSalaryBycontract.CurrencyID1 = model.CurenncyID1;

                    basicSalaryBycontract.ClassRateID = model.ClassRateID;
                    basicSalaryBycontract.RankRateID = model.RankRateID;

                    basicSalaryBycontract.AllowanceType1ID = model.AllowanceID1;
                    basicSalaryBycontract.AllowanceAmount1 = model.Allowance1;
                    basicSalaryBycontract.CurrencyID2 = model.CurenncyID2;

                    basicSalaryBycontract.AllowanceType2ID = model.AllowanceID2;
                    basicSalaryBycontract.AllowanceAmount2 = model.Allowance2;
                    basicSalaryBycontract.CurrencyID3 = model.CurenncyID3;

                    basicSalaryBycontract.AllowanceType3ID = model.AllowanceID3;
                    basicSalaryBycontract.AllowanceAmount3 = model.Allowance3;
                    basicSalaryBycontract.CurrencyID4 = model.CurenncyIDSalary;

                    salaryservices.Add(basicSalaryBycontract);
                }

                if (model.BasicSalaryForPerson == true)
                {
                    List<object> listObj = new List<object>();
                    listObj.Add(1);
                    listObj.Add(1000);
                    var BasicSalaryServices = new Sal_BasicSalaryServices();
                    var basicSalaryByProfile = actionService.GetData<Sal_BasicSalaryEntity>(Common.DotNetToOracle(profile.ID.ToString()), ConstantSql.hrm_sal_sp_get_BasicSalaryByProfileIds, ref status).FirstOrDefault();
                    Hre_ContractEntity contractgetNo = new Hre_ContractEntity();
                    model.CopyData(contractgetNo);
                    Hre_ContractEntity contract = new Hre_ContractEntity();

                    contract.Allowance = model.Allowance;
                    contract.Allowance1 = model.Allowance1;
                    contract.Allowance2 = model.Allowance2;
                    contract.Allowance3 = model.Allowance3;
                    contract.Allowance4 = model.Allowance4;
                    if (basicSalaryByProfile != null)
                    {
                        contract.AllowanceID1 = basicSalaryByProfile.AllowanceType1ID != null ? basicSalaryByProfile.AllowanceType1ID : null;
                        contract.AllowanceID2 = basicSalaryByProfile.AllowanceType2ID != null ? basicSalaryByProfile.AllowanceType2ID : null;
                        contract.AllowanceID3 = basicSalaryByProfile.AllowanceType3ID != null ? basicSalaryByProfile.AllowanceType3ID : null;
                        contract.AllowanceID4 = basicSalaryByProfile.AllowanceType4ID != null ? basicSalaryByProfile.AllowanceType4ID : null;
                        contract.ClassRateID = basicSalaryByProfile.ClassRateID != null ? basicSalaryByProfile.ClassRateID : null;
                        contract.CurenncyID = basicSalaryByProfile.CurrencyID;
                        contract.CurenncyID1 = basicSalaryByProfile.CurrencyID1 != null ? basicSalaryByProfile.CurrencyID1 : null;
                        contract.CurenncyID2 = basicSalaryByProfile.CurrencyID2 != null ? basicSalaryByProfile.CurrencyID2 : null;
                        contract.CurenncyID3 = basicSalaryByProfile.CurrencyID3 != null ? basicSalaryByProfile.CurrencyID3 : null;
                        contract.CurenncyID4 = basicSalaryByProfile.CurrencyID4 != null ? basicSalaryByProfile.CurrencyID4 : null;
                        contract.CurenncyID5 = basicSalaryByProfile.CurrencyID5 != null ? basicSalaryByProfile.CurrencyID5 : null;
                    }
                    contract.Code = model.Code;
                    contract.CodeEmp = model.CodeEmp;
                    contract.ContractTypeID = model.ContractTypeID;
                    contract.CurenncyIDSalary = model.CurenncyIDSalary;
                    contract.CurenncyInsName = model.CurenncyInsName;
                    contract.CurenncyOAllowanceName = model.CurenncyOAllowanceName;
                    contract.CurrencySalName = model.CurrencySalName;
                    contract.DateAuthorize = model.DateAuthorize;
                    contract.DateCreate = model.DateCreate;
                    contract.DateUpdate = DateTime.Now;
                    contract.DateEnd = model.DateEnd;
                    contract.DateSigned = model.DateSigned;
                    contract.DateStart = model.DateStart;
                    contract.FollowNo = model.FollowNo;
                    contract.FormPaySalary = model.FormPaySalary;
                    contract.HourWorkInMonth = model.HourWorkInMonth;
                    contract.InsuranceAmount = model.InsuranceAmount;
                    contract.IPCreate = model.IPCreate;
                    contract.IPUpdate = model.IPUpdate;
                    contract.JobTitleID = model.JobTitleID;
                    contract.PersonalRate = model.PersonalRate;
                    contract.PositionID = model.PositionID;
                    contract.ProfileID = model.ProfileID;
                    contract.ProfileSingID = model.ProfileSingID;
                    contract.ProfileName = model.ProfileName;
                    contract.ProfileSingName = model.ProfileSingName;
                    contract.QualificationID = model.QualificationID;
                    contract.RankRateID = basicSalaryByProfile.RankRateID;
                    contract.Salary = basicSalaryByProfile == null ? (double?)null : Convert.ToDouble(basicSalaryByProfile.GrossAmount);
                    contract.ClassRateID = basicSalaryByProfile.ClassRateID;
                    contract.SalaryClassTypeID = model.SalaryClassTypeID;
                    contract.ServerCreate = model.ServerCreate;
                    contract.ServerUpdate = model.ServerUpdate;
                    contract.WorkPlaceID = model.WorkPlaceID;
                    contract.NextContractTypeID = model.NextContractTypeID;
                    contract.Remark = model.Remark;
                    contract.RankDetailForNextContract = model.RankDetailForNextContract;
                    contract.ContractEvaType = model.ContractEvaType;
                    contract.DateOfContractEva = model.DateOfContractEva;
                    contract.EvaluationResult = model.EvaluationResult;
                    contract.ContractResult = model.ContractResult;
                    contract.TypeOfPass = model.TypeOfPass;
                    contract.DateEndNextContract = model.DateEndNextContract;
                    contract.DateExtend = model.DateEnd;
                    contract.Status = HRM.Infrastructure.Utilities.EnumDropDown.Status.E_WAITING.ToString();

                    if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                    {
                        contract = SetNewDateEndContract(contract);
                    }
                    //Tạo mã cho hợp đồng
                    //   contract = SetNewCodeContract(contract, listIdContract);
                    if (contract.ID == Guid.Empty)
                    {
                        contract.ActionStatus = ContractServices.Add(contract);
                    }
                    else
                    {
                        contract.ActionStatus = ContractServices.Edit(contract);
                    }

                    return Json(contract, JsonRequestBehavior.AllowGet);
                }

                Hre_ContractEntity contractgetNoGetBasicSalary = new Hre_ContractEntity();
                model.CopyData(contractgetNoGetBasicSalary);
                Hre_ContractEntity contractNoGetBasicSalary = new Hre_ContractEntity();
                contractNoGetBasicSalary.Allowance = model.Allowance;
                contractNoGetBasicSalary.Allowance1 = model.Allowance1;
                contractNoGetBasicSalary.Allowance3 = model.Allowance3;
                contractNoGetBasicSalary.Allowance2 = model.Allowance2;
                contractNoGetBasicSalary.Allowance4 = model.Allowance4;
                contractNoGetBasicSalary.AllowanceID1 = model.AllowanceID1;
                contractNoGetBasicSalary.AllowanceID2 = model.AllowanceID2;
                contractNoGetBasicSalary.AllowanceID3 = model.AllowanceID3;
                contractNoGetBasicSalary.AllowanceID4 = model.AllowanceID4;
                contractNoGetBasicSalary.ClassRateID = model.ClassRateID;
                contractNoGetBasicSalary.ClassRateName = model.ClassRateName;
                contractNoGetBasicSalary.Code = model.Code;
                contractNoGetBasicSalary.CodeEmp = model.CodeEmp;
                contractNoGetBasicSalary.ContractTypeID = model.ContractTypeID;
                contractNoGetBasicSalary.CurenncyID = model.CurenncyID;
                contractNoGetBasicSalary.CurenncyID1 = model.CurenncyID1;
                contractNoGetBasicSalary.CurenncyID2 = model.CurenncyID2;
                contractNoGetBasicSalary.CurenncyID3 = model.CurenncyID3;
                contractNoGetBasicSalary.CurenncyID4 = model.CurenncyID4;
                contractNoGetBasicSalary.CurenncyID5 = model.CurenncyID5;
                contractNoGetBasicSalary.CurenncyIDSalary = model.CurenncyIDSalary;
                contractNoGetBasicSalary.CurenncyInsName = model.CurenncyInsName;
                contractNoGetBasicSalary.CurenncyOAllowanceName = model.CurenncyOAllowanceName;
                contractNoGetBasicSalary.CurrencySalName = model.CurrencySalName;
                contractNoGetBasicSalary.DateAuthorize = model.DateAuthorize;
                contractNoGetBasicSalary.DateCreate = model.DateCreate;
                contractNoGetBasicSalary.DateEnd = model.DateEnd;
                contractNoGetBasicSalary.DateSigned = model.DateSigned;
                contractNoGetBasicSalary.DateStart = model.DateStart;
                contractNoGetBasicSalary.DateUpdate = DateTime.Now;
                contractNoGetBasicSalary.FollowNo = model.FollowNo;
                contractNoGetBasicSalary.FormPaySalary = model.FormPaySalary;
                contractNoGetBasicSalary.HourWorkInMonth = model.HourWorkInMonth;
                contractNoGetBasicSalary.InsuranceAmount = model.InsuranceAmount;
                contractNoGetBasicSalary.IPCreate = model.IPCreate;
                contractNoGetBasicSalary.IPUpdate = model.IPUpdate;
                contractNoGetBasicSalary.JobTitleID = model.JobTitleID;
                contractNoGetBasicSalary.PersonalRate = model.PersonalRate;
                contractNoGetBasicSalary.PositionID = model.PositionID;
                contractNoGetBasicSalary.ProfileID = model.ProfileID;
                contractNoGetBasicSalary.ProfileSingID = model.ProfileSingID;
                contractNoGetBasicSalary.ProfileName = model.ProfileName;
                contractNoGetBasicSalary.ProfileSingName = model.ProfileSingName;
                contractNoGetBasicSalary.QualificationID = model.QualificationID;
                contractNoGetBasicSalary.RankRateID = model.RankRateID;
                contractNoGetBasicSalary.Salary = model.Salary;
                contractNoGetBasicSalary.SalaryClassTypeID = model.SalaryClassTypeID;
                contractNoGetBasicSalary.ServerCreate = model.ServerCreate;
                contractNoGetBasicSalary.ServerUpdate = model.ServerUpdate;
                contractNoGetBasicSalary.WorkPlaceID = model.WorkPlaceID;
                contractNoGetBasicSalary.NextContractTypeID = model.NextContractTypeID;
                contractNoGetBasicSalary.Remark = model.Remark;
                contractNoGetBasicSalary.RankDetailForNextContract = model.RankDetailForNextContract;
                contractNoGetBasicSalary.ContractEvaType = model.ContractEvaType;
                contractNoGetBasicSalary.DateOfContractEva = model.DateOfContractEva;
                contractNoGetBasicSalary.EvaluationResult = model.EvaluationResult;
                contractNoGetBasicSalary.ContractResult = model.ContractResult;
                contractNoGetBasicSalary.TypeOfPass = model.TypeOfPass;
                contractNoGetBasicSalary.DateEndNextContract = model.DateEndNextContract;
                contractNoGetBasicSalary.DateExtend = model.DateEnd;
                contractNoGetBasicSalary.Status = HRM.Infrastructure.Utilities.EnumDropDown.Status.E_WAITING.ToString();


                if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                {
                    contractNoGetBasicSalary = SetNewDateEndContract(contractNoGetBasicSalary);
                }
                //Tạo mã cho hợp đồng
                // contractNoGetBasicSalary = SetNewCodeContract(contractNoGetBasicSalary, listIdContract);
                if (contractNoGetBasicSalary.ID == Guid.Empty)
                {
                    contractNoGetBasicSalary.ActionStatus = ContractServices.Add(contractNoGetBasicSalary);
                }
                else
                {
                    contractNoGetBasicSalary.ActionStatus = ContractServices.Edit(contractNoGetBasicSalary);
                }

                message = contractNoGetBasicSalary.ActionStatus;
                return Json(contractNoGetBasicSalary, JsonRequestBehavior.AllowGet);

            }
            return Json(null, JsonRequestBehavior.AllowGet);
        }
Пример #8
0
        public ActionResult CheckAddNextContract(string ContractTypeID, string ContractID)
        {
            string status = string.Empty;
            var contractTypeID = Guid.Empty;
            Guid convertContractID = Guid.Empty;
            string AddMessage = string.Empty;
            List<Guid> lstContractID = new List<Guid>();
            if (!string.IsNullOrEmpty(ContractTypeID))
            {
                contractTypeID = Guid.Parse(ContractTypeID);
            }
            if (ContractID.IndexOf(",") > 1)
            {
                var lstID = ContractID.Split(',');
                for (int i = 0; i < lstID.Length; i++)
                {
                    convertContractID = Common.ConvertToGuid(lstID[i]);
                    lstContractID.Add(convertContractID);
                }
            }
            else
            {
                convertContractID = Common.ConvertToGuid(ContractID);
                lstContractID.Add(convertContractID);
            }

            ActionService service = new ActionService(UserLogin);
            var actionServices = new ActionService(UserLogin);
            var contractServices = new Hre_ContractServices();
            var objContract = new List<object>();
            objContract.AddRange(new object[21]);
            objContract[19] = 1;
            objContract[20] = int.MaxValue - 1;
            var lstContracts = actionServices.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_Contract, ref status).Where(s => lstContractID.Contains(s.ID)).ToList();
            var lstContract = service.GetData<Hre_ContractEntity>(convertContractID, ConstantSql.hrm_hr_sp_get_ContractById, ref status).FirstOrDefault();

            var contractTypeServices = new Cat_ContractTypeServices();
            List<object> lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(10000000);
            var lstContractType = actionServices.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status);

            List<object> listObj = new List<object>();

            listObj.Add(1);
            listObj.Add(1000);
            var BasicSalaryServices = new Sal_BasicSalaryServices();
            var lstBasicSalary = actionServices.GetData<Sal_BasicSalaryEntity>(listObj, ConstantSql.hrm_sal_sp_get_BasicPayrollGetAll, ref status).Where(s => s.ProfileID == lstContract.ProfileID && s.DateOfEffect <= lstContract.DateEnd).OrderByDescending(s => s.DateOfEffect).FirstOrDefault();

            foreach (var hreContract in lstContracts)
            {
                //   lstContractType = lstContractType.Where( s=> s.ID == hreContract.ContractTypeID).ToList();
                string contractnextID = lstContractType.Where(s => s.ID == hreContract.ContractTypeID).Select(s => s.ContractNextID).FirstOrDefault();
                if (contractnextID == null)
                {
                    AddMessage = "Error";
                    return Json(AddMessage);
                }
                else
                {
                    Guid contractTypeIDbyContractnext = Common.OracleToDotNet(contractnextID);
                    Hre_ContractEntity contract = new Hre_ContractEntity();
                    hreContract.CopyData(contract);

                    contract.ContractTypeID = contractTypeIDbyContractnext;
                    // contract.ContractNo = getContractNo(contract, contract.DateSigned ?? DateTime.Now);
                    if (contract.DateEnd != null)
                    {
                        contract.DateSigned = contract.DateStart = contract.DateEnd.Value.AddDays(1);
                    }
                    Cat_ContractTypeEntity catContractType = new Cat_ContractTypeEntity();

                    catContractType = lstContractType.Where(s => s.ID == contractTypeIDbyContractnext).FirstOrDefault();

                    if (catContractType != null)
                    {
                        int month = 0;
                        if (catContractType.ValueTime != null)
                        {
                            month = (int)catContractType.ValueTime.Value;
                        }
                        if (catContractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                        {
                            month = month * 12;
                        }

                        if (hreContract.DateEnd != null)
                        {
                            contract.DateStart = hreContract.DateEnd.Value.AddDays(1);

                            contract.DateEnd = contract.DateStart.AddMonths(month);
                        }
                    }
                    else
                    {
                        contract.DateEnd = null;
                    }
                    if (lstBasicSalary != null)
                    {
                        contract.InsuranceAmount = lstBasicSalary.InsuranceAmount;
                        contract.CurenncyID1 = lstBasicSalary.CurrencyID1;
                        contract.ClassRateID = lstBasicSalary.ClassRateID;
                        contract.RankRateID = lstBasicSalary.RankRateID;
                    }
                    //Add new
                    AddMessage = contractServices.Add(contract);
                    //AddMessage = "Success";
                }

            }
            return Json(AddMessage);

        }
Пример #9
0
        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));
        }
Пример #10
0
        public string SaveContractAndNextSalaryApprovedEvaluation(Hre_ContractEntity contract)
        {

            if (contract.DateEndNextContract == null)
            {
                return string.Empty;
            }

            // Lấy biến Dateend này gắn cho quá trình công tác khi cập nhật quá trinh công tác ở dưới
            DateTime? dateEnd = contract.DateEnd;

            string message = string.Empty;
            var actionService = new ActionService(UserLogin);
            string status = string.Empty;

            var profile = actionService.GetData<Hre_ProfileEntity>(contract.ProfileID, ConstantSql.hrm_hr_sp_get_ProfileById, ref status).FirstOrDefault();
            var hrService = new Hre_ProfileServices();
            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjSalaryRank = new List<object>();
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(null);
            lstObjSalaryRank.Add(1);
            lstObjSalaryRank.Add(int.MaxValue - 1);
            var lstSalaryRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjSalaryRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();

            var contractServices = new Hre_ContractServices();

            var workhistoryService = new Hre_WorkHistoryServices();
            var lstObjWorkhistory = new List<object>();
            lstObjWorkhistory.AddRange(new object[17]);
            lstObjWorkhistory[15] = 1;
            lstObjWorkhistory[16] = int.MaxValue - 1;
            var lstWorkhistory = actionService.GetData<Hre_WorkHistoryEntity>(lstObjWorkhistory, ConstantSql.hrm_hr_sp_get_WorkHistory, ref status).ToList();

            var basicSalaryService = new Sal_BasicSalaryServices();

            var attGradeService = new Att_GradeServices();
            var lstObjAttGrade = new List<object>();
            lstObjAttGrade.AddRange(new object[6]);
            lstObjAttGrade[4] = 1;
            lstObjAttGrade[5] = int.MaxValue - 1;
            var lstAttGrade = actionService.GetData<Att_GradeEntity>(lstObjAttGrade, ConstantSql.hrm_att_sp_get_Att_Grade, ref status).ToList();

            var gradeService = new Sal_GradeServices();
            var lstObjSalGrade = new List<object>();
            lstObjSalGrade.AddRange(new object[7]);
            lstObjSalGrade[5] = 1;
            lstObjSalGrade[6] = int.MaxValue - 1;
            var lstSalGrade = actionService.GetData<Sal_GradeEntity>(lstObjSalGrade, ConstantSql.hrm_sal_sp_get_Sal_Grade, ref status).ToList();

            var gradePayrollService = new Cat_GradePayrollServices();
            var lstObjGradePayroll = new List<object>();
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(null);
            lstObjGradePayroll.Add(1);
            lstObjGradePayroll.Add(int.MaxValue - 1);
            var lstGradePayroll = actionService.GetData<Cat_GradePayrollEntity>(lstObjGradePayroll, ConstantSql.hrm_cat_sp_get_GradePayroll, ref status).ToList();

            var gradeAttService = new Cat_GradeAttendanceServices();
            var lstObjGradeAtt = new List<object>();
            lstObjGradeAtt.AddRange(new object[10]);
            lstObjGradeAtt[8] = 1;
            lstObjGradeAtt[9] = int.MaxValue - 1;
            var lstGradeAtt = actionService.GetData<Cat_GradeAttendanceEntity>(lstObjGradeAtt, ConstantSql.hrm_cat_sp_get_Cat_GradeAttendance, ref status).ToList();

            var currencyServices = new Cat_CurrencyServices();
            var lstObjCurrency = new List<object>();
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(null);
            lstObjCurrency.Add(1);
            lstObjCurrency.Add(int.MaxValue - 1);
            var lstCurrency = actionService.GetData<Cat_CurrencyEntity>(lstObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, ref status).ToList();
            var lstCurrencyNew = lstCurrency.Where(s => s.CurrencyName == "VND").FirstOrDefault();

            var contractTypeService = new Cat_ContractTypeServices();
            var lstObjContractType = new List<object>();
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(null);
            lstObjContractType.Add(1);
            lstObjContractType.Add(int.MaxValue - 1);
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var insuranceConfigServices = new Cat_InsuranceConfigServices();
            var objInsuranceConfig = new List<object>();
            objInsuranceConfig.Add(1);
            objInsuranceConfig.Add(int.MaxValue - 1);
            var lstInsuranceConfig = actionService.GetData<Cat_InsuranceConfigEntity>(objInsuranceConfig, ConstantSql.hrm_cat_sp_get_InsuranceConfig, ref status).ToList();

            var insuranceServices = new Sal_InsuranceSalaryServices();
            var objInsurance = new List<object>();
            objInsurance.AddRange(new object[9]);
            objInsurance[7] = 1;
            objInsurance[8] = int.MaxValue - 1;
            var lstInsurance = actionService.GetData<Sal_InsuranceSalaryEntity>(objInsurance, ConstantSql.hrm_sal_sp_get_InsuranceSalary, ref status).ToList();


            var contractTypeEntity = new Cat_ContractTypeEntity();
            var objContract = new List<object>();
            objContract.Add(contract.ProfileID);
            var lstContractIdByProfileID = actionService.GetData<Hre_ContractEntity>(objContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
            var listIdContract = string.Empty;
            if (lstContractIdByProfileID != null)
            {
                listIdContract = string.Join(",", lstContractIdByProfileID.Select(d => d.ContractTypeID));
            }

            if (contract.NextContractTypeID != null)
            {
                contractTypeEntity = lstContractType.Where(s => contract.NextContractTypeID.Value == s.ID).FirstOrDefault();
            }
            else
            {
                message = ConstantMessages.WarningContractHaveNotNextContract.ToString().TranslateString();
                return message;
            }


            if (contractTypeEntity != null)
            {
                if (contractTypeEntity.Type == EnumDropDown.TypeContract.E_NODURATION.ToString())
                {
                    return string.Empty;
                }
            }

            var workingHistoryEntity = lstWorkhistory.Where(s => s.ProfileID == contract.ProfileID).FirstOrDefault();
            var objSalGrade = new List<object>();
            objSalGrade.Add(contract.ProfileID);
            objSalGrade.Add(null);
            objSalGrade.Add(1);
            objSalGrade.Add(int.MaxValue - 1);
            var salGradeByProfileIDEntity = actionService.GetData<Sal_GradeEntity>(objSalGrade, ConstantSql.hrm_sal_sp_get_GradeAndAllownaceByProId, ref status).FirstOrDefault();
            var objAttGrade = new List<object>();
            objAttGrade.Add(contract.ProfileID);
            objAttGrade.Add(null);
            objAttGrade.Add(1);
            objAttGrade.Add(int.MaxValue - 1);
            var attGradeByProfileIDEntity = actionService.GetData<Att_GradeEntity>(objAttGrade, ConstantSql.hrm_att_sp_get_GradeAttendanceByProIdCutID, ref status).FirstOrDefault();

            if (contractTypeEntity == null)
            {
                return string.Empty;
            }

            var contracttypeByContract = lstContractType.Where(s => s.ID == contract.ContractTypeID).FirstOrDefault();

            if (contract.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
            {
                if (contract.ContractEvaType == EnumDropDown.ContractEvaType.E_EXPIRED_APPRENTICE.ToString())
                {

                    //chưa tìm dc cách xử lý nên hard code 
                    var lstSalaryRankNew = new Cat_SalaryRankEntity();
                    if (contract.RankDetailForNextContract != null)
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankDetailForNextContract != null && s.ID == contract.RankDetailForNextContract.Value).FirstOrDefault();
                    }
                    else
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankRateID != null && s.ID == contract.RankRateID.Value).FirstOrDefault();
                    }

                    #region Xử lý Hre_Contract
                    if (contract.TypeOfPass == EnumDropDown.TypeOfPass.E_SIGNED_NEXTCONTRACT.ToString())
                    {
                        int month = 0;
                        if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                        {
                            month = (int)contractTypeEntity.ValueTime.Value;
                            if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                            {
                                month = month * 12;
                            }
                            contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 
                            //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                            var contractEntity = new Hre_ContractEntity
                            {
                                //   ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = contract.ProfileID,
                                ProfileName = contract.ProfileName,
                                DateStart = contract.DateEnd.Value.AddDays(1),
                                DateSigned = contract.DateEnd.Value.AddDays(1),
                                JobTitleID = contract.JobTitleID,
                                PositionID = contract.PositionID,
                                DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID,
                                DateEndNextContract = contract.DateEndNextContract,
                            };
                            if (contract.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = contract.DateEndNextContract.Value;
                            }
                            contractEntity = SetNewCodeContract(contractEntity, listIdContract);

                            #region Nếu là loại hđ xác định thời hạn thì update lại cột TimesContract theo task 0049731
                            if (contracttypeByContract != null && contracttypeByContract.Type == HRM.Infrastructure.Utilities.EnumDropDown.TypeContract.E_DURATION.ToString())
                            {
                                try
                                {
                                    string times = contractEntity.ContractNo.Substring(contractEntity.ContractNo.Length - 1, 1);
                                    int Year = int.Parse(times);
                                    contractEntity.TimesContract = Year;
                                }
                                catch
                                {
                                }
                            }
                            #endregion
                            contractEntity.Status = "E_APPROVED";
                            contractEntity.StatusEvaluation = "E_APPROVED";
                            contractEntity.DateExtend = contract.DateEnd;
                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {
                                return string.Empty;
                            }
                            message = contractServices.Add(contractEntity);
                        }
                        else
                        {
                            contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                            //chưa tìm dc cách xử lý nên hard code 
                            //  var nextContractTypeID = Common.ConvertToGuid(contractTypeEntity.ContractNextID).ToString();
                            var contractEntity = new Hre_ContractEntity
                            {
                                //  ContractNo = getContractNo(item, item.DateSigned),
                                ProfileID = contract.ProfileID,
                                ProfileName = contract.ProfileName,
                                DateStart = contract.DateEnd.Value.AddDays(1),
                                DateSigned = contract.DateEnd.Value.AddDays(1),
                                JobTitleID = contract.JobTitleID,
                                PositionID = contract.PositionID,
                                //   DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                                Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                                RankRateID = lstSalaryRankNew == null ? contract.RankRateID : lstSalaryRankNew.ID,
                                ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                                SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                                ContractTypeID = contractTypeEntity.ID
                            };

                            //if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                            //{
                            //    contractEntity = SetNewDateEndContract(contractEntity);
                            //}
                            if (contract.DateEndNextContract != null)
                            {
                                contractEntity.DateEnd = contract.DateEndNextContract.Value;
                            }
                            contractEntity.DateExtend = contract.DateEnd;
                            contractEntity.StatusEvaluation = "E_APPROVED";

                            if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                            {
                                return string.Empty;
                            }

                            message = contractServices.Add(contractEntity);
                        }
                    }

                    //Edit lai StatusEvaluation 
                    contract.StatusEvaluation = "E_APPROVED";
                    message = contractServices.Edit(contract);

                    #endregion

                    #region Xử Lý Sal_BasicSalary
                    var salaryEntity = new Sal_BasicSalaryEntity
                    {
                        ProfileID = contract.ProfileID,
                        ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                        RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                        GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                        DateOfEffect = contract.DateSigned != null ? contract.DateSigned.Value : DateTime.Now,
                        CurrencyID = lstCurrencyNew.ID,
                        Note = contract.Remark,
                        Status = "E_APPROVED"
                    };
                    message = basicSalaryService.Add(salaryEntity);

                    #endregion

                    #region Xử Lý Hre_Profile
                    var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                    Guid? _AbilityTileID = null;
                    profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;
                    if (profileEntity.SalaryClassID != null)
                    {
                        var abilityTitleBySalaryClass = hrService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(profileEntity.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                        if (abilityTitleBySalaryClass != null)
                        {
                            _AbilityTileID = abilityTitleBySalaryClass.ID;
                            profileEntity.AbilityTileID = _AbilityTileID;
                        }
                    }

                    hrService.Edit(profileEntity);

                    if (workingHistoryEntity != null)
                    {
                        if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = contract.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                                AbilityTileID = _AbilityTileID,
                                Status = "E_APPROVED"

                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }


                    }
                    else
                    {
                        var workhistoryEntity = new Hre_WorkHistoryEntity
                        {
                            ProfileID = contract.ProfileID,
                            SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                            Status = "E_APPROVED",

                        };
                        message = workhistoryService.Add(workhistoryEntity);
                    }

                    #endregion

                    #region Sal_Grade
                    var lstGradeByProfileID = lstSalGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (salGradeByProfileIDEntity != null)
                    {
                        if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = contract.DateSigned.Value,
                            };
                            message = gradeService.Add(gradeEntity);
                        }

                    }
                    else
                    {
                        var gradeEntity = new Sal_GradeEntity
                        {
                            //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                            MonthStart = contract.DateSigned.Value,
                        };
                        message = gradeService.Add(gradeEntity);
                    }

                    #endregion

                    #region Att_Grade
                    var lstAttGradeByProfileID = lstAttGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (attGradeByProfileIDEntity != null)
                    {
                        if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradeAttendanceID = lstAttGradeByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = contract.DateSigned.Value,
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }
                    }
                    else
                    {
                        var gradeAttEntity = new Att_GradeEntity
                        {
                            // ID = lstGradeAttByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                            MonthStart = contract.DateSigned.Value,
                        };
                        message = attGradeService.Add(gradeAttEntity);
                    }


                    #endregion

                    #region Xử Lý Lương BHXH
                    if (contractTypeEntity.NoneTypeInsuarance == true)
                    {
                        var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = contract.ProfileID,
                            InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                            DateEffect = contract.DateSigned != null ? contract.DateSigned.Value : DateTime.Now,
                            IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                            IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                            IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                            CurrencyID = lstCurrencyNew.ID
                        };
                        if (insuranceEntityByProfileID != null)
                        {
                            insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                            insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                            insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                            insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                            message = insuranceServices.Edit(insuranceEntityByProfileID);
                        }
                        else
                        {
                            message = insuranceServices.Add(insuranceEntity);
                        }


                    }

                    if (contractTypeEntity.NoneTypeInsuarance == false)
                    {

                        var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                        if (insuranceConfigEntity != null)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = contract.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = contract.DateSigned != null ? contract.DateSigned.Value : DateTime.Now,
                                IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                CurrencyID = lstCurrencyNew.ID
                            };

                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }

                        }
                    }
                    #endregion
                }

                if (contract.ContractEvaType == EnumDropDown.ContractEvaType.E_ANNUAL_EVALUATION.ToString() && contract.ContractResult == EnumDropDown.ResultContract.PASS.ToString())
                {
                    var lstSalaryRankNew = new Cat_SalaryRankEntity();
                    if (contract.RankDetailForNextContract != null)
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankDetailForNextContract != null && s.ID == contract.RankDetailForNextContract.Value).FirstOrDefault();
                    }
                    else
                    {
                        lstSalaryRankNew = lstSalaryRank.Where(s => contract.RankRateID != null && s.ID == contract.RankRateID.Value).FirstOrDefault();
                    }

                    #region Xử lý Hre_Contract
                    int month = 0;
                    if (contractTypeEntity != null && contractTypeEntity.ValueTime != null)
                    {
                        month = (int)contractTypeEntity.ValueTime.Value;
                        if (contractTypeEntity.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                        {
                            month = month * 12;
                        }
                        contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                        //chưa tìm dc cách xử lý nên hard code 

                        var contractEntity = new Hre_ContractEntity
                        {
                            // ContractNo = getContractNo(item, item.DateSigned),
                            ProfileID = contract.ProfileID,
                            ProfileName = contract.ProfileName,
                            DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                            DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                            JobTitleID = contract.JobTitleID,
                            PositionID = contract.PositionID,
                            DateEnd = contractTypeEntity.DateStart.Value.AddMonths(month),
                            Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                            SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                            ContractTypeID = contractTypeEntity.ID
                        };

                        //if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                        //{
                        //    contractEntity = SetNewDateEndContract(contractEntity);
                        //}
                        if (contract.DateEndNextContract != null)
                        {
                            contractEntity.DateEnd = contract.DateEndNextContract.Value;
                        }
                        contractEntity = SetNewCodeContract(contractEntity, listIdContract);

                        #region Nếu là loại hđ xác định thời hạn thì update lại cột TimesContract theo task 0049731
                        if (contracttypeByContract != null && contracttypeByContract.Type == HRM.Infrastructure.Utilities.EnumDropDown.TypeContract.E_DURATION.ToString())
                        {
                            try
                            {
                                string times = contractEntity.ContractNo.Substring(contractEntity.ContractNo.Length - 1, 1);
                                int Year = int.Parse(times);
                                contractEntity.TimesContract = Year;
                            }
                            catch
                            {
                            }
                        }
                        #endregion

                        contractEntity.Status = "E_APPROVED";
                        contractEntity.DateExtend = contract.DateEnd;
                        contractEntity.StatusEvaluation = "E_APPROVED";

                        if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                        {
                            return string.Empty;
                        }
                        message = contractServices.Add(contractEntity);
                    }
                    else
                    {
                        contractTypeEntity.DateStart = contract.DateEnd.Value.AddDays(1);

                        //chưa tìm dc cách xử lý nên hard code 

                        var contractEntity = new Hre_ContractEntity
                        {
                            // ContractNo = getContractNo(item, item.DateSigned),
                            ProfileID = contract.ProfileID,
                            ProfileName = contract.ProfileName,
                            DateStart = new DateTime(DateTime.Now.Year, 6, 1),
                            DateSigned = new DateTime(DateTime.Now.Year, 6, 1),
                            JobTitleID = contract.JobTitleID,
                            PositionID = contract.PositionID,
                            // DateEnd = null,
                            Salary = lstSalaryRankNew == null ? 0 : lstSalaryRankNew.SalaryStandard,
                            RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                            ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            ClassRateName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryClassName,
                            SalaryRankName = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryRankName,
                            ContractTypeID = contractTypeEntity.ID
                        };

                        //if (!string.IsNullOrEmpty(contractTypeEntity.Formula))
                        //{
                        //    contractEntity = SetNewDateEndContract(contractEntity);
                        //}

                        if (contract.DateEndNextContract != null)
                        {
                            contractEntity.DateEnd = contract.DateEndNextContract.Value;
                        }
                        contractEntity.DateExtend = contract.DateEnd;
                        contractEntity.StatusEvaluation = "E_APPROVED";
                        if (!string.IsNullOrEmpty(contractEntity.ErrorMessage))
                        {

                            return string.Empty;
                        }
                        message = contractServices.Add(contractEntity);
                    }
                    //Edit lai StatusEvaluation 
                    contract.StatusEvaluation = "E_APPROVED";
                    message = contractServices.Edit(contract);

                    #endregion

                    #region Xử Lý Sal_BasicSalary
                    var salaryEntity = new Sal_BasicSalaryEntity
                    {
                        ProfileID = contract.ProfileID,
                        ClassRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                        RankRateID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.ID,
                        GrossAmount = lstSalaryRankNew == null ? string.Empty : lstSalaryRankNew.SalaryStandard.ToString(),
                        DateOfEffect = new DateTime(DateTime.Now.Year, 6, 1),
                        CurrencyID = lstCurrencyNew.ID,
                        Note = contract.Remark,
                        Status = "E_APPROVED"

                    };
                    message = basicSalaryService.Add(salaryEntity);

                    #endregion

                    #region Xử Lý Hre_Profile
                    var profileEntity = profile.CopyData<Hre_ProfileEntity>();
                    profileEntity.SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID;
                    Guid? _AbilityTileID = null;
                    if (profileEntity.SalaryClassID != null)
                    {
                        var abilityTitleBySalaryClass = actionService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(profileEntity.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, ref status).FirstOrDefault();
                        if (abilityTitleBySalaryClass != null)
                        {
                            _AbilityTileID = abilityTitleBySalaryClass.ID;
                            profileEntity.AbilityTileID = _AbilityTileID;
                        }
                    }
                    message = hrService.Edit(profileEntity);
                    if (workingHistoryEntity != null)
                    {
                        if (workingHistoryEntity.SalaryClassID != lstSalaryRankNew.SalaryClassID)
                        {
                            var workhistoryEntity = new Hre_WorkHistoryEntity
                            {
                                ProfileID = contract.ProfileID,
                                SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                                DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                                AbilityTileID = _AbilityTileID,
                                Status = "E_APPROVED"
                            };
                            message = workhistoryService.Add(workhistoryEntity);
                        }
                    }
                    else
                    {
                        var workhistoryEntity = new Hre_WorkHistoryEntity
                        {
                            ProfileID = contract.ProfileID,
                            SalaryClassID = lstSalaryRankNew == null ? Guid.Empty : lstSalaryRankNew.SalaryClassID,
                            DateEffective = dateEnd != null ? dateEnd.Value.AddDays(1) : DateTime.Now,
                            Status = "E_APPROVED"

                        };
                        message = workhistoryService.Add(workhistoryEntity);
                    }
                    #endregion

                    #region Sal_Grade
                    var lstGradeByProfileID = lstSalGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradePayrollByProfileID = lstGradePayroll.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (salGradeByProfileIDEntity != null)
                    {
                        if (salGradeByProfileIDEntity.GradePayrollID != lstGradePayrollByProfileID.ID)
                        {
                            var gradeEntity = new Sal_GradeEntity
                            {
                                //   ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1),

                            };
                            message = gradeService.Add(gradeEntity);
                        }
                    }
                    else
                    {
                        var gradeEntity = new Sal_GradeEntity
                        {
                            //  ID = lstGradeByProfileID == null ? Guid.Empty : lstGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradePayrollID = lstGradePayrollByProfileID == null ? Guid.Empty : lstGradePayrollByProfileID.ID,
                            MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                        };
                        message = gradeService.Add(gradeEntity);
                    }


                    #endregion

                    #region Att_Grade
                    var lstAttGradeByProfileID = lstAttGrade.Where(s => contract.ProfileID == s.ProfileID).ToList().OrderByDescending(s => s.MonthEnd <= DateTime.Now).FirstOrDefault();
                    var lstGradeAttByProfileID = lstGradeAtt.Where(s => s.Code == lstSalaryRankNew.Code).FirstOrDefault();
                    if (attGradeByProfileIDEntity != null)
                    {
                        if (attGradeByProfileIDEntity.GradeAttendanceID != lstGradeAttByProfileID.ID)
                        {
                            var gradeAttEntity = new Att_GradeEntity
                            {
                                //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                                ProfileID = contract.ProfileID,
                                GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                                MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                            };
                            message = attGradeService.Add(gradeAttEntity);
                        }
                    }
                    else
                    {
                        var gradeAttEntity = new Att_GradeEntity
                        {
                            //ID = lstAttGradeByProfileID == null ? Guid.Empty: lstAttGradeByProfileID.ID,
                            ProfileID = contract.ProfileID,
                            GradeAttendanceID = lstGradeAttByProfileID == null ? Guid.Empty : lstGradeAttByProfileID.ID,
                            MonthStart = new DateTime(DateTime.Now.Year, 6, 1)
                        };
                        message = attGradeService.Add(gradeAttEntity);
                    }


                    #endregion

                    #region Xử Lý Lương BHXH
                    if (contractTypeEntity.NoneTypeInsuarance == true)
                    {
                        var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = contract.ProfileID,
                            InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                            DateEffect = contract.DateEnd.Value.AddDays(1),
                            IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance,
                            IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance,
                            IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance,
                            CurrencyID = lstCurrencyNew.ID,

                        };

                        if (insuranceEntityByProfileID != null)
                        {
                            insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                            insuranceEntityByProfileID.IsSocialIns = contractTypeEntity.IsSocialInsurance == null ? null : contractTypeEntity.IsSocialInsurance;
                            insuranceEntityByProfileID.IsUnimploymentIns = contractTypeEntity.IsUnEmployInsurance == null ? null : contractTypeEntity.IsUnEmployInsurance;
                            insuranceEntityByProfileID.IsMedicalIns = contractTypeEntity.IsHealthInsurance == null ? null : contractTypeEntity.IsHealthInsurance;
                            message = insuranceServices.Edit(insuranceEntityByProfileID);
                        }
                        else
                        {
                            message = insuranceServices.Add(insuranceEntity);
                        }
                    }
                    if (contractTypeEntity.NoneTypeInsuarance == false)
                    {
                        var insuranceConfigEntity = lstInsuranceConfig.Where(s => s.ContractTypeID != null && s.ContractTypeID.Value == contractTypeEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                        if (insuranceConfigEntity != null)
                        {
                            var insuranceEntityByProfileID = lstInsurance.Where(s => s.ProfileID == contract.ProfileID && s.DateEffect == contract.DateEnd.Value.AddDays(1)).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                            var insuranceEntity = new Sal_InsuranceSalaryEntity
                            {
                                ProfileID = contract.ProfileID,
                                InsuranceAmount = lstSalaryRankNew.SalaryStandard,
                                DateEffect = contract.DateEnd.Value.AddDays(1),
                                IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial,
                                IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy,
                                IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth,
                                CurrencyID = lstCurrencyNew.ID
                            };
                            if (insuranceEntityByProfileID != null)
                            {
                                insuranceEntityByProfileID.InsuranceAmount = lstSalaryRankNew.SalaryStandard;
                                insuranceEntityByProfileID.IsSocialIns = insuranceConfigEntity.IsSocial == null ? null : insuranceConfigEntity.IsSocial;
                                insuranceEntityByProfileID.IsUnimploymentIns = insuranceConfigEntity.IsUnEmploy == null ? null : insuranceConfigEntity.IsUnEmploy;
                                insuranceEntityByProfileID.IsMedicalIns = insuranceConfigEntity.IsHealth == null ? null : insuranceConfigEntity.IsHealth;
                                message = insuranceServices.Edit(insuranceEntityByProfileID);
                            }
                            else
                            {
                                message = insuranceServices.Add(insuranceEntity);
                            }
                        }
                    }
                    #endregion

                }
            }

            return message;
            //   return null;
        }
Пример #11
0
        public ActionResult UpdateDataForProfileWaiting(string SalaryClassName, string ProfileIDs, DateTime? DateEndProbation,
            DateTime DateHire, Guid OrgStructureID, Guid? SalaryRankID, Guid? WorkPlaceID, Guid ContractTypeID, string BasicSalary,
            Guid? GradePayrollID, Guid? GradeAttendanceID,

            Guid? jobTitleID, Guid? positionID, Guid? allowanceID1, Guid? allowanceID2, Guid? allowanceID3, Guid? allowanceID4, Guid? allowanceID5,
            double? allowance1, double? allowance2, double? allowance3, double? allowance4, double? allowance5, Guid? currencyID, double? insuranceSalary, string codeEmp)
        {
            var profileSevices = new Hre_ProfileServices();
            string message = string.Empty;
            string status = string.Empty;
            var actionService = new ActionService(UserLogin);
            var workingHistoryServices = new Hre_WorkHistoryServices();
            var basicSalaryServices = new Sal_BasicSalaryServices();
            var insServices = new Sal_InsuranceSalaryServices();
            var attGradeServices = new Att_GradeServices();
            var salGradeServices = new Sal_GradeServices();
            var contractServices = new Hre_ContractServices();
            var contractTypeServices = new Cat_ContractTypeServices();
            var currencyServices = new Cat_CurrencyServices();
            var settingServices = new Sys_AllSettingServices();

            var lstProfiles = actionService.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status);

            var candidateServices = new Hre_CandidateGeneralServices();
            var lstCandidateGeneral = actionService.GetData<Hre_CandidateGeneralEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_hr_sp_get_CandidateGeneralByProfileIDs, ref status).ToList();

            var salaryRankServices = new Cat_SalaryRankServices();
            var lstObjRank = new List<object>();
            lstObjRank.Add(null);
            lstObjRank.Add(null);
            lstObjRank.Add(1);
            lstObjRank.Add(int.MaxValue - 1);
            var lstRank = actionService.GetData<Cat_SalaryRankEntity>(lstObjRank, ConstantSql.hrm_cat_sp_get_SalaryRank, ref status).ToList();
            var rankEntity = lstRank.Where(s => s.ID == SalaryRankID).FirstOrDefault();

            Cat_SalaryClassEntity salaryClassEntity = null;
            if (rankEntity != null)
            {
                var salaryClassServices = new Cat_SalaryClassServices();
                var lstObjClass = new List<object>();
                lstObjClass.Add(null);
                lstObjClass.Add(1);
                lstObjClass.Add(int.MaxValue - 1);
                var salaryClass = actionService.GetData<Cat_SalaryClassEntity>(lstObjClass, ConstantSql.hrm_cat_sp_get_SalaryClass, ref status).ToList();
                salaryClassEntity = salaryClass.Where(s => rankEntity.SalaryClassID == s.ID).FirstOrDefault();
            }

            var lstObjContractType = new List<object>();
            lstObjContractType.AddRange(new object[6]);
            lstObjContractType[4] = 1;
            lstObjContractType[5] = int.MaxValue - 1;
            var lstContractType = actionService.GetData<Cat_ContractTypeEntity>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            var lstProfile = new List<Hre_ProfileEntity>();
            var workplaceServices = new Cat_WorkPlaceServices();
            var workplace = actionService.GetData<Cat_WorkPlaceEntity>(Common.DotNetToOracle(WorkPlaceID.ToString()), ConstantSql.hrm_cat_sp_get_WorkPlaceById, ref status).FirstOrDefault();

            var lstAttGrade = actionService.GetData<Att_GradeEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_Att_GradeByProfileIds, ref status).ToList();

            var lstSalGrade = actionService.GetData<Sal_GradeEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_Sal_GradeByProfileIds, ref status).ToList();

            var lstBasicSalary = actionService.GetData<Sal_BasicSalaryEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_BasicSalaryByProfileIds, ref status).ToList();

            var lstInsuranceSalary = actionService.GetData<Sal_InsuranceSalaryEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_sal_sp_get_InsuranceSalaryByProfileIds, ref status).ToList();

            var lstWorkingHistory = actionService.GetData<Hre_WorkHistoryEntity>(Common.DotNetToOracle(ProfileIDs), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileIds, ref status).ToList();

            foreach (var item in lstProfiles)
            {
                var candidateGeneralByProfile = lstCandidateGeneral.Where(s => s.ProfileID.Value == item.ID).FirstOrDefault();

                var objContract = new List<object>();
                var lstContractByProfileID = actionService.GetData<Hre_ContractEntity>(Common.DotNetToOracle(item.ID.ToString()), ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status);
                var listIdContract = string.Empty;
                if (lstContractByProfileID != null)
                {
                    listIdContract = string.Join(",", lstContractByProfileID.Select(d => d.ContractTypeID));
                }
                var contractType = lstContractType.Where(s => s.ID == ContractTypeID).FirstOrDefault();
                DateTime dateEnd = DateHire;
                if (contractType != null)
                {
                    if (contractType.ValueTime != null)
                    {
                        if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_MONTH.ToString())
                        {
                            dateEnd = DateHire.AddMonths(int.Parse(contractType.ValueTime.Value.ToString()));
                        }
                        else if (contractType.UnitTime == HRM.Infrastructure.Utilities.EnumDropDown.UnitType.E_YEAR.ToString())
                        {
                            dateEnd = DateHire.AddYears(int.Parse(contractType.ValueTime.Value.ToString()));
                        }
                    }
                }
                double Salary = 0;
                if (!string.IsNullOrEmpty(BasicSalary))
                    Salary = double.Parse(BasicSalary);
                if (candidateGeneralByProfile == null)
                {
                    #region Add CandidateGeneral
                    Hre_CandidateGeneralEntity candidateGeneral = new Hre_CandidateGeneralEntity();
                    candidateGeneral.ProfileID = item.ID;
                    candidateGeneral.BasicSalary = Salary;
                    candidateGeneral.RankRateID = SalaryRankID;
                    if (salaryClassEntity != null)
                    {
                        candidateGeneral.SalaryClassID = salaryClassEntity.ID;
                    }
                    candidateGeneral.ContractTypeID = ContractTypeID;
                    candidateGeneral.EnteringDate = DateHire;
                    candidateGeneral.OrgStructureID = OrgStructureID;
                    candidateGeneral.GradeAttendanceID = GradeAttendanceID;
                    candidateGeneral.GradePayrollID = GradePayrollID;
                    candidateGeneral.WorkPlaceID = WorkPlaceID;
                    candidateGeneral.JobTitleID = jobTitleID;
                    candidateGeneral.PositionID = positionID;
                    candidateGeneral.AllowanceID1 = allowanceID1;
                    candidateGeneral.AllowanceID2 = allowanceID2;
                    candidateGeneral.AllowanceID3 = allowanceID3;
                    candidateGeneral.AllowanceID4 = allowanceID4;
                    candidateGeneral.AllowanceID5 = allowanceID5;
                    candidateGeneral.Allowance1 = allowance1;
                    candidateGeneral.Allowance2 = allowance2;
                    candidateGeneral.Allowance3 = allowance3;
                    candidateGeneral.Allowance4 = allowance4;
                    candidateGeneral.Allowance5 = allowance5;
                    candidateGeneral.CurrencyID = currencyID;
                    candidateGeneral.CodeEmp = codeEmp;
                    message = candidateServices.Add(candidateGeneral);

                    #endregion

                    #region Add Contract
                    //Add new contract

                    Hre_ContractEntity Contract = new Hre_ContractEntity();
                    Contract.ProfileID = item.ID;
                    Contract.Salary = Salary;
                    Contract.ContractTypeID = ContractTypeID;
                    Contract.DateStart = DateHire;
                    Contract.DateSigned = DateHire;
                    Contract.RankRateID = SalaryRankID;
                    if (salaryClassEntity != null)
                    {
                        Contract.ClassRateID = salaryClassEntity.ID;
                    }

                    Contract.InsuranceAmount = insuranceSalary;
                    Contract.AllowanceID1 = allowanceID1;
                    Contract.AllowanceID2 = allowanceID2;
                    Contract.AllowanceID3 = allowanceID3;
                    Contract.AllowanceID4 = allowanceID4;
                    Contract.Allowance1 = allowance1;
                    Contract.Allowance2 = allowance2;
                    Contract.Allowance3 = allowance3;
                    Contract.Allowance4 = allowance4;
                    Contract.Allowance = allowance5;

                    Contract.CurenncyID = currencyID;
                    Contract.CurenncyID1 = currencyID;
                    Contract.CurenncyID2 = currencyID;
                    Contract.CurenncyID3 = currencyID;
                    Contract.CurenncyIDSalary = currencyID;
                    Contract.CurenncyID4 = currencyID;
                    Contract.CurenncyID5 = currencyID;
                    Contract.Status = HRM.Infrastructure.Utilities.EnumDropDown.Status.E_WAITING.ToString();
                    Contract.JobTitleID = jobTitleID;
                    Contract.PositionID = positionID;

                    if (!string.IsNullOrEmpty(contractType.Formula))
                    {
                        Contract = SetNewDateEndContract(Contract);
                    }
                    Contract.DateExtend = Contract.DateEnd;
                    //   Contract = SetNewCodeContract(Contract, listIdContract);
                    message = contractServices.Add(Contract);
                    #endregion

                    #region Edit Profile
                    //Edit Profile
                    item.OrgStructureID = OrgStructureID;
                    if (salaryClassEntity != null)
                    {
                        item.SalaryClassID = salaryClassEntity.ID;
                    }
                    item.DateOfEffect = DateHire;
                    item.DateHire = DateHire;
                    item.DateEndProbation = Contract.DateEnd.Value;
                    item.WorkPlaceID = WorkPlaceID;
                    item.ContractTypeID = ContractTypeID;
                    item.CodeEmp = codeEmp;
                    item.StatusSyn = ProfileStatusSyn.E_WAITING.ToString();

                    message = profileSevices.Edit(item);
                    #endregion

                    #region Add Sal_Insurance
                    // Add Insurance
                    if (contractType != null && contractType.NoneTypeInsuarance == true)
                    {
                        var insuranceEntity = new Sal_InsuranceSalaryEntity
                        {
                            ProfileID = item.ID,
                            InsuranceAmount = insuranceSalary,
                            DateEffect = DateHire,
                            IsSocialIns = contractType.IsSocialInsurance == null ? null : contractType.IsSocialInsurance,
                            IsUnimploymentIns = contractType.IsUnEmployInsurance == null ? null : contractType.IsUnEmployInsurance,
                            IsMedicalIns = contractType.IsHealthInsurance == null ? null : contractType.IsHealthInsurance,
                            CurrencyID = currencyID
                        };
                        message = insServices.Add(insuranceEntity);
                    }
                    #endregion

                    #region Add Sal_BasicSalary
                    Sal_BasicSalaryEntity basicSalaryEntity = new Sal_BasicSalaryEntity();
                    basicSalaryEntity.ProfileID = item.ID;
                    basicSalaryEntity.GrossAmount = BasicSalary;
                    basicSalaryEntity.Amount = BasicSalary.Encrypt();
                    basicSalaryEntity.DateOfEffect = DateHire;
                    basicSalaryEntity.RankRateID = SalaryRankID;
                    basicSalaryEntity.CurrencyID = currencyID.Value;
                    if (salaryClassEntity != null)
                    {
                        basicSalaryEntity.ClassRateID = salaryClassEntity.ID;
                    }

                    basicSalaryEntity.AllowanceType1ID = allowanceID1;
                    basicSalaryEntity.AllowanceType2ID = allowanceID2;
                    basicSalaryEntity.AllowanceType3ID = allowanceID3;
                    basicSalaryEntity.AllowanceType4ID = allowanceID4;
                    basicSalaryEntity.AllowanceTypeID5 = allowanceID5;

                    basicSalaryEntity.AllowanceAmount1 = allowance1;
                    basicSalaryEntity.AllowanceAmount2 = allowance2;
                    basicSalaryEntity.AllowanceAmount3 = allowance3;
                    basicSalaryEntity.AllowanceAmount4 = allowance4;
                    basicSalaryEntity.AllowanceAmount5 = allowance5;

                    basicSalaryEntity.CurrencyID5 = currencyID;
                    basicSalaryEntity.CurrencyID2 = currencyID;
                    basicSalaryEntity.CurrencyID3 = currencyID;
                    basicSalaryEntity.CurrencyID4 = currencyID;
                    if (insuranceSalary != null)
                    {
                        basicSalaryEntity.InsuranceAmount = insuranceSalary.Value;
                    }

                    message = basicSalaryServices.Add(basicSalaryEntity);
                    #endregion

                    #region Add WorkHistory
                    Hre_WorkHistoryEntity workHistory = new Hre_WorkHistoryEntity();
                    workHistory.ProfileID = item.ID;
                    workHistory.DateEffective = DateHire;
                    if (salaryClassEntity != null)
                    {
                        workHistory.SalaryClassID = salaryClassEntity.ID;
                    }
                    workHistory.OrganizationStructureID = OrgStructureID;
                    workHistory.WorkLocation = workplace != null ? workplace.WorkPlaceName : null;
                    workHistory.JobTitleID = jobTitleID;
                    workHistory.PositionID = positionID;

                    message = workingHistoryServices.Add(workHistory);
                    #endregion

                    #region Add Att_Grade
                    Att_GradeEntity attGradeEntity = new Att_GradeEntity();
                    attGradeEntity.ProfileID = item.ID;
                    attGradeEntity.GradeAttendanceID = GradeAttendanceID;
                    attGradeEntity.MonthStart = DateHire;
                    message = attGradeServices.Add(attGradeEntity);
                    #endregion

                    #region Add Sal_Grade
                    Sal_GradeEntity salGradeEntity = new Sal_GradeEntity();
                    salGradeEntity.ProfileID = item.ID;
                    salGradeEntity.GradePayrollID = GradePayrollID;
                    salGradeEntity.MonthStart = DateHire;
                    message = salGradeServices.Add(salGradeEntity);
                    #endregion

                }
                else
                {
                    #region Edit CandidateGeneral

                    candidateGeneralByProfile.ProfileID = item.ID;
                    candidateGeneralByProfile.BasicSalary = Salary;
                    candidateGeneralByProfile.RankRateID = SalaryRankID;
                    if (salaryClassEntity != null)
                    {
                        candidateGeneralByProfile.SalaryClassID = salaryClassEntity.ID;
                    }
                    candidateGeneralByProfile.ContractTypeID = ContractTypeID;
                    candidateGeneralByProfile.EnteringDate = DateHire;
                    candidateGeneralByProfile.OrgStructureID = OrgStructureID;
                    candidateGeneralByProfile.GradeAttendanceID = GradeAttendanceID;
                    candidateGeneralByProfile.GradePayrollID = GradePayrollID;
                    candidateGeneralByProfile.WorkPlaceID = WorkPlaceID;
                    candidateGeneralByProfile.JobTitleID = jobTitleID;
                    candidateGeneralByProfile.PositionID = positionID;
                    candidateGeneralByProfile.AllowanceID1 = allowanceID1;
                    candidateGeneralByProfile.AllowanceID2 = allowanceID2;
                    candidateGeneralByProfile.AllowanceID3 = allowanceID3;
                    candidateGeneralByProfile.AllowanceID4 = allowanceID4;
                    candidateGeneralByProfile.AllowanceID5 = allowanceID5;
                    candidateGeneralByProfile.Allowance1 = allowance1;
                    candidateGeneralByProfile.Allowance2 = allowance2;
                    candidateGeneralByProfile.Allowance3 = allowance3;
                    candidateGeneralByProfile.Allowance4 = allowance4;
                    candidateGeneralByProfile.Allowance5 = allowance5;
                    candidateGeneralByProfile.CurrencyID = currencyID;
                    candidateGeneralByProfile.CodeEmp = codeEmp;
                    message = candidateServices.Edit(candidateGeneralByProfile);

                    #endregion

                    #region Edit Contract
                    if (lstContractByProfileID != null)
                    {
                        var contractEntityByProfileID = lstContractByProfileID.FirstOrDefault();
                        if (contractEntityByProfileID != null)
                        {
                            contractEntityByProfileID.Salary = Salary;
                            contractEntityByProfileID.ContractTypeID = ContractTypeID;
                            contractEntityByProfileID.DateStart = DateHire;
                            contractEntityByProfileID.DateSigned = DateHire;
                            contractEntityByProfileID.DateEnd = dateEnd;
                            contractEntityByProfileID.RankRateID = SalaryRankID;
                            if (salaryClassEntity != null)
                            {
                                contractEntityByProfileID.ClassRateID = salaryClassEntity.ID;
                            }

                            contractEntityByProfileID.InsuranceAmount = insuranceSalary;
                            contractEntityByProfileID.AllowanceID1 = allowanceID1;
                            contractEntityByProfileID.AllowanceID2 = allowanceID2;
                            contractEntityByProfileID.AllowanceID3 = allowanceID3;
                            contractEntityByProfileID.AllowanceID4 = allowanceID4;
                            contractEntityByProfileID.Allowance1 = allowance1;
                            contractEntityByProfileID.Allowance2 = allowance2;
                            contractEntityByProfileID.Allowance3 = allowance3;
                            contractEntityByProfileID.Allowance4 = allowance4;
                            contractEntityByProfileID.Allowance = allowance5;
                            contractEntityByProfileID.CurenncyID = currencyID;
                            contractEntityByProfileID.CurenncyID1 = currencyID;
                            contractEntityByProfileID.CurenncyID2 = currencyID;
                            contractEntityByProfileID.CurenncyID3 = currencyID;
                            contractEntityByProfileID.CurenncyIDSalary = currencyID;
                            contractEntityByProfileID.CurenncyID4 = currencyID;
                            contractEntityByProfileID.CurenncyID5 = currencyID;
                            contractEntityByProfileID.Status = HRM.Infrastructure.Utilities.EnumDropDown.Status.E_WAITING.ToString();
                            contractEntityByProfileID.JobTitleID = jobTitleID;
                            contractEntityByProfileID.PositionID = positionID;
                            if (!string.IsNullOrEmpty(contractType.Formula))
                            {
                                contractEntityByProfileID = SetNewDateEndContract(contractEntityByProfileID);
                            }
                            if (contractEntityByProfileID.DateExtend == null)
                            {
                                contractEntityByProfileID.DateExtend = dateEnd;
                            }
                            message = contractServices.Edit(contractEntityByProfileID);
                            if (contractEntityByProfileID.DateEnd != null)
                            {
                                item.DateEndProbation = contractEntityByProfileID.DateEnd.Value;
                            }
                        }
                    }

                    #endregion

                    #region Edit Profile
                    //Edit Profile
                    item.OrgStructureID = OrgStructureID;
                    if (salaryClassEntity != null)
                    {
                        item.SalaryClassID = salaryClassEntity.ID;
                    }
                    item.DateOfEffect = DateHire;
                    item.DateHire = DateHire;
                    item.WorkPlaceID = WorkPlaceID;
                    item.ContractTypeID = ContractTypeID;
                    item.StatusSyn = ProfileStatusSyn.E_WAITING.ToString();
                    item.CodeEmp = codeEmp;
                    message = profileSevices.Edit(item);
                    #endregion

                    #region Edit Sal_Insurance
                    var insSalaryEntityByProfileID = lstInsuranceSalary.Where(s => s.ProfileID == item.ID).OrderBy(s => s.DateUpdate).FirstOrDefault();
                    if (insSalaryEntityByProfileID != null)
                    {
                        if (contractType != null && contractType.NoneTypeInsuarance == true)
                        {
                            insSalaryEntityByProfileID.InsuranceAmount = insuranceSalary;
                            insSalaryEntityByProfileID.DateEffect = DateHire;
                            insSalaryEntityByProfileID.IsSocialIns = contractType.IsSocialInsurance == null ? null : contractType.IsSocialInsurance;
                            insSalaryEntityByProfileID.IsUnimploymentIns = contractType.IsUnEmployInsurance == null ? null : contractType.IsUnEmployInsurance;
                            insSalaryEntityByProfileID.IsMedicalIns = contractType.IsHealthInsurance == null ? null : contractType.IsHealthInsurance;
                            insSalaryEntityByProfileID.CurrencyID = currencyID;

                            message = insServices.Edit(insSalaryEntityByProfileID);
                        }
                    }
                    #endregion

                    #region Edit Sal_BasicSalary
                    var basicSalaryEntityByProfileID = lstBasicSalary.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (basicSalaryEntityByProfileID != null)
                    {
                        basicSalaryEntityByProfileID.GrossAmount = BasicSalary;
                        basicSalaryEntityByProfileID.Amount = BasicSalary.Encrypt();
                        basicSalaryEntityByProfileID.DateOfEffect = DateHire;
                        basicSalaryEntityByProfileID.RankRateID = SalaryRankID;
                        if (salaryClassEntity != null)
                        {
                            basicSalaryEntityByProfileID.ClassRateID = salaryClassEntity.ID;
                        }
                        basicSalaryEntityByProfileID.CurrencyID = currencyID.Value;
                        basicSalaryEntityByProfileID.AllowanceType1ID = allowanceID1;
                        basicSalaryEntityByProfileID.AllowanceType2ID = allowanceID2;
                        basicSalaryEntityByProfileID.AllowanceType3ID = allowanceID3;
                        basicSalaryEntityByProfileID.AllowanceType4ID = allowanceID4;
                        basicSalaryEntityByProfileID.AllowanceTypeID5 = allowanceID5;
                        basicSalaryEntityByProfileID.AllowanceAmount1 = allowance1;
                        basicSalaryEntityByProfileID.AllowanceAmount2 = allowance2;
                        basicSalaryEntityByProfileID.AllowanceAmount3 = allowance3;
                        basicSalaryEntityByProfileID.AllowanceAmount4 = allowance4;
                        basicSalaryEntityByProfileID.AllowanceAmount5 = allowance5;
                        basicSalaryEntityByProfileID.CurrencyID5 = currencyID;
                        basicSalaryEntityByProfileID.CurrencyID2 = currencyID;
                        basicSalaryEntityByProfileID.CurrencyID3 = currencyID;
                        basicSalaryEntityByProfileID.CurrencyID4 = currencyID;
                        if (insuranceSalary != null)
                        {
                            basicSalaryEntityByProfileID.InsuranceAmount = insuranceSalary.Value;
                        }
                        message = basicSalaryServices.Edit(basicSalaryEntityByProfileID);
                    }
                    #endregion

                    #region Edit WorkingHistory
                    var workingByProfileID = lstWorkingHistory.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (workingByProfileID != null)
                    {
                        workingByProfileID.DateEffective = DateHire;
                        if (salaryClassEntity != null)
                        {
                            workingByProfileID.SalaryClassID = salaryClassEntity.ID;
                        }
                        workingByProfileID.OrganizationStructureID = OrgStructureID;
                        workingByProfileID.WorkLocation = workplace != null ? workplace.WorkPlaceName : null;
                        workingByProfileID.JobTitleID = jobTitleID;
                        workingByProfileID.PositionID = positionID;
                        message = workingHistoryServices.Edit(workingByProfileID);
                    }
                    #endregion

                    #region Edit Att_Grade
                    var attGradeEntityByProfileID = lstAttGrade.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (attGradeEntityByProfileID != null)
                    {
                        attGradeEntityByProfileID.GradeAttendanceID = GradeAttendanceID;
                        attGradeEntityByProfileID.MonthStart = DateHire;
                        message = attGradeServices.Edit(attGradeEntityByProfileID);
                    }
                    #endregion

                    #region Edit Sal_Grade
                    var salGradeEntityByProfileID = lstSalGrade.Where(s => s.ProfileID == item.ID).FirstOrDefault();
                    if (salGradeEntityByProfileID != null)
                    {
                        salGradeEntityByProfileID.GradePayrollID = GradePayrollID;
                        salGradeEntityByProfileID.MonthStart = DateHire;
                        message = salGradeServices.Edit(salGradeEntityByProfileID);
                    }
                    #endregion
                }
            }


            return Json(message, JsonRequestBehavior.AllowGet);
        }
Пример #12
0
        public string ApplyPerformance(Guid? profileID, Guid? rankdetailID, DateTime? dateEffect,string userLogin)
        {
            using (var context = new VnrHrmDataContext())
            {
                string result = ConstantMessages.Succeed;
                var profileservices = new Hre_ProfileServices();
                BaseService service = new BaseService();
                string message = string.Empty;
                string status = string.Empty;
                var contractservices = new Hre_ContractServices();
                var basicSalaryServices = new Sal_BasicSalaryServices();
                var InsuranceSalaryServices = new Sal_InsuranceSalaryServices();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCandidate = new Rec_CandidateRepository(unitOfWork);
                var repoHistory = new Rec_RecruitmentHistoryRepository(unitOfWork);
                var profile = service.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, userLogin, ref status).FirstOrDefault();
                var salaryRank = service.GetData<Cat_SalaryRankEntity>(Common.DotNetToOracle(rankdetailID.ToString()), ConstantSql.hrm_cat_sp_get_SalaryRankById, userLogin, ref status).FirstOrDefault();

                Guid? _AbilitiTitleID = null;
                if (salaryRank != null && salaryRank.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = service.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(salaryRank.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, userLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        _AbilitiTitleID = abilityTitleBySalaryClass.ID;
                    }
                }

                // theo task 0049950 - không làm gì liên quan đến hđ hết.
                //var contractybyProfile = service.GetData<Hre_ContractEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_ContractsByProfileId, userLogin, ref status)
                //    .OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                ////if (contractybyProfile == null)
                ////{
                ////    result = ConstantDisplay.HRM_Common_ProfileNotHaveContract.ToString();
                ////    return result;
                ////}
                ////if (contractybyProfile != null && contractybyProfile.ContractNextID == null)
                ////{
                ////    result = ConstantDisplay.HRM_Common_ProfileNotHaveNextContract.ToString();
                ////    return result;
                ////}
                //if (contractybyProfile != null && contractybyProfile.ContractNextID != null)
                //{
                    //var contractype = service.GetData<Cat_ContractTypeEntity>(Guid.Parse(Common.DotNetToOracle(contractybyProfile.ContractNextID.ToString())), ConstantSql.hrm_cat_sp_get_ContractTypeById, userLogin, ref status).FirstOrDefault();
                    //if (contractype == null)
                    //{
                    //    result = ConstantDisplay.HRM_Common_ProfileNotHaveNextContract.ToString();
                    //    return result;
                    //}
                    //Hre_ContractEntity contract = new Hre_ContractEntity();
                    //contract.ProfileID = profile.ID;
                    //contract.DateStart = dateEffect.Value;
                    //contract.DateSigned = dateEffect;
                    //contract.RankRateID = rankdetailID;
                    //contract.ClassRateID = salaryRank != null ? salaryRank.SalaryClassID : null;
                    //contract.Salary = salaryRank != null ? salaryRank.SalaryStandard : null;
                    //contract.ContractTypeID = contractype.ID;
                    //if (!string.IsNullOrEmpty(contractype.Formula))
                    //{
                    //    contract = SetNewDateEndContract(contract,userLogin);
                    //}

                    //if (contractybyProfile.DateEndNextContract != null)
                    //{
                    //    contractybyProfile.DateEnd = contractybyProfile.DateEndNextContract.Value;
                    //}
                    //contractservices.Add(contract);

                    // Thêm mới lương cơ bản + lương BHXH
                    string defaultcur = null;
                    string ConfigHre = AppConfig.HRM_HRE_CONFIG.ToString();
                    List<object> lstOb = new List<object>();
                    lstOb.Add(ConfigHre);
                    lstOb.Add(null);
                    lstOb.Add(null);
                    var config = GetData<Sys_AllSettingEntity>(lstOb, ConstantSql.hrm_sys_sp_get_AllSetting, userLogin, ref status);
                    string valueConfig = AppConfig.HRM_HRE_CONFIG_DEFAULTCURRENCY.ToString();
                    if (config != null)
                    {
                        defaultcur = config.Where(s => s.Name == valueConfig).Select(s => s.Value1).FirstOrDefault().ToString();
                        List<object> listObjCurrency = new List<object>();
                        listObjCurrency.Add(null);
                        listObjCurrency.Add(defaultcur);
                        listObjCurrency.Add(1);
                        listObjCurrency.Add(Int32.MaxValue - 1);
                        var lstCurrency = service.GetData<Cat_CurrencyEntity>(listObjCurrency, ConstantSql.hrm_cat_sp_get_Currency, userLogin, ref status).FirstOrDefault();

                        var basicsalarybyprofile = service.GetData<Sal_BasicSalaryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_sal_sp_get_BasicSalaryByProfileIds, userLogin, ref status)
                            .OrderByDescending(s => s.DateOfEffect).FirstOrDefault();
                        var insuransalarybyprofile = service.GetData<Sal_InsuranceSalaryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_sal_sp_get_InsuranceSalaryByProfileIds, userLogin, ref status)
                     .OrderByDescending(s => s.DateEffect).FirstOrDefault();

                        if (basicsalarybyprofile != null && salaryRank != null && basicsalarybyprofile.RankRateID != rankdetailID && salaryRank.SalaryClassID == basicsalarybyprofile.ClassRateID)
                        {
                            Sal_BasicSalaryEntity basicSalary = new Sal_BasicSalaryEntity();
                            basicSalary.ProfileID = profile.ID;
                            basicSalary.GrossAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value.ToString() : null;
                            basicSalary.Amount = basicSalary.GrossAmount != null ? basicSalary.GrossAmount.Encrypt() : "";
                            basicSalary.InsuranceAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value : 0;
                            basicSalary.DateOfEffect = dateEffect.Value;
                            basicSalary.CurrencyID = lstCurrency.ID;
                            basicSalary.Status = EnumDropDown.Sal_BasicSalaryStatus.E_WATTING_APPROVED.ToString();
                            basicSalary.AmountTotal = salaryRank != null ? salaryRank.SalaryStandard : null;
                            basicSalary.ClassRateID = salaryRank.SalaryClassID;
                            basicSalary.RankRateID = salaryRank.ID;
                            basicSalaryServices.Add(basicSalary);

                            if(insuransalarybyprofile != null)
                            {
                                Sal_InsuranceSalaryEntity insuranceSalary = new Sal_InsuranceSalaryEntity();
                                insuranceSalary.ProfileID = profile.ID;
                                insuranceSalary.InsuranceAmount = salaryRank != null ? salaryRank.SalaryStandard : null;
                                insuranceSalary.DateEffect = dateEffect;
                                insuranceSalary.CurrencyID = lstCurrency.ID;
                                insuranceSalary.IsSocialIns = insuransalarybyprofile.IsSocialIns;
                                insuranceSalary.IsMedicalIns = insuransalarybyprofile.IsMedicalIns;
                                insuranceSalary.IsUnimploymentIns = insuransalarybyprofile.IsUnimploymentIns;
                                InsuranceSalaryServices.Add(insuranceSalary);
                            }
                          
                        }
                        else
                        {
                            profile.SalaryClassID = salaryRank == null ? Guid.Empty : salaryRank.SalaryClassID;
                            profile.AbilityTileID = _AbilitiTitleID;
                            profile.DateOfEffect = dateEffect;
                            service.Edit(profile);

                            var workHistoryEntity = service.GetData<Hre_WorkHistoryEntity>(Common.DotNetToOracle(profileID.ToString()), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileId, userLogin, ref status)
                                .OrderByDescending(s => s.DateEffective).FirstOrDefault();


                            if (workHistoryEntity == null || workHistoryEntity.DateEffective != dateEffect)
                            {
                                var workHistory = new Hre_WorkHistoryEntity();
                                workHistory.ProfileID = profile.ID;
                                workHistory.SalaryClassID = salaryRank != null ? salaryRank.SalaryClassID : null;
                                workHistory.DateEffective = dateEffect != null ? dateEffect.Value : DateTime.Now;
                                workHistory.AbilityTileID = _AbilitiTitleID;
                                service.Add(workHistory);
                            }
                            else
                            {
                                workHistoryEntity.SalaryClassID = salaryRank != null ? salaryRank.SalaryClassID : null;
                                workHistoryEntity.DateEffective = dateEffect != null ? dateEffect.Value : DateTime.Now;
                                workHistoryEntity.AbilityTileID = _AbilitiTitleID;
                                service.Edit(workHistoryEntity);
                            }

                            Sal_BasicSalaryEntity basicSalary = new Sal_BasicSalaryEntity();
                            basicSalary.ProfileID = profile.ID;
                            basicSalary.GrossAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value.ToString() : null;
                            basicSalary.Amount = basicSalary.GrossAmount != null ? basicSalary.GrossAmount.Encrypt() : "";
                            basicSalary.InsuranceAmount = (salaryRank != null && salaryRank.SalaryStandard != null) ? salaryRank.SalaryStandard.Value : 0;
                            basicSalary.AmountTotal = salaryRank != null ? salaryRank.SalaryStandard : null;
                            basicSalary.DateOfEffect = dateEffect.Value;
                            basicSalary.CurrencyID = lstCurrency.ID;
                            basicSalary.Status = EnumDropDown.Sal_BasicSalaryStatus.E_WATTING_APPROVED.ToString();
                            basicSalaryServices.Add(basicSalary);

                            if (insuransalarybyprofile != null)
                            {
                                Sal_InsuranceSalaryEntity insuranceSalary = new Sal_InsuranceSalaryEntity();
                                insuranceSalary.ProfileID = profile.ID;
                                insuranceSalary.InsuranceAmount = salaryRank != null ? salaryRank.SalaryStandard : null;
                                insuranceSalary.DateEffect = dateEffect;
                                insuranceSalary.CurrencyID = lstCurrency.ID;
                                insuranceSalary.IsSocialIns = insuransalarybyprofile.IsSocialIns;
                                insuranceSalary.IsMedicalIns = insuransalarybyprofile.IsMedicalIns;
                                insuranceSalary.IsUnimploymentIns = insuransalarybyprofile.IsUnimploymentIns;
                                InsuranceSalaryServices.Add(insuranceSalary);
                            }
                        }
                }
                return result;
            }
        }
Пример #13
0
        public Hre_ContractModel Post([Bind]Hre_ContractModel model)
        {
            #region Validate

            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ContractModel>(model, "Hre_Contract", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            if (model.ContractEvaType == "E_ANNUAL_EVALUATION")
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ContractModel>(model, "EvaContractinfo", "Hre_Contract", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return model;
                }
            }

            #endregion

            if(model.ID == Guid.Empty)
            {
                model.DateExtend = model.DateEnd;
            }

            if (model.CreateBasicSalary == true)
            {
                Sal_BasicSalaryServices salaryservices = new Sal_BasicSalaryServices();
                Sal_BasicSalaryEntity basicSalaryBycontract = new Sal_BasicSalaryEntity();

                basicSalaryBycontract.ProfileID = model.ProfileID;
                basicSalaryBycontract.GrossAmount = model.Salary != null ? model.Salary.ToString() : "0";
                basicSalaryBycontract.CurrencyID = model.CurenncyID != null ? model.CurenncyID.Value : Guid.Empty;
                basicSalaryBycontract.PersonalRate = model.PersonalRate;
                basicSalaryBycontract.DateOfEffect = model.DateStart;

                basicSalaryBycontract.InsuranceAmount = model.InsuranceAmount != null ? model.InsuranceAmount.Value : 0;
                basicSalaryBycontract.CurrencyID1 = model.CurenncyID1;

                basicSalaryBycontract.ClassRateID = model.ClassRateID;
                basicSalaryBycontract.RankRateID = model.RankRateID;

                basicSalaryBycontract.AllowanceType1ID = model.AllowanceID1;
                basicSalaryBycontract.AllowanceAmount1 = model.Allowance1;
                basicSalaryBycontract.CurrencyID2 = model.CurenncyID2;

                basicSalaryBycontract.AllowanceType2ID = model.AllowanceID2;
                basicSalaryBycontract.AllowanceAmount2 = model.Allowance2;
                basicSalaryBycontract.CurrencyID3 = model.CurenncyID3;

                basicSalaryBycontract.AllowanceType3ID = model.AllowanceID3;
                basicSalaryBycontract.AllowanceAmount3 = model.Allowance3;
                basicSalaryBycontract.CurrencyID4 = model.CurenncyIDSalary;

                salaryservices.Add(basicSalaryBycontract);

            }
            ActionService service = new ActionService(UserLogin);
            return service.UpdateOrCreate<Hre_ContractEntity, Hre_ContractModel>(model);
        }
Пример #14
0
        public void AddAdjustmentSuggestionForBasicSalary(List<Sal_AdjustmentSuggestionEntity> lstAdjust, DateTime dateOfEffect, string UserLogin) 
        {
            var salaryServices = new Sal_BasicSalaryServices();
            BaseService service = new BaseService();
            string ConfigHre = AppConfig.HRM_HRE_CONFIG.ToString();
            string status = string.Empty;
            List<object> lstOb = new List<object>();
            lstOb.Add(ConfigHre);
            lstOb.Add(null);
            lstOb.Add(null);
            var config = GetData<Sys_AllSettingEntity>(lstOb, ConstantSql.hrm_sys_sp_get_AllSetting,UserLogin, ref status);
            string defaultcur = null;
            string valueConfig = AppConfig.HRM_HRE_CONFIG_DEFAULTCURRENCY.ToString();
            var currencyEntity = new Cat_CurrencyEntity();
            if (config != null)
            {
                defaultcur = config.Where(s => s.Name == valueConfig).Select(s => s.Value1).FirstOrDefault().ToString();
                List<object> listObjCurrency = new List<object>();
                listObjCurrency.Add(null);
                listObjCurrency.Add(defaultcur);
                listObjCurrency.Add(1);
                listObjCurrency.Add(Int32.MaxValue - 1);
                currencyEntity = service.GetData<Cat_CurrencyEntity>(listObjCurrency, ConstantSql.hrm_cat_sp_get_Currency,UserLogin, ref status).FirstOrDefault();
            }
            if (lstAdjust.Count > 0) 
            {
                var lstBasicSalary = new List<Sal_BasicSalaryEntity>();
                var lstBasicSalaryAdd = new List<Sal_BasicSalaryEntity>();
                lstBasicSalary = lstAdjust.Translate<Sal_BasicSalaryEntity>();
                foreach (var item in lstBasicSalary)
                {
                    item.ID = Guid.Empty;
                    item.CurrencyID = currencyEntity.ID;
                    item.DateOfEffect = dateOfEffect;
                    item.ClassRateID = item.ClassRateID;
                    item.RankRateID = item.RankRateID;
                    item.Status = EnumDropDown.Sal_BasicSalaryStatus.E_WATTING_APPROVED.ToString();
                    lstBasicSalaryAdd.Add(item);
                }
                salaryServices.Add(lstBasicSalaryAdd);
            }

        }
Пример #15
0
        public DataTable GetReportProfile(List<Hre_ProfileEntity> lstprofile, Guid _CutOffDurationID, string UserLogin)
        {


            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (UnitOfWork)(new UnitOfWork(context));
                DataTable table = CreateReportProfileScheme();
                if (lstprofile == null)
                    return table;
                //var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                //var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                //var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                //var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();

                //hop dong
                string status = string.Empty;
                var hreServiceContract = new Hre_ContractServices();
                List<object> paraContract = new List<object>();
                paraContract.AddRange(new object[21]);
                paraContract[19] = 1;
                paraContract[20] = int.MaxValue;
                var lstContract = hreServiceContract.GetData<Hre_ContractEntity>(paraContract, ConstantSql.hrm_hr_sp_get_Contract, UserLogin, ref status);
                //ky cong
                string cutoff = Common.DotNetToOracle(_CutOffDurationID.ToString());
                var baseService = new BaseService();
                var objAtt_CutOffDurationEntity = baseService
                    .GetData<Att_CutOffDurationEntity>(cutoff, ConstantSql.hrm_att_sp_get_CutOffDurationById, UserLogin, ref status)
                    .FirstOrDefault();
                //
                DateTime _dateFrom = DateTime.MinValue;
                DateTime _dateTo = DateTime.MaxValue;
                if (objAtt_CutOffDurationEntity != null)
                {
                    if (objAtt_CutOffDurationEntity.DateStart != null)
                        _dateFrom = objAtt_CutOffDurationEntity.DateStart;
                    if (objAtt_CutOffDurationEntity.DateEnd != null)
                        _dateTo = objAtt_CutOffDurationEntity.DateEnd;
                }
                var salServiceBasicSalary = new Sal_BasicSalaryServices();
                List<object> paraBasicSalary = new List<object>();
                paraBasicSalary.AddRange(new object[4]);
                paraBasicSalary[0] = _dateFrom;
                paraBasicSalary[1] = _dateTo;
                paraBasicSalary[2] = 1;
                paraBasicSalary[3] = int.MaxValue - 1;
                var lstBasicSalary = salServiceBasicSalary.GetData<Sal_BasicSalaryEntity>(paraBasicSalary, ConstantSql.hrm_sal_sp_getdata_BasicSalaryByCutOff, UserLogin, ref status);
                //Hre_ProfilePartyUnion
                var repoHre_ProfilePartyUnion = new Hre_ProfilePartyUnionRepository(unitOfWork);
                var lstProfilePartyUnion = repoHre_ProfilePartyUnion.FindBy(s => s.IsDelete == null && s.IsTradeUnionist == true && s.YouthUnionEnrolledDate <= _dateTo).ToList();
                //Hre_StopWorking
                List<object> paraStopWorking = new List<object>();
                paraStopWorking.AddRange(new object[17]);
                paraStopWorking[6] = _dateFrom;
                paraStopWorking[7] = _dateTo;
                paraStopWorking[15] = 1;
                paraStopWorking[16] = int.MaxValue - 1;
                var hreServiceStopWorking = new Hre_StopWorkingServices();
                var lstStopWorking = hreServiceStopWorking.GetData<Hre_StopWorkingEntity>(paraStopWorking, ConstantSql.hrm_hr_sp_get_StopWorking, UserLogin, ref status);
                //Ins_ProfileInsuranceMonthly
                var repoProfileInsuranceMonthly = new Ins_ProfileInsuranceMonthlyRepository(unitOfWork);
                var lstProfileInsuranceMonthly = repoProfileInsuranceMonthly.FindBy(s => s.IsDelete == null && s.MonthYear >= _dateFrom && s.MonthYear <= _dateTo).ToList();

                foreach (var profile in lstprofile)
                {
                    if (profile != null)
                    {
                        var objContract = lstContract.Where(s => s.ProfileID == profile.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                        var objBasicSalary = lstBasicSalary.Where(s => s.ProfileID == profile.ID).OrderByDescending(s => s.DateOfEffect).FirstOrDefault();
                        var objProfilePartyUnion = lstProfilePartyUnion.Where(s => s.ProfileID == profile.ID).OrderByDescending(s => s.YouthUnionEnrolledDate).FirstOrDefault();
                        var objStopWorking = lstStopWorking.Where(s => s.ProfileID == profile.ID).OrderByDescending(s => s.DateStop).FirstOrDefault();
                        var objProfileInsuranceMonthly = lstProfileInsuranceMonthly.Where(s => s.ProfileID == profile.ID).OrderByDescending(s => s.MonthYear).FirstOrDefault();
                        DataRow row = table.NewRow();
                        if (profile.CodeEmp != null)
                            row[Sal_ReportProfileEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                        if (profile.ProfileName != null)
                            row[Sal_ReportProfileEntity.FieldNames.ProfileName] = profile.ProfileName;
                        if (profile.UnitNameOrg != null)
                            row[Sal_ReportProfileEntity.FieldNames.UnitNameOrg] = profile.UnitNameOrg;
                        if (profile.DepartmentNameOrg != null)
                            row[Sal_ReportProfileEntity.FieldNames.DepartmentNameOrg] = profile.DepartmentNameOrg;
                        if (profile.SectionNameOrg != null)
                            row[Sal_ReportProfileEntity.FieldNames.SectionNameOrg] = profile.SectionNameOrg;
                        if (profile.TeamNameOrg != null)
                            row[Sal_ReportProfileEntity.FieldNames.TeamNameOrg] = profile.TeamNameOrg;
                        if (profile.WorkPlaceName != null)
                            row[Sal_ReportProfileEntity.FieldNames.WorkPlaceName] = profile.WorkPlaceName;
                        if (profile.StatusSyn != null)
                            row[Sal_ReportProfileEntity.FieldNames.StatusSyn] = profile.StatusSyn;
                        if (objBasicSalary != null && objBasicSalary.SalaryClassName != null)
                            row[Sal_ReportProfileEntity.FieldNames.SalaryClassName] = objBasicSalary.SalaryClassName;
                        if (objBasicSalary != null && objBasicSalary.GrossAmount != null)
                            row[Sal_ReportProfileEntity.FieldNames.BasicSalary] = objBasicSalary.GrossAmount;
                        if (objBasicSalary != null && objBasicSalary.SalaryRankName != null)
                            row[Sal_ReportProfileEntity.FieldNames.SalaryRankName] = objBasicSalary.SalaryRankName;
                        if (profile.CostCentreCode != null)
                            row[Sal_ReportProfileEntity.FieldNames.CostCentreCode] = profile.CostCentreCode;
                        if (profile.IDNo != null)
                            row[Sal_ReportProfileEntity.FieldNames.IDNo] = profile.IDNo;
                        if (profile.DateOfBirth != null)
                            row[Sal_ReportProfileEntity.FieldNames.DateOfBirth] = profile.DateOfBirth;
                        if (profile.DateHire != null)
                            row[Sal_ReportProfileEntity.FieldNames.DateHire] = profile.DateHire;
                        if (objContract != null)
                        {
                            if (objContract.DateStart != null)
                                row[Sal_ReportProfileEntity.FieldNames.DateStart] = objContract.DateStart;
                            if (objContract.DateEnd != null)
                                row[Sal_ReportProfileEntity.FieldNames.DateEnd] = objContract.DateEnd;
                        }
                        //if (profile.WorkingPlace != null)
                        //    row[Sal_ReportProfileEntity.FieldNames.WorkingPlace] = profile.WorkingPlace;
                        if (objProfileInsuranceMonthly != null && objProfileInsuranceMonthly.IsUnEmpInsurance != null)
                            row[Sal_ReportProfileEntity.FieldNames.IsUnEmpInsurance] = objProfileInsuranceMonthly.IsUnEmpInsurance;
                        if (objProfileInsuranceMonthly != null && objProfileInsuranceMonthly.IsSocialInsurance != null)
                            row[Sal_ReportProfileEntity.FieldNames.IsSocialInsurance] = objProfileInsuranceMonthly.IsSocialInsurance;
                        if (objProfileInsuranceMonthly != null && objProfileInsuranceMonthly.IsHealthInsurance != null)
                            row[Sal_ReportProfileEntity.FieldNames.IsHealthInsurance] = objProfileInsuranceMonthly.IsHealthInsurance;
                        if (objProfilePartyUnion != null && objProfilePartyUnion.IsTradeUnionist != null)
                            row[Sal_ReportProfileEntity.FieldNames.IsTradeUnionist] = objProfilePartyUnion.IsTradeUnionist;
                        if (objStopWorking != null && objStopWorking.DateStop != null)
                            row[Sal_ReportProfileEntity.FieldNames.DateStop] = objStopWorking.DateStop;
                        if (profile.DateHire != null)
                            row[Sal_ReportProfileEntity.FieldNames.DateHire] = profile.DateHire;
                        table.Rows.Add(row);
                    }
                }
                return table.ConfigTable(true);
            }
        }