Exemple #1
0
        /// <summary>
        /// 入库通知单行转换入库单行
        /// </summary>
        /// <param name="outNoticeLine"></param>
        /// <returns></returns>
        protected WSellReturnLine CloneInNoticeLine(WSellLine outNoticeLine)
        {
            //如果通知数量-下推-完成<0 则返回
            decimal outCount = outNoticeLine.OutCount - outNoticeLine.ReturnCount;

            if (outCount <= 0)
            {
                return(null);
            }
            WSellReturnLine line = new WSellReturnLine()
            {
                Batch        = outNoticeLine.Batch,
                CreateDate   = DateTime.Now,
                Factory      = outNoticeLine.Factory,
                InCount      = outCount,
                MaterialCode = outNoticeLine.MaterialCode,
                MaterialID   = outNoticeLine.MaterialID,
                OwnerCode    = outNoticeLine.OwnerCode,
                UnitID       = outNoticeLine.UnitID,
                SourceLineID = outNoticeLine.ID,
                PositionID   = outNoticeLine.PositionID,
                PositionCode = outNoticeLine.PositionCode,
                InPutCount   = outCount
            };

            return(line);
        }
Exemple #2
0
        /// <summary>
        /// 构建通知单不足提示
        /// </summary>
        /// <param name="stockOut"></param>
        /// <returns></returns>
        private string BuilderNoticeLessMessage(WSellReturnLine inNoticeLine)
        {
            StringBuilder sb = new StringBuilder("入库数量大于通知数量");

            sb.AppendLine(",物料:" + inNoticeLine.MaterialCode);
            if (!string.IsNullOrWhiteSpace(inNoticeLine.Batch))
            {
                sb.AppendLine(",批次:" + inNoticeLine.Batch);
            }
            if (!string.IsNullOrWhiteSpace(inNoticeLine.OwnerCode))
            {
                sb.AppendLine(",货主:" + inNoticeLine.OwnerCode);
            }
            return(sb.ToString());
        }
Exemple #3
0
        /// <summary>
        /// 构建库存不足提示
        /// </summary>
        /// <param name="line"></param>
        /// <param name="msg">错误信息</param>
        /// <returns></returns>
        private string BuilderErrorMessage(WSellReturnLine line, string msg)
        {
            StringBuilder sb = new StringBuilder(msg);

            sb.AppendLine(",货位:" + line.PositionCode);
            sb.AppendLine(",物料:" + line.MaterialCode);
            if (!string.IsNullOrWhiteSpace(line.Batch))
            {
                sb.AppendLine(",批次:" + line.Batch);
            }
            if (!string.IsNullOrWhiteSpace(line.OwnerCode))
            {
                sb.AppendLine(",货主:" + line.OwnerCode);
            }
            return(sb.ToString());
        }
Exemple #4
0
        /// <summary>
        /// 其他入库复制入口记录
        /// </summary>
        /// <param name="line"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        private WStockIn CloneSellReturn(WSellReturnLine line, WSellReturn SellReturn)
        {
            WStockIn stockIn = new WStockIn();

            stockIn.Batch         = line.Batch;
            stockIn.Factory       = line.Factory;
            stockIn.InCount       = line.InCount;
            stockIn.MaterialCode  = line.MaterialCode;
            stockIn.MaterialID    = line.MaterialID;
            stockIn.OwnerCode     = line.OwnerCode;
            stockIn.PositionCode  = line.PositionCode;
            stockIn.PositionID    = line.PositionID;
            stockIn.SourceCode    = SellReturn.SellReturnCode;
            stockIn.SourceID      = line.ParentID;
            stockIn.SourceLineID  = line.ID;
            stockIn.StockInDate   = SellReturn.CreateDate;
            stockIn.StockInType   = StockInEnum.SellReturn;
            stockIn.UnitID        = line.UnitID;
            stockIn.WarehouseCode = SellReturn.WarehouseCode;
            stockIn.WarehouseID   = SellReturn.WarehouseID;
            stockIn.StockID       = line.StockID;
            return(stockIn);
        }
Exemple #5
0
        /// <summary>
        /// 根据入库通知添加入库
        /// </summary>
        /// <param name="sell"></param>
        /// <returns></returns>
        public ResultData <string> AddSellReturn(WSell sell, int createBy)
        {
            ResultData <string> rData = new ResultData <string>();

            if (sell.StockStatus != StockStatusEnum.Approve)
            {
                rData.status  = -1;
                rData.message = "单据未审核不能退库.";
                return(rData);
            }

            //查询明细
            if (sell.Lines.Count < 1)
            {
                sell.Lines = slRepository.GetLinesByParentId(sell.ID);
            }

            //克隆主表
            WSellReturn sellReturn = CloneInNotice(sell);

            sellReturn.CreateBy = createBy;

            foreach (var item in sell.Lines)
            {
                WSellReturnLine line = CloneInNoticeLine(item);
                if (line != null)
                {
                    sellReturn.Lines.Add(line);
                }
            }

            if (sellReturn.Lines.Count < 1)
            {
                rData.status  = -1;
                rData.message = "单据已经全部退库.";
                return(rData);
            }

            DatabaseContext dbContext = srRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                //添加入库单
                sellReturn.CreateDate     = DateTime.Now;
                sellReturn.StockStatus    = StockStatusEnum.New;
                sellReturn.SellReturnCode = nuRepository.GetNextNumber("XSTK");
                srRepository.Insert(sellReturn);
                foreach (var line in sellReturn.Lines)
                {
                    line.ParentID   = sellReturn.ID;
                    line.CreateBy   = sellReturn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    srlRepository.Insert(line);

                    //更新入库单 添加退库
                    decimal rt = slRepository.AddReturnCount(line.InCount, line.SourceLineID);
                    if (rt < 0)
                    {
                        dbContext.AbortTransaction();
                        rData.status  = -1;
                        rData.message = BuilderNoticeLessMessage(line);
                        return(rData);
                    }
                }

                //将插入主键赋值给返回值
                rData.result = sellReturn.ID.ToString();

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }

            return(rData);
        }