/// <summary> /// 删除 /// </summary> /// <param name="purchase"></param> /// <returns></returns> public int RemovePurchase(WPurchase purchase) { //查询明细 if (purchase.Lines.Count < 1) { purchase.Lines = plRepository.GetLinesByParentId(purchase.ID); } DatabaseContext db = pRepository.DbCondext; try { db.BeginTransaction(); //删除其他出库 int result = pRepository.RemovePurchaseByStatus(purchase.ID, StockStatusEnum.New); if (result > 0) { foreach (WPurchaseLine line in purchase.Lines) { if (line.SourceLineID > 0) { //删除下推 pnlRepository.RemoveDownCount(line.InCount, line.SourceLineID); } } plRepository.RemoveLinesByParentId(purchase.ID); } db.CompleteTransaction(); return(result); } catch (Exception ex) { db.AbortTransaction(); throw ex; } }
/// <summary> /// 根据入库单下推出库单 /// </summary> /// <param name="purchase"></param> /// <returns></returns> public ResultData <string> AddPurchaseReturn(WPurchase purchase, int createBy) { ResultData <string> rData = new ResultData <string>(); if (purchase.StockStatus != StockStatusEnum.Approve) { rData.status = -1; rData.message = "单据未审核不能退库."; return(rData); } //查询明细 if (purchase.Lines.Count < 1) { purchase.Lines = plRepository.GetLinesByParentId(purchase.ID); } //克隆主表 WPurchaseReturn purReturn = ClonePuchase(purchase); purReturn.CreateBy = createBy; //克隆子表 foreach (var item in purchase.Lines) { WPurchaseReturnLine line = ClonePurchaseLine(item); if (line != null) { purReturn.Lines.Add(line); } } if (purReturn.Lines.Count < 1) { rData.status = -1; rData.message = "单据已经全部退库."; return(rData); } DatabaseContext dbContext = pRepository.DbCondext; try { dbContext.BeginTransaction(); //添加入库单 purReturn.CreateDate = DateTime.Now; purReturn.StockStatus = StockStatusEnum.New; purReturn.PurchaseReturnCode = nuRepository.GetNextNumber("CGTK"); prRepository.Insert(purReturn); foreach (var line in purReturn.Lines) { //插入入库明细 line.ParentID = purReturn.ID; line.CreateBy = purReturn.CreateBy; line.CreateDate = DateTime.Now; line.Batch = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch; prlRepository.Insert(line); //更新入库单 添加退库 decimal rt = plRepository.AddReturnCount(line.OutCount, line.SourceLineID); if (rt < 0) { dbContext.AbortTransaction(); rData.status = -1; rData.message = BuilderNoticeLessMessage(line); return(rData); } } //将插入主键赋值给返回值 rData.result = purReturn.ID.ToString(); dbContext.CompleteTransaction(); } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } return(rData); }