Exemple #1
0
        public DataTable GetReportHCGender(DateTime dateSearch, List<Guid?> lstjobTitles, Guid orgID, Guid? orgTypeID, string Gender, bool _isIncludeQuitEmp, bool isCreateTemplate, string userLogin)
        {

            DataTable table = CreateReportHCGenderSchema(orgID, orgTypeID,userLogin);
            if (isCreateTemplate)
            {
                return table.ConfigTable();
            }
            string status = string.Empty;
            using (var context = new VnrHrmDataContext())
            {

                DataRow row1 = table.NewRow();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var serviceProfile = new Hre_ProfileServices();
                var baseService = new BaseService();
                var lstObjProfileIDs = new List<object>();

                var orgsService = new Cat_OrgStructureServices();
                var lstallorgs = orgsService.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, userLogin, ref status).ToList();

                var lstorgs = lstallorgs.Where(s => s.ParentID == orgID).ToList();
                var lstOrgName = lstallorgs.Where(s => s.ID == orgID).FirstOrDefault();

                string male = EnumDropDown.GenderType.E_MALE.ToString();
                string female = EnumDropDown.GenderType.E_FEMALE.ToString();


                var listorgid = lstorgs.Select(s => new { s.ID, s.OrderNumber, s.Code, s.OrgStructureName }).ToList();

                //Xử Lý lấy tất cả nhân viên trong phòng ban đã chọn và group 1 cấp
                var orgIDs = string.Empty;
                orderNumber = string.Empty;

                foreach (var item in listorgid)
                {
                    orderNumber += item.OrderNumber.ToString() + ",";
                    getChildOrgStructure(lstallorgs, item.ID);
                }
                if (orderNumber.IndexOf(',') > 0)
                    orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);

                var lstObjOrgByOrderNumber = new List<object>();
                lstObjOrgByOrderNumber.Add(orderNumber);
                var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, userLogin ,ref status).Select(s => s.ID).ToList();

                List<object> listObj = new List<object>();
                listObj.Add(orderNumber);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);

                var lstprofile = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin ,ref status).ToList();
                if (!_isIncludeQuitEmp)
                {
                    lstprofile = lstprofile.Where(s => s.DateQuit == null).ToList();
                }

                var jobtitleService = new Cat_JobTitleServices();
                var lstObjJobtitle = new List<object>();
                lstObjJobtitle.Add(null);
                lstObjJobtitle.Add(null);
                lstObjJobtitle.Add(null);
                lstObjJobtitle.Add(1);
                lstObjJobtitle.Add(100000);

                var lstJobtitle = GetData<Cat_JobTitleEntity>(lstObjJobtitle, ConstantSql.hrm_cat_sp_get_JobTitle, userLogin ,ref status).ToList();

                if (lstjobTitles != null && lstjobTitles[0] != null && lstjobTitles[0] != Guid.Empty)
                {
                    lstprofile = lstprofile.Where(s => s.JobTitleID != null && lstjobTitles.Contains(s.JobTitleID.Value)).ToList();
                    lstJobtitle = lstJobtitle.Where(s => lstjobTitles.Contains(s.ID)).ToList();
                }
                if (lstprofile == null || lstorgs == null)
                {
                    return table;
                }



                string gender = string.Empty;
                if (Gender == male)
                {
                    gender = "Male";

                }
                else
                {
                    gender = "Female";
                }

                row1[Hre_ReportHCGenderEntity.FieldNames.OrgStructureName] = lstOrgName == null ? string.Empty : lstOrgName.OrgStructureName + " - " + gender;
                table.Rows.Add(row1);

                foreach (var item in lstJobtitle)
                {
                    bool addTitle = false;
                    int totalcount = 0;
                    var count = 0;

                    DataRow row = table.NewRow();
                    var lstJobtitleById = lstJobtitle.Where(s => item.ID == s.ID).FirstOrDefault();
                    row[Hre_ReportHCGenderEntity.FieldNames.JobTitleName] = lstJobtitleById == null ? string.Empty : lstJobtitleById.JobTitleName;

                    foreach (var org in listorgid)
                    {

                        //xử lý đếm nhân viên của phòng ban con
                        orderNumber = string.Empty;
                        orderNumber += org.OrderNumber.ToString() + ",";
                        getChildOrgStructure(lstallorgs, org.ID);

                        if (orderNumber.IndexOf(',') > 0)
                            orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);

                        var lstObjOrgByOrderNumberCount = new List<object>();
                        lstObjOrgByOrderNumberCount.Add(orderNumber);
                        var lstOrgByOrderNumberCount = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumberCount, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, userLogin,ref status).ToList();
                        if (orgTypeID != null)
                        {
                            lstOrgByOrderNumberCount = lstOrgByOrderNumberCount.Where(s => s.OrgStructureTypeID == orgTypeID).ToList();
                        }

                        foreach (var orgName in lstOrgByOrderNumberCount)
                        {

                            var lstprofilebyOrg = lstprofile.Where(s => s.OrgStructureID != null && orgName.ID == s.OrgStructureID.Value && s.JobTitleID == lstJobtitleById.ID && s.Gender == Gender && s.DateHire != null && s.DateHire.Value <= dateSearch).ToList();

                            if (lstprofilebyOrg == null)
                            {
                                continue;
                            }
                            count = lstprofilebyOrg.Count();
                            totalcount += count;
                            if (count > 0)
                            {
                                var orgStructureName = orgName.OrgStructureName;
                                if (orgName != null && !string.IsNullOrEmpty(orgName.OrgStructureName) && table.Columns.Contains(orgStructureName))
                                {
                                    row[orgName.OrgStructureName] = count;
                                }
                                row[Hre_ReportHCGenderEntity.FieldNames.HeadCount] = totalcount;
                                row[Hre_ReportHCGenderEntity.FieldNames.Total] = totalcount;

                            }
                        }
                    }
                    if (totalcount == 0)
                    {
                        continue;
                    }
                    table.Rows.Add(row);

                }
                DataRow datarow = table.NewRow();
                datarow[1] = "Total GT";
                for (int i = 2; i < table.Columns.Count; i++)
                {
                    int gt = 0;
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        var valueRow = table.Rows[j][i].ToString();
                        if (!string.IsNullOrEmpty(valueRow) && !string.IsNullOrWhiteSpace(valueRow))
                        {
                            var value = int.Parse(valueRow);
                            if (value >= 0)
                            {
                                gt += value;
                            }
                        }
                    }

                    datarow[i] = gt;
                }

                table.Rows.Add(datarow);
                return table.ConfigTable(true);
            }
        }
