public static IQueryable <UserProfile> PromptLearnerByAdvisor <TEntity>(this ServingCoach coach, ModelSource <TEntity> models) where TEntity : class, new() { IQueryable <UserProfile> items = models.PromptLearner(); return(items.FilterLearnerByAdvisor(coach, models)); }
public static IQueryable <UserProfile> PromptLearnerWithBirthday <TEntity>(this ServingCoach coach, ModelSource <TEntity> models, DateTime startDate, DateTime endDate) where TEntity : class, new() { IQueryable <UserProfile> items = coach.PromptLearnerByAdvisor(models); return(items.FilterLearnerWithBirthday(startDate, endDate)); }
public ActionResult ShowAttenderListByCoach(int coachID) { ServingCoach item = models.GetTable <ServingCoach>().Where(u => u.CoachID == coachID).FirstOrDefault(); if (item == null) { return(View("~/Views/Shared/JsAlert.cshtml", model: "資料錯誤!!")); } return(View("~/Views/CoachFacet/Module/ShowAttenderListByCoach.ascx", item)); }
protected void ValidateCommonBooking(LessonTimeViewModel viewModel, out ServingCoach coach, out BranchStore branch) { if (!viewModel.ClassDate.HasValue) { ModelState.AddModelError("ClassDate", "請選擇上課日期!!"); } else if (viewModel.ClassDate < DateTime.Today) { ModelState.AddModelError("ClassDate", "預約時間不可早於今天!!"); } branch = null; if (!viewModel.BranchID.HasValue) { ModelState.AddModelError("BranchID", "請選擇上課地點!!"); } else { branch = models.GetTable <BranchStore>().Where(b => b.BranchID == viewModel.BranchID).FirstOrDefault(); } coach = models.GetTable <ServingCoach>().Where(s => s.CoachID == viewModel.CoachID).FirstOrDefault(); if (coach == null) { ModelState.AddModelError("CoachID", "未指定體能顧問!!"); } viewModel.Place = viewModel.Place.GetEfficientString(); if (branch?.IsVirtualClassroom() == true) { if (!viewModel.Place.ValidateMeetingRoom(branch, models)) { ModelState.AddModelError("Place", "請輸入正確會議室連結!!"); } } }
public static IQueryable <UserProfile> PromptLearnerWithBirthdayThisWeek <TEntity>(this ServingCoach coach, ModelSource <TEntity> models) where TEntity : class, new() { DateTime start = DateTime.Today.FirstDayOfWeek(); return(coach.PromptLearnerWithBirthday(models, start, start.AddDays(7))); }
public static IQueryable <UserProfile> PromptLearnerWithBirthday <TEntity>(this ServingCoach coach, ModelSource <TEntity> models, int incomingDays = 14) where TEntity : class, new() { return(coach.PromptLearnerWithBirthday(models, DateTime.Today, DateTime.Today.AddDays(incomingDays))); }
public static IQueryable <UserProfile> FilterLearnerByAdvisor <TEntity>(this IQueryable <UserProfile> items, ServingCoach coach, ModelSource <TEntity> models) where TEntity : class, new() { if (coach != null) { items = items.Join(models.GetTable <LearnerFitnessAdvisor>().Where(a => a.CoachID == coach.CoachID), u => u.UID, a => a.UID, (u, a) => u); } else { return(items.Where(u => false)); } return(items); }
public static DataTable CreateLessonAchievementDetails <TEntity>(this ModelSource <TEntity> models, IQueryable <LessonTime> items) where TEntity : class, new() { DataTable table = new DataTable(); table.Columns.Add(new DataColumn("合約編號", typeof(String))); table.Columns.Add(new DataColumn("體能顧問", typeof(String))); table.Columns.Add(new DataColumn("簽約場所", typeof(String))); table.Columns.Add(new DataColumn("學員", typeof(String))); table.Columns.Add(new DataColumn("合約名稱", typeof(String))); table.Columns.Add(new DataColumn("課程單價", typeof(int))); table.Columns.Add(new DataColumn("全價計算堂數", typeof(int))); table.Columns.Add(new DataColumn("半價計算堂數", typeof(int))); table.Columns.Add(new DataColumn("上課地點", typeof(String))); table.Columns.Add(new DataColumn("累計上課金額", typeof(int))); table.Columns.Add(new DataColumn("是否信託", typeof(String))); table.Columns.Add(new DataColumn("課程代碼", typeof(int))); table.Columns.Add(new DataColumn("體能顧問所屬分店", typeof(String))); var details = items.Where(t => t.RegisterLesson.RegisterLessonContract != null) .GroupBy(t => new { t.AttendingCoach, t.RegisterLesson.RegisterLessonContract.ContractID, t.BranchID }); foreach (var item in details) { CourseContract contract = models.GetTable <CourseContract>().Where(u => u.ContractID == item.Key.ContractID).First(); ServingCoach coach = models.GetTable <ServingCoach>().Where(c => c.CoachID == item.Key.AttendingCoach).First(); var branch = models.GetTable <BranchStore>().Where(b => b.BranchID == item.Key.BranchID).First(); var r = table.NewRow(); r[0] = contract.ContractNo(); r[1] = coach.UserProfile.FullName(); r[2] = contract.CourseContractExtension.BranchStore.BranchName; if (contract.CourseContractType.IsGroup == true) { r[3] = String.Join("/", contract.CourseContractMember.Select(m => m.UserProfile).ToArray().Select(m => m.FullName())); } else { r[3] = contract.ContractOwner.FullName(); } r[4] = contract.CourseContractType.TypeName + " (" + contract.LessonPriceType.DurationInMinutes + " 分鐘)"; r[5] = contract.LessonPriceType.ListPrice; var count = item.Count(); var halfCount = item.Count(t => t.LessonAttendance == null || !t.LessonPlan.CommitAttendance.HasValue); r[6] = count - halfCount; r[7] = halfCount; r[8] = branch.BranchName; var discount = contract.CourseContractType.GroupingLessonDiscount; r[9] = item.Sum(l => l.RegisterLesson.LessonPriceType.ListPrice) * discount.GroupingMemberCount * discount.PercentageOfDiscount / 100; r[10] = contract.Entrusted == true ? "是" : contract.Entrusted == false ? "否" : ""; if (contract.LessonPriceType.Status.HasValue) { r[11] = contract.LessonPriceType.Status.Value; } r[12] = coach.WorkPlace(); table.Rows.Add(r); } var enterprise = items.Where(t => t.RegisterLesson.RegisterLessonEnterprise != null) .GroupBy(t => new { t.AttendingCoach, t.RegisterLesson.RegisterLessonEnterprise.ContractID, t.RegisterID, t.BranchID }); foreach (var item in enterprise) { EnterpriseCourseContract contract = models.GetTable <EnterpriseCourseContract>().Where(u => u.ContractID == item.Key.ContractID).First(); ServingCoach coach = models.GetTable <ServingCoach>().Where(c => c.CoachID == item.Key.AttendingCoach).First(); RegisterLesson lesson = models.GetTable <RegisterLesson>().Where(g => g.RegisterID == item.Key.RegisterID).First(); var branch = models.GetTable <BranchStore>().Where(b => b.BranchID == item.Key.BranchID).First(); var r = table.NewRow(); r[0] = contract.ContractNo; r[1] = coach.UserProfile.FullName(); r[2] = contract.BranchStore.BranchName; if (lesson.GroupingMemberCount > 1) { r[3] = String.Join("/", lesson.GroupingLesson.RegisterLesson.Select(s => s.UserProfile).ToArray().Select(m => m.FullName())); } else { r[3] = lesson.UserProfile.FullName(); } r[4] = contract.Subject; r[5] = contract.EnterpriseCourseContent.OrderByDescending(c => c.ListPrice).First().ListPrice; var count = item.Count(); var halfCount = item.Count(t => t.LessonAttendance == null || !t.LessonPlan.CommitAttendance.HasValue); r[6] = count - halfCount; r[7] = halfCount; r[8] = branch.BranchName; r[9] = count * lesson.RegisterLessonEnterprise.EnterpriseCourseContent.ListPrice * lesson.GroupingLessonDiscount.PercentageOfDiscount / 100; r[11] = (int)Naming.LessonPriceStatus.企業合作方案; r[12] = coach.WorkPlace(); table.Rows.Add(r); } var others = items.Where(t => t.RegisterLesson.RegisterLessonContract == null && t.RegisterLesson.RegisterLessonEnterprise == null); foreach (var item in others) { var coach = item.AsAttendingCoach; var r = table.NewRow(); r[0] = "--"; r[1] = coach.UserProfile.FullName(); if (item.BranchID.HasValue) { r[2] = item.BranchStore.BranchName; } r[3] = item.RegisterLesson.UserProfile.FullName(); r[4] = item.RegisterLesson.LessonPriceType.Description + " (" + item.RegisterLesson.LessonPriceType.DurationInMinutes + " 分鐘)"; r[9] = r[5] = item.RegisterLesson.LessonPriceType.ListPrice; var halfCount = item.LessonAttendance == null || item.LessonPlan.CommitAttendance.HasValue ? 1 : 0; r[6] = 1 - halfCount; r[7] = halfCount; if (item.BranchID.HasValue) { r[8] = item.BranchStore.BranchName; } if (item.RegisterLesson.LessonPriceType.Status.HasValue) { r[11] = item.RegisterLesson.LessonPriceType.Status.Value; } r[12] = coach.WorkPlace(); table.Rows.Add(r); } table.TableName = "上課統計表-人員明細"; return(table); }
public static BranchStore CurrentWorkBranch(this ServingCoach item) { return(item.CoachWorkplace.Count == 1 ? item.CoachWorkplace.First().BranchStore : null); }
public static IQueryable <UserProfile> FilterLearnerByAdvisor(this IQueryable <UserProfile> items, ServingCoach coach, GenericManager <BFDataContext> models) { if (coach != null) { items = items.Join(models.GetTable <LearnerFitnessAdvisor>().Where(a => a.CoachID == coach.CoachID), u => u.UID, a => a.UID, (u, a) => u); } else { return(items.Where(u => false)); } return(items); }
public static IQueryable <UserProfile> PromptLearnerByAdvisor(this ServingCoach coach, GenericManager <BFDataContext> models) { IQueryable <UserProfile> items = models.PromptLearner(); return(items.FilterLearnerByAdvisor(coach, models)); }
public static IQueryable <UserProfile> PromptLearnerWithBirthday(this ServingCoach coach, GenericManager <BFDataContext> models, DateTime startDate, DateTime endDate) { IQueryable <UserProfile> items = coach.PromptLearnerByAdvisor(models); return(items.FilterLearnerWithBirthday(startDate, endDate)); }
private ActionResult CommitRemoteTrialLesson(LessonTimeViewModel viewModel, BranchStore branch, ServingCoach coach) { RegisterLesson lesson; UserProfile profileItem = models.GetTable <UserProfile>().Where(u => u.UID == viewModel.UID).FirstOrDefault(); if (profileItem == null) { return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "體驗學員資料錯誤!!")); } var priceType = models.CurrentTrialLessonPrice(true, viewModel.PriceID); if (priceType == null) { return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml", model: "體驗課程類型錯誤!!")); } lesson = new RegisterLesson { UID = viewModel.UID.Value, RegisterDate = DateTime.Now, GroupingMemberCount = 1, Lessons = 1, ClassLevel = priceType.PriceID, IntuitionCharge = new IntuitionCharge { ByInstallments = 1, Payment = "Cash", FeeShared = 0 }, AdvisorID = viewModel.CoachID, BranchID = branch.BranchID, GroupingLesson = new GroupingLesson { } }; //var installment = new TuitionInstallment //{ // PayoffDate = viewModel.ClassDate, // PayoffAmount = priceType.ListPrice, // Payment = new Payment // { // PayoffAmount = priceType.ListPrice, // PayoffDate = viewModel.ClassDate // } //}; //installment.Payment.TuitionAchievement.Add(new TuitionAchievement //{ // CoachID = lesson.AdvisorID.Value, // ShareAmount = installment.PayoffAmount //}); //lesson.IntuitionCharge.TuitionInstallment.Add(installment); models.GetTable <RegisterLesson>().InsertOnSubmit(lesson); models.SubmitChanges(); LessonTime timeItem = new LessonTime { InvitedCoach = viewModel.CoachID, AttendingCoach = viewModel.CoachID, ClassTime = viewModel.ClassDate, DurationInMinutes = priceType.DurationInMinutes, TrainingBySelf = (int)Naming.LessonSelfTraining.體驗課程, RegisterID = lesson.RegisterID, LessonPlan = new LessonPlan { }, BranchID = branch.BranchID, LessonTimeSettlement = new LessonTimeSettlement { ProfessionalLevelID = coach.LevelID.Value, MarkedGradeIndex = coach.LevelID.HasValue ? coach.ProfessionalLevel.GradeIndex : null, CoachWorkPlace = coach.WorkBranchID(), } }; if (models.GetTable <DailyWorkingHour>().Any(d => d.Hour == viewModel.ClassDate.Value.Hour)) { timeItem.HourOfClassTime = viewModel.ClassDate.Value.Hour; } timeItem.GroupID = lesson.RegisterGroupID; timeItem.LessonFitnessAssessment.Add(new LessonFitnessAssessment { UID = lesson.UID }); models.GetTable <LessonTime>().InsertOnSubmit(timeItem); try { models.SubmitChanges(); timeItem.BookingLessonTimeExpansion(models, timeItem.ClassTime.Value, timeItem.DurationInMinutes.Value); } catch (Exception ex) { models.ExecuteCommand("delete RegisterLesson where RegisterID = {0}", lesson.RegisterID); Logger.Error(ex); ViewBag.Message = "預約未完成,請重新預約!!"; return(View("~/Views/ConsoleHome/Shared/JsAlert.cshtml")); } return(Json(new { result = true, message = "上課時間預約完成!!" })); }
public static String WorkPlace(this ServingCoach item) { return(item.CoachWorkplace.Count == 1 ? item.CoachWorkplace.First().BranchStore.BranchName : "其他"); }
public static IQueryable <UserProfile> PromptLearnerWithBirthday(this ServingCoach coach, GenericManager <BFDataContext> models, int incomingDays = 14) { return(coach.PromptLearnerWithBirthday(models, DateTime.Today, DateTime.Today.AddDays(incomingDays))); }
public static int?WorkBranchID(this ServingCoach item) { return(item.CoachWorkplace.Count == 1 ? (int?)item.CoachWorkplace.First().BranchID : (int?)null); }
public static IQueryable <UserProfile> PromptLearnerWithBirthdayThisWeek(this ServingCoach coach, GenericManager <BFDataContext> models) { DateTime start = DateTime.Today.FirstDayOfWeek(); return(coach.PromptLearnerWithBirthday(models, start, start.AddDays(7))); }
public static int?SelectWorkBranchID(this ServingCoach item) { return(item.CoachWorkplace.FirstOrDefault()?.BranchID); }
public static DataTable CreateLessonAchievementDetails <TEntity>(this ModelSource <TEntity> models, IQueryable <V_Tuition> items) where TEntity : class, new() { DataTable table = new DataTable(); table.Columns.Add(new DataColumn("合約編號", typeof(String))); table.Columns.Add(new DataColumn("上課體能顧問", typeof(String))); table.Columns.Add(new DataColumn("簽約場所", typeof(String))); table.Columns.Add(new DataColumn("學生", typeof(String))); table.Columns.Add(new DataColumn("合約名稱", typeof(String))); table.Columns.Add(new DataColumn("課程單價", typeof(int))); table.Columns.Add(new DataColumn("已完成上課", typeof(int))); table.Columns.Add(new DataColumn("學員打卡", typeof(int))); table.Columns.Add(new DataColumn("上課場所", typeof(String))); table.Columns.Add(new DataColumn("上課金額", typeof(int))); table.Columns.Add(new DataColumn("是否信託", typeof(String))); table.Columns.Add(new DataColumn("課程代碼", typeof(int))); table.Columns.Add(new DataColumn("體能顧問所屬分店", typeof(String))); table.Columns.Add(new DataColumn("預約上課數", typeof(int))); table.Columns.Add(new DataColumn("SettlementID", typeof(int))); table.Columns.Add(new DataColumn("簽約體能顧問", typeof(String))); var details = items.Where(t => t.ContractID.HasValue) .GroupBy(t => new { t.AttendingCoach, t.ContractID, t.BranchID, t.SettlementID, }); var branchItems = models.GetTable <BranchStore>().ToArray(); foreach (var item in details) { CourseContract contract = models.GetTable <CourseContract>().Where(u => u.ContractID == item.Key.ContractID).First(); ServingCoach coach = models.GetTable <ServingCoach>().Where(c => c.CoachID == item.Key.AttendingCoach).First(); var branch = branchItems.Where(b => b.BranchID == item.Key.BranchID).First(); var r = table.NewRow(); r[0] = contract.ContractNo(); r[1] = coach.UserProfile.FullName(); r[2] = contract.CourseContractExtension.BranchStore.BranchName; if (contract.CourseContractType.IsGroup == true) { r[3] = String.Join("/", contract.CourseContractMember.Select(m => m.UserProfile).ToArray().Select(m => m.FullName())); } else { r[3] = contract.ContractOwner.FullName(); } r[4] = contract.CourseContractType.TypeName + " (" + contract.LessonPriceType.DurationInMinutes + " 分鐘)"; r[5] = contract.LessonPriceType.ListPrice; r[6] = item.Where(l => l.CoachAttendance.HasValue).Count(); //item.Where(l => l.AchievementIndex == 1m).Count(); r[7] = item.Join(models.GetTable <Settlement>(), l => l.SettlementID, s => s.SettlementID, (l, s) => new { l.CommitAttendance, s.SettlementDate }) .Where(l => l.CommitAttendance <= l.SettlementDate).Count(); //item.Where(l => l.AchievementIndex == 0.5m).Count(); r[8] = branch.BranchName; r[9] = item.Sum(l => l.ListPrice * l.GroupingMemberCount * l.PercentageOfDiscount / 100); r[10] = contract.Entrusted == true ? "是" : contract.Entrusted == false ? "否" : ""; if (contract.LessonPriceType.Status.HasValue) { r[11] = contract.LessonPriceType.Status.Value; } var sample = item.First(); r[12] = branchItems.Where(b => b.BranchID == sample.CoachWorkPlace) .Select(b => b.BranchName).FirstOrDefault() ?? "其他"; r[13] = item.Count(); if (item.Key.SettlementID.HasValue) { r[14] = item.Key.SettlementID; } r[15] = contract.ServingCoach.UserProfile.FullName(); table.Rows.Add(r); } var enterprise = items.Where(t => t.EnterpriseContractID.HasValue) .GroupBy(t => new { t.AttendingCoach, ContractID = t.EnterpriseContractID, t.RegisterID, t.BranchID, t.SettlementID, }); foreach (var item in enterprise) { EnterpriseCourseContract contract = models.GetTable <EnterpriseCourseContract>().Where(u => u.ContractID == item.Key.ContractID).First(); ServingCoach coach = models.GetTable <ServingCoach>().Where(c => c.CoachID == item.Key.AttendingCoach).First(); RegisterLesson lesson = models.GetTable <RegisterLesson>().Where(g => g.RegisterID == item.Key.RegisterID).First(); var branch = models.GetTable <BranchStore>().Where(b => b.BranchID == item.Key.BranchID).First(); var r = table.NewRow(); r[0] = contract.ContractNo; r[1] = coach.UserProfile.FullName(); r[2] = contract.BranchStore.BranchName; if (lesson.GroupingMemberCount > 1) { r[3] = String.Join("/", lesson.GroupingLesson.RegisterLesson.Select(s => s.UserProfile).ToArray().Select(m => m.FullName())); } else { r[3] = lesson.UserProfile.FullName(); } r[4] = contract.Subject; r[5] = contract.EnterpriseCourseContent.OrderByDescending(c => c.ListPrice).First().ListPrice; r[6] = item.Where(l => l.CoachAttendance.HasValue).Count(); //item.Where(l => l.AchievementIndex == 1m).Count(); r[7] = item.Join(models.GetTable <Settlement>(), l => l.SettlementID, s => s.SettlementID, (l, s) => new { l.CommitAttendance, s.SettlementDate }) .Where(l => l.CommitAttendance <= l.SettlementDate).Count(); //item.Where(l => l.AchievementIndex == 0.5m).Count(); r[8] = branch.BranchName; r[9] = item.Sum(l => l.EnterpriseListPrice * l.GroupingMemberCount * l.PercentageOfDiscount / 100); r[11] = item.FirstOrDefault()?.ELStatus; //(int)Naming.LessonPriceStatus.企業合作方案; var sample = item.First(); r[12] = branchItems.Where(b => b.BranchID == sample.CoachWorkPlace) .Select(b => b.BranchName).FirstOrDefault() ?? "其他"; r[13] = item.Count(); if (item.Key.SettlementID.HasValue) { r[14] = item.Key.SettlementID; } table.Rows.Add(r); } var others = items.Where(t => !t.ContractID.HasValue && !t.EnterpriseRegisterID.HasValue); foreach (var item in others) { ServingCoach coach = models.GetTable <ServingCoach>().Where(c => c.CoachID == item.AttendingCoach).First(); var branch = models.GetTable <BranchStore>().Where(b => b.BranchID == item.BranchID).FirstOrDefault(); var lesson = models.GetTable <RegisterLesson>().Where(g => g.RegisterID == item.RegisterID).First(); var r = table.NewRow(); r[0] = "--"; r[1] = coach.UserProfile.FullName(); if (item.BranchID.HasValue) { r[2] = branch.BranchName; } r[3] = lesson.UserProfile.FullName(); r[4] = lesson.LessonPriceType.Description + " (" + lesson.LessonPriceType.DurationInMinutes + " 分鐘)"; r[9] = r[5] = item.ListPrice; r[6] = item.CoachAttendance.HasValue ? 1 : 0; //item.AchievementIndex == 1m ? 1 : 0; var settlement = models.GetTable <Settlement>().Where(s => s.SettlementID == item.SettlementID).FirstOrDefault(); r[7] = item.CommitAttendance.HasValue && item.CommitAttendance <= settlement?.SettlementDate ? 1 : 0; //item.AchievementIndex == 0.5m ? 1 : 0; if (branch != null) { r[8] = branch.BranchName; } r[11] = item.PriceStatus; r[12] = branchItems.Where(b => b.BranchID == item.CoachWorkPlace) .Select(b => b.BranchName).FirstOrDefault() ?? "其他"; r[13] = 1; if (item.SettlementID.HasValue) { r[14] = item.SettlementID; } table.Rows.Add(r); } table.TableName = "上課統計表-人員明細"; return(table); }