public Sal_UnusualAllowanceModel Post([Bind]Sal_UnusualAllowanceModel model)
        {
            
            #region Validate
            string message = string.Empty;
            string status = string.Empty;
            ActionService service = new ActionService(UserLogin);
            var checkValidate=true;
            checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew", "Sal_UnusualAllowance", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            if(model != null && model.UnusualEDTypeID !=null)
            {
                var entity = service.GetByIdUseStore<Cat_UnusualAllowanceCfgEntity>(model.UnusualEDTypeID.Value, ConstantSql.hrm_cat_sp_get_UnusualAllowanceCfgId, ref status);
                if (entity != null && entity.Code != null)
                {
                    if (entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEE" || entity.Code.Replace(" ", "") == "HOSPITALOFEMPLOYEEMORETHANONEMONTH")
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew2", "Sal_UnusualAllowance", ref message);

                    }
                    else
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfoNew1", "Sal_UnusualAllowance", ref message);
                    }
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return model;
                    }
                    if (entity.Code.Replace(" ", "") == "BIRTHOFACHILD" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEECHILD" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEESPOUSE" || entity.Code.Replace(" ", "") == "FUNERALOFPARENT")
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo1And2", "Sal_UnusualAllowance", ref message);
                        if(checkValidate == false)
                        {
                            checkValidate = true;
                            //lay thong tin cua quan he
                            var objRelativesModel = service.GetData<Hre_RelativesModel>(Common.DotNetToOracle(model.RelativeID.ToString()), ConstantSql.hrm_hr_sp_get_RelativesById, ref status).FirstOrDefault();
                            var checkValidateRelatives = true;
                            if (objRelativesModel != null)
                            {
                                //lay all nguoi than cua nv do
                                Hre_RelativesServices hreServiveRelative = new Hre_RelativesServices();
                                var lstRelativeByProfileId = hreServiveRelative.GetRelativeByProfileId(model.ProfileID).ToList();
                                if (lstRelativeByProfileId.Count>0)
                                {
                                    //if (model.ID == Guid.Empty)
                                    //    objRelativesModel.ID = Guid.Empty;
                                    var lstDuplicateRelativeByProfileID=lstRelativeByProfileId.
                                        Where(s=>s.ProfileID==objRelativesModel.ProfileID && s.RelativeName==objRelativesModel.RelativeName && s.YearOfBirth==objRelativesModel.YearOfBirth).ToList();
                                    if(lstDuplicateRelativeByProfileID.Count>0)
                                        checkValidateRelatives=false;
                                }
                              //  checkValidateRelatives = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_RelativesModel>(objRelativesModel, "Hre_Relativesinfo1And2", "Hre_Relatives", ref message);
                            }
                            if (checkValidateRelatives == false)
                            {
                                model.ActionStatus = message;
                                return model;
                            }
                        }
                    }
                    else if (entity.Code.Replace(" ", "")=="HOSPITALOFEMPLOYEEMORETHANONEMONTH")
                    {
                        Sal_ReportService salService = new Sal_ReportService();
                        int _daysInMonth = System.DateTime.DaysInMonth(model.DateOccur.Value.Year, model.DateOccur.Value.Month);
                        DateTime _datestart = new DateTime(model.DateOccur.Value.Year, model.DateOccur.Value.Month, 1);
                        DateTime _dateend = new DateTime(model.DateOccur.Value.Year, model.DateOccur.Value.Month, _daysInMonth);
                        //List<object> paraUnusualAllowance = new List<object>();
                        //paraUnusualAllowance.AddRange(new object[7]);
                        //paraUnusualAllowance[2] = model.UnusualEDTypeID;
                        //paraUnusualAllowance[3] = _datestart;
                        //paraUnusualAllowance[4] = _dateend;
                        //paraUnusualAllowance[5] = 1;
                        //paraUnusualAllowance[6] = int.MaxValue;
                        Sal_UnusualAllowanceServices salServiceUnusualAllowance = new Sal_UnusualAllowanceServices();
                        //var lstUnusualAllowance = salServiceUnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(paraUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualAllowanceFilialWedding, ref status);
                        var lstUnusualAllowance = salServiceUnusualAllowance.GetUnusualAllowanceByUnusualEDTypeIDAndDateOccur(model.ProfileID,model.UnusualEDTypeID, _datestart, _dateend);
                        if (lstUnusualAllowance != null)
                        {
                            //lstUnusualAllowance = lstUnusualAllowance.Where(s => s.ProfileID == model.ProfileID).ToList();
                            if ((lstUnusualAllowance.Count > 0 && model.ID == Guid.Empty) || (lstUnusualAllowance.Count > 1 && model.ID != Guid.Empty))
                            {
                                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo3", "Sal_UnusualAllowance", ref message);
                                if (!checkValidate)
                                {
                                    model.ActionStatus = message;
                                    return model;
                                }
                            }
                        }
                    }
                    else if (entity.Code.Replace(" ", "") == "MARRIAGEOFEMPLOYEE" || entity.Code.Replace(" ", "") == "DEATHOFEMPLOYEE")
                    {
                        checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualAllowanceinfo5And6And7", "Sal_UnusualAllowance", ref message);
                    }
                }
             
            }
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            #endregion
        
            return service.UpdateOrCreate<Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model);
        }
