예제 #1
0
 public Sal_PayrollTableItem(Sal_UnusualAllowance alw)
 {
     this.Name      = alw.Cat_UnusualAllowanceCfg.UnusualAllowanceCfgName;
     this.Code      = alw.Cat_UnusualAllowanceCfg.Code;
     this.Value     = alw.Amount.ToString();
     this.ValueType = typeof(Double).ToString();
 }
예제 #2
0
        public int[] ApprevedKaiZenData(List<Guid> selectedIds, DateTime MonthYear, Guid UnusualEDTypeID, Guid Currency)
        {
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                var unitOfWork = (IUnitOfWork)new UnitOfWork(context);
                var repoKai_KaizenData = new CustomBaseRepository<Kai_KaizenData>(unitOfWork);
                var repoSal_UnusualAllowance = new CustomBaseRepository<Sal_UnusualAllowance>(unitOfWork);
                List<Sal_UnusualAllowance> listUnusualAllowance = new List<Sal_UnusualAllowance>();

                //lọc ra các kaizen được chọn
                List<Kai_KaizenData> listKaiZendata = repoKai_KaizenData.FindBy(m => m.IsDelete != true).ToList();
                listKaiZendata = listKaiZendata.Where(m => m.Status == EnumDropDown.Kai_KaizenDataStatus.E_APPROVED.ToString() && selectedIds.Any(t => t == m.ID)).ToList();

                int Pass = 0;
                int Fail = 0;

                Sal_UnusualAllowance item = new Sal_UnusualAllowance();
                foreach (var KaiZenItem in listKaiZendata)
                {
                    if (KaiZenItem.DateTransferPayment == null && (KaiZenItem.IsPaymentOut == null || KaiZenItem.IsPaymentOut == false))
                    {
                        item = new Sal_UnusualAllowance();
                        item.ProfileID = KaiZenItem.ProfileID != null ? (Guid)KaiZenItem.ProfileID : Guid.NewGuid();
                        item.MonthStart = new DateTime(MonthYear.Year, MonthYear.Month, 1);
                        item.MonthEnd = new DateTime(MonthYear.Year, MonthYear.Month, 1).AddMonths(1).AddDays(-1);
                        item.Type = EnumDropDown.EDType.E_EARNING.ToString();
                        item.UnusualEDTypeID = UnusualEDTypeID;
                        item.CurrencyID = Currency;
                        item.Amount = KaiZenItem.SumAmount != null ? KaiZenItem.SumAmount : 0;
                        listUnusualAllowance.Add(item);

                        KaiZenItem.DateTransferPayment = MonthYear;
                        Pass++;
                    }
                    else
                    {
                        Fail++;
                    }
                }
                repoSal_UnusualAllowance.Add(listUnusualAllowance);
                unitOfWork.SaveChanges();
                return new int[] { Pass, Fail };
            }
        }
예제 #3
0
파일: UserDataObject.cs 프로젝트: dtafe/vnr
 public Sal_PayrollTableItem(Sal_UnusualAllowance alw)
 {
     this.Name = alw.Cat_UnusualAllowanceCfg.UnusualAllowanceCfgName;
     this.Code = alw.Cat_UnusualAllowanceCfg.Code;
     this.Value = alw.Amount.ToString();
     this.ValueType = typeof(Double).ToString();
 }