Exemple #2
0
        public DataTable GetReportHCSeniority(DateTime dateSearch, List<Guid> lstjobTitles, Guid orgID, Guid? orgTypeId, bool isIncludeQuitEmp, bool isCreateTemplate, string userLogin)
        {
            List<string> lstSeniority = new List<string> { ">12 Tháng", "9-12 Tháng", "6-9 Tháng", "3-6 Tháng", "0-2 Tháng" };
            DataTable table = CreateReportHCSenioritySchema(orgID, orgTypeId, userLogin);
            if (isCreateTemplate)
            {
                return table.ConfigTable();
            }
            string status = string.Empty;
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var serviceProfile = new Hre_ProfileServices();
                var baseService = new BaseService();
                var lstObjProfileIDs = new List<object>();
                DataRow row1 = table.NewRow();

                var jobtitleServices = new Cat_JobTitleServices();
                var lstJobtitle = jobtitleServices.GetData<Cat_JobTitleEntity>(lstjobTitles[0], ConstantSql.hrm_cat_sp_get_JobTitleById, userLogin,ref status).FirstOrDefault();

                var orgsService = new Cat_OrgStructureServices();
                var lstallorgs = orgsService.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, userLogin, ref status).ToList();

                var lstorgs = lstallorgs.Where(s => s.ParentID == orgID).ToList();
                var lstOrgName = lstallorgs.Where(s => s.ID == orgID).FirstOrDefault();

                var listorgid = lstorgs.Select(s => new { s.ID, s.OrderNumber, s.Code, s.OrgStructureName }).ToList();

                //Xử Lý lấy tất cả nhân viên trong phòng ban đã chọn và group 1 cấp
                var orgIDs = string.Empty;
                orderNumber = string.Empty;
                foreach (var item in listorgid)
                {
                    orderNumber += item.OrderNumber.ToString() + ",";
                    getChildOrgStructure(lstallorgs, item.ID);
                }
                if (orderNumber.IndexOf(',') > 0)
                    orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);

                var lstObjOrgByOrderNumber = new List<object>();
                lstObjOrgByOrderNumber.Add(orderNumber);
                var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, userLogin,ref status).Select(s => s.ID).ToList();

                List<object> listObj = new List<object>();
                listObj.Add(orderNumber);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);

                var lstprofile = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin,ref status).ToList();

                if (!isIncludeQuitEmp)
                {
                    lstprofile = lstprofile.Where(s => s.DateQuit == null).ToList();
                }
                if (lstjobTitles != null && lstjobTitles[0] != null && lstjobTitles[0] != Guid.Empty)
                {
                    lstprofile = lstprofile.Where(s => s.JobTitleID != null && lstjobTitles.Contains(s.JobTitleID.Value)).ToList();
                }
                if (lstprofile == null || lstorgs == null)
                {
                    return table;
                }
                if (lstJobtitle != null)
                {
                    row1[Hre_ReportHCSeniorityEntity.FieldNames.OrgStructureName] = lstOrgName == null ? string.Empty : lstOrgName.OrgStructureName + " - " + lstJobtitle.JobTitleName;
                }
                else
                {
                    row1[Hre_ReportHCSeniorityEntity.FieldNames.OrgStructureName] = lstOrgName == null ? string.Empty : lstOrgName.OrgStructureName;

                }

                table.Rows.Add(row1);

                foreach (var item in lstSeniority)
                {
                    DataRow row = table.NewRow();
                    row[Hre_ReportHCSeniorityEntity.FieldNames.Type] = item;
                    var IDsCount = string.Empty;
                    var count = 0;
                    int totalcount = 0;
                    foreach (var org in lstorgs)
                    {

                        //xử lý đến nhân viên của phòng ban con
                        orderNumber = string.Empty;
                        orderNumber += org.OrderNumber.ToString() + ",";
                        getChildOrgStructure(lstallorgs, org.ID);

                        if (orderNumber.IndexOf(',') > 0)
                            orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);

                        var lstObjOrgByOrderNumberCount = new List<object>();
                        lstObjOrgByOrderNumberCount.Add(orderNumber);
                        var lstOrgByOrderNumberCount = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumberCount, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, userLogin,ref status).ToList();
                        if (orgTypeId != null)
                        {
                            lstOrgByOrderNumberCount = lstOrgByOrderNumberCount.Where(s => s.OrgStructureTypeID == orgTypeId).ToList();
                        }
                        foreach (var orgName in lstOrgByOrderNumberCount)
                        {
                            var lstprofilebyOrg = lstprofile.Where(s => s.OrgStructureID != null && orgName.ID == s.OrgStructureID.Value).ToList();
                            if (lstprofilebyOrg == null)
                            {
                                continue;
                            }
                            // > 12 tháng
                            DateTime dateHire = DateTime.MinValue;
                            if (item == ">12 Tháng")
                            {
                                dateHire = dateSearch.AddMonths(-12);
                                count = lstprofilebyOrg.Where(m => m.DateHire < dateHire).Count();
                            }
                            // 9 -12 tháng
                            if (item == "9-12 Tháng")
                            {
                                dateHire = dateSearch.AddMonths(-9);
                                DateTime datehireTo = dateSearch.AddMonths(-12);
                                count = lstprofilebyOrg.Where(m => m.DateHire < dateHire && m.DateHire >= datehireTo).Count();
                            }
                            // 6-9 tháng
                            if (item == "6-9 Tháng")
                            {
                                dateHire = dateSearch.AddMonths(-6);
                                DateTime datehireTo = dateSearch.AddMonths(-9);
                                count = lstprofilebyOrg.Where(m => m.DateHire < dateHire && m.DateHire >= datehireTo).Count();
                            }
                            // 3-6 tháng
                            if (item == "3-6 Tháng")
                            {
                                dateHire = dateSearch.AddMonths(-3);
                                DateTime datehireTo = dateSearch.AddMonths(-6);
                                count = lstprofilebyOrg.Where(m => m.DateHire < dateHire && m.DateHire >= datehireTo).Count();
                            }
                            // 0-2 tháng
                            if (item == "0-2 Tháng")
                            {
                                dateHire = dateSearch.AddMonths(-2);
                                count = lstprofilebyOrg.Where(m => m.DateHire >= dateHire).Count();
                            }

                            totalcount += count;

                            if (count > 0)
                            {
                                var orgStructureName = orgName.OrgStructureName + "_" + orgName.Code;
                                if (orgName != null && !string.IsNullOrEmpty(orgName.OrgStructureName) && table.Columns.Contains(orgName.OrgStructureName))
                                {
                                    row[Hre_ReportHCGenderEntity.FieldNames.HeadCount] = totalcount;
                                    row[orgName.OrgStructureName] = count;
                                    row[Hre_ReportHCGenderEntity.FieldNames.Total] = totalcount;

                                }
                            }
                        }
                    }
                    //if (totalcount == 0)
                    //{
                    //    continue;
                    //}
                    table.Rows.Add(row);


                }
                DataRow datarow = table.NewRow();
                datarow[1] = "Total GT";
                for (int i = 2; i < table.Columns.Count; i++)
                {
                    int gt = 0;
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        var valueRow = table.Rows[j][i].ToString();
                        if (!string.IsNullOrEmpty(valueRow) && !string.IsNullOrWhiteSpace(valueRow))
                        {
                            var value = int.Parse(valueRow);
                            if (value >= 0)
                            {
                                gt += value;
                            }
                        }
                    }

                    datarow[i] = gt;
                }

                table.Rows.Add(datarow);
                return table.ConfigTable(true);
            }
        }
