Ejemplo n.º 1
0
        /// <summary>
        /// 台账写入--批次发退药数量台账
        /// </summary>
        /// <param name="billHead">发药单表头</param>
        /// <param name="billDetails">发药单明细</param>
        /// <param name="batchAllot">批次</param>
        /// <param name="refundFlag">退药标志</param>
        /// <param name="storeParam">库存处理参数</param>
        public void WriteAccount(DS_OPDispHead billHead, DS_OPDispDetail billDetails, DGBatchAllot batchAllot, int refundFlag, StoreParam storeParam)
        {
            int    actYear;
            int    actMonth;
            string errMsg;

            if (!GetAccountTime(billHead.DeptID, out errMsg, out actYear, out actMonth))
            {
                throw new Exception(errMsg);
            }

            DS_Account account = NewObject <DS_Account>();

            account.BalanceYear  = actYear;
            account.BalanceMonth = actMonth;
            account.AccountType  = 0;//药房
            account.BalanceFlag  = 0;
            account.BatchNO      = billDetails.BatchNO;
            account.BusiType     = billHead.BusiType;
            account.CTypeID      = billDetails.CTypeID;
            account.DeptID       = billDetails.DeptID;
            account.DetailID     = billDetails.DispDetailID;
            account.DrugID       = billDetails.DrugID;
            account.UnitID       = billDetails.UnitID;
            account.UnitName     = billDetails.UnitName;
            account.RegTime      = DateTime.Now;
            account.UnitAmount   = batchAllot.UnitAmount;

            //盘盈 借方
            //盘亏 贷方
            if (billDetails.RetFlag == 1 || refundFlag == 1)
            {
                //退药 借方
                account.StockPrice    = storeParam.StockPrice;
                account.RetailPrice   = storeParam.RetailPrice;
                account.LendAmount    = Math.Abs(billDetails.DispAmount);
                account.LendRetailFee = batchAllot.DispRetailFee;
                account.LendStockFee  = batchAllot.DispStockFee;

                account.OverAmount = batchAllot.StoreAmount;

                //当药品批次价格和实际价格不一致时,退药按实际价格退
                if (storeParam.RetailPrice.Equals(batchAllot.RetailPrice) == false)
                {
                    account.OverRetailFee = batchAllot.StoreAmount * (storeParam.RetailPrice / storeParam.UnitAmount);
                }
                else
                {
                    account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount);
                }

                if (storeParam.StockPrice.Equals(batchAllot.StockPrice) == false)
                {
                    account.OverStockFee = batchAllot.StoreAmount * (storeParam.StockPrice / storeParam.UnitAmount);
                }
                else
                {
                    account.OverStockFee = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount);
                }
            }
            else
            {
                //发药 贷方
                account.StockPrice     = storeParam.StockPrice;
                account.RetailPrice    = storeParam.RetailPrice;
                account.DebitAmount    = billDetails.DispAmount;
                account.DebitRetailFee = batchAllot.DispRetailFee;
                account.DebitStockFee  = batchAllot.DispStockFee;

                account.OverAmount = batchAllot.StoreAmount;

                //当发药时价格和实际批次价格不一致时,剩余价格等于加上要发出的数量*调价后的金额减去发出药量的总金额(发出药量是按批次表原有的价格算的)
                if (storeParam.RetailPrice.Equals(batchAllot.RetailPrice) == false)
                {
                    account.OverRetailFee = ((batchAllot.StoreAmount + billDetails.DispAmount) * (batchAllot.RetailPrice / batchAllot.UnitAmount)) - batchAllot.DispRetailFee;
                }
                else
                {
                    account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount);
                }

                if (storeParam.StockPrice.Equals(batchAllot.StockPrice) == false)
                {
                    account.OverStockFee = ((batchAllot.StoreAmount + billDetails.DispAmount) * (batchAllot.StockPrice / batchAllot.UnitAmount)) - batchAllot.DispStockFee;
                }
                else
                {
                    account.OverStockFee = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount);
                }
            }

            account.save();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 台账写入
        /// </summary>
        /// <typeparam name="THead">药房盘点单表头模板</typeparam>
        /// <typeparam name="TDetail">药房盘点单明细模板</typeparam>
        /// <param name="billHead">药房盘点单头</param>
        /// <param name="billDetails">药房盘点单明细</param>
        /// <param name="batchAllot">批次分类对象</param>
        public void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGBatchAllot batchAllot)
        {
            DS_AuditDetail detail = billDetails as DS_AuditDetail;
            DS_AuditHead   head   = billHead as DS_AuditHead;
            int            actYear;
            int            actMonth;
            string         errMsg;

            if (!GetAccountTime(head.DeptID, out errMsg, out actYear, out actMonth))
            {
                throw new Exception(errMsg);
            }

            DS_Account account = NewObject <DS_Account>();

            account.BalanceYear  = actYear;
            account.BalanceMonth = actMonth;
            account.AccountType  = 0;
            account.BalanceFlag  = 0;
            account.RegTime      = System.DateTime.Now;
            account.BillNO       = head.BillNO;
            account.BatchNO      = detail.BatchNO;
            account.BusiType     = head.BusiType;
            account.CTypeID      = detail.CTypeID;
            account.DeptID       = head.DeptID;
            account.DetailID     = detail.AuditDetailID;
            account.DrugID       = detail.DrugID;
            account.UnitID       = detail.UnitID;
            account.UnitName     = detail.UnitName;

            //盘盈 借方
            //盘亏 贷方
            if (detail.FactAmount - detail.ActAmount > 0)
            {
                //借方
                account.StockPrice    = detail.StockPrice;
                account.RetailPrice   = detail.RetailPrice;
                account.LendAmount    = detail.FactAmount - detail.ActAmount;
                account.LendRetailFee = detail.FactRetailFee - detail.ActRetailFee;
                account.LendStockFee  = detail.FactStockFee - detail.ActStockFee;
                account.OverAmount    = batchAllot.StoreAmount;
                account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount);
                account.OverStockFee  = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount);
            }
            else
            {
                //贷方
                account.StockPrice     = detail.StockPrice;
                account.RetailPrice    = detail.RetailPrice;
                account.DebitAmount    = detail.ActAmount - detail.FactAmount;
                account.DebitRetailFee = detail.ActRetailFee - detail.FactRetailFee;
                account.DebitStockFee  = detail.ActStockFee - detail.FactStockFee;
                account.OverAmount     = batchAllot.StoreAmount;
                account.OverRetailFee  = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount);
                account.OverStockFee   = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount);
            }

            account.save();
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 台账写入--批次发退药价格差额台账
        /// </summary>
        /// <param name="billHead">发药单表头</param>
        /// <param name="billDetails">发药单明细</param>
        /// <param name="storeParam">库存参数</param>
        /// <param name="batchAllot">批次</param>
        public void WriteAccount(DS_OPDispHead billHead, DS_OPDispDetail billDetails, StoreParam storeParam, DGBatchAllot batchAllot)
        {
            int    actYear;
            int    actMonth;
            string errMsg;

            if (!GetAccountTime(billHead.DeptID, out errMsg, out actYear, out actMonth))
            {
                throw new Exception(errMsg);
            }

            DS_Account account = NewObject <DS_Account>();

            account.BalanceYear  = actYear;
            account.BalanceMonth = actMonth;
            account.AccountType  = 3;//药房
            account.BalanceFlag  = 0;
            account.BatchNO      = billDetails.BatchNO;
            account.BusiType     = billHead.BusiType;
            account.CTypeID      = billDetails.CTypeID;
            account.DeptID       = billDetails.DeptID;
            account.DetailID     = billDetails.DispDetailID;
            account.DrugID       = billDetails.DrugID;
            account.UnitID       = billDetails.UnitID;
            account.UnitName     = billDetails.UnitName;
            account.RegTime      = DateTime.Now;

            //盘盈 借方
            //盘亏 贷方
            if (storeParam.RetailPrice < billDetails.RetailPrice)
            {
                //该批次大于处方零售价写入 贷方
                account.StockPrice  = billDetails.StockPrice;
                account.RetailPrice = billDetails.RetailPrice;
                //发生调整时,数量为0,只调价格
                account.DebitAmount    = 0; //Math.Abs(billDetails.DispAmount);
                account.DebitRetailFee = GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, billDetails.RetailPrice, billHead.RecipeAmount) - GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, storeParam.RetailPrice, billHead.RecipeAmount);
                account.DebitStockFee  = GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, billDetails.StockPrice, billHead.RecipeAmount) - GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, storeParam.StockPrice, billHead.RecipeAmount);

                account.OverAmount    = batchAllot.StoreAmount;
                account.OverRetailFee = batchAllot.StoreAmount * (account.RetailPrice / batchAllot.UnitAmount);
                account.OverStockFee  = batchAllot.StoreAmount * (account.StockPrice / batchAllot.UnitAmount);
            }
            else
            {
                //发药 借方
                account.StockPrice  = billDetails.StockPrice;
                account.RetailPrice = billDetails.RetailPrice;
                //发生调整时,数量为0,只调价格
                account.LendAmount    = 0;//billDetails.DispAmount;
                account.LendRetailFee = GetFee(billDetails.DispAmount, billDetails.UnitAmount, storeParam.RetailPrice, billHead.RecipeAmount) - GetFee(billDetails.DispAmount, billDetails.UnitAmount, billDetails.RetailPrice, billHead.RecipeAmount);
                account.LendStockFee  = GetFee(billDetails.DispAmount, billDetails.UnitAmount, storeParam.StockPrice, billHead.RecipeAmount) - GetFee(billDetails.DispAmount, billDetails.UnitAmount, billDetails.StockPrice, billHead.RecipeAmount);

                account.OverAmount    = batchAllot.StoreAmount;
                account.OverRetailFee = batchAllot.StoreAmount * (account.RetailPrice / batchAllot.UnitAmount);
                account.OverStockFee  = batchAllot.StoreAmount * (account.StockPrice / batchAllot.UnitAmount);
            }

            account.save();
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 按批次增加库存
        /// </summary>
        /// <param name="storeParam">药品库存入参</param>
        /// <returns>库存处理结果</returns>
        public DGStoreResult AddStore(StoreParam storeParam)
        {
            DGStoreResult storeResult = new DGStoreResult();

            if (storeParam != null)
            {
                DS_Storage storage = NewDao <IDSDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID);
                if (storage != null)
                {
                    storeParam.StorageId = storage.StorageID;

                    //获取批次数据
                    DS_Batch batch = NewDao <IDSDao>().GetBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO);
                    if (batch != null)
                    {
                        //如果批次数量加退货数量大于0
                        if (batch.BatchAmount + storeParam.Amount >= 0 && storage.Amount + storeParam.Amount >= 0)
                        {
                            if ((batch.BatchAmount + storeParam.Amount) == 0)
                            {
                                //当库存量为零时,把批次记录标记为已删除,新增加该批次库存,然后再标记为有效
                                batch.DelFlag = 1;
                            }
                            else
                            {
                                batch.DelFlag = 0;
                            }

                            batch.BatchAmount += storeParam.Amount;
                            batch.BindDb(this as AbstractBusines);
                            batch.save();

                            storage.Amount += storeParam.Amount;
                            storage.BindDb(this as AbstractBusines);
                            storage.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    = 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.BussConstant == DGConstant.OP_DS_RETURNSOTRE)
                        {
                            //退库业务
                            storeResult.Result = 1;
                            return(storeResult);
                        }

                        if (storeParam.BussConstant == DGConstant.OP_DS_FIRSTIN)
                        {
                            if (storeParam.Amount < 0)
                            {
                                storeResult.Result = 1;
                                return(storeResult);
                            }
                        }

                        //新建批次
                        DS_Batch dwBatch = NewObject <DS_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.UnitAmount   = storeParam.PackAmount;//单位系数
                        dwBatch.InstoreTime  = System.DateTime.Now;
                        dwBatch.PackUnit     = storeParam.PackUnit;
                        dwBatch.UnitID       = storeParam.UnitID;
                        dwBatch.UnitName     = storeParam.UnitName;
                        dwBatch.RetailPrice  = storeParam.RetailPrice;
                        dwBatch.StockPrice   = storeParam.StockPrice;
                        dwBatch.save();
                        bool addRtn = NewDao <IDSDao>().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    = storeParam.PackAmount;
                            storeResult.StorageID     = storage.StorageID;
                        }
                        else
                        {
                            //添加失败
                            storeResult.Result      = 2;
                            storeResult.StoreAmount = storage.Amount;
                            storeResult.UnitAmount  = storeParam.PackAmount;
                            storeResult.StorageID   = storage.StorageID;
                            return(storeResult);
                        }
                    }
                }
                else
                {
                    if (storeParam.BussConstant == DGConstant.OP_DS_RETURNSOTRE)
                    {
                        //如果返库业务
                        storeResult.Result = 1;
                        return(storeResult);
                    }

                    if (storeParam.Amount < 0)
                    {
                        storeResult.Result = 1;
                        return(storeResult);
                    }

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

                    //新建批次记录
                    DS_Batch dwBatch = NewObject <DS_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.UnitAmount   = storeParam.PackAmount;
                    dwBatch.UnitID       = storeParam.UnitID;
                    dwBatch.PackUnit     = storeParam.PackUnit;
                    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  = storeParam.PackAmount;
                    storeResult.StorageID   = dwStorage.StorageID;
                    return(storeResult);
                }
            }

            return(storeResult);
        }