Beispiel #1
0
        /// <summary>
        /// 检查
        /// </summary>
        /// <param name="otherOut"></param>
        /// <returns></returns>
        private ResultData <string> CheckValid(WOtherOut otherOut)
        {
            ResultData <string> rt = new ResultData <string>();

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

            return(rt);
        }
Beispiel #2
0
        /// <summary>
        /// 更新其他出库
        /// </summary>
        /// <param name="otherOut"></param>
        /// <returns></returns>
        public ResultData <string> UpdateOtherOut(WOtherOut otherOut)
        {
            ResultData <string> rData = CheckValid(otherOut);

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

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

            DatabaseContext db = ooRepository.DbCondext;

            try
            {
                db.BeginTransaction();

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

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

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

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

            WOtherOut otherOut = GetAdd <WOtherOut>();

            otherOut.CreateBy = this.CurrentUser.ID;
            rt = outService.AddOtherOut(otherOut);
            return(ReturnResult(rt));
        }
Beispiel #4
0
        public ActionResult Approve()
        {
            ResultData <string> rt = new ResultData <string>();

            WOtherOut otherOut = GetParam <WOtherOut>("app");

            otherOut.UpdateBy = this.CurrentUser.ID;
            rt = outService.ApproveOtherOut(otherOut);

            return(ReturnResult(rt));
        }
Beispiel #5
0
        public ContentResult Update()
        {
            ResultData <string> rt = new ResultData <string>();

            WOtherOut otherOut = GetUpdate <WOtherOut>();

            otherOut.UpdateBy = this.CurrentUser.ID;
            rt = outService.UpdateOtherOut(otherOut);

            return(ReturnResult(rt));
        }
Beispiel #6
0
        /// <summary>
        /// 删除其他出库
        /// </summary>
        /// <param name="otherOut"></param>
        /// <returns></returns>
        public int RemoveOtherOut(WOtherOut otherOut)
        {
            //删除其他出库
            int result = ooRepository.RemoveOtherOutByStatus(otherOut.ID, StockStatusEnum.New);

            if (result > 0)
            {
                oolRepository.RemoveLinesByParentId(otherOut.ID);
            }
            return(result);
        }
Beispiel #7
0
        /// <summary>
        /// 审核
        /// </summary>
        /// <param name="otherOut"></param>
        /// <returns></returns>
        public ResultData <string> ApproveOtherOut(WOtherOut otherOut)
        {
            ResultData <string> rData = new ResultData <string>();

            if (otherOut.Lines.Count < 1)
            {
                otherOut.Lines = oolRepository.GetLinesByParentId(otherOut.ID);
            }

            DatabaseContext dbContext = ooRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //出库记录
                List <WStockOut> stockOuts = new List <WStockOut>(otherOut.Lines.Count);

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

                foreach (var line in otherOut.Lines)
                {
                    stockOuts.Add(CloneOtherOut(line, otherOut));
                }

                //更新库存
                WStockService sService = new WStockService(dbContext);
                rData = sService.DeleteStocks(stockOuts);
                if (rData.status != 0)
                {
                    dbContext.AbortTransaction();
                }
                else
                {
                    dbContext.CompleteTransaction();
                }
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
Beispiel #8
0
        public ContentResult Delete()
        {
            ResultData <string> rt = new ResultData <string>();

            //获取前台传会的删除ID
            WOtherOut otherOut = GetDelete <WOtherOut>();
            int       result   = outService.RemoveOtherOut(otherOut);

            if (result < 1)
            {
                rt.status  = -1;
                rt.message = "删除失败,只能删除新建单据.";
            }
            return(ReturnResult(rt));
        }
Beispiel #9
0
        /// <summary>
        /// 根据盘点单添加盘亏出库
        /// </summary>
        /// <param name="otherOut"></param>
        public int AddOtherLinesByInv(WOtherOut otherOut, int invId)
        {
            string sql = @"INSERT INTO WOtherOutLine
                                      ( WarehouseID ,
                                        PositionID ,
                                        WarehouseCode ,
                                        PositionCode ,
                                        MaterialID ,
                                        MaterialCode ,
                                        UnitID ,
                                        Batch ,
                                        OwnerCode ,
                                        Factory ,
                                        CreateDate ,
                                        CreateBy ,
                                        UpdateDate ,
                                        UpdateBy ,
                                        OutCount ,
                                        StockID ,
                                        StockInDate ,
                                        ParentID
                                      )
                            SELECT WarehouseID ,
                                        PositionID ,
                                        WarehouseCode ,
                                        PositionCode ,
                                        MaterialID ,
                                        MaterialCode ,
                                        UnitID ,
                                        Batch ,
                                        OwnerCode ,
                                        Factory ,
			                            GETDATE() AS CreateDate,
			                            {0} AS CreateBy,
			                            GETDATE() AS UpdateDate,
			                            0 AS UpdateBy,
			                            0-InventoryDiff AS OutCount,
			                            StockID,
			                            StockInDate,
			                            {1} AS ParentID
                            FROM WInventoryLine WITH(NOLOCK) WHERE ParentID={2} AND InventoryDiff<0";

            return(Execute(string.Format(sql, otherOut.CreateBy, otherOut.ID, invId)));
        }
Beispiel #10
0
        /// <summary>
        /// 插入新其他出库
        /// </summary>
        /// <param name="otherOut"></param>
        /// <returns></returns>
        public ResultData <string> AddOtherOut(WOtherOut otherOut)
        {
            ResultData <string> rData = CheckValid(otherOut);

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

            DatabaseContext dbContext = ooRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();
                //出库记录
                List <WStockOut> stockOuts = new List <WStockOut>(otherOut.Lines.Count);

                //添加其他出库
                otherOut.CreateDate   = DateTime.Now;
                otherOut.StockStatus  = StockStatusEnum.New;
                otherOut.OtherOutCode = nuRepository.GetNextNumber("QTCK");
                ooRepository.Insert(otherOut);

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

                dbContext.CompleteTransaction();
            }
            catch (Exception ex)
            {
                dbContext.AbortTransaction();
                throw ex;
            }
            return(rData);
        }
Beispiel #11
0
        /// <summary>
        /// 其他出库复制入口记录
        /// </summary>
        /// <param name="line"></param>
        /// <param name="other"></param>
        /// <returns></returns>
        private WStockOut CloneOtherOut(WOtherOutLine line, WOtherOut other)
        {
            WStockOut stockOut = new WStockOut();

            stockOut.Batch         = line.Batch;         //批次
            stockOut.Factory       = line.Factory;       //工厂
            stockOut.OutCount      = line.OutCount;      //出库数量
            stockOut.MaterialCode  = line.MaterialCode;  //物理编码
            stockOut.MaterialID    = line.MaterialID;    //物料ID
            stockOut.OwnerCode     = line.OwnerCode;     //所有者
            stockOut.PositionCode  = line.PositionCode;  //货位编码
            stockOut.PositionID    = line.PositionID;    //货位ID
            stockOut.SourceCode    = other.OtherOutCode; //出库单号
            stockOut.SourceID      = line.ParentID;      //出库ID
            stockOut.SourceLineID  = line.ID;            //出库行ID
            stockOut.StockOutDate  = other.CreateDate;   //出库时间
            stockOut.StockOutType  = other.StockOutType; //出库类型
            stockOut.UnitID        = line.UnitID;        //单位
            stockOut.WarehouseCode = line.WarehouseCode; //仓库编码
            stockOut.WarehouseID   = line.WarehouseID;   //仓库ID
            stockOut.StockInDate   = line.StockInDate;   //入库时间
            stockOut.StockID       = line.StockID;       //库存ID
            return(stockOut);
        }
Beispiel #12
0
        /// <summary>
        /// 添加盘亏出库
        /// </summary>
        /// <param name="inv"></param>
        /// <returns></returns>
        public ResultData <string> AddLoss(WInventory inv)
        {
            ResultData <string> rData = new ResultData <string>();

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

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

            DatabaseContext dbContext = ooRepository.DbCondext;

            try
            {
                dbContext.BeginTransaction();

                WOtherOut otherOut = new WOtherOut
                {
                    CreateBy     = inv.CreateBy,
                    CreateDate   = DateTime.Now,
                    OtherOutCode = nuRepository.GetNextNumber("QTCK"),
                    StockOutType = StockOutEnum.InvShortages,
                    StockStatus  = StockStatusEnum.New
                };

                //添加主表
                ooRepository.Insert(otherOut);

                //更新为盘点
                if (inv.InventoryStatus == InventoryStatusEnum.In)
                {
                    iRepository.UpdateLossStatus(inv.ID, otherOut.ID, otherOut.OtherOutCode, InventoryStatusEnum.Complete);
                }
                else if (inv.InventoryStatus == InventoryStatusEnum.Complete)
                {
                    rData.status  = -1;
                    rData.message = "单据已经完成.";
                    return(rData);
                }
                else
                {
                    iRepository.UpdateLossStatus(inv.ID, otherOut.ID, otherOut.OtherOutCode, InventoryStatusEnum.Out);
                }

                //添加明细
                oolRepository.AddOtherLinesByInv(otherOut, inv.ID);

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

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