/// <summary>
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Att_ChangeRosterGroupTableModel GetById(string id)
        {
            Att_ChangeRosterGroupTableModel result = new Att_ChangeRosterGroupTableModel();
            List<Guid> SelectedIds = new List<Guid>();
            var rosterGroupServices = new Att_RosterGroupServices();
            string status = string.Empty;
            var date = DateTime.Now;
            var services = new Sys_AllSettingServices();
            var key = AppConfig.HRM_ATT_CONFIG_NAME_ROSTERGROUP.ToString();
            var configEntity = services.GetData<Sys_AllSettingEntity>(key, ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).ToList().FirstOrDefault();

        

            if (!string.IsNullOrEmpty(id))
            {
                if (id.IndexOf('-') > 1)
                {
                   
                    SelectedIds = id.Split(',').Select(s => Guid.Parse(s)).ToList();
                    if (SelectedIds != null && SelectedIds.Count > 0)
                    {
                        if (id != "Create")
                        {
                            var rosterGroupEntity = services.GetData<Att_RosterGroupEntity>(Common.DotNetToOracle(id), ConstantSql.hrm_att_sp_get_RosterGroupById, UserLogin, ref status).FirstOrDefault();
                            if (rosterGroupEntity != null && rosterGroupEntity.DateStart != null)
                            {
                                date = rosterGroupEntity.DateStart.Value;
                            }
                            result.Table = rosterGroupServices.GetTableRosterGroupByMonth(date, ModifyType.E_EDIT);
                            if (configEntity != null)
                            {
                                result.lstType = configEntity.Name.Split(',').ToList();
                            }
                            return result;
                        
                        }
                       
                    }
                }
                else {
                    if (configEntity != null)
                    {
                        result.lstType = configEntity.Value1.Split(',').ToList();
                    }
                    result.Table = rosterGroupServices.GetTableRosterGroupByMonth(date, ModifyType.E_CREATE);
                    return result;
                }
               
            }
           

            
            return null;
        }
 /// <summary>
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public Att_ChangeRosterGroupTableModel GetById(string id)
 {
     Att_ChangeRosterGroupTableModel result = new Att_ChangeRosterGroupTableModel();
     string status = string.Empty;
     var services = new Sys_AllSettingServices();
     var configEntity = services.GetData<Sys_AllSettingEntity>(id, ConstantSql.hrm_sys_sp_get_AllSettingByKey, UserLogin, ref status).ToList().FirstOrDefault();
  
     
     return null;
 }
示例#3
0
        //// GET api/<controller>
        ///// <summary>
        ///// Lấy tất cả dữ liệu
        ///// </summary>
        ///// <returns></returns>
        public Sys_ConfigDBModel Get(string id)
        {
            var service = new Sys_AllSettingServices();
            string status = string.Empty;
            var listConfig = service.GetData<Sys_AllSettingEntity>(id, ConstantSql.hrm_cat_sp_get_GetAllSettings, UserLogin, ref status);
            Sys_ConfigDBModel config = new Sys_ConfigDBModel();
            foreach (var item in listConfig)
            {
                // Config Attendance
                // Sever 1
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.SERVERNAME.ToString())
                {
                    config.Att_ServerName1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.USERID.ToString())
                {
                    config.Att_UserID1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.PASSWORD.ToString())
                {
                    config.Att_Password1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.DBNAME.ToString())
                {
                    config.Att_DBName1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.TABLENAME.ToString())
                {
                    config.Att_TableName1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.CARDCOLNAME.ToString())
                {
                    config.Att_CardColName1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.DATACOLNAME.ToString())
                {
                    config.Att_DataColName1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.MACHINECODE.ToString())
                {
                    config.Att_SerialNumber1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.TYPE.ToString())
                {
                    config.Att_In_Out1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.FILTERDATA.ToString())
                {
                    config.Att_FilterData1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.FILTERDATASPLIT.ToString())
                {
                    config.Att_FilterDataSplit1 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.ISCODEEMP.ToString())
                {
                    config.Att_IsCodeEmp1 = item.Value1 == bool.TrueString ? true : false;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_1_.ToString() + AppConfig.ISACTIVATED.ToString())
                {
                    config.Att_IsActive1 = item.Value1 == bool.TrueString ? true : false;
                    continue;
                }

                // Sever 2
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.SERVERNAME.ToString())
                {
                    config.Att_ServerName2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.USERID.ToString())
                {
                    config.Att_UserID2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.PASSWORD.ToString())
                {
                    config.Att_Password2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.DBNAME.ToString())
                {
                    config.Att_DBName2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.TABLENAME.ToString())
                {
                    config.Att_TableName2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.CARDCOLNAME.ToString())
                {
                    config.Att_CardColName2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.DATACOLNAME.ToString())
                {
                    config.Att_DataColName2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.MACHINECODE.ToString())
                {
                    config.Att_SerialNumber2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.TYPE.ToString())
                {
                    config.Att_In_Out2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.FILTERDATA.ToString())
                {
                    config.Att_FilterData2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.FILTERDATASPLIT.ToString())
                {
                    config.Att_FilterDataSplit2 = item.Value1;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.ISCODEEMP.ToString())
                {
                    config.Att_IsCodeEmp2 = item.Value1 == bool.TrueString ? true : false;
                    continue;
                }
                if (item.Name == AppConfig.HRM_SYS_TAMSCANLOG_2_.ToString() + AppConfig.ISACTIVATED.ToString())
                {
                    config.Att_IsActive2 = item.Value1 == bool.TrueString ? true : false;
                    continue;
                }
            }
            return config;
        }
