Ejemplo n.º 1
0
        /// <summary>
        /// [Son.Vo] - 20140724 - BC Thanh Toán Trợ Cấp Ăn Ca Cho Nhân Viên
        /// </summary>
        /// <param name="CarteringIDs"></param>
        /// <param name="CanteenIDS"></param>
        /// <param name="LineIDS"></param>
        /// <param name="DateFrom"></param>
        /// <param name="DateTo"></param>
        /// <returns></returns>
        public List <Can_ReportAdjustmentMealAllowancePaymentEntity> ReportAdjustmentMealAllowancePayment(DateTime DateFrom, DateTime DateTo, List <int> lstProfileIDs)
        {
            #region GetData
            var lstMealRecord = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType, s.NoWorkDay }).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_MealRecordRepository(unitOfWork);
                lstMealRecord = repo.FindBy(m => m.TimeLog >= DateFrom || m.TimeLog <= DateTo && m.CardCode != null).Select(
                    s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType, s.NoWorkDay }).ToList();
            }
            var cardcode = lstMealRecord.Select(s => s.CardCode).Distinct().ToList();
            var profiles = new List <Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Hre_ProfileRepository(unitOfWork);
                profiles = repo.FindBy(s => cardcode.Contains(s.CodeEmp)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
            }

            var mealAllowanceTypeSantandIDs = new List <Can_MealAllowanceTypeSetting>().Select(m => m.Id).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                mealAllowanceTypeSantandIDs = repo.FindBy(s => s.Standard == true).Select(m => m.Id).ToList();
            }

            var lineHDTJobIDs = new List <Can_Line>().Select(m => m.Id).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_LineRepository(unitOfWork);
                lineHDTJobIDs = repo.FindBy(s => s.LineHDTJOB != null).Select(m => m.Id).ToList();
            }

            var lines = new List <Can_Line>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_LineRepository(unitOfWork);
                lines = repo.GetAll().ToList();
            }

            var lstOrgAll = new List <Cat_OrgStructure>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Cat_OrgStructureRepository(unitOfWork);
                lstOrgAll = repo.GetAll().ToList();
            }
            #endregion
            List <Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List <Can_ReportAdjustmentMealAllowancePaymentEntity>();
            foreach (var profile in profiles)
            {
                Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity();
                var orgbyprofile = lstOrgAll.Where(m => m.Id == profile.OrgStructureID).Select(m => m.OrgStructureName).FirstOrDefault();
                ReportAdjustmentMealAllowancePayment.CodeEmp        = profile.CodeEmp;
                ReportAdjustmentMealAllowancePayment.ProfileName    = profile.ProfileName;
                ReportAdjustmentMealAllowancePayment.OrgStructureId = orgbyprofile;
                var mealProfiles = lstMealRecord.Where(s => s.CardCode == profile.CodeEmp).ToList();
                if (mealProfiles.Count > 0)
                {
                    var line = lines.FirstOrDefault(s => s.Id == mealProfiles[0].LineID);
                    if (line != null)
                    {
                        ReportAdjustmentMealAllowancePayment.TotalAdditionalAmount = mealProfiles.Count * line.Amount;
                    }
                    ReportAdjustmentMealAllowancePayment.TotalMealTime = mealProfiles.Where(m => m.MealAllowanceType != null &&
                                                                                            mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Count();
                    ReportAdjustmentMealAllowancePayment.TotalDeductionAmount = mealProfiles.Where(m => m.MealAllowanceType != null &&
                                                                                                   mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Sum(m => m.Amount.Value);
                    var    countCardMore1          = 0;
                    double?AmountSubtractCardMore1 = 0;
                    for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1))
                    {
                        if (mealProfiles.Count(s => s.TimeLog == date) > 1)
                        {
                            countCardMore1++;
                            var meal = mealProfiles.FirstOrDefault(s => s.TimeLog == date);
                            if (meal != null)
                            {
                                AmountSubtractCardMore1 += meal.Amount;
                            }
                        }
                    }
                    ReportAdjustmentMealAllowancePayment.TotalScanManyTime          = countCardMore1;
                    ReportAdjustmentMealAllowancePayment.TotalDeductionScanManyTime = AmountSubtractCardMore1.Value;
                    ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatTime     = mealProfiles.Count(s => s.NoWorkDay == true);
                    ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount   = mealProfiles.Sum(s => s.Amount.Value);
                    ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount   = mealProfiles.Sum(s => s.Amount.Value);
                }
                lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment);
            }
            return(lstReportAdjustmentMealAllowancePayment);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// [Tam.Le] - 20140726 - Lấy dữ liệu BC Trường Hợp Quẹt Thẻ Ở Hàng Ăn Không Tiêu Chuẩn
        /// </summary>
        /// <param name="CarteringIDs"></param>
        /// <param name="CanteenIDS"></param>
        /// <param name="LineIDS"></param>
        /// <param name="DateFrom"></param>
        /// <param name="DateTo"></param>
        /// <returns></returns>
        public List <Can_ReportCardNotStandEntity> ReportCardNotStand(List <int?> cateringIDs, List <int?> canteenIDs, List <int?> lineIDs, DateTime dateStart, DateTime dateEnd, List <int?> orgIDs)
        {
            DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEnd);

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork         = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecords        = repoCan_MealRecord.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd)
                                         .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType }).ToList();
                //var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var codeAttendances = mealRecords.Select(s => s.CardCode).Distinct().ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles        = repoHre_Profile.FindBy(s => codeAttendances.Contains(s.CodeAttendance))
                                      .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList();
                var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealAllowanceTypeSantandIDs      = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true)
                                                       .Select(s => s.Id).ToList();
                var repoCan_Line  = new Can_LineRepository(unitOfWork);
                var lineHDTJobIDs = repoCan_Line.FindBy(s => s.LineHDTJOB != null)
                                    .Select(s => s.Id).ToList();
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                if (orgIDs != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                //if (!isIncludeQuitEmp)
                //{
                //    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 (canteenIDs != null)
                {
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList();
                }
                if (cateringIDs != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList();
                }
                if (lineIDs != null)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList();
                }
                //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                //{
                //    if (!table.Columns.Contains("Date" + date.Day))
                //        table.Columns.Add("Date" + date.Day, typeof(DateTime));
                //}
                mealRecords = mealRecords.Where(s => s.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(s.MealAllowanceType) &&
                                                s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList();
                profiles = profiles.Where(s => codeAttendances.Contains(s.CodeAttendance)).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>();
                Can_ReportCardNotStandEntity        reportCardNotStandEntity    = null;
                List <Can_ReportCardNotStandEntity> lstreportCardNotStandEntity = new List <Can_ReportCardNotStandEntity>();
                foreach (var profile in profiles)
                {
                    reportCardNotStandEntity = new Can_ReportCardNotStandEntity();
                    int?orgId      = profile.OrgStructureID;
                    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);
                    reportCardNotStandEntity.BranchCode     = orgBranch != null ? orgBranch.Code : string.Empty;
                    reportCardNotStandEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                    reportCardNotStandEntity.TeamCode       = orgTeam != null ? orgTeam.Code : string.Empty;
                    reportCardNotStandEntity.SectionCode    = orgSection != null ? orgSection.Code : string.Empty;
                    reportCardNotStandEntity.BranchName     = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.TeamName       = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.SectionName    = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.CodeEmp        = profile.CodeEmp;
                    reportCardNotStandEntity.ProfileName    = profile.ProfileName;
                    //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    //{
                    //    var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date);
                    //    if (meal != null)
                    //    {
                    //        //row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value;
                    //    }
                    //}
                    reportCardNotStandEntity.CountCard = mealRecords.Count(s => s.CardCode == profile.CodeAttendance);
                    reportCardNotStandEntity.SumAmount = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).Sum(s => s.Amount);
                    lstreportCardNotStandEntity.Add(reportCardNotStandEntity);
                }
                return(lstreportCardNotStandEntity);
            }
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// [Son.Vo] - 20140724 - BC Thanh Toán Trợ Cấp Ăn Ca Cho Nhân Viên
        /// </summary>
        /// <param name="CarteringIDs"></param>
        /// <param name="CanteenIDS"></param>
        /// <param name="LineIDS"></param>
        /// <param name="DateFrom"></param>
        /// <param name="DateTo"></param>
        /// <returns></returns>
        public List<Can_ReportAdjustmentMealAllowancePaymentEntity> ReportAdjustmentMealAllowancePayment(DateTime DateFrom, DateTime DateTo, List<int> lstProfileIDs)
        {
            #region GetData
            var lstMealRecord = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType,  s.NoWorkDay }).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_MealRecordRepository(unitOfWork);
                lstMealRecord = repo.FindBy(m => m.TimeLog >= DateFrom || m.TimeLog <= DateTo && m.CardCode != null).Select(
               s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount, s.MealAllowanceType,  s.NoWorkDay }).ToList();
            }
            var cardcode = lstMealRecord.Select(s => s.CardCode).Distinct().ToList();
            var profiles = new List<Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Hre_ProfileRepository(unitOfWork);
                profiles = repo.FindBy(s => cardcode.Contains(s.CodeAttendance)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeAttendance, s.CodeEmp, s.PositionID, s.JobTitleID }).ToList();
            }

            var mealAllowanceTypeSantandIDs = new List<Can_MealAllowanceTypeSetting>().Select(m=> m.Id).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                mealAllowanceTypeSantandIDs = repo.FindBy(s => s.Standard == true).Select(m=> m.Id).ToList();
            }

            var lineHDTJobIDs = new List<Can_Line>().Select(m => m.Id).ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_LineRepository(unitOfWork);
                lineHDTJobIDs = repo.FindBy(s => s.LineHDTJOB != null).Select(m => m.Id).ToList();
            }

            var lines = new List<Can_Line>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_LineRepository(unitOfWork);
                lines = repo.GetAll().ToList();
            }

            var lstOrgAll = new List<Cat_OrgStructure>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Cat_OrgStructureRepository(unitOfWork);
                lstOrgAll = repo.GetAll().ToList();
            }
            #endregion
            List<Can_ReportAdjustmentMealAllowancePaymentEntity> lstReportAdjustmentMealAllowancePayment = new List<Can_ReportAdjustmentMealAllowancePaymentEntity>();
            foreach (var profile in profiles)
            {
                Can_ReportAdjustmentMealAllowancePaymentEntity ReportAdjustmentMealAllowancePayment = new Can_ReportAdjustmentMealAllowancePaymentEntity();
                var orgbyprofile = lstOrgAll.Where(m => m.Id == profile.OrgStructureID).Select(m => m.OrgStructureName).FirstOrDefault();
                ReportAdjustmentMealAllowancePayment.CodeEmp = profile.CodeEmp;
                ReportAdjustmentMealAllowancePayment.ProfileName = profile.ProfileName;
                ReportAdjustmentMealAllowancePayment.OrgStructureName = orgbyprofile;
                var mealProfiles = lstMealRecord.Where(s => s.CardCode == profile.CodeAttendance).ToList();
                if (mealProfiles.Count > 0)
                {
                    var line = lines.FirstOrDefault(s => s.Id == mealProfiles[0].LineID);
                    if (line != null)
                    {
                        ReportAdjustmentMealAllowancePayment.TotalAdditionalAmount = mealProfiles.Count * line.Amount;
                    }
                    ReportAdjustmentMealAllowancePayment.TotalMealTime = mealProfiles.Where(m => m.MealAllowanceType != null
                        && mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Count();
                    ReportAdjustmentMealAllowancePayment.TotalDeductionAmount = mealProfiles.Where(m => m.MealAllowanceType != null
                      && mealAllowanceTypeSantandIDs.Contains(m.MealAllowanceType)).Sum(m => m.Amount.Value);
                    var countCardMore1 = 0;
                    double? AmountSubtractCardMore1 = 0;
                    for (DateTime date = DateFrom; date <= DateTo; date = date.AddDays(1))
                    {
                        if (mealProfiles.Count(s => s.TimeLog == date) > 1)
                        {
                            countCardMore1++;
                            var meal = mealProfiles.FirstOrDefault(s => s.TimeLog == date);
                            if (meal != null)
                            {
                                AmountSubtractCardMore1 += meal.Amount;
                            }

                        }
                    }
                    ReportAdjustmentMealAllowancePayment.TotalScanManyTime = countCardMore1;
                    ReportAdjustmentMealAllowancePayment.TotalDeductionScanManyTime = AmountSubtractCardMore1.Value;
                    ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatTime = mealProfiles.Count(s => s.NoWorkDay == true);
                    ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount = mealProfiles.Sum(s => s.Amount.Value);
                    ReportAdjustmentMealAllowancePayment.TotalNotWorkButEatAmount = mealProfiles.Sum(s => s.Amount.Value);
                }
                lstReportAdjustmentMealAllowancePayment.Add(ReportAdjustmentMealAllowancePayment);
            }
            return lstReportAdjustmentMealAllowancePayment;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// [Tam.Le] - 20140726 - Lấy dữ liệu BC Trường Hợp Quẹt Thẻ Ở Hàng Ăn Không Tiêu Chuẩn
        /// </summary>
        /// <param name="CarteringIDs"></param>
        /// <param name="CanteenIDS"></param>
        /// <param name="LineIDS"></param>
        /// <param name="DateFrom"></param>
        /// <param name="DateTo"></param>
        /// <returns></returns>
        public List<Can_ReportCardNotStandEntity> ReportCardNotStand(List<int?> cateringIDs, List<int?> canteenIDs, List<int?> lineIDs, DateTime dateStart, DateTime dateEnd, List<int?> orgIDs)
        {
            DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEnd);
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));               
                var repoCan_MealRecord = new Can_MealRecordRepository(unitOfWork);
                var mealRecords = repoCan_MealRecord.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd)
                 .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.Amount,s.MealAllowanceType }).ToList();
                //var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var codeAttendances = mealRecords.Select(s => s.CardCode).Distinct().ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(s => codeAttendances.Contains(s.CodeAttendance))
                 .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp,s.CodeAttendance }).ToList();
                var repoCan_MealAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealAllowanceTypeSantandIDs = repoCan_MealAllowanceTypeSetting.FindBy(s => s.Standard == true)
                  .Select(s => s.Id).ToList();
                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var lineHDTJobIDs = repoCan_Line.FindBy(s => s.LineHDTJOB != null)
                  .Select(s => s.Id).ToList();
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();                
                if (orgIDs != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                //if (!isIncludeQuitEmp)
                //{
                //    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 (canteenIDs != null)
                {
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && canteenIDs.Contains(s.CanteenID.Value)).ToList();
                }
                if (cateringIDs != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && cateringIDs.Contains(s.CateringID.Value)).ToList();
                }
                if (lineIDs != null)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && lineIDs.Contains(s.LineID.Value)).ToList();
                }                
                //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                //{
                //    if (!table.Columns.Contains("Date" + date.Day))
                //        table.Columns.Add("Date" + date.Day, typeof(DateTime));
                //}
                mealRecords = mealRecords.Where(s => s.MealAllowanceType != null && mealAllowanceTypeSantandIDs.Contains(s.MealAllowanceType)
                            && s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList();
                profiles = profiles.Where(s => codeAttendances.Contains(s.CodeAttendance)).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>();
                Can_ReportCardNotStandEntity reportCardNotStandEntity = null;
                List<Can_ReportCardNotStandEntity> lstreportCardNotStandEntity = new List<Can_ReportCardNotStandEntity>();
                foreach (var profile in profiles)
                {
                    reportCardNotStandEntity = new Can_ReportCardNotStandEntity();
                    int? orgId = profile.OrgStructureID;
                    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);
                    reportCardNotStandEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
                    reportCardNotStandEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
                    reportCardNotStandEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
                    reportCardNotStandEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                    reportCardNotStandEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    reportCardNotStandEntity.CodeEmp = profile.CodeEmp;
                    reportCardNotStandEntity.ProfileName = profile.ProfileName;
                    //for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    //{
                    //    var meal = mealRecords.FirstOrDefault(s => s.CardCode == profile.CodeAttendance && s.TimeLog == date);
                    //    if (meal != null)
                    //    {
                    //        //row["Date" + date.Day] = (object)meal.TimeLog ?? DBNull.Value;
                    //    }
                    //}
                    reportCardNotStandEntity.CountCard = mealRecords.Count(s => s.CardCode == profile.CodeAttendance);
                    reportCardNotStandEntity.SumAmount = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).Sum(s => s.Amount);
                    lstreportCardNotStandEntity.Add(reportCardNotStandEntity);
                }
                return lstreportCardNotStandEntity;
            }
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
        public DataTable ReportCardNotStand(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            DataTable datatable = CreateReportCardNotStandSchema(dateStart, dateEndSearch);
            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.WorkDay }).ToList();
                if (mealRecords.Count < 1)
                {
                    return datatable;
                }
                var Profileids = mealRecords.Select(s => s.ProfileID).ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(s => Profileids.Contains(s.ID)).ToList();

                var profileIdsByMealrecords = mealRecords.Where(m => m.ProfileID != null).Select(s => s.ProfileID.Value).ToList();
                var amountByMealrecords = mealRecords.Select(m => m.Amount).Distinct().ToList();

                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var workDayProfies = repoWorkDay.FindBy(s => s.ProfileID != null && s.WorkDate != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd &&
                    profileIdsByMealrecords.Contains(s.ProfileID)).ToList();

                var repoAllowanceType = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var mealAllowanceTypeStandard = repoAllowanceType.FindBy(s => s.Standard == true).FirstOrDefault();
                var amountStandar = mealAllowanceTypeStandard != null ? mealAllowanceTypeStandard.Amount : null;

                var repoline = new Can_LineRepository(unitOfWork);
                var lineHDTJobIDs = repoline.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList();
                var linIdNotAmoutStardands = repoline.FindBy(s => s.Amount != amountStandar).Select(s => s.ID).ToList();

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

                if (orgIDs != null && orgIDs[0] != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.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();
                }
                if (linIdNotAmoutStardands.Count > 0)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && linIdNotAmoutStardands.Contains(s.LineID.Value)).ToList();
                }
                if (lineHDTJobIDs.Count > 0)
                {
                    mealRecords = mealRecords.Where(s => s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)).ToList();
                }
                if (mealRecords.Count < 1)
                {
                    return datatable;
                }
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                var canteens = repocanteen.GetAll().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                var caterings = repocatering.GetAll().ToList();
                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 approve = LeaveDayStatus.E_APPROVED.ToString();
                var repoleavedays = new Att_LeavedayRepository(unitOfWork);
                var leavedays = repoleavedays.FindBy(s => s.Status == approve && dateStart <= s.DateEnd
                     && s.DateStart <= dateEnd && profileIdsByMealrecords.Contains(s.ProfileID)).Select(s => new { s.ProfileID, s.DateStart, s.DateEnd }).ToList();

                foreach (var profile in profiles)
                {
                    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID).Select(s => s.WorkDate.Date).ToList();
                    var dateLeveDays = new List<DateTime>();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        if (leaveDay != null)
                        {
                            dateLeveDays.Add(date.Date);
                        }
                    }
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaveDay = leavedays.FirstOrDefault(s => s.ProfileID == profile.ID && s.DateStart <= date && date <= s.DateEnd);
                        var meal = mealRecords.FirstOrDefault(s => s.ProfileID == profile.ID && s.TimeLog != null && s.WorkDay != null
                            && s.TimeLog.Value.Date == date.Date && workdayProfileDates.Contains(s.WorkDay.Value.Date) && leaveDay == null);
                        if (meal != null)
                        {
                            DataRow row = datatable.NewRow();
                            Guid? orgId = profile != null ? profile.OrgStructureID : null;
                            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_ReportCardNotStandEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            row[Can_ReportCardNotStandEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Can_ReportCardNotStandEntity.FieldNames.ProfileName] = profile.ProfileName;
                            row[Can_ReportCardNotStandEntity.FieldNames.DateFrom] = dateStart;
                            row[Can_ReportCardNotStandEntity.FieldNames.DateTo] = dateEnd;
                            row[Can_ReportCardNotStandEntity.FieldNames.DatePrint] = DateTime.Now;
                            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);
                            if (meal.WorkDay != null)
                            {
                                row["Data" + date.Day] = meal.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                            }
                            row[Can_ReportCardNotStandEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                            row[Can_ReportCardNotStandEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                            row[Can_ReportCardNotStandEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                            var countcard = mealRecords.Count(s => s.WorkDay != null && s.ProfileID == profile.ID && workdayProfileDates.Contains(s.WorkDay.Value.Date)
                                && !dateLeveDays.Contains(s.WorkDay.Value.Date));
                            if (countcard != null)
                            {
                                row[Can_ReportCardNotStandEntity.FieldNames.CountCard] = countcard;
                                var SumAmount = mealRecords.Where(s => s.WorkDay != null && s.ProfileID == profile.ID && workdayProfileDates.Contains(s.WorkDay.Value.Date) &&
                                    !dateLeveDays.Contains(s.WorkDay.Value.Date)).Sum(s => s.Amount) - countcard * amountStandar;
                                row[Can_ReportCardNotStandEntity.FieldNames.SumAmount] = SumAmount;
                            }
                            datatable.Rows.Add(row);
                        }
                    }
                }
                return datatable;
            }
        }
