StockOutDAL.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Repositories;
  6. using EMIS.ViewModel.TeachingMaterial;
  7. using System.Linq.Expressions;
  8. using EMIS.Entities;
  9. using EMIS.ViewModel;
  10. namespace EMIS.DataLogic.Common.TeachingMaterial
  11. {
  12. public class StockOutDAL
  13. {
  14. #region --0.0 定义--
  15. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  16. public StockOutRepository StockOutRepository { get; set; }
  17. public StockOutDetailRepository StockOutDetailRepository { get; set; }
  18. public SchoolyearRepository SchoolyearRepository { get; set; }
  19. public UserRepository UserRepository { get; set; }
  20. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  21. public CoursematerialRepository CoursematerialRepository { get; set; }
  22. public PublishRepository PublishRepository { get; set; }
  23. public CollegeRepository CollegeRepository { get; set; }
  24. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  25. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  26. #endregion
  27. #region 2.0 查询信息列表
  28. public IQueryable<StockOutView> GetStockOutGridView(Expression<Func<ET_StockOut, bool>> exporder)
  29. {
  30. var viewList = (from a in StockOutRepository.Entities.Where(exporder)
  31. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  32. join c in UserRepository.Entities on a.RecipientUserID equals c.UserID
  33. into tuser
  34. from ctuser in tuser.DefaultIfEmpty()
  35. join f in UserRepository.Entities on a.ModifyUserID equals f.UserID
  36. join e in StockOutDetailRepository.Entities on a.StockOutID equals e.StockOutID
  37. join ct in DictionaryItemRepository.Entities on new { a.StockOutType, DictionaryCode = DictionaryItem.CF_StockOutType.ToString() }
  38. equals new { StockOutType = (int)ct.Value, ct.DictionaryCode } into gbsta
  39. from ctCourseType in gbsta.DefaultIfEmpty()
  40. group new { a, b, ctuser, e, ctCourseType, f } by new
  41. {
  42. TypeName = ctCourseType.Name,
  43. a.StockOutID,
  44. a.SchoolyearID,
  45. a.OutNumber,
  46. b.Code,
  47. a.GetBookNo,
  48. a.StockOutType,
  49. StockOutUserName = f.Name,
  50. a.StockOutTime,
  51. a.StockOutNo,
  52. a.RecordStatus,
  53. RecipientUserName = a.StockOutType == 5 ? a.GetBookNo : ctuser.Name,
  54. a.Desc
  55. } into h
  56. select new StockOutView
  57. {
  58. StockOutID = h.Key.StockOutID,
  59. SchoolyearID = h.Key.SchoolyearID,
  60. GetBookNo = h.Key.GetBookNo,
  61. StockOutNo = h.Key.StockOutNo,
  62. SchoolyearName = h.Key.Code,
  63. StockOutTypeID = h.Key.StockOutType,
  64. StockOutSumMoney = h.Sum(x => x.e.Discount * x.e.StockOutQuantity),// * h.Sum(x => x.e.StockOutQuantity),
  65. RecipientUserName = h.Key.RecipientUserName == null ? h.Key.GetBookNo : h.Key.RecipientUserName,
  66. StockOutTime = h.Key.StockOutTime,
  67. StockOutTypeName = h.Key.TypeName,
  68. RecordStatus = h.Key.RecordStatus,
  69. RecordStatusName = h.Key.RecordStatus == 1 ? "是" : "否",
  70. StockOutUserName = h.Key.StockOutUserName,
  71. Desc = h.Key.Desc
  72. });
  73. return viewList;
  74. }
  75. #endregion
  76. #region 4.0 获取出库可编辑信息
  77. public StockOutView GetSingleStockOut(Guid stockOutID)
  78. {
  79. var stockOutDetail = StockOutDetailRepository.GetList(x => x.StockOutID == stockOutID).ToList();
  80. var query = from c in stockOutDetail
  81. group c by new
  82. {
  83. c.StockOutID
  84. }
  85. into s
  86. select new
  87. {
  88. Qty = s.Sum(x => x.StockOutQuantity)
  89. };
  90. int qty = query.Select(x => x.Qty).FirstOrDefault().Value;
  91. var view = (from a in StockOutRepository.Entities.Where(x => x.StockOutID == stockOutID)
  92. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  93. //join c in UserRepository.Entities on a.RecipientUserID equals c.UserID
  94. //into tc
  95. //from ctc in tc.DefaultIfEmpty()
  96. select new StockOutView
  97. {
  98. RecordStatus = a.RecordStatus,
  99. StockOutID = a.StockOutID,
  100. StockOutTime = a.StockOutTime,
  101. StockOutNo = a.StockOutNo,
  102. StockOutTypeID = a.StockOutType,
  103. GetBookNo = a.GetBookNo,
  104. OutNumber = (int)a.OutNumber == null ? 1 : qty,
  105. SchoolyearID = a.SchoolyearID,
  106. RecipientUserID = a.RecipientUserID == null ? Guid.Empty : a.RecipientUserID,
  107. Desc = a.Desc
  108. }).FirstOrDefault();
  109. return view;
  110. }
  111. #endregion
  112. #region 5.0 验证出库单据号是否存在
  113. public bool IsExistStockOutNo(string stockOutNo)
  114. {
  115. bool IsExist = false;
  116. var Endt = StockOutRepository.GetSingle(x => x.StockOutNo == stockOutNo);
  117. if (Endt != null)
  118. {
  119. IsExist = true;
  120. }
  121. return IsExist;
  122. }
  123. #endregion
  124. #region 8.0 根据ID、加载出库信息
  125. public IList<TeachingMaterialPoolView> GetTeachingMaterialView(Guid stockOutID)
  126. {
  127. var view = (from a in StockOutRepository.Entities.Where(x => x.StockOutID == stockOutID)
  128. join sr in StockOutDetailRepository.Entities on a.StockOutID equals sr.StockOutID
  129. join l in TeachingMaterialPoolRepository.Entities on sr.TeachingMaterialPoolID equals l.TeachingMaterialPoolID
  130. //join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
  131. //into td
  132. //from ctd in td.DefaultIfEmpty()
  133. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  134. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  135. join tm in TeachingMateriaInventoryRepository.Entities on sr.TeachingMaterialPoolID equals tm.TeachingMaterialPoolID
  136. select new TeachingMaterialPoolView
  137. {
  138. Author = l.Author,
  139. ISBN = l.ISBN,
  140. CoursematerialEntityList = l.EM_Coursematerial,
  141. Price = l.Price,
  142. TeachingMaterialCode = l.TeachingMaterialCode,
  143. TeachingMaterialName = l.TeachingMaterialName,
  144. TeachingMaterialShorName = l.TeachingMaterialShorName,
  145. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  146. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  147. //TeachingMaterialTypeName = ctd.Name,
  148. PublishID = l.PublishID,
  149. PublishName = p.UnitName,
  150. PublishTime = l.PublishTime,
  151. CreateTime = l.CreateTime,
  152. CreateUserName = u.Name,
  153. Desc = l.Desc,
  154. IsLate = l.IsLate.Value,
  155. ModifyTime = l.ModifyTime,
  156. IsLateName = l.IsLate == true ? "是" : "否",
  157. OrderQty = sr.StockOutQuantity,
  158. PresentInventory = tm.PresentInventory,
  159. Discount = sr.DiscountPrice,
  160. DiscountPrice = sr.Discount
  161. }).ToList();
  162. return view;
  163. }
  164. #endregion
  165. #region 10.0 出库明细信息列表
  166. public IQueryable<StockOutView> GetStockInDetailGridView(Expression<Func<ET_StockOut, bool>> exporder)
  167. {
  168. var viewList = (from a in StockOutRepository.Entities.Where(exporder)
  169. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  170. join c in UserRepository.Entities on a.CreateUserID equals c.UserID
  171. join e in StockOutDetailRepository.Entities on a.StockOutID equals e.StockOutID
  172. join t in TeachingMaterialPoolRepository.Entities on e.TeachingMaterialPoolID equals t.TeachingMaterialPoolID
  173. select new StockOutView
  174. {
  175. StockOutDetailID = e.StockOutDetailID,
  176. SchoolyearName = b.Code,
  177. SchoolyearID = (Guid)a.SchoolyearID,
  178. StockOutNo = a.StockOutNo,
  179. GetBookNo = a.GetBookNo.ToString(),
  180. TeachingMaterialCode = t.TeachingMaterialCode,
  181. TeachingMaterialName = t.TeachingMaterialName,
  182. PublishName = t.CF_Publish.UnitName,
  183. PublishTime = t.PublishTime,
  184. Author = t.Author,
  185. Quantity = e.StockOutQuantity,
  186. Price = t.Price,
  187. Discount = e.Discount,
  188. DiscountPrice = t.Price * e.Discount,
  189. TotalDollar = (t.Price * e.Discount) * e.StockOutQuantity,
  190. RecipientUserName = a.GetBookNo,
  191. StockOutUserName = c.Name,
  192. StockOutID = a.StockOutID,
  193. StockOutTime = a.StockOutTime,
  194. TotalPrice = t.Price * e.StockOutQuantity,
  195. Desc = a.Desc
  196. });
  197. return viewList;
  198. }
  199. #endregion
  200. #region 11.0 获取教材信息
  201. /// <summary>
  202. /// 获取教材信息
  203. /// </summary>
  204. /// <param name="exp"></param>
  205. /// <returns></returns>
  206. public IQueryable<TeachingMaterialPoolView> GetTeachersOrderByTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> exp)
  207. {
  208. //TeachingMateriaInventoryRepository
  209. var view = (from a in TeachingMateriaInventoryRepository.Entities
  210. join l in TeachingMaterialPoolRepository.GetList(exp) on a.TeachingMaterialPoolID equals l.TeachingMaterialPoolID
  211. //join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
  212. // into td
  213. //from ctd in td.DefaultIfEmpty()
  214. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  215. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  216. group new {
  217. TeachingMaterialPool = l,
  218. //TeachingMaterialType = ctd,
  219. TeachingMaterialInventory = a
  220. } by new {
  221. Author = l.Author,
  222. ISBN = l.ISBN,
  223. Price = l.Price,
  224. TeachingMaterialCode = l.TeachingMaterialCode,
  225. TeachingMaterialName = l.TeachingMaterialName,
  226. TeachingMaterialShorName = l.TeachingMaterialShorName,
  227. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  228. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  229. //TeachingMaterialTypeName = ctd.Name,
  230. PublishID = l.PublishID,
  231. PublishName = p.UnitName,
  232. PublishTime = l.PublishTime,
  233. CreateTime = l.CreateTime,
  234. CreateUserName = u.Name,
  235. Desc = l.Desc,
  236. IsLate = l.IsLate.Value,
  237. ModifyTime = l.ModifyTime,
  238. IsLateName = l.IsLate == true ? "是" : "否",
  239. //DiscountPrice = a.Discount,//折合价
  240. //Discount = Math.Round((decimal)(a.Discount/l.Price),2),//折扣率
  241. } into g
  242. join tmp in TeachingMaterialPoolRepository.Entities on g.Key.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID
  243. select new TeachingMaterialPoolView
  244. {
  245. Author = g.Key.Author,
  246. ISBN = g.Key.ISBN,
  247. CoursematerialEntityList = tmp.EM_Coursematerial,
  248. Price = g.Key.Price,
  249. TeachingMaterialCode = g.Key.TeachingMaterialCode,
  250. TeachingMaterialName = g.Key.TeachingMaterialName,
  251. TeachingMaterialShorName = g.Key.TeachingMaterialShorName,
  252. TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID,
  253. TeachingMaterialTypeID = g.Key.TeachingMaterialTypeID,
  254. //TeachingMaterialTypeName = g.Key.TeachingMaterialTypeName,
  255. PublishID = g.Key.PublishID,
  256. PublishName = g.Key.PublishName,
  257. PublishTime = g.Key.PublishTime,
  258. CreateTime = g.Key.CreateTime,
  259. CreateUserName = g.Key.CreateUserName,
  260. Desc = g.Key.Desc,
  261. IsLate = g.Key.IsLate,
  262. ModifyTime = g.Key.ModifyTime,
  263. IsLateName = g.Key.IsLateName,
  264. OrderQty = 1,
  265. //Discount = 1,
  266. DiscountPrice = g.Key.Price * g.OrderByDescending(x => x.TeachingMaterialInventory.CreateTime).FirstOrDefault().TeachingMaterialInventory.Discount,
  267. //g.OrderByDescending(x => x.TeachingMaterialInventory.CreateTime).FirstOrDefault().TeachingMaterialInventory.DiscountPrice,//折合价
  268. Discount = g.OrderByDescending(x => x.TeachingMaterialInventory.CreateTime).FirstOrDefault().TeachingMaterialInventory.Discount,
  269. //Math.Round((decimal)((g.OrderByDescending(x => x.TeachingMaterialInventory.CreateTime).FirstOrDefault().TeachingMaterialPool.Price) == 0 ? 0 : ((g.OrderByDescending(x => x.TeachingMaterialInventory.CreateTime).FirstOrDefault().TeachingMaterialInventory.Discount) / (g.OrderByDescending(x => x.TeachingMaterialInventory.CreateTime).FirstOrDefault().TeachingMaterialPool.Price))), 2),//折扣率
  270. PresentInventory = g.Sum(w => w.TeachingMaterialInventory.PresentInventory)
  271. });
  272. return view;
  273. }
  274. #endregion
  275. #region 12.0 获取出库对应明细的需要的教材信息
  276. /// <summary>
  277. /// 获取出库对应明细的需要的教材信息
  278. /// </summary>
  279. /// <param name="exp"></param>
  280. /// <returns></returns>
  281. public IQueryable<TeachingMaterialPoolView> GetStockOutByTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> exp)
  282. {
  283. //TeachingMateriaInventoryRepository
  284. var view = (from a in StockOutDetailRepository.Entities
  285. join l in TeachingMaterialPoolRepository.Entities on a.TeachingMaterialPoolID equals l.TeachingMaterialPoolID
  286. //join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
  287. // into td
  288. //from ctd in td.DefaultIfEmpty()
  289. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  290. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  291. select new TeachingMaterialPoolView
  292. {
  293. Author = l.Author,
  294. ISBN = l.ISBN,
  295. CoursematerialEntityList = l.EM_Coursematerial,
  296. Price = l.Price,
  297. TeachingMaterialCode = l.TeachingMaterialCode,
  298. TeachingMaterialName = l.TeachingMaterialName,
  299. TeachingMaterialShorName = l.TeachingMaterialShorName,
  300. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  301. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  302. //TeachingMaterialTypeName = ctd.Name,
  303. PublishID = l.PublishID,
  304. PublishName = p.UnitName,
  305. PublishTime = l.PublishTime,
  306. CreateTime = l.CreateTime,
  307. CreateUserName = u.Name,
  308. Desc = l.Desc,
  309. IsLate = l.IsLate.Value,
  310. ModifyTime = l.ModifyTime,
  311. IsLateName = l.IsLate == true ? "是" : "否",
  312. OrderQty = 1,
  313. Discount = 1
  314. });
  315. return view;
  316. }
  317. #endregion
  318. #region 13.0 验证输入的出库数量是否大于当前库存量
  319. public bool CheckInventoryQty(int Qty, Guid teachingMaterialPoolID)
  320. {
  321. bool IsExist = false;
  322. int? presentInventory = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == teachingMaterialPoolID).PresentInventory;
  323. if (Qty > presentInventory)
  324. {
  325. IsExist = true;
  326. }
  327. return IsExist;
  328. }
  329. #endregion
  330. }
  331. }