public ResultModel Audit(UserModel user, NFMT.WorkFlow.Model.DataSource dataSource, bool isPass) { ResultModel result = new ResultModel(); try { DAL.StockDAL stockDAL = new StockDAL(); DAL.StockLogDAL stockLogDAL = new StockLogDAL(); DAL.StockOutDetailDAL detailDAL = new StockOutDetailDAL(); DAL.StockNameDAL stockNameDAL = new StockNameDAL(); DAL.StockOutApplyDAL stockOutApplyDAL = new StockOutApplyDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = this.stockoutDAL.Get(NFMT.Common.DefaultValue.SysUser, dataSource.RowId); if (result.ResultStatus != 0) return result; Model.StockOut stockOut = result.ReturnValue as Model.StockOut; if (stockOut == null || stockOut.StockOutId <= 0) { result.ResultStatus = -1; result.Message = "出库不存在"; return result; } //审核,修改数据状态 result = this.stockoutDAL.Audit(user, stockOut, isPass); if (result.ResultStatus != 0) return result; //审核通过 if (isPass) { //流水操作:写入 流水类型:出库 流水状态:已生效 库存操作:更新 库存状态:预售库存 //获取出库申请 result = stockOutApplyDAL.Get(user,stockOut.StockOutApplyId); if(result.ResultStatus!=0) return result; Model.StockOutApply stockOutApply = result.ReturnValue as Model.StockOutApply; if(stockOutApply == null || stockOutApply.StockOutApplyId<=0) { result.ResultStatus = -1; result.Message = "出库申请获取失败"; return result; } //获取出库明细 result = detailDAL.Load(user, stockOut.StockOutId); if (result.ResultStatus != 0) return result; List<Model.StockOutDetail> outDetails = result.ReturnValue as List<Model.StockOutDetail>; if (outDetails == null) { result.ResultStatus = -1; result.Message = "出库明细获取失败"; return result; } foreach (Model.StockOutDetail outDetail in outDetails) { //获取库存 result = stockDAL.Get(user, outDetail.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "出库库存不存在"; return result; } //获取业务单 result = stockNameDAL.Get(user,stock.StockNameId); if(result.ResultStatus!=0) return result; Model.StockName stockName = result.ReturnValue as Model.StockName; if(stockName == null || stockName.StockNameId <=0) { result.ResultStatus = -1; result.Message = "业务单号获取失败"; return result; } //出库净重==当前净重时 库存状态更新至 预售库存 if (outDetail.NetAmount == stock.CurNetAmount) { result = stockDAL.UpdateStockStatus(stock, StockStatusEnum.预售库存); if (result.ResultStatus != 0) return result; } //写出库流水,流水状态为已生效 Model.StockLog stockLog = new StockLog() { AssetId = stock.AssetId, BrandId = stock.BrandId, CardNo = stock.CardNo, DeliverPlaceId = stock.DeliverPlaceId, GrossAmount = outDetail.GrossAmount, LogDate = DateTime.Now, LogDirection = (int)LogDirectionEnum.Out, LogSource = "dbo.St_StockOutDetail", LogSourceBase = "NFMT", LogStatus = StatusEnum.已生效, LogType = (int)LogTypeEnum.出库, NetAmount = outDetail.NetAmount, MUId = stock.UintId, OpPerson = user.EmpId, PaperHolder = stock.PaperHolder, PaperNo = stock.PaperNo, RefNo = stockName.RefNo, SourceId = outDetail.DetailId, StockId = stock.StockId, StockNameId = stock.StockNameId, SubContractId = stockOutApply.SubContractId, ContractId = stockOutApply.ContractId, Memo = stockOut.Memo, Bundles = outDetail.Bundles }; result = stockLogDAL.Insert(user, stockLog); if (result.ResultStatus != 0) return result; int stockLogId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockLogId) || stockLogId <= 0) { result.ResultStatus = -1; result.Message = "出库流水写入失败"; return result; } //更新出库明细的出库流水 outDetail.StockLogId = stockLogId; result = detailDAL.Update(user, outDetail); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; return result; } return result; }
public ResultModel CreateStockOut(NFMT.Common.UserModel user, int stockOutApplyId, List<int> detailIds, string memo) { ResultModel result = new ResultModel(); try { //dal init DAL.StockDAL stockDAL = new StockDAL(); DAL.StockOutApplyDAL stockOutApplyDAL = new StockOutApplyDAL(); DAL.StockOutApplyDetailDAL stockOutApplyDetailDAL = new StockOutApplyDetailDAL(); DAL.StockOutDAL stockOutDAL = new StockOutDAL(); DAL.StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL(); using (System.Transactions.TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //获取出库申请 result = stockOutApplyDAL.Get(user, stockOutApplyId); if (result.ResultStatus != 0) return result; Model.StockOutApply stockOutApply = result.ReturnValue as Model.StockOutApply; if (stockOutApply == null || stockOutApply.StockOutApplyId <= 0) { result.ResultStatus = -1; result.Message = "出库申请不存在"; return result; } //获取出库申请明细 result = stockOutApplyDetailDAL.Load(user, stockOutApplyId); if (result.ResultStatus != 0) return result; List<Model.StockOutApplyDetail> stockOutApplyDetails = result.ReturnValue as List<Model.StockOutApplyDetail>; if (stockOutApplyDetails == null) { result.ResultStatus = -1; result.Message = "出库申请明细获取失败"; return result; } //判断detailIds 是否都在出库申请明细中 List<int> applyDetails = new List<int>(); foreach (Model.StockOutApplyDetail detail in stockOutApplyDetails) { applyDetails.Add(detail.DetailId); } foreach (int id in detailIds) { if (!applyDetails.Contains(id)) { result.ResultStatus = -1; result.Message = "出库申请不包含选中库存"; return result; } } decimal sumGrossAmount = 0; decimal sumNetAmount = 0; int sumBundles = 0; //验证库存及申请明细 foreach (int id in detailIds) { Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id); if (applyDetail == null || applyDetail.DetailId <= 0) { result.ResultStatus = -1; result.Message = "出库申请不包含选中库存"; return result; } if (applyDetail.DetailStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "选中库存存在已作废状态库存"; return result; } //获取库存 result = stockDAL.Get(user, applyDetail.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //库存状态校验 if (stock.StockStatus != StockStatusEnum.在库正常 && stock.StockStatus != StockStatusEnum.新拆库存 && stock.StockStatus != StockStatusEnum.质押库存) { result.ResultStatus = -1; result.Message = "库存不允许出库,出库失败"; return result; } sumGrossAmount += applyDetail.GrossAmount; sumNetAmount += applyDetail.NetAmount; sumBundles += applyDetail.Bundles; } //新增出库表 Model.StockOut stockOut = new StockOut(); stockOut.Executor = user.EmpId; stockOut.Memo = memo; stockOut.StockOutApplyId = stockOutApply.StockOutApplyId; stockOut.StockOutStatus = StatusEnum.已录入; stockOut.StockOutTime = DateTime.Now; stockOut.Unit = stockOutApply.UnitId; stockOut.GrosstAmount = sumGrossAmount; stockOut.NetAmount = sumNetAmount; stockOut.Bundles = sumBundles; result = stockoutDAL.Insert(user, stockOut); if (result.ResultStatus != 0) return result; int stockOutId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockOutId)) { result.ResultStatus = -1; result.Message = "出库新增失败"; return result; } stockOut.StockOutId = stockOutId; //新增出库明细表 foreach (int id in detailIds) { Model.StockOutApplyDetail applyDetail = stockOutApplyDetails.FirstOrDefault(temp => temp.DetailId == id); Model.StockOutDetail stockOutDetail = new StockOutDetail(); stockOutDetail.DetailStatus = StatusEnum.已生效; stockOutDetail.GrossAmount = applyDetail.GrossAmount; stockOutDetail.NetAmount = applyDetail.NetAmount; stockOutDetail.Bundles = applyDetail.Bundles; stockOutDetail.StockId = applyDetail.StockId; stockOutDetail.StockOutApplyDetailId = applyDetail.DetailId; stockOutDetail.StockOutId = stockOutId; result = stockOutDetailDAL.Insert(user, stockOutDetail); if (result.ResultStatus != 0) return result; } if (result.ResultStatus == 0) result.ReturnValue = stockOut; scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; return result; } return result; }
public ResultModel CompleteCancel(UserModel user, int stockOutId) { ResultModel result = new ResultModel(); try { DAL.StockLogDAL stockLogDAL = new StockLogDAL(); DAL.StockDAL stockDAL = new StockDAL(); DAL.StockNameDAL stockNameDAL = new StockNameDAL(); DAL.StockOutDAL stockOutDAL = new StockOutDAL(); DAL.StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL(); DAL.StockOutApplyDAL outApplyDAL = new StockOutApplyDAL(); Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证出库 result = stockoutDAL.Get(user, stockOutId); if (result.ResultStatus != 0) return result; StockOut stockOut = result.ReturnValue as StockOut; if (stockOut == null || stockOut.StockOutId <= 0) { result.ResultStatus = -1; result.Message = "该数据不存在,不能进行执行完成操作"; return result; } //撤销出库 result = this.stockoutDAL.CompleteCancel(user, stockOut); if (result.ResultStatus != 0) return result; //验证出库申请 result = outApplyDAL.Get(user, stockOut.StockOutApplyId); if (result.ResultStatus != 0) return result; Model.StockOutApply outApply = result.ReturnValue as Model.StockOutApply; if (outApply == null || outApply.StockOutApplyId <= 0) { result.ResultStatus = -1; result.Message = "出库申请不存在"; return result; } //验证主申请 result = applyDAL.Get(user, outApply.ApplyId); if (result.ResultStatus != 0) return result; Operate.Model.Apply apply = result.ReturnValue as Operate.Model.Apply; if (apply == null || apply.ApplyId <= 0) { result.ResultStatus = -1; result.Message = "主申请不存在"; return result; } //判断主申请状态是否为已生效, if (apply.ApplyStatus != StatusEnum.已生效) { result.ResultStatus = -1; result.Message = "申请状态只有在已生效下才能进行执行完成撤销"; return result; } //获取已完成出库明细 result = stockOutDetailDAL.Load(user, stockOut.StockOutId, Common.StatusEnum.已完成); if (result.ResultStatus != 0) return result; List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取出库明细错误"; return result; } //将所有已完成出库明细更新至已生效 foreach (Model.StockOutDetail detail in details) { result = stockOutDetailDAL.CompleteCancel(user, detail); if (result.ResultStatus != 0) return result; //获取出库流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; Model.StockLog stockLog = result.ReturnValue as Model.StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "获取出库流水失败"; return result; } //更新出库流水状态为已生效 result = stockLogDAL.CompleteCancel(user, stockLog); if (result.ResultStatus != 0) return result; //获取库存 result = stockDAL.Get(user,stockLog.StockId); if(result.ResultStatus!=0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "获取库存错误"; return result; } //库存重量添加 stock.CurGrossAmount += detail.GrossAmount; stock.CurNetAmount += detail.NetAmount; stock.Bundles += detail.Bundles; //明细关联库存状态更新至前一状态 if (stock.StockStatus == StockStatusEnum.已售库存) stock.StockStatus = StockStatusEnum.预售库存; result = stockDAL.Update(user, stock); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Complete(UserModel user, int stockOutId) { ResultModel result = new ResultModel(); try { StockDAL stockDAL = new StockDAL(); StockLogDAL stockLogDAL = new StockLogDAL(); StockNameDAL stockNameDAL = new StockNameDAL(); StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL(); StockOutApplyDAL applyDAL = new StockOutApplyDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证出库 result = stockoutDAL.Get(user, stockOutId); if (result.ResultStatus != 0) return result; StockOut resultObj = result.ReturnValue as StockOut; if (resultObj == null || resultObj.StockOutId <= 0) { result.ResultStatus = -1; result.Message = "该数据不存在,不能进行执行完成操作"; return result; } //执行完成 result = stockoutDAL.Complete(user, resultObj); if (result.ResultStatus != 0) return result; //加载明细 result = stockOutDetailDAL.Load(user, resultObj.StockOutId); if (result.ResultStatus != 0) return result; List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取出库明细失败"; return result; } //加载对应出库申请 result = applyDAL.Get(user, resultObj.StockOutApplyId); if (result.ResultStatus != 0) return result; StockOutApply apply = result.ReturnValue as StockOutApply; if (apply == null || apply.StockOutApplyId <= 0) { result.ResultStatus = -1; result.Message = "对应出库申请加载失败"; return result; } //明细执行完成 foreach(Model.StockOutDetail detail in details) { //出库明细完成 result = stockOutDetailDAL.Complete(user,detail); if (result.ResultStatus != 0) return result; //获取出库流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; Model.StockLog stockLog = result.ReturnValue as Model.StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "出库流水获取失败"; return result; } //完成出库流水 result = stockLogDAL.Complete(user, stockLog); if (result.ResultStatus != 0) return result; //获取库存 result = stockDAL.Get(user, stockLog.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存获取失败"; return result; } //库存重量捆数减少 stock.CurGrossAmount -= detail.GrossAmount; stock.CurNetAmount -= detail.NetAmount; stock.Bundles -= detail.Bundles; //库存状态修改 if (stock.StockStatus == StockStatusEnum.预售库存) stock.StockStatus = StockStatusEnum.已售库存; result = stockDAL.Update(user, stock); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Close(UserModel user, int stockOutId) { ResultModel result = new ResultModel(); try { StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL(); StockOutApplyDAL applyDAL = new StockOutApplyDAL(); StockLogDAL stockLogDAL = new StockLogDAL(); StockDAL stockDAL = new StockDAL(); using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证出库 result = stockoutDAL.Get(user, stockOutId); if (result.ResultStatus != 0) return result; StockOut resultObj = result.ReturnValue as StockOut; if (resultObj == null || resultObj.StockOutId <= 0) { result.ResultStatus = -1; result.Message = "该数据不存在,不能进行执行完成操作"; return result; } //关闭出库 result = stockoutDAL.Close(user, resultObj); if (result.ResultStatus != 0) return result; //加载对应出库申请 result = applyDAL.Get(user, resultObj.StockOutApplyId); if (result.ResultStatus != 0) return result; StockOutApply apply = result.ReturnValue as StockOutApply; if (apply == null || apply.StockOutApplyId <= 0) { result.ResultStatus = -1; result.Message = "对应出库申请加载失败"; return result; } //加载明细 result = stockOutDetailDAL.Load(user, resultObj.StockOutId); if (result.ResultStatus != 0) return result; List<StockOutDetail> details = result.ReturnValue as List<StockOutDetail>; if(details ==null) { result.ResultStatus = -1; result.Message = "获取明细失败"; return result; } foreach (StockOutDetail detail in details) { //关闭明细 result = stockOutDetailDAL.Close(user,detail); if(result.ResultStatus !=0) return result; //获取出库流水 result = stockLogDAL.Get(user, detail.StockLogId); if (result.ResultStatus != 0) return result; Model.StockLog stockLog = result.ReturnValue as Model.StockLog; if (stockLog == null || stockLog.StockLogId <= 0) { result.ResultStatus = -1; result.Message = "获取出库流水失败"; return result; } //关闭出库流水 result = stockLogDAL.Close(user, stockLog); if (result.ResultStatus != 0) return result; //获取库存 result = stockDAL.Get(user, stockLog.StockId); if (result.ResultStatus != 0) return result; Model.Stock stock = result.ReturnValue as Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "获取库存失败"; return result; } if (stock.StockStatus == StockStatusEnum.预售库存) { result = stockDAL.UpdateStockStatusToPrevious(user, stock); if (result.ResultStatus != 0) return result; } } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; return result; } return result; }
public ResultModel Invalid(UserModel user, int stockOutId) { ResultModel result = new ResultModel(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { result = stockoutDAL.Get(user, stockOutId); if (result.ResultStatus != 0) return result; StockOut resultObj = result.ReturnValue as StockOut; if (resultObj == null || resultObj.StockOutId <= 0) { result.ResultStatus = -1; result.Message = "该数据不存在,不能作废"; return result; } result = stockoutDAL.Invalid(user, resultObj); if (result.ResultStatus != 0) return result; StockOutDetailDAL stockOutDetailDAL = new StockOutDetailDAL(); result = stockOutDetailDAL.Load(user, resultObj.StockOutId); if (result.ResultStatus != 0) return result; List<Model.StockOutDetail> details = result.ReturnValue as List<Model.StockOutDetail>; if (details == null) { result.ResultStatus = -1; result.Message = "获取出库明细失败"; return result; } foreach (Model.StockOutDetail detail in details) { detail.Status = StatusEnum.已录入; result = stockOutDetailDAL.Invalid(user, detail); if (result.ResultStatus != 0) return result; } scope.Complete(); } } catch (Exception ex) { result.Message = ex.Message; } finally { if (result.ResultStatus != 0) log.ErrorFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); else if (log.IsInfoEnabled) log.InfoFormat("{0} {1},序号:{2}", user.EmpName, result.Message, result.ReturnValue); } return result; }