Exemplo n.º 1
0
 public string ActionCancel(string selectedIds)
 {
     using (var context = new VnrHrmDataContext())
     {
         string message = string.Empty;
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Hre_HDTJobRepository(unitOfWork);
         List<Guid> lstIds = selectedIds.Split(',').Select(x => Guid.Parse(x)).ToList();
         var lstHDTJobs = repo.FindBy(m => m.ID != null && lstIds.Contains(m.ID)).ToList();
         foreach (var HDTJob in lstHDTJobs)
         {
             HDTJob.Status = HDTJobStatus.E_CANCEL.ToString();
         }
         repo.SaveChanges();
         message = NotificationType.Success.ToString();
         return message;
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Hàm tính ra số ngày không làm HDTJob
        /// </summary>
        /// <param name="lstProfile">Ds Nhân Viên</param>
        /// <param name="LeaveDayTypeCode">các mã ngày nghỉ không tính HDJob </param>
        /// <param name="MonthCheck">tháng kiểm tra</param>
        public static void GetHDTJobDayByProfile(List<Hre_ProfileEntity> lstProfile, string LeaveDayTypeCode, DateTime MonthCheck)
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoHre_HDTJob = new Hre_HDTJobRepository(unitOfWork);
                var repoAtt_LeaveDay = new Att_LeavedayRepository(unitOfWork);
                var repoAtt_Roster = new Att_RosterRepository(unitOfWork);


                DateTime DateStart = new DateTime(MonthCheck.Year, MonthCheck.Month, 1);
                DateTime DateEnd = DateStart.AddMonths(1).AddSeconds(-1);
                List<string> lstLeaveTypeCode = LeaveDayTypeCode.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                //=======Get DB
                string E_APPROVE = HDTJobStatus.E_APPROVE.ToString();
                string E_Four = EnumDropDown.HDTJobType.E_TYPE4.ToString();
                string E_Five = EnumDropDown.HDTJobType.E_TYPE5.ToString();
                var lstHDTJob = repoHre_HDTJob.FindBy(m => m.IsDelete == null && m.Status == E_APPROVE && m.DateFrom <= DateEnd && m.DateTo >= DateStart).Select(m => new { m.ProfileID, m.DateFrom, m.DateTo, m.Type }).ToList();

                string E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                //=======Get DB
                var lstLeaveDayHaveCode = repoAtt_LeaveDay.FindBy(m => m.IsDelete == null && m.Status == E_APPROVE && m.DateStart <= DateEnd && m.DateEnd >= DateStart && m.LeaveDayTypeID != null
                    && lstLeaveTypeCode.Contains(m.Cat_LeaveDayType.Code)).Select(m => new { m.ProfileID, m.DateStart, m.DateEnd }).ToList();

                //=======Get DB
                var lstRoster = repoAtt_Roster.FindBy(m => m.IsDelete == null && m.Status == E_APPROVED && m.DateStart <= DateEnd && m.DateEnd >= DateStart).Select(m => new { m.ProfileID, m.DateStart, m.DateEnd, m.MonShiftID, m.TueShiftID, m.WedShiftID, m.ThuShiftID, m.FriShiftID, m.SatShiftID, m.SunShiftID });
                foreach (var profile in lstProfile)
                {
                    var lstHDTJobByProfile = lstHDTJob.Where(m => m.ProfileID == profile.ID).ToList();
                    var lstLeaveDayHaveCodeByProfile = lstLeaveDayHaveCode.Where(m => m.ProfileID == profile.ID).ToList();
                    var lstRosterByProfile = lstRoster.Where(m => m.ProfileID == profile.ID).ToList();
                    int Numday_Non_HDTJob = 0;
                    int Numday_HDTJob_4 = 0;
                    int Numday_HDTJob_5 = 0;

                    bool isHaveHDTJob = lstHDTJob.Any(m => m.ProfileID == profile.ID);

                    if (isHaveHDTJob)
                    {
                        for (DateTime dateCheck = DateStart; dateCheck <= DateEnd; dateCheck = dateCheck.AddDays(1))
                        {
                            bool isHaveRoster = false;
                            switch (dateCheck.DayOfWeek)
                            {
                                case DayOfWeek.Monday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.MonShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                                case DayOfWeek.Tuesday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.TueShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                                case DayOfWeek.Wednesday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.WedShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                                case DayOfWeek.Thursday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.ThuShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                                case DayOfWeek.Friday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.FriShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                                case DayOfWeek.Saturday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.SatShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                                case DayOfWeek.Sunday:
                                    if (lstRosterByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck && m.SunShiftID != null))
                                    {
                                        isHaveRoster = true;
                                    }
                                    break;
                            }
                            if (isHaveRoster)
                            {
                                //thỏa 2 điều kiên 1: nam ngoài cung hdt job Hoặc là có ngày nghỉ trong loại kia
                                if (lstLeaveDayHaveCodeByProfile.Any(m => m.DateStart <= dateCheck && m.DateEnd >= dateCheck) || !lstHDTJobByProfile.Any(m => m.DateFrom <= dateCheck && m.DateTo >= dateCheck))
                                {
                                    Numday_Non_HDTJob++;
                                }

                                if (lstHDTJobByProfile.Any(m => m.Type == E_Four && m.DateFrom <= dateCheck && m.DateTo >= dateCheck))
                                {
                                    Numday_HDTJob_4++;
                                }
                                if (lstHDTJobByProfile.Any(m => m.Type == E_Five && m.DateFrom <= dateCheck && m.DateTo >= dateCheck))
                                {
                                    Numday_HDTJob_5++;
                                }
                            }
                        }
                        profile.NumdayNonHDTJob = Numday_Non_HDTJob;
                        profile.NumdayHDTJobTypeIV = Numday_HDTJob_4;
                        profile.NumdayHDTJobTypeV = Numday_HDTJob_5;
                    }
                    else
                    {
                        profile.NumdayNonHDTJob = int.MaxValue;
                        profile.NumdayHDTJobTypeIV = 0;
                        profile.NumdayHDTJobTypeV = 0;
                    }

                }
            }//close using
        }
