Example #1
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;
            }
        }
Example #2
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;
        }
Example #3
0
 /// <summary>
 /// [Tam.Le] - 20140725 - Lấy dữ liệu BC Chi Tiết Nhân Viên Không Chấm Công Nhưng Có Ă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_ReportMealTimeDetailEntity> ReportMealTimeDetail(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime dateStart, DateTime dateEnd, List<int?> orgIDs)
 {
     var mealRecords = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Can_MealRecordRepository(unitOfWork);
         if (LineIDS != null)
         {
             mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
             .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID })
             .ToList();
         }
         else mealRecords = repo.GetAll().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
     }
     var lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
     var lstProfile = new List<Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Hre_ProfileRepository(unitOfWork);
         lstProfile = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance))
         .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList();
     }
     List<Cat_OrgStructure> orgs = new List<Cat_OrgStructure>();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Cat_OrgStructureRepository(unitOfWork);
         orgs = repo.FindBy(s => s.Code != null).ToList();
     }
     lstProfile = lstProfile.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 (CarteringIDs != null)
     {
         mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList();
     }
     if (LineIDS != null)
     {
         mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList();
     }
     lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
     List<Hre_Profile> profiles = new List<Hre_Profile>();
     var lstProfileId = new List<int>();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Hre_ProfileRepository(unitOfWork);
         profiles = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)).ToList();
         lstProfileId = profiles.Select(s => s.Id).ToList();
     }
     var orgTypes = new List<Cat_OrgStructureType>();
     using (var context = new VnrHrmDataContext())
     {
         var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
         var repo = new Cat_OrgStructureTypeRepository(unitOfWork);
         orgTypes = repo.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
     }
     Can_ReportMealTimeDetailEntity reportMealTimeDetailEntity = null;
     List<Can_ReportMealTimeDetailEntity> lstreportMealTimeDetailEntity = new List<Can_ReportMealTimeDetailEntity>();
     foreach (var mealRecord in mealRecords)
     {
         reportMealTimeDetailEntity = new Can_ReportMealTimeDetailEntity();
         var profile = profiles.FirstOrDefault(s => s.CodeAttendance == mealRecord.CardCode);
         if (profile != null)
         {
             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);
             reportMealTimeDetailEntity.BranchCode = orgBranch != null ? orgBranch.Code : string.Empty;
             reportMealTimeDetailEntity.DepartmentCode = orgOrg != null ? orgOrg.Code : string.Empty;
             reportMealTimeDetailEntity.TeamCode = orgTeam != null ? orgTeam.Code : string.Empty;
             reportMealTimeDetailEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
             reportMealTimeDetailEntity.BranchName = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
             reportMealTimeDetailEntity.DepartmentName = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
             reportMealTimeDetailEntity.TeamName = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
             reportMealTimeDetailEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
             reportMealTimeDetailEntity.CodeEmp = profile.CodeEmp;
             reportMealTimeDetailEntity.ProfileName = profile.ProfileName;
             reportMealTimeDetailEntity.Date = mealRecord.TimeLog;
         }
         lstreportMealTimeDetailEntity.Add(reportMealTimeDetailEntity);
     }
     return lstreportMealTimeDetailEntity;
 }
Example #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.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);
        }
Example #5
0
        public DataTable ReportCardByLocation(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEndSearch, 
            List<Guid> lstProfileIds, List<Guid?> workPlaceIds, List<Guid?> eatLocationIds, Boolean isCludeEmpQuit)
        {
            DataTable datatable = CreateReportCardByLocationSchema(dateStart, dateEndSearch);
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_Line = new Can_LineRepository(unitOfWork);

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

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

                if (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();
                }
                profileIds = profiles.Select(s => s.ID).ToList();
                mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).ToList();

                var lstcateringids = mealRecords.Select(m => m.CateringID).ToList();
                var lstcanteenids = mealRecords.Select(m => m.CanteenID).ToList();
                var Cardcode = mealRecords.Select(s => s.ProfileID).Distinct().ToList();
                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoOrg.FindBy(m => m.Code != null).ToList();

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

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

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

                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (eatLocationIds != null && eatLocationIds[0] != null)
                {
                    var lstcanteenbylocation = repocanteen.FindBy(c => c.IsDelete == null && c.LocationID != null && eatLocationIds.Contains(c.LocationID.Value));
                    var lstcanteenbylocationID = lstcanteenbylocation.Select(s => s.ID).ToList();
                    mealRecords = mealRecords.Where(s => s.CanteenID != null && lstcanteenbylocationID.Contains(s.CanteenID.Value)).ToList();
                }

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

                var repoWorkLocation = new Cat_WorkPlaceRepository(unitOfWork);
                var lstWorkPlace = repoWorkLocation.GetAll().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                var caterings = repocatering.GetAll().ToList();
                var canteens = repocanteen.GetAll().ToList();
                var repoline = new Can_LineRepository(unitOfWork);
                var lines = repoline.GetAll().ToList();
                var orgTypes = new List<Cat_OrgStructureType>();
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                foreach (var profile in profiles)
                {
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var meal = mealRecords.FirstOrDefault(s => s.TimeLog != null && s.ProfileID == profile.ID && s.TimeLog.Value.Date == date.Date);
                        if (meal != null)
                        {
                            DataRow row = datatable.NewRow();
                            var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID);
                            var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID);
                            var line = lines.FirstOrDefault(s => s.ID == meal.LineID);
                            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_ReportCardByLocationEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.Code : string.Empty;
                            row[Can_ReportCardByLocationEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.Code : string.Empty;
                            row[Can_ReportCardByLocationEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.Code : string.Empty;
                            row[Can_ReportCardByLocationEntity.FieldNames.SectionName] = orgSection != null ? orgSection.Code : string.Empty;
                            row[Can_ReportCardByLocationEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Can_ReportCardByLocationEntity.FieldNames.ProfileName] = profile.ProfileName;
                            row[Can_ReportCardByLocationEntity.FieldNames.DateFrom] = dateStart;
                            row[Can_ReportCardByLocationEntity.FieldNames.DateTo] = dateEnd;
                            row[Can_ReportCardByLocationEntity.FieldNames.DatePrint] = DateTime.Now;
                            var location = cateen != null ? cateen.LocationID : null;
                            row[Can_ReportCardByLocationEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty;
                            row[Can_ReportCardByLocationEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty;
                            row[Can_ReportCardByLocationEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                            if (lstWorkPlace != null && lstWorkPlace.Count > 0)
                            {
                                var workPlaceByPro = lstWorkPlace.Where(m => m.ID == profile.WorkPlaceID).FirstOrDefault();
                                row[Can_ReportCardByLocationEntity.FieldNames.WorkLocationCode] = workPlaceByPro != null ? workPlaceByPro.Code : string.Empty;
                                row[Can_ReportCardByLocationEntity.FieldNames.WorkLocationHD] = workPlaceByPro != null ? workPlaceByPro.WorkPlaceName : string.Empty;
                            }

                            if (location != null && location != Guid.Empty)
                            {
                                var locationname = lstLocation.Where(s => s.ID == location).FirstOrDefault();
                                row[Can_ReportCardByLocationEntity.FieldNames.EatLoCationCode] = location != null ? locationname.LocationCode : string.Empty;
                                row[Can_ReportCardByLocationEntity.FieldNames.EatLoCationHD] = location != null ? locationname.LocationName : string.Empty;
                            }
                            if (meal.WorkDay != null)
                            {
                                row["Data" + date.Day] = meal.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                                row[Can_ReportCardByLocationEntity.FieldNames.Quantity] = 1;
                            }
                            row[Can_ReportCardByLocationEntity.FieldNames.Amount] = (object)meal.Amount ?? DBNull.Value;
                            row[Can_ReportCardByLocationEntity.FieldNames.Date] = meal.WorkDay;
                            if (meal.TimeLog != null)
                            {
                                row[Can_ReportCardByLocationEntity.FieldNames.Hour] = meal.TimeLog.Value;
                            }
                            datatable.Rows.Add(row);
                        }
                    }
                }
            }
            return datatable;
        }
