Пример #1
0
        public Guid ComputeAnnualLeaveAllowance(Sal_UnusualAllowanceEntity model)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork       = (IUnitOfWork) new UnitOfWork(context);
                var repoSys_AsynTask = new CustomBaseRepository <Sys_AsynTask>(unitOfWork);
                var repoCat_Element  = new CustomBaseRepository <Cat_Element>(unitOfWork);


                //tạo asynTask
                Sys_AsynTask asynTask = new Sys_AsynTask()
                {
                    ID              = Guid.NewGuid(),
                    Summary         = "Tính phép năm : " + model.MonthStart.Value.ToString("dd/MM/yyyy"),
                    Type            = AsynTask.Payroll_Compute_AnnualLeaveAllowance.ToString(),
                    Status          = AsynTaskStatus.Doing.ToString(),
                    TimeStart       = DateTime.Now,
                    PercentComplete = 0.01,
                };
                repoSys_AsynTask.Add(asynTask);
                unitOfWork.SaveChanges();

                Thread threadCompute = new Thread(() => ComputeBonusUnusualAllowance_Progress(asynTask.ID, model, true));
                threadCompute.Start();

                return(asynTask.ID);
            }
        }
Пример #2
0
        public void ComputeBonusUnusualAllowance_Progress(Guid AsynTaskID, Sal_UnusualAllowanceEntity model, bool AllowanceEvaluationYear = false)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork                  = (IUnitOfWork) new UnitOfWork(context);
                var repoSys_AsynTask            = new CustomBaseRepository <Sys_AsynTask>(unitOfWork);
                var repoCat_Element             = new CustomBaseRepository <Cat_Element>(unitOfWork);
                var repoCat_UnusualAllowanceCfg = new CustomBaseRepository <Cat_UnusualAllowanceCfg>(unitOfWork);
                var repoUnusualAllowance        = new CustomBaseRepository <Sal_UnusualAllowance>(unitOfWork);

                Sys_AsynTask asynTask = repoSys_AsynTask.GetById(AsynTaskID);

                Sal_ComputePayrollServices CumputePayrollServices = new Sal_ComputePayrollServices();
                List <object> listModel = new List <object>();
                string        status    = string.Empty;
                Sal_ComputePayrollServices        Services                 = new Sal_ComputePayrollServices();
                List <Sal_UnusualAllowanceEntity> ListResult               = new List <Sal_UnusualAllowanceEntity>();
                List <ElementFormula>             listElementFormula       = new List <ElementFormula>();
                Sal_UnusualAllowanceServices      UnusualAllowanceServices = new Sal_UnusualAllowanceServices();

                Att_CutOffDurationEntity CutOffDuration = new Att_CutOffDurationEntity();
                if (model.MonthEnd != null)
                {
                    CutOffDuration.MonthYear = model.MonthStart.Value;
                    CutOffDuration.DateStart = model.MonthStart.Value;
                    CutOffDuration.DateEnd   = model.MonthEnd.Value;
                }
                else
                {
                    CutOffDuration.MonthYear = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1);
                    CutOffDuration.DateStart = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1);
                    CutOffDuration.DateEnd   = new DateTime(model.MonthStart.Value.Year, model.MonthStart.Value.Month, 1).AddMonths(1).AddDays(-1);
                }

                List <Hre_ProfileEntity> ListProfile = new List <Hre_ProfileEntity>();

                if (model.OrgStructureIDs != null && model.OrgStructureIDs != string.Empty)
                {
                    listModel = new List <object>();
                    listModel.AddRange(new object[18]);
                    listModel[2]  = model.OrgStructureIDs;
                    listModel[16] = 1;
                    listModel[17] = Int32.MaxValue - 1;
                    ListProfile   = GetData <Hre_ProfileEntity>(listModel, ConstantSql.hrm_hr_sp_get_Profile, ref status);
                    if (model.ExProfileIDs != null)
                    {
                        string[] ExProfile = model.ExProfileIDs.Split(',');
                        ListProfile = ListProfile.Where(m => ExProfile.Contains(m.ID.ToString())).ToList();
                    }
                }
                else if (model.ProfileIDs != null && model.ProfileIDs != string.Empty)
                {
                    ListProfile = GetData <Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileIDs), ConstantSql.hrm_hr_sp_get_ProfileByIds, ref status);
                }


                //lọc profile theo workplace
                if (model.WorkingPlaceID != null)
                {
                    string[] listWorkPlare = model.WorkingPlaceID.Split(',');
                    ListProfile = ListProfile.Where(m => listWorkPlare.Contains(m.WorkPlaceID.ToString())).ToList();
                }

                List <Cat_UnusualAllowanceCfg> listUnusualAllowanceCfg = new List <Cat_UnusualAllowanceCfg>();
                listUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList();

                #region Delete các phụ cấp trong năm đã có
                List <Sal_UnusualAllowance> listUnusualAllowance = repoUnusualAllowance.FindBy(m => m.IsDelete != true && m.MonthStart != null && model.MonthStart != null && m.MonthStart.Value.Year == model.MonthStart.Value.Year && m.Status != WorkHistoryStatus.E_APPROVED.ToString()).ToList();

                //nếu là tính phép năm sức khỏe tốt thì delete thêm loại GoodHealth
                if (AllowanceEvaluationYear)
                {
                    var _tmp = listUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth");
                    listUnusualAllowance = listUnusualAllowance.Where(m => (m.UnusualEDTypeID == model.UnusualEDTypeID || m.UnusualEDTypeID == _tmp.ID) && ListProfile.Any(t => t.ID == m.ProfileID)).ToList();
                }
                else
                {
                    listUnusualAllowance = listUnusualAllowance.Where(m => m.UnusualEDTypeID == model.UnusualEDTypeID && ListProfile.Any(t => t.ID == m.ProfileID)).ToList();
                }
                //update isdelete is true
                listUnusualAllowance.ForEach(m => m.IsDelete = true);
                #endregion

                //Cat_ElementEntity ElementItem = repoCat_Element.GetById((Guid)model.Element).Copy<Cat_ElementEntity>();
                Cat_ElementEntity ElementItem = repoCat_Element.FindBy(m => m.ID == (Guid)model.Element).FirstOrDefault().Copy <Cat_ElementEntity>();


                ComputePayrollDataModel TotalData = Services.GetDataForComputeSalary(CutOffDuration);

                List <Cat_ElementEntity> listElementAll = new List <Cat_ElementEntity>();
                listElementAll = TotalData.listElement_All;

                #region Xử lý cho tính phép năm, sức khỏe tốt
                List <Cat_UnusualAllowanceCfg> ListUnusualAllowanceCfg = new List <Cat_UnusualAllowanceCfg>();
                Cat_UnusualAllowanceCfg        PaidLeave  = null;
                Cat_UnusualAllowanceCfg        GoodHealth = null;
                ElementFormula FormulaValue = new ElementFormula();
                if (AllowanceEvaluationYear)
                {
                    ListUnusualAllowanceCfg = repoCat_UnusualAllowanceCfg.FindBy(m => m.IsDelete != true).ToList();
                    PaidLeave  = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "PaidLeave");
                    GoodHealth = ListUnusualAllowanceCfg.FirstOrDefault(m => m.Code == "GoodHealth");
                }
                #endregion

                foreach (var profile in ListProfile)
                {
                    if (AllowanceEvaluationYear)
                    {
                        #region Tính Công Thức
                        try
                        {
                            listElementFormula        = new List <ElementFormula>();
                            TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate <Cat_ElementEntity>();
                            listElementFormula        = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary <Guid, ValueCount>());
                        }
                        catch
                        {
                            listElementFormula = null;
                            continue;
                        }
                        #endregion

                        if (PaidLeave != null)
                        {
                            //lưu phần tử TienBuPhepNam
                            Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance();
                            UnusualAllowance.ID              = Guid.NewGuid();
                            UnusualAllowance.ProfileID       = profile.ID;
                            UnusualAllowance.UnusualEDTypeID = PaidLeave.ID;

                            UnusualAllowance.MonthStart = CutOffDuration.DateStart;
                            UnusualAllowance.MonthEnd   = CutOffDuration.DateEnd;
                            UnusualAllowance.Type       = EnumDropDown.EDType.E_EARNING.ToString();
                            UnusualAllowance.CurrencyID = model.CurrencyID;
                            FormulaValue            = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienPhepNam").FirstOrDefault();
                            UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0");
                            repoUnusualAllowance.Add(UnusualAllowance);
                        }

                        if (GoodHealth != null)
                        {
                            //lưu phần tử TienSucKhoe
                            Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance();
                            UnusualAllowance                 = new Sal_UnusualAllowance();
                            UnusualAllowance.ID              = Guid.NewGuid();
                            UnusualAllowance.ProfileID       = profile.ID;
                            UnusualAllowance.UnusualEDTypeID = GoodHealth.ID;

                            UnusualAllowance.MonthStart = CutOffDuration.DateStart;
                            UnusualAllowance.MonthEnd   = CutOffDuration.DateEnd;
                            UnusualAllowance.Type       = EnumDropDown.EDType.E_EARNING.ToString();
                            UnusualAllowance.CurrencyID = model.CurrencyID;
                            FormulaValue            = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == "TienSucKhoe").FirstOrDefault();
                            UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0");
                            repoUnusualAllowance.Add(UnusualAllowance);
                        }
                    }
                    else
                    {
                        Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance();
                        UnusualAllowance.ID              = Guid.NewGuid();
                        UnusualAllowance.ProfileID       = profile.ID;
                        UnusualAllowance.UnusualEDTypeID = model.UnusualEDTypeID;

                        UnusualAllowance.MonthStart = CutOffDuration.DateStart;
                        UnusualAllowance.MonthEnd   = CutOffDuration.DateEnd;
                        UnusualAllowance.Type       = EnumDropDown.EDType.E_EARNING.ToString();
                        UnusualAllowance.CurrencyID = model.CurrencyID;
                        try
                        {
                            listElementFormula        = new List <ElementFormula>();
                            TotalData.listElement_All = repoCat_Element.FindBy(m => m.IsDelete != true).ToList().Translate <Cat_ElementEntity>();
                            listElementFormula        = CumputePayrollServices.ParseFormula(ElementItem, listElementFormula, TotalData, profile, CutOffDuration, new Dictionary <Guid, ValueCount>());
                            FormulaValue            = listElementFormula.Where(m => m.VariableName.ReplaceSpace() == ElementItem.ElementCode.ReplaceSpace()).FirstOrDefault();
                            UnusualAllowance.Amount = double.Parse(FormulaValue != null ? FormulaValue.Value.ToString() : "0");
                        }
                        catch
                        {
                            UnusualAllowance.Amount = 0;
                            UnusualAllowance.Notes  = "Không tính được công thức - Lỗi: " + TotalData.Status;
                        }
                        repoUnusualAllowance.Add(UnusualAllowance);
                    }

                    if (ListProfile.IndexOf(profile) % 10 == 0)
                    {
                        asynTask.PercentComplete = (double)(ListProfile.IndexOf(profile) + 1) / (double)ListProfile.Count;
                        unitOfWork.SaveChanges();
                    }
                }
                asynTask.PercentComplete = 1;
                unitOfWork.SaveChanges();
            }
        }
