Exemple #1
0
        public ResultModel Create(UserModel user, Model.StockIn stockIn, int subId, bool isSubmitAudit)
        {
            ResultModel result = new ResultModel();

            try
            {
                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    NFMT.User.Model.Corporation corporation = NFMT.User.UserProvider.Corporations.FirstOrDefault(temp => temp.CorpId == stockIn.CorpId);
                    if (corporation == null || corporation.CorpId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "归属公司不存在";
                        return result;
                    }

                    result = this.ValidateAuth(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    stockIn.GroupId = corporation.ParentId;
                    stockIn.StockInStatus = StatusEnum.已录入;

                    result = stockinDAL.Insert(user, stockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    int stockInId = 0;
                    if (result.ReturnValue == null || !int.TryParse(result.ReturnValue.ToString(), out stockInId) || stockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登录失败";
                        return result;
                    }

                    if (subId > 0)
                    {
                        //获取子合约
                        NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();
                        result = subDAL.Get(user, subId);
                        if (result.ResultStatus != 0)
                            return result;

                        Contract.Model.ContractSub sub = result.ReturnValue as Contract.Model.ContractSub;
                        if (sub == null || sub.SubId <= 0)
                        {
                            result.ResultStatus = -1;
                            result.Message = "子合约序号错误";
                            return result;
                        }

                        if (stockIn.GrossAmount > sub.SignAmount)
                        {
                            result.ResultStatus = -1;
                            result.Message = "入库重量不能大于子合约签订数量";
                            return result;
                        }

                        //获取当前子合约下所有大于已录状态的入库登记
                        result = stockinDAL.Load(user, sub.SubId, StatusEnum.已录入);
                        if (result.ResultStatus != 0)
                            return result;

                        List<StockIn> stockIns = result.ReturnValue as List<Model.StockIn>;
                        if (stockIns == null)
                        {
                            result.ResultStatus = -1;
                            result.Message = "获取子合约下入库登记失败";
                            return result;
                        }

                        decimal sumAmount = stockIns.Sum(temp => temp.GrossAmount);
                        //验证子合约下入库重量是否超额
                        if (stockIn.GrossAmount > sub.SignAmount - sumAmount)
                        {
                            result.ResultStatus = -1;
                            result.Message = "入库数量大于当前子合约下可入库数量";
                            return result;
                        }

                        NFMT.WareHouse.Model.ContractStockIn contractStockIn = new NFMT.WareHouse.Model.ContractStockIn()
                        {
                            ContractId = sub.ContractId,
                            ContractSubId = sub.SubId,
                            StockInId = stockInId,
                            RefStatus = StatusEnum.已生效
                        };

                        DAL.ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
                        result = contractStockInDAL.Insert(user, contractStockIn);
                        if (result.ResultStatus != 0)
                            return result;
                    }

                    if (result.ResultStatus == 0)
                    {
                        stockIn.StockInId = stockInId;
                        result.ReturnValue = stockIn;
                    }

                    scope.Complete();
                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Exemple #2
0
        public ResultModel Create(UserModel user, int subId, int stockInId)
        {
            ResultModel result = new ResultModel();

            try
            {
                DAL.StockInDAL stockInDAL = new StockInDAL();
                NFMT.Contract.DAL.ContractSubDAL subDAL = new Contract.DAL.ContractSubDAL();

                using (System.Transactions.TransactionScope scope = new TransactionScope())
                {
                    //验证子合约
                    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 = stockInDAL.Load(user, subId, StatusEnum.已录入);
                    if (result.ResultStatus != 0)
                        return result;

                    List<Model.StockIn> stockIns = result.ReturnValue as List<Model.StockIn>;
                    if (stockIns == null)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约下的入库登记获取失败";
                        return result;
                    }

                    decimal sumAmount = stockIns.Sum(temp => temp.GrossAmount);

                    if (sumAmount == sub.SignAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "子合约已分配满额";
                        return result;
                    }

                    //验证入库登记
                    result = stockInDAL.Get(user, stockInId);
                    if (result.ResultStatus != 0)
                        return result;

                    Model.StockIn stockIn = result.ReturnValue as Model.StockIn;
                    if (stockIn == null || stockIn.StockInId <= 0)
                    {
                        result.ResultStatus = -1;
                        result.Message = "入库登记不存在";
                        return result;
                    }

                    if (stockIn.GrossAmount > sub.SignAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "分配入库的重量大于子合约签订数量";
                        return result;
                    }

                    if (stockIn.GrossAmount > sub.SignAmount - sumAmount)
                    {
                        result.ResultStatus = -1;
                        result.Message = "分配入库的重量大于子合约可分配重量";
                        return result;
                    }

                    //新增入库分配
                    Model.ContractStockIn contractStockIn = new ContractStockIn();
                    contractStockIn.ContractId = sub.ContractId;
                    contractStockIn.ContractSubId = sub.SubId;
                    contractStockIn.RefStatus = StatusEnum.已录入;
                    contractStockIn.StockInId = stockIn.StockInId;

                    result = this.contractstockin_DAL.Insert(user, contractStockIn);
                    if (result.ResultStatus != 0)
                        return result;

                    scope.Complete();

                }
            }
            catch (Exception ex)
            {
                result.ResultStatus = -1;
                result.Message = ex.Message;
            }

            return result;
        }
Exemple #3
0
        public override IModel CreateModel(SqlDataReader dr)
        {
            ContractStockIn contractstockin = new ContractStockIn();

            int indexRefId = dr.GetOrdinal("RefId");
            contractstockin.RefId = Convert.ToInt32(dr[indexRefId]);

            int indexStockInId = dr.GetOrdinal("StockInId");
            if (dr["StockInId"] != DBNull.Value)
            {
                contractstockin.StockInId = Convert.ToInt32(dr[indexStockInId]);
            }

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

            int indexContractSubId = dr.GetOrdinal("ContractSubId");
            if (dr["ContractSubId"] != DBNull.Value)
            {
                contractstockin.ContractSubId = Convert.ToInt32(dr[indexContractSubId]);
            }

            int indexRefStatus = dr.GetOrdinal("RefStatus");
            if (dr["RefStatus"] != DBNull.Value)
            {
                contractstockin.RefStatus = (StatusEnum)Convert.ToInt32(dr[indexRefStatus]);
            }

            return contractstockin;
        }
Exemple #4
0
        public ResultModel ContractInCreateStockOperate(UserModel user, NFMT.Contract.Model.Contract contract, int subId, List<int> stockLogIds)
        {
            ResultModel result = new ResultModel();

            int assetId = contract.AssetId;
            int logDirection = (int)NFMT.WareHouse.LogDirectionEnum.In;
            int customsType = (int)NFMT.WareHouse.CustomTypeEnum.关外;
            if (contract.TradeBorder == (int)NFMT.Contract.TradeBorderEnum.内贸)
                customsType = (int)NFMT.WareHouse.CustomTypeEnum.关内;

            StockLogDAL stockLogDAL = new StockLogDAL();
            StockInDAL stockInDAL = new StockInDAL();
            ContractStockInDAL contractStockInDAL = new ContractStockInDAL();
            StockInStockDAL stockInStockDAL = new StockInStockDAL();

            foreach (int stockLogId in stockLogIds)
            {
                result = stockLogDAL.Get(user, stockLogId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockLog stockLog = result.ReturnValue as NFMT.WareHouse.Model.StockLog;
                if (stockLog == null || stockLog.StockLogId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "库存流水不存在";
                    return result;
                }

                if (stockLog.LogStatus != StatusEnum.已生效)
                {
                    result.ResultStatus = -1;
                    result.Message = "库存流水状态不正确";
                    return result;
                }

                if (assetId != stockLog.AssetId)
                {
                    result.ResultStatus = -1;
                    result.Message = "选中库存存在品种不一致";
                    return result;
                }

                if (logDirection != stockLog.LogDirection)
                {
                    result.ResultStatus = -1;
                    result.Message = "选中库存存在流水方向不一致";
                    return result;
                }

                if (customsType != stockLog.CustomsType)
                {
                    result.ResultStatus = -1;
                    result.Message = "选中库存存在关境不一致";
                    return result;
                }

                result = stockInStockDAL.GetByStockLogId(user, stockLog.StockLogId);
                if (result.ResultStatus != 0)
                    return result;

                NFMT.WareHouse.Model.StockInStock stockInStock = result.ReturnValue as NFMT.WareHouse.Model.StockInStock;
                if (stockInStock == null || stockInStock.RefId <= 0)
                {
                    result.ResultStatus = -1;
                    result.Message = "库存流水与入库登记关系获取失败";
                    return result;
                }

                NFMT.WareHouse.Model.ContractStockIn contractStockIn = new NFMT.WareHouse.Model.ContractStockIn();
                contractStockIn.ContractId = contract.ContractId;
                contractStockIn.ContractSubId = subId;
                contractStockIn.RefStatus = StatusEnum.已生效;
                contractStockIn.StockInId = stockInStock.StockInId;

                result = contractStockInDAL.Insert(user, contractStockIn);
                if (result.ResultStatus != 0)
                    return result;
            }

            return result;
        }