Example #6
0
        public DataTable ReportMultiSlideCard(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime dateStart, DateTime dateEnd, List <int> lstProfileIds)
        {
            List <Can_ReportMultiSlideCardEntity> lstReportMultiSlideCard = new List <Can_ReportMultiSlideCardEntity>();
            DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEnd);

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork  = (IUnitOfWork)(new UnitOfWork(context));
                var mealRecords = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var repo        = new Can_MealRecordRepository(unitOfWork);
                mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
                              .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var lstcateringids = mealRecords.Select(m => m.CateringID).ToList();
                var lstcanteenids  = mealRecords.Select(m => m.CanteenID).ToList();
                var lstlineids     = mealRecords.Select(m => m.LineID).ToList();

                var workDays    = new List <Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                workDays = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                           .Select(s => new { s.ProfileID, s.WorkDate }).ToList();

                var Cardcode    = mealRecords.Select(s => s.CardCode).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles    = repoProfile.FindBy(m => Cardcode.Contains(m.CodeAttendance) && lstProfileIds.Contains(m.Id)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList();

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

                var catering     = new List <Can_Catering>().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                if (CarteringIDs != null && CarteringIDs.Count > 0)
                {
                    catering = repocatering.FindBy(m => CarteringIDs.Contains(m.Id)).ToList();
                }
                else
                {
                    catering = repocatering.GetAll().ToList();
                }


                var canteen     = new List <Can_Canteen>().ToList();
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null && CanteenIDS.Count > 0)
                {
                    canteen = repocanteen.FindBy(m => CanteenIDS.Contains(m.Id)).ToList();
                }
                else
                {
                    canteen = repocanteen.GetAll().ToList();
                }

                var line     = new List <Can_Line>().ToList();
                var repoline = new Can_LineRepository(unitOfWork);
                if (LineIDS != null && LineIDS.Count > 0)
                {
                    line = repoline.FindBy(m => LineIDS.Contains(m.Id)).ToList();
                }
                else
                {
                    line = repoline.GetAll().ToList();
                }

                Can_ReportMultiSlideCardEntity ReportMultiSlideCardEntity = new Can_ReportMultiSlideCardEntity();
                foreach (var profile in profiles)
                {
                    DataRow row               = datatable.NewRow();
                    var     orgbyprofile      = orgs.Where(m => m.Id == profile.OrgStructureID).FirstOrDefault();
                    var     cateringbyprofile = catering.Where(m => lstcateringids.Contains(m.Id)).FirstOrDefault();
                    var     lineprofile       = line.Where(m => lstlineids.Contains(m.Id)).FirstOrDefault();
                    var     canteenbyprofile  = canteen.Where(m => lstcanteenids.Contains(m.Id)).FirstOrDefault();
                    row[Can_ReportMultiSlideCardEntity.FieldNames.CodeEmp]          = profile.CodeEmp;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.ProfileName]      = profile.ProfileName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.OrgStructureName] = orgbyprofile.OrgStructureName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Cartering]        = cateringbyprofile.CateringName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Canteen]          = canteenbyprofile.CanteenName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Line]             = lineprofile.LineName;
                    var mealRecordProfiles = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).ToList();
                    var workDayProfiles    = workDays.Where(s => s.ProfileID == profile.Id).ToList();
                    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;
                            //row["SumCardMore" + date.Day] = mealRecordProfiles.Count(s => s.TimeLog == date) - workDayProfiles.Count(s => s.WorkDate == date);
                        }
                    }
                    datatable.Rows.Add(row);
                }
            }
            return(datatable);
        }
        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();
            }
        }
Example #8
0
        public DataTable ReportHDTJobCardMore(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEnd, List<Guid> lstProfileIds,  Boolean isCludeEmpQuit)
        {
            DataTable datatable = CreateReportHDTJobCardMoreSchema();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var repo = new Can_MealRecordRepository(unitOfWork);

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                        var orgId = orgs.Where(og => og.ID == mealRecordProfiles[0].OrgStructureID).Select(og => og.ID).FirstOrDefault();
                                        var orgBranch = LibraryService.GetNearestParent(orgId, OrgUnit.E_DIVISION, orgs, orgTypes);
                                        var orgOrg = LibraryService.GetNearestParent(orgId, OrgUnit.E_DEPARTMENT, orgs, orgTypes);
                                        var orgTeam = LibraryService.GetNearestParent(orgId, OrgUnit.E_SECTION, orgs, orgTypes);
                                        var orgSection = LibraryService.GetNearestParent(orgId, OrgUnit.E_GROUP, orgs, orgTypes);

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

                }
            }
            return datatable;
        }
Example #9
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;
        }
