Пример #1
0
        public void ComputeMealRecordMissing(List<Guid> lstProfileIds, DateTime dateFrom, DateTime dateToSearch, List<Guid> TamScanReasonMissID, string Status, List<Guid?> lstAllowanceTypeIDs)
        {
            List<Can_MealRecordMissingEntity> lstMealRecord = new List<Can_MealRecordMissingEntity>();
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateTo = DateTime.Now;
                if (dateToSearch != null && dateToSearch != SqlDateTime.MaxValue.Value)
                {
                     dateTo = dateToSearch.AddDays(1).AddMinutes(-1);
                }
                if(lstProfileIds == null)
                {
                    return;
                }
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                string statusAllowance = StatusMealAllowanceToMoney.E_APPROVED.ToString();
                var repoMealAllowance = new Can_MealAllowanceToMoneyRepository(unitOfWork);
                var mealAllowanceProfies = repoMealAllowance.FindBy(s => s.Status == statusAllowance && dateFrom <= s.DateTo && s.DateFrom <= dateTo)
                    .Select(s => new { s.ProfileID, s.MealAllowanceTypeID, s.DateFrom, s.DateTo }).ToList();

                var repoMissReason = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var resons = repoMissReason.FindBy(s => s.IsForCMS == true).Select(s => new { s.ID, s.IsFullPay }).ToList();

                var repoWorkday = new Att_WorkDayRepository(unitOfWork);
                var workDays = repoWorkday.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateFrom <= s.WorkDate && s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID))
               .Select(s => new { s.ProfileID, s.WorkDate, s.MissInOutReason, s.Status, s.FirstInTime, s.LastOutTime }).ToList();

                var repoMealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecordProfiles = repoMealRecord.FindBy(s => s.WorkDay != null && s.ProfileID != null
                && dateFrom <= s.WorkDay && s.WorkDay <= dateTo && lstProfileIds.Contains(s.ProfileID.Value))
                .Select(s => new { s.ProfileID, s.TimeLog, s.WorkDay }).ToList();

                var statusLeaveDay = AttendanceDataStatus.E_APPROVED.ToString();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leaveDayProfiles = repoLeaveDay.FindBy(s => s.Status == statusLeaveDay && dateFrom <= s.DateEnd && s.DateStart <= dateTo)
               .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                var tamSanResons = repoMissReason.GetAll().ToList();
                var repoMealAllowanceTypeSettings = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealSesttings = repoMealAllowanceTypeSettings.GetAll().Select(s => new { s.ID, s.Amount, s.MealAllowanceTypeSettingName }).ToList();
                if (TamScanReasonMissID != null && TamScanReasonMissID[0] != Guid.Empty)
                {
                    workDays = workDays.Where(s => s.MissInOutReason != null && TamScanReasonMissID.Contains(s.MissInOutReason.Value)).ToList();
                }
                if (Status != null)
                {
                    workDays = workDays.Where(s => s.Status != null && Status == s.Status).ToList();
                }
                var repoRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                List<Can_MealRecordMissing> mealRecordMissings = repoRecordMissing.FindBy(s => dateFrom <= s.WorkDate && s.WorkDate <= dateTo && s.ProfileID != null
                    && lstProfileIds.Contains(s.ProfileID.Value)).ToList();
                var workDayProfies = repoWorkday.FindBy(s => (s.InTime1 != null || s.OutTime1 != null) && dateFrom <= s.WorkDate
                   && s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate, s.ShiftID }).ToList();
                var profileIDs = workDayProfies.Select(s => s.ProfileID).Distinct().ToList();
                var lstmeal = new List<Can_MealRecordMissing>();
                foreach (var profileID in profileIDs)
                {
                    for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
                    {
                        var recordProfileIDs = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var leavedayProfileIDs = leaveDayProfiles.Where(s => s.DateStart != null && s.DateEnd != null && s.DateStart.Date <= date.Date
                            && date.Date <= s.DateEnd.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date.Date && s.ProfileID == profileID && !recordProfileIDs.Contains(s.ProfileID) && !leavedayProfileIDs.Contains(s.ProfileID)).ToList();
                        foreach (var workDay in workDayProfiles)
                        {
                            var meal = mealRecordMissings.FirstOrDefault(s => s.ProfileID == workDay.ProfileID && s.WorkDate.Value.Date == workDay.WorkDate.Date);
                            if (meal == null)
                            {
                                meal = new Can_MealRecordMissing();
                                meal.ID = Guid.Empty;
                                lstmeal.Add(meal);
                            }
                            meal.ProfileID = workDay.ProfileID;
                            meal.WorkDate = workDay.WorkDate;
                            if (meal.TamScanReasonMissID == Guid.Empty)
                            {
                                if (workDay.MissInOutReason != Guid.Empty)
                                {
                                    meal.TamScanReasonMissID = workDay.MissInOutReason;
                                    var tamScan = tamSanResons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                    if (tamScan != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = tamScan.MealAllowanceTypeSettingID;
                                        meal.TamScanReasonMissID = tamScan.ID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == tamScan.MealAllowanceTypeSettingID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }
                                else
                                {
                                    var allownce = mealAllowanceProfies.FirstOrDefault(s => s.ProfileID == workDay.ProfileID &&
                                        s.DateFrom <= date && date <= s.DateTo);
                                    if (allownce != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = allownce.MealAllowanceTypeID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == allownce.MealAllowanceTypeID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }

                            }
                            if (meal.MealAllowanceTypeSettingID != Guid.Empty)
                            {
                                meal.Status = MealRecord_Status.E_APPROVED.ToString();
                            }
                            else
                            {
                                meal.Status = MealRecord_Status.E_SUBMIT.ToString();
                            }
                            meal.Type = WorkdaySrcType.E_MANUAL.ToString();
                            if (workDay.FirstInTime == null && workDay.LastOutTime == null && workDay.MissInOutReason != Guid.Empty)
                            {
                                var tamSanReson = resons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                if (tamSanReson != null)
                                {
                                    meal.IsFullPay = tamSanReson.IsFullPay;
                                }
                            }
                        }
                    }
                }

                 repoRecordMissing.Add(lstmeal);
                repoMissReason.SaveChanges();
            }
        }
