Example #1
0
        /// <summary>
        /// 按先进先出减少库存
        /// </summary>
        /// <param name="storeParam">库存参数</param>
        /// <param name="retAllBatch">true返回所有批次,返回</param>
        /// <returns>处理结果</returns>
        public DGStoreResult ReduceStoreAuto(StoreParam storeParam, bool retAllBatch)
        {
            DGStoreResult storeResult = new DGStoreResult();

            if (storeParam != null)
            {
                DS_Storage storage = NewDao <IDSDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID);
                if (storage != null)
                {
                    if (storage.Amount < storeParam.Amount)
                    {
                        //药品库存不足
                        //添加失败
                        storeResult.Result      = 2;
                        storeResult.StoreAmount = storage.Amount;
                        storeResult.UnitAmount  = storage.UnitAmount;
                        storeResult.StorageID   = storage.StorageID;
                        return(storeResult);
                    }

                    //减少药品库存
                    storage.Amount += -storeParam.Amount;

                    storage.BindDb(this as AbstractBusines);
                    int addStorageRtn = storage.save();

                    //取得所有批次
                    DataTable dtBatch    = NewDao <IDSDao>().GetStorageBatch(storage.StorageID);
                    decimal   tempAmount = Math.Abs(storeParam.Amount);
                    storeResult.BatchAllotList = new List <DGBatchAllot>();
                    storeResult.StoreAmount    = storage.Amount;
                    storeResult.StorageID      = storage.StorageID;
                    for (int i = 0; i < dtBatch.Rows.Count; i++)
                    {
                        DGBatchAllot batchAllot = new DGBatchAllot();
                        batchAllot.BatchNO      = dtBatch.Rows[i]["BatchNO"].ToString();
                        batchAllot.RetailPrice  = Convert.ToDecimal(dtBatch.Rows[i]["RetailPrice"]);
                        batchAllot.StockPrice   = Convert.ToDecimal(dtBatch.Rows[i]["StockPrice"]);
                        batchAllot.ValidityDate = Convert.ToDateTime(dtBatch.Rows[i]["ValidityTime"]);
                        batchAllot.StorageID    = storage.StorageID;
                        batchAllot.UnitAmount   = Convert.ToInt32(dtBatch.Rows[i]["UnitAmount"]);
                        decimal batchAmount = Convert.ToDecimal(dtBatch.Rows[i]["BatchAmount"]);
                        decimal retailPrice = storeParam.RetailPrice;//收费价格
                        decimal stockPrice  = storeParam.StockPrice;
                        decimal unitAmount  = Convert.ToDecimal(dtBatch.Rows[i]["UnitAmount"]);
                        decimal retailFee   = 0;
                        decimal stockFee    = 0;
                        decimal dispAmount  = 0;
                        if (tempAmount >= batchAmount)
                        {
                            stockFee  = batchAllot.CalFee(stockPrice, batchAllot.UnitAmount, batchAmount);
                            retailFee = batchAllot.CalFee(retailPrice, batchAllot.UnitAmount, batchAmount);
                            batchAllot.DispRetailFee = retailFee;
                            batchAllot.DispStockFee  = stockFee;
                            batchAllot.StoreAmount   = 0;
                            batchAllot.DispAmount    = batchAmount;
                            dispAmount = batchAmount;
                            storeResult.BatchAllotList.Add(batchAllot);
                            bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), -dispAmount, 0, 1);
                            if (!addBatchRtn)
                            {
                                storeResult.Result      = 1;
                                storeResult.StoreAmount = storage.Amount - storeParam.Amount;
                                storeResult.UnitAmount  = 1;
                                storeResult.StorageID   = storage.StorageID;
                                return(storeResult);
                            }
                        }
                        else
                        {
                            stockFee  = batchAllot.CalFee(stockPrice, batchAllot.UnitAmount, tempAmount);
                            retailFee = batchAllot.CalFee(retailPrice, batchAllot.UnitAmount, tempAmount);
                            batchAllot.DispRetailFee = retailFee;
                            batchAllot.DispStockFee  = stockFee;
                            batchAllot.StoreAmount   = batchAmount - tempAmount;
                            batchAllot.DispAmount    = tempAmount;
                            dispAmount = batchAmount;
                            storeResult.BatchAllotList.Add(batchAllot);
                            bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), -tempAmount, 0, 1);
                            if (!addBatchRtn)
                            {
                                storeResult.Result      = 1;
                                storeResult.StoreAmount = storage.Amount;
                                storeResult.UnitAmount  = 1;
                                storeResult.StorageID   = storage.StorageID;
                                return(storeResult);
                            }

                            break;
                        }

                        tempAmount -= batchAmount;
                    }
                }
            }

            return(storeResult);
        }