Exemplo n.º 3
0
        public string ActionApprovedForHDTJobWaiting(string selectedIds, string userLG)
        {
            string message = string.Empty;
            Guid userID = Guid.Empty;
            Guid.TryParse(userLG, out userID);
            if (userID == Guid.Empty)
            {
                message = "Bạn Không Có Quyền Duyệt HDTJob";
                return message;
            }
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Hre_HDTJobRepository(unitOfWork);
                var repoSys_UserApprove = new CustomBaseRepository<Sys_UserApprove>(unitOfWork);
                List<Guid> lstIds = selectedIds.Split(',').Select(x => Guid.Parse(x)).ToList();
                var lstHDTJobs = repo.FindBy(m => m.ID != null && lstIds.Contains(m.ID)).ToList();
                int suc = 0;
                int nop = 0;
                var checkPermission = repoSys_UserApprove.FindBy(s => s.IsDelete == null
                                                    && s.Type == ApproveType.E_HDTJOB_PAST.ToString()
                                                    && s.UserApproveID == userID).ToList();
                foreach (var HDTJob in lstHDTJobs)
                {
                    if (DateTime.Now.Date <= HDTJob.DateFrom.Value.Date)
                    {
                        suc += 1;
                        HDTJob.Status = HDTJobStatus.E_APPROVE.ToString();
                        repo.Edit(HDTJob);
                    }
                    else
                    {
                        if (checkPermission.Count > 0)
                        {
                            suc += 1;
                            HDTJob.Status = HDTJobStatus.E_APPROVE.ToString();
                            repo.Edit(HDTJob);
                        }
                        else
                        {
                            nop += 1;
                        }
                    }
                }

                repo.SaveChanges();
                if (nop > 0 && suc > 0)
                {
                    message = "Duyệt Thành Công [ " + suc + " ] Dòng HDTJob Và Bạn Không Có Quyền Duyệt [ " + nop + " ] Dòng HDTJob Trong Quá Khứ";
                    return message;
                }
                else if (suc > 0)
                {
                    message = "Bạn Đã Duyệt Thành Công [ " + suc + " ] Dòng HDTJob";
                    return message;
                }
                else if (nop > 0)
                {
                    message = "Bạn Không Có Quyền Duyệt [ " + nop + " ] Dòng HDTJob Trong Quá Khứ";
                    return message;
                }
                message = NotificationType.Success.ToString();
                return message;
            }
        }