Пример #3
0
        public Sal_UnusualAllowanceModel Post([Bind] Sal_UnusualAllowanceModel model)
        {
            var    hrService = new Hre_ProfileServices();
            var    UnusualAllowanceServices = new Sal_UnusualAllowanceServices();
            string status = string.Empty;

            #region Validate
            string message       = string.Empty;
            var    checkValidate = false;
            //kiểm tra xem có phải là đang create ở trang chi tiết nv ko
            if (model.IsGeneralProfile != null && model.IsGeneralProfile == true)
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDGeneralProfile", ref message);

                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }
                ActionService service = new ActionService(UserLogin);
                return(service.UpdateOrCreate <Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model));
            }
            else
            {
                if (!string.IsNullOrEmpty(model.OrgStructureIDs))
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDOrg", ref message);
                }
                else
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData <Sal_UnusualAllowanceModel>(model, "Sal_UnusualED", ref message);
                }
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return(model);
                }

                if (!string.IsNullOrEmpty(model.OrgStructureIDs))
                {
                    List <Guid> listGuid = new List <Guid>();
                    if (model.ProfileIDExclusion != null)
                    {
                        var listStr = model.ProfileIDExclusion.Split(',');

                        if (listStr[0] != "")
                        {
                            foreach (var item in listStr)
                            {
                                listGuid.Add(Guid.Parse(item));
                            }
                        }
                    }
                    List <object> listObj = new List <object>();
                    listObj.Add(model.OrgStructureID);
                    listObj.Add(string.Empty);
                    listObj.Add(string.Empty);
                    var lstProfile = hrService.GetData <Hre_ProfileIdEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).Select(s => s.ID).ToList();
                    if (listGuid != null)
                    {
                        lstProfile = lstProfile.Where(s => !listGuid.Contains(s)).ToList();
                    }

                    List <Sal_UnusualAllowanceEntity> lstUnusualAllowance = new List <Sal_UnusualAllowanceEntity>();
                    foreach (var i in lstProfile)
                    {
                        Sal_UnusualAllowanceEntity item = new Sal_UnusualAllowanceEntity();
                        item           = model.Copy <Sal_UnusualAllowanceEntity>();
                        item.ProfileID = i;
                        lstUnusualAllowance.Add(item);
                    }
                    model.ActionStatus = UnusualAllowanceServices.Add(lstUnusualAllowance);
                    return(model);
                }
                else
                {
                    string[] listProfile = model.ProfileIDs.Split(',');
                    List <Sal_UnusualAllowanceEntity> lstUnusualAllowance = new List <Sal_UnusualAllowanceEntity>();
                    foreach (var i in listProfile)
                    {
                        Sal_UnusualAllowanceEntity item = new Sal_UnusualAllowanceEntity();
                        item           = model.Copy <Sal_UnusualAllowanceEntity>();
                        item.ProfileID = Guid.Parse(i);
                        lstUnusualAllowance.Add(item);
                    }
                    model.ActionStatus = UnusualAllowanceServices.Add(lstUnusualAllowance);
                    return(model);
                }
            }
            #endregion
        }