Пример #1
0
        public ActionResult ExportContractAllByTemplate([DataSourceRequest] DataSourceRequest request, Hre_ContractSearchModel model)
        {
            var contractServices = new Hre_ContractServices();
            var actionServices = new ActionService(UserLogin);
            string status = string.Empty;
            string messages = string.Empty;
            //string folderStore = DateTime.Now.ToString("ddMMyyyyHHmmss");
            DateTime DateStart = DateTime.Now;

            var lstContractAll = GetListData<Hre_ContractModel, Hre_ContractEntity, Hre_ContractSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ContractList, ref status);


            string dirpath = Common.GetPath(Common.DownloadURL); ;
            if (!Directory.Exists(dirpath))
                Directory.CreateDirectory(dirpath);



            var objs = new List<object>();
            string strIDs = string.Empty;
            //foreach (var item in selectedIds)
            //{
            //    strIDs += Common.DotNetToOracle(item.ToString()) + ",";
            //}
            //if (strIDs.IndexOf(",") > 0)
            //    strIDs = strIDs.Substring(0, strIDs.Length - 1);
            //objs.Add(strIDs);
            //var lstContract = baseService.GetData<Hre_ContractEntity>(objs, ConstantSql.hrm_hr_sp_get_ContractsByListId, ref status);
            if (lstContractAll == null)
                return null;
            int i = 0;

            String suffix = DateStart.ToString("_ddMMyyyyHHmmss");
            string folferPath = string.Empty;
            string folderName = "ExportHre_Contract" + suffix;
            if (lstContractAll.Count > 1)
            {
                folferPath = dirpath + "/" + folderName;
                Directory.CreateDirectory(folferPath);
            }
            else
            {
                folferPath = dirpath;
            }
            var fileDoc = string.Empty;
            foreach (var contract in lstContractAll)
            {
                if (contract.NoPrint == null)
                {
                    contract.NoPrint = 1;
                }
                else
                {
                    contract.NoPrint++;
                }
                contract.DateNow = DateTime.Now.ToString("dd/MM/yyyy");
                contract.DateNow_Day = DateTime.Now.Day.ToString();
                contract.DateNow_Month = DateTime.Now.Month.ToString();
                contract.DateNow_Year = DateTime.Now.Year.ToString();
                contract.IDDateOfIssueFormat = contract.IDDateOfIssue.HasValue ? contract.IDDateOfIssue.Value.ToString("dd/MM/yyyy") : null;
                if (contract.DateStart != null)
                {
                    contract.DateStartFormat = contract.DateStart.ToString("dd/MM/yyyy");
                    contract.DateStart_Day = contract.DateStart.Day.ToString();
                    contract.DateStart_Month = contract.DateStart.Month.ToString();
                    contract.DateStart_Year = contract.DateStart.Year.ToString();
                }
                if (contract.DateEnd.HasValue)
                {
                    contract.DateEndFormat = contract.DateEnd.Value.ToString("dd/MM/yyyy");
                    contract.DateEnd_Day = contract.DateStart.Day.ToString();
                    contract.DateEnd_Month = contract.DateStart.Month.ToString();
                    contract.DateEnd_Year = contract.DateStart.Year.ToString();
                }

                if (contract.DateSigned.HasValue)
                {
                    contract.DateSignedFormat = contract.DateSigned.Value.ToString("dd/MM/yyyy");
                    contract.DateSigned_Day = contract.DateSigned.Value.Day.ToString("dd/MM/yyyy");
                    contract.DateSigned_Month = contract.DateSigned.Value.Month.ToString("dd/MM/yyyy");
                    contract.DateSigned_Year = contract.DateSigned.Value.Year.ToString("dd/MM/yyyy");
                }

                if (contract.DateHire.HasValue)
                {
                    contract.DateHireFormat = contract.DateHire.Value.ToString("dd/MM/yyyy");
                }
                if (contract.DateEndProbation.HasValue)
                {
                    contract.DateEndProbationFormat = contract.DateEndProbation.Value.ToString("dd/MM/yyyy");
                }
                contract.SalaryFormat = contract.Salary.HasValue ? contract.Salary.Value.ToString("N") : "0";
                if (contract.DateOfEffect.HasValue)
                {
                    contract.DateOfEffectFormat = contract.DateOfEffect.Value.ToString("dd MMM yyyy");
                    contract.DateOfEffectMoreTwoMonthFormat = contract.DateOfEffect.Value.AddMonths(+2).ToString("dd MMM yyyy");
                }
                if (contract.Gender == "E_FEMALE")
                {
                    contract.GraveName = "Ms." + contract.ProfileName.Substring(contract.ProfileName.LastIndexOf(' '));
                }
                else
                {
                    contract.GraveName = "Mr." + contract.ProfileName.Substring(contract.ProfileName.LastIndexOf(' '));
                }
                if (contract.DateQuit.HasValue)
                {
                    if (contract.DateHire.HasValue)
                    {
                        contract.MonthWorking = Math.Floor(contract.DateQuit.Value.Subtract(contract.DateHire.Value).TotalDays / 30);
                        contract.YearWorking = Math.Floor(contract.MonthWorking.Value / 12);
                        if (contract.YearWorking > 0)
                        {
                            contract.MonthWorking = contract.MonthWorking - (contract.YearWorking * 12);
                        }
                    }
                }
                else
                {
                    if (contract.DateHire.HasValue)
                    {
                        contract.MonthWorking = Math.Floor(DateTime.Now.Subtract(contract.DateHire.Value).TotalDays / 30);
                        contract.YearWorking = Math.Floor(contract.MonthWorking.Value / 12);
                        if (contract.YearWorking > 0)
                        {
                            contract.MonthWorking = contract.MonthWorking - (contract.YearWorking * 12);
                        }
                    }

                }
                contractServices.Edit(contract);

                ActionService service = new ActionService(UserLogin);
                var exportService = new Cat_ExportServices();
                Cat_ExportEntity template = null;
                string outputPath = string.Empty;
                //List<object> lstObjExport = new List<object>();
                //lstObjExport.Add(null);
                //lstObjExport.Add(null);
                //lstObjExport.Add(null);
                //lstObjExport.Add(null);
                //lstObjExport.Add(1);
                //lstObjExport.Add(10000000);
                if (contract.ExportID.HasValue)
                    template = actionServices.GetData<Cat_ExportEntity>(Common.DotNetToOracle(contract.ExportID.Value.ToString()), ConstantSql.hrm_cat_sp_get_ExportById, ref status).FirstOrDefault();
                if (template == null)
                {
                    messages = "Error";
                    return Json(messages, JsonRequestBehavior.AllowGet);
                }
                string templatepath = Common.GetPath(Common.TemplateURL + template.TemplateFile);

                if (!System.IO.File.Exists(templatepath))
                {
                    messages = "NotTemplate";
                    return Json(messages, JsonRequestBehavior.AllowGet);
                }
                outputPath = folferPath + "/" + Common.ChuyenTVKhongDau(contract.ProfileName) + suffix + i.ToString() + "_" + template.TemplateFile;
                fileDoc = NotificationType.Success.ToString() + "," + Common.DownloadURL + "/" + Common.ChuyenTVKhongDau(contract.ProfileName) + suffix + i.ToString() + "_" + template.TemplateFile;
                var lstcontract = new List<Hre_ContractModel>();
                lstcontract.Add(contract);
                ExportService.ExportWord(outputPath, templatepath, lstcontract);
            }
            if (lstContractAll.Count > 1)
            {
                var fileZip = Common.MultiExport("", true, folderName);
                return Json(fileZip);
            }
            return Json(fileDoc);
        }
