StockOutServices.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using EMIS.DataLogic.Common.TeachingMaterial;
  6. using EMIS.ViewModel.TeachingMaterial;
  7. using Bowin.Common.Linq.Entity;
  8. using EMIS.ViewModel;
  9. using EMIS.Entities;
  10. using EMIS.DataLogic.Repositories;
  11. using EMIS.DataLogic.UniversityManage.TeacherManage;
  12. using System.Linq.Expressions;
  13. using System.Web;
  14. using Bowin.Common.Linq;
  15. using EMIS.CommonLogic.SystemServices;
  16. using System.Text.RegularExpressions;
  17. namespace EMIS.CommonLogic.TeachingMaterial
  18. {
  19. public class StockOutServices : BaseServices, IStockOutServices
  20. {
  21. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  22. public StockOutRepository StockOutRepository { get; set; }
  23. public StockOutDetailRepository StockOutDetailRepository { get; set; }
  24. public SchoolyearRepository SchoolyearRepository { get; set; }
  25. public UserRepository UserRepository { get; set; }
  26. public Lazy<StaffDAL> staffDAL { get; set; }
  27. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  28. public CoursematerialRepository CoursematerialRepository { get; set; }
  29. public PublishRepository PublishRepository { get; set; }
  30. public CollegeRepository CollegeRepository { get; set; }
  31. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  32. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  33. public StockOutDAL StockOutDAL { get; set; }
  34. public StockOutDetailDAL StockOutDetailDAL { get; set; }
  35. public Lazy<IParameterServices> ParameterServices { get; set; }
  36. public Lazy<ISerialNumberServices> SerialNumberServices { get; set; }
  37. #region 1.0 查询出库信息
  38. public IGridResultSet<StockOutView> GetStockOutViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, IList<int> stockOutTypeList, Guid? supplierID, DateTime? stockOutTimeStart, DateTime? stockOutTimeEnd, int pageIndex, int pageSize)
  39. {
  40. if (stockOutTimeStart == null)
  41. {
  42. stockOutTimeStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
  43. }
  44. var query = StockOutDAL.GetStockOutGridView(x => stockOutTypeList.Contains(x.StockOutType));
  45. if (schoolyearID.HasValue)
  46. query = query.Where(x => x.SchoolyearID == schoolyearID);
  47. if (supplierID.HasValue)
  48. query = query.Where(x => x.SupplierID == supplierID);
  49. if (stockOutTimeStart.HasValue)
  50. query = query.Where(x => x.StockOutTime >= stockOutTimeStart);
  51. if (stockOutTimeEnd.HasValue)
  52. {
  53. DateTime newStockOutTimeEnd = stockOutTimeEnd.Value.AddDays(1);//取起止日期一天、
  54. query = query.Where(x => x.StockOutTime <= newStockOutTimeEnd);
  55. }
  56. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  57. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderByDescending(x => x.StockOutTime).ToGridResultSet<StockOutView>(pageIndex, pageSize);
  58. return query.OrderBy(x => x.SchoolyearName).OrderBy(x => x.StockOutNo).OrderByDescending(x => x.StockOutTime).ToGridResultSet<StockOutView>(pageIndex, pageSize);
  59. }
  60. #endregion
  61. #region 2.0 查询出库Excel导出信息
  62. //查询并导出
  63. public IList<StockOutView> GetStockOutViewList(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, IList<int> stockOutTypeList, Guid? supplierID, DateTime? stockOutTimeStart, DateTime? stockOutTimeEnd)
  64. {
  65. DateTime newStockOutTimeEnd = stockOutTimeEnd.Value.AddDays(1);//取起止日期一天、
  66. var query = StockOutDAL.GetStockOutGridView(x => stockOutTypeList.Contains(x.StockOutType));
  67. if (schoolyearID.HasValue)
  68. query = query.Where(x => x.SchoolyearID == schoolyearID);
  69. if (supplierID.HasValue)
  70. query = query.Where(x => x.SupplierID == supplierID);
  71. if (stockOutTimeStart.HasValue)
  72. query = query.Where(x => x.StockOutTime >= stockOutTimeStart);
  73. if (stockOutTimeEnd.HasValue)
  74. query = query.Where(x => x.StockOutTime <= newStockOutTimeEnd);
  75. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  76. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.StockOutTime).ToList();
  77. return query.OrderBy(x => x.StockOutTime).ToList();
  78. }
  79. #endregion
  80. #region 3.0 删除出库信息
  81. //删除出库信息
  82. public void Delete(List<Guid> stockOutIDs)
  83. {
  84. try
  85. {
  86. bool? IsOrdered = false;//是否包含出库信息!
  87. var stockOutList = StockOutRepository.GetList(x => stockOutIDs.Contains(x.StockOutID)).ToList();
  88. foreach (var stockOut in stockOutList)
  89. {
  90. if (stockOut.RecordStatus == (int)SYS_STATUS.USABLE)
  91. {
  92. throw new Exception("选择的信息已出库,无法删除。");
  93. }
  94. }
  95. if (stockOutIDs.Count > 0)
  96. {
  97. //删除入库数据、及该单号下挂钩的明细数据
  98. StockOutDetailRepository.UnitOfWork.Delete<ET_StockOutDetail>(x => stockOutIDs.Contains(x.StockOutID));
  99. StockOutRepository.UnitOfWork.Delete<ET_StockOut>(x => stockOutIDs.Contains(x.StockOutID));
  100. }
  101. }
  102. catch (Exception ex)
  103. {
  104. throw ex;
  105. }
  106. }
  107. #endregion
  108. #region 4.0 根据ID、获取出库编辑信息
  109. public StockOutView GetSingleStockOut(Guid stockOutID)
  110. {
  111. return StockOutDAL.GetSingleStockOut(stockOutID);
  112. }
  113. #endregion
  114. #region 5.0 检查编号唯一
  115. //验证出库单据号是否存在
  116. public bool IsExistStockOutNo(string stockOutNo)
  117. {
  118. return StockOutDAL.IsExistStockOutNo(stockOutNo);
  119. }
  120. #endregion
  121. #region 6.0 出库信息保存
  122. //注:折合价=单价*折扣率、码洋=单价*数量、总价(实洋)=折合价*数量(码洋*折扣率、单价*折扣率*数量)
  123. public void Save(StockOutView stockOutView, IList<TeachingMaterialPoolView> tmList, Guid? userId, string type)
  124. {
  125. //var curUser = EMIS.Utility.FormValidate.CustomPrincipal.Current;//提取当前用户信息
  126. //Expression<Func<CF_Staff, bool>> exp = (x => true);
  127. //if (curUser.CollegeID.HasValue)
  128. //{
  129. // exp = exp.And(x => x.CollegeID == curUser.CollegeID);
  130. //}
  131. //var staffInfo =staffDAL.Value.GetStaffViewQueryable(exp);//所选用户对应院系的所有老师、
  132. if (this.StockOutRepository.GetList(x => x.StockOutNo == stockOutView.StockOutNo
  133. && x.StockOutID != stockOutView.StockOutID).Count() > 0)
  134. {
  135. throw new Exception("出库单号已经存在,请重新输入!");
  136. }
  137. int RecordStatusType = (int)CF_GeneralPurpose.IsNo;
  138. Guid? GetBookUserId = stockOutView.RecipientUserID;
  139. if ((int)stockOutView.StockOutTypeID == (int)CF_StockOutType.TeachingMaterialRetail)
  140. {
  141. GetBookUserId = Guid.Empty;//如果是教材零售
  142. }
  143. if (type == "Submit")//如果是Save 那么状态默认为0、 如果是Submit 那么状态默认1
  144. {
  145. RecordStatusType = (int)CF_GeneralPurpose.IsYes;
  146. }
  147. ET_StockOut stockOutEntity = GetStockOut(stockOutView.StockOutID);
  148. if (stockOutEntity != null)//更新数据
  149. {
  150. stockOutEntity.SchoolyearID = (Guid)stockOutView.SchoolyearID;
  151. stockOutEntity.StockOutNo = stockOutView.StockOutNo;
  152. stockOutEntity.StockOutType = (int)stockOutView.StockOutTypeID;
  153. stockOutEntity.Desc = stockOutView.Desc;
  154. stockOutEntity.RecipientUserID = GetBookUserId;
  155. stockOutEntity.StockOutTime = stockOutView.StockOutTime;
  156. stockOutView.RecordStatus = RecordStatusType;
  157. stockOutEntity.GetBookNo = stockOutView.GetBookNo;
  158. StockOutRepository.UnitOfWork.Update(stockOutEntity);
  159. //StockOutRepository.UnitOfWork.Commit();//更新数据
  160. //删除出库明细数据、重新插入一次
  161. StockOutDetailRepository.UnitOfWork.Delete<ET_StockOutDetail>(x => x.StockOutID == stockOutView.StockOutID);
  162. //对数据进行分组、单价、教材ID一致、数量累加
  163. GetTMPList(tmList, userId, stockOutView.StockOutID);
  164. }
  165. else
  166. {
  167. ET_StockOut stockOut = new ET_StockOut()
  168. {
  169. StockOutID = Guid.NewGuid(),
  170. Desc = stockOutView.Desc,
  171. StockOutType = (int)stockOutView.StockOutTypeID,
  172. CreateTime = DateTime.Now,
  173. CreateUserID = userId,
  174. SchoolyearID = (Guid)stockOutView.SchoolyearID,
  175. ModifyTime = DateTime.Now,
  176. ModifyUserID = userId,
  177. RecordStatus = RecordStatusType,
  178. GetBookNo = stockOutView.GetBookNo,
  179. RecipientUserID = GetBookUserId == Guid.Empty ? userId : GetBookUserId,
  180. StockOutTime = stockOutView.StockOutTime,
  181. OutNumber = stockOutView.OutNumber,
  182. StockOutNo = stockOutView.StockOutNo
  183. };
  184. StockOutRepository.UnitOfWork.Add(stockOut);//添加出库信息
  185. UnitOfWork.Commit();
  186. GetTMPList(tmList, userId, stockOut.StockOutID);
  187. // UnitOfWork.BulkInsert(tpList);//统一写入
  188. }
  189. }
  190. #endregion
  191. #region 7.0 获取出库的教材信息
  192. public IList<TeachingMaterialPoolView> GetStockOutByTMViewList(Guid stockOutID)
  193. {
  194. return StockOutDAL.GetTeachingMaterialView(stockOutID);
  195. }
  196. #endregion
  197. #region 8.0 提交出库单
  198. //提交出库单
  199. public void Submit(List<Guid> stockOutIDs, Guid userId)
  200. {
  201. try
  202. {
  203. if (stockOutIDs.Count > 0)
  204. {
  205. IList<ET_StockOut> stockOutList = StockOutRepository.GetList(x => stockOutIDs.Contains(x.StockOutID), (x => x.ET_StockOutDetail)).ToList();
  206. foreach (var stockOutEntity in stockOutList)
  207. {
  208. if (stockOutEntity.RecordStatus == (int)CF_GeneralPurpose.IsYes)
  209. {
  210. throw new Exception("选择的信息已提交,无法重复提交。");
  211. }
  212. }
  213. foreach (var stockOutEntity in stockOutList)
  214. {
  215. stockOutEntity.RecordStatus = (int)CF_GeneralPurpose.IsYes;
  216. stockOutEntity.ModifyUserID = userId;
  217. StockOutRepository.UnitOfWork.Update(stockOutEntity);
  218. // StockOutRepository.UnitOfWork.Commit();
  219. IList<ET_StockOutDetail> stockOutDetailList = stockOutEntity.ET_StockOutDetail.ToList();
  220. //1.0 提取当前库存量、
  221. foreach (var stockOutDetailEntity in stockOutDetailList)
  222. {
  223. int? stockOutQuantity = stockOutDetailEntity.StockOutQuantity;
  224. List<ET_TeachingMateriaInventory> teachingMateriaInventorylist = GetTeachingMateriaInventory(stockOutDetailEntity.TeachingMaterialPoolID, stockOutDetailEntity.Discount).OrderBy(x => x.CreateTime).ToList();
  225. int count = 0;
  226. int Inventorysum = 0;
  227. int needQuantity = (int)stockOutQuantity;
  228. int oldInventory = 0;
  229. if (teachingMateriaInventorylist.Count > 0)
  230. {
  231. foreach (ET_TeachingMateriaInventory teachingMateriaInventory in teachingMateriaInventorylist)
  232. {
  233. Inventorysum = Inventorysum + (teachingMateriaInventory.PresentInventory ?? 0);
  234. count++;
  235. if (Inventorysum >= stockOutQuantity)
  236. {
  237. if (count == 1)
  238. {
  239. teachingMateriaInventory.PresentInventory = teachingMateriaInventory.PresentInventory - stockOutQuantity;
  240. teachingMateriaInventory.ModifyTime = DateTime.Now;
  241. TeachingMateriaInventoryRepository.UnitOfWork.Update(teachingMateriaInventory);//更新库存数量
  242. break;
  243. }
  244. else
  245. {
  246. for (int i = 0; i < count; i++)
  247. {
  248. var view = teachingMateriaInventorylist[i];
  249. oldInventory = (int)view.PresentInventory;
  250. view.PresentInventory = (view.PresentInventory - needQuantity) <= 0 ? 0 : (view.PresentInventory - needQuantity);
  251. view.ModifyTime = DateTime.Now;
  252. TeachingMateriaInventoryRepository.UnitOfWork.Update(view);//更新库存数量
  253. if (oldInventory - needQuantity <= 0)
  254. {
  255. needQuantity = needQuantity - oldInventory;
  256. }
  257. }
  258. break;
  259. }
  260. }
  261. }
  262. }
  263. if (Inventorysum < stockOutQuantity)
  264. {
  265. throw new Exception("出库数量大于当前库存量!");
  266. }
  267. }
  268. //BalanceInventory(stockInDetailList, userId);//提交平衡库存
  269. }
  270. }
  271. UnitOfWork.Commit();
  272. }
  273. catch (Exception ex)
  274. {
  275. throw ex;
  276. }
  277. }
  278. #endregion
  279. #region 9.0 查询出库明细列表
  280. //出库明细列表
  281. public IGridResultSet<StockOutView> GetStockOutDetailViewGrid(Guid? stockOutId, int pageIndex, int pageSize)
  282. {
  283. var query = StockOutDetailDAL.GetStockOutDetailGridView(x => x.StockOutID == stockOutId);
  284. return query.OrderBy(x => x.StockOutTime).ToGridResultSet<StockOutView>(pageIndex, pageSize);
  285. }
  286. #endregion
  287. #region 10. 出库明细列表导出Excel
  288. //出库明细Excel导出
  289. public IList<StockOutView> GetStockOutDetailViewList(Guid? stockOutId)
  290. {
  291. var query = StockOutDetailDAL.GetStockOutDetailGridView(x => x.StockOutID == stockOutId);
  292. return query.OrderBy(x => x.StockOutTime).ToList();
  293. }
  294. #endregion
  295. #region 11. 获取教材信息
  296. public IGridResultSet<TeachingMaterialPoolView> GetStockInByTeachingMaterialPoolViewGrid(ViewModel.ConfiguretView configuretView, bool? isLate, Guid? teachingMaterialPoolID, Guid? coursematerialID, bool isSelectMax, int pageIndex, int pageSize)
  297. {
  298. Expression<Func<CF_TeachingMaterialPool, bool>> exp = (x => true);
  299. if (teachingMaterialPoolID.HasValue)
  300. {
  301. exp = exp.And(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
  302. }
  303. if (coursematerialID.HasValue)
  304. {
  305. exp = exp.And(x => x.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID));
  306. }
  307. var query = StockOutDAL.GetTeachersOrderByTeachingMaterial(exp);
  308. //if (isLate.HasValue)
  309. //{
  310. // query = query.Where(x => x.IsLate == isLate);
  311. //}
  312. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  313. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
  314. var result = query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
  315. if (isSelectMax)
  316. {
  317. result.rows.ForEach(x => x.OrderQty = x.PresentInventory);
  318. }
  319. return result;
  320. }
  321. #endregion
  322. public IGridResultSet<TeachingMaterialPoolView> GetTeachingMaterialViewForRefundGrid(ViewModel.ConfiguretView configuretView, bool? isLate, Guid? teachingMaterialPoolID, Guid? coursematerialID, bool isSelectMax, int pageIndex, int pageSize)
  323. {
  324. Expression<Func<CF_TeachingMaterialPool, bool>> exp = (x => true);
  325. if (teachingMaterialPoolID.HasValue)
  326. {
  327. exp = exp.And(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
  328. }
  329. if (coursematerialID.HasValue)
  330. {
  331. exp = exp.And(x => x.EM_Coursematerial.Any(w => w.CoursematerialID == coursematerialID));
  332. }
  333. //if (isLate.HasValue)
  334. //{
  335. // exp = exp.And(x => x.IsLate == isLate);
  336. //}
  337. var query = StockOutDAL.GetTeachersOrderByTeachingMaterial(exp);
  338. //if (isLate.HasValue)
  339. //{
  340. // query = query.Where(x => x.IsLate == isLate);
  341. //}
  342. query = query.Where(x => x.PresentInventory > 0);
  343. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  344. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
  345. var result = query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
  346. if (isSelectMax)
  347. {
  348. result.rows.ForEach(x => x.OrderQty = x.PresentInventory);
  349. }
  350. return result;
  351. }
  352. #region 13.0 平衡教材库存数量(适用与出库、入库)
  353. //public void BalanceInventory(IList<ET_StockOutDetail> stockOutDetailList, Guid userId)
  354. //{
  355. // //1.0 提取当前库存量、
  356. // foreach (var stockOutDetailEntity in stockOutDetailList)
  357. // {
  358. // int? stockOutQuantity = stockOutDetailEntity.StockOutQuantity;
  359. // ET_TeachingMateriaInventory teachingMateriaInventoryEntity = GetTeachingMateriaInventory(stockOutDetailEntity.TeachingMaterialPoolID, stockOutDetailEntity.Discount);
  360. // if (teachingMateriaInventoryEntity != null)
  361. // {
  362. // if (teachingMateriaInventoryEntity.PresentInventory <= 0)
  363. // {
  364. // throw new Exception("该教材库存量为0,不能进行出库!");
  365. // }
  366. // if (teachingMateriaInventoryEntity.PresentInventory < stockOutQuantity)
  367. // {
  368. // throw new Exception("出库数量大于当前库存量!");
  369. // }
  370. // //2.0 当前库存量+入库数量 当前库存量-出库数量
  371. // teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory - stockOutQuantity;
  372. // teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
  373. // TeachingMateriaInventoryRepository.UnitOfWork.Update(teachingMateriaInventoryEntity);//更新库存数量
  374. // }
  375. // }
  376. // UnitOfWork.Commit();
  377. //}
  378. #endregion
  379. #region 14.0 教材分组
  380. public void GetTMPList(IList<TeachingMaterialPoolView> tmList, Guid? userId, Guid? stockOutID)
  381. {
  382. //对数据进行分组、单价、教材ID一致、数量累加
  383. var tmListGroupBy = (from tm in tmList
  384. group new { tm } by new
  385. {
  386. tm.TeachingMaterialPoolID,
  387. tm.TeachingMaterialCode,
  388. tm.TeachingMaterialName,
  389. tm.ISBN,
  390. tm.PublishTime,
  391. tm.PublishName,
  392. tm.Author,
  393. tm.Price,
  394. tm.Discount,
  395. tm.DiscountPrice
  396. } into h
  397. select new TeachingMaterialPoolView
  398. {
  399. TeachingMaterialPoolID = h.Key.TeachingMaterialPoolID,
  400. TeachingMaterialCode = h.Key.TeachingMaterialCode,
  401. TeachingMaterialName = h.Key.TeachingMaterialName,
  402. ISBN = h.Key.ISBN,
  403. PublishTime = h.Key.PublishTime,
  404. PublishName = h.Key.PublishName,
  405. Author = h.Key.Author,
  406. Price = h.Key.Price,
  407. Discount = h.Key.Discount,
  408. DiscountPrice = h.Key.DiscountPrice,
  409. OrderQty = h.Sum(x => x.tm.OrderQty)
  410. }).ToList();
  411. List<ET_StockOutDetail> stockOutDetailList = new List<ET_StockOutDetail>();
  412. foreach (var item in tmListGroupBy)
  413. {
  414. ET_StockOutDetail stockOutDetail = new ET_StockOutDetail()
  415. {
  416. CreateTime = DateTime.Now,
  417. CreateUserID = userId,
  418. DiscountPrice = item.Discount,//折扣率
  419. Discount = item.DiscountPrice,//折合价
  420. ModifyTime = DateTime.Now,
  421. ModifyUserID = userId,
  422. RecordStatus = 1,
  423. StockOutDetailID = Guid.NewGuid(),
  424. StockOutID = (Guid)stockOutID,
  425. StockOutQuantity = item.OrderQty,
  426. TeachingMaterialPoolID = item.TeachingMaterialPoolID
  427. };
  428. this.UnitOfWork.Add(stockOutDetail);
  429. }
  430. UnitOfWork.Commit();
  431. }
  432. #endregion
  433. #region 15.0 检查库存
  434. //验证出库单据号是否存在
  435. public bool CheckInventoryQty(int qty, Guid teachingMaterialPoolID)
  436. {
  437. return StockOutDAL.CheckInventoryQty(qty, teachingMaterialPoolID);
  438. }
  439. #endregion
  440. public ET_StockOut GetStockOut(Guid? stockOutID)
  441. {
  442. //查询条件
  443. System.Linq.Expressions.Expression<Func<ET_StockOut, bool>> expression =
  444. (x => x.RecordStatus > (int)SYS_STATUS.UNUSABLE);
  445. expression = (x => x.StockOutID == stockOutID);
  446. return StockOutDAL.StockOutRepository.GetSingle(expression);
  447. }
  448. public ET_StockOutDetail GetStockOutDetail(Guid? stockOutDetailID)
  449. {
  450. //查询条件
  451. System.Linq.Expressions.Expression<Func<ET_StockOutDetail, bool>> expression =
  452. (x => true);
  453. expression = (x => x.StockOutDetailID == stockOutDetailID);
  454. return StockOutDAL.StockOutDetailRepository.GetSingle(expression);
  455. }
  456. public List<ET_TeachingMateriaInventory> GetTeachingMateriaInventory(Guid? teachingMaterialPoolID, decimal? price)
  457. {
  458. //查询条件
  459. System.Linq.Expressions.Expression<Func<ET_TeachingMateriaInventory, bool>> expression =
  460. (x => true);
  461. expression = (x => x.TeachingMaterialPoolID == teachingMaterialPoolID && x.PresentInventory > 0);//出库不按折合价去扣减库存量
  462. return StockOutDAL.TeachingMateriaInventoryRepository.GetList(expression,(x => x.CF_TeachingMaterialPool)).ToList();
  463. }
  464. public string GetStockOutNo(CF_StockOutType stockOutType)
  465. {
  466. string prefix = "";
  467. DateTime nowTime = DateTime.Now;
  468. switch (stockOutType)
  469. {
  470. case CF_StockOutType.StudentBook:
  471. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.StudentMaterialStockOutPrifix);
  472. break;
  473. case CF_StockOutType.TeacherBook:
  474. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.TeacherMaterialStockOutPrifix);
  475. break;
  476. case CF_StockOutType.StudentPutOut:
  477. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.DistributeMaterialStockOutPrifix);
  478. break;
  479. case CF_StockOutType.TeacherPutOut:
  480. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.TeacherDistributeMaterialStockOutPrifix);
  481. break;
  482. case CF_StockOutType.TeachingMaterialRetail:
  483. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.MaterialSaleStockOutPrifix);
  484. break;
  485. case CF_StockOutType.Refund:
  486. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.MaterialRefundStockOutPrifix);
  487. break;
  488. }
  489. var matchFormatterList = Regex.Matches(prefix, @"\{[\S]*\}");
  490. for (int i = 0; i < matchFormatterList.Count; i++)
  491. {
  492. var formatter = matchFormatterList[i].Value.TrimStart('{').TrimEnd('}');
  493. var dateString = nowTime.ToString(formatter);
  494. prefix = prefix.Replace(matchFormatterList[i].Value, dateString);
  495. }
  496. string stockOutNo = SerialNumberServices.Value.SetSN(prefix, 4);
  497. return stockOutNo;
  498. }
  499. }
  500. }