Exemplo n.º 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);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存台账
        /// </summary>
        /// <typeparam name="TBatch">批次类型</typeparam>
        /// <param name="batchs">批次对象</param>
        /// <param name="currentDetail">当前调价明细单对象</param>
        public void SaveAccout <TBatch>(TBatch batchs, DG_AdjDetail currentDetail)
        {
            string errMsg   = string.Empty;
            int    actYear  = 0;
            int    actMonth = 0;
            int    actId    = 0;

            if (batchs.GetType() == typeof(DW_Batch))
            {
                DW_Batch batch = batchs as DW_Batch;
                currentDetail.AdjAmount = batch.BatchAmount;
                batch.RetailPrice       = currentDetail.NewRetailPrice;
                this.BindDb(batch);
                int dwresult = batch.save();
                if (dwresult > 0)
                {
                    this.BindDb(currentDetail);
                    int detailresult = currentDetail.save();
                    if (detailresult > 0)
                    {
                        if (!GetDWAccountTime(batch.DeptID, out errMsg, out actYear, out actMonth, out actId))
                        {
                            throw new Exception(errMsg);
                        }

                        DW_Account newaccount = new DW_Account();
                        newaccount.AccountType    = 0;
                        newaccount.BalanceFlag    = 0;
                        newaccount.BalanceID      = actId;
                        newaccount.BalanceMonth   = actMonth;
                        newaccount.BalanceYear    = actYear;
                        newaccount.BatchNO        = batch.BatchNO;
                        newaccount.BillNO         = currentDetail.BillNO;
                        newaccount.BusiType       = DGConstant.OP_DW_ADJPRICE;
                        newaccount.CTypeID        = NewDao <IDWDao>().GetTypeId(batch.BatchNO, batch.DrugID);
                        newaccount.LendRetailFee  = currentDetail.NewRetailPrice > currentDetail.OldRetailPrice ? (currentDetail.NewRetailPrice - currentDetail.OldRetailPrice) * currentDetail.AdjAmount : 0;
                        newaccount.DebitRetailFee = currentDetail.NewRetailPrice < currentDetail.OldRetailPrice ? (currentDetail.OldRetailPrice - currentDetail.NewRetailPrice) * currentDetail.AdjAmount : 0;
                        newaccount.OverRetailFee  = currentDetail.NewRetailPrice * currentDetail.AdjAmount;
                        newaccount.DebitAmount    = 0;
                        newaccount.LendAmount     = 0;
                        newaccount.OverAmount     = currentDetail.AdjAmount;
                        newaccount.OverStockFee   = batch.StockPrice * currentDetail.AdjAmount;
                        newaccount.DebitStockFee  = 0;
                        newaccount.LendStockFee   = 0;
                        newaccount.DeptID         = batch.DeptID;
                        newaccount.DetailID       = detailresult;
                        newaccount.DrugID         = batch.DrugID;
                        newaccount.UnitName       = currentDetail.PackUnitName;
                        newaccount.UnitID         = currentDetail.UnitID;
                        newaccount.StockPrice     = batch.StockPrice;
                        newaccount.RegTime        = DateTime.Now;
                        newaccount.RetailPrice    = currentDetail.NewRetailPrice;
                        this.BindDb(newaccount);
                        newaccount.save();
                    }
                }
            }
            else
            {
                DS_Batch batch = batchs as DS_Batch;
                currentDetail.AdjAmount = batch.BatchAmount;
                batch.RetailPrice       = currentDetail.NewRetailPrice;
                this.BindDb(batch);
                int dsresult = batch.save();
                if (dsresult > 0)
                {
                    this.BindDb(currentDetail);
                    int detailresult = currentDetail.save();
                    if (detailresult > 0)
                    {
                        if (!GetDSAccountTime(batch.DeptID, out errMsg, out actYear, out actMonth, out actId))
                        {
                            throw new Exception(errMsg);
                        }

                        DS_Account newaccount = new DS_Account();
                        newaccount.AccountType    = 0;
                        newaccount.BalanceFlag    = 0;
                        newaccount.BalanceID      = actId;
                        newaccount.BalanceMonth   = actMonth;
                        newaccount.BalanceYear    = actYear;
                        newaccount.BatchNO        = batch.BatchNO;
                        newaccount.BillNO         = currentDetail.BillNO;
                        newaccount.BusiType       = DGConstant.OP_DS_ADJPRICE;
                        newaccount.CTypeID        = NewDao <IDSDao>().GetTypeId(batch.BatchNO, batch.DrugID);
                        newaccount.LendRetailFee  = (currentDetail.NewRetailPrice > currentDetail.OldRetailPrice) ? ((currentDetail.NewRetailPrice - currentDetail.OldRetailPrice) * (currentDetail.AdjAmount / batch.UnitAmount)) : 0;
                        newaccount.DebitRetailFee = (currentDetail.NewRetailPrice < currentDetail.OldRetailPrice) ? ((currentDetail.OldRetailPrice - currentDetail.NewRetailPrice) * (currentDetail.AdjAmount / batch.UnitAmount)) : 0;
                        newaccount.OverRetailFee  = (currentDetail.NewRetailPrice * (currentDetail.AdjAmount / batch.UnitAmount));
                        newaccount.DebitAmount    = 0;
                        newaccount.LendAmount     = 0;
                        newaccount.OverAmount     = currentDetail.AdjAmount;
                        newaccount.OverStockFee   = (batch.StockPrice * (currentDetail.AdjAmount / batch.UnitAmount));
                        newaccount.DebitStockFee  = 0;
                        newaccount.LendStockFee   = 0;
                        newaccount.DeptID         = batch.DeptID;
                        newaccount.DetailID       = detailresult;
                        newaccount.DrugID         = batch.DrugID;
                        newaccount.UnitName       = currentDetail.UnitName;
                        newaccount.UnitID         = currentDetail.UnitID;
                        newaccount.StockPrice     = batch.StockPrice;
                        newaccount.RegTime        = DateTime.Now;
                        newaccount.RetailPrice    = currentDetail.NewRetailPrice;
                        this.BindDb(newaccount);
                        newaccount.save();
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// 按批次增加库存
        /// </summary>
        /// <param name="storeParam">药品库存入参</param>
        /// <returns>库存处理结果</returns>
        public DGStoreResult AddStore(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)
                    {
                        //如果批次数量加退货数量大于0
                        if (batch.BatchAmount + storeParam.Amount >= 0)
                        {
                            bool addRtn = NewDao <IDWDao>().AddStoreAmount(storeParam.DeptID, storeParam.DrugID, storeParam.Amount);
                            addRtn = NewDao <IDWDao>().AddBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO, storeParam.Amount);
                            if (addRtn)
                            {
                                //添加成功
                                DGBatchAllot batchAllot = new DGBatchAllot();
                                batchAllot.BatchNO        = storeParam.BatchNO;
                                batchAllot.RetailPrice    = batch.RetailPrice;
                                batchAllot.StockPrice     = batch.StockPrice;
                                batchAllot.StoreAmount    = batch.BatchAmount + storeParam.Amount;
                                batchAllot.StorageID      = storage.StorageID;
                                storeResult.BatchAllot    = new DGBatchAllot[1];
                                storeResult.BatchAllot[0] = batchAllot;
                                storeResult.StoreAmount   = storage.Amount + storeParam.Amount;
                                storeResult.UnitAmount    = 1;
                                storeResult.StorageID     = storage.StorageID;
                                return(storeResult);
                            }
                            else
                            {
                                //添加失败
                                storeResult.Result      = 2;
                                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
                    {
                        //批次不存在
                        if (storeParam.Amount < 0)
                        {
                            storeResult.Result = 1;
                            return(storeResult);
                        }

                        //新建批次
                        DW_Batch dwBatch = NewObject <DW_Batch>();
                        dwBatch.StorageID    = storage.StorageID;
                        dwBatch.BatchAmount  = storeParam.Amount;
                        dwBatch.BatchNO      = storeParam.BatchNO;
                        dwBatch.ValidityTime = storeParam.ValidityTime;
                        dwBatch.DelFlag      = 0;
                        dwBatch.DeptID       = storeParam.DeptID;
                        dwBatch.DrugID       = storeParam.DrugID;
                        dwBatch.DelFlag      = 0;
                        dwBatch.InstoreTime  = System.DateTime.Now;
                        dwBatch.UnitID       = storeParam.UnitID;
                        dwBatch.UnitName     = storeParam.UnitName;
                        dwBatch.RetailPrice  = storeParam.RetailPrice;
                        dwBatch.StockPrice   = storeParam.StockPrice;
                        dwBatch.save();
                        bool addRtn = NewDao <IDWDao>().AddStoreAmount(storeParam.DeptID, storeParam.DrugID, storeParam.Amount);//改库存
                        if (addRtn)
                        {
                            //构建返回值
                            DGBatchAllot batchAllot = new DGBatchAllot();
                            batchAllot.BatchNO        = storeParam.BatchNO;
                            batchAllot.RetailPrice    = dwBatch.RetailPrice;
                            batchAllot.StockPrice     = dwBatch.StockPrice;
                            batchAllot.StoreAmount    = dwBatch.BatchAmount;
                            batchAllot.StorageID      = storage.StorageID;
                            storeResult.BatchAllot    = new DGBatchAllot[1];
                            storeResult.BatchAllot[0] = batchAllot;
                            storeResult.StoreAmount   = storage.Amount + storeParam.Amount;
                            storeResult.UnitAmount    = 1;
                            storeResult.StorageID     = storage.StorageID;
                        }
                        else
                        {
                            //添加失败
                            storeResult.Result      = 2;
                            storeResult.StoreAmount = storage.Amount;
                            storeResult.UnitAmount  = 1;
                            storeResult.StorageID   = storage.StorageID;
                            return(storeResult);
                        }
                    }
                }
                else
                {
                    if (storeParam.Amount < 0)
                    {
                        storeResult.Result = 1;
                        return(storeResult);
                    }

                    //新建库存记录
                    DW_Storage dwStorage = NewObject <DW_Storage>();
                    dwStorage.DrugID      = storeParam.DrugID;
                    dwStorage.DeptID      = storeParam.DeptID;
                    dwStorage.DelFlag     = 0;
                    dwStorage.UnitID      = storeParam.UnitID;
                    dwStorage.UnitName    = storeParam.UnitName;
                    dwStorage.Amount      = storeParam.Amount;
                    dwStorage.UpperLimit  = 0;
                    dwStorage.LowerLimit  = 0;
                    dwStorage.LocationID  = 0;
                    dwStorage.Place       = string.Empty;
                    dwStorage.RegTime     = System.DateTime.Now;
                    dwStorage.LStockPrice = 0;
                    dwStorage.save();

                    //新建批次记录
                    DW_Batch dwBatch = NewObject <DW_Batch>();
                    dwBatch.StorageID    = dwStorage.StorageID;
                    dwBatch.BatchAmount  = storeParam.Amount;
                    dwBatch.BatchNO      = storeParam.BatchNO;
                    dwBatch.ValidityTime = storeParam.ValidityTime;
                    dwBatch.DelFlag      = 0;
                    dwBatch.DeptID       = storeParam.DeptID;
                    dwBatch.DrugID       = storeParam.DrugID;
                    dwBatch.DelFlag      = 0;
                    dwBatch.InstoreTime  = dwStorage.RegTime;
                    dwBatch.UnitID       = storeParam.UnitID;
                    dwBatch.UnitName     = storeParam.UnitName;
                    dwBatch.RetailPrice  = storeParam.RetailPrice;
                    dwBatch.StockPrice   = storeParam.StockPrice;
                    dwBatch.save();

                    //构建返回值
                    DGBatchAllot batchAllot = new DGBatchAllot();
                    batchAllot.BatchNO     = storeParam.BatchNO;
                    batchAllot.RetailPrice = storeParam.RetailPrice;
                    batchAllot.StockPrice  = storeParam.StockPrice;
                    batchAllot.StoreAmount = storeParam.Amount;
                    batchAllot.StorageID   = dwStorage.StorageID;
                    storeResult.BatchAllot = new DGBatchAllot[1] {
                        batchAllot
                    };
                    storeResult.StoreAmount = storeParam.Amount;
                    storeResult.UnitAmount  = 1;
                    storeResult.StorageID   = dwStorage.StorageID;
                    return(storeResult);
                }
            }

            return(storeResult);
        }