/// <summary>
        /// 审核药库入库单
        /// </summary>
        /// <param name="headID">药库入库单表头</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <returns>单据处理结果</returns>
        public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName)
        {
            DW_InStoreHead          head       = (DW_InStoreHead)NewObject <DW_InStoreHead>().getmodel(headID);
            List <DW_InStoreDetail> lstDetails = NewObject <DW_InStoreDetail>().getlist <DW_InStoreDetail>("InHeadID=" + headID);

            head.AuditEmpID   = auditEmpID;
            head.AuditEmpName = auditEmpName;
            head.AuditTime    = System.DateTime.Now;
            head.AuditFlag    = 1;
            head.save();
            DGBillResult result = new DGBillResult();

            foreach (DW_InStoreDetail detail in lstDetails)
            {
                StoreParam storeParam = new StoreParam();
                storeParam.Amount       = detail.Amount;
                storeParam.BatchNO      = detail.BatchNo;
                storeParam.DeptID       = head.DeptID;
                storeParam.DrugID       = detail.DrugID;
                storeParam.RetailPrice  = detail.RetailPrice;
                storeParam.StockPrice   = detail.StockPrice;
                storeParam.UnitID       = detail.UnitID;
                storeParam.UnitName     = detail.UnitName;
                storeParam.ValidityTime = detail.ValidityDate;
                storeParam.BussConstant = head.BusiType;
                //storeParam.PackUnit = detail.PackUnit;
                DGStoreResult storeRtn = iStore.AddStore(storeParam);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <DGNotEnough>();
                        DGNotEnough notEnough = new DGNotEnough();
                        notEnough.DeptID     = head.DeptID;
                        notEnough.DrugID     = detail.DrugID;
                        notEnough.LackAmount = storeRtn.StoreAmount + detail.Amount;
                        notEnough.DrugInfo   = "药品编号" + detail.DrugID + "药品批次号:" + detail.BatchNo;
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "药品更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    WriteAccount(head, detail, storeRtn);
                }
            }

            result.Result = 0;
            return(result);
        }
Exemple #2
0
    //----------------------------------------------------------------------------

    /*!
     *          @brief	イベント情報取得処理
     */
    //----------------------------------------------------------------------------
    private void SendShopProduct()
    {
        ServerDataUtilSend.SendPacketAPI_GetStoreProductEvent()
        .setSuccessAction(_data =>
        {
            RecvGetStoreProductEventValue result            = _data.GetResult <RecvGetStoreProductEvent>().result;
            UserDataAdmin.Instance.m_StructProductEvent     = result.store_product_event;
            UserDataAdmin.Instance.m_StructPlayer.pay_month = result.player.pay_month;

            //----------------------------------------
            // 現在時の状態で、StoreParam内のストア商品一覧を固める
            //----------------------------------------
            StoreParam.SetupStoreProductListNow();

            //アイテム選択へ
            SendStepItemSelect();
        })
        .setErrorAction(_data =>
        {
            finishAction(false);
        })
        .SendStart();
    }
Exemple #3
0
    //----------------------------------------------------------------------------

    /*!
     *          @brief	ダイアログオープン:ショップ特化:「どれ買いますか?」
     */
    //----------------------------------------------------------------------------
    static public Dialog OpenShopBuySelect(System.Action <DialogTipItem> tipAction = null, System.Action okAction = null)
    {
        // プレハブを追加
        Dialog dialog = Dialog.Create(DialogType.DialogShopSelect);

        dialog.SetDialogTextFromTextkey(DialogTextType.Title, "sh119q_title");

        List <DialogTipItem> tipList = new List <DialogTipItem>();

        StoreProduct[] productList = new StoreProduct[6];
        for (int i = 0; i < 6; i++)
        {
            productList[i] = StoreParam.GetStoreProductChanged(i);
            if (productList[i] == null)
            {
                productList[i] = StoreParam.GetStoreProductBase(i);
            }
        }
        tipList.Add(new DialogTipItem(productList[0], DialogButtonEventType.MULTI01));
        tipList.Add(new DialogTipItem(productList[1], DialogButtonEventType.MULTI02));
        tipList.Add(new DialogTipItem(productList[2], DialogButtonEventType.MULTI03));
        tipList.Add(new DialogTipItem(productList[3], DialogButtonEventType.MULTI04));
        tipList.Add(new DialogTipItem(productList[4], DialogButtonEventType.MULTI05));
        tipList.Add(new DialogTipItem(productList[5], DialogButtonEventType.MULTI06));
        dialog.SetTipEvent(tipList, tipAction, true);

        dialog.SetOkEvent(okAction, true);

        dialog.SetDialogObjectEnabled(DialogObjectType.Title, false);
        dialog.IsActiveTitleBorder = false;

        dialog.setupUnderKiyaku();

        dialog.EnableFadePanel();
        dialog.Show();
        return(dialog);
    }
