/// <summary>
        /// 挂号提交
        /// </summary>
        /// <param name="curPatlist">病人对象</param>
        /// <param name="paymentInfoList">支付对象</param>
        /// <param name="totalFee">总金额</param>
        /// <param name="cashFee">现金金额</param>
        /// <param name="posFee">POS金额</param>
        /// <param name="dtPrint">返回的打印数据</param>
        /// <param name="promFee">优惠金额</param>
        /// <returns>true成功false失败</returns>
        public bool SaveRegInfo(OP_PatList curPatlist, PayMentInfoList paymentInfoList, decimal totalFee, decimal cashFee, decimal posFee, out DataTable dtPrint, decimal promFee)
        {
            try
            {
                dtPrint = new DataTable();
                bool result = false;

                //插入挂号就诊表记录
                #region 插入挂号就诊表记录
                SerialNumberSource serialNumberSource = NewObject <SerialNumberSource>();
                curPatlist.VisitNO     = serialNumberSource.GetSerialNumber(SnType.门诊流水号);
                curPatlist.CureDeptID  = curPatlist.RegDeptID;
                curPatlist.CureEmpID   = curPatlist.RegEmpID;
                curPatlist.RegDate     = DateTime.Now;
                curPatlist.VisitStatus = 0;
                curPatlist.RegStatus   = 0;
                curPatlist.RegCategory = 0;
                DataTable dtOld = NewObject <OP_PatList>().gettable(" MemberID=" + curPatlist.MemberID);
                if (dtOld != null && dtOld.Rows.Count > 0)
                {
                    curPatlist.IsNew = 0;
                }
                else
                {
                    curPatlist.IsNew = 1;
                }

                this.BindDb(curPatlist);
                curPatlist.save();
                #endregion
                int iAccountType = 0;

                //得到当前结账ID
                int curAccountId = NewObject <CommonMethod>().GetAccountId(curPatlist.OperatorID, iAccountType);

                //插入结算主表对象
                #region 插入结算主表对象
                OP_CostHead costHead = new OP_CostHead();
                SetRegCostHead(costHead, curPatlist);
                costHead.CashFee   = cashFee;
                costHead.PosFee    = posFee;
                costHead.TotalFee  = totalFee;
                costHead.PromFee   = promFee;
                costHead.AccountID = curAccountId;
                this.BindDb(costHead);
                costHead.save();
                #endregion

                #region 插入费用表

                //插入费用主表 OP_FeeItemHead
                OP_FeeItemHead feeItemHead = new OP_FeeItemHead();
                SetRegFeeHeadValue(feeItemHead, costHead, curPatlist);
                this.BindDb(feeItemHead);
                feeItemHead.save();

                //插入费用明细表 OP_FeeItemDetail
                List <OP_FeeItemDetail> feeDetials = SetRegFeeDetailValue(feeItemHead.FeeItemHeadID, curPatlist);
                foreach (OP_FeeItemDetail feeDetial in feeDetials)
                {
                    this.BindDb(feeDetial);
                    feeDetial.save();
                }
                #endregion

                //插入结算明细表
                #region 插入结算明细表
                DataTable dtRegFeeDetail = NewDao <IOPManageDao>().GetRegItemFeeByStat(curPatlist.RegTypeID);
                for (int rowindex = 0; rowindex < dtRegFeeDetail.Rows.Count; rowindex++)
                {
                    OP_CostDetail costDetail = new OP_CostDetail();
                    costDetail.CostHeadID    = costHead.CostHeadID;
                    costDetail.FeeItemHeadID = feeItemHead.FeeItemHeadID;
                    costDetail.ExeDeptID     = curPatlist.RegDeptID;
                    costDetail.PresEmpID     = curPatlist.RegEmpID;
                    costDetail.PresDeptID    = curPatlist.RegDeptID;
                    costDetail.TotalFee      = Convert.ToDecimal(dtRegFeeDetail.Rows[rowindex]["statFee"]);
                    costDetail.StatID        = Convert.ToInt32(dtRegFeeDetail.Rows[rowindex]["statId"]);
                    this.BindDb(costDetail);
                    costDetail.save();
                }
                #endregion

                //插入结算支付方式明细表
                #region 插入结算支付方式明细表
                foreach (OP_CostPayMentInfo costpaymentinfo in paymentInfoList.paymentInfolist)
                {
                    if (costpaymentinfo.PayMentMoney > 0)
                    {
                        costpaymentinfo.AccountID  = curAccountId;
                        costpaymentinfo.CostHeadID = costHead.CostHeadID;
                        costpaymentinfo.PatListID  = curPatlist.PatListID;
                        costpaymentinfo.PatName    = curPatlist.PatName;
                        costpaymentinfo.PatType    = costHead.PatTypeID.ToString();
                        this.BindDb(costpaymentinfo);
                        costpaymentinfo.save();
                    }
                }
                #endregion

                //挂号记录表回写costheadid
                curPatlist.CostHeadID = costHead.CostHeadID;
                curPatlist.ChargeFlag = 1;
                this.BindDb(curPatlist);
                curPatlist.save();

                //结账表插入汇总金额
                NewObject <CommonMethod>().AddAccoutFee(costHead, curAccountId, 1, 0);

                //查数据库得到打印dtPrint
                dtPrint = NewObject <IOPManageDao>().GetRegPrint(curPatlist.PatListID);
                result  = true;
                return(result);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }
示例#2
0
        /// <summary>
        /// 收费预算
        /// </summary>
        /// <param name="prescriptions">处方对象</param>
        /// <returns>返回预算对象</returns>
        public override List <ChargeInfo> Budget(List <Prescription> prescriptions)
        {
            List <ChargeInfo> listChargeInfos = new List <ChargeInfo>();
            decimal           toTalFee        = prescriptions.Sum(p => p.TotalFee);
            OP_CostHead       costHead        = new OP_CostHead(); //插入结算头表

            costHead.MemberID        = GetPatient.MemberID;
            costHead.CardNO          = GetPatient.CardNO;
            costHead.PatListID       = GetPatient.PatListID;
            costHead.MemberAccountID = GetPatient.MemberAccountID;
            costHead.PatName         = GetPatient.PatName;
            costHead.PatTypeID       = CostTypeid;//结算时选择的病人类型ID
            costHead.BeInvoiceNO     = string.Empty;
            costHead.EndInvoiceNO    = string.Empty;
            costHead.ChargeEmpID     = GetOperatorId;
            costHead.TotalFee        = toTalFee;
            costHead.CashFee         = 0;
            costHead.PosFee          = 0;
            costHead.PromFee         = 0;
            costHead.RecipeFlag      = 0;
            costHead.CostStatus      = 9;//修改预算状态为9
            costHead.OldID           = 0;
            costHead.AccountID       = 0;
            costHead.RegFlag         = 0;
            this.BindDb(costHead);
            costHead.save();
            List <int> feeHeadIDs = new List <int>();

            for (int groupIndex = 0; groupIndex < BudgeGroupID.Count; groupIndex++)
            {
                int groupid = BudgeGroupID[groupIndex];
                List <Prescription> presDetails = prescriptions.Where(p => p.PrescGroupID == groupid).ToList();
                var result = from p in presDetails.AsEnumerable()
                             group p by p.StatID into g
                             select new
                {
                    g.Key,
                    SumValue = g.Sum(p => p.TotalFee)
                };
                foreach (var stat in result)
                {
                    OP_CostDetail costDetail = new OP_CostDetail();
                    costDetail.StatID        = stat.Key;
                    costDetail.TotalFee      = Convert.ToDecimal(stat.SumValue);
                    costDetail.CostHeadID    = costHead.CostHeadID;
                    costDetail.FeeItemHeadID = presDetails[0].FeeItemHeadID;
                    costDetail.PresEmpID     = presDetails[0].PresEmpID;
                    costDetail.PresDeptID    = presDetails[0].PresDeptID;
                    costDetail.ExeDeptID     = presDetails[0].ExecDeptID;
                    this.BindDb(costDetail);
                    costDetail.save();
                }

                feeHeadIDs.Add(presDetails[0].FeeItemHeadID);//记录费用头ID
                OP_FeeItemHead feeItemHead = NewObject <OP_FeeItemHead>().getmodel(presDetails[0].FeeItemHeadID) as OP_FeeItemHead;
                if (feeItemHead.ChargeFlag == 1)
                {
                    throw new Exception("处方已被别的收费员收费,请确认!");
                }

                //如果是医生站处方,要判断医生站处方状态,防止医生站已经修改
                feeItemHead.CostHeadID   = costHead.CostHeadID;
                feeItemHead.ChargeStatus = 0;//处方状态不修改
                this.BindDb(feeItemHead);
                feeItemHead.save();
            }

            ChargeInfo chargeInfo = new ChargeInfo();

            chargeInfo.TotalFee       = toTalFee;             //结算总金额
            chargeInfo.CostHeadID     = costHead.CostHeadID;  //结算ID
            chargeInfo.FeeItemHeadIDs = feeHeadIDs.ToArray(); //一次结算对应的费用头表ID
            listChargeInfos.Add(chargeInfo);
            return(listChargeInfos);
        }
        /// <summary>
        /// 退号提交
        /// </summary>
        /// <param name="invoiceNO">票据号</param>
        /// <param name="operatorID">操作员ID</param>
        public void BackReg(string invoiceNO, int operatorID)
        {
            int iAccountType            = 0;
            List <OP_CostHead> costList = NewObject <OP_CostHead>().getlist <OP_CostHead>(" endInvoiceNO='" + invoiceNO + "' and regFlag=1");

            if (costList == null || costList.Count == 0)
            {
                throw new Exception("找不到该票据号信息");
            }
            else if (costList[0].CostStatus != 0)
            {
                throw new Exception("该票据号已经退费,不能再退");
            }
            else if (costList[0].CostStatus == 0 && costList[0].CostDate.ToString("yyyy-MM-dd") != DateTime.Now.ToString("yyyy-MM-dd"))
            {
                throw new Exception("已超过退号日期,只能退当天挂的号");
            }

            //原op_patlist变化
            OP_PatList patlist = NewObject <OP_PatList>().getmodel(costList[0].PatListID) as OP_PatList;

            if (patlist.VisitStatus != 0)
            {
                throw new Exception("您已就诊,不能再退号");
            }

            patlist.RegStatus = 1;//原挂号记录状态置1
            this.BindDb(patlist);
            patlist.save();

            //得到当前结账ID
            int curAccountId = NewObject <CommonMethod>().GetAccountId(operatorID, iAccountType);

            //原op_costHead变化
            OP_CostHead oldCostHead = costList[0].Clone() as OP_CostHead;

            oldCostHead.CostStatus = 1;//原有记录状态改为1
            this.BindDb(oldCostHead);
            oldCostHead.save();

            //生成新op_costHead变化
            OP_CostHead newCostHead = costList[0].Clone() as OP_CostHead;

            newCostHead.CostHeadID  = 0;
            newCostHead.CostDate    = DateTime.Now;
            newCostHead.CostStatus  = 2;//新增记录状态为2
            newCostHead.ChargeEmpID = operatorID;
            newCostHead.AccountID   = curAccountId;
            newCostHead.CashFee     = (oldCostHead.CashFee + oldCostHead.PosFee) * (-1);//退金额,POS金额退现金
            newCostHead.PosFee      = 0;
            newCostHead.PromFee     = oldCostHead.PromFee * (-1);
            newCostHead.OldID       = oldCostHead.CostHeadID;//写入原退记录ID
            newCostHead.TotalFee    = newCostHead.TotalFee * (-1);
            this.BindDb(newCostHead);
            newCostHead.save();

            //得到原来OP_FeeItemHead
            List <OP_FeeItemHead> listFeeitemHead = NewObject <OP_FeeItemHead>().getlist <OP_FeeItemHead>(" costheadid=" + oldCostHead.CostHeadID);
            OP_FeeItemHead        newFeeItemHead  = new OP_FeeItemHead();

            if (listFeeitemHead != null && listFeeitemHead.Count > 0)
            {
                OP_FeeItemHead oldFeeItemHead = listFeeitemHead[0].Clone() as OP_FeeItemHead;
                oldFeeItemHead.ChargeStatus = 1;//原有记录状态改为1
                this.BindDb(oldFeeItemHead);
                oldFeeItemHead.save();

                //生成新OP_FeeItemHead变化
                newFeeItemHead = listFeeitemHead[0].Clone() as OP_FeeItemHead;
                newFeeItemHead.FeeItemHeadID = 0;
                newFeeItemHead.ChargeStatus  = 2;
                newFeeItemHead.CostHeadID    = newCostHead.CostHeadID;
                newFeeItemHead.TotalFee      = newFeeItemHead.TotalFee * (-1);
                newFeeItemHead.OldID         = oldFeeItemHead.FeeItemHeadID;//写入原退记录ID
                this.BindDb(newFeeItemHead);
                newFeeItemHead.save();

                List <OP_FeeItemDetail> listFeeItemDetail = NewObject <OP_FeeItemDetail>().getlist <OP_FeeItemDetail>(" FeeItemHeadID=" + oldFeeItemHead.FeeItemHeadID);
                foreach (OP_FeeItemDetail oldfeeitemDetail in listFeeItemDetail)
                {
                    OP_FeeItemDetail newfeeitemDetail = oldfeeitemDetail.Clone() as OP_FeeItemDetail;
                    newfeeitemDetail.PresDetailID  = 0;
                    newfeeitemDetail.FeeItemHeadID = newFeeItemHead.FeeItemHeadID;
                    newfeeitemDetail.TotalFee      = newfeeitemDetail.TotalFee * (-1);
                    newfeeitemDetail.Amount        = oldfeeitemDetail.Amount * (-1);
                    this.BindDb(newfeeitemDetail);
                    newfeeitemDetail.save();
                }
            }

            //生成新op_costDetail
            List <OP_CostDetail> costDetailList = NewObject <OP_CostDetail>().getlist <OP_CostDetail>(" costheadid=" + oldCostHead.CostHeadID);

            foreach (OP_CostDetail oldcostDetail in costDetailList)
            {
                OP_CostDetail newCostDetail = oldcostDetail.Clone() as OP_CostDetail;
                newCostDetail.CostHeadID    = newCostHead.CostHeadID;
                newCostDetail.FeeItemHeadID = newFeeItemHead.FeeItemHeadID;
                newCostDetail.TotalFee      = oldcostDetail.TotalFee * (-1);
                newCostDetail.CostDetailID  = 0;
                this.BindDb(newCostDetail);
                newCostDetail.save();
            }

            //生成新OP_CostPayMentInfo
            List <OP_CostPayMentInfo> costPayMentInfoList = NewObject <OP_CostPayMentInfo>().getlist <OP_CostPayMentInfo>(" costheadid=" + oldCostHead.CostHeadID);
            decimal oldposfee = 0;

            foreach (OP_CostPayMentInfo oldCostpayInfo in costPayMentInfoList)
            {
                if (oldCostpayInfo.PayMentCode == "02")
                {
                    oldposfee = oldCostpayInfo.PayMentMoney;
                }
            }

            foreach (OP_CostPayMentInfo oldCostpayInfo in costPayMentInfoList)
            {
                OP_CostPayMentInfo newCostPayInfo = oldCostpayInfo.Clone() as OP_CostPayMentInfo;
                newCostPayInfo.AccountID  = curAccountId;
                newCostPayInfo.ID         = 0;
                newCostPayInfo.CostHeadID = newCostHead.CostHeadID;

                //POS
                if (oldCostpayInfo.PayMentCode == "02")
                {
                    newCostPayInfo.PayMentMoney = 0;
                }

                //现金
                if (oldCostpayInfo.PayMentCode == "01")
                {
                    newCostPayInfo.PayMentMoney = (oldCostpayInfo.PayMentMoney + oldposfee) * (-1);
                }
                else
                {
                    newCostPayInfo.PayMentMoney = oldCostpayInfo.PayMentMoney * (-1);
                }

                this.BindDb(newCostPayInfo);
                newCostPayInfo.save();
            }

            //结账表插入汇总金额
            NewObject <CommonMethod>().AddAccoutFee(newCostHead, curAccountId, 0, 1);
        }
        /// <summary>
        /// 全退处方
        /// </summary>
        /// <param name="costHeadid">结算ID</param>
        /// <param name="operatoreid">操作员ID</param>
        /// <param name="refundPrescriptions">退费处方</param>
        /// <param name="refundInvoiceNO">退费票据号</param>
        public void AllRefund(int costHeadid, int operatoreid, List <Prescription> refundPrescriptions, string refundInvoiceNO)
        {
            /*
             * 1:获取当前退费操作员结账ID
             * 2:修改原结算记录OP_CostHead CostStatus=1
             * 3:新增红冲结算记录 CostStatus = 2,写入对冲OldID,金额为负
             * 4:新增红冲结算明细记录 OP_CostDetail
             * 5:新增红冲结算支付方式记录 OP_CostPayMentInfo
             * 6:修改原费用主表 OP_FeeItemHead ChargeStatus=1
             * 7:新增红冲费用主表记录ChargeStatus=2,写入对冲OldID,金额为负
             * 8:新增红冲费用明细表记录 OP_FeeItemDetail
             * 9:修改退费消息表OP_FeeRefundHead RefundPayFlag = 1
             * 10:减会员积分
             * 11:加虚拟库存
             * 12:修改op_account汇总金额
             */
            int      iAccountType = 0;
            DateTime chargedate   = DateTime.Now;

            //获取当前操作员得到当前结账ID
            int         curAccountId = NewObject <CommonMethod>().GetAccountId(operatoreid, iAccountType);
            OP_CostHead oldCostHead  = NewObject <OP_CostHead>().getmodel(costHeadid) as OP_CostHead;

            if (oldCostHead.CostStatus != 0)
            {
                throw new Exception("该处方已经被退费");
            }

            List <OP_FeeRefundHead> feerefundheadlist = NewObject <OP_FeeRefundHead>().getlist <OP_FeeRefundHead>("invoicenum='" + refundInvoiceNO + "' and flag=0");

            if (feerefundheadlist == null || feerefundheadlist.Count == 0)
            {
                throw new Exception("退费消息已经删除");
            }

            //再次判断退费消息,是不是存在已经删除又修改状态
            List <OP_FeeRefundDetail> feerefundDetailList = NewObject <OP_FeeRefundDetail>().getlist <OP_FeeRefundDetail>(" reheadid=" + feerefundheadlist[0].ReHeadID);

            //返回需要补收的处方记录
            foreach (Prescription refundPresc in refundPrescriptions)
            {
                foreach (OP_FeeRefundDetail refundDetail in feerefundDetailList)
                {
                    if (refundPresc.FeeItemHeadID == refundDetail.FeeItemHeadID && refundPresc.PresDetailID == refundDetail.FeeItemDetailID)
                    {
                        if (refundPresc.Refundamount != refundDetail.RefundAmount)
                        {
                            throw new Exception("退费消息已经修改,请重新获取退费消息");
                        }
                    }
                }
            }

            int refundPosType = Convert.ToInt32(NewObject <CommonMethod>().GetOpConfig(OpConfigConstant.RefundPosType));

            //原结算记录状态修改
            oldCostHead.CostStatus = 1; //状态变为退费状态
            this.BindDb(oldCostHead);
            oldCostHead.save();

            //新结算主表
            OP_CostHead newCostHead = oldCostHead.Clone() as OP_CostHead;

            newCostHead.CostHeadID = 0;
            newCostHead.CostStatus = 2;            //状态为空冲
            newCostHead.AccountID  = curAccountId; //定入新的结算ID
            if (refundPosType == 0)                //pos退现金
            {
                newCostHead.CashFee = (oldCostHead.CashFee + oldCostHead.PosFee) * -1;
                newCostHead.PosFee  = 0;
            }
            else
            {
                newCostHead.CashFee = oldCostHead.CashFee * -1;
                newCostHead.PosFee  = oldCostHead.PosFee * -1;
            }

            newCostHead.TotalFee    = newCostHead.TotalFee * -1;
            newCostHead.PromFee     = newCostHead.PromFee * -1;
            newCostHead.OldID       = oldCostHead.CostHeadID;//写入原costHeadID
            newCostHead.ChargeEmpID = operatoreid;
            newCostHead.CostDate    = chargedate;
            newCostHead.RoundingFee = oldCostHead.RoundingFee * -1;
            this.BindDb(newCostHead);
            newCostHead.save();

            //新结算支付方式表
            List <OP_CostPayMentInfo> oldCostPayList = NewObject <OP_CostPayMentInfo>().getlist <OP_CostPayMentInfo>(" costheadid=" + oldCostHead.CostHeadID);

            if (refundPosType == 0)
            {
                oldCostPayList = oldCostPayList.Where(p => p.PayMentCode != "02").ToList();
                foreach (OP_CostPayMentInfo oldCostPay in oldCostPayList)
                {
                    OP_CostPayMentInfo newCostPay = oldCostPay.Clone() as OP_CostPayMentInfo;
                    newCostPay.ID         = 0;
                    newCostPay.CostHeadID = newCostHead.CostHeadID;
                    newCostPay.AccountID  = curAccountId;

                    //现金
                    if (oldCostPay.PayMentCode != "01")
                    {
                        //退现金另外处理
                        newCostPay.PayMentMoney = oldCostPay.PayMentMoney * -1;
                        this.BindDb(newCostPay);
                        newCostPay.save();
                    }
                }

                if (newCostHead.CashFee != 0)
                {
                    OP_CostPayMentInfo cashCostPay = new OP_CostPayMentInfo();
                    cashCostPay.CostHeadID   = newCostHead.CostHeadID;
                    cashCostPay.AccountID    = curAccountId;
                    cashCostPay.PatListID    = newCostHead.PatListID;
                    cashCostPay.PatName      = newCostHead.PatName;
                    cashCostPay.PatType      = newCostHead.PatTypeID.ToString();
                    cashCostPay.PayMentCode  = "01";
                    cashCostPay.PayMentID    = 1002;
                    cashCostPay.PayMentMoney = newCostHead.CashFee;
                    cashCostPay.PayMentName  = "现金支付";
                    this.BindDb(cashCostPay);
                    cashCostPay.save();
                }
            }
            else if (refundPosType == 1)
            {
                foreach (OP_CostPayMentInfo oldCostPay in oldCostPayList)
                {
                    OP_CostPayMentInfo newCostPay = oldCostPay.Clone() as OP_CostPayMentInfo;
                    newCostPay.ID           = 0;
                    newCostPay.CostHeadID   = newCostHead.CostHeadID;
                    newCostPay.AccountID    = curAccountId;
                    newCostPay.PayMentMoney = oldCostPay.PayMentMoney * -1;
                    this.BindDb(newCostPay);
                    newCostPay.save();
                }
            }

            //费用表插入红冲记录
            List <OP_FeeItemHead> oldFeeItemHeadList = NewObject <OP_FeeItemHead>().getlist <OP_FeeItemHead>(" costheadid=" + oldCostHead.CostHeadID);

            foreach (OP_FeeItemHead oldFeeHead in oldFeeItemHeadList)
            {
                oldFeeHead.ChargeStatus = 1;//退费状态
                this.BindDb(oldFeeHead);
                oldFeeHead.save();

                OP_FeeItemHead newFeeHead = oldFeeHead.Clone() as OP_FeeItemHead;
                newFeeHead.FeeItemHeadID = 0;
                newFeeHead.CostHeadID    = newCostHead.CostHeadID;
                newFeeHead.OldID         = oldFeeHead.FeeItemHeadID; //红冲退记录ID
                newFeeHead.ChargeStatus  = 2;                        //新插入记录为红冲记录
                newFeeHead.ChargeEmpID   = operatoreid;
                newFeeHead.ChargeDate    = chargedate;
                newFeeHead.TotalFee      = oldFeeHead.TotalFee * -1;
                this.BindDb(newFeeHead);
                newFeeHead.save();

                List <OP_FeeItemDetail> oldFeeItemDetailList = NewObject <OP_FeeItemDetail>().getlist <OP_FeeItemDetail>(" feeitemheadid=" + oldFeeHead.FeeItemHeadID);
                foreach (OP_FeeItemDetail oldFeeItemDetail in oldFeeItemDetailList)
                {
                    OP_FeeItemDetail newFeeItemDetail = oldFeeItemDetail.Clone() as OP_FeeItemDetail;
                    newFeeItemDetail.PresDetailID  = 0;
                    newFeeItemDetail.TotalFee      = oldFeeItemDetail.TotalFee * -1;
                    newFeeItemDetail.Amount        = oldFeeItemDetail.Amount * -1;
                    newFeeItemDetail.FeeItemHeadID = newFeeHead.FeeItemHeadID;
                    this.BindDb(newFeeItemDetail);
                    newFeeItemDetail.save();
                }
            }

            //新结算明细表
            List <OP_CostDetail> oldCostDetailList = NewObject <OP_CostDetail>().getlist <OP_CostDetail>("costheadid=" + oldCostHead.CostHeadID);

            foreach (OP_CostDetail oldCostDetail in oldCostDetailList)
            {
                OP_CostDetail newCostDetail = oldCostDetail.Clone() as OP_CostDetail;
                newCostDetail.CostDetailID  = 0;
                newCostDetail.CostHeadID    = newCostHead.CostHeadID;//写入新CostHeadID
                newCostDetail.TotalFee      = oldCostDetail.TotalFee * -1;
                newCostDetail.FeeItemHeadID = NewDao <IOPManageDao>().GetNewFeeItemHeadId(oldCostDetail.FeeItemHeadID);
                this.BindDb(newCostDetail);
                newCostDetail.save();
            }

            //退费消息表置退费状态
            List <OP_FeeRefundHead> refundHeadList = NewObject <OP_FeeRefundHead>().getlist <OP_FeeRefundHead>(" invoiceNum='" + refundInvoiceNO + "' and flag=0");

            if (refundHeadList.Count == 0)
            {
                throw new Exception("找不到退费消息");
            }

            OP_FeeRefundHead refundHead = refundHeadList[0] as OP_FeeRefundHead;

            refundHead.RefundPayFlag = 1;//退费完成状态
            this.BindDb(refundHead);
            refundHead.save();

            //减会员积分
            AddScore(newCostHead.MemberAccountID, newCostHead.TotalFee, newCostHead.CostHeadID.ToString(), operatoreid);

            //药品加虚拟库存
            MinisStorage(refundPrescriptions, true);
            AddAccoutFee(newCostHead, curAccountId, 0, 1);

            //修改医生站处方状态
            RefundDocPrsc(refundPrescriptions);
        }