Ejemplo n.º 1
0
        public ServiceResponseData SaveRefundMessage()
        {
            try
            {
                DataTable        dtPresc     = requestData.GetData <DataTable>(0);
                DataTable        dtMedical   = requestData.GetData <DataTable>(1);
                int              operatoreid = requestData.GetData <int>(2);
                OP_FeeRefundHead refundHead  = new OP_FeeRefundHead();
                refundHead.RefundDocID   = operatoreid;
                refundHead.RefundDate    = DateTime.Now;
                refundHead.RefundPayFlag = 0;
                refundHead.Flag          = 0;
                refundHead.PatListID     = dtPresc == null || dtPresc.Rows.Count == 0 ? Convert.ToInt32(dtMedical.Rows[0]["patlistid"]):  Convert.ToInt32(dtPresc.Rows[0]["patlistid"]);
                refundHead.PatName       = dtPresc == null || dtPresc.Rows.Count == 0 ? dtMedical.Rows[0]["patname"].ToString(): dtPresc.Rows[0]["patname"].ToString();
                refundHead.InvoiceNum    = dtPresc == null || dtPresc.Rows.Count == 0 ? dtMedical.Rows[0]["invoiceNO"].ToString():dtPresc.Rows[0]["invoiceNO"].ToString();
                this.BindDb(refundHead);
                refundHead.save();

                if (dtPresc != null)
                {
                    for (int i = 0; i < dtPresc.Rows.Count; i++)
                    {
                        if (dtPresc.Rows[i]["ItemName"].ToString().Trim() == "小   计")
                        {
                            continue;
                        }

                        OP_FeeRefundDetail refundDetail = new OP_FeeRefundDetail();
                        refundDetail.ReHeadID      = refundHead.ReHeadID;
                        refundDetail.FeeItemHeadID = Convert.ToInt32(dtPresc.Rows[i]["FeeItemHeadID"]);
                        OP_FeeItemHead opfeeitemhead = NewObject <OP_FeeItemHead>().getmodel(refundDetail.FeeItemHeadID) as OP_FeeItemHead;
                        if (opfeeitemhead.ChargeStatus != 0 && opfeeitemhead.ChargeFlag != 1 && opfeeitemhead.DistributeFlag != Convert.ToInt32(dtPresc.Rows[i]["DistributeFlag"]))
                        {
                            throw new Exception("该处方没有正常的收费记录");
                        }

                        refundDetail.DistributeFlag  = opfeeitemhead.DistributeFlag;//取数据库最新记录状态,防止并发状态
                        refundDetail.RefundFlag      = 0;
                        refundDetail.FeeItemDetailID = Convert.ToInt32(dtPresc.Rows[i]["PresDetailID"]);
                        refundDetail.ItemID          = Convert.ToInt32(dtPresc.Rows[i]["ItemID"]);
                        refundDetail.ItemName        = dtPresc.Rows[i]["ItemName"].ToString();
                        refundDetail.OldAmount       = Convert.ToDecimal(dtPresc.Rows[i]["Amount"]);

                        decimal refundminimun    = Convert.ToDecimal(dtPresc.Rows[i]["RefundMiniNum"]);
                        decimal refundpacknum    = Convert.ToDecimal(dtPresc.Rows[i]["RefundPackNum"]);
                        decimal refundpresamount = Convert.ToDecimal(dtPresc.Rows[i]["refundpresamount"]);
                        decimal unitNO           = Convert.ToDecimal(dtPresc.Rows[i]["UnitNO"]);
                        decimal refundamount     = ((refundpacknum * unitNO) + refundminimun) * refundpresamount;
                        refundDetail.RefundAmount     = refundamount;
                        refundDetail.NewAmount        = refundDetail.OldAmount - refundDetail.RefundAmount;
                        refundDetail.RefundFee        = Convert.ToDecimal(dtPresc.Rows[i]["RefundFee"]);
                        refundDetail.RefundPresAmount = refundpresamount;
                        this.BindDb(refundDetail);
                        refundDetail.save();
                    }
                }

                if (dtMedical != null)
                {
                    //根据组合项目生成明细
                    for (int i = 0; i < dtMedical.Rows.Count; i++)
                    {
                        int            feeItemHeadID = Convert.ToInt32(dtMedical.Rows[i]["FeeItemHeadID"]);
                        OP_FeeItemHead opfeeitemhead = NewObject <OP_FeeItemHead>().getmodel(feeItemHeadID) as OP_FeeItemHead;
                        if (opfeeitemhead.ChargeStatus != 0 && opfeeitemhead.ChargeFlag != 1 && opfeeitemhead.DistributeFlag != Convert.ToInt32(dtMedical.Rows[i]["DistributeFlag"]))
                        {
                            throw new Exception("该处方没有正常的收费记录");
                        }

                        List <OP_FeeItemDetail> list = NewObject <OP_FeeItemDetail>().getlist <OP_FeeItemDetail>(" FeeItemHeadID=" + feeItemHeadID + " and ExamItemID=" + dtMedical.Rows[i]["ExamItemID"] + " ");
                        foreach (OP_FeeItemDetail detail in list)
                        {
                            OP_FeeRefundDetail refundDetail = new OP_FeeRefundDetail();
                            refundDetail.ReHeadID        = refundHead.ReHeadID;
                            refundDetail.FeeItemHeadID   = feeItemHeadID;
                            refundDetail.DistributeFlag  = opfeeitemhead.DistributeFlag;//取数据库最新记录状态,防止并发状态
                            refundDetail.RefundFlag      = 0;
                            refundDetail.FeeItemDetailID = detail.PresDetailID;
                            refundDetail.ItemID          = detail.ItemID;
                            refundDetail.ItemName        = detail.ItemName;
                            refundDetail.OldAmount       = detail.Amount;
                            if (dtMedical.Rows[i]["Sel"] != DBNull.Value &&
                                Convert.ToInt32(dtMedical.Rows[i]["Sel"]) == 1)
                            {
                                refundDetail.RefundAmount = detail.Amount;
                            }
                            else
                            {
                                refundDetail.RefundAmount = 0;
                            }

                            refundDetail.NewAmount        = refundDetail.OldAmount - refundDetail.RefundAmount;
                            refundDetail.RefundFee        = detail.RetailPrice * refundDetail.RefundAmount;
                            refundDetail.RefundPresAmount = detail.PresAmount;
                            this.BindDb(refundDetail);
                            refundDetail.save();
                        }
                    }
                }

                responseData.AddData(true);
                return(responseData);
            }
            catch (Exception err)
            {
                throw new Exception(err.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 根据发票号获取处方
        /// </summary>
        /// <param name="invoiceNo">票据号</param>
        /// <param name="patlistid">病人ID</param>
        /// <returns>处方对象</returns>
        public List <Prescription> GetPrescriptionByInvoiceNo(string invoiceNo, int patlistid)
        {
            List <Prescription> preslist  = new List <Prescription>();
            BasicDataManagement basicdata = NewObject <BasicDataManagement>();
            string condiction             = string.Empty;

            condiction = " PatListID = " + patlistid + " AND ChargeFlag = 1 AND ChargeStatus = 0 And invoiceNO='" + invoiceNo + "' and regflag=0";
            condiction = condiction + " order by feeitemheadid";

            //得到实体列表
            List <OP_FeeItemHead> presMastList = NewObject <OP_FeeItemHead>().getlist <OP_FeeItemHead>(condiction);

            if (presMastList.Count == 0)
            {
                throw new Exception("找不到发票信息!\r\n1、请确认发票号是否正确。\r\n2、请确认该发票是否已退费。");
            }

            for (int i = 0; i < presMastList.Count; i++)
            {
                decimal refundfee = 0;
                List <OP_FeeItemDetail> presDetailList = NewObject <OP_FeeItemDetail>().getlist <OP_FeeItemDetail>(" FeeItemHeadID=" + presMastList[i].FeeItemHeadID + " order by PresDetailID");
                for (int j = 0; j < presDetailList.Count; j++)
                {
                    #region 明细
                    Prescription pres = new Prescription();
                    pres.PresDetailID    = presDetailList[j].PresDetailID;
                    pres.FeeItemHeadID   = presDetailList[j].FeeItemHeadID;
                    pres.PatListID       = presDetailList[j].PatListID;
                    pres.ItemID          = presDetailList[j].ItemID;
                    pres.ItemName        = presDetailList[j].ItemName;
                    pres.Spec            = presDetailList[j].Spec;
                    pres.PackUnit        = presDetailList[j].PackUnit;
                    pres.UnitNO          = presDetailList[j].UnitNO;
                    pres.StockPrice      = presDetailList[j].StockPrice;
                    pres.Amount          = presDetailList[j].Amount;
                    pres.PresAmount      = presDetailList[j].PresAmount;
                    pres.TotalFee        = presDetailList[j].TotalFee;
                    pres.ExamItemID      = presDetailList[j].ExamItemID;
                    pres.DocPresDetailID = presDetailList[j].DocPresDetailID;
                    pres.MiniUnit        = presDetailList[j].MiniUnit;
                    pres.RetailPrice     = presDetailList[j].RetailPrice;
                    pres.StatID          = presDetailList[j].StatID;
                    pres.ItemType        = presDetailList[j].ItemType;

                    pres.PrescGroupID = i + 1;
                    pres.presNO       = j == 0 ? i + 1 : 0;
                    pres.PresDeptID   = presMastList[i].PresDeptID;
                    pres.PresEmpID    = presMastList[i].PresEmpID;
                    pres.ExecDeptID   = presMastList[i].ExecDeptID;
                    pres.PresDocName  = basicdata.GetEmpName(presMastList[i].PresEmpID);
                    pres.ExecDetpName = basicdata.GetDeptName(presMastList[i].ExecDeptID);
                    pres.PresType     = presMastList[i].PresType;
                    pres.ModifyFlag   = 0;
                    pres.Selected     = 1;
                    pres.CostHeadID   = presMastList[i].CostHeadID;

                    pres.DocPresNO       = presMastList[i].DocPresNO;
                    pres.DocPresHeadID   = presMastList[i].DocPresHeadID;
                    pres.DocPresDetailID = presDetailList[j].DocPresDetailID;
                    List <OP_FeeRefundHead>   refundHeadList   = NewObject <OP_FeeRefundHead>().getlist <OP_FeeRefundHead>(" invoiceNum='" + invoiceNo + "' and flag=0");
                    List <OP_FeeRefundDetail> refundDetailList = NewObject <OP_FeeRefundDetail>().getlist <OP_FeeRefundDetail>(" ReHeadID=" + refundHeadList[0].ReHeadID + " and FeeItemDetailID=" + presDetailList[j].PresDetailID + " ");
                    if (refundDetailList.Count == 0)
                    {
                        continue;
                    }

                    OP_FeeRefundDetail refundDetail = refundDetailList[0] as OP_FeeRefundDetail;
                    pres.Refundamount = refundDetail.RefundAmount;
                    pres.Refundfee    = refundDetail.RefundFee;
                    if (Convert.ToInt32(pres.ItemType) == (int)OP_Enum.ItemType.收费项目 || Convert.ToInt32(pres.ItemType) == (int)OP_Enum.ItemType.组合项目)
                    {
                        pres.MiniAmount = presDetailList[j].Amount;
                        pres.PackAmount = (presDetailList[j].Amount - pres.MiniAmount) / pres.UnitNO;

                        pres.RefundMiniAmount = refundDetail.RefundAmount;
                        pres.RefundPackAmount = (refundDetail.RefundAmount - pres.RefundMiniAmount) / pres.UnitNO;
                    }
                    else
                    {
                        pres.MiniAmount = presDetailList[j].Amount % presDetailList[j].UnitNO;
                        pres.PackAmount = (presDetailList[j].Amount - pres.MiniAmount) / pres.UnitNO;

                        pres.RefundMiniAmount = refundDetail.RefundAmount % pres.UnitNO;
                        pres.RefundPackAmount = (refundDetail.RefundAmount - pres.RefundMiniAmount) / pres.UnitNO;
                    }

                    pres.DocPresHeadID = presMastList[i].DocPresHeadID;
                    pres.Refundfee     = refundDetail.RefundFee;
                    refundfee         += pres.Refundfee;
                    #endregion
                    preslist.Add(pres);
                }

                Prescription presTotal = new Prescription();
                presTotal.ExecDetpName = "小 计";
                presTotal.SubTotalFlag = 1;
                presTotal.PrescGroupID = i + 1;
                presTotal.presNO       = 0;
                presTotal.TotalFee     = presMastList[i].TotalFee;
                presTotal.Refundfee    = refundfee;
                presTotal.Selected     = 1;
                preslist.Add(presTotal);
            }

            return(preslist);
        }