Exemple #4
0
        /// <summary>
        /// 审核物资库盘点单
        /// </summary>
        /// <param name="deptId">库房ID</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <returns>单据处理结果</returns>
        public MWBillResult AuditBill(int deptId, int auditEmpID, string auditEmpName)
        {
            string serialNO = string.Empty;//审核单据号
            //1.检查库房状态是否处于盘点状态
            int checkStatus = NewDao <SqlMWDao>().GetStoreRoomStatus(deptId);

            if (checkStatus == 0)
            {
                throw new Exception("系统没有进入盘点状态,请启用盘点状态");
            }

            //2.提取所有未审核的单据返回DataTable;
            DataTable dtNotAuditDetail = NewDao <SqlMWDao>().GetAllNotAuditDetail(deptId);
            //3.创建盘点审核单据头
            MW_AuditHead auditHead = NewObject <MW_AuditHead>();
            decimal      profitRetailFee = 0, profitStockFee = 0, lossRetailFee = 0, lossStockFee = 0;
            decimal      checkStockFee = 0, actStockFee = 0, checkRetailFee = 0, actRetailFee = 0;

            checkStockFee             = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactStockFee)", "true"));        //盘存进货金额
            actStockFee               = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActStockFee)", "true"));         //账存进货金额
            checkRetailFee            = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactRetailFee)", "true"));       //盘存零售金额
            actRetailFee              = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActRetailFee)", "true"));        //账存零售金额
            profitRetailFee           = checkRetailFee - actRetailFee > 0 ? checkRetailFee - actRetailFee : 0;           //盘盈零售金额
            profitStockFee            = checkStockFee - actStockFee > 0 ? checkStockFee - actStockFee : 0;               //盘盈进货金额
            lossRetailFee             = checkRetailFee - actRetailFee < 0 ? Math.Abs(checkRetailFee - actRetailFee) : 0; //盘亏零售金额
            lossStockFee              = checkStockFee - actStockFee < 0 ? Math.Abs(checkStockFee - actStockFee) : 0;     //盘亏进货金额
            serialNO                  = NewObject <SerialNumberSource>().GetSerialNumber(SnType.物资, deptId, MWConstant.OP_MW_AUDITCHECK);
            auditHead.BillNO          = Convert.ToInt64(serialNO);
            auditHead.EmpID           = auditEmpID;
            auditHead.EmpName         = auditEmpName;
            auditHead.AuditTime       = System.DateTime.Now;
            auditHead.Remark          = string.Empty;
            auditHead.DelFlag         = 0;
            auditHead.AuditFlag       = 1;
            auditHead.BusiType        = MWConstant.OP_MW_AUDITCHECK;
            auditHead.DeptID          = deptId;
            auditHead.ProfitRetailFee = profitRetailFee;
            auditHead.ProfitStockFee  = profitStockFee;
            auditHead.LossRetailFee   = lossRetailFee;
            auditHead.LossStockFee    = lossStockFee;
            auditHead.CheckStockFee   = checkStockFee;
            auditHead.ActStockFee     = actStockFee;
            auditHead.CheckRetailFee  = checkRetailFee;
            auditHead.ActRetailFee    = actRetailFee;
            BindDb(auditHead);
            auditHead.save();
            //循环DataTable,根据DataTable的每一行的值去构建盘点审核单明细和盘点审核单头;
            //4.保存盘点审核单表头和明细
            //5、按盘点审核单内容更新物资库库存
            MWBillResult result = new MWBillResult();

            foreach (DataRow drNotAuditRow in dtNotAuditDetail.Rows)
            {
                MW_AuditDetail auditdetail = NewObject <MW_AuditDetail>();
                auditdetail.StorageID     = Convert.ToInt32(drNotAuditRow["StorageID"]);
                auditdetail.MaterialID    = Convert.ToInt32(drNotAuditRow["MaterialID"]);
                auditdetail.Place         = drNotAuditRow["Place"].ToString();
                auditdetail.BatchNO       = drNotAuditRow["BatchNO"].ToString();
                auditdetail.ValidityDate  = Convert.ToDateTime(drNotAuditRow["ValidityDate"]);
                auditdetail.DeptID        = deptId;
                auditdetail.BillNO        = Convert.ToInt64(serialNO);
                auditdetail.FactAmount    = Convert.ToDecimal(drNotAuditRow["FactAmount"]);
                auditdetail.FactStockFee  = Convert.ToDecimal(drNotAuditRow["FactStockFee"]);
                auditdetail.FactRetailFee = Convert.ToDecimal(drNotAuditRow["FactRetailFee"]);
                auditdetail.ActAmount     = Convert.ToDecimal(drNotAuditRow["ActAmount"]);
                auditdetail.ActStockFee   = Convert.ToDecimal(drNotAuditRow["ActStockFee"]);
                auditdetail.ActRetailFee  = Convert.ToDecimal(drNotAuditRow["ActRetailFee"]);
                auditdetail.UnitID        = Convert.ToInt32(drNotAuditRow["UnitID"]);
                auditdetail.UnitName      = drNotAuditRow["UnitName"].ToString();
                auditdetail.RetailPrice   = Convert.ToDecimal(drNotAuditRow["RetailPrice"]);
                auditdetail.StockPrice    = Convert.ToDecimal(drNotAuditRow["StockPrice"]);
                auditdetail.AuditHeadID   = auditHead.AuditHeadID;
                BindDb(auditdetail);
                auditdetail.save();
                StoreParam storeParam = new StoreParam();
                storeParam.Amount       = auditdetail.FactAmount - auditdetail.ActAmount;
                storeParam.BatchNO      = auditdetail.BatchNO;
                storeParam.DeptID       = auditdetail.DeptID;
                storeParam.MaterialId   = auditdetail.MaterialID;
                storeParam.RetailPrice  = auditdetail.RetailPrice;
                storeParam.StockPrice   = auditdetail.StockPrice;
                storeParam.UnitID       = auditdetail.UnitID;
                storeParam.UnitName     = auditdetail.UnitName;
                storeParam.ValidityTime = auditdetail.ValidityDate;
                MWStoreResult storeRtn = NewObject <MwStore>().AddStore(storeParam);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <MWNotEnoughInfo>();
                        MWNotEnoughInfo notEnough = new MWNotEnoughInfo();
                        notEnough.DeptID       = auditdetail.DeptID;
                        notEnough.MaterialId   = auditdetail.MaterialID;
                        notEnough.LackAmount   = storeRtn.StoreAmount + auditdetail.FactAmount - auditdetail.ActAmount;
                        notEnough.MaterialInfo = "物资批次号:" + auditdetail.BatchNO.ToString();
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.MaterialInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "物资更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    //6、按盘点审核单内容写入台账
                    WriteAccount(auditHead, auditdetail, storeRtn);
                }
            }

            //7、更新所有未审核的盘点录入单状态
            MW_CheckHead checkHead = NewObject <MW_CheckHead>();

            checkHead.AuditEmpID   = auditEmpID;
            checkHead.AuditEmpName = auditEmpName;
            checkHead.AuditHeadID  = auditHead.AuditHeadID;
            checkHead.AuditNO      = auditHead.BillNO;
            checkHead.DeptID       = deptId;
            int ret = NewDao <IMWDao>().UpdateCheckHeadStatus(checkHead);

            if (ret > 0)
            {
                //8、设置库房盘点状态为运营状态
                NewDao <IMWDao>().SetCheckStatus(deptId, 0);
                result.Result = 0;
            }
            else
            {
                result.Result = 1;
            }

            return(result);
        }
        /// <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();
        }
        /// <summary>
        /// 门诊处方退药
        /// </summary>
        /// <param name="dispHead">退药单表头</param>
        /// <param name="dispDetail">退药单明细</param>
        /// <param name="dtRefund">退药单明细数据</param>
        /// <returns>返回处理结果</returns>
        public DGBillResult OPRefund(List <DS_OPDispHead> dispHead, List <DS_OPDispDetail> dispDetail, DataTable dtRefund)
        {
            //药品单据处理结果
            DGBillResult result = new DGBillResult();

            if (dispHead.Count > 0)
            {
                //1.判断药房是否处于盘点状态中
                if (NewObject <DrugStoreManagement>().IsCheckStatus(dispHead[0].DeptID, 0))
                {
                    throw new Exception("药房当前正在盘点中,不能退药");
                }

                //2.创建发药单表头,保存数据到发药表头中,发药单是多张,所以要做循环
                foreach (DS_OPDispHead dispHeadModel in dispHead)
                {
                    //生成单据号
                    string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, dispHeadModel.DeptID, DGConstant.OP_DS_OPREFUND);
                    dispHeadModel.BillNO   = Convert.ToInt64(serialNO);
                    dispHeadModel.DispTime = System.DateTime.Now;//退药时间
                    BindDb(dispHeadModel);
                    dispHeadModel.save();

                    //3.发药明细列表dispDetail通过字段(FeeItemHeadID)过滤出该表头对应的退药明细
                    List <DS_OPDispDetail> dispDetailList = dispDetail.Where(w => w.FeeItemHeadID == dispHeadModel.RecipeID).ToList();

                    //4.循环该张处方明细记录,更新DispHeadID等相关字段,保存数据到发药明细中,同时判断库存量,批次库存量,调用加库存的方法并返回处理结果
                    //退药如果跨批次的话,台账需要记录差额调整记录
                    foreach (DS_OPDispDetail ispDetailModel in dispDetailList)
                    {
                        decimal dispRetailPrice = ispDetailModel.RetailPrice;

                        //5发药明细设置发药头表ID,保存数据在库存处理方法中
                        ispDetailModel.DispHeadID = dispHeadModel.DispHeadID;

                        //6.加库存处理
                        StoreParam storeParam = new StoreParam();
                        storeParam.Amount      = ispDetailModel.DispAmount;
                        storeParam.BatchNO     = ispDetailModel.BatchNO;
                        storeParam.DeptID      = ispDetailModel.DeptID;
                        storeParam.DrugID      = ispDetailModel.DrugID;
                        storeParam.RetailPrice = ispDetailModel.RetailPrice;
                        storeParam.StockPrice  = ispDetailModel.StockPrice;
                        storeParam.UnitID      = ispDetailModel.UnitID;
                        storeParam.UnitName    = ispDetailModel.UnitName;
                        storeParam.UnitAmount  = ispDetailModel.UnitAmount;
                        DGStoreResult storeRtn = NewObject <DSStore>().AddStoreAuto(storeParam, false);
                        if (storeRtn.Result != 0)
                        {
                            result.Result = 1;
                            if (storeRtn.Result == 1)
                            {
                                result.ErrMsg = "药品更新库存出错";
                            }

                            return(result);
                        }
                        else
                        {
                            foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList)
                            {
                                //保存发药明细数据
                                ispDetailModel.DispDetailID = 0;
                                ispDetailModel.DispAmount   = batchAllot.DispAmount;
                                ispDetailModel.RetailPrice  = batchAllot.RetailPrice;
                                ispDetailModel.StockPrice   = batchAllot.StockPrice;
                                ispDetailModel.RetailFee    = batchAllot.DispRetailFee;
                                ispDetailModel.StockFee     = batchAllot.DispStockFee;
                                ispDetailModel.BatchNO      = batchAllot.BatchNO;

                                BindDb(ispDetailModel);
                                ispDetailModel.save();

                                if (ispDetailModel.RetailPrice != dispRetailPrice)
                                {
                                    //零售价不一致,调整金额差额台账
                                    WriteAccount(dispHeadModel, ispDetailModel, storeParam, batchAllot);//按收费价格算
                                }

                                //写减批次库存台账
                                WriteAccount(dispHeadModel, ispDetailModel, batchAllot, 1, storeParam);
                            }
                        }

                        int feeDetailID = ispDetailModel.FeeDetailID;

                        //更新明细退药标志
                        NewDao <IDSDao>().UpdateFeeRefundStatus(feeDetailID);
                    }
                }
            }

            //退药成功
            result.Result = 0;
            return(result);
        }
        /// <summary>
        /// 门诊处方发药
        /// </summary>
        /// <param name="dispHead">发药单表头</param>
        /// <param name="dispDetail">发药单明细</param>
        /// <param name="execEmpID">执行人ID</param>
        /// <returns>处理结果</returns>
        public DGBillResult OPDisp(List <DS_OPDispHead> dispHead, List <DS_OPDispDetail> dispDetail, int execEmpID)
        {
            //药品单据处理结果
            DGBillResult result = new DGBillResult();

            if (dispHead.Count > 0)
            {
                //1.判断药房是否处于盘点状态中
                if (NewObject <DrugStoreManagement>().IsCheckStatus(dispHead[0].DeptID, 0))
                {
                    throw new Exception("药房当前正在盘点中,不能发药");
                }

                //2.创建发药单表头,保存数据到发药表头中,发药单是多张,所以要做循环
                foreach (DS_OPDispHead dispHeadModel in dispHead)
                {
                    //生成单据号
                    string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, dispHeadModel.DeptID, DGConstant.OP_DS_OPDISPENSE);
                    dispHeadModel.BillNO   = Convert.ToInt64(serialNO);
                    dispHeadModel.DispTime = System.DateTime.Now;
                    BindDb(dispHeadModel);
                    dispHeadModel.save();

                    //3.发药明细列表dispDetail通过字段(FeeItemHeadID)过滤出该表头对应的发药明细
                    List <DS_OPDispDetail> dispDetailList = dispDetail.Where(w => w.FeeItemHeadID == dispHeadModel.RecipeID).ToList();

                    //4.循环该张处方明细记录,更新DispHeadID等相关字段,保存数据到发药明细中,同时判断库存量,批次库存量,调用减库存的方法并返回处理结果
                    //发药如果跨批次的化,台账需要记录差额调整记录
                    foreach (DS_OPDispDetail ispDetailModel in dispDetailList)
                    {
                        decimal dispRetailPrice = ispDetailModel.RetailPrice;

                        //5发药明细设置发药头表ID,保存数据在库存处理方法中
                        ispDetailModel.DispHeadID = dispHeadModel.DispHeadID;

                        //6减库存处理
                        StoreParam storeParam = new StoreParam();
                        storeParam.Amount      = ispDetailModel.DispAmount;
                        storeParam.BatchNO     = ispDetailModel.BatchNO;
                        storeParam.DeptID      = ispDetailModel.DeptID;
                        storeParam.DrugID      = ispDetailModel.DrugID;
                        storeParam.RetailPrice = ispDetailModel.RetailPrice;//收费价格
                        storeParam.StockPrice  = ispDetailModel.StockPrice;
                        storeParam.UnitID      = ispDetailModel.UnitID;
                        storeParam.UnitName    = ispDetailModel.UnitName;
                        DGStoreResult storeRtn = NewObject <DSStore>().ReduceStoreAuto(storeParam, true);
                        if (storeRtn.Result != 0)
                        {
                            result.Result = 1;
                            if (storeRtn.Result == 1)
                            {
                                result.LstNotEnough = new List <DGNotEnough>();
                                DGNotEnough notEnough = new DGNotEnough();
                                notEnough.DeptID     = ispDetailModel.DeptID;
                                notEnough.DrugID     = ispDetailModel.DrugID;
                                notEnough.LackAmount = ispDetailModel.DispAmount - storeRtn.StoreAmount;
                                notEnough.DrugInfo   = "药品批次号:" + ispDetailModel.BatchNO.ToString();
                                result.LstNotEnough.Add(notEnough);
                                result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                            }
                            else
                            {
                                result.ErrMsg = "药品更新库存出错";
                            }

                            return(result);
                        }
                        else
                        {
                            foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList)
                            {
                                //保存发药明细数据
                                ispDetailModel.DispDetailID = 0;
                                if (batchAllot.DispAmount == 0)
                                {
                                    continue;
                                }

                                ispDetailModel.DispAmount  = batchAllot.DispAmount;
                                ispDetailModel.RetailPrice = batchAllot.RetailPrice;
                                ispDetailModel.StockPrice  = batchAllot.StockPrice;
                                ispDetailModel.RetailFee   = batchAllot.DispRetailFee;
                                ispDetailModel.StockFee    = batchAllot.DispStockFee;
                                ispDetailModel.BatchNO     = batchAllot.BatchNO;
                                BindDb(ispDetailModel);
                                ispDetailModel.save();
                                if (ispDetailModel.RetailPrice != dispRetailPrice)
                                {
                                    //零售价不一致,调整金额差额台账
                                    WriteAccount(dispHeadModel, ispDetailModel, storeParam, batchAllot);//按收费价格算
                                }

                                //写减批次库存台账
                                WriteAccount(dispHeadModel, ispDetailModel, batchAllot, 0, storeParam);
                            }
                        }
                    }

                    //8.在循环发药头表末尾处,更新收费主表发药标志DistributeFlag=1
                    OP_FeeItemHead feeItemHead = (OP_FeeItemHead)NewObject <OP_FeeItemHead>().getmodel(dispHeadModel.RecipeID);
                    feeItemHead.DistributeFlag = 1;//发药标识=1
                    feeItemHead.ExecDate       = System.DateTime.Now;
                    feeItemHead.ExecEmpID      = execEmpID;
                    feeItemHead.save();
                }
            }

            //发药成功
            result.Result = 0;
            return(result);
        }
        /// <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();
        }