Ejemplo n.º 8
0
        public DataTable ReportMealAllowanceOfEmployee(List<Guid?> lstMealAllowanceTypeSettingID, DateTime dateStart, DateTime dateEnd, 
            List<Guid> lstProfileIds, List<Guid?> workPlaceIds, Boolean isCludeEmpQuit)
        {
            DataTable datatable = CreateReportMealAllowanceOfEmployeeSchema();
            using (var context = new VnrHrmDataContext())
            {
                //DateTime dateEnd = dateEnd.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

                string typeApprove = MealRecordMissingStatus.E_APPROVED.ToString(); 
                string typeWaitApprove = MealRecordMissingStatus.E_WAIT_APPROVED.ToString();

                var repoMealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);

                var lstMealRecordMiss = repoMealRecordMissing.FindBy(m => lstProfileIds.Contains(m.ProfileID.Value) &&
                                            (m.Status == typeApprove || m.Status == typeWaitApprove) &&
                                             m.WorkDate >= dateStart && m.WorkDate <= dateEnd).OrderBy(m => m.ProfileID).ThenBy(m => m.WorkDate).ToList();

                var profileIDs = lstMealRecordMiss.Select(hre => hre.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => profileIDs.Contains(m.ID)).ToList();

                //tất cả phòng ban và loại trợ cấp
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var lstOrgAll = repoCat_OrgStructure.FindBy(og => og.IsDelete == null).ToList();

                var repoTypeMealAllSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var lstTypeMealAllSetting = repoTypeMealAllSetting.GetAll().ToList();

                //ds Att_Workday và ca làm việc
                var repoAttWorkday = new Att_WorkDayRepository(unitOfWork);
                var workDays = repoAttWorkday.FindBy(wd => dateStart <= wd.WorkDate && wd.WorkDate <= dateEnd && profileIDs.Contains(wd.ProfileID))
                                .Select(wd => new { wd.ProfileID, wd.ShiftID, wd.WorkDate, wd.InTime1, wd.OutTime1, wd.ShiftActual, wd.ShiftApprove }).ToList();

                var repoShift = new Cat_ShiftRepository(unitOfWork);
                var lstShiftAll = repoShift.GetAll().ToList();

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

                if (workPlaceIds != null && workPlaceIds[0] != null)
                {
                    profiles = profiles.Where(s => workPlaceIds.Contains(s.WorkPlaceID)).ToList();
                }

                if (isCludeEmpQuit != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).ToList();
                }
                lstProfileIds = profiles.Select(s => s.ID).ToList();

                //ds ko quẹt thẻ theo loại trợ cấp
                if (lstMealAllowanceTypeSettingID[0] != Guid.Empty)
                {
                    lstMealRecordMiss = lstMealRecordMiss.Where(m => m.MealAllowanceTypeSettingID != null && lstMealAllowanceTypeSettingID.Contains(m.MealAllowanceTypeSettingID.Value)).ToList();
                }

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

                foreach (var recordmiss in lstMealRecordMiss)
                {
                    if (recordmiss == null)
                        continue;
                    var profile = profiles.FirstOrDefault(s => s.ID == recordmiss.ProfileID);
                    if (profile == null) continue;
                    DataRow row = datatable.NewRow();

                    var orgId = lstOrgAll.Where(s => s.ID == recordmiss.OrgStructureID).Select(og => og.ID).FirstOrDefault();

                    var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, lstOrgAll, orgTypes);
                    var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, lstOrgAll, orgTypes);
                    var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, lstOrgAll, orgTypes);
                    var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, lstOrgAll, orgTypes);

                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;

                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateExport] = DateTime.Now;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateFrom] = dateStart;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.DateTo] = dateEnd;

                    var mealAllowance = lstTypeMealAllSetting.FirstOrDefault(m => m.ID == recordmiss.MealAllowanceTypeSettingID);
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.MealAllowance] = mealAllowance != null ? mealAllowance.MealAllowanceTypeSettingName : string.Empty;

                    var attworkday = workDays.FirstOrDefault(at => at.ProfileID == profile.ID && at.WorkDate == recordmiss.WorkDate);
                    if (attworkday != null)
                    {
                        var shiftActual = lstShiftAll.FirstOrDefault(sf => sf.ID == attworkday.ShiftActual);
                        row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ShiftActual] = shiftActual != null ? shiftActual.ShiftName : string.Empty;

                        var shiftApprove = lstShiftAll.FirstOrDefault(sf => sf.ID == attworkday.ShiftApprove);
                        row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.ShiftApprove] = shiftApprove != null ? shiftApprove.ShiftName : string.Empty;
                    }
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.Date] = recordmiss.WorkDate;
                    row[Can_ReportMealAllowanceOfEmployeeEntity.FieldNames.Status] = recordmiss.Status;

                    datatable.Rows.Add(row);
                }

            }
            return datatable;
        }