예제 #4
0
        ///// <summary>
        ///// Lấy toàn bộ data
        ///// </summary>
        ///// <returns></returns>
        //public IQueryable<Att_AnnualLeave> Get()
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        return repo.Get().Where(i => i.IsDelete == null);
        //    }
        //}

        ///// <summary>
        ///// Lấy dữ liệu theo Id
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public Att_AnnualLeaveEntity Get(int id)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        var data = repo.GetAnnualLeaveById(id);
        //        if (data.IsDelete == true) data = null;
        //        return data;
        //    }
        //}

        //public List<Att_AnnualLeaveEntity> GetAnnualLeaveByIds(string selectedIds)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        return repo.GetAnnualLeaveByIds(selectedIds);
        //    }
        //}

        ///// <summary>
        ///// Thêm mới một record
        ///// </summary>
        ///// <param name="cat"></param>
        ///// <returns></returns>
        //public bool Add(Att_AnnualLeave model)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        try
        //        {
        //            repo.Add(model);
        //            repo.SaveChanges();
        //            return true;
        //        }
        //        catch
        //        {
        //            return false;
        //        }
        //    }
        //}

        ///// <summary>
        ///// Edit một record
        ///// </summary>
        ///// <param name="cat"></param>
        ///// <returns></returns>
        //public bool Edit(Att_AnnualLeave model)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        try
        //        {
        //            repo.Edit(model);
        //            repo.SaveChanges();
        //            return true;
        //        }
        //        catch
        //        {
        //            return false;
        //        }

        //    }
        //}

        ///// <summary>
        ///// Remove 1 record là chuyển trạng thái IsDelete=true
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public bool Remove(int id)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        var data = repo.GetById(id);
        //        try
        //        {
        //            repo.Remove(data);
        //            repo.SaveChanges();
        //            return true;
        //        }
        //        catch
        //        {
        //            return false;
        //        }

        //    }
        //}

        ///// <summary>
        ///// Delete 1 record là xóa luôn record khỏi database
        ///// </summary>
        ///// <param name="id"></param>
        ///// <returns></returns>
        //public bool Delete(int id)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        var repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        var data = repo.GetById(id);
        //        try
        //        {
        //            repo.Delete(data);
        //            repo.SaveChanges();
        //            return true;
        //        }
        //        catch
        //        {
        //            return false;
        //        }

        //    }
        //}

        //#region Store Procedure

        //#region Danh sách

        ///// <summary>
        ///// Lấy danh sách dữ liệu AnnualLeaves [Tung.Ly - 2014/05/09]
        ///// </summary>
        ///// <returns></returns>
        //public IQueryable<Att_AnnualLeaveEntity> GetAnnualLeaves(ListQueryModel model)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        IAtt_AnnualLeaveRepository repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        var rs = repo.GetAnnualLeaves(model);
        //        return rs;
        //    }
        //}

        //#endregion

        //#region Chi tiet

        ///// <summary>
        ///// Lấy dữ liệu AnnualLeave theo Id [Tung.Ly - 2014/05/09]
        ///// </summary>
        ///// <param name="annualLeaveId"></param>
        ///// <returns></returns>
        //public Att_AnnualLeaveEntity GetAnnualLeaveById(int annualLeaveId)
        //{
        //    using (var context = new VnrHrmDataContext())
        //    {
        //        var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
        //        IAtt_AnnualLeaveRepository repo = new Att_AnnualLeaveRepository(unitOfWork);
        //        var data = repo.GetAnnualLeaveById(annualLeaveId);
        //        return data;
        //    }
        //}

        //#endregion

        //#endregion
        #endregion

        #region thanh toán phép năm đầu kỳ

        public void SetAnnualLeaveBeginYear(List<Guid> lstProfileIDs, double? limitMaximum, int Year, int? MonthResetANL, Guid? AllowanceTypeID, Guid? CuttOffDurationID)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoAtt_AnnualLeave = new CustomBaseRepository<Att_AnnualLeave>(unitOfWork);
                var repoAtt_AnnualDetail = new CustomBaseRepository<Att_AnnualDetail>(unitOfWork);
                var repoSal_UnusualAllowance = new CustomBaseRepository<Sal_UnusualAllowance>(unitOfWork);
                var repoAtt_CutOffDuration = new CustomBaseRepository<Att_CutOffDuration>(unitOfWork);
                //nếu có rồi thì chỉ cần Update
                //Nếu chưa có thì tạo mới
                Att_CutOffDuration CutOffDuration = new Att_CutOffDuration();
                if (CuttOffDurationID != null)
                {
                    CutOffDuration = repoAtt_CutOffDuration.FindBy(m => m.ID == CuttOffDurationID).FirstOrDefault();
                }


                int LastYear = Year - 1;
                DateTime? MaxTime = repoAtt_AnnualDetail.FindBy(m => m.IsDelete != null && m.Year == LastYear).OrderByDescending(m => m.MonthYear).Select(m => m.MonthYear).FirstOrDefault();
                List<Att_AnnualDetail> lstAnnualDetail = new List<Att_AnnualDetail>();
                if (MaxTime != null)
                {
                    lstAnnualDetail = repoAtt_AnnualDetail.FindBy(m => m.MonthYear == MaxTime
                        && m.ProfileID != null
                        && lstProfileIDs.Contains(m.ProfileID.Value)).ToList();
                }
                var lstAnnualLeaveInDB = repoAtt_AnnualLeave.FindBy(m => m.IsDelete == null && m.Year == Year && lstProfileIDs.Contains(m.ProfileID)).ToList();


                foreach (var ProfileID in lstProfileIDs)
                {
                    Att_AnnualLeave AnnualLeaveByProfile = lstAnnualLeaveInDB.Where(m => m.ProfileID == ProfileID).FirstOrDefault();
                    bool IsNew = false;
                    if (AnnualLeaveByProfile == null)
                    {
                        IsNew = true;
                        AnnualLeaveByProfile = new Att_AnnualLeave();
                        AnnualLeaveByProfile.ID = Guid.NewGuid();
                        AnnualLeaveByProfile.ProfileID = ProfileID;
                        AnnualLeaveByProfile.Year = Year;
                        AnnualLeaveByProfile.MonthStart = 1;

                    }
                    AnnualLeaveByProfile.MonthResetAnlOfBeforeYear = MonthResetANL;
                    double RemainLastYear = lstAnnualDetail.Where(m => m.ProfileID == ProfileID).Select(m => m.Remain ?? 0).FirstOrDefault();
                    if (limitMaximum != null)
                    {
                        AnnualLeaveByProfile.InitAnlValue = RemainLastYear > limitMaximum.Value ? limitMaximum.Value : RemainLastYear;
                        AnnualLeaveByProfile.SurplusAnllastYear = RemainLastYear > limitMaximum ? RemainLastYear - limitMaximum : 0;
                        if (CutOffDuration.ID != null && CutOffDuration.ID != Guid.Empty && AllowanceTypeID != null)
                        {
                            Sal_UnusualAllowance UnusualAllowance = new Sal_UnusualAllowance();
                            UnusualAllowance.ProfileID = ProfileID;
                            UnusualAllowance.MonthStart = CutOffDuration.DateStart;
                            UnusualAllowance.MonthEnd = CutOffDuration.DateEnd;
                            UnusualAllowance.UnusualEDTypeID = AllowanceTypeID;
                            UnusualAllowance.Amount = AnnualLeaveByProfile.SurplusAnllastYear;
                            repoSal_UnusualAllowance.Add(UnusualAllowance);
                        }
                    }
                    else
                    {
                        AnnualLeaveByProfile.InitAnlValue = RemainLastYear;
                        AnnualLeaveByProfile.SurplusAnllastYear = 0;
                    }
                    //Sửa lại theo phần tử mới mà Sơn build
                    if (IsNew)
                    {
                        repoAtt_AnnualLeave.Add(AnnualLeaveByProfile);
                    }
                    else
                    {
                        repoAtt_AnnualLeave.Edit(AnnualLeaveByProfile);
                    }
                }
                repoAtt_AnnualLeave.SaveChanges();
                repoSal_UnusualAllowance.SaveChanges();
            }
        }
예제 #5
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();
            }
        }