示例#4
0
        public Att_RosterModel Post([Bind]Att_RosterModel model)
        {
            ActionService service = new ActionService(UserLogin);
            var baseService = new BaseService();
            string status = string.Empty;
            var hrService = new Hre_ProfileServices();
            string strMessages = string.Empty;
            var rosterService = new Att_RosterServices();
            var sysAllSetttingService = new Sys_AllSettingServices();
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Att_RosterModel>(model, "Att_Roster", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Att_RosterModel>(model, "Att_ProfileNotRoster", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            if (string.IsNullOrEmpty(model.OrgStructureIDs) && string.IsNullOrEmpty(model.ProfileIds) && model.ProfileID == Guid.Empty)
            {
                message = string.Format(ConstantMessages.FieldNotAllowNull.TranslateString(), ("ProfileID").TranslateString());
                model.ActionStatus = message;
                return model;
            }
            #endregion

            List<Guid> lstProfileIDs = new List<Guid>();

            if(!string.IsNullOrEmpty(model.OrgStructureIDs))
            {
                List<object> listObj = new List<object>();
                listObj.Add(model.OrgStructureIDs);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var lstProfile = hrService.GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure,UserLogin, ref status).Select(s => s.ID).ToList();
               lstProfileIDs.AddRange(lstProfile);
            }
            else if (model.ProfileIds != null && model.ProfileIds!="")
            {
               var listGuid = model.ProfileIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
               lstProfileIDs.AddRange(listGuid);
            }
            var lstRosterEntity_Validate = new List<Att_RosterEntity>();
            foreach (var item in lstProfileIDs)
            {
                Att_RosterEntity rosterEntity = model.CopyData<Att_RosterEntity>();
                rosterEntity.ProfileID = item;
                if (rosterEntity.ID != null && rosterEntity.ID!= Guid.Empty)
                {
                }
                else
                {
                    rosterEntity.ID = Guid.NewGuid();
                }
                lstRosterEntity_Validate.Add(rosterEntity);
            }
            var key = AppConfig.HRM_ATT_ALLOWSAVEDUPLICATE.ToString();
            var lstSysAllSetting = sysAllSetttingService.GetData<Sys_AllSettingEntity>(key,ConstantSql.hrm_sys_sp_get_AllSettingByKey,UserLogin, ref status).FirstOrDefault();


            var ValidateLess12Hour = AppConfig.HRM_ATT_VALIDATE_ROSTER_NON_CONTINUE_12HOUR.ToString();
            var lstSysSetting_ValidateLess12Hour = sysAllSetttingService.GetData<Sys_AllSettingEntity>(ValidateLess12Hour, ConstantSql.hrm_sys_sp_get_AllSettingByKey,UserLogin, ref status).FirstOrDefault();
            if (lstSysSetting_ValidateLess12Hour != null && lstSysSetting_ValidateLess12Hour.Value1==bool.TrueString)
            {
                string Err = string.Empty;
                Err = rosterService.ValidateShiftHourContinue(lstRosterEntity_Validate);
                if (Err != string.Empty)
                {
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + Err);
                    return model;
                }
            }

            if (!string.IsNullOrEmpty(model.OrgStructureIDs))
            {
                List<object> listObj = new List<object>();
                listObj.Add(model.OrgStructureIDs);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);
                var lstProfile = hrService.GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure,UserLogin, ref status).Select(s => s.ID).ToList();
                if(lstProfile.Count==0 || lstProfile == null)
                {
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Info + "," + strMessages + ConstantMessages.FieldDuplicate);
                    return model;
                }
                if(lstProfile != null && model.ProfileIds != null)
                {
                        Guid[] listGuid = null;
                        listGuid = model.ProfileIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
                        lstProfile = lstProfile.Where(s => !listGuid.Contains(s)).ToList();
                }
                List<Att_RosterEntity> lstRosterEntity = new List<Att_RosterEntity>();
                List<object> paraRoster = new List<object>();
                paraRoster.AddRange(new object[4]);
                paraRoster[0]=(object)model.OrgStructureIDs;
                paraRoster[1]=null;
                paraRoster[2]=null;
                paraRoster[3]=null;
                var listRosterData = rosterService.GetData<Att_RosterEntity>(paraRoster, ConstantSql.hrm_att_getdata_Roster,UserLogin, ref status);
                foreach (var item in lstProfile)
                {
                    Att_RosterModel modelSave = model.CopyData<Att_RosterModel>();
                    var listRoster = listRosterData.Where(s => s.ProfileID == item);
                    if (modelSave.Type != RosterType.E_CHANGE_SHIFT.ToString()
                        && modelSave.Type != RosterType.E_TIME_OFF.ToString() 
                        && listRoster != null 
                        && listRoster.Any(d => d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                    {
                        strMessages += listRoster.FirstOrDefault().ProfileName + ", ";
                        continue;
                    }
                    modelSave.ProfileID = item;
                    Att_RosterEntity rosterEntity = modelSave.CopyData<Att_RosterEntity>();
                    lstRosterEntity.Add(rosterEntity);
                }
                if (strMessages == "" && lstRosterEntity.Count > 0)
                {
                    model.ActionStatus = rosterService.Add(lstRosterEntity);
                }
                else
                {
                    if (lstSysAllSetting != null && lstSysAllSetting.Value1 == bool.TrueString && lstRosterEntity.Count > 0)
                    {
                        model.ActionStatus = rosterService.Add(lstRosterEntity);
                    }
                    else if (lstSysAllSetting.Value1 == bool.FalseString)
                    {
                        model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                        return model;
                    }
                    else if(lstRosterEntity.Count == 0)
                    {
                        model.SetPropertyValue(Constant.ActionStatus, NotificationType.Info + "," + strMessages + ConstantMessages.FieldDuplicate);
                        return model;
                    }
                }
                return model;
            }
            //Xử lý khi chọn nhiều nhân viên
            if (model.ProfileIds != null && model.ProfileIds.IndexOf(',') > 0 && model.OrgStructureIDs == null)
            {
                Guid[] listGuid = null;
                listGuid = model.ProfileIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
                List<Att_RosterEntity> lstRosterEntity = new List<Att_RosterEntity>();
                foreach (var item in listGuid)
                {
                    Att_RosterModel modelSave = model.CopyData<Att_RosterModel>();
                    var listRoster = service.GetData<Att_RosterEntity>(item, ConstantSql.hrm_att_sp_get_RosterByProfileId, ref status);
                    if (modelSave.Type != RosterType.E_CHANGE_SHIFT.ToString()
                        && modelSave.Type != RosterType.E_TIME_OFF.ToString()
                        && listRoster != null
                        && listRoster.Any(d => d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                    {
                        strMessages += listRoster.FirstOrDefault().ProfileName + ", ";
                        continue;
                    }
                    modelSave.ProfileID = item;
                    Att_RosterEntity rosterEntity = modelSave.CopyData<Att_RosterEntity>();
                    lstRosterEntity.Add(rosterEntity);
                }
                if(strMessages == "")
                {
                    model.ActionStatus = rosterService.Add(lstRosterEntity);
                }
                else
                {
                    if (lstSysAllSetting != null && lstSysAllSetting.Value1 == bool.TrueString)
                    {
                        model.ActionStatus = rosterService.Add(lstRosterEntity);
                    }
                    else
                    {
                        model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                        return model;
                    }
                }
                return model;
            }
            //Xử lý khi chỉ chọn 1 nhân viên
            if(model.ID == Guid.Empty){
                var lstRoster = service.GetData<Att_RosterEntity>(model.ProfileID, ConstantSql.hrm_att_sp_get_RosterByProfileId, ref status);
                if (model.Type != RosterType.E_CHANGE_SHIFT.ToString()
                    && model.Type != RosterType.E_TIME_OFF.ToString()
                    && lstRoster != null 
                    && lstRoster.Any(d => d.DateStart <= model.DateEnd && d.DateEnd >= model.DateStart))
                {
                    strMessages = lstRoster.FirstOrDefault().ProfileName + ",";
                    model.SetPropertyValue(Constant.ActionStatus, NotificationType.Error + "," + strMessages + ConstantMessages.FieldDuplicate);
                    return model;
                }
                return service.UpdateOrCreate<Att_RosterEntity, Att_RosterModel>(model);
            }
            return service.UpdateOrCreate<Att_RosterEntity, Att_RosterModel>(model);
        }
示例#5
0
        public bool ComputePayrollEstimate(List<Sal_PayrollEstimateDetailEntity> listPayrollEstimateDetail, Sal_PayrollEstimateEntity model, string userLogin)
        {
            try
            {
                using (var context = new VnrHrmDataContext())
                {
                    var unitOfWork = (IUnitOfWork)new UnitOfWork(context);
                    var repoCutOffDuration = new CustomBaseRepository<Att_CutOffDuration>(unitOfWork);
                    var repoPayrollEstimateDetail = new CustomBaseRepository<Sal_PayrollEstimateDetail>(unitOfWork);
                    var repoPayrollEstimate = new CustomBaseRepository<Sal_PayrollEstimate>(unitOfWork);

                    List<Att_CutOffDuration> listCutoffDuration = repoCutOffDuration.FindBy(m => m.IsDelete != true && m.MonthYear <= model.MonthEnd && m.MonthYear >= model.MonthStart).ToList();

                    #region Delete Sal_PayrollEstimate và Sal_PayrollEstimateDetail

                    List<Sal_PayrollEstimateDetail> ListPayrollEstimateDetailDelete = new List<Sal_PayrollEstimateDetail>();
                    List<Sal_PayrollEstimate> ListPayrollEstimateDelete = new List<Sal_PayrollEstimate>();

                    ListPayrollEstimateDelete = repoPayrollEstimate.FindBy(m => m.IsDelete != true && m.OrgStructureID == model.OrgStructureID).ToList();
                    ListPayrollEstimateDelete = ListPayrollEstimateDelete.Where(m => listCutoffDuration.Any(t => t.ID == m.CutOffDurationID)).ToList();

                    ListPayrollEstimateDetailDelete = repoPayrollEstimateDetail.FindBy(m => m.IsDelete != true).ToList();
                    ListPayrollEstimateDetailDelete = ListPayrollEstimateDetailDelete.Where(m => ListPayrollEstimateDelete.Any(t => t.ID == m.PayrollEstimateID)).ToList();

                    ListPayrollEstimateDelete.ForEach(m => m.IsDelete = true);
                    ListPayrollEstimateDetailDelete.ForEach(m => m.IsDelete = true);

                    unitOfWork.SaveChanges();
                    #endregion
                    
                    //Giờ công chuẩn lấy trong web config
                    double TotalAmount = 0;

                    //lay du lieu  cau hinh
                    string status = string.Empty;
                    Sys_AllSettingServices sysServices = new Sys_AllSettingServices();
                    var AllSetting = sysServices.GetData<Sys_AllSettingEntity>("HRM_SAL_PAYROLL_ESTIMATE_SALRYAVERAGE", ConstantSql.hrm_sys_sp_get_AllSettingByKey, userLogin, ref status).FirstOrDefault();
                    double StandardHour = 200;
                    Double.TryParse(AllSetting != null ? AllSetting.Value2 : "a", out StandardHour);

                    foreach (var CutOff in listCutoffDuration)
                    {
                        //reset tổng tiền master
                        TotalAmount = 0;
                        //tạo dữ liệu master
                        Sal_PayrollEstimate Master = new Sal_PayrollEstimate();
                        Master.ID = Guid.NewGuid();
                        Master.OrgStructureID = model.OrgStructureID;
                        Master.CutOffDurationID = CutOff.ID;
                        Master.PayrollGroupID = model.PayrollGroupID;
                        Master.RateAdjust = model.RateAdjust;
                        Master.OrgStructureType = model.OrgStructureType;
                        Master.BonusBudget = model.BonusBudget;
                        Master.StatusEmp = model.StatusEmp;

                        foreach (var i in listPayrollEstimateDetail)
                        {
                            #region Check null value
                            i.SalaryAverage = i.SalaryAverage != null ? (double)i.SalaryAverage : 0;
                            i.QuantityEmp = i.QuantityEmp != null ? (double)i.QuantityEmp : 0;
                            i.LeaveUnpaid = i.LeaveUnpaid != null ? (double)i.LeaveUnpaid : 0;

                            i.OvertimeNormal = i.OvertimeNormal != null ? (double)i.OvertimeNormal : 0;
                            i.OvertimeNightNormal = i.OvertimeNightNormal != null ? (double)i.OvertimeNightNormal : 0;
                            i.OvertimeWeekend = i.OvertimeWeekend != null ? (double)i.OvertimeWeekend : 0;
                            i.OvertimeNightWeekend = i.OvertimeNightWeekend != null ? (double)i.OvertimeNightWeekend : 0;
                            i.OvertimeHoliday = i.OvertimeHoliday != null ? (double)i.OvertimeHoliday : 0;
                            i.OvertimeNightHoliday = i.OvertimeNightHoliday != null ? (double)i.OvertimeNightHoliday : 0;

                            model.RateAdjust = model.RateAdjust != null ? (double)model.RateAdjust : 0;
                            model.BonusBudget = model.BonusBudget != null ? (double)model.BonusBudget : 0;
                            #endregion

                            #region Tính toán số liệu
                            double AmountHour = (double)i.SalaryAverage * (double)i.QuantityEmp;
                            double AmountLeaveDay = (double)i.SalaryAverage * (double)i.LeaveUnpaid != 0 ? ((double)i.LeaveUnpaid / StandardHour) : 1;
                            double AmountOvertime = 0;
                            AmountOvertime += (double)i.SalaryAverage * 1.5 * (double)i.OvertimeNormal;
                            AmountOvertime += (double)i.SalaryAverage * 1.95 * (double)i.OvertimeNightNormal;
                            AmountOvertime += (double)i.SalaryAverage * 2.0 * (double)i.OvertimeWeekend;
                            AmountOvertime += (double)i.SalaryAverage * 2.6 * (double)i.OvertimeNightWeekend;
                            AmountOvertime += (double)i.SalaryAverage * 3.0 * (double)i.OvertimeHoliday;
                            AmountOvertime += (double)i.SalaryAverage * 3.9 * (double)i.OvertimeNightHoliday;
                            double Percent = (double)model.RateAdjust != 0 ? (double)model.RateAdjust / 100 : 1;
                            double AmountTotal = ((AmountHour - AmountLeaveDay + AmountOvertime) * Percent) + (double)model.BonusBudget;
                            //cập nhật tổng tiền cho master
                            TotalAmount += AmountTotal;
                            #endregion

                            //tạo dữ liệu detail
                            Sal_PayrollEstimateDetail Detail = new Sal_PayrollEstimateDetail();
                            Detail.ID = Guid.NewGuid();
                            Detail.SalaryAverage = i.SalaryAverage;
                            Detail.PayrollEstimateID = Master.ID;
                            Detail.OrgStructureID = i.OrgStructureID;
                            Detail.LeaveUnpaid = i.LeaveUnpaid;
                            Detail.OvertimeHoliday = i.OvertimeHoliday;
                            Detail.OvertimeNightHoliday = i.OvertimeNightHoliday;
                            Detail.OvertimeNightNormal = i.OvertimeNightNormal;
                            Detail.OvertimeNightWeekend = i.OvertimeNightWeekend;
                            Detail.QuantityEmp = i.QuantityEmp;
                            Detail.OvertimeNormal = i.OvertimeNormal;
                            Detail.OvertimeWeekend = i.OvertimeWeekend;
                            Detail.AmountHour = AmountHour;
                            Detail.AmountLeaveDay = AmountLeaveDay;
                            Detail.AmountOvertime = AmountOvertime;
                            Detail.AmountTotal = AmountTotal;
                            repoPayrollEstimateDetail.Add(Detail);
                        }

                        //update tổng tiền
                        Master.AmountTotal = TotalAmount;
                        repoPayrollEstimate.Add(Master);
                    }
                    unitOfWork.SaveChanges();
                    return true;
                }
            }
            catch
            {
                return false;
            }
        }