Exemple #3
0
        public DataTable GetReportMonthlyHC(DateTime DateSearch, List<Guid?> lstjobTitles, Guid orgID, Guid? orgTypeId, bool isCreateTemplate, string userLogin)
        {

            DataTable table = CreateReportMonthlyHCSchema();
            if (isCreateTemplate)
            {
                return table;
            }
            string status = string.Empty;
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var serviceProfile = new Hre_ProfileServices();
                var baseService = new BaseService();
                var lstObjProfileIDs = new List<object>();

                var orgsService = new Cat_OrgStructureServices();
                var lstallorgs = orgsService.GetDataNotParam<Cat_OrgStructure>(ConstantSql.hrm_cat_sp_get_AllOrg, userLogin, ref status).ToList();

                var lstorgs = lstallorgs.Where(s => s.ParentID == orgID).ToList();

                var listorgid = lstorgs.Select(s => new { s.ID, s.OrderNumber, s.OrgStructureTypeID }).ToList();


                //Xử Lý lấy tất cả nhân viên trong phòng ban đã chọn và group 1 cấp
                var orgIDs = string.Empty;
                orderNumber = string.Empty;
                foreach (var item in listorgid)
                {
                    orderNumber += item.OrderNumber.ToString() + ",";
                    getChildOrgStructure(lstallorgs, item.ID);
                }
                if (orderNumber.IndexOf(',') > 0)
                    orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);
                if (orderNumber == string.Empty)
                    return table;

                var lstObjOrgByOrderNumber = new List<object>();
                lstObjOrgByOrderNumber.Add(orderNumber);
                var lstOrgByOrderNumber = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumber, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, userLogin ,ref status).Select(s => new { s.ID, s.OrderNumber, s.OrgStructureName, s.OrgStructureTypeID, s.ParentID }).ToList();
                if (orgTypeId != null)
                {
                    lstOrgByOrderNumber = lstOrgByOrderNumber.Where(s => s.OrgStructureTypeID == orgTypeId).ToList();
                }

                List<object> listObj = new List<object>();
                listObj.Add(orderNumber);
                listObj.Add(string.Empty);
                listObj.Add(string.Empty);


                var headCountService = new Hre_PlanHeadCountServices();
                var lstObjPlanHeadCount = new List<object>();
                lstObjPlanHeadCount.Add(null);
                lstObjPlanHeadCount.Add(1);
                lstObjPlanHeadCount.Add(10000000);
                var lstPlanHeadCount = GetData<Hre_PlanHeadCountEntity>(lstObjPlanHeadCount, ConstantSql.hrm_hr_sp_get_PlanHeadCount, userLogin, ref status).ToList();

                var lstProfile = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin, ref status).Where(s => s.DateHire != null && s.DateQuit == null && s.DateHire <= DateSearch).ToList();
                var lstprofileWorking = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin, ref status).Where(s => s.DateHire != null && s.StatusSyn == null && s.DateHire.Value.Year == DateSearch.Year && s.DateQuit == null).ToList();
                var lstprofileQuit = GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, userLogin, ref status).Where(s => s.DateQuit != null && s.DateQuit.Value.Year == DateSearch.Year).ToList();

                var jobtitleService = new Cat_JobTitleServices();
                var lstObjJobtitle = new List<object>();
                lstObjJobtitle.Add(null);
                lstObjJobtitle.Add(null);
                lstObjJobtitle.Add(null);
                lstObjJobtitle.Add(1);
                lstObjJobtitle.Add(100000);

                var lstJobtitle = GetData<Cat_JobTitleEntity>(lstObjJobtitle, ConstantSql.hrm_cat_sp_get_JobTitle, userLogin, ref status).ToList();

                if (lstjobTitles != null && lstjobTitles[0] != null && lstjobTitles[0] != Guid.Empty)
                {
                    lstprofileWorking = lstprofileWorking.Where(s => s.JobTitleID != null && lstjobTitles.Contains(s.JobTitleID.Value)).ToList();
                    lstprofileQuit = lstprofileQuit.Where(s => s.JobTitleID != null && lstjobTitles.Contains(s.JobTitleID.Value)).ToList();
                    lstJobtitle = lstJobtitle.Where(s => lstjobTitles.Contains(s.ID)).ToList();
                }
                if (lstprofileWorking == null || lstorgs == null || lstprofileQuit == null)
                {
                    return table;
                }

                foreach (var org in lstOrgByOrderNumber)
                {
                    DataRow row = table.NewRow();
                    var parentOrg = lstallorgs.Where(s => s.ID == org.ParentID).FirstOrDefault();
                    row[Hre_ReportMonthlyHCEntity.FieldNames.OrgStructureParentName] = parentOrg != null ? parentOrg.OrgStructureName : string.Empty;
                    row[Hre_ReportMonthlyHCEntity.FieldNames.OrgStructureName] = org != null ? org.OrgStructureName : string.Empty;

                    //xử lý đếm nhân viên của phòng ban con
                    var IDsCount = string.Empty;
                    orderNumber = string.Empty;
                    orderNumber += org.OrderNumber.ToString() + ",";
                    getChildOrgStructure(lstallorgs, org.ID);

                    if (orderNumber.IndexOf(',') > 0)
                        orderNumber = orderNumber.Substring(0, orderNumber.Length - 1);

                    var lstObjOrgByOrderNumberCount = new List<object>();
                    lstObjOrgByOrderNumberCount.Add(orderNumber);
                    var lstOrgByOrderNumberCount = orgsService.GetData<Cat_OrgStructure>(lstObjOrgByOrderNumberCount, ConstantSql.hrm_cat_sp_get_OrgStructureByOrderNumber, userLogin, ref status).Select(s => new { s.ID, s.OrgStructureTypeID }).ToList();
                    if (orgTypeId != null)
                    {
                        lstOrgByOrderNumberCount = lstOrgByOrderNumberCount.Where(s => s.OrgStructureTypeID == orgTypeId).ToList();
                    }
                    var lstOrgGroupByType = lstOrgByOrderNumberCount.Select(s => s.ID).ToList();


                    bool addTitle = false;


                    foreach (var jobtitle in lstJobtitle)
                    {
                        DataRow row1 = table.NewRow();
                        var countingPlanHeadCount = 0;
                        var counttingProfileWorking = 0;
                        var countingProfileQuit = 0;


                        if (jobtitle.OrgStructureID != null)
                        {
                            if (jobtitle.OrgStructureID == orgID)
                            {
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.JobTitleName] = jobtitle != null ? jobtitle.JobTitleName : string.Empty;

                                #region Approved
                                var countProfile = 0;
                                var totalProfile = 0;
                                var lstProfileWorkingByJobTitleID = lstprofileWorking.Where(s => jobtitle.ID == s.JobTitleID && lstOrgGroupByType.Contains(s.OrgStructureID.Value)).Select(p => new { p.ID, p.DateHire, p.StatusSyn }).ToList();
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 01).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 01).ToList().Count();
                                    //   countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    //row1[Hre_ReportMonthlyHCEntity.FieldNames.AppJan] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 02).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 02).ToList().Count();
                                    //    countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    //row1[Hre_ReportMonthlyHCEntity.FieldNames.AppFeb] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 03).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 03).ToList().Count();
                                    //    countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    // row1[Hre_ReportMonthlyHCEntity.FieldNames.AppMar] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 04).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 04).ToList().Count();
                                    //    countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    // row1[Hre_ReportMonthlyHCEntity.FieldNames.AppApr] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 05).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 05).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    // row1[Hre_ReportMonthlyHCEntity.FieldNames.AppMay] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 06).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 06).ToList().Count();
                                    //   countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    //row1[Hre_ReportMonthlyHCEntity.FieldNames.AppJun] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 07).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 07).ToList().Count();
                                    //   countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    //row1[Hre_ReportMonthlyHCEntity.FieldNames.AppJul] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 08).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 08).ToList().Count();
                                    // countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    //row1[Hre_ReportMonthlyHCEntity.FieldNames.AppAug] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 09).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 09).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.AppSep] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 10).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 10).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    // row1[Hre_ReportMonthlyHCEntity.FieldNames.AppOct] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 11).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 11).ToList().Count();
                                    //countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.AppNov] = totalProfile;
                                }
                                if (lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 12).ToList() != null)
                                {
                                    countProfile = lstProfileWorkingByJobTitleID.Where(s => s.DateHire.Value.Month == 12).ToList().Count();
                                    // countingProfileQuit += countProfileQuit;
                                    totalProfile += countProfile;
                                    //row1[Hre_ReportMonthlyHCEntity.FieldNames.AppDec] = totalProfile;
                                }


                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppJan] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppFeb] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppMar] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppApr] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppMay] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppJun] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppJul] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppAug] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppSep] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppOct] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppNov] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppDec] = totalProfile;
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.AppYear] = totalProfile;


                                #endregion

                                #region  Actual HC
                                double countProfileWorking = 0;
                                double totalProfileWorking = 0;

                                var lstProfileByJobTitleID = lstProfile.Where(s => jobtitle.ID == s.JobTitleID && lstOrgGroupByType.Contains(s.OrgStructureID.Value)).Select(p => new { p.ID, p.DateHire, p.StatusSyn, p.DateQuit }).ToList();


                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 01).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 01).ToList().Count();
                                    //   counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActJan] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 02).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 02).ToList().Count();
                                    //  counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActFeb] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 03).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 03).ToList().Count();
                                    //   counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActMar] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 04).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 04).ToList().Count();
                                    //  counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActApr] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 05).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 05).ToList().Count();
                                    //  counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActMay] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 06).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 06).ToList().Count();
                                    // counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActJun] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 07).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 07).ToList().Count();
                                    //  counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActJul] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 08).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 08).ToList().Count();
                                    // counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActAug] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 09).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 09).ToList().Count();
                                    // counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActSep] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 10).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 10).ToList().Count();
                                    // counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActOct] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 11).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 11).ToList().Count();
                                    // counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActNov] = countProfileWorking;
                                }
                                if (lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 12).ToList() != null)
                                {
                                    countProfileWorking = lstProfileByJobTitleID.Where(s => s.DateHire.Value.Month == 12).ToList().Count();
                                    // counttingProfileWorking += countProfileWorking;
                                    totalProfileWorking += countProfileWorking;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.ActDec] = countProfileWorking;
                                }
                                double total = 0;
                                if (totalProfileWorking / 12 < 1 && totalProfileWorking / 12 > 0)
                                {
                                    total = 1;
                                }
                                else
                                {
                                    total = Math.Round(totalProfileWorking / 12);
                                }
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.ActYear] = totalProfileWorking;
                                #endregion

                                #region Leaver HC
                                var countProfileQuit = 0;
                                var totalQuit = 0;
                                var lstProfileQuitByJobTitleID = lstprofileQuit.Where(s => jobtitle.ID == s.JobTitleID && lstOrgGroupByType.Contains(s.OrgStructureID.Value)).Select(p => new { p.ID, p.DateHire, p.StatusSyn, p.DateQuit }).ToList();

                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 01).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 01).ToList().Count();
                                    //   countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaJan] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 02).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 02).ToList().Count();
                                    //    countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaFeb] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 03).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 03).ToList().Count();
                                    //    countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaMar] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 04).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 04).ToList().Count();
                                    //    countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaApr] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 05).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 05).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaMay] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 06).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 06).ToList().Count();
                                    //   countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaJun] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 07).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 07).ToList().Count();
                                    //   countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaJul] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 08).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 08).ToList().Count();
                                    // countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaAug] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 09).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 09).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaSep] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 10).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 10).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaOct] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 11).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 11).ToList().Count();
                                    //  countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaNov] = countProfileQuit;
                                }
                                if (lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 12).ToList() != null)
                                {
                                    countProfileQuit = lstProfileQuitByJobTitleID.Where(s => s.DateQuit.Value.Month == 12).ToList().Count();
                                    // countingProfileQuit += countProfileQuit;
                                    totalQuit += countProfileQuit;
                                    row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaDec] = countProfileQuit;
                                }
                                row1[Hre_ReportMonthlyHCEntity.FieldNames.LeaYear] = totalQuit;
                                #endregion
                                //if (totalQuit == 0 && totalProfileWorking == 0)
                                //{
                                //    continue;
                                //}
                                //if (lstProfileQuitByJobTitleID.Count == 0 && lstProfileWorkingByJobTitleID.Count == 0)
                                //{
                                //    continue;
                                //}
                                if (!addTitle)
                                {
                                    table.Rows.Add(row);
                                    addTitle = true;
                                }
                                table.Rows.Add(row1);
                            }

                        }
                    }

                }

                DataRow datarow = table.NewRow();
                datarow[1] = "Total GT";

                for (int i = 3; i < table.Columns.Count; i++)
                {
                    int gt = 0;
                    for (int j = 0; j < table.Rows.Count; j++)
                    {
                        var valueRow = table.Rows[j][i].ToString();
                        if (!string.IsNullOrEmpty(valueRow) && !string.IsNullOrWhiteSpace(valueRow))
                        {
                            var value = int.Parse(valueRow);
                            if (value >= 0)
                            {
                                gt += value;

                            }
                        }
                    }
                    datarow[i] = gt;
                }

                table.Rows.Add(datarow);
                return table;
            }
        }