Exemple #9
0
        /// <summary>
        /// 审核单据
        /// </summary>
        /// <param name="deptId">科室Id</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <returns>处理结果</returns>
        public override DGBillResult AuditBill(int deptId, int auditEmpID, string auditEmpName)
        {
            string serialNO = string.Empty;//审核单据号

            //1.检查库房状态是否处于盘点状态
            int checkStatus = NewDao <SqlDSDao>().GetStoreRoomStatus(deptId);

            if (checkStatus == 0)
            {
                throw new Exception("药房系统没有进入盘点状态,请启用盘点状态");
            }

            //2.提取所有未审核的单据返回DataTable;
            Dictionary <string, string> queryCondition = new Dictionary <string, string>();

            queryCondition.Add("a.DeptID", deptId.ToString());
            DataTable dtNotAuditDetail = LoadAllNotAuditDetail(queryCondition, true);

            //3.创建盘点审核单据头
            DS_AuditHead auditHead = NewObject <DS_AuditHead>();
            decimal      profitRetailFee = 0, profitStockFee = 0, lossRetailFee = 0, lossStockFee = 0;
            decimal      checkStockFee = 0, actStockFee = 0, checkRetailFee = 0, actRetailFee = 0;

            checkStockFee             = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactStockFee)", "true"));        //盘存进货金额
            actStockFee               = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActStockFee)", "true"));         //账存进货金额
            checkRetailFee            = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactRetailFee)", "true"));       //盘存零售金额
            actRetailFee              = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActRetailFee)", "true"));        //账存零售金额
            profitRetailFee           = checkRetailFee - actRetailFee > 0 ? checkRetailFee - actRetailFee : 0;           //盘盈零售金额
            profitStockFee            = checkStockFee - actStockFee > 0 ? checkStockFee - actStockFee : 0;               //盘盈进货金额
            lossRetailFee             = checkRetailFee - actRetailFee < 0 ? Math.Abs(checkRetailFee - actRetailFee) : 0; //盘亏零售金额
            lossStockFee              = checkStockFee - actStockFee < 0 ? Math.Abs(checkStockFee - actStockFee) : 0;     //盘亏进货金额
            serialNO                  = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, deptId, DGConstant.OP_DS_AUDITCHECK);
            auditHead.BillNO          = Convert.ToInt64(serialNO);
            auditHead.EmpID           = auditEmpID;
            auditHead.EmpName         = auditEmpName;
            auditHead.AuditTime       = System.DateTime.Now;
            auditHead.Remark          = string.Empty;
            auditHead.DelFlag         = 0;
            auditHead.AuditFlag       = 1;
            auditHead.BusiType        = DGConstant.OP_DS_AUDITCHECK;
            auditHead.DeptID          = deptId;
            auditHead.ProfitRetailFee = profitRetailFee;
            auditHead.ProfitStockFee  = profitStockFee;
            auditHead.LossRetailFee   = lossRetailFee;
            auditHead.LossStockFee    = lossStockFee;
            auditHead.CheckStockFee   = checkStockFee;
            auditHead.ActStockFee     = actStockFee;
            auditHead.CheckRetailFee  = checkRetailFee;
            auditHead.ActRetailFee    = actRetailFee;
            BindDb(auditHead);
            auditHead.save();

            //循环DataTable,根据DataTable的每一行的值去构建盘点审核单明细和盘点审核单头;
            //4.保存盘点审核单表头和明细
            //5、按盘点审核单内容更新药库库存
            DGBillResult result = new DGBillResult();

            foreach (DataRow drNotAuditRow in dtNotAuditDetail.Rows)
            {
                StoreParam storeParam = new StoreParam();
                storeParam.DeptID      = auditHead.DeptID;
                storeParam.DrugID      = Convert.ToInt32(drNotAuditRow["DrugID"]);
                storeParam.RetailPrice = Convert.ToDecimal(drNotAuditRow["RetailPrice"]);
                storeParam.StockPrice  = Convert.ToDecimal(drNotAuditRow["StockPrice"]);
                storeParam.FactAmount  = Convert.ToDecimal(drNotAuditRow["FactAmount"]);
                storeParam.ActAmount   = Convert.ToDecimal(drNotAuditRow["ActAmount"]);
                DGStoreResult storeRtn = NewObject <DSStore>().AddStoreAuto(storeParam, true);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <DGNotEnough>();
                        DGNotEnough notEnough = new DGNotEnough();
                        notEnough.DeptID   = Convert.ToInt32(drNotAuditRow["DeptID"]);
                        notEnough.DrugID   = Convert.ToInt32(drNotAuditRow["DrugID"]);
                        notEnough.DrugInfo = "药品名称:" + drNotAuditRow["ChemName"].ToString();
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.DrugInfo + "】保存错误";
                    }
                    else
                    {
                        result.ErrMsg = "药品更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList)
                    {
                        DS_AuditDetail auditdetail = NewObject <DS_AuditDetail>();
                        auditdetail.StorageID = Convert.ToInt32(drNotAuditRow["StorageID"]);
                        auditdetail.CTypeID   = Convert.ToInt32(drNotAuditRow["CTypeID"]);
                        auditdetail.DrugID    = Convert.ToInt32(drNotAuditRow["DrugID"]);
                        auditdetail.Place     = drNotAuditRow["Place"].ToString();
                        auditdetail.DeptID    = auditHead.DeptID;
                        auditdetail.BillNO    = auditHead.BillNO;

                        auditdetail.UnitID      = Convert.ToInt32(drNotAuditRow["UnitID"]);
                        auditdetail.UnitName    = drNotAuditRow["UnitName"].ToString();
                        auditdetail.PackUnit    = drNotAuditRow["PackUnit"].ToString();
                        auditdetail.UnitAmount  = Convert.ToInt32(drNotAuditRow["UnitAmount"].ToString());
                        auditdetail.AuditHeadID = auditHead.AuditHeadID;

                        auditdetail.BatchNO       = batchAllot.BatchNO;
                        auditdetail.ValidityDate  = batchAllot.ValidityDate;
                        auditdetail.RetailPrice   = batchAllot.RetailPrice;
                        auditdetail.StockPrice    = batchAllot.StockPrice;
                        auditdetail.FactAmount    = batchAllot.FactAmount;
                        auditdetail.FactStockFee  = batchAllot.FactStockFee;
                        auditdetail.FactRetailFee = batchAllot.FactRetailFee;
                        auditdetail.ActAmount     = batchAllot.ActAmount;
                        auditdetail.ActStockFee   = batchAllot.ActStockFee;
                        auditdetail.ActRetailFee  = batchAllot.ActRetailFee;
                        BindDb(auditdetail);
                        auditdetail.save();

                        //写台账表
                        WriteAccount(auditHead, auditdetail, batchAllot);
                    }
                }
            }

            //7、更新所有未审核的盘点录入单状态
            DS_CheckHead checkHead = NewObject <DS_CheckHead>();

            checkHead.AuditEmpID   = auditEmpID;
            checkHead.AuditEmpName = auditEmpName;
            checkHead.AuditHeadID  = auditHead.AuditHeadID;
            checkHead.AuditNO      = (int)auditHead.BillNO;
            checkHead.DeptID       = deptId;
            int ret = NewDao <IDSDao>().UpdateCheckHeadStatus(checkHead);

            if (ret > 0)
            {
                //8、设置库房盘点状态为运营状态
                NewDao <IDGDao>().SetCheckStatus(deptId, 0, 0);
                result.Result = 0;
            }
            else
            {
                result.Result = 1;
            }

            return(result);
        }
        /// <summary>
        /// 审核单据
        /// </summary>
        /// <param name="headID">头id</param>
        /// <param name="auditEmpID">审核人id</param>
        /// <param name="auditEmpName">审核人名称</param>
        /// <returns>审核结果信息</returns>
        public MWBillResult AuditBill(int headID, int auditEmpID, string auditEmpName)
        {
            MW_OutStoreHead head   = (MW_OutStoreHead)NewObject <MW_OutStoreHead>().getmodel(headID);
            MWBillResult    result = new MWBillResult();

            if (!NewObject <MaterialDeptMgr>().IsDeptChecked(head.DeptID))
            {
                result.Result = 1;
                result.ErrMsg = "当前科室处于盘点状态或者没有设置科室的盘点状态 不能处理业务操作";
                return(result);
            }

            if (head.AuditFlag == 1)
            {
                result.Result = 1;
                result.ErrMsg = "物资已经被审核,请刷新数据";
                return(result);
            }

            if (head != null)
            {
                List <MW_OutStoreDetail> lstDetails = NewObject <MW_OutStoreDetail>().getlist <MW_OutStoreDetail>("OutHeadID=" + headID);
                head.AuditEmpID   = auditEmpID;
                head.AuditEmpName = auditEmpName;
                head.AuditTime    = System.DateTime.Now;
                head.AuditFlag    = 1;
                head.save();

                foreach (MW_OutStoreDetail detail in lstDetails)
                {
                    StoreParam storeParam = new StoreParam();

                    storeParam.BatchNO    = detail.BatchNO;
                    storeParam.DeptID     = head.DeptID;
                    storeParam.MaterialId = detail.MaterialID;

                    storeParam.RetailPrice  = detail.RetailPrice;
                    storeParam.StockPrice   = detail.StockPrice;
                    storeParam.UnitID       = detail.UnitID;
                    storeParam.UnitName     = detail.UnitName;
                    storeParam.ValidityTime = detail.ValidityDate;
                    storeParam.UnitAmount   = 1;

                    storeParam.Amount     = detail.Amount;
                    storeParam.PackAmount = 1;

                    storeParam.BussConstant = head.BusiType;
                    MWStoreResult storeRtn = NewObject <MwStore>().ReduceStore(storeParam);

                    if (storeRtn.Result != 0)
                    {
                        result.Result = 1;
                        if (storeRtn.Result == 1)
                        {
                            result.LstNotEnough = new List <MWNotEnoughInfo>();
                            MWNotEnoughInfo notEnough = new MWNotEnoughInfo();
                            notEnough.DeptID       = head.DeptID;
                            notEnough.MaterialId   = detail.MaterialID;
                            notEnough.LackAmount   = storeRtn.StoreAmount + detail.Amount;
                            notEnough.MaterialInfo = "药品编号" + detail.MaterialID + "批次号:" + detail.BatchNO;
                            result.LstNotEnough.Add(notEnough);
                            result.ErrMsg = "【" + notEnough.MaterialInfo + "】库存不足";
                        }
                        else
                        {
                            result.ErrMsg = "药品更新库存出错";
                        }

                        return(result);
                    }
                    else
                    {
                        WriteAccount(head, detail, storeRtn);
                    }
                }

                result.Result = 0;
                return(result);
            }

            return(result);
        }
        /// <summary>
        /// 审核药库单据
        /// </summary>
        /// <param name="headID">药库入库单表头ID</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <param name="workId">机构ID</param>
        /// <returns>单据处理结果</returns>
        public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName, int workId)
        {
            DW_InStoreHead          head       = (DW_InStoreHead)NewObject <DW_InStoreHead>().getmodel(headID);
            List <DW_InStoreDetail> lstDetails = NewObject <DW_InStoreDetail>().getlist <DW_InStoreDetail>("InHeadID=" + headID);

            head.AuditEmpID   = auditEmpID;
            head.AuditEmpName = auditEmpName;
            head.AuditTime    = System.DateTime.Now;
            head.AuditFlag    = 1;
            head.save();
            DGBillResult result = new DGBillResult();

            if (!NewObject <DrugDeptMgr>().IsDeptChecked(head.DeptID, workId))
            {
                result.Result = 1;
                result.ErrMsg = "当前科室处于盘点状态或者没有设置科室的盘点状态 不能处理业务操作";
                return(result);
            }

            foreach (DW_InStoreDetail detail in lstDetails)
            {
                //获取批次数据
                DW_Batch batch = NewDao <IDWDao>().GetBatchAmount(head.DeptID, detail.DrugID, detail.BatchNo);

                if (batch != null)
                {
                    if (detail.Amount < 0)
                    {
                        if ((batch.RetailPrice.Equals(detail.RetailPrice) == false) ||
                            (batch.StockPrice.Equals(detail.StockPrice) == false))
                        {
                            result.Result = 1;
                            result.ErrMsg = "编码【" + detail.DrugID.ToString() + "的(进货价/零售价)】与【" + batch.BatchNO + "】批次价格不一致(进货价:" + batch.StockPrice.ToString()
                                            + ",零售价:" + batch.RetailPrice.ToString() + "),请核查库存!";

                            return(result);
                        }
                    }
                    else
                    {
                        if ((batch.RetailPrice.Equals(detail.RetailPrice) == false) ||
                            (batch.StockPrice.Equals(detail.StockPrice) == false))
                        {
                            result.Result = 1;
                            result.ErrMsg = "编码【" + detail.DrugID.ToString() + "的(进货价/零售价)】与【" + batch.BatchNO + "】批次价格不一致(进货价:" + batch.StockPrice.ToString()
                                            + ",零售价:" + batch.RetailPrice.ToString() + "),请核查库存!";

                            return(result);
                        }
                    }
                }

                StoreParam storeParam = new StoreParam();
                storeParam.Amount       = detail.Amount;
                storeParam.BatchNO      = detail.BatchNo;
                storeParam.DeptID       = head.DeptID;
                storeParam.DrugID       = detail.DrugID;
                storeParam.RetailPrice  = detail.RetailPrice;
                storeParam.StockPrice   = detail.StockPrice;
                storeParam.UnitID       = detail.UnitID;
                storeParam.UnitName     = detail.UnitName;
                storeParam.ValidityTime = detail.ValidityDate;
                storeParam.BussConstant = head.BusiType;

                //storeParam.PackUnit = detail.PackUnit;
                DGStoreResult storeRtn = iStore.AddStore(storeParam);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <DGNotEnough>();
                        DGNotEnough notEnough = new DGNotEnough();
                        notEnough.DeptID     = head.DeptID;
                        notEnough.DrugID     = detail.DrugID;
                        notEnough.LackAmount = storeRtn.StoreAmount + detail.Amount;
                        notEnough.DrugInfo   = "药品编号" + detail.DrugID + " 药品批次号:" + detail.BatchNo;
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "药品更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    WriteAccount(head, detail, storeRtn);
                }
            }

            result.Result = 0;
            return(result);
        }
        /// <summary>
        /// 审核药库出库单
        /// </summary>
        /// <param name="headID">药库出库单表头ID</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <returns>单据处理结果</returns>
        public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName)
        {
            DW_OutStoreHead outHead = (DW_OutStoreHead)NewObject <DW_OutStoreHead>().getmodel(headID);

            outHead.AuditEmpID   = auditEmpID;
            outHead.AuditEmpName = auditEmpName;
            outHead.AuditTime    = System.DateTime.Now;
            outHead.AuditFlag    = 1;
            outHead.save();
            List <DW_OutStoreDetail> lstDetails = NewObject <DW_OutStoreDetail>().getlist <DW_OutStoreDetail>("OutHeadID=" + headID);
            DGBillResult             result     = new DGBillResult();

            foreach (var outDeatils in lstDetails)
            {
                StoreParam storeParam = new StoreParam();
                storeParam.Amount       = outDeatils.Amount;
                storeParam.BatchNO      = outDeatils.BatchNO;
                storeParam.DeptID       = outDeatils.DeptID;
                storeParam.DrugID       = outDeatils.DrugID;
                storeParam.RetailPrice  = outDeatils.RetailPrice;
                storeParam.StockPrice   = outDeatils.StockPrice;
                storeParam.UnitID       = outDeatils.UnitID;
                storeParam.UnitName     = outDeatils.UnitName;
                storeParam.ValidityTime = outDeatils.ValidityDate;
                DGStoreResult storeRtn = iStore.ReduceStore(storeParam);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <DGNotEnough>();
                        DGNotEnough notEnough = new DGNotEnough();
                        notEnough.DeptID     = outHead.DeptID;
                        notEnough.DrugID     = outDeatils.DrugID;
                        notEnough.LackAmount = outDeatils.Amount - storeRtn.StoreAmount;
                        notEnough.DrugInfo   = "药品批次号:" + outDeatils.BatchNO;
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "药品更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    WriteAccount(outHead, outDeatils, storeRtn);
                }
            }

            if (outHead.BusiType == DGConstant.OP_DW_CIRCULATEOUT || outHead.BusiType == DGConstant.OP_DW_RETURNSTORE)
            {
                //流通出库业务和退库业务
                var                     t         = outHead.BusiType == DGConstant.OP_DW_CIRCULATEOUT ? DGConstant.OP_DS_CIRCULATEIN:DGConstant.OP_DS_RETURNSOTRE;
                DS_InstoreHead          dshead    = NewObject <DGBillConverter>().ConvertInFromDWOutHead(outHead, auditEmpID, auditEmpName, t);
                IDGBill                 iProcess  = NewObject <DGBillFactory>().GetBillProcess(t);
                List <DS_InStoreDetail> dsInStore = NewObject <DGBillConverter>().ConvertInFromDwStoreDetail(headID);
                iProcess.SaveBill(dshead, dsInStore);//药房入库
                Basic_SystemConfig config = NewObject <IDGDao>().GetDeptParameters(dshead.DeptID, "AutoAuditInstore");
                if (config != null)
                {
                    //药房是否需要审核
                    if (config.Value == "1")
                    {
                        result = iProcess.AuditBill(dshead.InHeadID, auditEmpID, auditEmpName);
                    }
                }
            }

            return(result);
        }
