123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Linq.Expressions;
- using Bowin.Common.Linq;
- using Bowin.Common.Linq.Entity;
- using EMIS.ViewModel.PaymentManage;
- using EMIS.ViewModel;
- using EMIS.DataLogic.PaymentManage;
- using EMIS.Entities;
- using EMIS.Utility;
- namespace EMIS.CommonLogic.PaymentManage
- {
- public class PaymentServices : BaseServices, IPaymentServices
- {
- public PaymentDAL PaymentDAL { get; set; }
- public TeacherTypePaymentFormulaDAL TeacherTypePaymentFormulaDAL { get; set; }
- public IGridResultSet<PaymentDetailView> GetPaymentDetailViewList(ConfiguretView paymentConditionView, Guid? schoolyearID, Guid? collegeID, int? titleID, int pageIndex, int pageSize)
- {
- Expression<Func<CF_Staff, bool>> staffExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EM_Coursematerial, bool>> coursematerialExp = (x => true);
- Expression<Func<EM_EducationMission, bool>> missionExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- missionExp = missionExp.And(x => x.CollegeID == collegeID);
- }
- if (titleID.HasValue)
- {
- staffExp = staffExp.And(x => x.TitleID == titleID);
- }
- var query = PaymentDAL.GetPaymentDetailViewQueryable(staffExp, schoolyearExp, missionExp, coursematerialExp);
- if (!string.IsNullOrEmpty(paymentConditionView.ConditionValue) && !string.IsNullOrEmpty(paymentConditionView.Attribute))
- query = query.DynamicWhere(paymentConditionView.Attribute, paymentConditionView.Condition, paymentConditionView.ConditionValue);
- query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName);
- var result = query.ToGridResultSet<PaymentDetailView>(pageIndex, pageSize);
- result.rows = this.CalculatePaymentDetailView(result.rows);
- return result;
- }
- public List<PaymentDetailView> GetPaymentDetailViewList(ConfiguretView paymentConditionView, Guid? schoolyearID, Guid? collegeID, int? titleID)
- {
- Expression<Func<CF_Staff, bool>> staffExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EM_Coursematerial, bool>> coursematerialExp = (x => true);
- Expression<Func<EM_EducationMission, bool>> missionExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- missionExp = missionExp.And(x => x.CollegeID == collegeID);
- }
- if (titleID.HasValue)
- {
- staffExp = staffExp.And(x => x.TitleID == titleID);
- }
- var query = PaymentDAL.GetPaymentDetailViewQueryable(staffExp, schoolyearExp, missionExp, coursematerialExp);
- if (!string.IsNullOrEmpty(paymentConditionView.ConditionValue) && !string.IsNullOrEmpty(paymentConditionView.Attribute))
- query = query.DynamicWhere(paymentConditionView.Attribute, paymentConditionView.Condition, paymentConditionView.ConditionValue);
- query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName);
- var result = query.ToList();
- result = this.CalculatePaymentDetailView(result);
- return result;
- }
- public List<PaymentTotalView> GetPaymentTotalViewList(ConfiguretView paymentConditionView, Guid? schoolyearID, Guid? collegeID, int? titleID)
- {
- Expression<Func<CF_Staff, bool>> staffExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- Expression<Func<EM_Coursematerial, bool>> coursematerialExp = (x => true);
- Expression<Func<EM_EducationMission, bool>> missionExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
- if (schoolyearID.HasValue)
- {
- schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
- }
- if (collegeID.HasValue)
- {
- missionExp = missionExp.And(x => x.CollegeID == collegeID);
- }
- if (titleID.HasValue)
- {
- staffExp = staffExp.And(x => x.TitleID == titleID);
- }
- var query = PaymentDAL.GetPaymentDetailViewQueryable(staffExp, schoolyearExp, missionExp, coursematerialExp);
- if (!string.IsNullOrEmpty(paymentConditionView.ConditionValue) && !string.IsNullOrEmpty(paymentConditionView.Attribute))
- query = query.DynamicWhere(paymentConditionView.Attribute, paymentConditionView.Condition, paymentConditionView.ConditionValue);
- query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName);
- var detailList = query.ToList();
- detailList = this.CalculatePaymentDetailView(detailList);
- var totalList = detailList.GroupBy(x => new { x.CollegeID, x.CollegeNo, x.CollegeName, x.UserID, x.LoginID, x.UserName, x.Account })
- .Select(x => new PaymentTotalView
- {
- CollegeID = x.Key.CollegeID,
- CollegeNo = x.Key.CollegeNo,
- CollegeName = x.Key.CollegeName,
- Account = x.Key.Account,
- UserID = x.Key.UserID,
- LoginID = x.Key.LoginID,
- UserName = x.Key.UserName,
- TotalPayment = x.Sum(w => w.TotalPayment ?? 0)
- }).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName).ToList();
- return totalList;
- }
- private List<PaymentDetailView> CalculatePaymentDetailView(IList<PaymentDetailView> paymentDetailViewList)
- {
- var teacherTypePaymentFormularList = TeacherTypePaymentFormulaDAL.GetTeacherTypePaymentFormulaViewQueryable(x => true).ToList();
- foreach (var paymentDetailView in paymentDetailViewList)
- {
- var teacherTypePaymentFormular = teacherTypePaymentFormularList.FirstOrDefault(x => x.TeacherType == paymentDetailView.TeacherTypeID);
- if (teacherTypePaymentFormular != null)
- {
- ReflectorHelper.RunMethod(teacherTypePaymentFormular.StudentCountRateFormunla, paymentDetailView);
- ReflectorHelper.RunMethod(teacherTypePaymentFormular.PaymentFormula, paymentDetailView);
- }
- }
- return paymentDetailViewList.ToList();
- }
- public void GetNormalStudentCountRate(PaymentDetailView paymentDetailView)
- {
- if ((paymentDetailView.StudentCount - paymentDetailView.ExemptionCount) <= paymentDetailView.BaseStudentCount)
- {
- paymentDetailView.StudentCountRate = 1;
- }
- else
- {
- paymentDetailView.StudentCountRate = (decimal?)(paymentDetailView.StudentCount - paymentDetailView.ExemptionCount) / (decimal?)(paymentDetailView.BaseStudentCount ?? 1);
- }
- if (paymentDetailView.StudentCountRate > paymentDetailView.StudentCountRateLimit)
- {
- paymentDetailView.StudentCountRate = paymentDetailView.StudentCountRateLimit;
- }
- }
- public void GetNormalPayment(PaymentDetailView paymentDetailView)
- {
- paymentDetailView.HoursPayment = (paymentDetailView.PaymentStandard ?? 0) * (paymentDetailView.LearningformRate ?? 0) * (paymentDetailView.StudentCountRate ?? 0)
- * (paymentDetailView.ActualScheduleHours +
- (2 * ((paymentDetailView.ExaminationModeID == (int)CF_ExaminationMode.WrittenExam && paymentDetailView.LearningformID == (int)CF_Learningform.Correspondence) ? 1 : 0))
- );
- }
- public void GetOuterStudentCountRate(PaymentDetailView paymentDetailView)
- {
- paymentDetailView.StudentCountRate = 1 + ((paymentDetailView.StudentCount - paymentDetailView.ExemptionCount) - 50) / 100;
- if (paymentDetailView.StudentCountRate < 1)
- {
- paymentDetailView.StudentCountRate = 1;
- }
- }
- public void GetOuterPayment(PaymentDetailView paymentDetailView)
- {
- paymentDetailView.HoursPayment = (paymentDetailView.PaymentStandard ?? 0) * (paymentDetailView.StudentCountRate ?? 0) * (paymentDetailView.ActualScheduleHours +
- (2 * ((paymentDetailView.ExaminationModeID == (int)CF_ExaminationMode.WrittenExam && paymentDetailView.LearningformID == (int)CF_Learningform.Correspondence) ? 1 : 0))
- );
- }
- }
- }
|