Example #2
0
        /// <summary>
        /// 按先进先出增加库存
        /// </summary>
        /// <param name="storeParam">药品库存入参</param>
        /// <param name="retAllBatch">true返回所有批次,返回</param>
        /// <returns>库存处理结果</returns>
        public DGStoreResult AddStoreAuto(StoreParam storeParam, bool retAllBatch)
        {
            DGStoreResult storeResult = new DGStoreResult();

            if (storeParam != null)
            {
                if (storeParam.Amount < 0)
                {
                    storeParam.Amount = Math.Abs(storeParam.Amount);
                }

                DS_Storage storage = NewDao <IDSDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID);
                if (storage != null)
                {
                    if (!retAllBatch)
                    {
                        //退药模式,返回最近入库批次
                        //获取该药品最近入库批次,将药品加到该批次上
                        DS_Batch latelyBatch = NewDao <IDSDao>().GetLatelyBatchInfo(storeParam.DeptID, storeParam.DrugID);
                        if (latelyBatch != null)
                        {
                            //增加药品库存
                            storage.Amount += storeParam.Amount;
                            int addStorageRtn = storage.save();

                            //增加药品批次库存
                            bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(latelyBatch.DeptID, latelyBatch.DrugID, latelyBatch.BatchNO, storeParam.Amount, 0, 1);

                            //如果批次数量加退货数量大于0
                            if (addStorageRtn >= 0 && addBatchRtn == true)
                            {
                                //添加成功
                                DGBatchAllot batchAllot = new DGBatchAllot();
                                batchAllot.BatchNO         = latelyBatch.BatchNO;
                                batchAllot.StoreAmount     = latelyBatch.BatchAmount + storeParam.Amount;
                                batchAllot.StorageID       = storage.StorageID;
                                batchAllot.RetailPrice     = latelyBatch.RetailPrice;
                                batchAllot.StockPrice      = latelyBatch.StockPrice;
                                batchAllot.DispAmount      = storeParam.Amount;
                                batchAllot.UnitAmount      = latelyBatch.UnitAmount;
                                batchAllot.DispRetailFee   = batchAllot.CalFee(storeParam.RetailPrice, latelyBatch.UnitAmount, storeParam.Amount);
                                batchAllot.DispStockFee    = batchAllot.CalFee(storeParam.StockPrice, latelyBatch.UnitAmount, storeParam.Amount);
                                storeResult.BatchAllotList = new List <DGBatchAllot>();
                                storeResult.BatchAllotList.Add(batchAllot);
                                storeResult.StoreAmount = storage.Amount + storeParam.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
                    {
                        //盘点模式返回所有批次
                        decimal profitAmount = storeParam.FactAmount - storeParam.ActAmount;

                        //更新药品库存
                        storage.Amount += profitAmount;
                        int addStorageRtn = storage.save();

                        //更新有效库存
                        if (profitAmount != 0)
                        {
                            UpdateValidStore(storeParam.DrugID, storeParam.DeptID, profitAmount);
                        }

                        //取得所有批次
                        DataTable dtBatch    = NewDao <IDSDao>().GetStorageBatch(storage.StorageID);
                        decimal   tempAmount = storeParam.FactAmount;
                        storeResult.BatchAllotList = new List <DGBatchAllot>();
                        storeResult.StoreAmount    = storage.Amount;
                        storeResult.StorageID      = storage.StorageID;
                        for (int i = dtBatch.Rows.Count - 1; i >= 0; i--)
                        {
                            DGBatchAllot batchAllot = new DGBatchAllot();
                            batchAllot.BatchNO     = dtBatch.Rows[i]["BatchNO"].ToString();
                            batchAllot.RetailPrice = Convert.ToDecimal(dtBatch.Rows[i]["RetailPrice"]);
                            batchAllot.StockPrice  = Convert.ToDecimal(dtBatch.Rows[i]["StockPrice"]);

                            batchAllot.ValidityDate = Convert.ToDateTime(dtBatch.Rows[i]["ValidityTime"]);
                            batchAllot.StorageID    = storage.StorageID;
                            batchAllot.DispAmount   = storeParam.Amount;
                            batchAllot.UnitAmount   = Convert.ToInt32(dtBatch.Rows[i]["UnitAmount"]);

                            decimal batchAmount = Convert.ToDecimal(dtBatch.Rows[i]["BatchAmount"]);
                            decimal retailPrice = Convert.ToDecimal(dtBatch.Rows[i]["RetailPrice"]);
                            decimal stockPrice  = Convert.ToDecimal(dtBatch.Rows[i]["StockPrice"]);//盘点按照批次库存价格调整
                            decimal unitAmount  = Convert.ToDecimal(dtBatch.Rows[i]["UnitAmount"]);

                            decimal factAmount    = 0;
                            decimal factStockFee  = 0;
                            decimal factRetailFee = 0;
                            decimal actAmount     = 0;
                            decimal actStockFee   = 0;
                            decimal actRetailFee  = 0;
                            if (tempAmount >= batchAmount)
                            {
                                //按照批次数计算金额
                                if (profitAmount > 0 && i == dtBatch.Rows.Count - 1)
                                {
                                    //盘盈加入到最近入库批次
                                    factAmount             = batchAmount + profitAmount;
                                    factStockFee           = batchAllot.CalFee(stockPrice, unitAmount, factAmount);
                                    factRetailFee          = batchAllot.CalFee(retailPrice, unitAmount, factAmount);
                                    actAmount              = batchAmount;
                                    actStockFee            = batchAllot.CalFee(stockPrice, unitAmount, actAmount);
                                    actRetailFee           = batchAllot.CalFee(retailPrice, unitAmount, actAmount);
                                    batchAllot.StoreAmount = factAmount;

                                    //更改批次库存
                                    //增加药品批次库存
                                    bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), profitAmount, 0, 1);
                                    if (!addBatchRtn)
                                    {
                                        storeResult.Result      = 1;
                                        storeResult.StoreAmount = storage.Amount;
                                        storeResult.UnitAmount  = 1;
                                        storeResult.StorageID   = storage.StorageID;
                                        return(storeResult);
                                    }
                                }
                                else
                                {
                                    factAmount             = batchAmount;
                                    factStockFee           = batchAllot.CalFee(stockPrice, unitAmount, factAmount);
                                    factRetailFee          = batchAllot.CalFee(retailPrice, unitAmount, factAmount);
                                    actAmount              = batchAmount;
                                    actStockFee            = factStockFee;
                                    actRetailFee           = factRetailFee;
                                    batchAllot.StoreAmount = factAmount;
                                }

                                tempAmount -= batchAmount;
                            }
                            else
                            {
                                if (tempAmount > 0)
                                {
                                    //按照剩余数算
                                    factAmount             = tempAmount;
                                    factStockFee           = batchAllot.CalFee(stockPrice, unitAmount, factAmount);
                                    factRetailFee          = batchAllot.CalFee(retailPrice, unitAmount, factAmount);
                                    actAmount              = batchAmount;
                                    actStockFee            = batchAllot.CalFee(stockPrice, unitAmount, actAmount);
                                    actRetailFee           = batchAllot.CalFee(retailPrice, unitAmount, actAmount);
                                    batchAllot.StoreAmount = tempAmount;
                                }
                                else
                                {
                                    factAmount             = 0;
                                    factStockFee           = batchAllot.CalFee(stockPrice, unitAmount, factAmount);
                                    factRetailFee          = batchAllot.CalFee(retailPrice, unitAmount, factAmount);
                                    actAmount              = batchAmount;
                                    actStockFee            = batchAllot.CalFee(stockPrice, unitAmount, actAmount);
                                    actRetailFee           = batchAllot.CalFee(retailPrice, unitAmount, actAmount);
                                    batchAllot.StoreAmount = 0;
                                }

                                //增加药品批次库存
                                bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), -(batchAmount - tempAmount), 0, 1);
                                if (!addBatchRtn)
                                {
                                    storeResult.Result      = 1;
                                    storeResult.StoreAmount = storage.Amount;
                                    storeResult.UnitAmount  = 1;
                                    storeResult.StorageID   = storage.StorageID;
                                    return(storeResult);
                                }

                                tempAmount = 0;
                            }

                            batchAllot.FactAmount    = factAmount;
                            batchAllot.FactStockFee  = factStockFee;
                            batchAllot.FactRetailFee = factRetailFee;
                            batchAllot.ActAmount     = actAmount;
                            batchAllot.ActStockFee   = actStockFee;
                            batchAllot.ActRetailFee  = actRetailFee;
                            storeResult.BatchAllotList.Add(batchAllot);
                        }
                    }
                }
            }

            return(storeResult);
        }