Пример #2
0
        public DataTable GetReportLateEarlyTotal(Att_ReportLateEarlyTotalEntity model, string userLogin)
        {
            DataTable    tblData   = getSchema();
            var          service   = new Att_ReportLateEarlyTotalServices();
            var          hrService = new Hre_ProfileServices();
            DateTime     DateFrom  = DateTime.Now;
            DateTime     DateTo    = DateTime.Now;
            List <Guid?> OrgIds    = new List <Guid?>();

            if (model.SDateFrom != null)
            {
                DateFrom = model.SDateFrom.Value;
            }
            if (model.SDateTo != null)
            {
                DateTo = model.SDateTo.Value;
            }
            var From = DateFrom;
            var To   = DateTo;

            string strOrgIDs = null;

            if (!string.IsNullOrEmpty(model.OrgStructureID))
            {
                strOrgIDs = model.OrgStructureID;
            }
            List <object> listObj = new List <object>();

            listObj.Add(strOrgIDs);
            listObj.Add(string.Empty);
            listObj.Add(string.Empty);


            string status = string.Empty;

            var result     = new DataTable();
            var lstprofile = hrService.GetData <Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).ToList();

            if (lstprofile == null || lstprofile.Count == 0)
            {
                return(null);
            }
            List <Guid> lstProfileIDs = lstprofile.Select(x => x.ID).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork            = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile           = new Hre_ProfileRepository(unitOfWork);
                var repoOrgStructure      = new Cat_OrgStructureRepository(unitOfWork);
                var repoOrgStructureType  = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoTAMScanReasonMiss = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var repoAtt_Workday       = new Att_WorkDayRepository(unitOfWork);
                //var lstprofile=repoProfile.FindBy(x=>lstProfileIDs.Contains(x.ID)).ToList();
                var  orgs                     = repoOrgStructure.FindBy(s => s.Code != null).ToList();
                var  orgTypes                 = repoOrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                Guid ForgetTams               = repoTAMScanReasonMiss.FindBy(x => x.Code.Equals("FC")).Select(x => x.ID).FirstOrDefault();
                var  lstWorkdayQuery          = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && (m.LateEarlyDuration > 0 || m.Type == WorkdayType.E_LATE_EARLY.ToString()) && !(m.Status == WorkdayStatus.E_APPROVED.ToString() && m.LateEarlyDuration == 0)).ToList();
                var  lstWorkdayFogetTamsQuery = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && m.MissInOutReason == ForgetTams).ToList();
                // var listProfile = repoProfile.FindBy(x => lstProfileIDs.Contains(x.ID)).ToList();
                if (lstProfileIDs != null && lstProfileIDs.Count != 0)
                {
                    lstWorkdayQuery          = lstWorkdayQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                    lstWorkdayFogetTamsQuery = lstWorkdayFogetTamsQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                }
                var lstWorkday          = lstWorkdayQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate, m.LateEarlyDuration }).ToList();
                var lstWorkdayFogetTams = lstWorkdayFogetTamsQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate }).ToList();
                foreach (var item in lstprofile)
                {
                    DataRow row = tblData.NewRow();
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.CodeEmp]     = item.CodeEmp;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.ProfileName] = item.ProfileName;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateFrom]    = From;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateTo]      = To;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.UserExport]  = model.UserExport;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateExport]  = DateTime.Today;
                    if (item.OrgStructureID.HasValue)
                    {
                        Cat_OrgStructure objOrgStructure = orgs.Where(x => x.ID == item.OrgStructureID).FirstOrDefault();
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.OrgStructureName] = objOrgStructure.OrgStructureName;
                        Guid?orgId      = item.OrgStructureID;
                        var  orgBrand   = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                        var  orgOrg     = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                        var  orgTeam    = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes);
                        var  orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchCode]     = orgBrand != null ? orgBrand.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamCode]       = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionCode]    = orgSection != null ? orgSection.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchName]     = orgBrand != null ? orgBrand.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamName]       = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionName]    = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    }
                    for (DateTime MonthCheck = From; MonthCheck <= To; MonthCheck = MonthCheck.AddMonths(1))
                    {
                        DateTime BeginMonth     = new DateTime(MonthCheck.Year, MonthCheck.Month, 1);
                        DateTime EndMonth       = BeginMonth.AddMonths(1).AddMinutes(-1);
                        double   Less2Hour      = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration < 2).ToList().Count;
                        double   Over2Hour      = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration >= 2).ToList().Count;
                        double   TotalLateEarly = Less2Hour + Over2Hour;
                        double   ForgetTamscan  = lstWorkdayFogetTams.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth).ToList().Count;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Less2Hour + BeginMonth.Month]      = Less2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Over2Hour + BeginMonth.Month]      = Over2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TotalLateEarly + BeginMonth.Month] = TotalLateEarly;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.ForgetTamscan + BeginMonth.Month]  = ForgetTamscan;
                    }
                    tblData.Rows.Add(row);
                }
            }
            var configs       = new Dictionary <string, Dictionary <string, object> >();
            var confighidden  = new Dictionary <string, object>();
            var configCodeEmp = new Dictionary <string, object>();

            configCodeEmp.Add("width", 90);
            var configProfileName = new Dictionary <string, object>();

            configProfileName.Add("width", 125);
            var configOrgStructureName = new Dictionary <string, object>();

            configOrgStructureName.Add("width", 80);
            var configDepartmentCode = new Dictionary <string, object>();

            configDepartmentCode.Add("width", 98);
            var configSectionCode = new Dictionary <string, object>();

            configSectionCode.Add("width", 50);
            var configBranchCode = new Dictionary <string, object>();

            configBranchCode.Add("width", 90);
            var configBranchName = new Dictionary <string, object>();

            configBranchName.Add("width", 77);
            confighidden.Add("hidden", true);
            configs.Add("CodeEmp", configCodeEmp);
            configs.Add("ProfileName", configProfileName);
            configs.Add("OrgStructureName", configOrgStructureName);
            configs.Add("DepartmentCode", configDepartmentCode);
            configs.Add("SectionCode", configSectionCode);
            configs.Add("BranchCode", configBranchCode);
            configs.Add("DepartmentName", configOrgStructureName);
            configs.Add("SectionName", configSectionCode);
            configs.Add("BranchName", configBranchName);
            configs.Add("TeamName", configSectionCode);
            configs.Add("DateFrom", confighidden);
            configs.Add("DateTo", confighidden);
            configs.Add("UserExport", confighidden);
            configs.Add("DateExport", confighidden);
            return(tblData.ConfigTable(configs));
        }