Example #10
0
        public List<Can_ReportMealTimeSummaryEntity> ReportMealTimeSummary(List<Guid> CarteringIDs, List<Guid> CanteenIDS, List<Guid> LineIDS, DateTime DateFrom, DateTime dateEndSearch, List<Guid> OrgIds)
        {
            #region GetData
            using (var context = new VnrHrmDataContext())
            {
                DateTime DateTo = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                List<Can_ReportMealTimeSummaryEntity> lstReportMealTimeSummary = new List<Can_ReportMealTimeSummaryEntity>();
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_MealRecordRepository(unitOfWork);
                var lstMealRecord = repo.FindBy(m => m.CateringID != null && m.WorkDay >= DateFrom && m.WorkDay <= DateTo && m.ProfileID != null).ToList();
                if (lstMealRecord.Count < 0)
                {
                    return lstReportMealTimeSummary;
                }
                var lstProfileIdsByMealRecord = lstMealRecord.Select(m => m.ProfileID).ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => lstProfileIdsByMealRecord.Contains(m.ID)).ToList();
                if (OrgIds != null && OrgIds[0] != Guid.Empty)
                {
                    profiles = profiles.Where(m => m.OrgStructureID != null && OrgIds.Contains(m.OrgStructureID.Value)).ToList();
                }
                if (CanteenIDS != null && CanteenIDS[0] != Guid.Empty)
                {
                    lstMealRecord = lstMealRecord.Where(m => m.CanteenID != null && CanteenIDS.Contains(m.CanteenID.Value)).ToList();
                }
                if (CarteringIDs != null && CarteringIDs[0] != Guid.Empty)
                {
                    lstMealRecord = lstMealRecord.Where(m => m.CateringID != null && CarteringIDs.Contains(m.CateringID.Value)).ToList();
                }
                if (lstMealRecord.Count < 1)
                {
                    return lstReportMealTimeSummary;
                }
                if (LineIDS != null && LineIDS[0] != Guid.Empty)
                {
                    lstMealRecord = lstMealRecord.Where(m => m.LineID != null && LineIDS.Contains(m.LineID.Value)).ToList();
                }
                if (lstMealRecord.Count < 0)
                {
                    return lstReportMealTimeSummary;
                }
                var repoCatering = new Can_CateringRepository(unitOfWork);
                var caterings = repoCatering.GetAll().ToList();
                var repoLine = new Can_LineRepository(unitOfWork);
                var lines = repoLine.GetAll().ToList();
                var repoCanteen = new Can_CanteenRepository(unitOfWork);
                var canteens = repoCanteen.GetAll().ToList();

            #endregion

                foreach (var canLine in lines)
                {
                    var cateIDs = lstMealRecord.Where(s => s.LineID == canLine.ID).Select(s => s.CateringID).Distinct().ToList();
                    foreach (var catering in caterings.Where(s => cateIDs.Contains(s.ID)).ToList())
                    {
                        var cantenIDs = lstMealRecord.Where(s => s.LineID == canLine.ID).Select(s => s.CanteenID).Distinct().ToList();
                        foreach (var canteen in canteens.Where(s => cantenIDs.Contains(s.ID)).ToList())
                        {
                            Can_ReportMealTimeSummaryEntity ReportMealTimeSummaryEntity = new Can_ReportMealTimeSummaryEntity();
                            ReportMealTimeSummaryEntity.CateringName = catering != null ? catering.CateringName : string.Empty;
                            ReportMealTimeSummaryEntity.CanteenName = canteen != null ? canteen.CanteenName : string.Empty;
                            ReportMealTimeSummaryEntity.DateFrom = DateFrom;
                            ReportMealTimeSummaryEntity.DateTo = DateTo;
                            ReportMealTimeSummaryEntity.LineName = canLine != null ? canLine.LineName : string.Empty;
                            ReportMealTimeSummaryEntity.Price = (double)(canLine.Amount != null ? canLine.Amount.Value : 0);
                            var count = lstMealRecord.Count(s => canLine != null && (canteen != null && (catering != null && (s.CateringID == catering.ID && s.CanteenID == canteen.ID && s.LineID == canLine.ID))));
                            var sumAll = lstMealRecord.Where(s => catering != null && catering.ID == s.CateringID).Sum(s => s.Amount);
                            if (count > 0)
                            {
                                ReportMealTimeSummaryEntity.Total = count;
                            }
                            if (canLine.Amount != null)
                            {
                                var amount = count * canLine.Amount;
                                if (amount > 0)
                                    ReportMealTimeSummaryEntity.TotalAmount = (double)amount;
                                if (amount > 0)
                                {
                                    var rate = (double)(amount / sumAll);
                                    ReportMealTimeSummaryEntity.Rate = Math.Round(rate, 6);
                                }
                            }
                            ReportMealTimeSummaryEntity.DatePrint = DateTime.Now;
                            if (ReportMealTimeSummaryEntity.Rate > 0)
                                lstReportMealTimeSummary.Add(ReportMealTimeSummaryEntity);
                        }
                    }
                }
                return lstReportMealTimeSummary;
            }
        }
Example #11
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;
            }
        }
Example #12
0
        public DataTable GetReportPayMoneyEat(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs,
            DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs, List<Guid?> countryIDs, String codeEmp, Boolean IsIncludeQuitEmp)
        {
            DataTable datatable = CreatePayMoneyEatSchema();
            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 }).ToList();

                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().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();

                if (orgIDs != null && orgIDs[0] != null)
                {
                    profiles = profiles.Where(s => s.OrgStructureID != null && orgIDs.Contains(s.OrgStructureID.Value)).ToList();
                }
                //if (empTypes != null && empTypes[0] != null)
                //{
                //    profiles = profiles.Where(s => s.EmpTypeID != null && empTypes.Contains(s.EmpTypeID.Value)).ToList();
                //}
                if (countryIDs[0] != Guid.Empty)
                {
                    profiles = profiles.Where(s => s.NationalityID != null && countryIDs.Contains(s.NationalityID.Value)).ToList();
                    //profileIds = profiles.Select(s => s.ID).ToList();
                    //mealRecords = mealRecords.Where(s => profileIds.Contains(s.ProfileID.Value)).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 = mealRecords.Select(s => s.ProfileID.Value).ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();

                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var repoCaterings = new Can_CateringRepository(unitOfWork);
                var caterings = repoCaterings.GetAll().ToList();
                var repoCanteen = new Can_CanteenRepository(unitOfWork);
                var canteens = repoCanteen.GetAll().ToList();

                var amounts = repoCan_Line.FindBy(s => s.Amount != null).Select(s => new { s.Amount, s.ID }).Distinct().ToList();

                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                foreach (var profile in profiles)
                {
                    var careringIDs = mealRecords.Where(s => s.ProfileID == profile.ID).Select(s => s.CateringID).ToList();
                    var carerings = caterings.Where(s => careringIDs.Contains(s.ID)).ToList();
                    foreach (var catering in carerings)
                    {
                        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_ReportPayMoneyEatEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.ProfileName] = profile.ProfileName;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.DateFrom] = dateStart;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.DateTo] = dateEnd;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.DatePrint] = DateTime.Now;
                        row[Can_ReportPayMoneyEatEntity.FieldNames.CateringName] = catering.CateringName;

                        var lstAmount = amounts.Select(am => am.Amount).Distinct().ToList();
                        foreach (var amount in lstAmount)
                        {
                            var lsLineID = amounts.Where(am => am.Amount == amount).Select(am => am.ID).ToList();
                            var countCareing = mealRecords.Where(meal => meal.ProfileID == profile.ID && meal.LineID != null && lsLineID.Contains(meal.LineID.Value)).Count();
                            if (countCareing > 0)
                                row[amount.ToString()] = countCareing;
                        }

                        foreach (var amount in amounts)
                        {
                            var countCareing = mealRecords.Count(s => s.ProfileID == profile.ID && s.CateringID == catering.ID && s.LineID == amount.ID);
                            if (countCareing > 0)
                                row[amount.Amount.ToString()] = countCareing;
                        }
                        var countEat = mealRecords.Count(s => s.ProfileID == profile.ID && s.CateringID == catering.ID);
                        if (countEat > 0)
                            row[Can_ReportPayMoneyEatEntity.FieldNames.CountEat] = countEat;
                        var subtractSalary = mealRecords.Where(s => s.ProfileID == profile.ID && s.CateringID == catering.ID).Sum(s => s.Amount);
                        if (subtractSalary > 0)
                            row[Can_ReportPayMoneyEatEntity.FieldNames.SubtractSalary] = subtractSalary;
                        datatable.Rows.Add(row);
                    }
                }
                return datatable;
            }
        }
