Пример #1
0
        /// <summary>
        /// 检查
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        private ResultData <string> CheckValid(WOtherIn otherIn)
        {
            ResultData <string> rt = new ResultData <string>();

            foreach (var item in otherIn.Lines)
            {
                //删除行,不验证
                if (item.CURD == CurdEnum.Delete)
                {
                    continue;
                }
                if (item.PositionID < 1)
                {
                    rt.status  = -1;
                    rt.message = BuilderErrorMessage(item, "货位不能为空");
                    break;
                }
                else if (item.InCount <= 0)
                {
                    rt.status  = -1;
                    rt.message = BuilderErrorMessage(item, "入库数量必须大于0");
                    break;
                }
            }

            return(rt);
        }
Пример #2
0
        /// <summary>
        /// 更新其他入库
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        public ResultData <string> UpdateOtherIn(WOtherIn otherIn)
        {
            ResultData <string> rData = CheckValid(otherIn);

            if (rData.status != 0)
            {
                return(rData);
            }

            if (otherIn.StockStatus != StockStatusEnum.New)
            {
                rData.status  = -1;
                rData.message = "单据已经审核,不能编辑.";
                return(rData);
            }

            DatabaseContext db = oiRepository.DbCondext;

            try
            {
                db.BeginTransaction();

                otherIn.UpdateDate = DateTime.Now;
                oiRepository.Update(otherIn);
                foreach (var line in otherIn.Lines)
                {
                    switch (line.CURD)
                    {
                    case CurdEnum.Add:
                        line.ParentID   = otherIn.ID;
                        line.CreateBy   = otherIn.CreateBy;
                        line.CreateDate = DateTime.Now;
                        line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                        oilRepository.Insert(line);
                        break;

                    case CurdEnum.Delete:
                        oilRepository.Delete(line);
                        break;

                    case CurdEnum.Update:
                        line.UpdateBy   = otherIn.UpdateBy;
                        line.UpdateDate = DateTime.Now;
                        line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                        oilRepository.Update(line);
                        break;
                    }
                }

                db.CompleteTransaction();
            }
            catch (Exception ex)
            {
                db.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
Пример #3
0
        public ContentResult Add()
        {
            ResultData <string> rt = new ResultData <string>();

            WOtherIn otherIn = GetAdd <WOtherIn>();

            otherIn.CreateBy = this.CurrentUser.ID;
            rt = inService.AddOtherIn(otherIn);
            return(ReturnResult(rt));
        }
Пример #4
0
        /// <summary>
        /// 删除其他入库
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        public int RemoveOtherIn(WOtherIn otherIn)
        {
            //删除其他入库
            int result = oiRepository.RemoveOtherInByStatus(otherIn.ID, StockStatusEnum.New);

            if (result > 0)
            {
                oilRepository.RemoveLinesByParentId(otherIn.ID);
            }
            return(result);
        }
Пример #5
0
        public ActionResult Approve()
        {
            ResultData <string> rt = new ResultData <string>();

            WOtherIn otherIn = GetParam <WOtherIn>("app");

            otherIn.UpdateBy   = this.CurrentUser.ID;
            otherIn.UpdateDate = DateTime.Now;
            rt = inService.ApproveOtherIn(otherIn);

            return(ReturnResult(rt));
        }
Пример #6
0
        public ContentResult Update()
        {
            ResultData <string> rt = new ResultData <string>();

            WOtherIn otherIn = GetUpdate <WOtherIn>();

            otherIn.UpdateBy   = this.CurrentUser.ID;
            otherIn.UpdateDate = DateTime.Now;
            rt = inService.UpdateOtherIn(otherIn);

            return(ReturnResult(rt));
        }
Пример #7
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        public ResultData <string> ApproveOtherIn(WOtherIn otherIn)
        {
            if (otherIn.Lines.Count < 1)
            {
                otherIn.Lines = oilRepository.GetLinesByParentId(otherIn.ID);
            }

            ResultData <string> rData     = new ResultData <string>();
            DatabaseContext     dbContext = oiRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //入库记录
                List <WStockIn> stockIns = new List <WStockIn>(otherIn.Lines.Count);

                //添加其他入库
                int result = oiRepository.ApproveOtherIn(otherIn);
                if (result < 1)
                {
                    rData.status  = -1;
                    rData.message = "单据已经审核或删除.";
                    dbContext.AbortTransaction();
                    return(rData);
                }

                foreach (var line in otherIn.Lines)
                {
                    stockIns.Add(CloneOtherIn(line, otherIn));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.AddStocks(stockIns);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
Пример #8
0
        public ContentResult Delete()
        {
            ResultData <string> rt = new ResultData <string>();

            //获取前台传会的删除ID
            WOtherIn otherIn = GetDelete <WOtherIn>();
            int      result  = inService.RemoveOtherIn(otherIn);

            if (result < 1)
            {
                rt.status  = -1;
                rt.message = "删除失败,只能删除新建单据.";
            }
            return(ReturnResult(rt));
        }
Пример #9
0
        /// <summary>
        /// 插入新其他入库
        /// </summary>
        /// <param name="otherIn"></param>
        /// <returns></returns>
        public ResultData <string> AddOtherIn(WOtherIn otherIn)
        {
            ResultData <string> rData = CheckValid(otherIn);

            if (rData.status != 0)
            {
                return(rData);
            }

            DatabaseContext dbContext = oiRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //入库记录
                List <WStockIn> stockIns = new List <WStockIn>(otherIn.Lines.Count);

                //添加其他入库
                otherIn.CreateDate  = DateTime.Now;
                otherIn.StockStatus = StockStatusEnum.New;
                otherIn.OtherInCode = nuRepository.GetNextNumber("QTRK");
                oiRepository.Insert(otherIn);

                foreach (var line in otherIn.Lines)
                {
                    line.ParentID   = otherIn.ID;
                    line.CreateBy   = otherIn.CreateBy;
                    line.CreateDate = DateTime.Now;
                    line.Batch      = string.IsNullOrEmpty(line.Batch) ? "" : line.Batch;
                    oilRepository.Insert(line);
                }

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
Пример #10
0
        /// <summary>
        /// 根据盘点单添加盘亏出库
        /// </summary>
        /// <param name="otherIn"></param>
        public int AddOtherLinesByInv(WOtherIn otherIn, int invId)
        {
            string sql = @"INSERT INTO WOtherInLine
                                    ( WarehouseID ,
                                      PositionID ,
                                      WarehouseCode ,
                                      PositionCode ,
                                      MaterialID ,
                                      MaterialCode ,
                                      UnitID ,
                                      Batch ,
                                      OwnerCode ,
                                      Factory ,
                                      CreateDate ,
                                      CreateBy ,
                                      UpdateDate ,
                                      UpdateBy ,
                                      InCount ,
                                      ParentID
                                    )
                        SELECT      WarehouseID ,
                                    PositionID ,
                                    WarehouseCode ,
                                    PositionCode ,
                                    MaterialID ,
                                    MaterialCode ,
                                    UnitID ,
                                    Batch ,
                                    OwnerCode ,
                                    Factory ,
			                        GETDATE() AS CreateDate,
			                        {0} AS CreateBy,
			                        GETDATE() AS UpdateDate,
			                        0 AS UpdateBy,
			                        InventoryDiff AS InCount,
			                        {1} AS ParentID
                        FROM WInventoryLine WITH(NOLOCK) WHERE ParentID={2} AND InventoryDiff>0";

            return(Execute(string.Format(sql, otherIn.CreateBy, otherIn.ID, invId)));
        }
Пример #11
0
        /// <summary>
        /// 其他入库复制入口记录
        /// </summary>
        /// <param name="line"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        private WStockIn CloneOtherIn(WOtherInLine line, WOtherIn other)
        {
            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    = other.OtherInCode;
            stockIn.SourceID      = line.ParentID;
            stockIn.SourceLineID  = line.ID;
            stockIn.StockInDate   = other.CreateDate;
            stockIn.StockInType   = other.StockInType;
            stockIn.UnitID        = line.UnitID;
            stockIn.WarehouseCode = line.WarehouseCode;
            stockIn.WarehouseID   = line.WarehouseID;
            return(stockIn);
        }
Пример #12
0
        /// <summary>
        /// 添加盘盈入库
        /// </summary>
        /// <param name="inv"></param>
        /// <returns></returns>
        public ResultData <string> AddProfit(WInventory inv)
        {
            ResultData <string> rData = new ResultData <string>();

            if (inv.InventoryStatus == InventoryStatusEnum.In)
            {
                rData.status  = -1;
                rData.message = "单据已经盘盈.";
                return(rData);
            }
            else if (inv.InventoryStatus == InventoryStatusEnum.Complete)
            {
                rData.status  = -1;
                rData.message = "单据已经完成.";
                return(rData);
            }

            if (ilRepository.HasNoProfit(inv.ID))
            {
                if (inv.InventoryStatus == InventoryStatusEnum.Out)
                {
                    iRepository.UpdateProfitStatus(inv.ID, 0, "", InventoryStatusEnum.Complete);
                }
                else
                {
                    iRepository.UpdateProfitStatus(inv.ID, 0, "", InventoryStatusEnum.In);
                }
                rData.status  = -1;
                rData.message = "单据没有盘盈记录.";
                return(rData);
            }

            DatabaseContext dbContext = ooRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                WOtherIn otherIn = new WOtherIn
                {
                    CreateBy    = inv.CreateBy,
                    CreateDate  = DateTime.Now,
                    OtherInCode = nuRepository.GetNextNumber("QTRK"),
                    StockInType = StockInEnum.InvProfit,
                    StockStatus = StockStatusEnum.New
                };

                //添加主表
                oiRepositroy.Insert(otherIn);

                //添加明细
                oilRepository.AddOtherLinesByInv(otherIn, inv.ID);

                //更新为盘点
                if (inv.InventoryStatus == InventoryStatusEnum.Out)
                {
                    iRepository.UpdateProfitStatus(inv.ID, otherIn.ID, otherIn.OtherInCode, InventoryStatusEnum.Complete);
                }
                else
                {
                    iRepository.UpdateProfitStatus(inv.ID, otherIn.ID, otherIn.OtherInCode, InventoryStatusEnum.In);
                }

                //返回插入的ID
                rData.result = otherIn.ID.ToString();

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