StockInServices.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  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 System.Linq.Expressions;
  12. using Bowin.Common.Linq;
  13. using EMIS.DataLogic.Common.ProcurementPlan;
  14. using EMIS.CommonLogic.SystemServices;
  15. using System.Text.RegularExpressions;
  16. namespace EMIS.CommonLogic.TeachingMaterial
  17. {
  18. public class StockInServices : BaseServices, IStockInServices
  19. {
  20. public StockInDAL StockInDAL { get; set; }
  21. public PurchasingStatisticsDAL PurchasingStatisticsDAL { get; set; }
  22. public Lazy<ITeachersOrderServices> TeachersOrderServices { get; set; }
  23. public Lazy<IParameterServices> ParameterServices { get; set; }
  24. public Lazy<ISerialNumberServices> SerialNumberServices { get; set; }
  25. #region --0.0 定义--
  26. public TeachersOrderRepository TeachersOrderRepository { get; set; }
  27. public StockInRepository StockInRepository { get; set; }
  28. public StockInDetailRepository StockInDetailRepository { get; set; }
  29. public SchoolyearRepository SchoolyearRepository { get; set; }
  30. public UserRepository UserRepository { get; set; }
  31. public TeachingMaterialPoolRepository TeachingMaterialPoolRepository { get; set; }
  32. public CoursematerialRepository CoursematerialRepository { get; set; }
  33. public PublishRepository PublishRepository { get; set; }
  34. public CollegeRepository CollegeRepository { get; set; }
  35. public DictionaryItemRepository DictionaryItemRepository { get; set; }
  36. public TeachingMateriaInventoryRepository TeachingMateriaInventoryRepository { get; set; }
  37. #endregion
  38. #region 1.0 查询入库信息
  39. public Bowin.Common.Linq.Entity.IGridResultSet<StockInView> GetStockInViewGrid(ViewModel.ConfiguretView configuretView,
  40. Guid? schoolyearID, Guid? supplierID, DateTime? stockInDJTimeStart, DateTime? stockInDJTimeEnd, int? isLate, IList<int?> stockInTypeIDList,
  41. int pageIndex, int pageSize)
  42. {
  43. if (stockInDJTimeStart == null)
  44. {
  45. stockInDJTimeStart = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));
  46. }
  47. var query = StockInDAL.GetStockInGridView(x => stockInTypeIDList.Contains(x.StockInType));
  48. if (isLate.HasValue&& isLate >= 0)
  49. {
  50. query = query.Where(x => x.RecordStatus == isLate);
  51. }
  52. if (schoolyearID.HasValue)
  53. query = query.Where(x => x.SchoolyearID == schoolyearID);
  54. if (supplierID.HasValue)
  55. query = query.Where(x => x.SupplierID == supplierID);
  56. if (stockInDJTimeStart.HasValue)
  57. query = query.Where(x => x.StockInDJTime >= stockInDJTimeStart);
  58. if (stockInDJTimeEnd.HasValue)
  59. {
  60. DateTime newStockOutTimeEnd = stockInDJTimeEnd.Value.AddDays(1);//取起止日期一天、
  61. query = query.Where(x => x.StockInDJTime <= newStockOutTimeEnd);
  62. }
  63. // query = GetQueryByDataRangeByCollege(query);//区分院系数据
  64. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  65. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.StockInDJTime).ToGridResultSet<StockInView>(pageIndex, pageSize);
  66. return query.OrderBy(x => x.SchoolyearName).OrderBy(x => x.StockInDocumentNo).OrderByDescending(x => x.StockInDJTime).ToGridResultSet<StockInView>(pageIndex, pageSize);
  67. }
  68. #endregion
  69. #region 2.0 查询教材信息
  70. public IGridResultSet<TeachingMaterialPoolView> GetStockInByTeachingMaterialPoolViewGrid(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? teachingMaterialPoolID, Guid? teachingMaterialCodeID, decimal? discount, int pageIndex, int pageSize)
  71. {
  72. var endStatusID = TeachersOrderServices.Value.GetCorrectEndStatus();
  73. Expression<Func<ET_TeachersOrder, bool>> teacherOrderExp = (x => x.ApprovalStatus == endStatusID);
  74. Expression<Func<ET_StudentsOrder, bool>> studentOrderExp = (x => true);
  75. if (schoolyearID.HasValue)
  76. {
  77. teacherOrderExp = teacherOrderExp.And(x => x.SchoolyearID == schoolyearID);
  78. studentOrderExp = studentOrderExp.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  79. }
  80. if (teachingMaterialPoolID.HasValue)
  81. {
  82. teacherOrderExp = teacherOrderExp.And(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
  83. studentOrderExp = studentOrderExp.And(x => x.TeachingMaterialPoolID == teachingMaterialPoolID);
  84. }
  85. if (teachingMaterialCodeID.HasValue)
  86. {
  87. teacherOrderExp = teacherOrderExp.And(x => x.TeachingMaterialPoolID == teachingMaterialCodeID);
  88. studentOrderExp = studentOrderExp.And(x => x.TeachingMaterialPoolID == teachingMaterialCodeID);
  89. }
  90. var query = StockInDAL.GetTeachingMaterial(x => x.IsLate == false, 1);
  91. if (discount.HasValue)
  92. {
  93. query = StockInDAL.GetTeachingMaterial(x => x.IsLate == false, discount);//获取不过期数据
  94. }
  95. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  96. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
  97. return query.OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToGridResultSet<TeachingMaterialPoolView>(pageIndex, pageSize);
  98. }
  99. #endregion
  100. #region 3.0 保存
  101. public void Save(StockInView stockInView, IList<TeachingMaterialPoolView> tmList, Guid? userId, string type)
  102. {
  103. if (this.StockInRepository.GetList(x => x.StockInDocumentNo == stockInView.StockInDocumentNo
  104. && x.StockInID != stockInView.StockInID).Count() > 0)
  105. {
  106. throw new Exception("入库单号已经存在,请重新输入!");
  107. }
  108. int RecordStatusType = (int)CF_GeneralPurpose.IsNo;
  109. if (type == "Submit")//如果是Save 那么状态默认为0、 如果是Submit 那么状态默认1
  110. {
  111. RecordStatusType = (int)CF_GeneralPurpose.IsYes;
  112. }
  113. ET_StockIn stockInEntity = StockInRepository.GetSingle(x => x.StockInID == stockInView.StockInID);
  114. if (stockInEntity != null)
  115. {
  116. stockInEntity.Desc = stockInView.Desc;
  117. stockInEntity.SchoolyearID = stockInView.SchoolyearID;
  118. stockInEntity.StockInTime = (DateTime)stockInView.StockInDJTime;
  119. stockInEntity.StockInDocumentNo = stockInView.StockInDocumentNo;
  120. stockInEntity.SupplierID = (Guid)stockInView.SupplierID;
  121. stockInEntity.StockInNumber = stockInView.StockInNumber;
  122. stockInEntity.RecordStatus = RecordStatusType;
  123. StockInRepository.UnitOfWork.Update(stockInEntity);
  124. // StockInRepository.UnitOfWork.Commit();
  125. //删除明细数据、重新插入
  126. StockInDetailRepository.UnitOfWork.Delete<ET_StockInDetail>(x => x.StockInID == stockInView.StockInID);
  127. List<ET_StockInDetail> stockInDetailList = new List<ET_StockInDetail>();
  128. foreach (var item in tmList)
  129. {
  130. ET_StockInDetail stockInDetail = new ET_StockInDetail()
  131. {
  132. CreateTime = DateTime.Now,
  133. CreateUserID = userId,
  134. Desc = stockInView.Desc,
  135. Discount = item.Discount,
  136. LibraryID = null,//stockInView.LibraryID,,
  137. ModifyTime = DateTime.Now,
  138. ModifyUserID = userId,
  139. DiscountPrice = item.Discount * item.Price,//折合价
  140. Quantity = item.OrderQty,
  141. RecordStatus = RecordStatusType,
  142. StockInDetailID = Guid.NewGuid(),
  143. StockInID = stockInView.StockInID,
  144. TeachingMaterialPoolID = item.TeachingMaterialPoolID
  145. };
  146. UnitOfWork.Add(stockInDetail);
  147. }
  148. }
  149. else
  150. {
  151. ET_StockIn stockIn = new ET_StockIn()
  152. {
  153. StockInID = Guid.NewGuid(),
  154. Desc = stockInView.Desc,
  155. StockInType = stockInView.StockInType,
  156. CreateTime = DateTime.Now,
  157. CreateUserID = userId,
  158. SchoolyearID = stockInView.SchoolyearID,
  159. ModifyTime = DateTime.Now,
  160. ModifyUserID = userId,
  161. HandlerUserID = userId,
  162. OrdersNo = stockInView.OrdersNo,
  163. RecordStatus = RecordStatusType,
  164. StockInSumMoney = stockInView.StockInSumMoney,
  165. StockInTime = (DateTime)stockInView.StockInDJTime,
  166. StockInNumber = stockInView.StockInNumber,
  167. StockInDocumentNo = stockInView.StockInDocumentNo,
  168. SupplierID = (Guid)stockInView.SupplierID
  169. };
  170. UnitOfWork.Add(stockIn);
  171. List<ET_StockInDetail> stockInDetailList = new List<ET_StockInDetail>();
  172. foreach (var item in tmList)
  173. {
  174. ET_StockInDetail stockInDetail = new ET_StockInDetail()
  175. {
  176. CreateTime = DateTime.Now,
  177. CreateUserID = userId,
  178. Desc = stockInView.Desc,
  179. Discount = item.Discount,
  180. LibraryID = null,//stockInView.LibraryID,
  181. ModifyTime = DateTime.Now,
  182. ModifyUserID = userId,
  183. DiscountPrice = item.Discount * item.Price,//折合价
  184. Quantity = item.OrderQty,
  185. RecordStatus = RecordStatusType,
  186. StockInDetailID = Guid.NewGuid(),
  187. StockInID = stockIn.StockInID,
  188. TeachingMaterialPoolID = item.TeachingMaterialPoolID
  189. };
  190. UnitOfWork.Add(stockInDetail);
  191. }
  192. }
  193. UnitOfWork.Commit();
  194. }
  195. #endregion
  196. #region 4.0 Excel 查询
  197. public IList<StockInView> GetStockInViewList(ViewModel.ConfiguretView configuretView, Guid? schoolyearID, Guid? supplierID, DateTime? stockInDJTimeStart, DateTime? stockInDJTimeEnd, int? isLate, IList<int?> stockInTypeIDList)
  198. {
  199. DateTime newStockOutTimeEnd = stockInDJTimeEnd.Value.AddDays(1);//取起止日期一天、
  200. var query = StockInDAL.GetStockInGridView(x => stockInTypeIDList.Contains(x.StockInType));
  201. if (isLate.HasValue && isLate > 0)
  202. {
  203. query = query.Where(x => x.RecordStatus == isLate);
  204. }
  205. if (schoolyearID.HasValue)
  206. query = query.Where(x => x.SchoolyearID == schoolyearID);
  207. if (supplierID.HasValue)
  208. query = query.Where(x => x.SupplierID == supplierID);
  209. if (stockInDJTimeStart.HasValue)
  210. query = query.Where(x => x.StockInDJTime >= stockInDJTimeStart);
  211. if (stockInDJTimeEnd.HasValue)
  212. query = query.Where(x => x.StockInDJTime <= newStockOutTimeEnd);
  213. if (!string.IsNullOrEmpty(configuretView.ConditionValue))
  214. return query.DynamicWhere(configuretView.Attribute, configuretView.Condition, configuretView.ConditionValue).OrderBy(x => x.StockInDJTime).ToList();
  215. return query.OrderBy(x => x.StockInDJTime).ToList();
  216. }
  217. #endregion
  218. #region 5.0 删除
  219. /// <summary>
  220. /// 删除入库信息
  221. /// </summary>
  222. /// <param name="stockInIDs"></param>
  223. public void Delete(List<Guid> stockInIDs)
  224. {
  225. try
  226. {
  227. var stockInList = StockInRepository.GetList(x => stockInIDs.Contains(x.StockInID)).ToList();
  228. foreach (var stockIn in stockInList)
  229. {
  230. if (stockIn.RecordStatus == (int)SYS_STATUS.USABLE)
  231. {
  232. throw new Exception("选择的信息已入库,无法删除。");
  233. }
  234. }
  235. if (stockInIDs.Count > 0)
  236. {
  237. //删除入库数据、及该单号下挂钩的明细数据
  238. StockInDetailRepository.UnitOfWork.Delete<ET_StockInDetail>(x => stockInIDs.Contains(x.StockInID));
  239. StockInRepository.UnitOfWork.Delete<ET_StockIn>(x => stockInIDs.Contains(x.StockInID));
  240. }
  241. }
  242. catch (Exception ex)
  243. {
  244. throw ex;
  245. }
  246. }
  247. #endregion
  248. #region 6.0 获取编辑信息
  249. /// <summary>
  250. /// 获取编辑数据
  251. /// </summary>
  252. /// <param name="stockInID"></param>
  253. /// <returns></returns>
  254. public StockInView GetSingleStockIn(Guid stockInID)
  255. {
  256. return StockInDAL.GetSingleStockIn(stockInID);
  257. }
  258. #endregion
  259. #region 7.0 获取要入库的教材信息
  260. public IList<TeachingMaterialPoolView> GetStockInByTMViewList(Guid stockInID)
  261. {
  262. return StockInDAL.GetTeachingMaterialView(stockInID).OrderBy(x => x.TeachingMaterialCode.Length).ThenBy(x => x.TeachingMaterialCode).ToList();
  263. }
  264. #endregion
  265. #region 8.0 废弃的提交
  266. public void Submit(List<Guid> stockInIDs, Guid userId)
  267. {
  268. try
  269. {
  270. if (stockInIDs.Count > 0)
  271. {
  272. var stockInList = StockInRepository.GetList(x => stockInIDs.Contains(x.StockInID), (x => x.ET_StockInDetail)).ToList();
  273. foreach (var stockInEnity in stockInList)
  274. {
  275. if (stockInEnity.RecordStatus == (int)CF_GeneralPurpose.IsYes)
  276. {
  277. throw new Exception("选择的信息已提交,无法重复提交。");
  278. }
  279. }
  280. foreach (var stockInEnity in stockInList)
  281. {
  282. stockInEnity.RecordStatus = (int)CF_GeneralPurpose.IsYes;
  283. StockInRepository.UnitOfWork.Update(stockInEnity);
  284. StockInRepository.UnitOfWork.Commit();
  285. IList<ET_StockInDetail> stockInDetailList = stockInEnity.ET_StockInDetail.ToList();
  286. BalanceInventory(stockInDetailList, userId);//提交平衡库存
  287. }
  288. }
  289. }
  290. catch (Exception ex)
  291. {
  292. throw ex;
  293. }
  294. }
  295. #endregion
  296. #region 9.0 检验入库单据编号是否存在
  297. /// <summary>
  298. /// 检验入库单据编号是否存在
  299. /// </summary>
  300. /// <param name="stockInDocumentNo"></param>
  301. /// <returns></returns>
  302. public bool IsExistStockInDocumentNo(string stockInDocumentNo)
  303. {
  304. return StockInDAL.IsExistStockInDocumentNo(stockInDocumentNo);
  305. }
  306. #endregion
  307. #region 11.0 平衡教材库存数量(适用与出库、入库)
  308. public void BalanceInventory(IList<ET_StockInDetail> stockInDetailList, Guid userId)
  309. {
  310. //1.0 提取当前库存量、
  311. foreach (var stockInDetail in stockInDetailList)
  312. {
  313. ET_TeachingMateriaInventory teachingMateriaInventoryEntity = TeachingMateriaInventoryRepository.GetSingle(x => x.TeachingMaterialPoolID == stockInDetail.TeachingMaterialPoolID && x.Discount == stockInDetail.DiscountPrice);
  314. if (teachingMateriaInventoryEntity != null)
  315. {
  316. //2.0 当前库存量+入库数量 当前库存量-出库数量
  317. teachingMateriaInventoryEntity.PresentInventory = teachingMateriaInventoryEntity.PresentInventory + stockInDetail.Quantity;
  318. teachingMateriaInventoryEntity.ModifyTime = DateTime.Now;
  319. TeachingMateriaInventoryRepository.UnitOfWork.Update(teachingMateriaInventoryEntity);//更新库存数量
  320. }
  321. else
  322. {
  323. ET_TeachingMateriaInventory teachingMateriaInventoryEnt = new ET_TeachingMateriaInventory
  324. {
  325. PresentInventory = stockInDetail.Quantity,
  326. TeachingMateriaInventoryID = Guid.NewGuid(),
  327. CreateTime = DateTime.Now,
  328. CreateUserID = userId,
  329. Discount = stockInDetail.Discount,
  330. DiscountPrice = stockInDetail.DiscountPrice,
  331. ModifyTime = DateTime.Now,
  332. ModifyUserID = userId,
  333. TeachingMaterialPoolID = (Guid)stockInDetail.TeachingMaterialPoolID
  334. };
  335. TeachingMateriaInventoryRepository.UnitOfWork.Add(teachingMateriaInventoryEnt);
  336. }
  337. }
  338. UnitOfWork.Commit();
  339. }
  340. #endregion
  341. #region 12.0 自动生成入库信息
  342. public void AutoNewStockIn(Guid? schoolyearID, Guid? userId)
  343. {
  344. var endStatusID = TeachersOrderServices.Value.GetCorrectEndStatus();
  345. Expression<Func<ET_TeachersOrder, bool>> exporder = (x => x.ApprovalStatus == endStatusID);
  346. Expression<Func<ET_StudentsOrder, bool>> stuExporder = (x => true);
  347. Expression<Func<CF_TeachingMaterialPool, bool>> poolexp = (x => true);
  348. if (schoolyearID.HasValue)
  349. {
  350. exporder = exporder.And(x => x.SchoolyearID == schoolyearID);
  351. stuExporder = stuExporder.And(x => x.EM_SpecialtyPlan.SchoolyearID == schoolyearID);
  352. }
  353. var Purchasingquery = PurchasingStatisticsDAL.GetPurchasingStatisticsGridView(exporder, stuExporder);
  354. List<PurchasingStatisticsView> purchasingList = Purchasingquery.ToList();//获取一个学期下所有采购信息
  355. var StockInquery = StockInDAL.GetStockInGridView(x => true);
  356. if (schoolyearID.HasValue)
  357. {
  358. StockInquery = StockInquery.Where(x => x.SchoolyearID == schoolyearID);
  359. }
  360. List<StockInView> stockInList = StockInquery.ToList();
  361. List<Guid> TeachingMaterialPoolIDList = new List<Guid>();
  362. List<Guid> stockinIDList = stockInList.Select(x => x.StockInID).ToList();
  363. var teachingMaterialPoolViewList = StockInDAL.GetDetailByIDList(stockinIDList).ToList();
  364. List<PurchasingStatisticsView> purchasingList1 = new List<PurchasingStatisticsView>();
  365. List<PurchasingStatisticsView> a = new List<PurchasingStatisticsView>();
  366. foreach (PurchasingStatisticsView purchasing in purchasingList)
  367. {
  368. //判断这个学期下是否已经有入库信息,有的就排除。
  369. if (stockInList != null)
  370. {
  371. foreach (StockInView stockIn in stockInList)
  372. {
  373. var teachingMaterialPoolView = teachingMaterialPoolViewList.Where(x => x.StockInID == stockIn.StockInID);
  374. foreach (var view in teachingMaterialPoolView)
  375. {
  376. if (view.TeachingMaterialPoolID == purchasing.TeachingMaterialPoolID)
  377. {
  378. TeachingMaterialPoolIDList.Add(purchasing.TeachingMaterialPoolID);//获取已有入库信息的教材ID
  379. }
  380. };
  381. };
  382. }
  383. };
  384. List<Guid> id = TeachingMaterialPoolIDList.Distinct().ToList<Guid>();
  385. List<TeachingMaterialPoolView> tmList = new List<TeachingMaterialPoolView>();
  386. var supplier = StockInDAL.SupplierDiscountSetRepository.GetList(x => x.IsDefault == true).FirstOrDefault();
  387. var query = StockInDAL.GetTeachersOrderByTeachingMaterial(x => x.IsLate == false, exporder, stuExporder);
  388. purchasingList1 = Purchasingquery.Where(x => id.All(y => y!=x.TeachingMaterialPoolID)).ToList();
  389. tmList = StockInDAL.GetTeachersOrderByTeachingMaterial(poolexp, exporder, stuExporder).Where(x => id.All(y => y != x.TeachingMaterialPoolID)).ToList();
  390. //foreach (var MateriaPoolID in id)
  391. //{
  392. // //purchasingList = null;
  393. // //PurchasingStatisticsView view = Purchasingquery.Where(x => x.TeachingMaterialPoolID != MateriaPoolID).FirstOrDefault();
  394. // //purchasingList1.Add(view);//排除掉已有的入库信息
  395. // poolexp = poolexp.And(x => x.TeachingMaterialPoolID == MateriaPoolID);
  396. // TeachingMaterialPoolView pool = StockInDAL.GetTeachersOrderByTeachingMaterial(poolexp, exporder, stuExporder).FirstOrDefault();//根据教材总库ID获取教材信息
  397. // tmList.Add(pool);
  398. //};
  399. string datestr = DateTime.Now.ToString("yyyyMMdd");
  400. var stockInNumber = this.GetStockInNo(CF_StockInType.PurchasingStockIn);
  401. var numStr = stockInNumber.Remove(0, stockInNumber.Length - 4);
  402. var num = int.Parse(numStr);
  403. var noStr = stockInNumber.Remove(stockInNumber.Length - 4);
  404. int count = 0;
  405. foreach (PurchasingStatisticsView pur in purchasingList1)
  406. {
  407. string stockInNumberstr = noStr + num.ToString("0000");
  408. ET_StockIn NewstockIn = new ET_StockIn()
  409. {
  410. StockInID = Guid.NewGuid(),
  411. Desc = "",//
  412. StockInType = (int)CF_StockInType.PurchasingStockIn,
  413. CreateTime = DateTime.Now,
  414. CreateUserID = userId,
  415. SchoolyearID = schoolyearID,
  416. ModifyTime = DateTime.Now,
  417. ModifyUserID = userId,
  418. HandlerUserID = userId,
  419. OrdersNo = null,//
  420. RecordStatus = 0,
  421. StockInSumMoney = Math.Round((decimal)(pur.Price * supplier.Discount * pur.CountNumber), 2),//
  422. StockInTime = DateTime.Now,//
  423. StockInNumber = datestr + num.ToString("0000"),//入库编号
  424. StockInDocumentNo = stockInNumberstr,//入库单据号
  425. SupplierID = supplier == null ? null : supplier.PublishID,
  426. };
  427. num += 1;
  428. count += 1;
  429. UnitOfWork.Add(NewstockIn);
  430. foreach (var item in tmList.Where(x => x.TeachingMaterialPoolID == pur.TeachingMaterialPoolID))
  431. {
  432. List<ET_StockInDetail> stockInDetailList = new List<ET_StockInDetail>();
  433. ET_StockInDetail stockInDetail = new ET_StockInDetail()
  434. {
  435. CreateTime = DateTime.Now,
  436. CreateUserID = userId,
  437. Desc = "",//
  438. Discount = supplier == null ? 1 : supplier.Discount,
  439. LibraryID = null,//stockInView.LibraryID,
  440. ModifyTime = DateTime.Now,
  441. ModifyUserID = userId,
  442. DiscountPrice = (supplier == null ? 1 : supplier.Discount) * pur.Price,//折合价
  443. Quantity = pur.CountNumber,
  444. RecordStatus = 0,
  445. StockInDetailID = Guid.NewGuid(),
  446. StockInID = NewstockIn.StockInID,
  447. TeachingMaterialPoolID = item.TeachingMaterialPoolID
  448. };
  449. UnitOfWork.Add(stockInDetail);
  450. };
  451. };
  452. string prefix = "";
  453. DateTime nowTime = DateTime.Now;
  454. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.PurchaseStockInPrifix);
  455. var matchFormatterList = Regex.Matches(prefix, @"\{[\S]*\}");
  456. for (int i = 0; i < matchFormatterList.Count; i++)
  457. {
  458. var formatter = matchFormatterList[i].Value.TrimStart('{').TrimEnd('}');
  459. var dateString = nowTime.ToString(formatter);
  460. prefix = prefix.Replace(matchFormatterList[i].Value, dateString);
  461. }
  462. UnitOfWork.Commit();
  463. SerialNumberServices.Value.SkipSN(prefix, count - 1);
  464. }
  465. #endregion
  466. public string GetStockInNo(CF_StockInType stockInType)
  467. {
  468. string prefix = "";
  469. DateTime nowTime = DateTime.Now;
  470. switch (stockInType)
  471. {
  472. case CF_StockInType.PurchasingStockIn:
  473. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.PurchaseStockInPrifix);
  474. break;
  475. case CF_StockInType.Return:
  476. prefix = ParameterServices.Value.GetParameterValue(CF_ParameterType.ReturnStockInPrifix);
  477. break;
  478. }
  479. var matchFormatterList = Regex.Matches(prefix, @"\{[\S]*\}");
  480. for (int i = 0; i < matchFormatterList.Count; i++)
  481. {
  482. var formatter = matchFormatterList[i].Value.TrimStart('{').TrimEnd('}');
  483. var dateString = nowTime.ToString(formatter);
  484. prefix = prefix.Replace(matchFormatterList[i].Value, dateString);
  485. }
  486. string stockOutNo = SerialNumberServices.Value.SetSN(prefix, 4);
  487. return stockOutNo;
  488. }
  489. }
  490. }