Example #13
0
        public DataTable ReportMultiSlideCard(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, List<Guid?> lstWorkPlaceID,
            DateTime dateStart, DateTime dateEndSearch, List<Guid> lstProfileIds, Boolean IsIncludeQuitEmp)
        {
            DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEndSearch);
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));

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

                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                var wordDayProfiles = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                    .Select(s => new { s.ProfileID, s.WorkDate, s.FirstInTime, s.LastOutTime }).ToList();

                var repo = new Can_MealRecordRepository(unitOfWork);
                var mealRecords = repo.FindBy(s => s.LineID != null && s.WorkDay != null && !lineHDTJobIDs.Contains(s.LineID.Value) && s.ProfileID != null
                    && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).Select(s => new { s.ProfileID, s.TimeLog, s.CanteenID, s.CateringID, s.LineID, s.WorkDay }).ToList();
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var profileIds = mealRecords.Select(s => s.ProfileID.Value).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => profileIds.Contains(m.ID)).ToList();
                if (lstProfileIds != null && lstProfileIds.Count >= 1)
                {
                    profiles = profiles.Where(s => lstProfileIds.Contains(s.ID)).ToList();
                }
                if (lstWorkPlaceID[0] != Guid.Empty)
                {
                    profiles = profiles.Where(hr => hr.WorkPlaceID != null && lstWorkPlaceID.Contains(hr.WorkPlaceID.Value)).ToList();
                }
                //Kiểm tra ko nghỉ việc
                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();

                var Cardcode = mealRecords.Select(s => s.ProfileID).Distinct().ToList();
                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                var orgs = repoOrg.FindBy(m => m.Code != null).ToList();
                var catering = new List<Can_Catering>().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                if (CarteringIDs != null && CarteringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CateringID != null && CarteringIDs.Contains(m.CateringID)).ToList();
                }
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null && CanteenIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.CanteenID != null && CanteenIDS.Contains(m.CanteenID)).ToList();
                }
                if (LineIDS != null && LineIDS[0] != null)
                {
                    mealRecords = mealRecords.Where(m => m.LineID != null && LineIDS.Contains(m.LineID)).ToList();
                }
                if (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                var orgTypes = new List<Cat_OrgStructureType>();
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();
                var repoCan_Catering = new Can_CateringRepository(unitOfWork);
                var repoCan_Canteen = new Can_CanteenRepository(unitOfWork);
                var repoline = new Can_LineRepository(unitOfWork);
                var canteens = repoCan_Canteen.GetAll().ToList();
                var caterings = repoCan_Catering.GetAll().ToList();
                var lines = repoCan_Line.GetAll().ToList();

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

                foreach (var profile in profiles)
                {
                    var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList();
                    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 workDayDates = wordDayProfiles.Where(s => s.ProfileID == profile.ID && (s.FirstInTime != null || s.LastOutTime != null)).Select(s => s.WorkDate.Date).ToList();
                        var mealDoubles = mealRecordProfiles.Where(s => s.TimeLog != null && s.TimeLog.Value.Date == date.Date).ToList();
                        if (mealDoubles.Count > 1)
                        {
                            foreach (var meal in mealDoubles)
                            {
                                DataRow row = datatable.NewRow();
                                Guid? orgId = profile != null ? profile.OrgStructureID : Guid.Empty;
                                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_ReportMultiSlIDeCardEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.ProfileName] = profile.ProfileName;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DateFrom] = dateStart;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DateTo] = dateEnd;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.DatePrint] = DateTime.Now;
                                if (meal.TimeLog != null)
                                {
                                    row["Data" + date.Day] = meal.TimeLog.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                                }
                                var count1 = 0;
                                for (DateTime date1 = dateStart; date1 <= dateEnd; date1 = date1.AddDays(1))
                                {
                                    int countDay = mealRecordProfiles.Count(s => s.TimeLog != null && s.TimeLog.Value.Date == date1.Date && leaveDay == null);
                                    if (countDay > 1)
                                    {
                                        count1 += countDay - 1;
                                    }
                                }
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.SumCardMore] = count1;
                                var cate = caterings.FirstOrDefault(s => s.ID == meal.CateringID);
                                var cateen = canteens.FirstOrDefault(s => s.ID == meal.CanteenID);
                                var line = lines.FirstOrDefault(s => s.ID == meal.LineID);
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                                row[Can_ReportMultiSlIDeCardEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                                datatable.Rows.Add(row);
                            }
                        }
                    }
                }
                return datatable;
            }
        }
Example #14
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;
            }
        }
Example #15
0
        public DataTable ReportMultiSlideCard(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime dateStart, DateTime dateEnd, List<int> lstProfileIds)
        {
            List<Can_ReportMultiSlideCardEntity> lstReportMultiSlideCard = new List<Can_ReportMultiSlideCardEntity>();
            DataTable datatable = CreateReportMultiSlideCardSchema(dateStart, dateEnd);
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var mealRecords = new List<Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var repo = new Can_MealRecordRepository(unitOfWork);
                mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
                        .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                var lstcateringids = mealRecords.Select(m =>m.CateringID).ToList();
                var lstcanteenids = mealRecords.Select(m =>m.CanteenID).ToList();
                var lstlineids = mealRecords.Select(m => m.LineID).ToList();

                var workDays = new List<Att_WorkDay>().Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                var repoWorkDay = new Att_WorkDayRepository(unitOfWork);
                workDays = repoWorkDay.FindBy(s => s.ProfileID != null && dateStart <= s.WorkDate && s.WorkDate <= dateEnd)
                    .Select(s => new { s.ProfileID, s.WorkDate }).ToList();
                
                var Cardcode = mealRecords.Select(s => s.CardCode).Distinct().ToList();
                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(m => Cardcode.Contains(m.CodeAttendance) && lstProfileIds.Contains(m.Id)).Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp, s.CodeAttendance }).ToList();

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

                var catering = new List<Can_Catering>().ToList();
                var repocatering = new Can_CateringRepository(unitOfWork);
                if(CarteringIDs != null && CarteringIDs.Count >0)
                {
                    catering = repocatering.FindBy(m => CarteringIDs.Contains(m.Id)).ToList();
                }
                else
                    catering = repocatering.GetAll().ToList();


                var canteen = new List<Can_Canteen>().ToList();
                var repocanteen = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null && CanteenIDS.Count > 0)
                {
                    canteen = repocanteen.FindBy(m => CanteenIDS.Contains(m.Id)).ToList();
                }
                else
                    canteen = repocanteen.GetAll().ToList();

                var line = new List<Can_Line>().ToList();
                var repoline = new Can_LineRepository(unitOfWork);
                if (LineIDS != null && LineIDS.Count > 0)
                {
                    line = repoline.FindBy(m => LineIDS.Contains(m.Id)).ToList();
                }
                else
                    line = repoline.GetAll().ToList();

                Can_ReportMultiSlideCardEntity ReportMultiSlideCardEntity = new Can_ReportMultiSlideCardEntity();
                foreach (var profile in profiles)
                {
                    DataRow row = datatable.NewRow();
                    var orgbyprofile = orgs.Where(m => m.Id == profile.OrgStructureID).FirstOrDefault();
                    var cateringbyprofile = catering.Where(m => lstcateringids.Contains(m.Id)).FirstOrDefault();
                    var lineprofile = line.Where(m => lstlineids.Contains(m.Id)).FirstOrDefault();
                    var canteenbyprofile = canteen.Where(m =>  lstcanteenids.Contains(m.Id)).FirstOrDefault();
                    row[Can_ReportMultiSlideCardEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.ProfileName] = profile.ProfileName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.OrgStructureName] = orgbyprofile.OrgStructureName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Cartering] = cateringbyprofile.CateringName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Canteen] = canteenbyprofile.CanteenName;
                    row[Can_ReportMultiSlideCardEntity.FieldNames.Line] = lineprofile.LineName;
                    var mealRecordProfiles = mealRecords.Where(s => s.CardCode == profile.CodeAttendance).ToList();
                    var workDayProfiles = workDays.Where(s => s.ProfileID == profile.Id).ToList();
                    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;
                            //row["SumCardMore" + date.Day] = mealRecordProfiles.Count(s => s.TimeLog == date) - workDayProfiles.Count(s => s.WorkDate == date);
                        }
                    }
                    datatable.Rows.Add(row);
                }
            }
            return datatable;
        }
