FeeServices.cs 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Linq.Expressions;
  5. using System.Text;
  6. using System.Transactions;
  7. using Bowin.Common.Linq;
  8. using Bowin.Common.Linq.Entity;
  9. using EMIS.CommonLogic.SystemServices;
  10. using EMIS.DataLogic.FeeManage;
  11. using EMIS.Entities;
  12. using EMIS.ViewModel;
  13. using EMIS.ViewModel.FeeManage;
  14. using MRMS.Utility;
  15. using EMIS.Utility.FormValidate;
  16. using EMIS.DataLogic.Repositories;
  17. namespace EMIS.CommonLogic.FeeManage
  18. {
  19. public class FeeServices : BaseServices, IFeeServices
  20. {
  21. public FeeDAL FeeDAL { get; set; }
  22. public InvalidReceiptDAL InvalidReceiptDAL { get; set; }
  23. public Lazy<IParameterServices> ParameterServices { get; set; }
  24. public ReceiptRepository ReceiptRepository { get; set; }
  25. public ReceiptView GetReceiptView()
  26. {
  27. ReceiptView receiptView = new ReceiptView();
  28. var userID = CustomPrincipal.Current.UserID;
  29. var receipt = ReceiptRepository.GetSingle(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  30. && x.UserID == userID);
  31. if (receipt != null)
  32. {
  33. receiptView.StartNo = receipt.ReceiptStartNo;
  34. receiptView.EndNo = receipt.ReceiptEndNo;
  35. }
  36. return receiptView;
  37. }
  38. public IGridResultSet<StudentFeeView> GetStudentFeeViewGrid(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID, Guid? examinationTypeID,
  39. Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? yearID, Guid? classmajorID, int? recordStatus, bool? isConfirm, DateTime? startDate, DateTime? endDate, int? payWay,
  40. DateTime? refundStartDate, DateTime? refundEndDate, int? pageIndex, int? pageSize)
  41. {
  42. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  43. Expression<Func<EX_ExaminationType, bool>> typeExp = (x => true);
  44. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  45. Expression<Func<EX_ExaminationRegistration, bool>> registExp = (x => true);
  46. Expression<Func<CF_College, bool>> collegeExp = (x => true);
  47. Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
  48. Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
  49. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  50. if (schoolyearID.HasValue)
  51. {
  52. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  53. }
  54. if (examinationBatchID.HasValue)
  55. {
  56. batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
  57. }
  58. if (examinationTypeID.HasValue)
  59. {
  60. typeExp = typeExp.And(x => x.ExaminationTypeID == examinationTypeID);
  61. }
  62. if (examinationProjectID.HasValue)
  63. {
  64. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  65. }
  66. if (schoolAreaID.HasValue)
  67. {
  68. grademajorExp = grademajorExp.And(x => x.SchoolAreaID == schoolAreaID);
  69. }
  70. if (collegeID.HasValue)
  71. {
  72. facultExp = facultExp.And(x => x.CollegeID == collegeID);
  73. }
  74. if (yearID.HasValue)
  75. {
  76. grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
  77. }
  78. if (classmajorID.HasValue)
  79. {
  80. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  81. }
  82. if (recordStatus.HasValue)
  83. {
  84. registExp = registExp.And(x => x.RecordStatus == recordStatus);
  85. }
  86. if (isConfirm.HasValue)
  87. {
  88. if (isConfirm.Value)
  89. {
  90. registExp = registExp.And(x => x.ExaminationRegistrationConfirmID != null);
  91. }
  92. else
  93. {
  94. registExp = registExp.And(x => x.ExaminationRegistrationConfirmID == null);
  95. }
  96. }
  97. if (startDate.HasValue)
  98. {
  99. registExp = registExp.And(x => x.PayTime >= startDate);
  100. }
  101. if (endDate.HasValue)
  102. {
  103. var correctEndDate = endDate.Value.Date.AddDays(1);
  104. registExp = registExp.And(x => x.PayTime < correctEndDate);
  105. }
  106. if (refundStartDate.HasValue)
  107. {
  108. registExp = registExp.And(x => x.RefundTime >= refundStartDate);
  109. }
  110. if (refundEndDate.HasValue)
  111. {
  112. var correctRefundEndDate = refundEndDate.Value.Date.AddDays(1);
  113. registExp = registExp.And(x => x.RefundTime < correctRefundEndDate);
  114. }
  115. var query = FeeDAL.GetStudentFeeViewQueryable(batchExp, typeExp, projectExp, registExp, collegeExp, facultExp, grademajorExp, classmajorExp);
  116. if(payWay.HasValue)
  117. {
  118. query = query.Where(x => x.PayWay == payWay);
  119. }
  120. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  121. {
  122. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  123. }
  124. var result = GetQueryByDataRangeByCollege(query);
  125. return result.OrderBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.FeeTypeID).ThenBy(x => x.UserName).ToGridResultSet<StudentFeeView>(pageIndex, pageSize);
  126. }
  127. public List<StudentFeeView> GetStudentFeeViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID, Guid? examinationTypeID,
  128. Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? yearID, Guid? classmajorID, int? recordStatus, bool? isConfirm, DateTime? startDate, DateTime? endDate, int? payWay,
  129. DateTime? refundStartDate, DateTime? refundEndDate, IList<Guid> examinationRegistrationIDList)
  130. {
  131. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  132. Expression<Func<EX_ExaminationType, bool>> typeExp = (x => true);
  133. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  134. Expression<Func<EX_ExaminationRegistration, bool>> registExp = (x => true);
  135. Expression<Func<CF_College, bool>> collegeExp = (x => true);
  136. Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
  137. Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
  138. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  139. if (schoolyearID.HasValue)
  140. {
  141. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  142. }
  143. if (examinationBatchID.HasValue)
  144. {
  145. batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
  146. }
  147. if (examinationTypeID.HasValue)
  148. {
  149. typeExp = typeExp.And(x => x.ExaminationTypeID == examinationTypeID);
  150. }
  151. if (examinationProjectID.HasValue)
  152. {
  153. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  154. }
  155. if (schoolAreaID.HasValue)
  156. {
  157. grademajorExp = grademajorExp.And(x => x.SchoolAreaID == schoolAreaID);
  158. }
  159. if (collegeID.HasValue)
  160. {
  161. facultExp = facultExp.And(x => x.CollegeID == collegeID);
  162. }
  163. if (yearID.HasValue)
  164. {
  165. grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
  166. }
  167. if (classmajorID.HasValue)
  168. {
  169. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  170. }
  171. if (recordStatus.HasValue)
  172. {
  173. registExp = registExp.And(x => x.RecordStatus == recordStatus);
  174. }
  175. if (isConfirm.HasValue)
  176. {
  177. if (isConfirm.Value)
  178. {
  179. registExp = registExp.And(x => x.ExaminationRegistrationConfirmID != null);
  180. }
  181. else
  182. {
  183. registExp = registExp.And(x => x.ExaminationRegistrationConfirmID == null);
  184. }
  185. }
  186. if (startDate.HasValue)
  187. {
  188. registExp = registExp.And(x => x.PayTime >= startDate);
  189. }
  190. if (endDate.HasValue)
  191. {
  192. var correctEndDate = endDate.Value.Date.AddDays(1);
  193. registExp = registExp.And(x => x.PayTime < correctEndDate);
  194. }
  195. if (refundStartDate.HasValue)
  196. {
  197. registExp = registExp.And(x => x.RefundTime >= refundStartDate);
  198. }
  199. if (refundEndDate.HasValue)
  200. {
  201. var correctRefundEndDate = refundEndDate.Value.Date.AddDays(1);
  202. registExp = registExp.And(x => x.RefundTime < correctRefundEndDate);
  203. }
  204. if (examinationRegistrationIDList.Count > 0)
  205. {
  206. registExp = registExp.And(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID));
  207. }
  208. var query = FeeDAL.GetStudentFeeViewQueryable(batchExp, typeExp, projectExp, registExp, collegeExp, facultExp, grademajorExp, classmajorExp);
  209. if (payWay.HasValue)
  210. {
  211. query = query.Where(x => x.PayWay == payWay);
  212. }
  213. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  214. {
  215. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  216. }
  217. var result = GetQueryByDataRangeByCollege(query);
  218. return result.OrderByDescending(x => x.SchoolyearCode).ThenBy(x => x.ExaminationBatchName)
  219. .ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.ClassmajorName).ThenBy(x => x.UserName)
  220. .ToList();
  221. }
  222. public decimal GetStudentFeeViewListSum(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID, Guid? examinationTypeID,
  223. Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? yearID, Guid? classmajorID, int? recordStatus, bool? isConfirm, DateTime? startDate, DateTime? endDate, int? payWay,
  224. DateTime? refundStartDate, DateTime? refundEndDate)
  225. {
  226. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  227. Expression<Func<EX_ExaminationType, bool>> typeExp = (x => true);
  228. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  229. Expression<Func<EX_ExaminationRegistration, bool>> registExp = (x => true);
  230. Expression<Func<CF_College, bool>> collegeExp = (x => true);
  231. Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
  232. Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
  233. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  234. if (schoolyearID.HasValue)
  235. {
  236. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  237. }
  238. if (examinationBatchID.HasValue)
  239. {
  240. batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
  241. }
  242. if (examinationTypeID.HasValue)
  243. {
  244. typeExp = typeExp.And(x => x.ExaminationTypeID == examinationTypeID);
  245. }
  246. if (examinationProjectID.HasValue)
  247. {
  248. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  249. }
  250. if (schoolAreaID.HasValue)
  251. {
  252. grademajorExp = grademajorExp.And(x => x.SchoolAreaID == schoolAreaID);
  253. }
  254. if (collegeID.HasValue)
  255. {
  256. facultExp = facultExp.And(x => x.CollegeID == collegeID);
  257. }
  258. if (yearID.HasValue)
  259. {
  260. grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
  261. }
  262. if (classmajorID.HasValue)
  263. {
  264. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  265. }
  266. if (recordStatus.HasValue)
  267. {
  268. registExp = registExp.And(x => x.RecordStatus == recordStatus);
  269. }
  270. if (isConfirm.HasValue)
  271. {
  272. if (isConfirm.Value)
  273. {
  274. registExp = registExp.And(x => x.ExaminationRegistrationConfirmID != null);
  275. }
  276. else
  277. {
  278. registExp = registExp.And(x => x.ExaminationRegistrationConfirmID == null);
  279. }
  280. }
  281. if (startDate.HasValue)
  282. {
  283. registExp = registExp.And(x => x.PayTime >= startDate);
  284. }
  285. if (endDate.HasValue)
  286. {
  287. var correctEndDate = endDate.Value.Date.AddDays(1);
  288. registExp = registExp.And(x => x.PayTime < correctEndDate);
  289. }
  290. if (refundStartDate.HasValue)
  291. {
  292. registExp = registExp.And(x => x.RefundTime >= refundStartDate);
  293. }
  294. if (refundEndDate.HasValue)
  295. {
  296. var correctRefundEndDate = refundEndDate.Value.Date.AddDays(1);
  297. registExp = registExp.And(x => x.RefundTime < correctRefundEndDate);
  298. }
  299. var query = FeeDAL.GetStudentFeeViewQueryable(batchExp, typeExp, projectExp, registExp, collegeExp, facultExp, grademajorExp, classmajorExp);
  300. if (payWay.HasValue)
  301. {
  302. query = query.Where(x => x.PayWay == payWay);
  303. }
  304. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  305. {
  306. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  307. }
  308. var result = GetQueryByDataRangeByCollege(query);
  309. return result.Sum(x => x.Fee) ?? 0;
  310. }
  311. public void SaveInvalidReceipt(string invalidReceiptNo)
  312. {
  313. var dupReceipt = InvalidReceiptDAL.InvalidReceiptRepository.GetSingle(x => x.ReceiptNo == invalidReceiptNo);
  314. if (dupReceipt != null)
  315. {
  316. throw new Exception("该收据已经作废,无需重复作废。");
  317. }
  318. var invalidReceipt = new EX_InvalidReceipt();
  319. invalidReceipt.InvalidReceiptID = Guid.NewGuid();
  320. invalidReceipt.ReceiptNo = invalidReceiptNo;
  321. this.SetNewStatus(invalidReceipt);
  322. this.UnitOfWork.Add(invalidReceipt);
  323. this.UnitOfWork.Commit();
  324. }
  325. public void SaveReceiptView(ReceiptView receiptView)
  326. {
  327. if (receiptView.StartNo.Length != receiptView.EndNo.Length)
  328. {
  329. throw new Exception("开始号码和结束号码长度不一致,请检查。");
  330. }
  331. var userID = CustomPrincipal.Current.UserID;
  332. var allReceiptList = this.ReceiptRepository.Entities.ToList();
  333. foreach (var oldReceipt in allReceiptList)
  334. {
  335. if (OperateSerialNo.CheckRangeContentedValue(oldReceipt.ReceiptStartNo, oldReceipt.ReceiptEndNo, receiptView.StartNo)
  336. || OperateSerialNo.CheckRangeContentedValue(oldReceipt.ReceiptStartNo, oldReceipt.ReceiptEndNo, receiptView.EndNo))
  337. {
  338. throw new Exception("收据号码全部或部分已经被使用,请重新输入。");
  339. }
  340. }
  341. this.UnloadReceipt();
  342. EX_Receipt receipt = new EX_Receipt();
  343. receipt.ReceiptID = Guid.NewGuid();
  344. receipt.UserID = userID;
  345. receipt.ReceiptStartNo = receiptView.StartNo;
  346. receipt.ReceiptEndNo = receiptView.EndNo;
  347. receipt.CurrentReceipNo = receiptView.StartNo;
  348. this.SetNewStatus(receipt);
  349. this.UnitOfWork.Update<EX_Receipt>(x => new EX_Receipt { RecordStatus = (int)SYS_STATUS.UNUSABLE }, x => x.UserID == userID);
  350. this.UnitOfWork.Add(receipt);
  351. this.UnitOfWork.Commit();
  352. //ParameterServices.Value.SaveTo(CF_ParameterType.ReceiptStartNo, receiptView.StartNo);
  353. //ParameterServices.Value.SaveTo(CF_ParameterType.ReceiptEndNo, receiptView.EndNo);
  354. //ParameterServices.Value.SaveTo(CF_ParameterType.CurrentReceiptNo, receiptView.StartNo);
  355. //this.UnitOfWork.Delete<EX_InvalidReceipt>(x => true);
  356. }
  357. public IGridResultSet<StudentFeeDetailView> GetStudentFeeDetailViewGrid(ConfiguretView conditionView, string examinationRegistConfirmNo, int? pageIndex, int? pageSize)
  358. {
  359. Expression<Func<EX_ExaminationRegistrationConfirm, bool>> confirmExp = (x => true);
  360. if (!string.IsNullOrEmpty(examinationRegistConfirmNo))
  361. {
  362. confirmExp = confirmExp.And(x => x.No == examinationRegistConfirmNo);
  363. }
  364. var query = FeeDAL.GetStudentFeeDetailViewQueryable(confirmExp);
  365. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  366. {
  367. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  368. }
  369. return query.OrderBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.FeeTypeID).ThenBy(x => x.UserName).ToGridResultSet(pageIndex, pageSize);
  370. }
  371. public decimal GetStudentFeeDetailTotal(ConfiguretView conditionView, string examinationRegistConfirmNo)
  372. {
  373. Expression<Func<EX_ExaminationRegistrationConfirm, bool>> confirmExp = (x => true);
  374. if (!string.IsNullOrEmpty(examinationRegistConfirmNo))
  375. {
  376. confirmExp = confirmExp.And(x => x.No == examinationRegistConfirmNo);
  377. }
  378. var query = FeeDAL.GetStudentFeeDetailViewQueryable(confirmExp);
  379. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  380. {
  381. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  382. }
  383. return query.Sum(x => x.Fee) ?? 0;
  384. }
  385. private string GetCurrentReceiptNo()
  386. {
  387. List<string> invalidReceiptNoList = InvalidReceiptDAL.GetInvalidReceipt().ToList();
  388. var userID = CustomPrincipal.Current.UserID;
  389. var receipt = ReceiptRepository.GetSingle(x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE
  390. && x.UserID == userID);
  391. if (receipt == null)
  392. {
  393. throw new Exception("未装载收据号,请先装载。");
  394. }
  395. string currentReceiptNo = receipt.CurrentReceipNo;
  396. string receiptStartNo = receipt.ReceiptStartNo;
  397. string receiptEndNo = receipt.ReceiptEndNo;
  398. while (invalidReceiptNoList.Contains(currentReceiptNo))
  399. {
  400. currentReceiptNo = OperateSerialNo.CardSerialNoAddNum(currentReceiptNo, 1);
  401. }
  402. string nextReceiptNo = OperateSerialNo.CardSerialNoAddNum(currentReceiptNo, 1);
  403. while (invalidReceiptNoList.Contains(nextReceiptNo))
  404. {
  405. nextReceiptNo = OperateSerialNo.CardSerialNoAddNum(nextReceiptNo, 1);
  406. }
  407. if (!OperateSerialNo.CheckRangeContentedValue(receiptStartNo, receiptEndNo, currentReceiptNo))
  408. {
  409. throw new Exception("收据号已经用完,请重新设置。");
  410. }
  411. receipt.CurrentReceipNo = nextReceiptNo;
  412. this.SetModifyStatus(receipt);
  413. this.UnitOfWork.Commit();
  414. return currentReceiptNo;
  415. }
  416. public string GetProductId()
  417. {
  418. DateTime today = DateTime.Today;
  419. string productId = ParameterServices.Value.GetParameterValue(CF_ParameterType.ReceiptNo);
  420. int seed = 1;
  421. if (productId != null)
  422. {
  423. if (productId.Substring(0, 8) == today.ToString("yyyyMMdd"))
  424. {
  425. seed = Convert.ToInt32(productId.Substring(8, productId.Length - 8)) + 1;
  426. }
  427. }
  428. productId = today.ToString("yyyyMMdd") + seed.ToString().PadLeft(3, '0');
  429. ParameterServices.Value.SaveTo(CF_ParameterType.ReceiptNo, productId);
  430. return productId;
  431. }
  432. public PrintView PrintSave(string examinationRegistConfirmNo)
  433. {
  434. var examinationRegistConfirm = this.FeeDAL.ExaminationRegistrationConfirmRepository.GetSingle(x => x.No == examinationRegistConfirmNo);
  435. if (examinationRegistConfirm == null)
  436. {
  437. throw new Exception("打印错误,无法找到该确认单号,请检查输入。");
  438. }
  439. string currentReceiptNo = this.GetCurrentReceiptNo();
  440. DateTime nowTime = DateTime.Now;
  441. examinationRegistConfirm.ReceiptNo = currentReceiptNo;
  442. this.SetModifyStatus(examinationRegistConfirm);
  443. examinationRegistConfirm.Receiver = examinationRegistConfirm.ModifyUserID;
  444. using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead }))
  445. {
  446. this.UnitOfWork.Commit();
  447. this.UnitOfWork.Update<EX_ExaminationRegistration>((x => new EX_ExaminationRegistration { PayTime = nowTime, RecordStatus = (int)EX_ExaminationRegistrationStatus.Paid }),
  448. (x => x.ExaminationRegistrationConfirmID == examinationRegistConfirm.ExaminationRegistrationConfirmID));
  449. scope.Complete();
  450. }
  451. var printView = FeeDAL.GetPrintViewQueryable(x => x.No == examinationRegistConfirmNo).FirstOrDefault();
  452. return printView;
  453. }
  454. public PrintGDCXView PrintSaveGDCX(string examinationRegistConfirmNo)
  455. {
  456. var userName = CustomPrincipal.Current.Name;
  457. var examinationRegistConfirm = this.FeeDAL.ExaminationRegistrationConfirmRepository.GetSingle(x => x.No == examinationRegistConfirmNo);
  458. if (examinationRegistConfirm == null)
  459. {
  460. throw new Exception("打印错误,无法找到该确认单号,请检查输入。");
  461. }
  462. string currentReceiptNo = this.GetProductId();
  463. DateTime nowTime = DateTime.Now;
  464. examinationRegistConfirm.ReceiptNo = currentReceiptNo;
  465. this.SetModifyStatus(examinationRegistConfirm);
  466. examinationRegistConfirm.Receiver = examinationRegistConfirm.ModifyUserID;
  467. using (var scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.RepeatableRead }))
  468. {
  469. this.UnitOfWork.Commit();
  470. this.UnitOfWork.Update<EX_ExaminationRegistration>((x => new EX_ExaminationRegistration { PayTime = nowTime, RecordStatus = (int)EX_ExaminationRegistrationStatus.Paid }),
  471. (x => x.ExaminationRegistrationConfirmID == examinationRegistConfirm.ExaminationRegistrationConfirmID));
  472. scope.Complete();
  473. }
  474. var printView = FeeDAL.GetPrintGDCXViewQueryable(x => x.No == examinationRegistConfirmNo).FirstOrDefault();
  475. var projectView = FeeDAL.GetPrintProjectViewQueryable(x => x.No == examinationRegistConfirmNo).ToList();
  476. printView.projectList = projectView;
  477. printView.Operator = userName;
  478. return printView;
  479. }
  480. public void RefundOffline(RefundView refundView)
  481. {
  482. var user = CustomPrincipal.Current;
  483. var regist = this.FeeDAL.ExaminationRegistrationRepository.GetSingle(x => x.ExaminationRegistrationID == refundView.ExaminationRegistrationID);
  484. regist.BankName = refundView.BankName;
  485. regist.CardNo = refundView.CardNo;
  486. regist.RefundReason = refundView.RefundReason;
  487. regist.RecordStatus = (int)EX_ExaminationRegistrationStatus.Refunding;
  488. regist.RefundUserID = user.UserID;
  489. regist.RefundTime = DateTime.Now;
  490. this.SetModifyStatus(regist);
  491. UnitOfWork.Commit();
  492. }
  493. public RefundView GetRefundView(Guid examinationRegistrationID)
  494. {
  495. var refundView = this.FeeDAL.GetRefundViewQueryable(x => x.ExaminationRegistrationID == examinationRegistrationID
  496. //&& x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid
  497. ).FirstOrDefault();
  498. return refundView;
  499. }
  500. public void RefundConfirm(Guid examinationRegistrationID)
  501. {
  502. var regist = this.FeeDAL.ExaminationRegistrationRepository
  503. .GetSingle(x => x.ExaminationRegistrationID == examinationRegistrationID);
  504. regist.RefundConfirmUserID = CustomPrincipal.Current.UserID;
  505. regist.RefundConfirmTime = DateTime.Now;
  506. regist.RecordStatus = (int)EX_ExaminationRegistrationStatus.Refunded;
  507. this.SetModifyStatus(regist);
  508. UnitOfWork.Commit();
  509. }
  510. private IQueryable<StudentFeeClassStatisticView> GetStudentFeeClassStatisticViewQueryable(ConfiguretView conditionView, Guid? schoolyearID,
  511. Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID, Guid? collegeID, int? yearID, int? standardID,
  512. Guid? classmajorID)
  513. {
  514. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  515. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  516. Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
  517. Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
  518. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  519. if (schoolyearID.HasValue)
  520. {
  521. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  522. }
  523. if (examinationBatchID.HasValue)
  524. {
  525. batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
  526. }
  527. if (examinationTypeID.HasValue)
  528. {
  529. projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID);
  530. }
  531. if (examinationProjectID.HasValue)
  532. {
  533. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  534. }
  535. if (collegeID.HasValue)
  536. {
  537. facultExp = facultExp.And(x => x.CollegeID == collegeID);
  538. }
  539. if (yearID.HasValue)
  540. {
  541. grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
  542. }
  543. if (standardID.HasValue)
  544. {
  545. facultExp = facultExp.And(x => x.StandardID == standardID);
  546. }
  547. if (classmajorID.HasValue)
  548. {
  549. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  550. }
  551. var query = FeeDAL.GetStudentFeeClassStatisticViewQueryable(batchExp, projectExp, facultExp, grademajorExp, classmajorExp);
  552. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  553. {
  554. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  555. }
  556. var result = query;
  557. //GetQueryByDataRangeByCollege(query);
  558. return result;
  559. }
  560. private IQueryable<StudentFeeProjectStatisticView> GetStudentFeeProjectStatisticViewQueryable(ConfiguretView conditionView, Guid? schoolyearID,
  561. Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID,int? schoolAreaID, Guid? collegeID, int? yearID, int? standardID,
  562. Guid? classmajorID,DateTime? startdate, DateTime? enddate)
  563. {
  564. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => true);
  565. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  566. Expression<Func<CF_Facultymajor, bool>> facultExp = (x => true);
  567. Expression<Func<CF_Grademajor, bool>> grademajorExp = (x => true);
  568. Expression<Func<CF_Classmajor, bool>> classmajorExp = (x => true);
  569. Expression<Func<EX_ExaminationRegistration, bool>> registExp = (x => true);
  570. if (schoolyearID.HasValue)
  571. {
  572. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  573. }
  574. if (examinationBatchID.HasValue)
  575. {
  576. batchExp = batchExp.And(x => x.ExaminationBatchID == examinationBatchID);
  577. }
  578. if (examinationTypeID.HasValue)
  579. {
  580. projectExp = projectExp.And(x => x.ExaminationTypeID == examinationTypeID);
  581. }
  582. if (examinationProjectID.HasValue)
  583. {
  584. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  585. }
  586. if (schoolAreaID.HasValue)
  587. {
  588. grademajorExp = grademajorExp.And(x => x.SchoolAreaID == schoolAreaID);
  589. }
  590. if (collegeID.HasValue)
  591. {
  592. facultExp = facultExp.And(x => x.CollegeID == collegeID);
  593. }
  594. if (yearID.HasValue)
  595. {
  596. grademajorExp = grademajorExp.And(x => x.SchoolyearID == yearID);
  597. }
  598. if (standardID.HasValue)
  599. {
  600. facultExp = facultExp.And(x => x.StandardID == standardID);
  601. }
  602. if (classmajorID.HasValue)
  603. {
  604. classmajorExp = classmajorExp.And(x => x.ClassmajorID == classmajorID);
  605. }
  606. if (startdate.HasValue)
  607. {
  608. registExp = registExp.And(x => x.PayTime > startdate);
  609. }
  610. if (enddate.HasValue)
  611. {
  612. var correctEndDate = enddate.Value.Date.AddDays(1);
  613. registExp = registExp.And(x => x.PayTime < correctEndDate);
  614. }
  615. var query = FeeDAL.GetStudentFeeProjectStatisticViewQueryable(batchExp, projectExp, facultExp, grademajorExp, classmajorExp, registExp);
  616. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  617. {
  618. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  619. }
  620. return query;
  621. }
  622. public IGridResultSet<StudentFeeClassStatisticView> GetStudentFeeClassStatisticViewGrid(ConfiguretView conditionView, Guid? schoolyearID,
  623. Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID, Guid? collegeID, int? yearID, int? standardID,
  624. Guid? classmajorID, int? pageIndex, int? pageSize)
  625. {
  626. var result = this.GetStudentFeeClassStatisticViewQueryable(conditionView, schoolyearID, examinationBatchID,
  627. examinationTypeID, examinationProjectID, collegeID, yearID, standardID, classmajorID);
  628. return result.OrderByDescending(x => x.CollegeName).ThenBy(x => x.ClassmajorName)
  629. .ThenBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.FeeTypeID)
  630. .ToGridResultSet(pageIndex, pageSize);
  631. }
  632. public List<StudentFeeClassStatisticView> GetStudentFeeClassStatisticViewList(ConfiguretView conditionView, Guid? schoolyearID,
  633. Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID)
  634. {
  635. var result = this.GetStudentFeeClassStatisticViewQueryable(conditionView, schoolyearID, examinationBatchID,
  636. examinationTypeID, examinationProjectID, collegeID, yearID, standardID, classmajorID);
  637. return result.OrderByDescending(x => x.CollegeName).ThenBy(x => x.ClassmajorName)
  638. .ThenBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.FeeTypeID)
  639. .ToList();
  640. }
  641. public StudentFeeStatisticTotalView GetStudentFeeClassStatisticViewTotal(ConfiguretView conditionView, Guid? schoolyearID,
  642. Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID)
  643. {
  644. var queryable = this.GetStudentFeeClassStatisticViewQueryable(conditionView, schoolyearID, examinationBatchID,
  645. examinationTypeID, examinationProjectID, collegeID, yearID, standardID, classmajorID);
  646. var resultQueryable = (from statistic in queryable
  647. select new StudentFeeStatisticTotalView
  648. {
  649. TotalRegistCount = queryable.Sum(x => x.TotalRegistCount),
  650. TotalRegistAmount = queryable.Sum(x => x.TotalRegistAmount),
  651. TotalPaidCount = queryable.Sum(x => x.TotalPaidCount),
  652. TotalPaidAmount = queryable.Sum(x => x.TotalPaidAmount),
  653. TotalRefundCount = queryable.Sum(x => x.TotalRefundCount),
  654. TotalRefundAmount = queryable.Sum(x => x.TotalRefundAmount),
  655. TotalRefundApplyCount = queryable.Sum(x => x.TotalRefundApplyCount),
  656. TotalRefundApplyAmount = queryable.Sum(x => x.TotalRefundApplyAmount),
  657. TotalRefundingCount = queryable.Sum(x => x.TotalRefundingCount),
  658. TotalRefundingAmount = queryable.Sum(x => x.TotalRefundingAmount)
  659. });
  660. return resultQueryable.First();
  661. }
  662. public IGridResultSet<StudentFeeProjectStatisticView> GetStudentFeeProjectStatisticViewGrid(ConfiguretView conditionView, Guid? schoolyearID,
  663. Guid? examinationBatchID, Guid? examinationTypeID, Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, DateTime? startdate, DateTime? enddate,
  664. int? pageIndex, int? pageSize)
  665. {
  666. var result = this.GetStudentFeeProjectStatisticViewQueryable(conditionView, schoolyearID, examinationBatchID,
  667. examinationTypeID, examinationProjectID, schoolAreaID, collegeID, yearID, standardID, classmajorID, startdate, enddate);
  668. return result.OrderByDescending(x => x.ExaminationBatchName)
  669. .ThenBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.FeeTypeID)
  670. .ToGridResultSet(pageIndex, pageSize);
  671. }
  672. public List<StudentFeeProjectStatisticView> GetStudentFeeProjectStatisticViewList(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID,
  673. Guid? examinationTypeID, Guid? examinationProjectID,int? schoolAreaID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, DateTime? startdate, DateTime? enddate)
  674. {
  675. var result = this.GetStudentFeeProjectStatisticViewQueryable(conditionView, schoolyearID, examinationBatchID,
  676. examinationTypeID, examinationProjectID, schoolAreaID, collegeID, yearID, standardID, classmajorID, startdate, enddate);
  677. return result.OrderByDescending(x => x.ExaminationBatchName)
  678. .ThenBy(x => x.ExaminationTypeName).ThenBy(x => x.ExaminationProjectName).ThenBy(x => x.FeeTypeID)
  679. .ToList();
  680. }
  681. public StudentFeeStatisticTotalView GetStudentFeeProjectStatisticViewTotal(ConfiguretView conditionView, Guid? schoolyearID, Guid? examinationBatchID,
  682. Guid? examinationTypeID, Guid? examinationProjectID, int? schoolAreaID, Guid? collegeID, int? yearID, int? standardID, Guid? classmajorID, DateTime? startdate, DateTime? enddate)
  683. {
  684. var queryable = this.GetStudentFeeProjectStatisticViewQueryable(conditionView, schoolyearID, examinationBatchID,
  685. examinationTypeID, examinationProjectID, schoolAreaID, collegeID, yearID, standardID, classmajorID, startdate, enddate);
  686. var resultQueryable = (from statistic in queryable
  687. select new StudentFeeStatisticTotalView
  688. {
  689. TotalRegistCount = queryable.Sum(x => x.TotalRegistCount),
  690. TotalRegistAmount = queryable.Sum(x => x.TotalRegistAmount),
  691. TotalPaidCount = queryable.Sum(x => x.TotalPaidCount),
  692. TotalPaidAmount = queryable.Sum(x => x.TotalPaidAmount),
  693. TotalRefundCount = queryable.Sum(x => x.TotalRefundCount),
  694. TotalRefundAmount = queryable.Sum(x => x.TotalRefundAmount),
  695. TotalRefundApplyCount = queryable.Sum(x => x.TotalRefundApplyCount),
  696. TotalRefundApplyAmount = queryable.Sum(x => x.TotalRefundApplyAmount),
  697. TotalRefundingCount = queryable.Sum(x => x.TotalRefundingCount),
  698. TotalRefundingAmount = queryable.Sum(x => x.TotalRefundingAmount)
  699. });
  700. return resultQueryable.First();
  701. }
  702. private IQueryable<FinanceReportView> GetFinanceReportViewQueryabled(ConfiguretView conditionView, Guid? schoolyearID, DateTime? payTimeStart, DateTime? payTimeEnd,
  703. Guid? examinationProjectID, Guid? receiverID)
  704. {
  705. Expression<Func<EX_ExaminationBatch, bool>> batchExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  706. Expression<Func<EX_ExaminationProject, bool>> projectExp = (x => true);
  707. Expression<Func<EX_ExaminationRegistration, bool>> registExp = (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  708. if (schoolyearID.HasValue)
  709. {
  710. batchExp = batchExp.And(x => x.SchoolyearID == schoolyearID);
  711. }
  712. if (payTimeStart.HasValue)
  713. {
  714. registExp = registExp.And(x => x.PayTime >= payTimeStart);
  715. }
  716. if (payTimeEnd.HasValue)
  717. {
  718. var correctPayTimeEnd = payTimeEnd.Value.Date.AddDays(1);
  719. registExp = registExp.And(x => x.PayTime < correctPayTimeEnd);
  720. }
  721. if (examinationProjectID.HasValue)
  722. {
  723. projectExp = projectExp.And(x => x.ExaminationProjectID == examinationProjectID);
  724. }
  725. if (receiverID.HasValue)
  726. {
  727. registExp = registExp.And(x => x.EX_ExaminationRegistrationConfirm.Receiver == receiverID);
  728. }
  729. var query = FeeDAL.GetFinanceReportViewQueryable(batchExp, projectExp, registExp);
  730. if (!string.IsNullOrEmpty(conditionView.ConditionValue) && !string.IsNullOrEmpty(conditionView.Attribute))
  731. {
  732. query = query.DynamicWhere(conditionView.Attribute, conditionView.Condition, conditionView.ConditionValue);
  733. }
  734. return query.OrderBy(x => x.PayTimeOrder).ThenBy(x => x.ReceiptNo.Length).ThenBy(x => x.ReceiptNo);
  735. }
  736. public IGridResultSet<FinanceReportView> GetFinanceReportViewGrid(ConfiguretView conditionView, Guid? schoolyearID, DateTime? payTimeStart, DateTime? payTimeEnd,
  737. Guid? examinationProjectID, Guid? receiverID, int? pageIndex, int? pageSize)
  738. {
  739. var query = this.GetFinanceReportViewQueryabled(conditionView, schoolyearID, payTimeStart, payTimeEnd, examinationProjectID, receiverID);
  740. return query.ToGridResultSet(pageIndex, pageSize);
  741. }
  742. public List<FinanceReportView> GetFinanceReportViewList(ConfiguretView conditionView, Guid? schoolyearID, DateTime? payTimeStart, DateTime? payTimeEnd,
  743. Guid? examinationProjectID, Guid? receiverID)
  744. {
  745. var query = this.GetFinanceReportViewQueryabled(conditionView, schoolyearID, payTimeStart, payTimeEnd, examinationProjectID, receiverID);
  746. return query.ToList();
  747. }
  748. public FinanceReportTotalView GetFinanceReportViewTotal(ConfiguretView conditionView, Guid? schoolyearID, DateTime? payTimeStart, DateTime? payTimeEnd, Guid? examinationProjectID, Guid? receiverID)
  749. {
  750. var query = this.GetFinanceReportViewQueryabled(conditionView, schoolyearID, payTimeStart, payTimeEnd, examinationProjectID, receiverID);
  751. var resultQueryable = (from statistic in query
  752. select new FinanceReportTotalView
  753. {
  754. TotalCount = query.Sum(x => x.StudentCount),
  755. TotalAmount = query.Sum(x => x.Amount)
  756. });
  757. return resultQueryable.First();
  758. }
  759. public void UnloadReceipt()
  760. {
  761. var userID = CustomPrincipal.Current.UserID;
  762. var availableReceiptList = this.ReceiptRepository.GetList(x => x.RecordStatus == (int)SYS_STATUS.USABLE
  763. && x.UserID == userID).ToList();
  764. availableReceiptList.ForEach(x => {
  765. x.ReceiptEndNo = OperateSerialNo.CardSerialNoAddNum(x.CurrentReceipNo, -1);
  766. x.CurrentReceipNo = x.ReceiptEndNo;
  767. x.RecordStatus = (int)SYS_STATUS.UNUSABLE;
  768. this.SetModifyStatus(x);
  769. });
  770. this.UnitOfWork.Commit();
  771. }
  772. public void ApproveRefund(RefundApproveView refundApproveView)
  773. {
  774. var examinationRegistrationIDList = refundApproveView. ExaminationRegistrationIDs.Split(',').Where(x => x.IndexOf("-") >= 0).Select(x => new Guid(x)).ToList();
  775. var examinationRegistrationList = FeeDAL.ExaminationRegistrationRepository.Entities.Where(x => examinationRegistrationIDList.Contains(x.ExaminationRegistrationID)).ToList();
  776. try
  777. {
  778. if (refundApproveView.ApproveStatus == (int)CF_RefundFeeApproval.Agree)
  779. {
  780. examinationRegistrationList.ForEach(x =>
  781. {
  782. x.ModifyTime = DateTime.Now;
  783. x.ModifyUserID = CustomPrincipal.Current.UserID;
  784. x.RecordStatus = (int)EX_ExaminationRegistrationStatus.Refunding;
  785. });
  786. }
  787. else if (refundApproveView.ApproveStatus == (int)CF_RefundFeeApproval.Returnback)
  788. {
  789. examinationRegistrationList.ForEach(x =>
  790. {
  791. x.RecordStatus = (int)EX_ExaminationRegistrationStatus.Paid;
  792. x.ModifyTime = DateTime.Now;
  793. x.ModifyUserID = CustomPrincipal.Current.UserID;
  794. });
  795. }
  796. UnitOfWork.BatchUpdate<EX_ExaminationRegistration>(examinationRegistrationList);
  797. }
  798. catch (Exception)
  799. {
  800. throw;
  801. }
  802. }
  803. }
  804. }