FeeDAL.cs 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using EMIS.DataLogic.Repositories;
  7. using EMIS.Entities;
  8. using EMIS.ViewModel.FeeManage;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.FeeManage
  11. {
  12. public class FeeDAL
  13. {
  14. public SchoolyearRepository SchoolyearRepository { get; set; }
  15. public ExaminationBatchRepository ExaminationBatchRepository { get; set; }
  16. public ExaminationBatchProjectRepository ExaminationBatchProjectRepository { get; set; }
  17. public ExaminationProjectRepository ExaminationProjectRepository { get; set; }
  18. public ExaminationTypeRepository ExaminationTypeRepository { get; set; }
  19. public ExaminationRegistrationRepository ExaminationRegistrationRepository { get; set; }
  20. public ExaminationRegistrationConfirmRepository ExaminationRegistrationConfirmRepository { get; set; }
  21. public ExaminationProjectFeeTypeRepository ExaminationProjectFeeTypeRepository { get; set; }
  22. public StudentRepository StudentRepository { get; set; }
  23. public StudentAccountRepository StudentAccountRepository { get; set; }
  24. public StudentContactRepository StudentContactRepository { get; set; }
  25. public CollegeRepository CollegeRepository { get; set; }
  26. public ClassmajorRepository ClassmajorRepository { get; set; }
  27. public GrademajorRepository GrademajorRepository { get; set; }
  28. public FacultymajorRepository FacultymajorRepository { get; set; }
  29. public UserRepository UserRepository { get; set; }
  30. public WechatPayListRepository WechatPayListRepository { get; set; }
  31. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  32. public IQueryable<StudentFeeView> GetStudentFeeViewQueryable(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  33. Expression<Func<EX_ExaminationType, bool>> typeExp, Expression<Func<EX_ExaminationProject, bool>> projectExp,
  34. Expression<Func<EX_ExaminationRegistration, bool>> registExp, Expression<Func<CF_College, bool>> collegeExp,
  35. Expression<Func<CF_Facultymajor, bool>> facultExp, Expression<Func<CF_Grademajor, bool>> grademajorExp, Expression<Func<CF_Classmajor, bool>> classmajorExp)
  36. {
  37. var query = (from batch in ExaminationBatchRepository.GetList(batchExp)
  38. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == batch.ExaminationBatchID)
  39. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  40. from type in ExaminationTypeRepository.Entities.Where(typeExp).Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  41. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  42. from regist in ExaminationRegistrationRepository.Entities.Where(registExp).Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID)
  43. from confirm in ExaminationRegistrationConfirmRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == regist.ExaminationRegistrationConfirmID)
  44. .DefaultIfEmpty()
  45. from feeType in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  46. from user in UserRepository.Entities.Where(x => x.UserID == regist.UserID)
  47. from student in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  48. from account in StudentAccountRepository.Entities.Where(x => x.UserID == student.UserID)
  49. from classmajor in ClassmajorRepository.Entities.Where(classmajorExp).Where(x => x.ClassmajorID == student.ClassmajorID)
  50. from grademajor in GrademajorRepository.Entities.Where(grademajorExp).Where(x => x.GrademajorID == classmajor.GrademajorID)
  51. from facultmajor in FacultymajorRepository.Entities.Where(facultExp).Where(x => x.FacultymajorID == grademajor.FacultymajorID)
  52. from college in CollegeRepository.Entities.Where(collegeExp).Where(x => x.CollegeID == facultmajor.CollegeID)
  53. from refundUser in UserRepository.Entities.Where(x => x.UserID == regist.RefundUserID)
  54. .DefaultIfEmpty()
  55. from refundConfirmUser in UserRepository.Entities.Where(x => x.UserID == regist.RefundConfirmUserID)
  56. .DefaultIfEmpty()
  57. from pay in WechatPayListRepository.Entities.Where(x => x.ExaminationRegistrationID == regist.ExaminationRegistrationID)
  58. .DefaultIfEmpty()
  59. select new StudentFeeView
  60. {
  61. ExaminationRegistrationID = regist.ExaminationRegistrationID,
  62. ExaminationBatchProjectID = batchProject.ExaminationBatchProjectID,
  63. ExaminationProjectID = project.ExaminationProjectID,
  64. ExaminationTypeName = project.EX_ExaminationType.Name,
  65. ExaminationRegistrationConfirmID = confirm.ExaminationRegistrationConfirmID,
  66. No = confirm.No,
  67. ReceiptNo = confirm.ReceiptNo,
  68. ExaminationProjectName = project.Name,
  69. ExaminationBatchName = batch.Name,
  70. SchoolyearID = schoolyear.SchoolyearID,
  71. SchoolyearCode = schoolyear.Code,
  72. ExaminationProjectFeeTypeID = feeType.ExaminationProjectFeeTypeID,
  73. FeeTypeID = feeType.FeeTypeID,
  74. UserID = student.UserID,
  75. CollegeID = college.CollegeID,
  76. ClassmajorID = classmajor.ClassmajorID,
  77. ClassmajorName = classmajor.Name,
  78. LoginID = user.LoginID,
  79. StudentNo = student.StudentCardNo,
  80. UserName = user.Name,
  81. Sex = student.Sex,
  82. CertificatesType = student.CertificatesType,
  83. IDNumber = student.IDNumber,
  84. PhoneNumber = student.CF_StudentContact.Mobile,
  85. Fee = regist.Fee,
  86. Remark = regist.Remark,
  87. RecordStatus = regist.RecordStatus,
  88. PayTime = regist.PayTime,
  89. BankName = (regist.BankName == null && regist.CardNo == null) ? account.BankName : regist.BankName,
  90. CardNo = (regist.BankName == null && regist.CardNo == null) ? account.CardNo : regist.CardNo,
  91. PayWay = regist.RecordStatus != (int)EX_ExaminationRegistrationStatus.ForPay ? (confirm.ExaminationRegistrationConfirmID != null ? (int)EX_PayWay.Offline : (int)EX_PayWay.Online) : (int?)null,
  92. SchoolAreaID = grademajor.SchoolAreaID,
  93. RefundUserID = regist.RefundUserID,
  94. RefundUserName = refundUser.Name,
  95. RefundTime = regist.RefundTime,
  96. RefundConfirmUserID = regist.RefundConfirmUserID,
  97. RefundConfirmUserName = refundConfirmUser.Name,
  98. RefundConfirmTime = regist.RefundConfirmTime,
  99. WechatOrderID = pay.WechatOrderID,
  100. RefundOrderID = pay.RefundOrderID
  101. }
  102. );
  103. return query;
  104. }
  105. public IQueryable<StudentFeeDetailView> GetStudentFeeDetailViewQueryable(Expression<Func<EX_ExaminationRegistrationConfirm, bool>> confirmExp)
  106. {
  107. var query = (from confirm in ExaminationRegistrationConfirmRepository.GetList(confirmExp)
  108. from regist in ExaminationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == confirm.ExaminationRegistrationConfirmID)
  109. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == regist.ExaminationBatchProjectID)
  110. from project in ExaminationProjectRepository.Entities.Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  111. from type in ExaminationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  112. from user in UserRepository.Entities.Where(x => x.UserID == regist.UserID)
  113. from student in StudentRepository.Entities.Where(x => x.UserID == user.UserID)
  114. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  115. from feetype in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  116. select new StudentFeeDetailView
  117. {
  118. ExaminationRegistrationID = regist.ExaminationRegistrationID,
  119. ExaminationTypeID = type.ExaminationTypeID,
  120. ExaminationTypeName = type.Name,
  121. ExaminationProjectID = project.ExaminationProjectID,
  122. ExaminationProjectName = project.Name,
  123. UserID = user.UserID,
  124. ClassmajorID = student.ClassmajorID,
  125. ClassmajorName = classmajor.Name,
  126. LoginID = user.LoginID,
  127. UserName = user.Name,
  128. Sex = student.Sex,
  129. IDNumber = student.IDNumber,
  130. FeeTypeID = feetype.FeeTypeID,
  131. Fee = regist.Fee
  132. }
  133. );
  134. return query;
  135. }
  136. public IQueryable<PrintView> GetPrintViewQueryable(Expression<Func<EX_ExaminationRegistrationConfirm, bool>> exp)
  137. {
  138. var query = (
  139. from confirm in ExaminationRegistrationConfirmRepository.GetList(exp)
  140. from firstRegist in (from regist in ExaminationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == confirm.ExaminationRegistrationConfirmID)
  141. from user in UserRepository.Entities.Where(x => x.UserID == regist.UserID)
  142. from student in StudentRepository.Entities.Where(x => x.UserID == user.UserID)
  143. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  144. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == regist.ExaminationBatchProjectID)
  145. from project in ExaminationProjectRepository.Entities.Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  146. orderby user.LoginID
  147. select new { ClassmajorName = classmajor.Name, ExaminationProjectName = project.Name, user.LoginID }).Take(1)
  148. from total in (from regist in ExaminationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == confirm.ExaminationRegistrationConfirmID)
  149. group regist by regist.ExaminationRegistrationConfirmID into g
  150. select g.Sum(x => x.Fee))
  151. select new PrintView
  152. {
  153. ReceiptNo = "收据号:" + confirm.ReceiptNo,
  154. Classmajor = firstRegist.ClassmajorName + "&nbsp;" + firstRegist.ExaminationProjectName,
  155. Total = total
  156. });
  157. return query;
  158. }
  159. public IQueryable<PrintGDCXView> GetPrintGDCXViewQueryable(Expression<Func<EX_ExaminationRegistrationConfirm, bool>> exp)
  160. {
  161. var query = from confirm in ExaminationRegistrationConfirmRepository.GetList(exp)
  162. from regist in ExaminationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == confirm.ExaminationRegistrationConfirmID)
  163. from stu in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  164. from cla in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == stu.ClassmajorID)
  165. from gra in GrademajorRepository.Entities.Where(x => x.GrademajorID == cla.GrademajorID)
  166. from fac in FacultymajorRepository.Entities.Where(x => x.FacultymajorID == gra.FacultymajorID)
  167. from col in CollegeRepository.Entities.Where(x => x.CollegeID == fac.CollegeID)
  168. group regist by new { confirm.No, confirm.ReceiptNo, col.CollegeID, collegeName = col.Name, cla.ClassmajorID, ClassName = cla.Name }
  169. into gregist
  170. select new PrintGDCXView
  171. {
  172. ReceiptNo = gregist.Key.ReceiptNo,
  173. ConfirmNo = gregist.Key.No,
  174. College = gregist.Key.collegeName,
  175. Classmajor = gregist.Key.ClassName,
  176. Total = gregist.Sum(x => x.Fee),
  177. };
  178. return query;
  179. }
  180. public IQueryable<PrintProjectView> GetPrintProjectViewQueryable(Expression<Func<EX_ExaminationRegistrationConfirm, bool>> exp)
  181. {
  182. var query = from confirm in ExaminationRegistrationConfirmRepository.GetList(exp)
  183. from regist in ExaminationRegistrationRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == confirm.ExaminationRegistrationConfirmID)
  184. from ebpr in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == regist.ExaminationBatchProjectID)
  185. from ebr in ExaminationProjectRepository.Entities.Where(x => x.ExaminationProjectID == ebpr.ExaminationProjectID)
  186. from epftp in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  187. from dic in DictionaryItemRepository.Entities.Where(x => x.Value == epftp.FeeTypeID && x.DictionaryCode == "EX_ExaminationProjectFeeType")
  188. from stu in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  189. group regist by new { ebr.ExaminationProjectID, ExaminationProjectName = ebr.Name, epftp.FeeTypeID, FeeTypeName = dic.Name }
  190. into gregist
  191. select new PrintProjectView
  192. {
  193. ExaminationProjectName = gregist.Key.ExaminationProjectName,
  194. ExaminationProjectFeeName = gregist.Key.FeeTypeName,
  195. StudentCount = gregist.Count(),
  196. Fee = gregist.Sum(x => x.Fee)
  197. };
  198. return query;
  199. }
  200. public IQueryable<RefundView> GetRefundViewQueryable(Expression<Func<EX_ExaminationRegistration, bool>> exp)
  201. {
  202. var query = (from regist in ExaminationRegistrationRepository.GetList(exp)
  203. from confirm in ExaminationRegistrationConfirmRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == regist.ExaminationRegistrationConfirmID).DefaultIfEmpty()
  204. from user in UserRepository.Entities.Where(x => x.UserID == regist.UserID)
  205. from student in StudentRepository.Entities.Where(x => x.UserID == user.UserID)
  206. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  207. from grademajor in GrademajorRepository.Entities.Where(x => x.GrademajorID == classmajor.GrademajorID)
  208. from facultmajor in FacultymajorRepository.Entities.Where(x => x.FacultymajorID == grademajor.FacultymajorID)
  209. from college in CollegeRepository.Entities.Where(x => x.CollegeID == facultmajor.CollegeID)
  210. from account in StudentAccountRepository.Entities.Where(x => x.UserID == student.UserID)
  211. from contact in StudentContactRepository.Entities.Where(x => x.UserID == student.UserID)
  212. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchProjectID == regist.ExaminationBatchProjectID)
  213. from batch in ExaminationBatchRepository.Entities.Where(x => x.ExaminationBatchID == batchProject.ExaminationBatchID)
  214. from project in ExaminationProjectRepository.Entities.Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  215. from feetype in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  216. from refundUser in UserRepository.Entities.Where(x => x.UserID == regist.RefundUserID)
  217. .DefaultIfEmpty()
  218. select new RefundView
  219. {
  220. ExaminationRegistrationID = regist.ExaminationRegistrationID,
  221. UserID = regist.UserID,
  222. UserName = user.Name,
  223. IDNumber = student.IDNumber,
  224. Mobile = contact.Mobile,
  225. Year = grademajor.SchoolyearID,
  226. CollegeID = college.CollegeID,
  227. CollegeName = college.Name,
  228. ClassmajorID = classmajor.ClassmajorID,
  229. ClassmajorName = classmajor.Name,
  230. ExaminationBatchID = batch.ExaminationBatchID,
  231. ExaminationBatchName = batch.Name,
  232. ExaminationProjectID = project.ExaminationProjectID,
  233. ExaminationProjectName = project.Name,
  234. FeeTypeID = feetype.FeeTypeID,
  235. Fee = regist.Fee,
  236. ReceiptNo = confirm.ReceiptNo,
  237. BankName = (regist.BankName == null && regist.CardNo == null) ? account.BankName : regist.BankName,
  238. CardNo = (regist.BankName == null && regist.CardNo == null) ? account.CardNo : regist.CardNo,
  239. RefundReason = regist.RefundReason,
  240. RefundUserID = regist.RefundUserID,
  241. RefundUserName = refundUser.Name,
  242. RefundTime = regist.RefundTime,
  243. ConfirmNo = confirm.No,
  244. SchoolYearID = batch.SchoolyearID,
  245. SchoolYearCode = batch.CF_Schoolyear.Code,
  246. StudentNo = student.StudentCardNo,
  247. RecordStatus = regist.RecordStatus
  248. }
  249. );
  250. return query;
  251. }
  252. public IQueryable<StudentFeeClassStatisticView> GetStudentFeeClassStatisticViewQueryable(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  253. Expression<Func<EX_ExaminationProject, bool>> projectExp, Expression<Func<CF_Facultymajor, bool>> facultExp,
  254. Expression<Func<CF_Grademajor, bool>> grademajorExp, Expression<Func<CF_Classmajor, bool>> classmajorExp)
  255. {
  256. var query = (from batch in ExaminationBatchRepository.GetList(batchExp)
  257. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == batch.ExaminationBatchID)
  258. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  259. from type in ExaminationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  260. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  261. from regist in ExaminationRegistrationRepository.Entities.Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID)
  262. from feeType in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  263. from student in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  264. from classmajor in ClassmajorRepository.Entities.Where(classmajorExp).Where(x => x.ClassmajorID == student.ClassmajorID)
  265. from grademajor in GrademajorRepository.Entities.Where(grademajorExp).Where(x => x.GrademajorID == classmajor.GrademajorID)
  266. from facultmajor in FacultymajorRepository.Entities.Where(facultExp).Where(x => x.FacultymajorID == grademajor.FacultymajorID)
  267. from college in CollegeRepository.Entities.Where(x => x.CollegeID == facultmajor.CollegeID)
  268. group regist by new
  269. {
  270. Year = grademajor.SchoolyearID,
  271. CollegeID = facultmajor.CollegeID,
  272. CollegeName = college.Name,
  273. ClassmajorID = classmajor.ClassmajorID,
  274. ClassmajorName = classmajor.Name,
  275. ExaminationTypeID = type.ExaminationTypeID,
  276. ExaminationTypeName = type.Name,
  277. ExaminationProjectID = project.ExaminationProjectID,
  278. ExaminationProjectName = project.Name,
  279. FeeTypeID = feeType.FeeTypeID
  280. } into g
  281. select new StudentFeeClassStatisticView
  282. {
  283. Year = g.Key.Year,
  284. CollegeID = g.Key.CollegeID,
  285. CollegeName = g.Key.CollegeName,
  286. ClassmajorID = g.Key.ClassmajorID,
  287. ClassmajorName = g.Key.ClassmajorName,
  288. ExaminationTypeID = g.Key.ExaminationTypeID,
  289. ExaminationTypeName = g.Key.ExaminationTypeName,
  290. ExaminationProjectID = g.Key.ExaminationProjectID,
  291. ExaminationProjectName = g.Key.ExaminationProjectName,
  292. FeeTypeID = g.Key.FeeTypeID,
  293. TotalRegistCount = g.Sum(x => 1),
  294. TotalRegistAmount = g.Sum(x => x.Fee),
  295. TotalPaidCount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid ? 1 : 0),
  296. TotalPaidAmount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid ? x.Fee : 0),
  297. TotalRefundCount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunded ? 1 : 0),
  298. TotalRefundAmount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunded ? x.Fee : 0),
  299. TotalRefundApplyCount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.RefundApply ? 1 : 0),
  300. TotalRefundApplyAmount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.RefundApply ? x.Fee : 0),
  301. TotalRefundingCount = g.Sum(x => (x.RecordStatus == (int)EX_ExaminationRegistrationStatus.OnRefund || x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunding) ? 1 : 0),
  302. TotalRefundingAmount = g.Sum(x => (x.RecordStatus == (int)EX_ExaminationRegistrationStatus.OnRefund || x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunding) ? x.Fee : 0),
  303. }
  304. );
  305. return query;
  306. }
  307. public IQueryable<StudentFeeProjectStatisticView> GetStudentFeeProjectStatisticViewQueryable(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  308. Expression<Func<EX_ExaminationProject, bool>> projectExp, Expression<Func<CF_Facultymajor, bool>> facultExp,
  309. Expression<Func<CF_Grademajor, bool>> grademajorExp, Expression<Func<CF_Classmajor, bool>> classmajorExp,
  310. Expression<Func<EX_ExaminationRegistration, bool>> registExp)
  311. {
  312. var query = (from batch in ExaminationBatchRepository.GetList(batchExp)
  313. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == batch.ExaminationBatchID)
  314. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  315. from type in ExaminationTypeRepository.Entities.Where(x => x.ExaminationTypeID == project.ExaminationTypeID)
  316. from schoolyear in SchoolyearRepository.Entities.Where(x => x.SchoolyearID == batch.SchoolyearID)
  317. from regist in ExaminationRegistrationRepository.Entities.Where(registExp).Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID)
  318. from feeType in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  319. from student in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  320. from classmajor in ClassmajorRepository.Entities.Where(classmajorExp).Where(x => x.ClassmajorID == student.ClassmajorID)
  321. from grademajor in GrademajorRepository.Entities.Where(grademajorExp).Where(x => x.GrademajorID == classmajor.GrademajorID)
  322. from facultmajor in FacultymajorRepository.Entities.Where(facultExp).Where(x => x.FacultymajorID == grademajor.FacultymajorID)
  323. from college in CollegeRepository.Entities.Where(x => x.CollegeID == facultmajor.CollegeID)
  324. group regist by new
  325. {
  326. ExaminationBatchID = batch.ExaminationBatchID,
  327. ExaminationBatchName = batch.Name,
  328. ExaminationTypeID = type.ExaminationTypeID,
  329. ExaminationTypeName = type.Name,
  330. ExaminationProjectID = project.ExaminationProjectID,
  331. ExaminationProjectName = project.Name,
  332. FeeTypeID = feeType.FeeTypeID
  333. } into g
  334. select new StudentFeeProjectStatisticView
  335. {
  336. ExaminationBatchID = g.Key.ExaminationBatchID,
  337. ExaminationBatchName = g.Key.ExaminationBatchName,
  338. ExaminationTypeID = g.Key.ExaminationTypeID,
  339. ExaminationTypeName = g.Key.ExaminationTypeName,
  340. ExaminationProjectID = g.Key.ExaminationProjectID,
  341. ExaminationProjectName = g.Key.ExaminationProjectName,
  342. FeeTypeID = g.Key.FeeTypeID,
  343. TotalRegistCount = g.Sum(x => 1),
  344. TotalRegistAmount = g.Sum(x => x.Fee),
  345. TotalPaidCount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid ? 1 : 0),
  346. TotalPaidAmount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid ? x.Fee : 0),
  347. TotalRefundCount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunded ? 1 : 0),
  348. TotalRefundAmount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunded ? x.Fee : 0),
  349. TotalRefundApplyCount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.RefundApply ? 1 : 0),
  350. TotalRefundApplyAmount = g.Sum(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.RefundApply ? x.Fee : 0),
  351. TotalRefundingCount = g.Sum(x => (x.RecordStatus == (int)EX_ExaminationRegistrationStatus.OnRefund || x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunding) ? 1 : 0),
  352. TotalRefundingAmount = g.Sum(x => (x.RecordStatus == (int)EX_ExaminationRegistrationStatus.OnRefund || x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Refunding) ? x.Fee : 0),
  353. }
  354. );
  355. return query;
  356. }
  357. public IQueryable<FinanceReportView> GetFinanceReportViewQueryable(Expression<Func<EX_ExaminationBatch, bool>> batchExp,
  358. Expression<Func<EX_ExaminationProject, bool>> projectExp,
  359. Expression<Func<EX_ExaminationRegistration, bool>> registExp)
  360. {
  361. var sql = (from batch in ExaminationBatchRepository.GetList(batchExp)
  362. from batchProject in ExaminationBatchProjectRepository.Entities.Where(x => x.ExaminationBatchID == batch.ExaminationBatchID)
  363. from project in ExaminationProjectRepository.Entities.Where(projectExp).Where(x => x.ExaminationProjectID == batchProject.ExaminationProjectID)
  364. from regist in ExaminationRegistrationRepository.Entities.Where(registExp).Where(x => x.ExaminationBatchProjectID == batchProject.ExaminationBatchProjectID)
  365. from feeType in ExaminationProjectFeeTypeRepository.Entities.Where(x => x.ExaminationProjectFeeTypeID == regist.ExaminationProjectFeeTypeID)
  366. from student in StudentRepository.Entities.Where(x => x.UserID == regist.UserID)
  367. from classmajor in ClassmajorRepository.Entities.Where(x => x.ClassmajorID == student.ClassmajorID)
  368. from confirm in ExaminationRegistrationConfirmRepository.Entities.Where(x => x.ExaminationRegistrationConfirmID == regist.ExaminationRegistrationConfirmID)
  369. .DefaultIfEmpty()
  370. from receiver in UserRepository.Entities.Where(x => x.UserID == confirm.Receiver)
  371. .DefaultIfEmpty()
  372. group regist by new
  373. {
  374. confirm.ReceiptNo,
  375. regist.PayTime,
  376. classmajor.ClassmajorID,
  377. ClassmajorName = classmajor.Name,
  378. ExaminationRegistrationConfirmNo = confirm.No,
  379. project.ExaminationProjectID,
  380. ExaminationProjectName = project.Name,
  381. feeType.FeeTypeID,
  382. regist.Fee,
  383. confirm.Receiver,
  384. ReceiverName = receiver.Name
  385. } into g
  386. select new FinanceReportView
  387. {
  388. ReceiptNo = g.Key.ReceiptNo,
  389. PayTime = g.Key.PayTime,
  390. ClassmajorID = g.Key.ClassmajorID,
  391. ClassmajorName = g.Key.ClassmajorName,
  392. ExaminationRegistrationConfirmNo = g.Key.ExaminationRegistrationConfirmNo,
  393. ExaminationProjectID = g.Key.ExaminationProjectID,
  394. ExaminationProjectName = g.Key.ExaminationProjectName,
  395. FeeTypeID = g.Key.FeeTypeID,
  396. Fee = g.Key.Fee,
  397. StudentCount = g.Sum(x => 1),
  398. Amount = g.Sum(x => (x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid ? x.Fee : 0)),
  399. Receiver = g.Key.Receiver,
  400. ReceiverName = g.Key.ReceiverName,
  401. PayTimeOrder = g.Key.PayTime.HasValue ? "" : g.Key.PayTime.ToString().Substring(0, 10)
  402. }
  403. );
  404. return sql;
  405. }
  406. }
  407. }