Example #16
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;
            }
        }
Example #17
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);
            }
        }
Example #18
0
        public DataTable ReportMealTimeDetail(List<Guid?> CarteringIDs, List<Guid?> CanteenIDS, List<Guid?> LineIDS, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            using (var context = new VnrHrmDataContext())
            {
                DateTime dateEnd = dateEndSearch.AddDays(1).AddMilliseconds(-1);
                DataTable datatable = CreateReportMealTimeDetailSchema(dateStart, dateEnd);
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repoMealRecord = new Can_MealRecordRepository(unitOfWork);
                var repoLine = new Can_LineRepository(unitOfWork);
                var lineHDTJobIDs = repoLine.FindBy(s => s.HDTJ != null).Select(s => s.ID).ToList();
                var mealRecords = repoMealRecord.FindBy(s => s.LineID != null && !lineHDTJobIDs.Contains(s.LineID.Value)
                    && s.ProfileID != null && dateStart <= s.WorkDay && s.WorkDay <= dateEnd).ToList();
                if (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.ProfileID != null && dateStart <= s.WorkDate
                  && s.WorkDate <= dateEnd && profileIds.Contains(s.ProfileID)).ToList();

                var repoProfile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoProfile.FindBy(s => profileIds.Contains(s.ID)).ToList();

                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, s.LeaveDayTypeID }).ToList();

                var repoleaveDayType = new Cat_LeaveDayTypeRepository(unitOfWork);
                var leaveDayTypes = repoleaveDayType.GetAll().Select(s => new { s.ID, s.LeaveDayTypeName }).ToList();

                List<Cat_OrgStructure> orgs = new List<Cat_OrgStructure>();
                var repoOrg = new Cat_OrgStructureRepository(unitOfWork);
                orgs = repoOrg.FindBy(s => s.Code != null).ToList();
                if (orgIDs != null && orgIDs.Count > 0)
                {
                    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 (CarteringIDs != null && CarteringIDs[0] != null)
                {
                    mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.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 (mealRecords.Count < 1)
                {
                    return datatable;
                }
                profileIds = mealRecords.Select(s => s.ProfileID.Value).ToList();
                profiles = profiles.Where(s => profileIds.Contains(s.ID)).ToList();
                var orgTypes = new List<Cat_OrgStructureType>();

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

                var repoCanteen = new Can_CanteenRepository(unitOfWork);
                var repoCatering = new Can_CateringRepository(unitOfWork);
                var canteens = repoCanteen.GetAll().ToList();
                var caterings = repoCatering.GetAll().ToList();
                var lines = repoLine.GetAll().ToList();
                #region Code Cũ
                //foreach (var profile in profiles)
                //{
                //    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.Id).Select(s => s.WorkDate.Date).ToList();
                //    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                //    {
                //        var record = mealRecords.FirstOrDefault(s => s.ProfileID == profile.Id && date == s.TimeLog.Date && !workdayProfileDates.Contains(date.Date));
                //        if (record != null)
                //        {
                //            DataRow row = datatable.NewRow();
                //            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);
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.ProfileName] = profile.ProfileName;
                //            var line = repoLine.FindBy(m => record.LineID == m.Id).FirstOrDefault();
                //            var canteen = repoCanteen.FindBy(m => record.CanteenID == m.Id).FirstOrDefault();
                //            var catering = repoCatering.FindBy(m => record.CateringID == m.Id).FirstOrDefault();
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.CateringName] = catering != null ? catering.CateringName : null;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.CanteenName] = canteen != null ? canteen.CanteenName : null;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.LineName] = line != null ? line.LineName : null;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DateFrom] = dateStart;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DateTo] = dateEnd;
                //            row[Can_ReportMealTimeDetailEntity.FieldNames.DatePrint] = DateTime.Now;
                //            if (record.TimeLog != null)
                //            {
                //                row["Data" + date.Day] = record.TimeLog.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                //            }
                //            datatable.Rows.Add(row);
                //        }
                //    }
                //} 
                #endregion
                foreach (var profile in profiles)
                {
                    var workdayProfileDates = workDayProfies.Where(s => s.ProfileID == profile.ID && (s.FirstInTime != null || s.LastOutTime != null)).Select(s => s.WorkDate.Date).ToList();
                    var mealRecordProfiles = mealRecords.Where(s => s.ProfileID == profile.ID).ToList();
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var leaday = leavedays.FirstOrDefault(s => s.DateStart != null && s.DateEnd != null && s.ProfileID == profile.ID && s.DateStart.Date <= date.Date && date.Date <= s.DateEnd.Date);
                        var record = mealRecordProfiles.FirstOrDefault(s => date.Date == s.WorkDay.Value.Date && (!workdayProfileDates.Contains(s.WorkDay.Value.Date) || leaday != null));
                        if (record != null)
                        {
                            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_ReportMealTimeDetailEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.CodeEmp] = profile.CodeEmp;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.ProfileName] = profile.ProfileName;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.Date] = record.WorkDay;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DateFrom] = dateStart;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DateTo] = dateEnd;
                            var cate = caterings.FirstOrDefault(s => s.ID == record.CateringID);
                            var cateen = canteens.FirstOrDefault(s => s.ID == record.CanteenID);
                            var line = lines.FirstOrDefault(s => s.ID == record.LineID);
                            row[Can_ReportMealTimeDetailEntity.FieldNames.CateringName] = cate != null ? cate.CateringName : string.Empty; ;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.CanteenName] = cateen != null ? cateen.CanteenName : string.Empty; ;
                            row[Can_ReportMealTimeDetailEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                            if (record.TimeLog != null)
                            {
                                row["Data" + record.WorkDay.Value.Day] = record.TimeLog == null ? null : (object)record.TimeLog.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime) ?? DBNull.Value;
                            }
                            row[Can_ReportMealTimeDetailEntity.FieldNames.DatePrint] = DateTime.Now;
                            if (leaday != null)
                            {
                                var leadayType = leaveDayTypes.FirstOrDefault(s => s.ID == leaday.LeaveDayTypeID);
                                row[Can_ReportMealTimeDetailEntity.FieldNames.LeaveDayTypeName] = leadayType != null ? leadayType.LeaveDayTypeName : string.Empty;
                            }
                            datatable.Rows.Add(row);
                        }
                    }
                }
                return datatable;
            }
        }
