StockInDAL.cs 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  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. using EMIS.DataLogic.Common.ProcurementPlan;
  11. namespace EMIS.DataLogic.Common.TeachingMaterial
  12. {
  13. /// <summary>
  14. /// 入库
  15. /// </summary>
  16. public class StockInDAL
  17. {
  18. #region --0.0 定义--
  19. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  20. public StockInRepository StockInRepository { get; set; }
  21. public StockInDetailRepository StockInDetailRepository { get; set; }
  22. public SchoolyearRepository SchoolyearRepository { get; set; }
  23. public UserRepository UserRepository { get; set; }
  24. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  25. public CoursematerialRepository CoursematerialRepository { get; set; }
  26. public PublishRepository PublishRepository { get; set; }
  27. public CollegeRepository CollegeRepository { get; set; }
  28. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  29. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  30. public SupplierDiscountSetRepository SupplierDiscountSetRepository { get; set; }
  31. public PurchasingStatisticsDAL PurchasingStatisticsDAL { get; set; }
  32. #endregion
  33. #region 2.0 入库编辑
  34. /// <summary>
  35. /// 编辑入库信息
  36. /// </summary>
  37. /// <param name="publisherView"></param>
  38. /// <param name="createUserID"></param>
  39. public void Update(StockInView stockInView)
  40. {
  41. try
  42. {
  43. ET_StockIn stockIn = StockInRepository.GetSingle(x => x.StockInID == stockInView.StockInID);
  44. stockIn.StockInDocumentNo = stockInView.StockInDocumentNo;
  45. stockIn.SchoolyearID = stockInView.SchoolyearID;
  46. stockIn.SupplierID = (Guid)stockInView.SupplierID;
  47. //stockIn.StockInDJTime = (DateTime)stockInView.StockInDJTime;
  48. //stockIn.Discount = (double)stockInView.Discount;
  49. stockIn.Desc = stockInView.Desc;
  50. StockInRepository.UnitOfWork.Update(stockIn);
  51. StockInRepository.UnitOfWork.Commit();
  52. }
  53. catch (Exception ex)
  54. {
  55. throw ex;
  56. }
  57. }
  58. #endregion
  59. #region 4.0 信息列表
  60. public IQueryable<StockInView> GetStockInGridView(Expression<Func<ET_StockIn, bool>> exporder)
  61. {
  62. var viewList = (from a in StockInRepository.GetList(exporder)
  63. join c in UserRepository.Entities on a.HandlerUserID equals c.UserID
  64. into cdata
  65. from cta in cdata.DefaultIfEmpty()
  66. join d in PublishRepository.Entities on a.SupplierID equals d.PublishID
  67. into ddata
  68. from dta in ddata.DefaultIfEmpty()
  69. from e in a.ET_StockInDetail
  70. group new { a, cta, e, dta } by new
  71. {
  72. a.StockInID,
  73. a.CF_Schoolyear.SchoolyearID,
  74. a.SupplierID,
  75. a.CreateUserID,
  76. a.StockInTime,
  77. a.Desc,
  78. a.CF_Schoolyear.Code,
  79. cta.Name,
  80. dta.UnitName,
  81. a.StockInDocumentNo,
  82. a.RecordStatus
  83. } into h
  84. select new StockInView
  85. {
  86. StockInID = h.Key.StockInID,
  87. SchoolyearName = h.Key.Code,
  88. StockInDocumentNo = h.Key.StockInDocumentNo,
  89. SupplierName = h.Key.UnitName,
  90. HandlerUserName = h.Key.Name,
  91. StockInDJTime = h.Key.StockInTime,
  92. StockInSumMoney = h.Sum(x => x.a.StockInSumMoney) == null ? Math.Round((decimal)(h.Sum(x => (x.e.DiscountPrice) * x.e.Quantity) == null ? 0 : h.Sum(x => (x.e.DiscountPrice) * x.e.Quantity)), 2) : h.Sum(x => x.a.StockInSumMoney),
  93. SupplierID = h.Key.SupplierID,
  94. SchoolyearID = (Guid)h.Key.SchoolyearID,
  95. RecordStatus = h.Key.RecordStatus,
  96. RecordStatusName = h.Key.RecordStatus == 1 ? "是" : "否",
  97. isLate = h.Key.RecordStatus == 1 ? true : false,
  98. Desc = h.Key.Desc,
  99. Discount = 1,
  100. DiscountPrice = 1,
  101. TotalDollar = 1,
  102. TotalPrice = 1
  103. });
  104. return viewList;
  105. }
  106. #endregion
  107. #region 5.0 验证入库单据号是否存在
  108. public bool IsExistStockInDocumentNo(string stockInDocumentNo)
  109. {
  110. bool IsExist = false;
  111. var Endt = StockInRepository.GetSingle(x => x.StockInDocumentNo == stockInDocumentNo);
  112. if (Endt != null)
  113. {
  114. IsExist = true;
  115. }
  116. return IsExist;
  117. }
  118. #endregion
  119. #region 6.0 获取入库对应的需要的教材信息
  120. /// <summary>
  121. /// 获取入库对应的需要的教材信息
  122. /// </summary>
  123. /// <param name="exp"></param>
  124. /// <returns></returns>
  125. public IQueryable<TeachingMaterialPoolView> GetTeachersOrderByTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> exp,
  126. Expression<Func<ET_TeachersOrder, bool>> teacherOrderExp,
  127. Expression<Func<ET_StudentsOrder, bool>> studentOrderExp)
  128. {
  129. var view = (from l in TeachingMaterialPoolRepository.Entities.Where(exp)
  130. //教材新增不考虑是否有征订信息
  131. join ps in PurchasingStatisticsDAL.GetPurchasingStatisticsGridView(teacherOrderExp, studentOrderExp)
  132. on l.TeachingMaterialPoolID equals ps.TeachingMaterialPoolID
  133. //join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
  134. //into td
  135. //from ctd in td.DefaultIfEmpty()
  136. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  137. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  138. group new {
  139. TeachingMaterial = l,
  140. //TeachingMaterialType = ctd
  141. }
  142. by new {
  143. Author = l.Author,
  144. ISBN = l.ISBN,
  145. Price = l.Price,
  146. TeachingMaterialCode = l.TeachingMaterialCode,
  147. TeachingMaterialName = l.TeachingMaterialName,
  148. TeachingMaterialShorName = l.TeachingMaterialShorName,
  149. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  150. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  151. //TeachingMaterialTypeName = ctd.Name,
  152. PublishID = l.PublishID,
  153. PublishName = p.UnitName,
  154. PublishTime = l.PublishTime,
  155. CreateTime = l.CreateTime,
  156. CreateUserName = u.Name,
  157. Desc = l.Desc,
  158. DiscountPrice = l.Price,
  159. IsLate = l.IsLate.Value,
  160. ModifyTime = l.ModifyTime,
  161. IsLateName = l.IsLate == true ? "是" : "否",
  162. ZongJia = l.Price,
  163. MaYang = l.Price
  164. } into g
  165. join tmp in TeachingMaterialPoolRepository.Entities on g.Key.TeachingMaterialPoolID equals tmp.TeachingMaterialPoolID
  166. select new TeachingMaterialPoolView
  167. {
  168. Author = g.Key.Author,
  169. ISBN = g.Key.ISBN,
  170. CoursematerialEntityList = tmp.EM_Coursematerial,
  171. Price = g.Key.Price,
  172. TeachingMaterialCode = g.Key.TeachingMaterialCode,
  173. TeachingMaterialName = g.Key.TeachingMaterialName,
  174. TeachingMaterialShorName = g.Key.TeachingMaterialShorName,
  175. TeachingMaterialPoolID = g.Key.TeachingMaterialPoolID,
  176. TeachingMaterialTypeID = g.Key.TeachingMaterialTypeID,
  177. //TeachingMaterialTypeName = g.Key.TeachingMaterialTypeName,
  178. PublishID = g.Key.PublishID,
  179. PublishName = g.Key.PublishName,
  180. PublishTime = g.Key.PublishTime,
  181. CreateTime = g.Key.CreateTime,
  182. CreateUserName = g.Key.CreateUserName,
  183. Desc = g.Key.Desc,
  184. DiscountPrice = g.Key.Price,
  185. IsLate = g.Key.IsLate,
  186. ModifyTime = g.Key.ModifyTime,
  187. IsLateName = g.Key.IsLateName,
  188. OrderQty = 1,
  189. Discount = 1,
  190. ZongJia = g.Key.Price,
  191. MaYang = g.Key.Price
  192. });
  193. return view;
  194. }
  195. #endregion
  196. #region 7.0 获取入库编辑信息
  197. /// <summary>
  198. /// 获取入库信息
  199. /// </summary>
  200. /// <returns></returns>
  201. public StockInView GetSingleStockIn(Guid stockInID)
  202. {
  203. //var stockInDetail = StockInDetailRepository.GetList(x => x.StockInID == stockInID).ToList();
  204. //var query = from c in stockInDetail
  205. // group c by new
  206. // {
  207. // c.StockInID
  208. // }
  209. // into s
  210. // select new
  211. // {
  212. // Qty = s.Sum(x => x.Quantity)
  213. // };
  214. //int qty = query.Select(x => x.Qty).FirstOrDefault().Value;
  215. var view = (from a in StockInRepository.Entities.Where(x => x.StockInID == stockInID)
  216. join b in SchoolyearRepository.Entities on a.SchoolyearID equals b.SchoolyearID
  217. join c in UserRepository.Entities on a.HandlerUserID equals c.UserID
  218. into handlerUser
  219. from HandlerUserTab in handlerUser.DefaultIfEmpty()
  220. join d in PublishRepository.Entities on a.SupplierID equals d.PublishID
  221. into publish
  222. from pu in publish.DefaultIfEmpty()
  223. select new StockInView
  224. {
  225. StockInID = a.StockInID,
  226. SchoolyearName = b.Code,
  227. SchoolyearID = a.SchoolyearID,
  228. StockInDocumentNo = a.StockInDocumentNo,
  229. OrdersNo = a.OrdersNo,
  230. StockInType = a.StockInType,
  231. SupplierName = pu.UnitName,
  232. SupplierID = a.SupplierID,
  233. StockInNumber = a.StockInNumber,
  234. RecordStatus = a.RecordStatus,
  235. StockInDJTime = a.StockInTime,
  236. Desc = a.Desc
  237. }).FirstOrDefault();
  238. return view;
  239. }
  240. #endregion
  241. #region 8.0 获取总价格
  242. public decimal? GetSumMoney(decimal? Price, double? Discount, int? Quantity)
  243. {
  244. decimal Total = decimal.Multiply((decimal)Price, (decimal)Discount);
  245. decimal Money = decimal.Multiply(Total, (decimal)Quantity);
  246. return Money;
  247. }
  248. #endregion
  249. #region 9.0 根据ID、加载入库信息
  250. public IList<TeachingMaterialPoolView> GetTeachingMaterialView(Guid stockInID)
  251. {
  252. var view = (from a in StockInRepository.Entities.Where(x => x.StockInID == stockInID)
  253. join sr in StockInDetailRepository.Entities on a.StockInID equals sr.StockInID
  254. join l in TeachingMaterialPoolRepository.Entities on sr.TeachingMaterialPoolID equals l.TeachingMaterialPoolID
  255. //join d in DictionaryItemRepository.Entities on l.TeachingMaterialTypeID equals d.Value
  256. // into td
  257. //from ctd in td.DefaultIfEmpty()
  258. join u in UserRepository.Entities on l.CreateUserID equals u.UserID
  259. join p in PublishRepository.Entities on l.PublishID equals p.PublishID
  260. select new TeachingMaterialPoolView
  261. {
  262. Author = l.Author,
  263. ISBN = l.ISBN,
  264. CoursematerialEntityList = l.EM_Coursematerial,
  265. Price = l.Price,
  266. TeachingMaterialCode = l.TeachingMaterialCode,
  267. TeachingMaterialName = l.TeachingMaterialName,
  268. TeachingMaterialShorName = l.TeachingMaterialShorName,
  269. TeachingMaterialPoolID = l.TeachingMaterialPoolID,
  270. TeachingMaterialTypeID = l.TeachingMaterialTypeID,
  271. //TeachingMaterialTypeName = ctd.Name,
  272. PublishID = l.PublishID,
  273. PublishName = p.UnitName,
  274. PublishTime = l.PublishTime,
  275. CreateTime = l.CreateTime,
  276. CreateUserName = u.Name,
  277. DiscountPrice = sr.DiscountPrice == null ? 0 : sr.DiscountPrice,
  278. Desc = l.Desc,
  279. IsLate = l.IsLate.Value,
  280. ModifyTime = l.ModifyTime,
  281. IsLateName = l.IsLate == true ? "是" : "否",
  282. OrderQty = sr.Quantity == null ? 1 : sr.Quantity,
  283. Discount = sr.Discount == null ? 1 : sr.Discount,
  284. ZongJia = Math.Round((decimal)(sr.Quantity * sr.DiscountPrice), 2) == null ? 0 : Math.Round((decimal)(sr.Quantity * sr.DiscountPrice), 2),
  285. MaYang = Math.Round((decimal)(sr.Quantity * l.Price), 2) == null ? 0 : Math.Round((decimal)(sr.Quantity * l.Price), 2)
  286. }).ToList();
  287. return view;
  288. }
  289. #endregion
  290. #region 10.0 获取入库对应的需要的教材信息(新增)
  291. /// <summary>
  292. /// 获取入库对应的需要的教材信息(新增)
  293. /// </summary>
  294. /// <param name="exp"></param>
  295. /// <returns></returns>
  296. public IQueryable<TeachingMaterialPoolView> GetTeachingMaterial(Expression<Func<CF_TeachingMaterialPool, bool>> exp, decimal? discount)
  297. {
  298. var view = from a in TeachingMaterialPoolRepository.GetList(exp)
  299. join p in PublishRepository.Entities on a.PublishID equals p.PublishID
  300. into pp
  301. from ppp in pp.DefaultIfEmpty()
  302. join u in UserRepository.Entities on a.CreateUserID equals u.UserID
  303. select new TeachingMaterialPoolView
  304. {
  305. Author = a.Author,
  306. ISBN = a.ISBN,
  307. CoursematerialEntityList = a.EM_Coursematerial,
  308. Price = a.Price,
  309. TeachingMaterialCode = a.TeachingMaterialCode,
  310. TeachingMaterialName = a.TeachingMaterialName,
  311. TeachingMaterialShorName = a.TeachingMaterialShorName,
  312. TeachingMaterialPoolID = a.TeachingMaterialPoolID,
  313. TeachingMaterialTypeID = a.TeachingMaterialTypeID,
  314. //TeachingMaterialTypeName = a.TeachingMaterialTypeName,
  315. PublishID = a.PublishID,
  316. PublishName = ppp.UnitName,
  317. PublishTime = a.PublishTime,
  318. CreateTime = a.CreateTime,
  319. CreateUserName = u.Name,
  320. Desc = a.Desc,
  321. DiscountPrice = a.Price,
  322. IsLate = a.IsLate.Value,
  323. ModifyTime = a.ModifyTime,
  324. IsLateName = a.IsLate == true ? "是" : "否",
  325. OrderQty = 1,
  326. Discount = discount,
  327. ZongJia = a.Price,
  328. MaYang = a.Price
  329. };
  330. return view;
  331. }
  332. #endregion
  333. public IQueryable<StockInDetailView> GetDetailByIDList(List<Guid> idList)
  334. {
  335. var query = from stock in StockInRepository.GetList(x => idList.Contains(x.StockInID))
  336. join detail in StockInDetailRepository.Entities
  337. on stock.StockInID equals detail.StockInID
  338. select new StockInDetailView
  339. {
  340. StockInDetailID = detail.StockInDetailID,
  341. StockInID = detail.StockInID,
  342. TeachingMaterialPoolID = detail.TeachingMaterialPoolID,
  343. Discount = detail.Discount,
  344. DiscountPrice = detail.DiscountPrice,
  345. LibraryID = detail.LibraryID,
  346. Quantity = detail.Quantity
  347. };
  348. return query;
  349. }
  350. }
  351. }