Example #2
0
        public DataTable GetReportHaveChildUsunual(string orderNumberOrg, DateTime? dateFrom, DateTime? dateTo, string UserLogin, bool IsCreateTemplate)
        {

            DataTable table = CreateReportHaveChildUsunualSchema();
            if (IsCreateTemplate)
            {
                return table;
            }
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var orgTypeServices = new Cat_OrgStructureTypeServices();
                var objOrgType = new List<object>();
                objOrgType.Add(null);
                objOrgType.Add(null);
                objOrgType.Add(1);
                objOrgType.Add(int.MaxValue - 1);
                var lstOrgType = orgTypeServices.GetData<Cat_OrgStructureTypeEntity>(objOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, UserLogin, ref status).ToList();

                var orgServices = new Cat_OrgStructureServices();
                var objOrg = new List<object>();
                objOrg.Add(null);
                objOrg.Add(null);
                objOrg.Add(null);
                objOrg.Add(1);
                objOrg.Add(int.MaxValue - 1);
                var lstOrg = orgServices.GetData<Cat_OrgStructureEntity>(objOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, UserLogin, ref status).ToList();

                //if (lstOrgType != null)
                //{
                //    lstOrg = lstOrg.Where(s => s.OrgStructureTypeID != null && s.OrgStructureTypeID == lstOrgType.ID).ToList();
                //}
                var lstOrgNumber = lstOrg.Select(s => s.OrderNumber).ToList();
                var strOrderNumber = string.Join(",", lstOrgNumber);

                var profileServices = new Hre_ProfileServices();
                var objProfile = new List<object>();
                objProfile.Add(strOrderNumber);
                objProfile.Add(null);
                objProfile.Add(null);
                var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, UserLogin, ref status).ToList();

                var relativeServices = new Hre_RelativesServices();
                var objRelative = new List<object>();
                objRelative.AddRange(new object[11]);
                objRelative[9] = 1;
                objRelative[10] = int.MaxValue - 1;
                var lstRelatives = relativeServices.GetData<Hre_RelativesEntity>(objRelative, ConstantSql.hrm_hr_sp_get_Relatives, UserLogin, ref status).ToList();
                var repoCat_OrgStructure = new CustomBaseRepository<Cat_OrgStructure>(unitOfWork);
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => s.IsDelete == null).ToList();
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();

                var UnusualAllowance = new Sal_UnusualAllowanceServices();
                var objUnusualAllowance = new List<object>();
                objUnusualAllowance.AddRange(new object[7]);
                objUnusualAllowance[3] = dateFrom;
                objUnusualAllowance[4] = dateTo;
                objUnusualAllowance[5] = 1;
                objUnusualAllowance[6] = int.MaxValue - 1;
                List<Sal_UnusualAllowanceEntity> listUnusualAllowance = UnusualAllowance.GetData<Sal_UnusualAllowanceEntity>(objUnusualAllowance, ConstantSql.hrm_sal_sp_get_UnusualEDChildCare, UserLogin, ref status);

                //lọc nhân viên có hưởng phụ cấp con nhỏ
                lstProfile = lstProfile.Where(m => listUnusualAllowance.Any(t => t.ProfileID == m.ID)).ToList();

                foreach (var item in lstProfile)
                {
                    DataRow dr = table.NewRow();

                    var lstRelativeByProfileID = lstRelatives.Where(s => s.ProfileID == item.ID).ToList();
                    if (lstRelativeByProfileID.Count == 0)
                    {
                        continue;
                    }
                    Guid? orgId = item.OrgStructureID;
                    var unit = LibraryService.GetNearestParent(orgId, OrgUnit.E_UNIT, orgs, orgTypes);
                    var division = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);
                    var department = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                    var section = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.CodeEmp] = item.CodeEmp;
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.ProfileName] = item.ProfileName;
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_UNIT] = item.E_UNIT;
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_DIVISION] = item.E_DIVISION;
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_DEPARTMENT] = item.E_DEPARTMENT;
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_TEAM] = item.E_TEAM;
                    dr[Sal_ReportHaveChildUsunualEntity.FieldNames.E_SECTION] = item.E_SECTION;
                    if (lstRelativeByProfileID.Count > 0)
                    {
                        var count = 0;
                        foreach (var relative in lstRelativeByProfileID)
                        {
                            var _tmp = new DateTime();
                            count++;
                            if (count == 11)
                            {
                                break;
                            }
                            if (relative.YearOfBirth != null)
                            {
                                var strYearOfBirth = relative.YearOfBirth.Split('/');
                                var newYOB = new DateTime(int.Parse(strYearOfBirth[2]), int.Parse(strYearOfBirth[1]), int.Parse(strYearOfBirth[0]));
                                var dateCheck = DateTime.Now;

                                var age = (dateCheck.Subtract(_tmp).TotalDays / 30) / 12;
                                dr[Sal_ReportHaveChildUsunualEntity.FieldNames.RelativeName + count] = relative.RelativeName;
                                dr[Sal_ReportHaveChildUsunualEntity.FieldNames.DateBorn + count] = newYOB;

                            }

                        }
                    }
                    table.Rows.Add(dr);
                }

                return table.ConfigTable(true);
            }


        }
        public Sal_UnusualAllowanceModel Post([Bind]Sal_UnusualAllowanceModel model)
        {
            #region Validate
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDChildCareInfo", "Sal_UnusualAllowance", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            if (model.RelativeID != null)
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDChildCareDuplicate", "Sal_UnusualAllowance", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return model;
                }
            }
            else
            {
                checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Sal_UnusualAllowanceModel>(model, "Sal_UnusualEDChildCareDuplicate1", "Sal_UnusualAllowance", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return model;
                }
            }
            DateTime now = model.MonthEnd.Value;
            int age = now.Year - model.MonthStart.Value.Year;
            if (now < model.MonthStart.Value.AddYears(age)) age--;
            if (age > 18)
            {
                model.ActionStatus = "Con nhân viên không được vượt quá 18 tuổi";
                return model;
            }

            #endregion

            string status = string.Empty;
            var relativeServices = new Hre_RelativesServices();
            var objRelatives = new List<object>();
            objRelatives.AddRange(new object[11]);
            objRelatives[9] = 1;
            objRelatives[10] = int.MaxValue - 1;
            var lstRelatives = relativeServices.GetData<Hre_RelativesEntity>(objRelatives, ConstantSql.hrm_hr_sp_get_Relatives, UserLogin, ref status).ToList();
            if (model.RelativeID != null)
            {
                var dateNow = DateTime.Now;
                var entity = lstRelatives.Where(s => s.ID == model.RelativeID).FirstOrDefault();
                if (entity != null)
                {
                    if (!string.IsNullOrEmpty(entity.YearOfBirth))
                    {
                        var strDob = entity.YearOfBirth.Split('/');
                        //    var dob = DateTime.Parse(entity.YearOfBirth);
                        var checkDob = (dateNow.Year - int.Parse(strDob[2])) * 12 + dateNow.Month - int.Parse(strDob[1]);
                        if (checkDob >= 216)
                        {
                            model.ActionStatus = ConstantMessages.WarningRelativeGreaterThan18.ToString().TranslateString();
                            return model;
                        }
                    }
                }
            }

            ActionService service = new ActionService(UserLogin);
            return service.UpdateOrCreate<Sal_UnusualAllowanceEntity, Sal_UnusualAllowanceModel>(model);
        }
Example #4
0
 public JsonResult GetMultiRelation()
 {
     string status = string.Empty;
     var service = new Hre_RelativesServices();
     var get = service.GetAllUseEntity<Hre_RelativesEntity>(ref status);
     var result = get.Select(item => new Hre_RelativesModel()
     {
         ID = item.ID,
         RelativeName = item.RelativeName,
     });
     return Json(result, JsonRequestBehavior.AllowGet);
 }