Beispiel #1
0
        public ActionResult ExportProfileListByTemplate([DataSourceRequest] DataSourceRequest request, Hre_ProfileActiveSearchModel model)
        {
            //if(model.ExportId == Guid.Empty)
            //{
            //    return null;
            //}
            var actionService = new ActionService(UserLogin);
            string status = string.Empty;
            var profileServices = new Hre_ProfileServices();

            bool isGroup = profileServices.IsGroupByOrgProfileQuit();
            var isDataTable = false;
            object obj = new Hre_ProfileModel();
            var result = GetListData<Hre_ProfileModel, Hre_ProfileEntity, Hre_ProfileActiveSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ProfileActive, ref status);

            if (isGroup == true)
            {
                var rptServices = new Hre_ReportServices();
                var orgServices = new Cat_OrgStructureServices();
                var lstObjOrg = new List<object>();
                lstObjOrg.Add(null);
                lstObjOrg.Add(null);
                lstObjOrg.Add(null);
                lstObjOrg.Add(1);
                lstObjOrg.Add(int.MaxValue - 1);
                var lstOrg = actionService.GetData<Cat_OrgStructureEntity>(lstObjOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, ref status).ToList();

                var orgTypeService = new Cat_OrgStructureTypeServices();
                var lstObjOrgType = new List<object>();
                lstObjOrgType.Add(null);
                lstObjOrgType.Add(null);
                lstObjOrgType.Add(1);
                lstObjOrgType.Add(int.MaxValue - 1);
                var lstOrgType = actionService.GetData<Cat_OrgStructureTypeEntity>(lstObjOrgType, ConstantSql.hrm_cat_sp_get_OrgStructureType, ref status).ToList();

                result = GetListData<Hre_ProfileModel, Hre_ProfileEntity, Hre_ProfileActiveSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ProfileActive, ref status);
                DataTable table = new DataTable("Hre_ProfileModel");
                table.Columns.Add("CodeEmp");
                table.Columns.Add("ProfileName");
                table.Columns.Add("FirstName");
                table.Columns.Add("NameFamily");
                table.Columns.Add("Channel");
                table.Columns.Add("Region");
                table.Columns.Add("Area");
                table.Columns.Add("IDNo");
                table.Columns.Add("IDDateOfIssue", typeof(DateTime));
                table.Columns.Add("IDPlaceOfIssue");
                table.Columns.Add("DateOfBirth", typeof(DateTime));
                table.Columns.Add("PlaceOfBirth");
                table.Columns.Add("Gender");
                table.Columns.Add("MarriageStatus");
                table.Columns.Add("NationalityName");
                table.Columns.Add("ReligionName");
                table.Columns.Add("EthnicGroupName");
                table.Columns.Add("Email");
                table.Columns.Add("CellPhone");
                table.Columns.Add("CodeTax");
                table.Columns.Add("TDistrictName");
                table.Columns.Add("PDistrictName");
                table.Columns.Add("JobTitleName");
                table.Columns.Add("DateHire", typeof(DateTime));
                table.Columns.Add("ContractNo");
                table.Columns.Add("DateStartContract");
                table.Columns.Add("DateEndContract");
                table.Columns.Add("ContractTypeName");
                table.Columns.Add("TimesOfContract");
                table.Columns.Add("Notes");
                table.Columns.Add("TAddress");
                table.Columns.Add("PAddress");
                table.Columns.Add("BasicSalary", typeof(double));

                var salaryServices = new Sal_BasicSalaryServices();
                var objSalary = new List<object>();
                objSalary.AddRange(new object[10]);
                objSalary[8] = 1;
                objSalary[9] = int.MaxValue - 1;
                var lstBasicSalary = actionService.GetData<Sal_BasicSalaryEntity>(objSalary, ConstantSql.hrm_sal_sp_get_BasicPayroll, ref status).ToList();

                var unuServices = new Sal_UnusualAllowanceServices();
                var objUnu = new List<object>();
                objUnu.AddRange(new object[9]);
                objUnu[7] = 1;
                objUnu[8] = int.MaxValue - 1;
                var lstUnu = actionService.GetData<Sal_UnusualAllowanceEntity>(objUnu, ConstantSql.hrm_sal_sp_get_UnusualED, ref status).ToList();

                foreach (var item in result)
                {
                    var basicSalaryEntity = lstBasicSalary.Where(s => s.ProfileID == item.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();
                    var lstUnuByProfileID = lstUnu.Where(s => s.ProfileID == item.ID).ToList();
                    var orgName = new List<string>();
                    if (item.OrgStructureID != null)
                    {
                        orgName = rptServices.GetParentOrgName(lstOrg, lstOrgType, item.OrgStructureID);
                        if (orgName.Count < 3)
                        {
                            orgName.Insert(0, string.Empty);
                            if (orgName.Count < 3)
                            {
                                orgName.Insert(0, string.Empty);
                            }
                        }
                    }

                    var lstObjPayroll = new List<object>();
                    lstObjPayroll.Add(item.ID);
                    lstObjPayroll.Add(null);
                    lstObjPayroll.Add(null);
                    lstObjPayroll.Add(null);
                    lstObjPayroll.Add(1);
                    lstObjPayroll.Add(int.MaxValue - 1);
                    var payrollTableByProfileID = actionService.GetData<Sal_PayrollTableItemEntity>(lstObjPayroll, ConstantSql.hrm_sal_sp_get_PayrollTableItemByProfile, ref status).OrderByDescending(s => s.DateCreate);

                    var lstObjContract = new List<object>();
                    lstObjContract.Add(item.ID);
                    var lstContract = actionService.GetData<Hre_ContractEntity>(lstObjContract, ConstantSql.hrm_hr_sp_get_ContractsByProfileId, ref status).OrderBy(s => s.DateCreate).ToList();

                    var lstObjRelative = new List<object>();
                    lstObjRelative.Add(item.ID);
                    lstObjRelative.Add(1);
                    lstObjRelative.Add(Int32.MaxValue - 1);
                    var lstDependant = actionService.GetData<Hre_DependantEntity>(lstObjRelative, ConstantSql.hrm_hr_sp_get_DependantByProfileId, ref status).ToList();

                    DataRow dr = table.NewRow();


                    dr["CodeEmp"] = item.CodeEmp;
                    dr["ProfileName"] = item.ProfileName;
                    dr["FirstName"] = item.FirstName;
                    dr["NameFamily"] = item.NameFamily;
                    if (orgName.Count > 0)
                    {
                        dr["Channel"] = orgName[2];
                        dr["Region"] = orgName[1];
                        dr["Area"] = orgName[0];

                    }

                    dr["IDNo"] = item.IDNo;
                    if (item.IDDateOfIssue != null)
                    {
                        dr["IDDateOfIssue"] = item.IDDateOfIssue.Value;
                    }

                    dr["IDPlaceOfIssue"] = item.IDPlaceOfIssue;
                    if (item.DateOfBirth != null)
                    {
                        dr["DateOfBirth"] = item.DateOfBirth;
                    }
                    dr["Gender"] = item.Gender;
                    if (item.Gender == EnumDropDown.Gender.E_FEMALE.ToString())
                    {
                        dr["Gender"] = "Nữ";
                    }
                    if (item.Gender == EnumDropDown.Gender.E_MALE.ToString())
                    {
                        dr["Gender"] = "Nam";
                    }
                    dr["MarriageStatus"] = item.MarriageStatus;
                    dr["NationalityName"] = item.NationalityName;
                    dr["ReligionName"] = item.ReligionName;
                    dr["EthnicGroupName"] = item.EthnicGroupName;
                    dr["Email"] = item.Email;
                    dr["CellPhone"] = item.Cellphone;
                    dr["CodeTax"] = item.CodeTax;
                    dr["TDistrictName"] = item.TDistrictName;
                    dr["PDistrictName"] = item.PDistrictName;
                    dr["JobTitleName"] = item.JobTitleName;
                    dr["Notes"] = item.Notes;
                    dr["TAddress"] = item.TAddress;
                    dr["PAddress"] = item.PAddress;
                    if (basicSalaryEntity != null)
                    {
                        dr["BasicSalary"] = double.Parse(basicSalaryEntity.GrossAmount);
                    }
                    if (item.DateHire != null)
                    {
                        dr["DateHire"] = item.DateHire.Value;
                    }

                    //if (payrollTableByProfileID != null)
                    //{
                    //    foreach (var payroll in payrollTableByProfileID)
                    //    {
                    //        Double value = 0;
                    //        if (!table.Columns.Contains(payroll.Code))
                    //        {
                    //            table.Columns.Add(payroll.Code, typeof(Double));
                    //        }
                    //        if (table.Columns.Contains(payroll.Code))
                    //        {
                    //            if (payroll.ValueType == typeof(Double).Name)
                    //            {
                    //                Double.TryParse(payroll.Value, out value);
                    //            }
                    //            dr[payroll.Code] = value;
                    //        }
                    //    }
                    //}

                    if (lstContract != null && lstContract.Count > 0)
                    {
                        var contractEntity = lstContract.FirstOrDefault();
                        dr["TimesOfContract"] = lstContract.Count;
                        dr["ContractNo"] = contractEntity.ContractNo;
                        dr["ContractTypeName"] = contractEntity.ContractTypeName;
                        dr["DateStartContract"] = contractEntity.DateStart;
                        if (contractEntity.DateEnd != null)
                        {
                            dr["DateStartContract"] = contractEntity.DateEnd.Value;
                        }

                    }
                    if (lstUnuByProfileID.Count > 0 && lstUnuByProfileID != null)
                    {
                        foreach (var unu in lstUnuByProfileID)
                        {
                            var titleName = unu.UnusualEDTypeCode + "|" + unu.UnusualAllowanceCfgName;
                            if (!table.Columns.Contains(titleName))
                            {
                                table.Columns.Add(titleName);
                            }
                            if (table.Columns.Contains(titleName))
                            {
                                dr[titleName] = unu.Amount;
                            }
                        }
                    }

                    if (lstDependant.Count > 0 && lstDependant != null)
                    {
                        foreach (var dependant in lstDependant)
                        {
                            var titleName = dependant.DependantName + "|" + dependant.RelativeTypeName;
                            if (!table.Columns.Contains(titleName))
                            {
                                table.Columns.Add(titleName);
                            }
                            if (table.Columns.Contains(titleName))
                            {
                                dr[titleName] = dependant.DependantName;
                            }
                        }
                    }
                    table.Rows.Add(dr);
                }

                if (model.IsCreateTemplateForDynamicGrid)
                {
                    obj = result;
                    isDataTable = false;
                }
                if (model != null && model.IsCreateTemplate)
                {

                    var path = Common.GetPath("Templates");
                    ExportService exportService = new ExportService();

                    ConfigExport cfgExport = new ConfigExport()
                    {
                        Object = table,
                        FileName = "Hre_ProfileModel",
                        OutPutPath = path,
                        // HeaderInfo = listHeaderInfo,
                        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, table, null, model.ExportType);
                    return Json(fullPath);
                }

                return Json(result.ToDataSourceResult(request));
            }

            if (model.IsCreateTemplateForDynamicGrid)
            {
                obj = result;
                isDataTable = false;
            }
            if (model != null && model.IsCreateTemplate)
            {

                var path = Common.GetPath("Templates");
                ExportService exportService = new ExportService();

                ConfigExport cfgExport = new ConfigExport()
                {
                    Object = obj,
                    FileName = "Hre_ProfileModel",
                    OutPutPath = path,
                    // HeaderInfo = listHeaderInfo,
                    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);
            }

            return Json(result.ToDataSourceResult(request));
        }
Beispiel #2
0
        public ActionResult GetProfileList([DataSourceRequest] DataSourceRequest request, Hre_ProfileActiveSearchModel model)
        {

            return GetListDataAndReturn<Hre_ProfileModel, Hre_ProfileEntity, Hre_ProfileActiveSearchModel>(request, model, ConstantSql.hrm_hr_sp_get_ProfileActive);
        }