示例#1
0
        public override IModel CreateModel(SqlDataReader dr)
        {
            StockOutApply stockoutapply = new StockOutApply();

            int indexStockOutApplyId = dr.GetOrdinal("StockOutApplyId");
            stockoutapply.StockOutApplyId = Convert.ToInt32(dr[indexStockOutApplyId]);

            int indexApplyId = dr.GetOrdinal("ApplyId");
            if (dr["ApplyId"] != DBNull.Value)
            {
                stockoutapply.ApplyId = Convert.ToInt32(dr[indexApplyId]);
            }

            int indexContractId = dr.GetOrdinal("ContractId");
            if (dr["ContractId"] != DBNull.Value)
            {
                stockoutapply.ContractId = Convert.ToInt32(dr[indexContractId]);
            }

            int indexSubContractId = dr.GetOrdinal("SubContractId");
            if (dr["SubContractId"] != DBNull.Value)
            {
                stockoutapply.SubContractId = Convert.ToInt32(dr[indexSubContractId]);
            }

            int indexGrossAmount = dr.GetOrdinal("GrossAmount");
            if (dr["GrossAmount"] != DBNull.Value)
            {
                stockoutapply.GrossAmount = Convert.ToDecimal(dr[indexGrossAmount]);
            }

            int indexNetAmount = dr.GetOrdinal("NetAmount");
            if (dr["NetAmount"] != DBNull.Value)
            {
                stockoutapply.NetAmount = Convert.ToDecimal(dr[indexNetAmount]);
            }

            int indexBundles = dr.GetOrdinal("Bundles");
            if (dr["Bundles"] != DBNull.Value)
            {
                stockoutapply.Bundles = Convert.ToInt32(dr[indexBundles]);
            }

            int indexUnitId = dr.GetOrdinal("UnitId");
            if (dr["UnitId"] != DBNull.Value)
            {
                stockoutapply.UnitId = Convert.ToInt32(dr[indexUnitId]);
            }

            int indexBuyCorpId = dr.GetOrdinal("BuyCorpId");
            if (dr["BuyCorpId"] != DBNull.Value)
            {
                stockoutapply.BuyCorpId = Convert.ToInt32(dr[indexBuyCorpId]);
            }

            int indexCreateFrom = dr.GetOrdinal("CreateFrom");
            if (dr["CreateFrom"] != DBNull.Value)
            {
                stockoutapply.CreateFrom = Convert.ToInt32(dr[indexCreateFrom]);
            }

            int indexCreatorId = dr.GetOrdinal("CreatorId");
            if (dr["CreatorId"] != DBNull.Value)
            {
                stockoutapply.CreatorId = Convert.ToInt32(dr[indexCreatorId]);
            }

            int indexCreateTime = dr.GetOrdinal("CreateTime");
            if (dr["CreateTime"] != DBNull.Value)
            {
                stockoutapply.CreateTime = Convert.ToDateTime(dr[indexCreateTime]);
            }

            int indexLastModifyId = dr.GetOrdinal("LastModifyId");
            if (dr["LastModifyId"] != DBNull.Value)
            {
                stockoutapply.LastModifyId = Convert.ToInt32(dr[indexLastModifyId]);
            }

            int indexLastModifyTime = dr.GetOrdinal("LastModifyTime");
            if (dr["LastModifyTime"] != DBNull.Value)
            {
                stockoutapply.LastModifyTime = Convert.ToDateTime(dr[indexLastModifyTime]);
            }

            return stockoutapply;
        }
示例#2
0
        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;
        }
示例#3
0
        /// <summary>
        /// 更新st_stockoutapply
        /// </summary>
        /// <param name="user">当前操作用户</param>
        /// <param name="st_stockoutapply">StockOutApply对象</param>
        /// <returns></returns>
        public ResultModel Update(UserModel user, StockOutApply st_stockoutapply)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
                {
                    ResultModel st_stockoutapplyResult = this.Get(user, st_stockoutapply.StockOutApplyId);
                    StockOutApply resultObj = st_stockoutapplyResult.ReturnValue as StockOutApply;

                    if (st_stockoutapply == null)
                    {
                        result.Message = "该数据不存在,不能更新";
                        return result;
                    }
                    result = stockoutapplyDAL.Update(user, st_stockoutapply);

                    if (result.ResultStatus == 0)
                        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;
        }
示例#4
0
        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;
        }
示例#5
0
        public ResultModel GetByApplyId(UserModel user, int applyId)
        {
            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);

            SqlDataReader dr = null;

            try
            {
                string cmdText = "select * from dbo.St_StockOutApply where ApplyId=@applyId";
                dr = SqlHelper.ExecuteReader(ConnectString, CommandType.Text, cmdText, paras.ToArray());

                StockOutApply stockoutapply = new StockOutApply();

                if (dr.Read())
                {
                    stockoutapply = this.CreateModel<StockOutApply>(dr);

                    result.AffectCount = 1;
                    result.Message = "读取成功";
                    result.ResultStatus = 0;
                    result.ReturnValue = stockoutapply;
                }
                else
                {
                    result.Message = "读取失败或无数据";
                    result.AffectCount = 0;
                }
            }
            catch (Exception ex)
            {
                result.Message = ex.Message;
            }
            finally
            {
                if (dr != null)
                    dr.Dispose();
            }
            return result;
        }