/// <summary> /// 审核 /// </summary> /// <param name="transferOut"></param> /// <returns></returns> public ResultData <string> ApproveTransferOut(WTransferOut transferOut) { ResultData <string> rData = new ResultData <string>(); if (transferOut.Lines.Count < 1) { transferOut.Lines = tolRepository.GetLinesByParentId(transferOut.ID); } DatabaseContext dbContext = toRepository.DbCondext; try { dbContext.BeginTransaction(); //出库记录 List <WStockOut> stockOuts = new List <WStockOut>(transferOut.Lines.Count); //审核 int result = toRepository.ApproveTransferOut(transferOut); if (result < 1) { rData.status = -1; rData.message = "单据已经审核或删除."; dbContext.AbortTransaction(); return(rData); } foreach (var line in transferOut.Lines) { stockOuts.Add(CloneTransferOut(line, transferOut)); } //更新库存 WStockService sService = new WStockService(dbContext); rData = sService.DeleteStocks(stockOuts); if (rData.status != 0) { dbContext.AbortTransaction(); } else { dbContext.CompleteTransaction(); } } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } if (rData.status == 0) { //调拨入库通知单 WTransferInNotice inNotice = CloneInNotice(transferOut); rData = new WTransferInNoticeService().AddTransferInNotice(inNotice); } return(rData); }
/// <summary> /// 审核 /// </summary> /// <param name="purReturn"></param> /// <returns></returns> public ResultData <string> ApprovePurchaseReturn(WPurchaseReturn purReturn) { if (purReturn.Lines.Count < 1) { purReturn.Lines = prlRepository.GetLinesByParentId(purReturn.ID); } ResultData <string> rData = CheckValid(purReturn); if (rData.status != 0) { return(rData); } DatabaseContext dbContext = prRepository.DbCondext; try { dbContext.BeginTransaction(); //出库记录 List <WStockOut> stockOuts = new List <WStockOut>(purReturn.Lines.Count); //添加其他出库 int result = prRepository.ApprovePurchaseReturn(purReturn); if (result < 1) { rData.status = -1; rData.message = "单据已经审核或删除."; dbContext.AbortTransaction(); return(rData); } foreach (var line in purReturn.Lines) { stockOuts.Add(ClonePurchaseReturn(line, purReturn)); } //更新库存 WStockService sService = new WStockService(dbContext); rData = sService.DeleteStocks(stockOuts); if (rData.status != 0) { dbContext.AbortTransaction(); } else { dbContext.CompleteTransaction(); } } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } return(rData); }
/// <summary> /// 审核 /// </summary> /// <param name="sellReturn"></param> /// <returns></returns> public ResultData <string> ApproveSellReturn(WSellReturn sellReturn) { ResultData <string> rData = new ResultData <string>(); if (sellReturn.Lines.Count < 1) { sellReturn.Lines = srlRepository.GetLinesByParentId(sellReturn.ID); } DatabaseContext dbContext = srRepository.DbCondext; try { dbContext.BeginTransaction(); //入库记录 List <WStockIn> stockIns = new List <WStockIn>(sellReturn.Lines.Count); //添加其他入库 int result = srRepository.ApproveSellReturn(sellReturn); if (result < 1) { rData.status = -1; rData.message = "单据已经审核或删除."; dbContext.AbortTransaction(); return(rData); } foreach (var line in sellReturn.Lines) { stockIns.Add(CloneSellReturn(line, sellReturn)); } //更新库存 WStockService sService = new WStockService(dbContext); rData = sService.AddStocks(stockIns); if (rData.status != 0) { dbContext.AbortTransaction(); } else { dbContext.CompleteTransaction(); } } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } return(rData); }
/// <summary> /// 审核 /// </summary> /// <param name="otherOut"></param> /// <returns></returns> public ResultData <string> ApproveOtherOut(WOtherOut otherOut) { ResultData <string> rData = new ResultData <string>(); if (otherOut.Lines.Count < 1) { otherOut.Lines = oolRepository.GetLinesByParentId(otherOut.ID); } DatabaseContext dbContext = ooRepository.DbCondext; try { dbContext.BeginTransaction(); //出库记录 List <WStockOut> stockOuts = new List <WStockOut>(otherOut.Lines.Count); //添加其他出库 int result = ooRepository.ApproveOtherOut(otherOut); if (result < 1) { rData.status = -1; rData.message = "单据已经审核或删除."; dbContext.AbortTransaction(); return(rData); } foreach (var line in otherOut.Lines) { stockOuts.Add(CloneOtherOut(line, otherOut)); } //更新库存 WStockService sService = new WStockService(dbContext); rData = sService.DeleteStocks(stockOuts); if (rData.status != 0) { dbContext.AbortTransaction(); } else { dbContext.CompleteTransaction(); } } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } return(rData); }
/// <summary> /// 审核 /// </summary> /// <param name="sell"></param> /// <returns></returns> public ResultData <string> ApproveSell(WSell sell) { if (sell.Lines.Count < 1) { sell.Lines = slRepository.GetLinesByParentId(sell.ID); } ResultData <string> rData = CheckValid(sell); if (rData.status != 0) { return(rData); } DatabaseContext dbContext = sRepository.DbCondext; try { dbContext.BeginTransaction(); //出库记录 List <WStockOut> stockOuts = new List <WStockOut>(sell.Lines.Count); //添加其他出库 int result = sRepository.ApproveSell(sell); if (result < 1) { rData.status = -1; rData.message = "单据已经审核或删除."; dbContext.AbortTransaction(); return(rData); } foreach (var line in sell.Lines) { stockOuts.Add(CloneSell(line, sell)); //添加完成数量 if (line.SourceLineID > 0) { snlRepository.AddCompleteCount(line.SourceLineID, line.OutCount); } } //更新库存 WStockService sService = new WStockService(dbContext); rData = sService.DeleteStocks(stockOuts); if (rData.status != 0) { dbContext.AbortTransaction(); } else { dbContext.CompleteTransaction(); } } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } return(rData); }
/// <summary> /// 审核 /// </summary> /// <param name="purchase"></param> /// <returns></returns> public ResultData <string> ApprovePurchase(WPurchase purchase) { if (purchase.Lines.Count < 1) { purchase.Lines = plRepository.GetLinesByParentId(purchase.ID); } ResultData <string> rData = CheckValid(purchase); if (rData.status != 0) { return(rData); } DatabaseContext dbContext = pRepository.DbCondext; try { dbContext.BeginTransaction(); //入库记录 List <WStockIn> stockIns = new List <WStockIn>(purchase.Lines.Count); //更新主表状态 int result = pRepository.ApprovePurchase(purchase); if (result < 1) { rData.status = -1; rData.message = "单据已经审核或删除."; dbContext.AbortTransaction(); return(rData); } foreach (var line in purchase.Lines) { stockIns.Add(ClonePurchase(line, purchase)); //添加完成数量 if (line.SourceLineID > 0) { pnlRepository.AddCompleteCount(line.SourceLineID, line.InCount); } } //更新库存 WStockService sService = new WStockService(dbContext); rData = sService.AddStocks(stockIns); if (rData.status != 0) { dbContext.AbortTransaction(); } //更新通知单状态 if (purchase.SourceID > 0) { bool isAll = pnlRepository.IsAllComplete(purchase.SourceID); if (isAll) { pnRepository.UpdateNoticeStatus(NoticeStatusEnum.Complete, purchase.SourceID); } } dbContext.CompleteTransaction(); } catch (Exception ex) { dbContext.AbortTransaction(); throw ex; } return(rData); }