Пример #3
0
        public DataTable GetReportLateEarlyTotal(Att_ReportLateEarlyTotalEntity model, string userLogin)
        {
            DataTable tblData = getSchema();
            var service = new Att_ReportLateEarlyTotalServices();
            var hrService = new Hre_ProfileServices();
            DateTime DateFrom = DateTime.Now;
            DateTime DateTo = DateTime.Now;
            List<Guid?> OrgIds = new List<Guid?>();
            if (model.SDateFrom != null)
            {
                DateFrom = model.SDateFrom.Value;
            }
            if (model.SDateTo != null)
            {
                DateTo = model.SDateTo.Value;
            }
            var From = DateFrom;
            var To = DateTo;

            string strOrgIDs = null;
            if (!string.IsNullOrEmpty(model.OrgStructureID))
            {
                strOrgIDs = model.OrgStructureID;
            }
            List<object> listObj = new List<object>();
            listObj.Add(strOrgIDs);
            listObj.Add(string.Empty);
            listObj.Add(string.Empty);


            string status = string.Empty;
           
            var result = new DataTable();
            var lstprofile = hrService.GetData<Hre_ProfileEntity>(listObj, ConstantSql.hrm_hr_sp_get_ProfileIdsByOrgStructure, userLogin, ref status).ToList();
            if (lstprofile == null || lstprofile.Count == 0)
            {
            return null;
            }
            List<Guid> lstProfileIDs = lstprofile.Select(x => x.ID).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var repoOrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoOrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoTAMScanReasonMiss = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var repoAtt_Workday = new Att_WorkDayRepository(unitOfWork);
                //var lstprofile=repoProfile.FindBy(x=>lstProfileIDs.Contains(x.ID)).ToList();
                var orgs = repoOrgStructure.FindBy(s => s.Code != null).ToList();
                var orgTypes = repoOrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                Guid ForgetTams = repoTAMScanReasonMiss.FindBy(x => x.Code.Equals("FC")).Select(x => x.ID).FirstOrDefault();
                var lstWorkdayQuery = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && (m.LateEarlyDuration > 0 || m.Type == WorkdayType.E_LATE_EARLY.ToString()) && !(m.Status == WorkdayStatus.E_APPROVED.ToString() && m.LateEarlyDuration == 0)).ToList();
                var lstWorkdayFogetTamsQuery = repoAtt_Workday.FindBy(m => m.WorkDate >= From && m.WorkDate <= To && m.MissInOutReason == ForgetTams).ToList();
                // var listProfile = repoProfile.FindBy(x => lstProfileIDs.Contains(x.ID)).ToList();
                if (lstProfileIDs != null && lstProfileIDs.Count != 0)
                {
                    lstWorkdayQuery = lstWorkdayQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                    lstWorkdayFogetTamsQuery = lstWorkdayFogetTamsQuery.Where(x => lstProfileIDs.Contains(x.ProfileID)).ToList();
                }
                var lstWorkday = lstWorkdayQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate, m.LateEarlyDuration }).ToList();
                var lstWorkdayFogetTams = lstWorkdayFogetTamsQuery.Select(m => new { m.ID, m.ProfileID, m.WorkDate }).ToList();
                foreach (var item in lstprofile)
                {
                    DataRow row = tblData.NewRow();
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.CodeEmp] = item.CodeEmp;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.ProfileName] = item.ProfileName;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateFrom] = From;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateTo] = To;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.UserExport] = model.UserExport;
                    row[Att_ReportLateEarlyTotalEntity.FieldNames.DateExport] = DateTime.Today;
                    if (item.OrgStructureID.HasValue)
                    {
                        Cat_OrgStructure objOrgStructure = orgs.Where(x => x.ID == item.OrgStructureID).FirstOrDefault();
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.OrgStructureName] = objOrgStructure.OrgStructureName;
                        Guid? orgId = item.OrgStructureID;
                        var orgBrand = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                        var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                        var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes);
                        var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.DepartmentCode] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchCode] = orgBrand != null ? orgBrand.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamCode] = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionCode] = orgSection != null ? orgSection.Code : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.BranchName] = orgBrand != null ? orgBrand.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    }
                    for (DateTime MonthCheck = From; MonthCheck <= To; MonthCheck = MonthCheck.AddMonths(1))
                    {
                        DateTime BeginMonth = new DateTime(MonthCheck.Year, MonthCheck.Month, 1);
                        DateTime EndMonth = BeginMonth.AddMonths(1).AddMinutes(-1);
                        double Less2Hour = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration < 2).ToList().Count;
                        double Over2Hour = lstWorkday.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth && m.LateEarlyDuration >= 2).ToList().Count;
                        double TotalLateEarly = Less2Hour + Over2Hour;
                        double ForgetTamscan = lstWorkdayFogetTams.Where(m => m.ProfileID == item.ID && m.WorkDate >= BeginMonth && m.WorkDate <= EndMonth).ToList().Count;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Less2Hour + BeginMonth.Month] = Less2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.Over2Hour + BeginMonth.Month] = Over2Hour;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.TotalLateEarly + BeginMonth.Month] = TotalLateEarly;
                        row[Att_ReportLateEarlyTotalEntity.FieldNames.ForgetTamscan + BeginMonth.Month] = ForgetTamscan;
                    }
                    tblData.Rows.Add(row);
                }

            }
            var configs = new Dictionary<string, Dictionary<string, object>>();
            var confighidden = new Dictionary<string, object>();
            var configCodeEmp = new Dictionary<string, object>();
            configCodeEmp.Add("width", 90);
            var configProfileName = new Dictionary<string, object>();
            configProfileName.Add("width", 125);
            var configOrgStructureName = new Dictionary<string, object>();
            configOrgStructureName.Add("width", 80);
            var configDepartmentCode = new Dictionary<string, object>();
            configDepartmentCode.Add("width", 98);
            var configSectionCode = new Dictionary<string, object>();
            configSectionCode.Add("width", 50);
            var configBranchCode = new Dictionary<string, object>();
            configBranchCode.Add("width", 90);
            var configBranchName = new Dictionary<string, object>();
            configBranchName.Add("width", 77);
            confighidden.Add("hidden", true);
            configs.Add("CodeEmp", configCodeEmp);
            configs.Add("ProfileName", configProfileName);
            configs.Add("OrgStructureName", configOrgStructureName);
            configs.Add("DepartmentCode", configDepartmentCode);
            configs.Add("SectionCode", configSectionCode);
            configs.Add("BranchCode", configBranchCode);
            configs.Add("DepartmentName", configOrgStructureName);
            configs.Add("SectionName", configSectionCode);
            configs.Add("BranchName", configBranchName);
            configs.Add("TeamName", configSectionCode);
            configs.Add("DateFrom", confighidden);
            configs.Add("DateTo", confighidden);
            configs.Add("UserExport", confighidden);
            configs.Add("DateExport", confighidden);
            return tblData.ConfigTable(configs);
        }