Пример #2
0
        public ActionResult ExportContractList([DataSourceRequest] DataSourceRequest request, Hre_ContractSearchModel model)
        {
            return ExportAllAndReturn<Hre_ContractEntity, Hre_ContractModel, Hre_ContractSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ContractList);

        }
Пример #3
0
        public ActionResult GetContractList([DataSourceRequest] DataSourceRequest request, Hre_ContractSearchModel model)
        {
            string status = string.Empty;
            var isDataTable = false;

            var result = GetListData<Hre_ContractModel, Hre_ContractEntity, Hre_ContractSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ContractList, ref status);
            if (model.IsLastestContract == true && result != null)
            {
                var lstProfileID = result.Select(s => s.ProfileID).Distinct().ToList();
                if (lstProfileID.Count > 0)
                {
                    result = result.Where(s => lstProfileID.Contains(s.ProfileID)).OrderByDescending(s => s.DateStart).DistinctBy(s => s.ProfileID).ToList();
                }
            }

            if (model != null && model.IsCreateTemplate)
            {
                var path = Common.GetPath("Templates");
                ExportService exportService = new ExportService();
                ConfigExport cfgExport = new ConfigExport()
                {
                    Object = new Hre_ContractModel(),
                    FileName = "Hre_Contract",
                    OutPutPath = path,
                    DownloadPath = Hrm_Main_Web + "Templates",
                    IsDataTable = isDataTable
                };
                var str = exportService.CreateTemplate(cfgExport);
                return Json(str);
            }
            if (model.ExportId != Guid.Empty)
            {
                var fullPath = ExportService.Export(model.ExportId, result, null, model.ExportType);
                return Json(fullPath);
            }

            var listModel = new List<Hre_ContractModel>();
            if (result != null)
            {
                request.Page = 1;
                foreach (var item in result)
                {
                    var newModle = (Hre_ContractModel)typeof(Hre_ContractModel).CreateInstance();
                    foreach (var property in item.GetType().GetProperties())
                    {
                        newModle.SetPropertyValue(property.Name, item.GetPropertyValue(property.Name));
                    }
                    listModel.Add(newModle);
                }
                var dataSourceResult = listModel.ToDataSourceResult(request);
                if (listModel.FirstOrDefault().GetPropertyValue("TotalRow") != null)
                {
                    dataSourceResult.Total = listModel.Count() <= 0 ? 0 : (int)listModel.FirstOrDefault().GetPropertyValue("TotalRow");
                }
                return Json(dataSourceResult, JsonRequestBehavior.AllowGet);
            }
            return Json(result.ToDataSourceResult(request));
        }
