/// <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="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); }