Example #19
0
        public DataTable GetReportRecieveObjectByTime(string orgStructureIDs, DateTime dateFrom, DateTime dateTo, bool IsCreateTemplate, string userLogin)
        {
            DataTable table = GetSchemaReportRecieveObjectByTime(userLogin);
            if (IsCreateTemplate)
            {
                return table.ConfigTable();
            }
            string status = string.Empty;
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var basevices = new BaseService();
                var hdtJobServices = new Hre_HDTJobServices();
                List<object> listObjHDTJob = new List<object>();
                listObjHDTJob.AddRange(new object[14]);
                listObjHDTJob[5] = orgStructureIDs;
                listObjHDTJob[6] = dateFrom;
                listObjHDTJob[7] = dateTo;
                listObjHDTJob[12] = 1;
                listObjHDTJob[13] = Int32.MaxValue - 1;
                var lstHDTJob = hdtJobServices.GetData<Hre_HDTJobEntity>(listObjHDTJob, ConstantSql.hrm_hr_sp_get_RptRecieveObjectByTime, userLogin, ref status).ToList();
                if (lstHDTJob.Count == 0)
                {
                    return table;
                }

                var lstProfileIDByHDTJob = lstHDTJob.Select(s => s.ProfileID).Distinct().ToList();

                #region Lấy WorkDay
                var workDayRepository = new Att_WorkDayRepository(unitOfWork);
                var lstworkDays = new List<Att_Workday>().Select(d => new
                {
                    d.ProfileID,
                    d.WorkDate,
                    d.FirstInTime,
                    d.LastOutTime
                }).ToList();

                foreach (var item in lstProfileIDByHDTJob.Chunk(1000))
                {
                    lstworkDays.AddRange(workDayRepository.FindBy(s => s.IsDelete == null && s.WorkDate >= dateFrom
                        && s.WorkDate <= dateTo && item.Contains(s.ProfileID)).Select(d => new
                        {
                            d.ProfileID,
                            d.WorkDate,
                            d.FirstInTime,
                            d.LastOutTime
                        }).ToList());
                }

                if (lstworkDays.Count == 0)
                {
                    return table;
                }
                #endregion

                #region Lấy MealRecord
                var mealRecordRepository = new Can_MealRecordRepository(unitOfWork);
                var lstmeadrecored = new List<Can_MealRecord>().Select(d => new
                {
                    d.ProfileID,
                    d.WorkDay,
                    d.Amount
                }).ToList();

                foreach (var item in lstProfileIDByHDTJob.Chunk(1000))
                {
                    lstmeadrecored.AddRange(mealRecordRepository.FindBy(s => s.IsDelete == null && s.WorkDay >= dateFrom
                        && s.WorkDay <= dateTo && item.Contains(s.ProfileID)).Select(d => new
                        {
                            d.ProfileID,
                            d.WorkDay,
                            d.Amount
                        }).ToList());
                }
                #endregion

                List<object> listObjPrice = new List<object>();
                listObjPrice.Add(null);
                listObjPrice.Add(null);
                listObjPrice.Add(null);
                listObjPrice.Add(1);
                listObjPrice.Add(Int32.MaxValue - 1);
                var lstHDTJobTypePrice = basevices.GetData<Cat_HDTJobTypePriceEntity>(listObjPrice, ConstantSql.hrm_cat_sp_get_HDTJobTypePrice, userLogin, ref status).Where(s => s.Price != null).Distinct().ToList();
                var profileServices = new Hre_ProfileServices();
                var listResult = profileServices.getHDTJobByPrice(lstHDTJob, dateFrom, dateTo);

                var ListProfileID = listResult.Select(m => m.ProfileID).Distinct().ToList();

                foreach (var profileID in ListProfileID)
                {
                    var firstProfile = listResult.Where(m => m.ProfileID == profileID).FirstOrDefault();
                    var lstWorkDaysByProfile = lstworkDays.Where(m => m.ProfileID == profileID && (m.FirstInTime != null || m.LastOutTime != null)).ToList();
                    var lstmeadlbypro = lstmeadrecored.Where(s => s.ProfileID == profileID).ToList();
                    if (firstProfile != null && lstWorkDaysByProfile.Count != 0)
                    {
                        bool isAdd = false;
                        DataRow row = table.NewRow();
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.ProfileName] = firstProfile.ProfileName;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.CodeEmp] = firstProfile.CodeEmp;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_DEPARTMENT] = firstProfile.E_DEPARTMENT;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_DIVISION] = firstProfile.E_DIVISION;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_SECTION] = firstProfile.E_SECTION;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_TEAM] = firstProfile.E_TEAM;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.E_UNIT] = firstProfile.E_UNIT;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Dept] = firstProfile.Dept;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Unit] = firstProfile.Unit;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Part] = firstProfile.Part;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Line] = firstProfile.Line;
                        row[Hre_ReportRecieveObjectByTimeEntity.FieldNames.Session] = firstProfile.Session;
                        var hdtjobbyprofile = lstHDTJob.Where(s => s.ProfileID == profileID).ToList();
                        var workdaybyProfile = lstworkDays.Where(s => s.ProfileID == profileID).ToList();
                        foreach (var item in lstHDTJobTypePrice)
                        {
                            var resultByPrice = listResult.Where(m => m.ProfileID == profileID && m.Price == item.Price).ToList();

                            if (resultByPrice.Count == 0)
                            {
                                continue;
                            }
                            int? count = 0;

                            foreach (var Price in resultByPrice)
                            {
                                if (Price.DateTo == null)
                                {
                                    Price.DateTo = dateTo;
                                }
                                for (DateTime date = Price.DateFrom.Value; date <= Price.DateTo; date = date.AddDays(1))
                                {
                                    var workdaybyprice = workdaybyProfile.Where(s => s.WorkDate != null && s.WorkDate.Date == date.Date && s.FirstInTime != null && s.LastOutTime != null).FirstOrDefault();
                                    var mealbyprice = lstmeadlbypro.Where(s => s.Amount != null && s.WorkDay != null && s.WorkDay.Value.Date == date.Date && (double)s.Amount == Price.Price).FirstOrDefault();

                                    if (workdaybyprice != null && mealbyprice != null)
                                    {
                                        count++;
                                    }
                                    row[item.Price.ToString()] = count != 0 ? count : null;
                                    if (count != null && count != 0)
                                    {
                                        isAdd = true;
                                    }
                                }

                            }
                        }
                        if (isAdd == true)
                        {
                            table.Rows.Add(row);
                        }
                    }
                }
            }
            return table.ConfigTable();
        }