Exemplo n.º 4
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;
        }
Exemplo n.º 5
0
        public DataTable ReportHDTJobCardMore(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEnd, List<Guid> lstProfileIds,  Boolean isCludeEmpQuit)
        {
            DataTable datatable = CreateReportHDTJobCardMoreSchema();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var repo = new Can_MealRecordRepository(unitOfWork);

                var mealRecords = repo.FindBy(s => s.ProfileID != null && s.WorkDay != null && s.TimeLog != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).ToList();
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => profileIds.Contains(m.ID)).ToList();

                var repoCan_Location = new Can_LocationRepository(unitOfWork);
                var lstLocation = repoCan_Location.FindBy(s => s.IsDelete == null).ToList();

                if (lstProfileIds != null && lstProfileIds.Count >= 1)
                {
                    profiles = profiles.Where(s => lstProfileIds.Contains(s.ID)).ToList();
                }

                if (isCludeEmpQuit != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                var lstcateringids = mealRecords.Select(m => m.CateringID).ToList();
                var lstcanteenids = mealRecords.Select(m => m.CanteenID).ToList();
                var Cardcode = mealRecords.Select(s => s.ProfileID).Distinct().ToList();

                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoOrg.FindBy(m => m.Code != null).ToList();

                if (CarteringIDs != null && CarteringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CateringID != null && CarteringIDs.Contains(m.CateringID)).ToList();
                }

                if (CanteenIDS != null && CanteenIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CanteenID != null && CanteenIDS.Contains(m.CanteenID)).ToList();
                }

                if (LineIDS != null && LineIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.LineID != null && LineIDS.Contains(m.LineID)).ToList();
                }

                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }

                var repoWorkLocation = new Cat_WorkPlaceRepository(unitOfWork);
                var lstWorkPlace = repoWorkLocation.GetAll().ToList();

                var repocatering = new Can_CateringRepository(unitOfWork);
                var caterings = repocatering.GetAll().ToList();

                var repocanteen = new Can_CanteenRepository(unitOfWork);
                var canteens = repocanteen.GetAll().ToList();

                var repoline = new Can_LineRepository(unitOfWork);
                var lines = repoline.GetAll().ToList();

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

                var repoAttWorkday = new Att_WorkDayRepository(unitOfWork);
                var wordDayProfiles = repoAttWorkday.FindBy(wd => dateStart <= wd.WorkDate && wd.WorkDate <= dateEnd)
                                .Select(wd => new { wd.ProfileID, wd.ShiftID, wd.WorkDate, wd.InTime1, wd.OutTime1 }).ToList();

                var approve = LeaveDayStatus.E_APPROVED.ToString();
                var repoAttLeaveday = new Att_LeavedayRepository(unitOfWork);
                var leavedays = repoAttLeaveday.FindBy(ld => ld.Status == approve && dateStart <= ld.DateEnd
                                && ld.DateStart <= dateEnd && profileIds.Contains(ld.ProfileID)).Select(ld => new { ld.ProfileID, ld.DateStart, ld.DateEnd }).ToList();

                var repoHDTjob = new Hre_HDTJobRepository(unitOfWork);
                var hdtJobs = repoHDTjob.FindBy(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value) 
                                && dateStart <= s.DateTo && s.DateFrom <= dateEnd).Select(s => new { s.DateFrom, s.ProfileID, s.DateTo, s.Type }).ToList();

                for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                {
                    if (!datatable.Columns.Contains("Data" + date.Day))
                    {
                        datatable.Columns.Add("Data" + date.Day, typeof(double));
                    }
                }

                foreach (var profile in profiles)
                {
                    List<DateTime> leaveDayDates = new List<DateTime>();
                    var leaveDayProfiles = leavedays.Where(s => s.ProfileID == profile.ID).ToList();
                    foreach (var leaveDayProfile in leaveDayProfiles)
                    {
                        for (DateTime date = leaveDayProfile.DateStart; date <= leaveDayProfile.DateEnd; date = date.AddDays(1))
                        {
                            leaveDayDates.Add(date.Date);
                        }
                    }
                    var workDayDates = wordDayProfiles.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                    workDayDates = workDayDates.Where(s => !leaveDayDates.Contains(s.Date)).ToList();

                    var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID && workDayDates.Contains(s.WorkDay.Value.Date)).ToList();
                    if (mealRecordProfiles.Count > 0)
                    {
                        var dateend = mealRecordProfiles[mealRecordProfiles.Count - 1].WorkDay;
                        for (DateTime date = mealRecordProfiles[0].WorkDay.Value; date <= dateend; date = date.AddDays(1))
                        {
                            if (mealRecordProfiles.Count(s => s.WorkDay.Value.Date == date.Date) > 1)
                            {
                                var mealDoubles = mealRecordProfiles.Where(s => s.WorkDay.Value.Date == date.Date).ToList();
                                if (mealDoubles.Count > 1)
                                {
                                    var hdtType = hdtJobs.FirstOrDefault(s => s.DateFrom <= date && date <= s.DateTo && s.ProfileID == profile.ID);
                                    foreach (var meal in mealDoubles)
                                    {
                                        DataRow row = datatable.NewRow();

                                        var orgId = orgs.Where(og => og.ID == mealRecordProfiles[0].OrgStructureID).Select(og => og.ID).FirstOrDefault();
                                        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);

                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.ProfileName] = profile.ProfileName;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateFrom] = dateStart;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateTo] = dateEnd;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateExport] = DateTime.Now;
                                        if (meal.TimeLog != null)
                                        {
                                            row[Can_ReportHDTJobCardMoreEntity.FieldNames.DateCard] = meal.WorkDay;
                                            row[Can_ReportHDTJobCardMoreEntity.FieldNames.Hour] = meal.TimeLog.Value.ToString("HH:mm:ss");
                                        }
                                        var count1 = 0;
                                        for (DateTime date1 = dateStart; date1 <= dateEnd; date1 = date1.AddDays(1))
                                        {
                                            int countDay = mealRecordProfiles.Count(s => s.WorkDay.Value.Date == date1.Date && !leaveDayDates.Contains(date1.Date));
                                            if (countDay > 1)
                                            {
                                                count1 += countDay - 1;
                                            }
                                        }
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.Total] = count1;
                                        row["Data" + date.Day] = mealDoubles.Sum(s => s.Amount);
                                        var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID);
                                        var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID);
                                        var line = lines.FirstOrDefault(s => s.ID == meal.LineID);
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                                        row[Can_ReportHDTJobCardMoreEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                                        if (hdtType != null)
                                        {
                                            var hdttype = lines.FirstOrDefault(s => s.HDTJ == hdtType.Type);
                                            if (hdttype != null)
                                            {
                                                row[Can_ReportHDTJobCardMoreEntity.FieldNames.PriceStardand] = (object)hdttype.Amount ?? DBNull.Value;
                                            }
                                        }
                                        datatable.Rows.Add(row);
                                    }
                                }
                            }
                        }
                    }

                }
            }
            return datatable;
        }
