Beispiel #1
0
        public ActionResult GetExpiryContract([DataSourceRequest] DataSourceRequest request, Hre_ReportExpiryContractModel Model)
        {
            string status = string.Empty;
            var service = new Hre_ReportServices();
            var actionServices = new ActionService(UserLogin);
            var profileServices = new Hre_ProfileServices();
            var contractServices = new Hre_ContractServices();
            BaseService baseServices = new BaseService();
            bool isshowloopcontract = profileServices.IsNotUseExpiryContractLoop();

            var ShowAfterDate1 = actionServices.GetData<Sys_AllSettingEntity>("HRM_HRE_CONTRACT_ALERT_EXPRIDAY_VALUEAFTE", ConstantSql.hrm_sys_sp_get_AllSettingByKey, ref status).FirstOrDefault();
            var ShowBeforDate1 = actionServices.GetData<Sys_AllSettingEntity>("HRM_HRE_CONTRACT_ALERT_EXPRIDAY_VALUEBEFOR", ConstantSql.hrm_sys_sp_get_AllSettingByKey, ref status).FirstOrDefault();
            DateTime? dateTo = null;
            DateTime? dateFrom = null;
            if (isshowloopcontract == false)
            {
                dateTo = DateTime.Now.AddDays(Convert.ToDouble(ShowAfterDate1.Value1));
                dateFrom = DateTime.Now.AddDays(-Convert.ToDouble(ShowBeforDate1.Value1));
            }
            var isDataTable = false;
            object obj = new Hre_ReportExpiryContractModel();
         
            //var lstProfile = new List<Hre_ProfileEntity>();
            var objProfile = new List<object>();
            objProfile.AddRange(new object[2]);
            objProfile[0] = 1;
            objProfile[1] = int.MaxValue - 1;
            var lstProfile = actionServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileDataAll, ref status).ToList();

            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 = actionServices.GetData<CatContractTypeModel>(lstObjContractType, ConstantSql.hrm_cat_sp_get_ContractType, ref status).ToList();

            List<object> listObj = new List<object>();
            listObj.Add(Model.OrgStructureID);
            listObj.Add(Model.Status);
            listObj.Add(dateFrom);
            listObj.Add(dateTo);
            listObj.Add(Model.CodeEmp);
            listObj.Add(Model.ProfileName);
            listObj.Add(Model.IDNo);
            listObj.Add(Model.WorkPlaceID);
            listObj.Add(Model.DateSignedFrom);
            listObj.Add(Model.DateSignedTo);
            listObj.Add(Model.ContractNo);
            listObj.Add(1);
            listObj.Add(int.MaxValue - 1);

            var result = actionServices.GetData<Hre_ReportExpiryContractEntity>(listObj, ConstantSql.hrm_hr_sp_get_RptExpireContract, ref status).Where(s => s.StatusEvaluation != WorkdayStatus.E_APPROVED.ToString()).ToList().Translate<Hre_ReportExpiryContractModel>();

           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).ToList();
           
            Guid[] _RankDetailForNextContract = null;
            if (!string.IsNullOrEmpty(Model.RankDetailForNextContractIds))
            {
                _RankDetailForNextContract = Model.RankDetailForNextContractIds.Split(',').Select(s => Guid.Parse(s)).ToArray();
            }
            if (Model.ContractTypeID != null)
            {
                result = result.Where(s => s.ContractTypeID == Model.ContractTypeID).ToList();
            }
            if (!string.IsNullOrEmpty(Model.Status))
            {
                result = result.Where(s => s.Status == Model.Status).ToList();
            }

            var lstModel = new List<Hre_ReportExpiryContractModel>();


            if (_RankDetailForNextContract != null)
            {
                result = result.Where(s => _RankDetailForNextContract.Contains(s.RankDetailForNextContract != null ? s.RankDetailForNextContract.Value : Guid.Empty)).ToList();
            }

            if (Model.EvaType == EnumDropDown.EvaExpiryContract.E_EVA_CONTRACT.ToString())
            {
                result = result.Where(s => s.StatusEvaluation != WorkdayStatus.E_APPROVED.ToString() && s.ContractResult != null).ToList();
                if (isshowloopcontract == false)
                {
                    var model = new Hre_ReportExpiryContractModel();
                    foreach (var item in result)
                    {
                        var ContractByProfileID = lstContracts.Where(s => s.ProfileID == item.ProfileID).OrderByDescending(s => s.DateCreate).FirstOrDefault();
                        if (ContractByProfileID != null)
                        {
                            if (ContractByProfileID.DateCreate != null && ContractByProfileID.DateCreate.Value.ToShortDateString() != DateTime.Now.ToShortDateString())
                            {
                                if (item.DateExtend != null && item.DateExtend >= dateFrom && item.DateExtend <= dateTo)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                                if (item.DateExtend == null && item.DateEnd != null && item.DateEnd >= dateFrom && item.DateEnd <= dateTo)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (var item in result)
                    {
                        var dateSenior = new TimeSpan();
                        double monthSenior = 0;
                        var profileEntity = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();
                        if (profileEntity != null && profileEntity.DateHire != null && Model.DateEnd != null)
                        {
                            dateSenior = Model.DateEnd.Value.Subtract(profileEntity.DateHire.Value);
                            monthSenior = Math.Floor(dateSenior.TotalDays / 30);
                        }

                        item.MonthSenior = (double?)monthSenior;
                        var dateCheck = DateTime.Now;
                        var model = new Hre_ReportExpiryContractModel();
                        var contractTypeEntity = lstContractType.Where(s => item.ContractTypeID == s.ID).FirstOrDefault();
                            if (item.ContractResult == null)
                            {
                                if (contractTypeEntity != null && contractTypeEntity.ExpiryContractLoop != null)
                                {
                                    var dateExpiry = dateCheck.AddDays(contractTypeEntity.ExpiryContractLoop.Value);

                                    if (item.DateExtend != null && item.DateExtend <= dateExpiry)
                                    {
                                        model = item;
                                        lstModel.Add(model);
                                    }
                                    if (item.DateExtend == null && item.DateEnd != null && item.DateEnd.Value <= dateExpiry)
                                    {
                                        model = item;
                                        lstModel.Add(model);
                                    }
                                }
                            }
                        
                    }
                }

            }
            else if (Model.EvaType == EnumDropDown.EvaExpiryContract.E_NONEEVA_CONTRACT.ToString()) 
            {
                result = result.Where(s =>  s.ContractResult == null).ToList();
                if (isshowloopcontract == false)
                {
                    var model = new Hre_ReportExpiryContractModel();
                    foreach (var item in result)
                    {
                        var ContractByProfileID = lstContracts.Where(s => s.ProfileID == item.ProfileID).OrderByDescending(s => s.DateCreate).FirstOrDefault();
                        if (ContractByProfileID != null)
                        {
                            if (ContractByProfileID.DateCreate != null && ContractByProfileID.DateCreate.Value.ToShortDateString() != DateTime.Now.ToShortDateString())
                            {
                                if (item.DateExtend != null && item.DateExtend >= dateFrom && item.DateExtend <= dateTo)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                                if (item.DateExtend == null && item.DateEnd != null && item.DateEnd >= dateFrom && item.DateEnd <= dateTo)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (var item in result)
                    {
                        var dateSenior = new TimeSpan();
                        double monthSenior = 0;
                        var profileEntity = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();
                        if (profileEntity != null && profileEntity.DateHire != null && Model.DateEnd != null)
                        {
                            dateSenior = Model.DateEnd.Value.Subtract(profileEntity.DateHire.Value);
                            monthSenior = Math.Floor(dateSenior.TotalDays / 30);
                        }

                        item.MonthSenior = (double?)monthSenior;
                        var dateCheck = DateTime.Now;
                        var model = new Hre_ReportExpiryContractModel();
                        var contractTypeEntity = lstContractType.Where(s => item.ContractTypeID == s.ID).FirstOrDefault();
                        if (item.ContractResult == null)
                        {
                            if (contractTypeEntity != null && contractTypeEntity.ExpiryContractLoop != null)
                            {
                                var dateExpiry = dateCheck.AddDays(contractTypeEntity.ExpiryContractLoop.Value);

                                if (item.DateExtend != null && item.DateExtend <= dateExpiry)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                                if (item.DateExtend == null && item.DateEnd != null && item.DateEnd.Value <= dateExpiry)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                            }
                        }

                    }
                }
            }
            else
            {
                if (isshowloopcontract == false)
                {
                    var model = new Hre_ReportExpiryContractModel();
                    foreach (var item in result)
                    {
                        var ContractByProfileID = lstContracts.Where(s => s.ProfileID == item.ProfileID).OrderByDescending(s => s.DateCreate).FirstOrDefault();
                        if (ContractByProfileID != null)
                        {
                            if (ContractByProfileID.DateCreate != null && ContractByProfileID.DateCreate.Value.ToShortDateString() != DateTime.Now.ToShortDateString())
                            {
                                if (item.DateExtend != null && item.DateExtend >= dateFrom && item.DateExtend <= dateTo)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                                if (item.DateExtend == null && item.DateEnd != null && item.DateEnd >= dateFrom && item.DateEnd <= dateTo)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                            }
                        }
                    }
                }
                else
                {
                    foreach (var item in result)
                    {
                        var dateSenior = new TimeSpan();
                        double monthSenior = 0;
                        var profileEntity = lstProfile.Where(s => s.ID == item.ProfileID).FirstOrDefault();
                        if (profileEntity != null && profileEntity.DateHire != null && Model.DateEnd != null)
                        {
                            dateSenior = Model.DateEnd.Value.Subtract(profileEntity.DateHire.Value);
                            monthSenior = Math.Floor(dateSenior.TotalDays / 30);
                        }

                        item.MonthSenior = (double?)monthSenior;
                        var dateCheck = DateTime.Now;
                        var model = new Hre_ReportExpiryContractModel();
                        var contractTypeEntity = lstContractType.Where(s => item.ContractTypeID == s.ID).FirstOrDefault();
                      
                            if (contractTypeEntity != null && contractTypeEntity.ExpiryContractLoop != null)
                            {
                                var dateExpiry = dateCheck.AddDays(contractTypeEntity.ExpiryContractLoop.Value);

                                if (item.DateExtend != null && item.DateExtend <= dateExpiry)
                                {
                                    model = item;
                                    lstModel.Add(model);
                                }
                                if (item.DateExtend == null && item.DateEnd != null && item.DateEnd.Value <= dateExpiry)
                                {
                                    model = item;
                                    lstModel.Add(model); 
                                }
                            }
                    }
                }
            }
            
            #region Lấy phụ lục hợp đông
            var _ReportService = new Hre_ContractServices();
            var lisEntity = result.Translate<Hre_ContractEntity>();
            DataTable tb = _ReportService.GetDataContract(lisEntity, UserLogin);
            #endregion
            #region Xuất template

            if (Model != null && Model.IsCreateTemplate)
            {
                var path = Common.GetPath("Templates");
                ExportService exportService = new ExportService();
                ConfigExport cfgExport = new ConfigExport()
                {
                    Object = tb,
                    FileName = "Hre_ContractEntity",
                    OutPutPath = path,
                    DownloadPath = Hrm_Main_Web + "Templates",
                    IsDataTable = true
                };
                var str = exportService.CreateTemplate(cfgExport);
                return Json(str);
            }
            #endregion

            if (Model.ExportID != Guid.Empty)
            {
                var fullPath = ExportService.Export(Model.ExportID, tb, Model.ExportType);
                return Json(fullPath);
            }
            return Json(lstModel.ToDataSourceResult(request));
        }
Beispiel #2
0
        public ActionResult GetReportExpiryContract([DataSourceRequest] DataSourceRequest request, Hre_ReportExpiryContractModel Model)
        {
            var service = new Hre_ReportServices();
            var actionServices = new ActionService(UserLogin);

            DateTime From = DateTime.Now.AddMonths(-1);
            DateTime To = DateTime.Now.AddMonths(1);
            if (Model.DateStart != null)
            {
                From = Model.DateStart.Value;
            }
            if (Model.DateEnd != null)
            {
                To = Model.DateEnd.Value;
            }

            List<object> listObj = new List<object>();
            listObj.Add(Model.OrgStructureID);
            listObj.Add(Model.Status);
            listObj.Add(From);
            listObj.Add(To);
            listObj.Add(Model.CodeEmp);
            listObj.Add(Model.ProfileName);
            listObj.Add(Model.IDNo);
            listObj.Add(Model.WorkPlaceID);
            listObj.Add(Model.DateSignedFrom);
            listObj.Add(Model.DateSignedTo);
            listObj.Add(Model.ContractNo);
            listObj.Add(1);
            listObj.Add(int.MaxValue - 1);
            string status = string.Empty;
            var result = actionServices.GetData<Hre_ReportExpiryContractEntity>(listObj, ConstantSql.hrm_hr_sp_get_RptExpireContract, ref status).ToList().Translate<Hre_ReportExpiryContractModel>();

            if (Model.ExportID != Guid.Empty)
            {
                var fullPath = ExportService.Export(Model.ExportID, result, Model.ExportType);
                return Json(fullPath);
                //ExportService.ExportWord(@"D:\app\TestHD.doc", @"D:\app\BD_HDLDNV.doc", result);
            }
            return Json(result.ToDataSourceResult(request));
        }