Exemple #4
0
        public DataTable GetReportTraineeJoinCourse(Guid[] rankIds, string[] courseIds, string orderNumber, bool IsCreateTemplate, DateTime? dateSeniory, string UserLogin)
        {

            DataTable table = CreateReportTraineeJoinCourseSchema();
            if (IsCreateTemplate)
            {
                return table;
            }
            using (var context = new VnrHrmDataContext())
            {
                string status = string.Empty;

                var dateCheck = DateTime.Now;
                //var dateSeniotyConfig = "31/03/N";
                // var strDateSeniorty = dateSeniotyConfig.Split('/');
                var dateCheckConfig = DateTime.Now;

                //if (dateCheckConfig.Day <= int.Parse(strDateSeniorty[0]) && dateCheckConfig.Month <= int.Parse(strDateSeniorty[1]))
                //{
                //    dateCheckConfig = new DateTime(dateCheckConfig.Year - 1, dateCheckConfig.Month, dateCheckConfig.Day);
                //}
                if (dateSeniory != null)
                {
                    dateCheckConfig = dateSeniory.Value;
                }

                var profileServices = new Hre_ProfileServices();
                var objProfile = new List<object>();
                objProfile.AddRange(new object[17]);
                objProfile[2] = orderNumber;
                objProfile[15] = 1;
                objProfile[16] = int.MaxValue - 1;
                //objProfile.Add(orderNumber);
                //objProfile.Add(null);
                //objProfile.Add(null);
                var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileAll, UserLogin, ref status).Where(s => s.DateQuit == null).ToList();
                //var lstProfile = profileServices.GetData<Hre_ProfileEntity>(objProfile, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrg, ref status).ToList();
                var lstProfileID = lstProfile.Select(s => s.ID).ToList();

                var orgsService = new Cat_OrgStructureServices();
                var objOrg = new List<object>();
                objOrg.AddRange(new object[5]);
                objOrg[3] = 1;
                objOrg[4] = int.MaxValue - 1;
                var lstallorgs = orgsService.GetData<Cat_OrgStructureEntity>(objOrg, ConstantSql.hrm_cat_sp_get_OrgStructure, UserLogin, ref status).ToList();

                var courseServices = new Tra_CourseServices();
                var objCourse = new List<object>();
                objCourse.AddRange(new object[11]);
                objCourse[9] = 1;
                objCourse[10] = int.MaxValue - 1;
                var lstCourse = courseServices.GetData<Tra_CourseEntity>(objCourse, ConstantSql.hrm_tra_sp_get_Course, UserLogin, ref status).ToList();
                if (courseIds != null)
                {
                    lstCourse = lstCourse.Where(s => courseIds.Contains(s.Code)).ToList();
                }

                var jobTitleServices = new Cat_JobTitleServices();
                var objJobtitle = new List<object>();
                objJobtitle.Add(null);
                objJobtitle.Add(null);
                objJobtitle.Add(null);
                objJobtitle.Add(1);
                objJobtitle.Add(int.MaxValue - 1);
                var lstJobtitle = jobTitleServices.GetData<Cat_JobTitleEntity>(objJobtitle, ConstantSql.hrm_cat_sp_get_JobTitle, UserLogin, ref status).ToList();

                var classServices = new Tra_ClassServices();
                var objClass = new List<object>();
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(null);
                objClass.Add(1);
                objClass.Add(int.MaxValue - 1);
                var lstClass = classServices.GetData<Tra_ClassEntity>(objClass, ConstantSql.hrm_tra_sp_get_Class, UserLogin, ref status).ToList();

                var salaryClassServices = new Cat_SalaryClassServices();
                var objSalaryClass = new List<object>();
                objSalaryClass.Add(null);
                objSalaryClass.Add(1);
                objSalaryClass.Add(int.MaxValue - 1);
                var lstSalaryClass = salaryClassServices.GetData<Cat_SalaryClassEntity>(objSalaryClass, ConstantSql.hrm_cat_sp_get_SalaryClass, UserLogin, ref status).ToList();
                if (rankIds != null)
                {
                    lstSalaryClass = lstSalaryClass.Where(s => rankIds.Contains(s.ID)).ToList();
                }

                var rankServices = new Cat_SalaryRankServices();
                var objRank = new List<object>();
                objRank.Add(null);
                objRank.Add(null);
                objRank.Add(1);
                objRank.Add(int.MaxValue - 1);
                var lstRank = rankServices.GetData<Cat_SalaryRankEntity>(objRank, ConstantSql.hrm_cat_sp_get_SalaryRank, UserLogin, ref status).ToList();

                var traineeServices = new Tra_TraineeServices();
                var objTrainee = new List<object>();
                objTrainee.AddRange(new object[15]);
                objTrainee[13] = 1;
                objTrainee[14] = int.MaxValue - 1;
                var lstTrainee = rankServices.GetData<Tra_TraineeEntity>(objTrainee, ConstantSql.hrm_tra_sp_get_Trainee, UserLogin, ref status).ToList();

                var workingHistoryServices = new Hre_WorkHistoryServices();
                var objWorking = new List<object>();
                objWorking.AddRange(new object[17]);
                objWorking[15] = 1;
                objWorking[16] = int.MaxValue - 1;
                var lstWorking = workingHistoryServices.GetData<Hre_WorkHistoryEntity>(objWorking, ConstantSql.hrm_hr_sp_get_WorkHistory, UserLogin, ref status).ToList();


                var stopWorkingServices = new Hre_StopWorkingServices();
                var objStopWorking = new List<object>();
                objStopWorking.AddRange(new object[17]);
                objStopWorking[15] = 1;
                objStopWorking[16] = int.MaxValue - 1;
                var lstStopWorking = stopWorkingServices.GetData<Hre_StopWorkingEntity>(objStopWorking, ConstantSql.hrm_hr_sp_get_StopWorking, UserLogin, ref status).ToList();

                var traineeCertificateServices = new Tra_TraineeCertificateServices();
                var objTraineeCertificate = new List<object>();
                objTraineeCertificate.Add(1);
                objTraineeCertificate.Add(int.MaxValue - 1);
                var lstTraineeCertificate = traineeCertificateServices.GetData<Tra_TraineeCertificateEntity>(objTraineeCertificate, ConstantSql.hrm_tra_sp_get_TraineeCertificate, UserLogin, ref status).ToList();
                var lstTraineeIDFromTraineeCertificate = lstTraineeCertificate.Select(s => s.TraineeID).ToList();

                var requirmentDetailServices = new Tra_RequirementTrainDetailServices();
                var objRequirementDetail = new List<object>();
                objRequirementDetail.Add(null);
                objRequirementDetail.Add(1);
                objRequirementDetail.Add(int.MaxValue - 1);
                var lstRequirementDetail = requirmentDetailServices.GetData<Tra_RequirementTrainDetailEntity>(objRequirementDetail, ConstantSql.hrm_tra_sp_get_RequirementDetail, UserLogin, ref status).ToList();

                //if(lstTrainee != null)
                //{
                //    lstTrainee = lstTrainee.Where(s => lstProfileID.Contains(s.ProfileID)).ToList();
                //}

                if (lstTraineeCertificate != null)
                {
                    lstTrainee = lstTrainee.Where(s => !lstTraineeIDFromTraineeCertificate.Contains(s.ID)).ToList();
                }

                foreach (var item in lstCourse)
                {
                    string[] arrCourse = new string[1];
                    if (!string.IsNullOrEmpty(item.CourseListID))
                    {
                        arrCourse = item.CourseListID.Split(',').ToArray();
                    }

                    string[] arrJobtitle = new string[1];
                    int[] arrOrg = new int[1];
                    if (!string.IsNullOrEmpty(item.JobTitleListCode1))
                    {
                        arrJobtitle = item.JobTitleListCode1.Split(',').ToArray();
                    }
                    if (!string.IsNullOrEmpty(item.OrgListCode1))
                    {
                        arrOrg = item.OrgListCode1.Split(',').Select(s => int.Parse(s)).ToArray();
                    }

                    var lstJobtitleByJobtitleCode = lstJobtitle.Where(s => arrJobtitle.Contains(s.Code)).Select(s => s.ID).ToList();
                    var lstOrgByOrderNumber = lstallorgs.Where(s => arrOrg.Contains(s.OrderNumber)).Select(s => s.ID).ToList();
                    string[] _ranklistID = new string[1];
                    if (!string.IsNullOrEmpty(item.RankListID))
                    {
                        _ranklistID = item.RankListID.Split(',').ToArray();
                    }

                    // var lstClassByCourseID = lstClass.Where(s => s.CourseID == item.ID && arrCourse.Contains(s.CourseID)).ToList();
                    var salaryClassEntity = lstSalaryClass.Where(s => _ranklistID.Contains(s.Code)).ToList();
                    var lstSalaryClassID = salaryClassEntity.Select(s => s.ID).ToList();

                    var lstTraineePassedCourse = new List<Tra_TraineeEntity>();
                    // var lstTraineeForProfile = lstProfile.Where(s => s.CodeEmp == "M26423");
                    if (arrCourse[0] != null)
                    {
                        lstTraineePassedCourse = lstTrainee.Where(s => arrCourse.Contains(s.CourseCode) && s.Status == EnumDropDown.TraineeStatus.E_PASSED.ToString()).ToList();
                        int soLuongKhoaTienQUyet = arrCourse.Count();
                        var lstCheckTraineePassedCourse = lstTraineePassedCourse.GroupBy(m => m.ProfileID).Where(m => m.Count() >= soLuongKhoaTienQUyet).ToList();
                        var lstProfileIDPassedCourse = lstCheckTraineePassedCourse.Select(s => s.Key).Distinct().ToList();
                        lstProfile = lstProfile.Where(s => lstProfileIDPassedCourse.Contains(s.ID)).ToList();
                    }

                    foreach (var profileEntity in lstProfile)
                    {
                        var traineePassCourse = lstTrainee.Where(s => s.CourseID == item.ID && profileEntity.ID == s.ProfileID && s.Status == EnumDropDown.TraineeStatus.E_PASSED.ToString()).FirstOrDefault();
                        if (traineePassCourse != null)
                        {
                            continue;
                        }
                        Guid? orgId = profileEntity.OrgStructureID;
                        //    var org = lstOrg.FirstOrDefault(s => s.ID == profileEntity.OrgStructureID);
                        //   var orgOrg = LibraryService.GetNearestParentEntity(orgId, OrgUnit.E_DEPARTMENT, lstOrg, lstOrgType);
                        DataRow dr = table.NewRow();
                        bool flag = false;
                        var lstTraineeByProfileID = lstTrainee.Where(s => s.ProfileID == profileEntity.ID && arrCourse.Contains(s.CourseCode)).ToList();
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.ID] = profileEntity.ID != null ? profileEntity.ID : Guid.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.CodeEmp] = profileEntity.CodeEmp != null ? profileEntity.CodeEmp : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.TraineeName] = profileEntity.ProfileName != null ? profileEntity.ProfileName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.IDNo] = profileEntity.IDNo != null ? profileEntity.IDNo : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.OrgStructureName] = profileEntity.OrgStructureName != null ? profileEntity.OrgStructureName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_UNIT] = profileEntity.E_UNIT != null ? profileEntity.E_UNIT : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_DIVISION] = profileEntity.E_DIVISION != null ? profileEntity.E_DIVISION : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_DEPARTMENT] = profileEntity.E_DEPARTMENT != null ? profileEntity.E_DEPARTMENT : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_SECTION] = profileEntity.E_SECTION != null ? profileEntity.E_SECTION : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.E_TEAM] = profileEntity.E_TEAM != null ? profileEntity.E_TEAM : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.JobTitleName] = profileEntity.JobTitleName != null ? profileEntity.JobTitleName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.PositionName] = profileEntity.PositionName != null ? profileEntity.PositionName : string.Empty;
                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.CourseName] = item.CourseName != null ? item.CourseName : string.Empty;

                        //var profileEntity = lstProfile.Where(s => s.ID == trainee.ProfileID && s.SalaryClassID != null).FirstOrDefault();
                        var stopWorkingEntity = lstStopWorking.Where(s => s.ProfileID.Value == profileEntity.ID).OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        //var workingEntity = new Hre_WorkHistoryEntity();
                        var lstWorkingByProfileID = lstWorking.Where(s => s.ProfileID == profileEntity.ID && lstSalaryClassID.Contains(s.SalaryClassID == null ? Guid.Empty : s.SalaryClassID.Value)).ToList();
                        if (lstJobtitleByJobtitleCode.Count > 0)
                        {
                            lstWorkingByProfileID = lstWorkingByProfileID.Where(s => lstJobtitleByJobtitleCode.Contains(s.JobTitleID != null ? s.JobTitleID.Value : Guid.Empty)).ToList();

                        }
                        if (lstOrgByOrderNumber.Count > 0)
                        {
                            lstWorkingByProfileID = lstWorkingByProfileID.Where(s => lstOrgByOrderNumber.Contains(s.OrganizationStructureID != null ? s.OrganizationStructureID.Value : Guid.Empty)).ToList();
                        }
                        var workingEntity = lstWorkingByProfileID.OrderByDescending(s => s.DateUpdate).FirstOrDefault();

                        var dateSuspend = new TimeSpan();
                        var dateSeniority = new TimeSpan();
                        double dateResult = 0;
                        double monthSeniority = 0;
                        if (profileEntity.DateHire == null)
                        {
                            continue;
                        }
                        dateSeniority = dateCheckConfig.Subtract(profileEntity.DateHire.Value);

                        if (stopWorkingEntity != null && stopWorkingEntity.DateStop != null && stopWorkingEntity.DateComeBack != null)
                        {
                            dateSuspend = stopWorkingEntity.DateComeBack.Value.Subtract(stopWorkingEntity.DateStop.Value);
                            dateResult = dateSeniority.Subtract(dateSuspend).TotalDays / 30;
                            monthSeniority = Math.Floor(dateResult);
                        }

                        dateSeniority = dateCheckConfig.Subtract(profileEntity.DateHire.Value);
                        monthSeniority = Math.Floor(dateSeniority.TotalDays / 30);

                        dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.Seniority] = monthSeniority;


                        #region KT điều kiện seniority và maxSeniority != null
                        if (item.Seniority != null && item.MaxSeniority != null)
                        {
                            if (monthSeniority >= item.Seniority && item.MaxSeniority >= monthSeniority)
                            {

                                if (salaryClassEntity != null)
                                {
                                    if (workingEntity != null)
                                    {
                                        // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                        // {
                                        var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                        var monthRank = Math.Floor(dateCheckRank);
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (monthRank < item.TimeOnCurrentRank)
                                            {
                                                flag = true;
                                                // table.Rows.Add(dr);
                                            }
                                        }

                                        //}

                                    }
                                }

                            }
                            else
                            {
                                flag = true;
                            }
                        }
                        #endregion

                        #region KT điều kiện seniority != null && maxSeniority == null
                        if (item.Seniority != null && item.MaxSeniority == null)
                        {
                            if (monthSeniority >= item.Seniority)
                            {
                                if (salaryClassEntity != null)
                                {
                                    if (workingEntity != null)
                                    {
                                        //  if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                        // {
                                        var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                        var monthRank = Math.Floor(dateCheckRank);
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (monthRank < item.TimeOnCurrentRank)
                                            {
                                                flag = true;
                                                //  table.Rows.Add(dr);
                                            }
                                        }
                                        // }
                                    }
                                }
                            }
                            else
                            {
                                flag = true;
                            }
                        }
                        #endregion

                        #region KT điều kiện seniority == && maxSeniority != null
                        if (item.MaxSeniority != null && item.Seniority == null)
                        {
                            if (monthSeniority <= item.MaxSeniority)
                            {
                                if (salaryClassEntity != null)
                                {
                                    if (workingEntity != null)
                                    {
                                        // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                        // {
                                        var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                        var monthRank = Math.Floor(dateCheckRank);
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (item.TimeOnCurrentRank != null)
                                            {
                                                if (monthRank < item.TimeOnCurrentRank)
                                                {
                                                    flag = true;
                                                    // table.Rows.Add(dr);
                                                }
                                            }

                                        }

                                        //}

                                    }
                                }
                            }
                            else
                            {
                                flag = true;
                            }

                        }
                        #endregion

                        //#region kiem tra dk Seniority == null và MaxSeniority == null
                        //if (item.Seniority == null && item.MaxSeniority == null)
                        //{
                        //    if (salaryClassEntity != null)
                        //    {
                        //        if (workingEntity != null)
                        //        {
                        //           // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                        //           // {
                        //                var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                        //                var monthRank = Math.Floor(dateCheckRank);
                        //                if (item.TimeOnCurrentRank != null)
                        //                {
                        //                    if (item.TimeOnCurrentRank != null)
                        //                    {
                        //                        if (monthRank < item.TimeOnCurrentRank)
                        //                        {
                        //                            flag = true;
                        //                          //  table.Rows.Add(dr);
                        //                        }
                        //                    }

                        //                }
                        //            //}

                        //        }
                        //    }
                        //}
                        //#endregion


                        if (lstTraineeByProfileID.Count > 0)
                        {
                            foreach (var traineeEntity in lstTraineeByProfileID)
                            {
                                // dr[Tra_ReportTraineeJoinCourseEntity.FieldNames.Note] = traineeEntity.TeacherComment != null ? traineeEntity.TeacherComment : string.Empty;
                                double monthCourse = Math.Floor(dateCheck.Subtract(traineeEntity.EndDate.Value).TotalDays / 30);
                                var traineeInRequirementDetail = lstRequirementDetail.Where(s => s.CourseID == traineeEntity.ID && traineeEntity.ID == s.ProfileID && s.YearAnalyze != null && s.YearAnalyze.Value.Year == dateCheckConfig.Year).ToList();

                                if (traineeInRequirementDetail.Count >= 1)
                                {
                                    flag = true;
                                    continue;
                                }
                                if (traineeEntity.EndDate == null)
                                {
                                    flag = true;
                                    continue;
                                }

                                if (item.DurationMinCourse != null)
                                {
                                    if (monthCourse < item.DurationMinCourse)
                                    {
                                        flag = true;
                                        continue;
                                    }

                                }
                            }
                        }
                        else
                        {
                            var traineeInRequirementDetail = lstRequirementDetail.Where(s => s.CourseID == item.ID && profileEntity.ID == s.ProfileID && s.YearAnalyze != null && s.YearAnalyze.Value.Year == dateCheckConfig.Year).ToList();
                            if (traineeInRequirementDetail.Count >= 1)
                            {
                                flag = true;
                                continue;
                            }

                        }


                        if (flag == false)
                        {
                            if (salaryClassEntity != null)
                            {
                                if (workingEntity != null)
                                {
                                    // if (profileEntity.SalaryClassID != workingEntity.SalaryClassID)
                                    // {
                                    var dateCheckRank = dateCheck.Subtract(workingEntity.DateEffective).TotalDays / 30;
                                    var monthRank = Math.Floor(dateCheckRank);
                                    if (item.TimeOnCurrentRank != null)
                                    {
                                        if (item.TimeOnCurrentRank != null)
                                        {
                                            if (monthRank >= item.TimeOnCurrentRank)
                                            {
                                                flag = true;
                                                table.Rows.Add(dr);
                                            }
                                        }
                                    }
                                    else
                                    {
                                        table.Rows.Add(dr);
                                    }
                                    // }
                                }
                            }
                        }
                    }
                }
            }

            return table;
        }
        public Hre_WorkHistoryModel Post([Bind]Hre_WorkHistoryModel model)
        {
            #region Validate
            BaseService BaseService = new BaseService();
            string status = string.Empty;
            string message = string.Empty;
            var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_WorkHistoryModel>(model, "Hre_WorkHistory", ref message);
            if (!checkValidate)
            {
                model.ActionStatus = message;
                return model;
            }
            #endregion         
            var WorkHistoryServices = new Hre_WorkHistoryServices();
            var SalaryClassServices = new Cat_SalaryClassServices();
            var OrgStructureServices = new Cat_OrgStructureServices();
            var JobTitleServices = new Cat_JobTitleServices();
            var PositionServices = new Cat_PositionServices();
            var WorkHistoryOld = BaseService.GetData<Hre_WorkHistoryEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_WorkHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffective).FirstOrDefault();
            if (WorkHistoryOld != null)
            {
                model.SalaryClassNameOld = WorkHistoryOld.SalaryClassName;
                model.JobTitleOld = WorkHistoryOld.JobTitleName;
                model.PositionOld = WorkHistoryOld.PositionName;
                model.OrgStructureOldID = WorkHistoryOld.OrganizationStructureID;
                model.WorkLocationOld = WorkHistoryOld.WorkLocation;
            }

            if (model.SalaryClassID != null)
            {
                var abilityTitleBySalaryClass = BaseService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId,UserLogin, ref status).FirstOrDefault();
                if (abilityTitleBySalaryClass != null)
                {
                    model.AbilityTileID = abilityTitleBySalaryClass.ID;
                }
            }
            // Son.Vo - 20140107 - Xử lý cập nhật ngược lại bảng profile
            if (model.Status == WorkHistoryStatus.E_APPROVED.ToString() && model.DateEffective != null && model.DateEffective <= DateTime.Now.Date)
            {
                Hre_ProfileServices profileServices = new Hre_ProfileServices();
                Hre_ProfileEntity profile = BaseService.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(model.ProfileID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById,UserLogin, ref status).FirstOrDefault();
                if (profile != null) 
                {
                    profile.OrgStructureID = model.OrganizationStructureID;
                    profile.JobTitleID = model.JobTitleID;
                    profile.PositionID = model.PositionID;
                    profile.DateOfEffect = model.DateEffective;
                    profile.LaborType = model.LaborType;
                    profile.CostCentreID = model.CostCentreID;
                    profile.FormType = model.FormType;
                    profile.EmpTypeID = model.EmployeeTypeID;
                    profile.WorkingPlace = model.WorkLocation;
                    profile.AbilityTileID = model.AbilityTileID;
                    profileServices.Edit(profile);
                }
            }

            ActionService service = new ActionService(UserLogin);
            return service.UpdateOrCreate<Hre_WorkHistoryEntity, Hre_WorkHistoryModel>(model);
        }