Ejemplo n.º 9
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;
            }
        }
Ejemplo n.º 10
0
        DataTable CreateReportSumaryReturnMoneyEatSchema()
        {
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

                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 repoCan_Line = new Can_LineRepository(unitOfWork);
                var amounts = repoCan_Line.FindBy(s => s.HDTJ == null && s.Amount != amountStardand).OrderBy(s => s.Amount).Select(s => s.Amount).Distinct().ToList();
                DataTable tb = new DataTable();
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CodeEmp);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.ProfileName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CateringName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CanteenName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.LineName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.BranchName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DepartmentName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.TeamName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SectionName);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountCardMore, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountCardMore, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountNotWorkButHasEat, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumNotWorkButHasEat, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumAmountMustSubtract, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.MoneyMustSubtractHDT, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.SumMoneyMustSubtract, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountWorkDay, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.CountSandard, typeof(double));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateFrom, typeof(DateTime));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DateTo, typeof(DateTime));
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.UserPrint);
                tb.Columns.Add(Can_ReportSumaryReturnMoneyEatEntity.FieldNames.DatePrint, typeof(DateTime));

                foreach (var amount in amounts)
                {
                    if (!tb.Columns.Contains(amount.ToString()))
                    {
                        tb.Columns.Add(amount.ToString());
                        tb.Columns.Add("Số Tiền " + amount, typeof(double));
                    }
                }
                return tb;
            }
        }