Example #20
0
        public DataTable ReportDetailCard(List<Guid?> cateringIDs, List<Guid?> canteenIDs, List<Guid?> lineIDs, DateTime dateStart, DateTime dateEndSearch, List<Guid?> orgIDs)
        {
            DataTable datatable = CreateReportDetailCardSchema(dateStart, dateEndSearch);
            using (var context = new VnrHrmDataContext())
            {
                #region get data
                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 != null && mealRecords.Count < 1)
                {
                    return datatable;
                }

                var profileIdsByMealRecord = mealRecords.Select(s => s.ProfileID).Distinct().ToList();
                var repoHre_Profile = new Hre_ProfileRepository(unitOfWork);
                var profiles = repoHre_Profile.FindBy(s => profileIdsByMealRecord.Contains(s.ID)).ToList();

                var repoCan_Line = new Can_LineRepository(unitOfWork);
                var repoCan_Canteen = new Can_CanteenRepository(unitOfWork);
                var repoCan_Catering = new Can_CateringRepository(unitOfWork);
                var repoCat_OrgStructure = new Cat_OrgStructureRepository(unitOfWork);
                var repoCat_OrgStructureType = new Cat_OrgStructureTypeRepository(unitOfWork);

                var orgs = repoCat_OrgStructure.FindBy(s => s.Code != null).ToList();
                var lstallLine = repoCan_Line.GetAll().ToList();
                var lstallCatering = repoCan_Catering.GetAll().ToList();
                var lstallCanteen = repoCan_Canteen.GetAll().ToList();
                var orgTypes = repoCat_OrgStructureType.FindBy(s => s.IsDelete == null).ToList<Cat_OrgStructureType>();

                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 (mealRecords == null && mealRecords.Count < 1)
                {
                    return datatable;
                }
                #endregion
                foreach (var profile in profiles)
                {
                    var mealRecordByProfile = mealRecords.Where(m => m.ProfileID != null && m.ProfileID.Value == profile.ID).ToList();
                    if (mealRecordByProfile == null && mealRecordByProfile.Count() == 0)
                        continue;
                    for (DateTime date = dateStart; date <= dateEnd; date = date.AddDays(1))
                    {
                        var lstMealByPro = mealRecords.Where(m => m.ProfileID == profile.ID && m.TimeLog != null && m.TimeLog.Value.Date == date.Date).ToList();
                        foreach (var MealByPro in lstMealByPro)
                        {
                            if (MealByPro != null)
                            {
                                DataRow row = datatable.NewRow();
                                var profilebymeal = repoHre_Profile.FindBy(m => m.ID == MealByPro.ProfileID).FirstOrDefault();
                                Guid? orgId = profilebymeal.OrgStructureID;
                                var org = orgs.FirstOrDefault(s => s.ID == profilebymeal.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_ReportDetailCardEntity.FieldNames.BranchName] = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                                row[Can_ReportDetailCardEntity.FieldNames.DepartmentName] = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                                row[Can_ReportDetailCardEntity.FieldNames.TeamName] = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                                row[Can_ReportDetailCardEntity.FieldNames.SectionName] = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                                row[Can_ReportDetailCardEntity.FieldNames.CodeEmp] = profilebymeal.CodeEmp;
                                row[Can_ReportDetailCardEntity.FieldNames.ProfileName] = profilebymeal.ProfileName;
                                if (MealByPro.WorkDay != null)
                                {
                                    row["Data" + date.Day] = MealByPro.WorkDay.Value.ToString(ConstantFormat.HRM_Format_Grid_ShortTime);
                                }
                                var line = lstallLine.Where(m => MealByPro.LineID == m.ID).FirstOrDefault();
                                row[Can_ReportDetailCardEntity.FieldNames.LineName] = line != null ? line.LineName : string.Empty;
                                var catering = lstallCatering.Where(m => MealByPro.CateringID == m.ID).FirstOrDefault();
                                row[Can_ReportDetailCardEntity.FieldNames.CateringName] = catering != null ? catering.CateringName : string.Empty;
                                var canteen = lstallCanteen.Where(m => MealByPro.CanteenID == m.ID).FirstOrDefault();
                                row[Can_ReportDetailCardEntity.FieldNames.CanteenName] = canteen != null ? canteen.CanteenName : string.Empty;
                                row[Can_ReportDetailCardEntity.FieldNames.DateFrom] = dateStart;
                                row[Can_ReportDetailCardEntity.FieldNames.DateTo] = dateEnd;
                                row[Can_ReportDetailCardEntity.FieldNames.DatePrint] = DateTime.Now;
                                datatable.Rows.Add(row);
                            }
                        }
                    }
                }
                return datatable;
            }
        }
Example #21
0
        /// <summary>
        /// [Son.Vo] - 20140724 - Lấy dữ liệu BC Tổng Hợp Suất Ăn Của 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_ReportMealTimeSummaryEntity> ReportMealTimeSummary(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime DateFrom, DateTime DateTo)
        {
            #region GetData
            var lstMealRecord = new List <Can_MealRecord>().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).ToList();
            }

            var lstCanteens = new List <Can_Canteen>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null)
                {
                    lstCanteens = repo.FindBy(s => CanteenIDS.Contains(s.Id)).ToList();
                }
                else
                {
                    lstCanteens = repo.GetAll().ToList();
                }
            }

            var lstCaterings = new List <Can_Catering>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_CateringRepository(unitOfWork);
                if (CarteringIDs != null)
                {
                    lstCaterings = repo.FindBy(s => CarteringIDs.Contains(s.Id)).ToList();
                }
                else
                {
                    lstCaterings = repo.GetAll().ToList();
                }
            }

            var lstLines = new List <Can_Line>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_LineRepository(unitOfWork);
                if (LineIDS != null)
                {
                    lstLines = repo.FindBy(s => LineIDS.Contains(s.Id)).ToList();
                }
                else
                {
                    lstLines = repo.GetAll().ToList();
                }
            }
            #endregion
            List <Can_ReportMealTimeSummaryEntity> lstReportMealTimeSummary = new List <Can_ReportMealTimeSummaryEntity>();
            foreach (var cate in lstCaterings)
            {
                Can_ReportMealTimeSummaryEntity ReportAdjustmentMealAllowancePayment = new Can_ReportMealTimeSummaryEntity();
                ReportAdjustmentMealAllowancePayment.Catering = cate.CateringName;
                foreach (var item in lstCanteens)
                {
                    ReportAdjustmentMealAllowancePayment.Canteen = item.CanteenName;
                    foreach (var line in lstLines)
                    {
                        ReportAdjustmentMealAllowancePayment.Line  = line.LineName;
                        ReportAdjustmentMealAllowancePayment.Price = line.Amount.Value;
                        var sum  = lstMealRecord.Where(s => s.CateringID == cate.Id && s.CanteenID == cate.Id && s.LineID == line.Id).Sum(s => s.Amount);
                        var rate = lstMealRecord.Where(s => s.CateringID == cate.Id && s.LineID == line.Id).Sum(s => s.Amount) / sum;
                        ReportAdjustmentMealAllowancePayment.TotalAmount = sum != null ? sum.Value : 0;
                        ReportAdjustmentMealAllowancePayment.Rate        = rate != null ? rate.Value : 0;
                    }
                }
                lstReportMealTimeSummary.Add(ReportAdjustmentMealAllowancePayment);
            }
            return(lstReportMealTimeSummary);
        }