Exemple #6
0
        public Hre_ProfileModel Post([Bind]Hre_ProfileModel model)
        {
            string status = string.Empty;
            if (model != null)
            {
                ActionService service = new ActionService(UserLogin);
                BaseService BaseService = new BaseService();

                if (!string.IsNullOrWhiteSpace(model.CodeAttendance))
                {
                    model.CodeAttendance = model.CodeAttendance.TrimAll();
                }

                #region Validate

                string message = string.Empty;

                var checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ProfileModel>(model, "Hre_Profile", ref message);
                if (!checkValidate)
                {
                    model.ActionStatus = message;
                    return model;
                }
                if (model.DateOfEffectOld != null)
                {
                    checkValidate = HRM.Business.Main.Domain.ValidatorService.OnValidateData<Hre_ProfileModel>(model, "Hre_ProfileCheckDateOfEffect", ref message);
                    if (!checkValidate)
                    {
                        model.ActionStatus = message;
                        return model;
                    }
                }
                #endregion

                #region Xử lý cập nhật AbilityTitle khi chọn rank

                if (model.SalaryClassID != null)
                {
                    var abilityTitleBySalaryClass = BaseService.GetData<Cat_AbilityTileEntity>(Common.DotNetToOracle(model.SalaryClassID.ToString()), ConstantSql.hrm_cat_sp_get_AbilityTileBySalaryClassId, UserLogin, ref status).FirstOrDefault();
                    if (abilityTitleBySalaryClass != null)
                    {
                        model.AbilityTileID = abilityTitleBySalaryClass.ID;
                    }
                }

                #endregion

                #region Xử Lý Lưu field DateOfBirth
                var dateOfBirth = string.Empty;
                if (model.DayOfBirth == 00 && model.MonthOfBirth == 00)
                {
                    model.ActionStatus = "ErrorDateOfBirth";
                    return model;
                }
                if (model.DayOfBirth == null && model.MonthOfBirth == null && model.YearOfBirth == null)
                {
                    dateOfBirth = string.Empty;

                }
                else
                {
                    if (model.DayOfBirth == null)
                    {
                        model.DayOfBirth = DateTime.Now.Day;
                    }
                    if (model.MonthOfBirth == null)
                    {
                        model.MonthOfBirth = DateTime.Now.Month;
                    }
                    if (model.YearOfBirth == null)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                }


                if (model.DayOfBirth >= 0 || model.MonthOfBirth >= 0 || model.YearOfBirth >= 0)
                {
                    if (model.DayOfBirth == 30 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                    if (model.DayOfBirth == 31 && model.MonthOfBirth == 2)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                    if (model.DayOfBirth > 31 || model.MonthOfBirth > 12)
                    {
                        model.ActionStatus = "ErrorDateOfBirth";
                        return model;
                    }
                    dateOfBirth = model.MonthOfBirth + "/" + model.DayOfBirth + "/" + model.YearOfBirth;

                }

                model.DateOfBirth = string.IsNullOrEmpty(dateOfBirth) ? (DateTime?)null : DateTime.Parse(dateOfBirth);
                #endregion
                Hre_ProfileModel HreProfile = new Hre_ProfileModel();
                if (model.ID != Guid.Empty)
                {
                    HreProfile = GetById(model.ID);
                }
                if (HreProfile != null && (model.ID == HreProfile.ID) && model.ActionStatus != "1")
                {
                    string[] listFieldName = new[] { "JobTitleID", "PositionID", "EmpTypeID", "DateOfEffect", "CostCentreID", "OrgStructureID", "WorkPlaceID", "SupervisorID" };
                    foreach (var item in listFieldName)
                    {
                        var value1 = model.GetPropertyValue(item);
                        var value2 = HreProfile.GetPropertyValue(item);
                        if ((value1 != null && value2 != null) && (value1.ToString() != value2.ToString()))
                        {
                            model.SetPropertyValue(Constant.ActionStatus, NotificationType.Change.ToString());
                            return model;
                        }
                    }
                    if (HreProfile.ProfileName != model.ProfileName)
                    {
                        if (model.ProfileName.Contains(' '))
                        {
                            model.FirstName = model.ProfileName.Substring(model.ProfileName.LastIndexOf(' ') + 1);
                            model.NameFamily = model.ProfileName.Substring(0, model.ProfileName.LastIndexOf(' '));
                        }
                        else
                        {
                            model.FirstName = model.ProfileName;
                        }
                    }
                }
                if (model.ActionStatus == "1" || model.ActionStatus == "Success" || string.IsNullOrEmpty(model.ActionStatus))
                {

                    var serviceAddress = new Hre_AddressServices();
                    var serviceProfile = new Hre_ProfileServices();
                    var profileEntity = new Hre_ProfileEntity();
                    if (model.ID != Guid.Empty)
                    {
                        profileEntity = serviceProfile.GetData<Hre_ProfileEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
                    }

                    #region Xử lý lưu CardCode
                    Hre_CardHistoryServices cardservices = new Hre_CardHistoryServices();
                    Hre_WorkHistoryServices workHistoryservices = new Hre_WorkHistoryServices();

                    if (profileEntity != null && model.CodeAttendance != null && model.DateApplyAttendanceCode != null && (model.CodeAttendance != profileEntity.CodeAttendance
                    || model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        // Chỉ thay đổi mã chấm công
                        if (model.DateApplyAttendanceCode == profileEntity.DateApplyAttendanceCode && model.CodeAttendance != profileEntity.CodeAttendance)
                        {
                            Hre_CardHistoryEntity history = cardservices.GetData<Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.CardCode = model.CodeAttendance;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history = new Hre_CardHistoryEntity();
                                history.ProfileID = model.ID;
                                history.CardCode = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                        // Chỉ thay đổi Ngày áp dụng mã chấm công

                        else if (model.CodeAttendance == profileEntity.CodeAttendance && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode)
                        {
                            if (model.DateApplyAttendanceCode < profileEntity.DateApplyAttendanceCode)
                            {
                                model.StatusVerify = "Invalid";
                                return model;
                            }
                            Hre_CardHistoryEntity history = cardservices.GetData<Hre_CardHistoryEntity>(Common.DotNetToOracle(model.ID.ToString()), ConstantSql.hrm_hr_sp_get_CardHistoryByProfileId, UserLogin, ref status).OrderByDescending(s => s.DateEffect).FirstOrDefault();
                            if (history != null)
                            {
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Edit(history);
                            }
                            else
                            {
                                history = new Hre_CardHistoryEntity();
                                history.ProfileID = model.ID;
                                history.CardCode = model.CodeAttendance;
                                history.DateEffect = model.DateApplyAttendanceCode;
                                cardservices.Add(history);
                            }
                        }
                    }
                    // Tạo mới NV hoặc thay đổi cả 2( mã chấm công + ngày hiệu lực)
                    Hre_CardHistoryEntity cardhistory = null;
                    if (model != null && model.ID == Guid.Empty || (model != null && profileEntity != null && model.CodeAttendance != profileEntity.CodeAttendance
                                && model.DateApplyAttendanceCode != profileEntity.DateApplyAttendanceCode))
                    {
                        cardhistory = new Hre_CardHistoryEntity();
                        cardhistory.ProfileID = model.ID;
                        cardhistory.CardCode = model.CodeAttendance;
                        cardhistory.DateEffect = model.DateApplyAttendanceCode;
                    }
                    #endregion

                    #region Xử lý lưu quá trình công tác
                    Hre_WorkHistoryEntity workHistory = null;
                    if (model != null && (model.JobTitleID != profileEntity.JobTitleID || model.PositionID != profileEntity.PositionID || model.EmpTypeID != profileEntity.EmpTypeID ||
                        (model.DateOfEffect != null && profileEntity.DateOfEffect != null &&
                        model.DateOfEffect.Value.ToString() != profileEntity.DateOfEffect.Value.ToString())
                        || model.CostCentreID != profileEntity.CostCentreID || model.SupervisorID != profileEntity.SupervisorID
                        || model.OrgStructureID != profileEntity.OrgStructureID || model.WorkPlaceID != profileEntity.WorkPlaceID))
                    {

                        workHistory = new Hre_WorkHistoryEntity();
                        var orgService = new Cat_OrgStructureServices();
                        var jobtitleService = new Cat_JobTitleServices();
                        var postitionService = new Cat_PositionServices();
                        var workPlaceService = new Cat_WorkPlaceServices();

                        workHistory.CostCentreID = model.CostCentreID;
                        workHistory.OrganizationStructureID = model.OrgStructureID;
                        workHistory.PositionID = model.PositionID;
                        workHistory.JobTitleID = model.JobTitleID;
                        workHistory.SalaryClassID = model.SalaryClassID;
                        workHistory.CostSourceID = model.CostSourceID;
                        workHistory.AbilityTileID = model.AbilityTileID;
                        if (profileEntity != null)
                        {
                            var orgStructureOld = new Cat_OrgStructureEntity();
                            if (profileEntity.OrgStructureID != null && profileEntity.OrgStructureID != Guid.Empty)
                            {
                                orgStructureOld = orgService.GetData<Cat_OrgStructureEntity>(profileEntity.OrgStructureID, ConstantSql.hrm_cat_sp_get_OrgStructureById, UserLogin, ref status).FirstOrDefault();
                            }
                            var jobtitleOld = new Cat_JobTitleEntity();
                            if (profileEntity.JobTitleID != null && profileEntity.JobTitleID != Guid.Empty)
                            {
                                jobtitleOld = jobtitleService.GetData<Cat_JobTitleEntity>(profileEntity.JobTitleID, ConstantSql.hrm_cat_sp_get_HDTJobTypeById, UserLogin, ref status).FirstOrDefault();
                            }
                            var postitionOld = new Cat_PositionEntity();
                            if (profileEntity.PositionID != null && profileEntity.PositionID != Guid.Empty)
                            {
                                postitionOld = postitionService.GetData<Cat_PositionEntity>(profileEntity.PositionID, ConstantSql.hrm_cat_sp_get_PositionById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlace = new Cat_WorkPlaceEntity();
                            if (model.WorkPlaceID != null && model.WorkPlaceID != Guid.Empty)
                            {
                                workPlace = workPlaceService.GetData<Cat_WorkPlaceEntity>(model.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            var workPlaceOld = new Cat_WorkPlaceEntity();
                            if (profileEntity.WorkPlaceID != null && profileEntity.WorkPlaceID != Guid.Empty)
                            {
                                workPlaceOld = workPlaceService.GetData<Cat_WorkPlaceEntity>(profileEntity.WorkPlaceID, ConstantSql.hrm_cat_sp_get_WorkPlaceById, UserLogin, ref status).FirstOrDefault();
                            }
                            workHistory.OrgOld = orgStructureOld != null ? orgStructureOld.OrgStructureName : "";
                            workHistory.JobTitleOld = jobtitleOld != null ? jobtitleOld.JobTitleName : "";
                            workHistory.PositionOld = postitionOld != null ? postitionOld.PositionName : "";
                            workHistory.WorkLocation = workPlace != null ? workPlace.WorkPlaceName : "";
                            workHistory.WorkLocationOld = workPlaceOld != null ? workPlaceOld.WorkPlaceName : "";
                        }
                        if (workHistory.ID == Guid.Empty)
                        {
                            if (model.DateOfEffect != null)
                            {
                                workHistory.DateEffective = model.DateOfEffect.Value;
                            }
                            else
                            {
                                workHistory.DateEffective = DateTime.Now;
                            }
                        }

                        if (model.DateQuit != null && (profileEntity == null || profileEntity.DateQuit != model.DateQuit))
                        {
                            workHistory.DateEffective = model.DateQuit.Value;
                        }
                    }

                    #region Ngày hiệu lực phải <= ngày hiện tại thì mới cập nhật lại quá trình công tác
                    if (model.DateOfEffect > DateTime.Now && profileEntity != null && profileEntity.DateOfEffect != null)
                    {
                        model.DateOfEffect = profileEntity.DateOfEffect;
                        model.OrgStructureID = profileEntity.OrgStructureID;
                        model.ShopID = profileEntity.ShopID;
                        model.JobTitleID = profileEntity.JobTitleID;
                        model.PositionID = profileEntity.PositionID;
                        model.SupervisorID = profileEntity.SupervisorID;
                        model.HighSupervisorID = profileEntity.HighSupervisorID;
                        model.IsHeadDept = profileEntity.IsHeadDept;
                        model.EmpTypeID = profileEntity.EmpTypeID;
                        model.LaborType = profileEntity.LaborType;
                        model.SikillLevel = profileEntity.SikillLevel;
                        model.PayrollGroupID = profileEntity.PayrollGroupID;
                        model.SalaryClassID = profileEntity.SalaryClassID;
                        model.CostCentreID = profileEntity.CostCentreID;
                        model.LocationCode = profileEntity.LocationCode;
                        model.WorkPlaceID = profileEntity.WorkPlaceID;
                    }
                    #endregion

                    #endregion

                    var profileModel = service.UpdateOrCreate<Hre_ProfileEntity, Hre_ProfileModel>(model);

                    if (cardhistory != null && profileModel != null)
                    {
                        cardhistory.ProfileID = profileModel.ID;
                        cardservices.Add(cardhistory);
                    }

                    if (workHistory != null && profileModel != null)
                    {
                        workHistory.EmployeeTypeID = profileModel.EmpTypeID;
                        workHistory.ProfileID = profileModel.ID;
                        workHistoryservices.Add(workHistory);
                    }
                }
            }

            //Xóa cache lưu lại của cây phòng ban
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeView");
            HttpContext.Current.Cache.Remove("List_OrgStructureTreeViewSumProfile");

            return model;
        }