Пример #4
0
        public ActionResult ExportContractListByTemplate([DataSourceRequest] DataSourceRequest request, Hre_ContractSearchModel model)
        {
            string status = string.Empty;
            var contractServices = new Hre_ContractServices();
            var isDataTable = false;
            object obj = new Hre_ProfileModel();
            var result = GetListData<Hre_ContractModel, Hre_ContractEntity, Hre_ContractSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ContractList, ref status);
            DataTable tb = new DataTable();
            var actionServices = new ActionService(UserLogin);
            var _ConstractSearchModel = new Hre_ContractSearchModel();
            var _lsContractAll = GetListData<Hre_ContractModel, Hre_ContractEntity, Hre_ContractSearchModel>(request, _ConstractSearchModel, ConstantSql.hrm_hr_sp_get_Contract, ref status);

            var Lstobj = new List<object>();
            Lstobj.AddRange(new object[18]);
            Lstobj[16] = 1;
            Lstobj[17] = (int.MaxValue - 1);
            var _profileAll = actionServices.GetData<Hre_ProfileEntity>(Lstobj, ConstantSql.hrm_hr_sp_get_Profile, ref status);

            #region lay thong tin hop dong
            for (int i = 0; i < result.Count; i++)
            {
                #region Lay thong tin Profile
                var _profile = _profileAll.Where(s => s.ID == result[i].ProfileID && result[i].ProfileID != null).FirstOrDefault();
                if (_profile != null)
                {
                    if (_profile.PAddress != null)
                        result[i].PAddress = _profile.PAddress;

                    if (_profile.PDistrictName != null)
                        result[i].PDistrictName = _profile.PDistrictName;

                    if (_profile.PCountryName != null)
                        result[i].PCountryName = _profile.PCountryName;

                    if (_profile.PProvinceName != null)
                        result[i].PProvinceName = _profile.PProvinceName;

                    if (result[i].ProfileName != null)
                    {
                        var _profilename = result[i].ProfileName.Split(' ');
                        if (_profilename.Count() == 1)
                        {
                            result[i].FristName = result[i].ProfileName;
                        }
                        else
                        {
                            if (_profilename.Count() == 2)
                            {
                                result[i].FristName = _profilename[0];
                                result[i].LastName = _profilename[1];
                            }
                            else
                            {
                                result[i].FristName = _profilename[0];
                                result[i].LastName = _profilename[_profilename.Count() - 1];
                                for (int j = 1; j < _profilename.Count() - 1; j++)
                                {
                                    result[i].TenDem = result[i].TenDem + _profilename[j];
                                }
                            }

                        }
                    }
                }
                #endregion
                #region Lay thong tin hopn dong truoc do
                var _lsContract = _lsContractAll.Where(s => s.ID == result[i].ID && result[i].ID != null).ToList();
                if (_lsContract != null && _lsContract.Count >= 2)
                {
                    _lsContract = _lsContract.Where(m => m.DateSigned <= result[i].DateSigned).ToList();
                    if (_lsContract.Count >= 2)
                    {
                        Hre_ContractModel _contract = new Hre_ContractModel();
                        _lsContract = _lsContract.OrderByDescending(m => m.DateSigned).ToList();
                        _contract = _lsContract[0];
                        if (_contract.DateStart != null)
                        {
                            result[i].DateStartOld = _contract.DateStart;
                            result[i].DateStartOld_Day = _contract.DateStart.Day.ToString();
                            result[i].DateStartOld_Month = _contract.DateStart.Month.ToString();
                            result[i].DateStartOld_Year = _contract.DateStart_Year.ToString();
                        }
                        if (_contract.DateEnd != null)
                        {
                            result[i].DateEndOld = _contract.DateEnd;
                            result[i].DateEndOld_Day = _contract.DateEnd.Value.Day.ToString();
                            result[i].DateEndOld_Month = _contract.DateEnd.Value.Month.ToString();
                            result[i].DateEndOld_Year = _contract.DateEnd.Value.Year.ToString();
                        }
                        if (_contract.DateSigned != null)
                        {
                            result[i].DateSignedOld = _contract.DateSigned;
                            result[i].DateSignedOld_Day = _contract.DateSigned.Value.Day.ToString();
                            result[i].DateSignedOld_Month = _contract.DateSigned.Value.Month.ToString();
                            result[i].DateSignedOld_Year = _contract.DateSigned.Value.Year.ToString();
                        }
                    }

                }
                #endregion
            }

            #endregion


            var lstEntity = result.Translate<Hre_ContractEntity>();
            tb = contractServices.GetDataContract(lstEntity, UserLogin);

            if (model != null && model.IsCreateTemplate)
            {
                var path = Common.GetPath("Templates");
                ExportService exportService = new ExportService();
                ConfigExport cfgExport = new ConfigExport()
                {
                    Object = tb,
                    FileName = "Hre_Contract",
                    OutPutPath = path,
                    DownloadPath = Hrm_Main_Web + "Templates",
                    IsDataTable = true
                };
                var str = exportService.CreateTemplate(cfgExport);
                return Json(str);
            }
            if (model.ExportId != Guid.Empty)
            {
                var fullPath = ExportService.Export(model.ExportId, lstEntity, null, model.ExportType);
                return Json(fullPath);
            }
            return Json(result.ToDataSourceResult(request));
        }
Пример #5
0
 public ActionResult ApprovedContractAll([DataSourceRequest] DataSourceRequest request, Hre_ContractSearchModel model)
 {
     return GetListDataAndReturn<Hre_ContractModel, Hre_ContractEntity, Hre_ContractSearchModel>(request, model, ConstantSql.hrm_hr_sp_set_ApprovedAllContract);
 }