Exemple #13
0
        /// <summary>
        /// 住院统领发药
        /// </summary>
        /// <param name="dispHead">发药单表头</param>
        /// <param name="dispDetail">发药单明细</param>
        /// <returns>返回结果对象</returns>
        public DGBillResult IPDisp(DS_IPDispHead dispHead, List <DS_IPDispDetail> dispDetail)
        {
            //药品单据处理结果
            DGBillResult result = new DGBillResult();

            if (dispHead != null)
            {
                //1.判断药房是否处于盘点状态中
                if (NewObject <DrugStoreManagement>().IsCheckStatus(dispHead.ExecDeptID, 0))
                {
                    throw new Exception("药房当前正在盘点中,不能发药");
                }

                //生成单据号
                string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, dispHead.ExecDeptID, DGConstant.OP_DS_IPDISPENSE);
                dispHead.BillNO   = Convert.ToInt64(serialNO);
                dispHead.DispTime = System.DateTime.Now;
                BindDb(dispHead);
                dispHead.save();

                //发药如果跨批次的化,台账需要记录差额调整记录
                foreach (DS_IPDispDetail ispDetailModel in dispDetail)
                {
                    decimal dispRetailPrice = ispDetailModel.RetailPrice;

                    //5发药明细设置发药头表ID,保存数据在库存处理方法中
                    ispDetailModel.DispHeadID = dispHead.DispHeadID;

                    //6减库存处理
                    StoreParam storeParam = new StoreParam();
                    storeParam.Amount      = ispDetailModel.DispAmount;
                    storeParam.BatchNO     = ispDetailModel.BatchNO;
                    storeParam.DeptID      = ispDetailModel.DeptID;
                    storeParam.DrugID      = ispDetailModel.DrugID;
                    storeParam.RetailPrice = ispDetailModel.RetailPrice;
                    storeParam.StockPrice  = ispDetailModel.StockPrice;
                    storeParam.UnitID      = ispDetailModel.UnitID;
                    storeParam.UnitName    = ispDetailModel.UnitName;
                    if (storeParam.Amount > 0)
                    {
                        DGStoreResult storeRtn = NewObject <DSStore>().ReduceStoreAuto(storeParam, true);
                        if (storeRtn.Result != 0)
                        {
                            result.Result = 1;
                            if (storeRtn.Result == 1)
                            {
                                result.LstNotEnough = new List <DGNotEnough>();
                                DGNotEnough notEnough = new DGNotEnough();
                                notEnough.DeptID     = ispDetailModel.DeptID;
                                notEnough.DrugID     = ispDetailModel.DrugID;
                                notEnough.LackAmount = ispDetailModel.DispAmount - storeRtn.StoreAmount;
                                notEnough.DrugInfo   = "药品批次号:" + ispDetailModel.BatchNO.ToString();
                                result.LstNotEnough.Add(notEnough);
                                result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                            }
                            else
                            {
                                result.ErrMsg = "药品更新库存出错";
                            }

                            return(result);
                        }
                        else
                        {
                            //NewObject<DSStore>().UpdateValidStore(ispDetailModel.DrugID, ispDetailModel.DeptID,  - Math.Abs(ispDetailModel.DispAmount));
                            foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList)
                            {
                                //保存发药明细数据
                                ispDetailModel.DispDetailID = 0;
                                ispDetailModel.DispAmount   = batchAllot.DispAmount;
                                if (batchAllot.DispAmount == 0)
                                {
                                    continue;
                                }

                                ispDetailModel.RetailPrice = batchAllot.RetailPrice;
                                ispDetailModel.StockPrice  = batchAllot.StockPrice;
                                ispDetailModel.RetailFee   = batchAllot.DispRetailFee;
                                ispDetailModel.StockFee    = batchAllot.DispStockFee;
                                ispDetailModel.BatchNO     = batchAllot.BatchNO;
                                ispDetailModel.RetFlag     = 0;
                                BindDb(ispDetailModel);
                                ispDetailModel.save();
                                if (ispDetailModel.RetailPrice != dispRetailPrice)
                                {
                                    //零售价不一致,调整金额差额台账
                                    WriteAccount(dispHead, ispDetailModel, storeParam, batchAllot);
                                }

                                //写减批次库存台账
                                WriteAccount(dispHead, ispDetailModel, batchAllot, 0, storeParam);
                            }
                        }
                    }
                    else
                    {
                        //退药
                        DGStoreResult storeRtn = NewObject <DSStore>().AddStoreAuto(storeParam, false);
                        if (storeRtn.Result != 0)
                        {
                            result.Result = 1;
                            if (storeRtn.Result == 1)
                            {
                                result.ErrMsg = "药品更新库存出错";
                            }

                            return(result);
                        }

                        //更新有效库存
                        NewObject <DSStore>().UpdateValidStore(ispDetailModel.DrugID, ispDetailModel.DeptID, Math.Abs(ispDetailModel.DispAmount));
                        foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList)
                        {
                            //保存发药明细数据
                            ispDetailModel.DispDetailID = 0;
                            ispDetailModel.DispAmount   = -Math.Abs(batchAllot.DispAmount);
                            ispDetailModel.RetailPrice  = batchAllot.RetailPrice;
                            ispDetailModel.StockPrice   = batchAllot.StockPrice;
                            ispDetailModel.RetailFee    = batchAllot.DispRetailFee;
                            ispDetailModel.StockFee     = batchAllot.DispStockFee;
                            ispDetailModel.BatchNO      = batchAllot.BatchNO;
                            ispDetailModel.RetFlag      = 1;
                            BindDb(ispDetailModel);
                            ispDetailModel.save();
                            ispDetailModel.DispAmount = Math.Abs(ispDetailModel.DispAmount);
                            if (ispDetailModel.RetailPrice != dispRetailPrice)
                            {
                                //零售价不一致,调整金额差额台账
                                WriteAccountRefund(dispHead, ispDetailModel, storeParam, batchAllot);
                            }

                            //写减批次库存台账
                            WriteAccount(dispHead, ispDetailModel, batchAllot, 1, storeParam);
                        }
                    }

                    //回写住院统领单状态
                    IP_DrugBillDetail ipDrugBillDetail = (IP_DrugBillDetail)NewObject <IP_DrugBillDetail>().getmodel(ispDetailModel.MsgDetaillID);
                    ipDrugBillDetail.DispDrugFlag = 1;
                    ipDrugBillDetail.DispHeadID   = dispHead.DispHeadID;
                    ipDrugBillDetail.save();

                    //回写住院费用明细单
                    IP_FeeItemRecord feeItemRecord = (IP_FeeItemRecord)NewObject <IP_FeeItemRecord>().getmodel(ipDrugBillDetail.FeeRecordID);
                    feeItemRecord.DrugFlag = 1;
                    feeItemRecord.save();
                }
            }

            //发药成功
            result.Result     = 0;
            result.DispHeadID = dispHead.DispHeadID;
            return(result);
        }
        /// <summary>
        /// 审核药房出库单
        /// </summary>
        /// <param name="headID">药房出库单表头ID</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <param name="workId">机构ID</param>
        /// <returns>单据处理结果</returns>
        public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName, int workId)
        {
            DS_OutStoreHead outHead = (DS_OutStoreHead)NewObject <DS_OutStoreHead>().getmodel(headID);

            outHead.AuditEmpID   = auditEmpID;
            outHead.AuditEmpName = auditEmpName;
            outHead.AuditTime    = System.DateTime.Now;
            outHead.AuditFlag    = 1;
            outHead.save();
            List <DS_OutStoreDetail> lstDetails = NewObject <DS_OutStoreDetail>().getlist <DS_OutStoreDetail>("OutHeadID=" + headID);
            DGBillResult             result     = new DGBillResult();

            if (!NewObject <DrugDeptMgr>().IsDeptChecked(outHead.DeptID, workId))
            {
                result.Result = 1;
                result.ErrMsg = "当前科室处于盘点状态或者没有设置科室的盘点状态 不能处理业务操作";
                return(result);
            }

            foreach (var outDeatils in lstDetails)
            {
                StoreParam storeParam = new StoreParam();
                storeParam.Amount = outDeatils.Amount;
                decimal packAmount = GetPackAmount(outDeatils.DrugID);
                storeParam.PackAmount = Convert.ToInt32(packAmount);

                storeParam.Amount       = outDeatils.Amount;//包装数*系数+基本单位数
                storeParam.BatchNO      = outDeatils.BatchNO;
                storeParam.DeptID       = outDeatils.DeptID;
                storeParam.DrugID       = outDeatils.DrugID;
                storeParam.RetailPrice  = outDeatils.RetailPrice;
                storeParam.StockPrice   = outDeatils.StockPrice;
                storeParam.UnitID       = outDeatils.UnitID;
                storeParam.UnitName     = outDeatils.UnitName;
                storeParam.ValidityTime = outDeatils.ValidityDate;
                DGStoreResult storeRtn = iStore.ReduceStore(storeParam);

                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <DGNotEnough>();
                        DGNotEnough notEnough = new DGNotEnough();
                        notEnough.DeptID     = outHead.DeptID;
                        notEnough.DrugID     = outDeatils.DrugID;
                        notEnough.LackAmount = outDeatils.Amount - storeRtn.StoreAmount;
                        notEnough.DrugInfo   = "药品编号" + outDeatils.DrugID + " 药品批次号:" + outDeatils.BatchNO;
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "药品更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    DGStoreResult vStoreRtn = NewObject <DSStore>().ReduceValidStore(storeParam);
                    if (vStoreRtn.Result != 0)
                    {
                        result.Result = 1;
                        if (vStoreRtn.Result == 1)
                        {
                            result.LstNotEnough = new List <DGNotEnough>();
                            DGNotEnough notEnough = new DGNotEnough();
                            notEnough.DeptID     = outHead.DeptID;
                            notEnough.DrugID     = outDeatils.DrugID;
                            notEnough.LackAmount = outDeatils.Amount - storeRtn.StoreAmount;
                            notEnough.DrugInfo   = "药品编号" + outDeatils.DrugID + " 药品批次号:" + outDeatils.BatchNO;
                            result.LstNotEnough.Add(notEnough);
                            result.ErrMsg = "【" + notEnough.DrugInfo + "】没有有效库存";
                        }
                        else
                        {
                            result.ErrMsg = "药品更新有效库存出错";
                        }

                        return(result);
                    }

                    WriteAccount(outHead, outDeatils, storeRtn, packAmount);
                }
            }

            return(result);
        }