/// <summary>
        /// 生成入库单
        /// </summary>
        private BillStoringVM GenerateStoring(BillStoringProductExchangeEntity entity)
        {
            BillStoringVM storing = new BillStoringVM();
            BillStoring   bill    = storing.Master;

            bill.OrganizationID   = VMGlobal.CurrentUser.OrganizationID;
            bill.StorageID        = entity.StorageID;
            bill.RefrenceBillCode = entity.Code;
            bill.BillType         = (int)BillTypeEnum.BillProductExchange;
            bill.Remark           = "交接入库";
            bill.BrandID          = entity.BrandID;

            List <BillStoringDetails> siDetails = new List <BillStoringDetails>();

            foreach (var p in entity.Details)
            {
                siDetails.Add(new BillStoringDetails
                {
                    ProductID = p.ProductID,
                    Quantity  = p.Quantity
                });
            }
            ;
            storing.Details = siDetails;
            return(storing);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 生成入库单
        /// </summary>
        private BillStoringVM GenerateStoring(int brandID)
        {
            var           bill     = this.Master;
            BillStoringVM storing  = new BillStoringVM();
            var           soMaster = storing.Master;

            soMaster.Remark         = "零售入库";
            soMaster.BillType       = (int)BillTypeEnum.BillRetail;
            soMaster.OrganizationID = VMGlobal.CurrentUser.OrganizationID;
            soMaster.StorageID      = bill.StorageID;
            soMaster.BrandID        = brandID;

            List <BillStoringDetails> soDetails = new List <BillStoringDetails>();

            this.TraverseGridDataItems(p =>
            {
                if (p.BrandID == brandID && p.Quantity < 0)
                {
                    soDetails.Add(new BillStoringDetails
                    {
                        ProductID = p.ProductID,
                        Quantity  = (-1) * p.Quantity
                    });
                }
            });
            storing.Details = soDetails;
            return(storing);
        }
        public OPResult Storing(BillStoringProductExchangeEntity entity)
        {
            if (entity.Status == (int)BillProductExchangeStatusEnum.已入库)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "该单已经入库."
                });
            }
            if (entity.Status == (int)BillProductExchangeStatusEnum.被退回)
            {
                return(new OPResult {
                    IsSucceed = false, Message = "被退回单据不能入库."
                });
            }
            if (entity.StorageID == default(int))
            {
                return(new OPResult {
                    IsSucceed = false, Message = "请选择入库仓库."
                });
            }
            BillStoringVM       storingvm = this.GenerateStoring(entity);
            BillProductExchange pe        = VMGlobal.ManufacturingQuery.LinqOP.GetById <BillProductExchange>(entity.ID);

            pe.Status = (int)BillProductExchangeStatusEnum.已入库;
#if UniqueCode
            var uniqueCodes = BillStoringVM.GetSnapshotDetails(pe.Code);
#endif
            using (TransactionScope scope = new TransactionScope())
            {
                try
                {
                    storingvm.SaveWithNoTran();
                    VMGlobal.ManufacturingQuery.LinqOP.Update <BillProductExchange>(pe);
#if UniqueCode
                    storingvm.SaveUniqueCodes(uniqueCodes);
#endif
                    scope.Complete();
                }
                catch (Exception e)
                {
                    return(new OPResult {
                        IsSucceed = false, Message = "入库失败\n失败原因:" + e.Message
                    });
                }
            }
            entity.Status = (int)BillProductExchangeStatusEnum.已入库;
            ((ObservableCollection <BillStoringProductExchangeEntity>) this.Entities).Remove(entity);
            return(new OPResult {
                IsSucceed = true, Message = "入库成功."
            });
        }