Пример #4
0
        /// <summary>
        /// Lấy Dữ Liệu BC Thống Kê Đi Muộn Về Sớm
        /// </summary>
        /// <returns></returns>
        public List<Att_ReportSummaryLateInOutEntity> GetReportSummaryLateInOut(DateTime dateStart, DateTime dateEnd, List<Hre_ProfileEntity> profiles, Guid[] shiftIDs, bool isIncludeQuitEmp, string codeEmp, string userExport)
        {
            using (var context = new VnrHrmDataContext())
            {
                List<Guid> lstProfileIDs = profiles.Select(s => s.ID).ToList();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var repoAtt_WorkDay = new Att_WorkDayRepository(unitOfWork);
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoShift = new Cat_ShiftRepository(unitOfWork);
                var repoCat_TAMReasonmiss = new Cat_TAMScanReasonMissRepository(unitOfWork);

                string E_LATE_EARLY = WorkdayType.E_LATE_EARLY.ToString();
                string E_APPROVED = WorkdayStatus.E_APPROVED.ToString();
                var workDays = new List<Att_Workday>().Select(s => new { s.ProfileID, s.WorkDate, s.LateEarlyDuration, s.ShiftID, s.InTime1, s.OutTime1, s.MissInOutReason, s.LateDuration1, s.EarlyDuration1 }).ToList();

                workDays = repoAtt_WorkDay.FindBy(s => s.IsDelete == null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd && s.Type == E_LATE_EARLY && !(s.Status == E_APPROVED && s.LateEarlyDuration == 0))
                    .Select(s => new { s.ProfileID, s.WorkDate, s.LateEarlyDuration, s.ShiftID, s.InTime1, s.OutTime1, s.MissInOutReason, s.LateDuration1, s.EarlyDuration1 }).ToList();

                var profileIds = workDays.Select(s => s.ProfileID).Distinct().ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList();
                #region MyRegion
                var repoCat_Position = new Cat_PositionRepository(unitOfWork);
                var positions = repoCat_Position.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.PositionName }).ToList();
                var repoCat_JobTitle = new Cat_JobTitleRepository(unitOfWork);
                var jobtitles = repoCat_JobTitle.FindBy(s => s.Code != null).Select(s => new { s.ID, s.Code, s.JobTitleName }).ToList();
                #endregion
                var reasons = repoCat_TAMReasonmiss.FindBy(s => s.IsDelete == null);
                var shifts = repoShift.FindBy(s => s.IsDelete == null);
                if (shiftIDs != null)
                {
                    workDays = workDays.Where(s => s.ShiftID.HasValue && shiftIDs.Contains(s.ShiftID.Value)).ToList();
                    profileIds = workDays.Select(s => s.ProfileID).ToList();
                    profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                }

                if (!isIncludeQuitEmp)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateStart).ToList();
                }
                if (!string.IsNullOrEmpty(codeEmp))
                {
                    profiles = profiles.Where(s => s.CodeEmp == codeEmp).ToList();
                }

                var key = LeaveDayStatus.E_APPROVED.ToString();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var leaveDays = repoLeaveDay.FindBy(s => s.Status == key && dateStart <= s.DateEnd && s.DateStart <= dateEnd);
                List<Guid> guids = profiles.Select(s => s.ID).ToList();
                workDays = workDays.Where(s => guids.Contains(s.ProfileID)).ToList();
                profiles = profiles.Where(s => guids.Contains(s.ID)).ToList();
                List<Att_ReportSummaryLateInOutEntity> lstReportSummaryLateInOutEntity = new List<Att_ReportSummaryLateInOutEntity>();
                Att_ReportSummaryLateInOutEntity reportSummaryLateInOutEntityEntity = null;
                foreach (var profile in profiles)
                {
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var workDayProfiles = workDays.Where(s => s.ProfileID == profile.ID && s.WorkDate.Date == date).ToList();
                        var leveDay = leaveDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        if (workDayProfiles.Count > 0 && leveDay == null)
                        {
                            var workDay = workDayProfiles.FirstOrDefault(s => s.WorkDate.Date == date);
                            if (workDay != null)
                            {
                                reportSummaryLateInOutEntityEntity = new Att_ReportSummaryLateInOutEntity();
                                Guid? orgId = profile.OrgStructureID;
                                var reason = reasons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                                var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                                var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes);
                                var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);

                                reportSummaryLateInOutEntityEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;

                                reportSummaryLateInOutEntityEntity.BranchName = orgBranch != null ? orgOrg.OrgStructureName : string.Empty;
                                reportSummaryLateInOutEntityEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                reportSummaryLateInOutEntityEntity.TeamName = orgTeam != null ? orgOrg.OrgStructureName : string.Empty;
                                reportSummaryLateInOutEntityEntity.SectionName = orgSection != null ? orgOrg.OrgStructureName : string.Empty;

                                #region MyRegion
                                var positon = positions.FirstOrDefault(s => s.ID == profile.PositionID);
                                var jobtitle = jobtitles.FirstOrDefault(s => s.ID == profile.JobTitleID);
                                #endregion
                                var shift = shifts.FirstOrDefault(s => s.ID == workDay.ShiftID);
                                reportSummaryLateInOutEntityEntity.ProfileName = profile.ProfileName;
                                reportSummaryLateInOutEntityEntity.CodeEmp = profile.CodeEmp;
                                #region MyRegion
                                reportSummaryLateInOutEntityEntity.PositionCode = positon != null ? positon.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.JobtitleCode = jobtitle != null ? jobtitle.Code : string.Empty;
                                reportSummaryLateInOutEntityEntity.PositionName = positon != null ? positon.PositionName : string.Empty;
                                reportSummaryLateInOutEntityEntity.JobtitleName = jobtitle != null ? jobtitle.JobTitleName : string.Empty;
                                #endregion
                                reportSummaryLateInOutEntityEntity.DateFrom = dateStart;
                                reportSummaryLateInOutEntityEntity.Date = date;
                                reportSummaryLateInOutEntityEntity.DateTo = dateEnd;
                                reportSummaryLateInOutEntityEntity.DateExport = DateTime.Now;
                                reportSummaryLateInOutEntityEntity.UserExport = userExport;
                                reportSummaryLateInOutEntityEntity.udTAMScanReasonMiss = reason == null ? string.Empty : reason.TAMScanReasonMissName;
                                reportSummaryLateInOutEntityEntity.ShiftName = shift == null ? string.Empty : shift.ShiftName;
                                reportSummaryLateInOutEntityEntity.udInTime = workDay.InTime1 != null ? workDay.InTime1.Value : DateTime.MinValue;
                                reportSummaryLateInOutEntityEntity.udOutTime = workDay.OutTime1 != null ? workDay.OutTime1.Value : DateTime.MinValue;
                                if (workDay.LateEarlyDuration >= 120)
                                {
                                    reportSummaryLateInOutEntityEntity.EarlyDurationMore2 = "X";
                                }
                                else
                                {
                                    reportSummaryLateInOutEntityEntity.EarlyDurationLess2 = "X";
                                }

                                if (workDay.LateDuration1 != null && workDay.LateDuration1 > 0)
                                {
                                    reportSummaryLateInOutEntityEntity.LateForWork = "X";
                                }
                                if (workDay.EarlyDuration1 != null && workDay.EarlyDuration1 > 0)
                                {
                                    reportSummaryLateInOutEntityEntity.EarlyGoHome = "X";
                                }

                                lstReportSummaryLateInOutEntity.Add(reportSummaryLateInOutEntityEntity);
                            }
                        }
                    }
                    #region MyRegion
                    //Guid? orgId = profile.OrgStructureID;
                    //var attendanceProfiles = attendanceTables.Where(s => s.ProfileID == profile.ID).ToList();
                    //var attendaceProfileIDs = attendanceProfiles.Select(s => s.ID).ToList();
                    //var attendanceItemProfiles = attendanceItems.Where(s => attendaceProfileIDs.Contains(s.AttendanceTableID)).ToList();                    
                    //var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID);
                    //var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_BRANCH, orgs, orgTypes);
                    //var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                    //var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_TEAM, orgs, orgTypes);
                    //var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                    //reportSummaryLateInOutEntityEntity.LateMinutes = attendanceItemProfiles.Sum(s => s.LateInMinutes);
                    //reportSummaryLateInOutEntityEntity.EarlyMinutes = attendanceItemProfiles.Sum(s => s.EarlyOutMinutes);
                    //reportSummaryLateInOutEntityEntity.NumTimeLate = attendanceItemProfiles.Count(s => s.LateInMinutes > 0);
                    //reportSummaryLateInOutEntityEntity.NumTimeEarly = attendanceItemProfiles.Count(s => s.EarlyOutMinutes > 0);
                    //lstReportSummaryLateInOutEntity.Add(reportSummaryLateInOutEntityEntity);
                    #endregion
                }
                return lstReportSummaryLateInOutEntity;
            }
        }
