public ResultModel CreateStockOutApply(UserModel user, int subId, List<Model.StockOutApplyDetail> details, int deptId, string memo, int corpId, int buyCorpId) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new Operate.DAL.ApplyDAL(); NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL(); NFMT.WareHouse.DAL.StockOutApplyDAL outApplyDAL = new DAL.StockOutApplyDAL(); NFMT.WareHouse.DAL.StockOutApplyDetailDAL detailDAL = new DAL.StockOutApplyDetailDAL(); NFMT.WareHouse.DAL.StockExclusiveDAL exclusiveDAL = new DAL.StockExclusiveDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new StockDAL(); NFMT.Contract.DAL.ContractDAL contractDAL = new Contract.DAL.ContractDAL(); try { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required)) { //验证分配库存 if (details == null || details.Count == 0) { result.ResultStatus = -1; result.Message = "未分配任务库存"; return result; } //验证子合约 result = subDAL.Get(user, subId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.ContractSub sub = result.ReturnValue as NFMT.Contract.Model.ContractSub; if (sub == null || sub.SubId <= 0) { result.ResultStatus = -1; result.Message = "子合约不存在"; return result; } //验证合约 result = contractDAL.Get(user, sub.ContractId); if (result.ResultStatus != 0) return result; NFMT.Contract.Model.Contract contract = result.ReturnValue as NFMT.Contract.Model.Contract; if (contract == null || contract.ContractId <= 0) { result.ResultStatus = -1; result.Message = "合约不存在"; return result; } //获取部门信息 NFMT.User.Model.Department dept = User.UserProvider.Departments.Single(temp => temp.DeptId == deptId); if (dept == null || dept.DeptId <= 0) { result.ResultStatus = -1; result.Message = "部门不存在"; return result; } //添加主申请表 NFMT.Operate.Model.Apply apply = new Operate.Model.Apply(); apply.ApplyDept = deptId; apply.ApplyCorp = corpId; apply.ApplyTime = DateTime.Now; apply.ApplyDesc = memo; apply.ApplyType = NFMT.Operate.ApplyType.出库申请; apply.EmpId = user.EmpId; apply.ApplyStatus = Common.StatusEnum.已录入; result = applyDAL.Insert(user, apply); if (result.ResultStatus != 0) return result; int applyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out applyId) || applyId <= 0) { result.ResultStatus = -1; result.Message = "申请主表添加失败"; return result; } decimal sumGrossAmount = details.Sum(temp => temp.GrossAmount); decimal sumNetAmount = details.Sum(temp => temp.NetAmount); int sumBundles = details.Sum(temp => temp.Bundles); //添加出库申请主表 NFMT.WareHouse.Model.StockOutApply outApply = new StockOutApply(); outApply.ApplyId = applyId; outApply.ContractId = sub.ContractId; outApply.SubContractId = sub.SubId; outApply.GrossAmount = sumGrossAmount; outApply.NetAmount = sumNetAmount; outApply.Bundles = sumBundles; outApply.UnitId = sub.UnitId; outApply.BuyCorpId = buyCorpId; result = outApplyDAL.Insert(user, outApply); if (result.ResultStatus != 0) return result; int outApplyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out outApplyId) || outApplyId <= 0) { result.ResultStatus = -1; result.Message = "出库申请添加失败"; return result; } foreach (Model.StockOutApplyDetail applyDetail in details) { //验证库存 result = stockDAL.Get(user, applyDetail.StockId); if (result.ResultStatus != 0) return result; NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //判断库存品种是否与合约品种相同 if (stock.AssetId != contract.AssetId) { result.ResultStatus = -1; result.Message = "分配库存的品种与合约品种不一致"; return result; } //不允许配货库存 int planStockInStatus = (int)NFMT.WareHouse.StockStatusEnum.预入库存; int planCustomsStatus = (int)NFMT.WareHouse.StockStatusEnum.预报关库存; int stockStatus = (int)stock.StockStatus; if (stockStatus > planCustomsStatus || stockStatus < planStockInStatus) { result.ResultStatus = -1; result.Message = "访笔库存不能进行出库申请分配"; return result; } applyDetail.ContractId = sub.ContractId; applyDetail.DetailStatus = StatusEnum.已生效; applyDetail.SubContractId = sub.SubId; applyDetail.StockOutApplyId = outApplyId; if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.ForeignTrade) applyDetail.GrossAmount = stock.GrossAmount; else applyDetail.GrossAmount = applyDetail.NetAmount; result = detailDAL.Insert(user, applyDetail); if (result.ResultStatus != 0) return result; int detailApplyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailApplyId) || detailApplyId <= 0) { result.ResultStatus = -1; result.Message = "库存明细添加失败"; return result; } //排他表校验 result = exclusiveDAL.LoadByStockId(user, stock.StockId); if (result.ResultStatus != 0) return result; List<Model.StockExclusive> excs = result.ReturnValue as List<Model.StockExclusive>; if (excs == null) { result.ResultStatus = -1; result.Message = "获取排他库存信息失败"; return result; } decimal excAmount = excs.Sum(temp => temp.ExclusiveAmount); if (excAmount >= stock.CurNetAmount) { result.ResultStatus = -1; result.Message = "该笔库存剩余净重不足,配货失败"; return result; } //排他表新增 NFMT.WareHouse.Model.StockExclusive exculsive = new StockExclusive(); exculsive.ApplyId = applyId; exculsive.DetailApplyId = detailApplyId; exculsive.ExclusiveStatus = StatusEnum.已生效; exculsive.StockApplyId = outApplyId; exculsive.StockId = stock.StockId; exculsive.ExclusiveAmount = applyDetail.NetAmount; result = exclusiveDAL.Insert(user, exculsive); if (result.ResultStatus != 0) return result; } //验证出库申请与子合约签订数量 if (sumNetAmount > sub.SignAmount) { result.ResultStatus = -1; result.Message = "出库申请数量不能大于子合约签订数量"; return result; } //获取当前子合约下所有出库申请明细 result = detailDAL.LoadBySubId(user, sub.SubId, NFMT.Common.StatusEnum.已生效); if (result.ResultStatus != 0) return result; List<Model.StockOutApplyDetail> ds = result.ReturnValue as List<Model.StockOutApplyDetail>; sumNetAmount = ds.Sum(temp => temp.NetAmount); if (sumNetAmount > sub.SignAmount) { result.ResultStatus = -1; result.Message = "出库申请数量不能大于子合约可分配数量"; return result; } scope.Complete(); } } catch (Exception ex) { result.ResultStatus = -1; 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; }
public ResultModel ContractOutCreateStockOperate(UserModel user, NFMT.Contract.Model.Contract contract, int subId, int outCorpId, List<NFMT.WareHouse.Model.StockOutApplyDetail> details) { ResultModel result = new ResultModel(); NFMT.Operate.DAL.ApplyDAL applyDAL = new NFMT.Operate.DAL.ApplyDAL(); NFMT.WareHouse.DAL.StockOutApplyDAL outApplyDAL = new NFMT.WareHouse.DAL.StockOutApplyDAL(); NFMT.WareHouse.DAL.StockOutApplyDetailDAL detailDAL = new NFMT.WareHouse.DAL.StockOutApplyDetailDAL(); NFMT.WareHouse.DAL.StockExclusiveDAL exclusiveDAL = new NFMT.WareHouse.DAL.StockExclusiveDAL(); NFMT.WareHouse.DAL.StockDAL stockDAL = new NFMT.WareHouse.DAL.StockDAL(); try { //验证分配库存 if (details == null || details.Count == 0) { result.ResultStatus = -1; result.Message = "未分配任务库存"; return result; } //添加主申请表 NFMT.Operate.Model.Apply apply = new NFMT.Operate.Model.Apply(); apply.ApplyDept = user.DeptId; apply.ApplyCorp = user.CorpId; apply.ApplyTime = DateTime.Now; apply.ApplyDesc = string.Empty; apply.ApplyType = NFMT.Operate.ApplyType.出库申请; apply.EmpId = user.EmpId; apply.ApplyStatus = NFMT.Common.StatusEnum.绑定合约; result = applyDAL.Insert(user, apply); if (result.ResultStatus != 0) return result; int applyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out applyId) || applyId <= 0) { result.ResultStatus = -1; result.Message = "申请主表添加失败"; return result; } decimal sumNetAmount = details.Sum(temp => temp.NetAmount); int sumBundles = details.Sum(temp => temp.Bundles); //添加出库申请主表 NFMT.WareHouse.Model.StockOutApply outApply = new NFMT.WareHouse.Model.StockOutApply(); outApply.ApplyId = applyId; outApply.ContractId = contract.ContractId; outApply.SubContractId = subId; outApply.NetAmount = sumNetAmount; outApply.Bundles = sumBundles; outApply.UnitId = contract.UnitId; outApply.BuyCorpId = outCorpId; foreach (NFMT.WareHouse.Model.StockOutApplyDetail applyDetail in details) { //验证库存 result = stockDAL.Get(user, applyDetail.StockId); if (result.ResultStatus != 0) return result; NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //判断库存品种是否与合约品种相同 if (stock.AssetId != contract.AssetId) { result.ResultStatus = -1; result.Message = "分配库存的品种与合约品种不一致"; return result; } //验证关境 if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.外贸 && stock.CustomsType != (int)NFMT.WareHouse.CustomTypeEnum.关外) { result.ResultStatus = -1; result.Message = "库存关境与合约不一致"; return result; } else if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.内贸 && stock.CustomsType != (int)NFMT.WareHouse.CustomTypeEnum.关内) { result.ResultStatus = -1; result.Message = "库存关境与合约不一致"; return result; } //不允许配货库存 int planStockInStatus = (int)NFMT.WareHouse.StockStatusEnum.预入库存; int planCustomsStatus = (int)NFMT.WareHouse.StockStatusEnum.预报关库存; int stockStatus = (int)stock.StockStatus; if (stockStatus > planCustomsStatus || stockStatus < planStockInStatus) { result.ResultStatus = -1; result.Message = "访笔库存不能进行出库申请分配"; return result; } applyDetail.ContractId = contract.ContractId; applyDetail.DetailStatus = StatusEnum.已生效; applyDetail.SubContractId = subId; if (contract.ContractId == (int)NFMT.Contract.TradeBorderEnum.ForeignTrade) applyDetail.GrossAmount = stock.GrossAmount; else applyDetail.GrossAmount = applyDetail.NetAmount; } decimal sumGrossAmount = details.Sum(temp => temp.GrossAmount); outApply.GrossAmount = sumGrossAmount; outApply.CreateFrom = (int)NFMT.Common.CreateFromEnum.销售合约库存创建; result = outApplyDAL.Insert(user, outApply); if (result.ResultStatus != 0) return result; int outApplyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out outApplyId) || outApplyId <= 0) { result.ResultStatus = -1; result.Message = "出库申请添加失败"; return result; } foreach (NFMT.WareHouse.Model.StockOutApplyDetail applyDetail in details) { NFMT.WareHouse.Model.StockOutApplyDetail appDetail = new NFMT.WareHouse.Model.StockOutApplyDetail(); appDetail.StockOutApplyId = outApplyId; appDetail.Bundles = applyDetail.Bundles; appDetail.ContractId = applyDetail.ContractId; appDetail.DetailStatus = StatusEnum.已生效; appDetail.GrossAmount = applyDetail.GrossAmount; appDetail.NetAmount = applyDetail.NetAmount; appDetail.StockId = applyDetail.StockId; appDetail.SubContractId = applyDetail.SubContractId; result = detailDAL.Insert(user, appDetail); if (result.ResultStatus != 0) return result; int detailApplyId = 0; if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out detailApplyId) || detailApplyId <= 0) { result.ResultStatus = -1; result.Message = "库存明细添加失败"; return result; } //验证库存 result = stockDAL.Get(user, applyDetail.StockId); if (result.ResultStatus != 0) return result; NFMT.WareHouse.Model.Stock stock = result.ReturnValue as NFMT.WareHouse.Model.Stock; if (stock == null || stock.StockId <= 0) { result.ResultStatus = -1; result.Message = "库存不存在"; return result; } //排他表校验 result = exclusiveDAL.LoadByStockId(user, stock.StockId); if (result.ResultStatus != 0) return result; List<NFMT.WareHouse.Model.StockExclusive> excs = result.ReturnValue as List<NFMT.WareHouse.Model.StockExclusive>; if (excs == null) { result.ResultStatus = -1; result.Message = "获取排他库存信息失败"; return result; } decimal excAmount = excs.Sum(temp => temp.ExclusiveAmount); if (excAmount + applyDetail.NetAmount > stock.CurNetAmount) { result.ResultStatus = -1; result.Message = "该笔库存剩余净重不足,配货失败"; return result; } //排他表新增 NFMT.WareHouse.Model.StockExclusive exculsive = new NFMT.WareHouse.Model.StockExclusive(); exculsive.ApplyId = applyId; exculsive.DetailApplyId = detailApplyId; exculsive.ExclusiveStatus = StatusEnum.已生效; exculsive.StockApplyId = outApplyId; exculsive.StockId = stock.StockId; exculsive.ExclusiveAmount = applyDetail.NetAmount; result = exclusiveDAL.Insert(user, exculsive); if (result.ResultStatus != 0) return result; } } catch (Exception ex) { result.ResultStatus = -1; result.Message = ex.Message; } return result; }
public ResultModel Load(UserModel user, int applyId) { ResultModel result = new ResultModel(); try { string cmdText = string.Format("select * from dbo.St_StockExclusive where ApplyId={0} and ExclusiveStatus={1}", applyId, (int)Common.StatusEnum.已生效); DataTable dt = SqlHelper.ExecuteDataTable(ConnectString, cmdText, null, CommandType.Text); List<StockExclusive> stockExclusives = new List<StockExclusive>(); foreach (DataRow dr in dt.Rows) { StockExclusive stockexclusive = new StockExclusive(); stockexclusive.ExclusiveId = Convert.ToInt32(dr["ExclusiveId"]); if (dr["ApplyId"] != DBNull.Value) { stockexclusive.ApplyId = Convert.ToInt32(dr["ApplyId"]); } if (dr["StockApplyId"] != DBNull.Value) { stockexclusive.StockApplyId = Convert.ToInt32(dr["StockApplyId"]); } if (dr["DetailApplyId"] != DBNull.Value) { stockexclusive.DetailApplyId = Convert.ToInt32(dr["DetailApplyId"]); } if (dr["StockId"] != DBNull.Value) { stockexclusive.StockId = Convert.ToInt32(dr["StockId"]); } if (dr["ExclusiveStatus"] != DBNull.Value) { stockexclusive.ExclusiveStatus = (Common.StatusEnum)Enum.Parse(typeof(Common.StatusEnum), dr["ExclusiveStatus"].ToString()); } stockExclusives.Add(stockexclusive); } result.AffectCount = dt.Rows.Count; result.Message = "获取列表成功"; result.ResultStatus = 0; result.ReturnValue = stockExclusives; } catch (Exception ex) { result.Message = ex.Message; } return result; }
public ResultModel InsertOrUpdateStatus(UserModel user, StockExclusive stockExclusive) { ResultModel result = new ResultModel(); try { List<SqlParameter> paras = new List<SqlParameter>(); SqlParameter detailidpara = new SqlParameter(); detailidpara.Direction = ParameterDirection.Output; detailidpara.SqlDbType = SqlDbType.Int; detailidpara.ParameterName = "@ExclusiveId"; detailidpara.Size = 4; paras.Add(detailidpara); SqlParameter applyIdpara = new SqlParameter("@ApplyId", SqlDbType.Int, 4); applyIdpara.Value = stockExclusive.ApplyId; paras.Add(applyIdpara); SqlParameter stockApplyIdpara = new SqlParameter("@StockApplyId", SqlDbType.Int, 4); stockApplyIdpara.Value = stockExclusive.StockApplyId; paras.Add(stockApplyIdpara); SqlParameter detailApplyIdpara = new SqlParameter("@DetailApplyId", SqlDbType.Int, 4); detailApplyIdpara.Value = stockExclusive.DetailApplyId; paras.Add(detailApplyIdpara); SqlParameter stockIdpara = new SqlParameter("@StockId", SqlDbType.Int, 4); stockIdpara.Value = stockExclusive.StockId; paras.Add(stockIdpara); int i = SqlHelper.ExecuteNonQuery(ConnectString, CommandType.StoredProcedure, "InsertOrUpdate_St_StockExclusive", paras.ToArray()); if (i > 0) { result.Message = "操作成功"; result.ResultStatus = 0; result.AffectCount = i; result.ReturnValue = detailidpara.Value; } else { result.Message = "操作失败"; result.ResultStatus = -1; } } catch (Exception e) { result.Message = string.Format("操作失败,{0}", e.Message); result.ResultStatus = -1; } return result; }
public ResultModel Get(UserModel user, int applyId, int stockApplyId, int detailId) { ResultModel result = new ResultModel(); if (applyId < 1) { result.Message = "申请不能小于1"; return result; } List<SqlParameter> paras = new List<SqlParameter>(); SqlParameter para = new SqlParameter("@applyId", SqlDbType.Int, 4); para.Value = applyId; paras.Add(para); para = new SqlParameter("@stockApplyId", SqlDbType.Int, 4); para.Value = stockApplyId; paras.Add(para); para = new SqlParameter("@detailId", SqlDbType.Int, 4); para.Value = detailId; paras.Add(para); para = new SqlParameter("@status", SqlDbType.Int, 4); para.Value = (int)StatusEnum.已生效; paras.Add(para); SqlDataReader dr = null; try { string cmdText = "select * from dbo.St_StockExclusive where ApplyId=@applyId and StockApplyId=@stockApplyId and DetailApplyId=@detailId and ExclusiveStatus=@status"; dr = SqlHelper.ExecuteReader(ConnectString, CommandType.Text, cmdText, paras.ToArray()); StockExclusive stockexclusive = new StockExclusive(); if (dr.Read()) { int indexExclusiveId = dr.GetOrdinal("ExclusiveId"); stockexclusive.ExclusiveId = Convert.ToInt32(dr[indexExclusiveId]); int indexApplyId = dr.GetOrdinal("ApplyId"); if (dr["ApplyId"] != DBNull.Value) { stockexclusive.ApplyId = Convert.ToInt32(dr[indexApplyId]); } int indexStockApplyId = dr.GetOrdinal("StockApplyId"); if (dr["StockApplyId"] != DBNull.Value) { stockexclusive.StockApplyId = Convert.ToInt32(dr[indexStockApplyId]); } int indexDetailApplyId = dr.GetOrdinal("DetailApplyId"); if (dr["DetailApplyId"] != DBNull.Value) { stockexclusive.DetailApplyId = Convert.ToInt32(dr[indexDetailApplyId]); } int indexStockId = dr.GetOrdinal("StockId"); if (dr["StockId"] != DBNull.Value) { stockexclusive.StockId = Convert.ToInt32(dr[indexStockId]); } int indexExclusiveStatus = dr.GetOrdinal("ExclusiveStatus"); if (dr["ExclusiveStatus"] != DBNull.Value) { stockexclusive.ExclusiveStatus = (Common.StatusEnum)Enum.Parse(typeof(Common.StatusEnum), dr[indexExclusiveStatus].ToString()); } result.AffectCount = 1; result.Message = "读取成功"; result.ResultStatus = 0; result.ReturnValue = stockexclusive; } else { result.Message = "读取失败或无数据"; result.AffectCount = 0; } } catch (Exception ex) { result.Message = ex.Message; } finally { if (dr != null) dr.Dispose(); } return result; }
public override IModel CreateModel(SqlDataReader dr) { StockExclusive stockexclusive = new StockExclusive(); int indexExclusiveId = dr.GetOrdinal("ExclusiveId"); stockexclusive.ExclusiveId = Convert.ToInt32(dr[indexExclusiveId]); int indexApplyId = dr.GetOrdinal("ApplyId"); if (dr["ApplyId"] != DBNull.Value) { stockexclusive.ApplyId = Convert.ToInt32(dr[indexApplyId]); } int indexStockApplyId = dr.GetOrdinal("StockApplyId"); if (dr["StockApplyId"] != DBNull.Value) { stockexclusive.StockApplyId = Convert.ToInt32(dr[indexStockApplyId]); } int indexDetailApplyId = dr.GetOrdinal("DetailApplyId"); if (dr["DetailApplyId"] != DBNull.Value) { stockexclusive.DetailApplyId = Convert.ToInt32(dr[indexDetailApplyId]); } int indexStockId = dr.GetOrdinal("StockId"); if (dr["StockId"] != DBNull.Value) { stockexclusive.StockId = Convert.ToInt32(dr[indexStockId]); } int indexExclusiveAmount = dr.GetOrdinal("ExclusiveAmount"); if (dr["ExclusiveAmount"] != DBNull.Value) { stockexclusive.ExclusiveAmount = Convert.ToDecimal(dr[indexExclusiveAmount]); } int indexExclusiveStatus = dr.GetOrdinal("ExclusiveStatus"); if (dr["ExclusiveStatus"] != DBNull.Value) { stockexclusive.ExclusiveStatus = (StatusEnum)Convert.ToInt32(dr[indexExclusiveStatus]); } return stockexclusive; }