Exemplo n.º 6
0
        public DataTable GetReportSumaryReturnMoneyEat(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, List<Guid?> workPlaceIds,
            DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs, String codeEmp, Boolean IsIncludeQuitEmp)
        {
            DataTable datatable = CreateReportSumaryReturnMoneyEatSchema();
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecords = repoCan_MealRecord.FindBy(s => s.ProfileID != null && s.WorkDay != null &&
                dateStart <= s.WorkDay && s.WorkDay <= dateEnd).Select(
                s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceTypeID, s.NoWorkDay, s.WorkDay }).ToList();

                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var workDayProfies = repoWorkDay.FindBy(s => (s.FirstInTime != null || s.LastOutTime != null) && dateStart <= s.WorkDate
                 && s.WorkDate <= dateEnd && profileIds.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(m => profileIds.Contains(m.ID)).ToList();
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                var repoHre_HDTJob = new Hre_HDTJobRepository(unitOfWork);
                var profileHDTJIDs = repoHre_HDTJob.FindBy(s => s.DateTo >= dateStart && s.DateFrom <= dateEnd).Select(s => s.ProfileID).ToList();
                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var lineHDTJIDs = repoCan_Line.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList();
                var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var amountStardand = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true && s.Amount != null).Select(s => s.Amount).FirstOrDefault();
                var repoLeaveDay = new Att_LeavedayRepository(unitOfWork);

                var leavedays = repoLeaveDay.FindBy(s => dateStart <= s.DateEnd && s.DateStart <= dateEnd && profileIds.Contains(s.ProfileID))
                    .Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();
                if (orgIDs != null && orgIDs[0] != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                if (workPlaceIds != null && workPlaceIds[0] != null)
                {
                    profiles = profiles.Where(s => workPlaceIds.Contains(s.WorkPlaceID)).ToList();
                }

                if (IsIncludeQuitEmp != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                    //profileIds = profiles.Select(s => s.ID).ToList();
                    //mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();
                }
                if (!string.IsNullOrEmpty(codeEmp))
                {
                    char[] ext = new char[] { ';', ',' };
                    List<string> codeEmpSeachs = codeEmp.Split(ext, StringSplitOptions.RemoveEmptyEntries).ToList<string>();
                    if (codeEmpSeachs.Count == 1)
                    {
                        string codeEmpSearch = codeEmpSeachs[0];
                        profiles = profiles.Where(hr => hr.CodeEmp == codeEmpSearch).ToList();
                    }
                    else
                    {
                        profiles = profiles.Where(hr => codeEmpSeachs.Contains(hr.CodeEmp)).ToList();
                    }
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                if (canteenIDs != null && canteenIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList();
                }
                if (cateringIDs != null && cateringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList();
                }
                if (lineIDs != null && lineIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList();
                }
                var codeAttendaceByProfile = profiles.Select(m => m.ID).ToList();
                if (codeAttendaceByProfile != null && codeAttendaceByProfile.Count > 0)
                {
                    mealRecords = mealRecords.Where(m => m.ProfileID != null && codeAttendaceByProfile.Contains(m.ProfileID.Value)).ToList();
                }
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => s.ProfileID != null && profileIds.Contains(s.ProfileID.Value)).ToList();

                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();

                var repoLine = new Can_LineRepository(unitOfWork);
                var lines = repoLine.FindBy(s => s.Amount != null && s.HDTJ == null && s.Amount != amountStardand).Select(s => new { s.Amount.Value, s.ID }).Distinct().ToList();

                foreach (var profile in profiles)
                {
                    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                    var mealProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList();
                    DataRow row = datatable.NewRow();
                    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);
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateFrom] = dateStart;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateTo] = dateEnd;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DatePrint] = DateTime.Now;
                    bool isAdd = false;
                    var amounts = lines.Select(s => s.Value).Distinct().ToList();
                    foreach (var amount in amounts)
                    {
                        var countCareing = 0;
                        double sumCareing = 0;
                        var line1IDs = lines.Where(s => s.Value == amount).Select(s => s.ID).ToList();
                        for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                        {
                            var leaday = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                            countCareing += mealProfiles.Count(s => line1IDs.Contains(s.LineID.Value) && s.WorkDay.Value.Date == date.Date && (workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null));
                            var sumAmount = mealProfiles.Where(s => line1IDs.Contains(s.LineID.Value) && s.WorkDay.Value.Date == date.Date && (workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null)).Sum(s => s.Amount);
                            if (sumAmount > 0)
                            {
                                sumCareing += (double)(sumAmount.Value - amountStardand.Value);
                            }

                        }
                        if (countCareing > 0)
                        {
                            isAdd = true;
                            row[amount.ToString()] = countCareing;
                            row["Số Tiền " + amount] = sumCareing;
                        }
                    }

                    var countSard = mealProfiles.Where(hr => hr.WorkDay != null).Count(hr => hr.Amount == amountStardand && workdayProfileDates.Contains(hr.WorkDay.Value.Date));
                    var countWorkDay = workDayProfies.Where(wd => wd.WorkDate != null).Count(wd => workdayProfileDates.Contains(wd.WorkDate.Date));
                    if (countSard > 0)
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountSandard] = countSard;
                    if (countWorkDay > 0)
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountWorkDay] = countWorkDay;

                    var countCardMore1 = 0;
                    double sumAmountNotStardand = 0;// tong so tien quet the ko dat chuan
                    double? sumAmountHDTJOB = 0;// tong so tien cua nhan vien ko phai HDTJOb ma an o cua an HDTJOB
                    sumAmountHDTJOB = (double?)mealProfiles.Where(s => s.ProfileID == profile.ID && s.LineID != null && lineHDTJIDs.Contains(s.LineID.Value) && !profileHDTJIDs.Contains(s.ProfileID.Value)).Sum(s => s.Amount);
                    double sumAmountNotWorkHasEat = 0;// tong so tien ko di lam ma co an
                    var countNotWorkButHasEat = 0;
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaday = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        if (mealProfiles.Count(s => s.WorkDay.Value.Date == date.Date) > 1)
                        {
                            countCardMore1++;
                        }
                        var amount = mealProfiles.FirstOrDefault(s => s.WorkDay.Value.Date == date.Date);
                        if (amount != null)
                        {
                            sumAmountNotStardand += (double)(amount.Amount.Value - amountStardand.Value);
                        }
                        var meal = mealProfiles.FirstOrDefault(s => date.Date == s.WorkDay.Value.Date && (!workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null));
                        if (meal != null)
                        {
                            countNotWorkButHasEat++;
                            sumAmountNotWorkHasEat += (double)meal.Amount.Value;
                        }
                    }

                    if (countCardMore1 > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountCardMore] = countCardMore1;
                        isAdd = true;
                    }
                    var sumCardMore = countCardMore1 * amountStardand.Value;
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountCardMore] = sumCardMore;
                    if (countNotWorkButHasEat > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountNotWorkButHasEat] = countNotWorkButHasEat;
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumNotWorkButHasEat] = sumAmountNotWorkHasEat;
                        isAdd = true;
                    }
                    var sum = Math.Round((sumAmountNotWorkHasEat + sumAmountNotStardand + (double)sumCardMore), 0);
                    row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountMustSubtract] = sum == 0 ? (object)DBNull.Value : sum;
                    sum = Math.Round(sumAmountHDTJOB.Value, 0);
                    if (sum > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.MoneyMustSubtractHDT] = sum;
                        isAdd = true;
                    }

                    sum = Math.Round((sumAmountNotWorkHasEat + sumAmountNotStardand + sumAmountHDTJOB.Value + (double)sumCardMore), 0);
                    if (sum > 0)
                    {
                        row[Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumMoneyMustSubtract] = sum;
                        isAdd = true;
                    }
                    if (isAdd)
                        datatable.Rows.Add(row);
                }
                return datatable;
            }
        }