Пример #5
0
        public bool SaveSumryMealRecord(Guid CutOffDurationID, List<Guid> lstProfileIDs)
        {
            using (var context = new VnrHrmDataContext())
            {
                try
                {
                    #region GetData
                    List<Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List<Can_ReportAdjustmentMealAllowancePaymentEntity>();
            
                    var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                    var repoMealRecord = new Can_MealRecordRepository(unitOfWork);
                    var cutoffdurationRepository = new Att_CutOffDurationRepository(unitOfWork);
                    var Cutoffduration = cutoffdurationRepository.FindBy(m => m.ID == CutOffDurationID && m.IsDelete != true).FirstOrDefault();
                    DateTime DateFrom = new DateTime();
                    DateTime DateTo = new DateTime();
                    if (Cutoffduration != null)
                    {
                        DateFrom = Cutoffduration.DateStart;
                        DateTo = Cutoffduration.DateEnd.AddDays(1).AddMilliseconds(-1);
                    }
                    var sumryMealRecordRepository = new Can_SumryMealRecordRepository(unitOfWork);
                    var lstMealRecord = repoMealRecord.FindBy(m => m.WorkDay != null && m.WorkDay >= DateFrom && m.WorkDay <= DateTo && m.ProfileID != null)
                        .Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay }).ToList();

                    if (lstMealRecord.Count < 0)
                    {
                        return true;
                    }

                    var status = StatusMealAllowanceToMoney.E_APPROVED.ToString();
                    #region Dư ko dùng
                    //var repoAllowanceToMoney = new Can_MealAllowanceToMoneyRepository(unitOfWork);
                    //var mealAllowncaToMoneyProfileIDs = repoAllowanceToMoney.FindBy(s => s.Status == status && s.ProfileID != null && DateFrom <= s.DateTo && s.DateFrom <= DateTo).ToList();
                    #endregion

                    var lstProfileIdsByMeal = lstMealRecord.Select(s => s.ProfileID).Distinct().ToList();
                    var repoprofiles = new Hre_ProfileRepository(unitOfWork);
                    var profiles = repoprofiles.FindBy(s => lstProfileIdsByMeal.Contains(s.ID)).Select(s => new { s.ID, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
                    if (lstProfileIDs != null && lstProfileIDs.Count > 0)
                    {
                        profiles = profiles.Where(m => lstProfileIDs.Contains(m.ID)).ToList();
                    }

                    var repomealAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                    var mealAllowanceTypeSantandIDs = repomealAllowanceType.FindBy(s => s.Standard == true).Select(m => m.ID).ToList();
                    var mealAllowanceTypes = repomealAllowanceType.FindBy(s => s.IsDelete == null).ToList();
                    var amountStardand = repomealAllowanceType.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount.Value).FirstOrDefault();

                    var repoLineHDTJob = new Can_LineRepository(unitOfWork);
                    var lineHDTJobIDs = repoLineHDTJob.FindBy(s => s.HDTJ != null).Select(m => m.ID).ToList();

                    var repoHDTJob = new Hre_HDTJobRepository(unitOfWork);
                    var profileHDTJs = repoHDTJob.FindBy(s => DateFrom <= s.DateTo && s.DateFrom <= DateTo)
                        .Select(s => new { s.ProfileID, s.Type, s.DateFrom, s.DateTo }).ToList(); 
                    var profileHDTJIDs = profileHDTJs.Select(s => s.ProfileID).Distinct().ToList();

                    string approveKey = MealRecord_Status.E_APPROVED.ToString();
                    var repo_MealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                    var mealRecordMissings = repo_MealRecordMissing.FindBy(s => s.Status == approveKey && DateFrom <= s.WorkDate && s.WorkDate <= DateTo)
                        .Select(s => new { s.ProfileID, s.WorkDate, s.MealAllowanceTypeSettingID, s.TamScanReasonMissID, s.Amount }).ToList();

                    var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                    var dateStart1 = DateFrom.AddDays(-1);
                    var workDays = repoWorkDay.FindBy(s => dateStart1 <= s.WorkDate && s.WorkDate <= DateTo).Select(s => new { s.ProfileID, s.FirstInTime, s.LastOutTime, s.ShiftID, s.WorkDate }).ToList();
                    var workDayProfies = workDays.Where(s => s.FirstInTime != null || s.LastOutTime != null).ToList();

                    var repotamScan = new Cat_TAMScanReasonMissRepository(unitOfWork);
                    var tamSans = repotamScan.GetAll().ToList();
                    var tamScanNotFullPayIDs = tamSans.Where(s => s.IsFullPay == null || s.IsFullPay == false).Select(s => s.ID).ToList();

                    var reposhift = new Cat_ShiftRepository(unitOfWork);
                    var shifts = reposhift.GetAll().ToList();

                    var lines = new List<Can_Line>().ToList();
                    var repolines = new Can_LineRepository(unitOfWork);
                    lines = repolines.GetAll().ToList();

                    var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                    var orgs = repoOrg.GetAll().ToList();

                    var orgTypes = new List<Cat_OrgStructureType>();
                    var repoorgType = new Cat_OrgStructureTypeRepository(unitOfWork);
                    orgTypes = repoorgType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                    #endregion

                    foreach (var profile in profiles)
                    {
                      
                        var mealProfiles = lstMealRecord.Where(s => s.ProfileID == profile.ID).ToList();
                        #region Dư ko dùng
                        //var mealAllownProfiles = mealAllowncaToMoneyProfileIDs.Where(s => s.ProfileID == profile.ID).ToList();
                        //var mealNotStardands = lstMealRecord.Where(s => s.ProfileID == profile.ID && s.Amount > amountStardand).ToList();
                        #endregion
                        Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity();
                        Guid? orgId = profile.OrgStructureID;
                        var org = orgs.FirstOrDefault(s => s.ID == profile.OrgStructureID);
                        var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);
                        var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                        var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                        var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes);
                        ReportAdjustmentMealAllowancePayment.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                        ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp;
                        ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName;
                        ReportAdjustmentMealAllowancePayment.DateFrom = DateFrom;
                        ReportAdjustmentMealAllowancePayment.DateTo = DateTo;
                        ReportAdjustmentMealAllowancePayment.DatePrint = DateTime.Now;
                        var countCard = 0;
                        var sumCard = 0.0;
                        int countCardMore1 = 0;
                        var countNotWorkButHasEat = 0;
                        var sumNotWorkButHasEat = 0.0;
                        var countmealNotStardand = 0;
                        var amountmealNotStardand = 0.0;
                        var countHDTJ = 0;
                        var amountHDTJ = 0.0;
                        var countNotStandHDTJ = 0;
                        var amountNotStandHDTJ = 0.0;
                        int amount3OnMonth = 0;
                        var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                        for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1))
                        {
                            var workDay = workDays.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Date == date.Date);
                            var shift = shifts.FirstOrDefault(s => workDay != null && s.ID == workDay.ShiftID);
                            var missing = mealRecordMissings.FirstOrDefault(s => s.ProfileID == profile.ID && s.WorkDate.Value.Date == date.Date);
                            if (missing != null)
                            {
                                if (missing.MealAllowanceTypeSettingID != null && missing.TamScanReasonMissID == null)
                                {
                                    countCard++;
                                    sumCard += (double)(missing.Amount != null ? missing.Amount.Value : 0);
                                }
                                else if (missing.TamScanReasonMissID != null)
                                {
                                    var tamscan = tamSans.FirstOrDefault(s => s.ID == missing.TamScanReasonMissID);
                                    if (tamscan != null)
                                    {
                                        if (tamscan.IsFullPay == true)
                                        {
                                            countCard++;
                                            sumCard += (double)amountStardand;
                                        }
                                        else
                                        {
                                            amount3OnMonth++;
                                        }
                                    }
                                }
                            }
                            if (mealProfiles.Count(s => s.TimeLog != null && s.TimeLog.Value.Date == date.Date) > 1)
                            {
                                countCardMore1++;
                            }
                            var record = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)
                                && s.ProfileID == profile.ID && date.Date == s.TimeLog.Value.Date && !workdayProfileDates.Contains(date.Date));
                            if (record != null)
                            {
                                countNotWorkButHasEat++;
                                sumNotWorkButHasEat += (double)(record.Amount != null ? record.Amount.Value : 0);
                            }
                            var meal = lstMealRecord.FirstOrDefault(s => s.TimeLog != null && s.Amount > amountStardand && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)
                                && s.ProfileID == profile.ID && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(date.Date));
                            if (meal != null)
                            {
                                countmealNotStardand++;
                                amountmealNotStardand += (double)(meal.Amount != null ? meal.Amount.Value : 0);
                            }
                            var mealHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && s.TimeLog != null && 
                                s.TimeLog.Value.Date == date.Date && (!profileHDTJIDs.Contains(s.ProfileID.Value) || (profileHDTJIDs.Contains(s.ProfileID.Value) && !workdayProfileDates.Contains(date.Date))));
                            if (mealHDT != null)
                            {
                                countHDTJ++;
                                amountHDTJ += (double)(mealHDT.Amount != null ? mealHDT.Amount.Value : 0);
                            }
                            var mealNotStandandHDT = lstMealRecord.FirstOrDefault(s => s.ProfileID != null && s.ProfileID == profile.ID && s.LineID != null && lineHDTJobIDs.Contains(s.LineID.Value) && 
                                s.TimeLog != null && s.TimeLog.Value.Date == date.Date && profileHDTJIDs.Contains(s.ProfileID.Value) && workdayProfileDates.Contains(date.Date));
                            if (mealNotStandandHDT != null && mealNotStandandHDT.LineID != null)
                            {
                                var line = lines.FirstOrDefault(s => s.ID == mealNotStandandHDT.LineID);
                                var hdtjob = profileHDTJs.FirstOrDefault(s => s.Type != null && s.ProfileID == profile.ID && s.DateFrom.Value.Date <= date.Date && date.Date <= s.DateTo.Value.Date);
                                if (line != null && line.HDTJ != null && hdtjob.Type != line.HDTJ)
                                {
                                    var lineHDT = lines.FirstOrDefault(s => s.HDTJ == hdtjob.Type);
                                    if (lineHDT != null && lineHDT.Amount != null && lineHDT.Amount < line.Amount)
                                    {
                                        countNotStandHDTJ++;
                                        var lineAmount = line.Amount != null ? line.Amount.Value : 0;
                                        var lineAmountHDT = lineHDT.Amount != null ? lineHDT.Amount.Value : 0;
                                        amountNotStandHDTJ += (double)(lineAmount - lineAmountHDT);
                                    }
                                }
                            }
                            double countMiss = mealRecordMissings.Count(s => s.ProfileID == profile.ID && s.TamScanReasonMissID != null && tamScanNotFullPayIDs.Contains(s.TamScanReasonMissID.Value));
                            countMiss = GetCountAmount((int)countMiss);
                            if (countCard > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.TotalMealAllowance = countCard + countMiss;
                            }
                            if (sumCard > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.SumAmount = (double)(sumCard + countMiss * (double)amountStardand);
                            }
                            if (countmealNotStardand > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountEatNotStandar = countmealNotStardand;
                                ReportAdjustmentMealAllowancePayment.AmountEatNotStandar = amountmealNotStardand - (double)(amountStardand * countmealNotStardand);
                            }
                            if (countCardMore1 > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountCardMore = countCardMore1;
                                ReportAdjustmentMealAllowancePayment.SumCardMore = (double)Math.Round(countCardMore1 * amountStardand, 2);
                            }
                            if (countNotWorkButHasEat > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat = countNotWorkButHasEat;
                                ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat = sumNotWorkButHasEat;
                            }
                            amount3OnMonth = amount3OnMonth - (int)GetCountAmount(amount3OnMonth);
                            if (amount3OnMonth > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.Amount3OnMonth = amount3OnMonth;
                            }
                            if (countHDTJ > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountHDTJob = countHDTJ;
                                ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob = amountHDTJ;
                            }
                            if (countNotStandHDTJ > 0)
                            {
                                ReportAdjustmentMealAllowancePayment.CountCardWorngStandar = countNotStandHDTJ;
                                ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandar = amountNotStandHDTJ;
                            }
                        }
                        Can_SumryMealRecord sumryMealRecordNew = new Can_SumryMealRecord();
                        sumryMealRecordNew.ProfileID = profile.ID;
                        sumryMealRecordNew.DateFrom = Cutoffduration.DateStart;
                        sumryMealRecordNew.DateTo = Cutoffduration.DateEnd;
                        sumryMealRecordNew.TotalMealAllowance = ReportAdjustmentMealAllowancePayment.TotalMealAllowance;
                        sumryMealRecordNew.SumAmount = ReportAdjustmentMealAllowancePayment.SumAmount;
                        sumryMealRecordNew.CountEatNotStandar = ReportAdjustmentMealAllowancePayment.CountEatNotStandar;
                        sumryMealRecordNew.AmountEatNotStandar = ReportAdjustmentMealAllowancePayment.AmountEatNotStandar;
                        sumryMealRecordNew.CountCardMore = ReportAdjustmentMealAllowancePayment.CountCardMore;
                        sumryMealRecordNew.SumAmountCardMore = ReportAdjustmentMealAllowancePayment.SumCardMore;
                        sumryMealRecordNew.CountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.CountNotWorkHasEat;
                        sumryMealRecordNew.AmountNotWorkHasEat = ReportAdjustmentMealAllowancePayment.AmountNotWorkHasEat;
                        sumryMealRecordNew.Amount3OnMonth = ReportAdjustmentMealAllowancePayment.Amount3OnMonth;
                        sumryMealRecordNew.CountHDTJob = ReportAdjustmentMealAllowancePayment.CountHDTJob;
                        sumryMealRecordNew.AmountHDTJob = ReportAdjustmentMealAllowancePayment.AmounSubtractHDTJob;
                        sumryMealRecordNew.AmountNotWorkButHasHDT = ReportAdjustmentMealAllowancePayment.AmountNotWorkButHasHDT;
                        sumryMealRecordNew.CountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.CountSubtractWorngStandarHDT;
                        sumryMealRecordNew.AmountSubtractWorngStandarHDT = ReportAdjustmentMealAllowancePayment.AmountSubtractWorngStandarHDT;
                        sumryMealRecordRepository.Add(sumryMealRecordNew);
                        lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment);

                        if (profiles.IndexOf(profile) % 1000 == 0)
                        {
                            sumryMealRecordRepository.SaveChanges();
                        }
                    }
                    sumryMealRecordRepository.SaveChanges();
                }
                catch (Exception)
                {
                    return false;
                }
            }
            return true;
        }