Example #22
0
        /// <summary>
        /// [Son.Vo] - 20140724 - Lấy dữ liệu BC Tổng Hợp Suất Ăn Của 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_ReportMealTimeSummaryEntity> ReportMealTimeSummary(List<int?> CarteringIDs, List<int?> CanteenIDS, List<int?> LineIDS, DateTime DateFrom, DateTime DateTo)
        {
            #region GetData
            var lstMealRecord = new List<Can_MealRecord>().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).ToList();
            }

            var lstCanteens = new List<Can_Canteen>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_CanteenRepository(unitOfWork);
                if (CanteenIDS != null)
                {
                    lstCanteens = repo.FindBy(s => CanteenIDS.Contains(s.Id)).ToList();
                }
                else lstCanteens = repo.GetAll().ToList();
            }

            var lstCaterings = new List<Can_Catering>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_CateringRepository(unitOfWork);
                if (CarteringIDs != null)
                {
                    lstCaterings = repo.FindBy(s => CarteringIDs.Contains(s.Id)).ToList();
                }
                else lstCaterings = repo.GetAll().ToList();
            }

            var lstLines = new List<Can_Line>().ToList();
            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo = new Can_LineRepository(unitOfWork);
                if (LineIDS != null)
                {
                    lstLines = repo.FindBy(s => LineIDS.Contains(s.Id)).ToList();
                }
                else lstLines = repo.GetAll().ToList();
            }
            #endregion
            List<Can_ReportMealTimeSummaryEntity> lstReportMealTimeSummary = new List<Can_ReportMealTimeSummaryEntity>();
            foreach (var cate in lstCaterings)
            {
                Can_ReportMealTimeSummaryEntity ReportAdjustmentMealAllowancePayment = new Can_ReportMealTimeSummaryEntity();
                ReportAdjustmentMealAllowancePayment.Catering = cate.CateringName;
                foreach (var item in lstCanteens)
                {
                    ReportAdjustmentMealAllowancePayment.Canteen = item.CanteenName;
                    foreach (var line in lstLines)
                    {
                        ReportAdjustmentMealAllowancePayment.Line = line.LineName;
                        ReportAdjustmentMealAllowancePayment.Price = line.Amount.Value;
                        var sum = lstMealRecord.Where(s => s.CateringID == cate.Id && s.CanteenID == cate.Id && s.LineID == line.Id).Sum(s => s.Amount);
                        var rate = lstMealRecord.Where(s => s.CateringID == cate.Id && s.LineID == line.Id).Sum(s => s.Amount) / sum;
                        ReportAdjustmentMealAllowancePayment.TotalAmount = sum != null ? sum.Value : 0;
                        ReportAdjustmentMealAllowancePayment.Rate = rate != null ? rate.Value : 0;
                        lstReportMealTimeSummary.Add(ReportAdjustmentMealAllowancePayment);
                    }
                }
            }
            return lstReportMealTimeSummary;
        }
Example #23
0
        /// <summary>
        /// [Tam.Le] - 20140725 - Lấy dữ liệu BC Chi Tiết Nhân Viên Không Chấm Công Nhưng Có Ă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_ReportMealTimeDetailEntity> ReportMealTimeDetail(List <int?> CarteringIDs, List <int?> CanteenIDS, List <int?> LineIDS, DateTime dateStart, DateTime dateEnd, List <int?> orgIDs)
        {
            var mealRecords = new List <Can_MealRecord>().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Can_MealRecordRepository(unitOfWork);
                if (LineIDS != null)
                {
                    mealRecords = repo.FindBy(s => s.CardCode != null && dateStart <= s.TimeLog && s.TimeLog <= dateEnd && s.NoWorkDay == true)
                                  .Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID })
                                  .ToList();
                }
                else
                {
                    mealRecords = repo.GetAll().Select(s => new { s.CardCode, s.TimeLog, s.CanteenID, s.CateringID, s.LineID }).ToList();
                }
            }
            var lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
            var lstProfile        = new List <Hre_Profile>().Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Hre_ProfileRepository(unitOfWork);
                lstProfile = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance))
                             .Select(s => new { s.Id, s.DateQuit, s.OrgStructureID, s.ProfileName, s.CodeEmp }).ToList();
            }
            List <Cat_OrgStructure> orgs = new List <Cat_OrgStructure>();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Cat_OrgStructureRepository(unitOfWork);
                orgs = repo.FindBy(s => s.Code != null).ToList();
            }
            lstProfile = lstProfile.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[0] != null)
            {
                mealRecords = mealRecords.Where(s => s.CanteenID != null && CanteenIDS.Contains(s.CanteenID.Value)).ToList();
            }
            if (CarteringIDs[0] != null)
            {
                mealRecords = mealRecords.Where(s => s.CateringID != null && CarteringIDs.Contains(s.CateringID.Value)).ToList();
            }
            if (LineIDS[0] != null)
            {
                mealRecords = mealRecords.Where(s => s.LineID != null && LineIDS.Contains(s.LineID.Value)).ToList();
            }
            lstCodeAttendance = mealRecords.Select(s => s.CardCode).Distinct().ToList();
            List <Hre_Profile> profiles = new List <Hre_Profile>();
            var lstProfileId            = new List <int>();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Hre_ProfileRepository(unitOfWork);
                profiles     = repo.FindBy(s => lstCodeAttendance.Contains(s.CodeAttendance)).ToList();
                lstProfileId = profiles.Select(s => s.Id).ToList();
            }
            var orgTypes = new List <Cat_OrgStructureType>();

            using (var context = new VnrHrmDataContext())
            {
                var unitOfWork = (IUnitOfWork)(new UnitOfWork(context));
                var repo       = new Cat_OrgStructureTypeRepository(unitOfWork);
                orgTypes = repo.FindBy(s => s.IsDelete == null).ToList <Cat_OrgStructureType>();
            }
            Can_ReportMealTimeDetailEntity        reportMealTimeDetailEntity    = null;
            List <Can_ReportMealTimeDetailEntity> lstreportMealTimeDetailEntity = new List <Can_ReportMealTimeDetailEntity>();

            foreach (var mealRecord in mealRecords)
            {
                var profile = profiles.FirstOrDefault(s => s.CodeAttendance == mealRecord.CardCode);
                if (profile != null)
                {
                    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);
                    reportMealTimeDetailEntity.BranchCode  = orgBranch != null ? orgBranch.Code : string.Empty;
                    reportMealTimeDetailEntity.OrgCode     = orgOrg != null ? orgOrg.Code : string.Empty;
                    reportMealTimeDetailEntity.TeamCode    = orgTeam != null ? orgTeam.Code : string.Empty;
                    reportMealTimeDetailEntity.SectionCode = orgSection != null ? orgSection.Code : string.Empty;
                    reportMealTimeDetailEntity.BranchName  = orgBranch != null ? orgBranch.OrgStructureName : string.Empty;
                    reportMealTimeDetailEntity.OrgName     = orgOrg != null ? orgOrg.OrgStructureName : string.Empty;
                    reportMealTimeDetailEntity.TeamName    = orgTeam != null ? orgTeam.OrgStructureName : string.Empty;
                    reportMealTimeDetailEntity.SectionName = orgSection != null ? orgSection.OrgStructureName : string.Empty;
                    reportMealTimeDetailEntity.CodeEmp     = profile.CodeEmp;
                    reportMealTimeDetailEntity.ProfileName = profile.ProfileName;
                    reportMealTimeDetailEntity.Date        = mealRecord.TimeLog;
                }
                lstreportMealTimeDetailEntity.Add(reportMealTimeDetailEntity);
            }
            return(lstreportMealTimeDetailEntity);
        }
        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();
            }
        }