Exemple #1
0
        /// <summary>
        /// 按批次减少库存
        /// </summary>
        /// <param name="storeParam">库存处理入参</param>
        /// <returns>库存处理结果</returns>
        public DGStoreResult ReduceStore(StoreParam storeParam)
        {
            DGStoreResult storeResult = new DGStoreResult();

            if (storeParam != null)
            {
                DW_Storage storage = NewDao <IDWDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID);

                if (storage != null)
                {
                    DW_Batch batch = NewDao <IDWDao>().GetBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO);

                    if (batch != null)
                    {
                        //本批次存量 和库存总量都必须大于出库数量
                        if (batch.BatchAmount >= storeParam.Amount && storage.Amount >= storeParam.Amount)
                        {
                            storage.Amount = storage.Amount - storeParam.Amount;
                            storage.BindDb(this as AbstractBusines);
                            storage.save();
                            batch.BatchAmount -= storeParam.Amount;
                            batch.BindDb(this as AbstractBusines);
                            batch.save();

                            DGBatchAllot batchAllot = new DGBatchAllot();
                            batchAllot.BatchNO        = storeParam.BatchNO;
                            batchAllot.RetailPrice    = batch.RetailPrice;
                            batchAllot.StockPrice     = batch.StockPrice;
                            batchAllot.StoreAmount    = batch.BatchAmount;
                            batchAllot.StorageID      = storage.StorageID;
                            storeResult.BatchAllot    = new DGBatchAllot[1];
                            storeResult.BatchAllot[0] = batchAllot;
                            storeResult.StoreAmount   = storage.Amount;
                            storeResult.UnitAmount    = storeParam.UnitAmount;
                            storeResult.StorageID     = storage.StorageID;
                            return(storeResult);
                        }
                        else
                        {
                            storeResult.Result      = 1;
                            storeResult.StoreAmount = storage.Amount;
                            storeResult.UnitAmount  = 1;
                            storeResult.StorageID   = storage.StorageID;
                            return(storeResult);
                        }
                    }
                    else
                    {
                        storeResult.Result      = 1;
                        storeResult.StoreAmount = storage.Amount;
                        storeResult.UnitAmount  = 1;
                        storeResult.StorageID   = storage.StorageID;
                        return(storeResult);
                    }
                }
                else
                {
                    storeResult.Result = 1;
                    return(storeResult);
                }
            }

            return(storeResult);
        }