Exemple #1
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);
        }
Exemple #2
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);
        }