Ejemplo n.º 11
0
        public DataTable ReportMealTimeDetailNoEat(List<Guid?> lstWorkPlace, String status, String codeEmp, Boolean isCludeEmpQuit,
            DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            List<Can_ReportMealTimeDetailNoEatEntity> lstreportMealTimeDetailNoEatEntity = new List<Can_ReportMealTimeDetailNoEatEntity>();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);

                var repomealRecordMissing = new Can_MealRecordMissingRepository(unitOfWork);
                var mealRecordMissings = repomealRecordMissing.FindBy(s => s.ProfileID != null && s.WorkDate != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd
                                         && s.MealAllowanceTypeSettingID == null)
                                         .Select(s => new { s.ProfileID, s.WorkDate, s.Status, s.MealAllowanceTypeSettingID, s.OrgStructureID }).ToList();
                DataTable table = GetSchemaRptMealTimeDetailNoEat();
                if (mealRecordMissings == null && mealRecordMissings.Count < 1)
                {
                    return table;
                }
                var profileIds = mealRecordMissings.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(s => profileIds.Contains(s.ID)).ToList();

                if (orgIDs != null && orgIDs[0] != null)
                {
                    profiles = profiles.Where(hr => hr.OrgStructureID != null && orgIDs.Contains(hr.OrgStructureID)).ToList();
                }
                if (lstWorkPlace[0] != Guid.Empty)
                {
                    profiles = profiles.Where(wp => wp.WorkPlaceID != null && lstWorkPlace.Contains(wp.WorkPlaceID.Value)).ToList();
                }
                if (isCludeEmpQuit != true)
                {
                    profiles = profiles.Where(s => s.DateQuit == null || s.DateQuit > dateEnd).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();
                mealRecordMissings = mealRecordMissings.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                //trạng thái
                if (status != null)
                {
                    mealRecordMissings = mealRecordMissings.Where(meal => status.Contains(meal.Status)).ToList();
                }

                //workday
                var repAttWorkday = new Att_WorkDayRepository(unitOfWork);
                var lstWorkday = repAttWorkday.FindBy(wd => wd.WorkDate >= dateStart && wd.WorkDate <= dateEnd && profileIds.Contains(wd.ProfileID))
                                 .Select(wd => new {wd.ProfileID, wd.InTime1, wd.OutTime1, wd.WorkDate }).ToList();

                //danh mục leaveday type
                var repLeaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leadayHLDID = repLeaveDayType.FindBy(ld => ld.Code == "HLD").Select(ld => ld.ID).FirstOrDefault();

                //att_leaveday
                var repAttLeaveDay = new Att_LeavedayRepository(unitOfWork);
                var E_APPROVED = LeaveDayStatus.E_APPROVED.ToString();
                var lstLeaveday = repAttLeaveDay.FindBy(ld => ld.LeaveDayTypeID != leadayHLDID && (profileIds.Contains(ld.ProfileID))
                                && ld.Status == E_APPROVED && dateStart <= ld.DateEnd && ld.DateStart <= dateEnd)
                                .Select(ld => new { ld.ProfileID, ld.DateStart, ld.DateEnd }).ToList();

                //can_line
                var repHDTjob = new Can_LineRepository(unitOfWork);
                var lstHDTjobID = repHDTjob.FindBy(hdt => hdt.IsHDTJOB == true).Select(hdt => hdt.ID).ToList();
                
                //Can_mealRecord
                var repMealRecord = new Can_MealRecordRepository(unitOfWork);
                var lstMealRecord = repMealRecord.FindBy(meal => meal.LineID != null && !lstHDTjobID.Contains(meal.LineID.Value) && meal.ProfileID.HasValue && profileIds.Contains(meal.ProfileID.Value)
                                    && dateStart <= meal.WorkDay && meal.WorkDay <= dateEnd)
                                  .Select(meal => new { meal.ProfileID, meal.WorkDay }).ToList();

                //Allowance type setting
                var repAllowanceTypeSetting = new Can_MealAllowanceTypeSettingRepository(unitOfWork);
                var lstAllowanceTypeSetting = repAllowanceTypeSetting.GetAll().Select(al => new {al.ID, al.MealAllowanceTypeSettingName }).ToList();


                var repoOrgType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var listOrgType = repoOrgType.FindBy(s => s.IsDelete == null).ToList();

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

                //var repoLine = new Can_LineRepository(unitOfWork);
                //var repoCatering = new Can_CateringRepository(unitOfWork);
                //var repoCanteen = new Can_CanteenRepository(unitOfWork);

                foreach (var mealRecordMissing in mealRecordMissings)
                {
                    // neu co quet the an thi ko tinh
                    var meadRecord = lstMealRecord.FirstOrDefault(s => s.ProfileID == mealRecordMissing.ProfileID && s.WorkDay.Value.Date == mealRecordMissing.WorkDate.Value.Date);
                    if (meadRecord != null)
                    {
                        continue;
                    }
                    // neu ngay do dk nghi thi ko tinh
                    var leaveday = lstLeaveday.FirstOrDefault(s => s.ProfileID == mealRecordMissing.ProfileID && s.DateStart <= mealRecordMissing.WorkDate && mealRecordMissing.WorkDate <= s.DateEnd);
                    if (leaveday != null)
                    {
                        continue;
                    }
                    // neu ngay do ko di lam thi ko tinh
                    var workday = lstWorkday.FirstOrDefault(s => s.ProfileID == mealRecordMissing.ProfileID && s.WorkDate.Date == mealRecordMissing.WorkDate.Value.Date);
                    if (workday == null)
                    {
                        continue;
                    }
                    DataRow row = table.NewRow();
                    if (workday != null && workday.InTime1 != null)
                    {
                        row["TimeIn"] = workday.InTime1;
                    }
                    if (workday != null && workday.OutTime1 != null)
                    {
                        row["TimeOut"] = workday.OutTime1;
                    }
                    var profile = profiles.FirstOrDefault(s => s.ID == mealRecordMissing.ProfileID);
                    if (profile != null)
                    {
                        var type = lstAllowanceTypeSetting.FirstOrDefault(s => s.ID == mealRecordMissing.MealAllowanceTypeSettingID);
                        var org = listOrgAll.FirstOrDefault(s => profile != null && s.ID == mealRecordMissing.OrgStructureID);
                        var orgBranch = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_BRANCH, listOrgAll, listOrgType);
                        var orgOrg = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_DEPARTMENT, listOrgAll, listOrgType);
                        var orgTeam = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_TEAM, listOrgAll, listOrgType);
                        var orgSection = LibraryService.GetNearestParent(profile.OrgStructureID, OrgUnit.E_SECTION, listOrgAll, listOrgType);

                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeBranch] = orgBranch != null ? orgBranch.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeDepartment] = orgOrg != null ? orgOrg.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeTeam] = orgTeam != null ? orgTeam.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.CodeSection] = orgSection != null ? orgSection.Code : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            
                        row[Can_ReportCardByLocationEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                        row[Can_ReportCardByLocationEntity.FieldNames.ProfileName] = profile.ProfileName;
                        row[Can_ReportCardByLocationEntity.FieldNames.Date] = mealRecordMissing.WorkDate;
                        row[Can_ReportCardByLocationEntity.FieldNames.DateFrom] = dateStart;
                        row[Can_ReportCardByLocationEntity.FieldNames.DateTo] = dateEnd;

                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.DateExport] = DateTime.Now;
                        row[Can_ReportMealTimeDetailNoEatEntity.FieldNames.MealAllowanceName] = type != null ? type.MealAllowanceTypeSettingName : string.Empty;
                        table.Rows.Add(row);
                    }

                }
                return table;
            }
        }
Ejemplo n.º 12
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();
            }
        }