PaymentServices.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Linq.Expressions;
  6. using Bowin.Common.Linq;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel.PaymentManage;
  9. using EMIS.ViewModel;
  10. using EMIS.DataLogic.PaymentManage;
  11. using EMIS.Entities;
  12. using EMIS.Utility;
  13. namespace EMIS.CommonLogic.PaymentManage
  14. {
  15. public class PaymentServices : BaseServices, IPaymentServices
  16. {
  17. public PaymentDAL PaymentDAL { get; set; }
  18. public TeacherTypePaymentFormulaDAL TeacherTypePaymentFormulaDAL { get; set; }
  19. public IGridResultSet<PaymentDetailView> GetPaymentDetailViewList(ConfiguretView paymentConditionView, Guid? schoolyearID, Guid? collegeID, int? titleID, int pageIndex, int pageSize)
  20. {
  21. Expression<Func<CF_Staff, bool>> staffExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  22. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  23. Expression<Func<EM_Coursematerial, bool>> coursematerialExp = (x => true);
  24. Expression<Func<EM_EducationMission, bool>> missionExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  25. if (schoolyearID.HasValue)
  26. {
  27. schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
  28. }
  29. if (collegeID.HasValue)
  30. {
  31. missionExp = missionExp.And(x => x.CollegeID == collegeID);
  32. }
  33. if (titleID.HasValue)
  34. {
  35. staffExp = staffExp.And(x => x.TitleID == titleID);
  36. }
  37. var query = PaymentDAL.GetPaymentDetailViewQueryable(staffExp, schoolyearExp, missionExp, coursematerialExp);
  38. if (!string.IsNullOrEmpty(paymentConditionView.ConditionValue) && !string.IsNullOrEmpty(paymentConditionView.Attribute))
  39. query = query.DynamicWhere(paymentConditionView.Attribute, paymentConditionView.Condition, paymentConditionView.ConditionValue);
  40. query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName);
  41. var result = query.ToGridResultSet<PaymentDetailView>(pageIndex, pageSize);
  42. result.rows = this.CalculatePaymentDetailView(result.rows);
  43. return result;
  44. }
  45. public List<PaymentDetailView> GetPaymentDetailViewList(ConfiguretView paymentConditionView, Guid? schoolyearID, Guid? collegeID, int? titleID)
  46. {
  47. Expression<Func<CF_Staff, bool>> staffExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  48. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  49. Expression<Func<EM_Coursematerial, bool>> coursematerialExp = (x => true);
  50. Expression<Func<EM_EducationMission, bool>> missionExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  51. if (schoolyearID.HasValue)
  52. {
  53. schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
  54. }
  55. if (collegeID.HasValue)
  56. {
  57. missionExp = missionExp.And(x => x.CollegeID == collegeID);
  58. }
  59. if (titleID.HasValue)
  60. {
  61. staffExp = staffExp.And(x => x.TitleID == titleID);
  62. }
  63. var query = PaymentDAL.GetPaymentDetailViewQueryable(staffExp, schoolyearExp, missionExp, coursematerialExp);
  64. if (!string.IsNullOrEmpty(paymentConditionView.ConditionValue) && !string.IsNullOrEmpty(paymentConditionView.Attribute))
  65. query = query.DynamicWhere(paymentConditionView.Attribute, paymentConditionView.Condition, paymentConditionView.ConditionValue);
  66. query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName);
  67. var result = query.ToList();
  68. result = this.CalculatePaymentDetailView(result);
  69. return result;
  70. }
  71. public List<PaymentTotalView> GetPaymentTotalViewList(ConfiguretView paymentConditionView, Guid? schoolyearID, Guid? collegeID, int? titleID)
  72. {
  73. Expression<Func<CF_Staff, bool>> staffExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  74. Expression<Func<EMIS.Entities.CF_Schoolyear, bool>> schoolyearExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  75. Expression<Func<EM_Coursematerial, bool>> coursematerialExp = (x => true);
  76. Expression<Func<EM_EducationMission, bool>> missionExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  77. if (schoolyearID.HasValue)
  78. {
  79. schoolyearExp = schoolyearExp.And(x => x.SchoolyearID == schoolyearID);
  80. }
  81. if (collegeID.HasValue)
  82. {
  83. missionExp = missionExp.And(x => x.CollegeID == collegeID);
  84. }
  85. if (titleID.HasValue)
  86. {
  87. staffExp = staffExp.And(x => x.TitleID == titleID);
  88. }
  89. var query = PaymentDAL.GetPaymentDetailViewQueryable(staffExp, schoolyearExp, missionExp, coursematerialExp);
  90. if (!string.IsNullOrEmpty(paymentConditionView.ConditionValue) && !string.IsNullOrEmpty(paymentConditionView.Attribute))
  91. query = query.DynamicWhere(paymentConditionView.Attribute, paymentConditionView.Condition, paymentConditionView.ConditionValue);
  92. query = query.OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName);
  93. var detailList = query.ToList();
  94. detailList = this.CalculatePaymentDetailView(detailList);
  95. var totalList = detailList.GroupBy(x => new { x.CollegeID, x.CollegeNo, x.CollegeName, x.UserID, x.LoginID, x.UserName, x.Account })
  96. .Select(x => new PaymentTotalView
  97. {
  98. CollegeID = x.Key.CollegeID,
  99. CollegeNo = x.Key.CollegeNo,
  100. CollegeName = x.Key.CollegeName,
  101. Account = x.Key.Account,
  102. UserID = x.Key.UserID,
  103. LoginID = x.Key.LoginID,
  104. UserName = x.Key.UserName,
  105. TotalPayment = x.Sum(w => w.TotalPayment ?? 0)
  106. }).OrderBy(x => x.CollegeNo.Length).ThenBy(x => x.CollegeNo).ThenBy(x => x.UserName).ToList();
  107. return totalList;
  108. }
  109. private List<PaymentDetailView> CalculatePaymentDetailView(IList<PaymentDetailView> paymentDetailViewList)
  110. {
  111. var teacherTypePaymentFormularList = TeacherTypePaymentFormulaDAL.GetTeacherTypePaymentFormulaViewQueryable(x => true).ToList();
  112. foreach (var paymentDetailView in paymentDetailViewList)
  113. {
  114. var teacherTypePaymentFormular = teacherTypePaymentFormularList.FirstOrDefault(x => x.TeacherType == paymentDetailView.TeacherTypeID);
  115. if (teacherTypePaymentFormular != null)
  116. {
  117. ReflectorHelper.RunMethod(teacherTypePaymentFormular.StudentCountRateFormunla, paymentDetailView);
  118. ReflectorHelper.RunMethod(teacherTypePaymentFormular.PaymentFormula, paymentDetailView);
  119. }
  120. }
  121. return paymentDetailViewList.ToList();
  122. }
  123. public void GetNormalStudentCountRate(PaymentDetailView paymentDetailView)
  124. {
  125. if ((paymentDetailView.StudentCount - paymentDetailView.ExemptionCount) <= paymentDetailView.BaseStudentCount)
  126. {
  127. paymentDetailView.StudentCountRate = 1;
  128. }
  129. else
  130. {
  131. paymentDetailView.StudentCountRate = (decimal?)(paymentDetailView.StudentCount - paymentDetailView.ExemptionCount) / (decimal?)(paymentDetailView.BaseStudentCount ?? 1);
  132. }
  133. if (paymentDetailView.StudentCountRate > paymentDetailView.StudentCountRateLimit)
  134. {
  135. paymentDetailView.StudentCountRate = paymentDetailView.StudentCountRateLimit;
  136. }
  137. }
  138. public void GetNormalPayment(PaymentDetailView paymentDetailView)
  139. {
  140. paymentDetailView.HoursPayment = (paymentDetailView.PaymentStandard ?? 0) * (paymentDetailView.LearningformRate ?? 0) * (paymentDetailView.StudentCountRate ?? 0)
  141. * (paymentDetailView.ActualScheduleHours +
  142. (2 * ((paymentDetailView.ExaminationModeID == (int)CF_ExaminationMode.WrittenExam && paymentDetailView.LearningformID == (int)CF_Learningform.Correspondence) ? 1 : 0))
  143. );
  144. }
  145. public void GetOuterStudentCountRate(PaymentDetailView paymentDetailView)
  146. {
  147. paymentDetailView.StudentCountRate = 1 + ((paymentDetailView.StudentCount - paymentDetailView.ExemptionCount) - 50) / 100;
  148. if (paymentDetailView.StudentCountRate < 1)
  149. {
  150. paymentDetailView.StudentCountRate = 1;
  151. }
  152. }
  153. public void GetOuterPayment(PaymentDetailView paymentDetailView)
  154. {
  155. paymentDetailView.HoursPayment = (paymentDetailView.PaymentStandard ?? 0) * (paymentDetailView.StudentCountRate ?? 0) * (paymentDetailView.ActualScheduleHours +
  156. (2 * ((paymentDetailView.ExaminationModeID == (int)CF_ExaminationMode.WrittenExam && paymentDetailView.LearningformID == (int)CF_Learningform.Correspondence) ? 1 : 0))
  157. );
  158. }
  159. }
  160. }