Пример #6
0
        public void ComputeMealRecordMissing(List <Guid> lstProfileIds, DateTime dateFrom, DateTime dateToSearch, List <Guid> TamScanReasonMissID, string Status, List <Guid?> lstAllowanceTypeIDs)
        {
            List <Can_MealRecordMissingEntity> lstMealRecord = new List <Can_MealRecordMissingEntity>();

            using (var context = new VnrHrmDataContext())
            {
                DateTime dateTo = DateTime.Now;
                if (dateToSearch != null && dateToSearch != SqlDateTime.MaxValue.Value)
                {
                    dateTo = dateToSearch.AddDays(1).AddMinutes(-1);
                }
                if (lstProfileIds == null)
                {
                    return;
                }
                var    unitOfWork           = (IUnitOfWork)(new UnitOfWork(context));
                var    repoProfile          = new Hre_ProfileRepository(unitOfWork);
                string statusAllowance      = StatusMealAllowanceToMoney.E_APPROVED.ToString();
                var    repoMealAllowance    = new Can_MealAllowanceToMoneyRepository(unitOfWork);
                var    mealAllowanceProfies = repoMealAllowance.FindBy(s => s.Status == statusAllowance && dateFrom <= s.DateTo && s.DateFrom <= dateTo)
                                              .Select(s => new { s.ProfileID, s.MealAllowanceTypeID, s.DateFrom, s.DateTo }).ToList();

                var repoMissReason = new Cat_TAMScanReasonMissRepository(unitOfWork);
                var resons         = repoMissReason.FindBy(s => s.IsForCMS == true).Select(s => new { s.ID, s.IsFullPay }).ToList();

                var repoWorkday = new Att_WorkDayRepository(unitOfWork);
                var workDays    = repoWorkday.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateFrom <= s.WorkDate && s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID))
                                  .Select(s => new { s.ProfileID, s.WorkDate, s.MissInOutReason, s.Status, s.FirstInTime, s.LastOutTime }).ToList();

                var repoMealRecord     = new Can_MealRecordRepository(unitOfWork);
                var mealRecordProfiles = repoMealRecord.FindBy(s => s.WorkDay != null && s.ProfileID != null &&
                                                               dateFrom <= s.WorkDay && s.WorkDay <= dateTo && lstProfileIds.Contains(s.ProfileID.Value))
                                         .Select(s => new { s.ProfileID, s.TimeLog, s.WorkDay }).ToList();

                var statusLeaveDay   = AttendanceDataStatus.E_APPROVED.ToString();
                var repoLeaveDay     = new Att_LeavedayRepository(unitOfWork);
                var leaveDayProfiles = repoLeaveDay.FindBy(s => s.Status == statusLeaveDay && dateFrom <= s.DateEnd && s.DateStart <= dateTo)
                                       .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                var tamSanResons = repoMissReason.GetAll().ToList();
                var repoMealAllowanceTypeSettings = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealSesttings = repoMealAllowanceTypeSettings.GetAll().Select(s => new { s.ID, s.Amount, s.MealAllowanceTypeSettingName }).ToList();
                if (TamScanReasonMissID != null && TamScanReasonMissID[0] != Guid.Empty)
                {
                    workDays = workDays.Where(s => s.MissInOutReason != null && TamScanReasonMissID.Contains(s.MissInOutReason.Value)).ToList();
                }
                if (Status != null)
                {
                    workDays = workDays.Where(s => s.Status != null && Status == s.Status).ToList();
                }
                var repoRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                List <Can_MealRecordMissing> mealRecordMissings = repoRecordMissing.FindBy(s => dateFrom <= s.WorkDate && s.WorkDate <= dateTo && s.ProfileID != null &&
                                                                                           lstProfileIds.Contains(s.ProfileID.Value)).ToList();
                var workDayProfies = repoWorkday.FindBy(s => (s.InTime1 != null || s.OutTime1 != null) && dateFrom <= s.WorkDate &&
                                                        s.WorkDate <= dateTo && lstProfileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate, s.ShiftID }).ToList();
                var profileIDs = workDayProfies.Select(s => s.ProfileID).Distinct().ToList();
                var lstmeal    = new List <Can_MealRecordMissing>();
                foreach (var profileID in profileIDs)
                {
                    for (DateTime date = dateFrom; date <= dateTo; date = date.AddDays(1))
                    {
                        var recordProfileIDs   = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var leavedayProfileIDs = leaveDayProfiles.Where(s => s.DateStart != null && s.DateEnd != null && s.DateStart.Date <= date.Date &&
                                                                        date.Date <= s.DateEnd.Date && s.ProfileID == profileID).Select(s => s.ProfileID).ToList();
                        var workDayProfiles = workDays.Where(s => s.WorkDate.Date == date.Date && s.ProfileID == profileID && !recordProfileIDs.Contains(s.ProfileID) && !leavedayProfileIDs.Contains(s.ProfileID)).ToList();
                        foreach (var workDay in workDayProfiles)
                        {
                            var meal = mealRecordMissings.FirstOrDefault(s => s.ProfileID == workDay.ProfileID && s.WorkDate.Value.Date == workDay.WorkDate.Date);
                            if (meal == null)
                            {
                                meal    = new Can_MealRecordMissing();
                                meal.ID = Guid.Empty;
                                lstmeal.Add(meal);
                            }
                            meal.ProfileID = workDay.ProfileID;
                            meal.WorkDate  = workDay.WorkDate;
                            if (meal.TamScanReasonMissID == Guid.Empty)
                            {
                                if (workDay.MissInOutReason != Guid.Empty)
                                {
                                    meal.TamScanReasonMissID = workDay.MissInOutReason;
                                    var tamScan = tamSanResons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                    if (tamScan != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = tamScan.MealAllowanceTypeSettingID;
                                        meal.TamScanReasonMissID        = tamScan.ID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == tamScan.MealAllowanceTypeSettingID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }
                                else
                                {
                                    var allownce = mealAllowanceProfies.FirstOrDefault(s => s.ProfileID == workDay.ProfileID &&
                                                                                       s.DateFrom <= date && date <= s.DateTo);
                                    if (allownce != null)
                                    {
                                        meal.MealAllowanceTypeSettingID = allownce.MealAllowanceTypeID;
                                        var messting = mealSesttings.FirstOrDefault(s => s.ID == allownce.MealAllowanceTypeID);
                                        if (messting != null)
                                        {
                                            meal.Amount = messting.Amount;
                                        }
                                    }
                                }
                            }
                            if (meal.MealAllowanceTypeSettingID != Guid.Empty)
                            {
                                meal.Status = MealRecord_Status.E_APPROVED.ToString();
                            }
                            else
                            {
                                meal.Status = MealRecord_Status.E_SUBMIT.ToString();
                            }
                            meal.Type = WorkdaySrcType.E_MANUAL.ToString();
                            if (workDay.FirstInTime == null && workDay.LastOutTime == null && workDay.MissInOutReason != Guid.Empty)
                            {
                                var tamSanReson = resons.FirstOrDefault(s => s.ID == workDay.MissInOutReason);
                                if (tamSanReson != null)
                                {
                                    meal.IsFullPay = tamSanReson.IsFullPay;
                                }
                            }
                        }
                    }
                }

                repoRecordMissing.Add(lstmeal);
                repoMissReason.SaveChanges();
            }
        }