/// <summary>
        /// 得到打折金额
        /// </summary>
        /// <param name="patTypeCode"></param>
        /// <param name="allCost"></param>
        /// <param name="invoice"></param>
        /// <returns></returns>
        protected decimal GetFavorCost(string patTypeCode, ChargeInfo chargeInfo, Prescription prescription)
        {
            Prescription[] prescripions = new Prescription[1];
            prescripions[0] = prescription;

            return(GetFavorCost(Patient.MediType, chargeInfo, prescripions));
        }
 /// <summary>
 /// 预算
 /// </summary>
 /// <param name="prescriptions">要预算的处方</param>
 /// <returns>预算信息,供正式结算用</returns>
 public override ChargeInfo[] Budget(Prescription[] prescriptions)
 {
     ChargeInfo[] chargeInfos = new ChargeInfo[prescriptions.Length];
     try
     {
         oleDb.BeginTransaction( );
         chargeInfos = _budget(prescriptions);
         oleDb.CommitTransaction( );
     }
     catch (Exception err)
     {
         oleDb.RollbackTransaction( );
         ErrorWriter.WriteLog(err);
         throw new Exception("预结算发生错误!");
     }
     return(chargeInfos);
 }
        /// <summary>
        /// 得到打折金额
        /// </summary>
        /// <param name="patTypeCode"></param>
        /// <param name="allCost"></param>
        /// <param name="invoice"></param>
        /// <returns></returns>
        protected decimal GetFavorCost(string patTypeCode, ChargeInfo chargeInfo, Prescription[] Prescriptions)
        {
            HIS.DAL.Public_DAL pub_dal = new HIS.DAL.Public_DAL( );
            pub_dal._OleDB = oleDb;
            List <HIS.DAL.Public_DAL.faoverAllData> invoiceItems = new List <HIS.DAL.Public_DAL.faoverAllData>( );

            for (int i = 0; i < chargeInfo.Items.Length; i++)
            {
                HIS.DAL.Public_DAL.faoverAllData data = new HIS.DAL.Public_DAL.faoverAllData( );
                data.Code     = chargeInfo.Items[i].ItemCode;
                data.Totalfee = chargeInfo.Items[i].Cost;
                invoiceItems.Add(data);
            }
            List <HIS.DAL.Public_DAL.faoverAllData> details = new List <HIS.DAL.Public_DAL.faoverAllData>( );

            for (int i = 0; i < Prescriptions.Length; i++)
            {
                for (int j = 0; j < Prescriptions[i].PresDetails.Length; j++)
                {
                    HIS.DAL.Public_DAL.faoverAllData data = new HIS.DAL.Public_DAL.faoverAllData( );
                    data.Code     = Prescriptions[i].PresDetails[j].ItemId.ToString( );
                    data.Totalfee = Prescriptions[i].PresDetails[j].Tolal_Fee;
                    if (Prescriptions[i].PresDetails[j].BigitemCode == "01" || Prescriptions[i].PresDetails[j].BigitemCode == "02" || Prescriptions[i].PresDetails[j].BigitemCode == "03")
                    {
                        data.Type = 2;
                    }
                    else
                    {
                        if (Prescriptions[i].PresDetails[j].ComplexId == 0)
                        {
                            data.Type = 0;
                        }
                        else
                        {
                            data.Type = 1;
                        }
                    }
                    details.Add(data);
                }
            }
            return(pub_dal.GetfaoverAll_Fee(1, patTypeCode, chargeInfo.TotalFee, invoiceItems, details));
        }
Beispiel #4
0
        /// <summary>
        /// 预算
        /// </summary>
        /// <param name="prescriptions">要预算的处方</param>
        /// <returns>预算信息,供正式结算用</returns>
        public override ChargeInfo[] Budget(Prescription[] prescriptions)
        {
            //单张处方明细转化为大项目明细合并后累加在取舍。
            //保存每张处方的大项目明细
            List <List <Item> > lstStatItems = new List <List <Item> >( );
            //本次结算总金额(等于每张处方舍入后的金额的合计)
            decimal chargeTotalCost = 0;

            #region 合并大类并计算舍入金额
            try
            {
                for (int i = 0; i < prescriptions.Length; i++)
                {
                    List <Item> lstTemp = new List <Item>( );
                    lstTemp         = MergePrescriptionByStatItemCode(ref prescriptions[i]);
                    chargeTotalCost = chargeTotalCost + prescriptions[i].Total_Fee;
                    lstStatItems.Add(lstTemp);
                }
            }
            catch (Exception err)
            {
                ErrorWriter.WriteLog(err.Message + "\r\n" + err.StackTrace);
                throw new OperatorException("合并项目发生错误!");
            }
            #endregion
            //保存合并后的所有大项目明细,类型MZ_CostOrder
            Hashtable htCostOrder = new Hashtable();
            #region 合并所有结算明细(不需要再舍入)
            try
            {
                foreach (List <Item> lstTemp in lstStatItems)
                {
                    foreach (object obj in lstTemp)
                    {
                        if (htCostOrder.ContainsKey(((Item)obj).Text.Trim( )))
                        {
                            Item item = (Item)obj;
                            Model.MZ_CostOrder mz_costorder = (Model.MZ_CostOrder)htCostOrder[item.Text.Trim( )];
                            mz_costorder.Total_Fee = mz_costorder.Total_Fee + Convert.ToDecimal(item.Value);
                        }
                        else
                        {
                            Model.MZ_CostOrder mz_costorder = new HIS.Model.MZ_CostOrder( );
                            mz_costorder.ItemType  = ((Item)obj).Text.Trim( );
                            mz_costorder.Total_Fee = Convert.ToDecimal(((Item)obj).Value);
                            htCostOrder.Add(mz_costorder.ItemType, mz_costorder);
                        }
                    }
                }
            }
            catch (Exception err)
            {
                ErrorWriter.WriteLog(err.Message);
                throw new OperatorException("合并明细大类发生错误!");
            }
            #endregion
            int costmasterid = 0; //本次结算ID
            #region 数据库操作,得到结算号
            try
            {
                oleDb.BeginTransaction( );

                #region 赋值结算头表并保存
                HIS.Model.MZ_CostMaster mz_costmaster = new HIS.Model.MZ_CostMaster( );
                mz_costmaster.PatID        = Patient.PatID;
                mz_costmaster.PatListID    = Patient.PatListID;
                mz_costmaster.PresMasterID = 0;
                mz_costmaster.TicketNum    = "";
                mz_costmaster.TicketCode   = "";
                mz_costmaster.ChargeCode   = OperatorId.ToString( );
                //mz_costmaster.ChargeName = PublicDataReader.GetEmployeeNameById( OperatorId );
                mz_costmaster.ChargeName   = BaseDataController.GetName(BaseDataCatalog.人员列表, OperatorId);
                mz_costmaster.Total_Fee    = chargeTotalCost;//结算表的总金额
                mz_costmaster.Self_Fee     = 0;
                mz_costmaster.Village_Fee  = 0;
                mz_costmaster.Favor_Fee    = 0;
                mz_costmaster.Pos_Fee      = 0;
                mz_costmaster.Money_Fee    = 0;
                mz_costmaster.Ticket_Flag  = 0;
                mz_costmaster.Record_Flag  = 9;//预结算记录状态置为9
                mz_costmaster.OldID        = 0;
                mz_costmaster.AccountID    = 0;
                mz_costmaster.Hang_Flag    = (int)OPDOperationType.门诊收费;
                mz_costmaster.Hurried_Flag = Patient.IsEmergency ? 1 : 0;
                mz_costmaster.CostMasterID = BindEntity <Model.MZ_CostMaster> .CreateInstanceDAL(oleDb).Add(mz_costmaster);

                #endregion
                costmasterid = mz_costmaster.CostMasterID;
                #region 更新处方表的结算号和总金额,舍入金额
                for (int prescCount = 0; prescCount < prescriptions.Length; prescCount++)
                {
                    string strWhere = Tables.mz_presmaster.PRESMASTERID + oleDb.EuqalTo( ) + prescriptions[prescCount].PrescriptionID;
                    Model.MZ_PresMaster mz_presmaster = BindEntity <Model.MZ_PresMaster> .CreateInstanceDAL(oleDb).GetModel(strWhere);

                    if (mz_presmaster.Charge_Flag == 1)
                    {
                        throw new OperatorException("处方已被别的收费员收费,请确认!");
                    }
                    if (prescriptions[prescCount].DocPresId != 0)
                    {
                        if (HIS.Interface.InstanceFactory.CreatMZ_ClinicDataInstance().CheckPresStatus(prescriptions[prescCount].DocPresId) == false)
                        {
                            throw new OperatorException("处方已经收费,请重新刷新病人信息以获取最新未收费处方!\r\n(建议不要同时打开多个收费界面)");
                        }
                    }
                    //更新处方表的结算号和总金额,舍入金额
                    BindEntity <Model.MZ_PresMaster> .CreateInstanceDAL(oleDb).Update(strWhere,
                                                                                      Tables.mz_presmaster.COSTMASTERID + oleDb.EuqalTo( ) + mz_costmaster.CostMasterID,
                                                                                      Tables.mz_presmaster.TOTAL_FEE + oleDb.EuqalTo( ) + prescriptions[prescCount].Total_Fee,
                                                                                      Tables.mz_presmaster.ROUNGINGMONEY + oleDb.EuqalTo( ) + prescriptions[prescCount].RoundingMoney);
                }
                #endregion

                #region 保存结算明细到数据库(按大项目保存)
                foreach (object obj in htCostOrder)
                {
                    HIS.Model.MZ_CostOrder mz_costorder = (HIS.Model.MZ_CostOrder)((System.Collections.DictionaryEntry)obj).Value;
                    mz_costorder.CostID = mz_costmaster.CostMasterID;
                    //保存到数据库
                    mz_costorder.CostOrderID = BindEntity <Model.MZ_CostOrder> .CreateInstanceDAL(oleDb).Add(mz_costorder);
                }
                #endregion

                oleDb.CommitTransaction( );
            }
            catch (OperatorException oe)
            {
                oleDb.RollbackTransaction( );
                throw oe;
            }
            catch (Exception err)
            {
                oleDb.RollbackTransaction( );
                ErrorWriter.WriteLog(err.Message + "\r\n" + err.StackTrace);
                throw new OperatorException("保存预算结果到数据库发生错误!");
            }
            #endregion
            //回填处方的结算号
            for (int prescCount = 0; prescCount < prescriptions.Length; prescCount++)
            {
                prescriptions[prescCount].ChargeID = costmasterid;
            }

            #region 返回预算结果
            try
            {
                Hashtable htInvoiceItem = new Hashtable( );
                foreach (object obj in htCostOrder)
                {
                    HIS.Model.MZ_CostOrder mz_costorder = (HIS.Model.MZ_CostOrder)((System.Collections.DictionaryEntry)obj).Value;
                    InvoiceItem            invoice      = GetInvoiceByStatCode(mz_costorder.ItemType.Trim( ));
                    invoice.Cost = mz_costorder.Total_Fee;
                    if (htInvoiceItem.ContainsKey(invoice.ItemCode.Trim( )))
                    {
                        InvoiceItem _invoice = (InvoiceItem)htInvoiceItem[invoice.ItemCode];
                        _invoice.Cost = _invoice.Cost + invoice.Cost;
                        htInvoiceItem.Remove(invoice.ItemCode);
                        htInvoiceItem.Add(_invoice.ItemCode, _invoice);
                    }
                    else
                    {
                        htInvoiceItem.Add(invoice.ItemCode, invoice);
                    }
                }
                List <InvoiceItem> chargeItems = new List <InvoiceItem>( );
                foreach (object item in htInvoiceItem)
                {
                    chargeItems.Add((InvoiceItem)((DictionaryEntry)item).Value);
                }

                ChargeInfo chargeInfos = new ChargeInfo( );
                chargeInfos.Items    = chargeItems.ToArray( );
                chargeInfos.ChargeID = costmasterid;
                chargeInfos.TotalFee = chargeTotalCost;

                ChargeInfo[] chargeInfo = new ChargeInfo[1];
                chargeInfo[0].TotalFee = chargeTotalCost;
                chargeInfo[0]          = chargeInfos;
                //计算本次的优惠金额
                chargeInfo[0].FavorFee = GetFavorCost(Patient.MediType, chargeInfo[0], prescriptions);
                return(chargeInfo);
            }
            catch (Exception err)
            {
                ErrorWriter.WriteLog(err);
                throw new OperatorException("返回预算结果发生错误!");
            }
            #endregion
        }
Beispiel #5
0
        /// <summary>
        /// 退费处理
        /// </summary>
        private void RefundmentProcess()
        {
               //delete by heyan 2011.3.22 不是该收费员收的费也可以退费
            //if ( _EmployeeID != Convert.ToInt32( currentInvoice.ChargeUserId ) )
            //{
            //    throw new OperatorException( "该发票不是您收费,需收费员【"+currentInvoice.ChargeUser+"】才能退费!" );
            //}
            //得到新的处方
            List <int> returnedDocPresIdList = new List <int>(); //有退费处理的医生处方ID

            Prescription[] remanentPrescriptions = GetPrescriptionRemanentFromGrid(true, out returnedDocPresIdList);
            if (remanentPrescriptions == null)
            {
                throw new OperatorException("至少需要指定一条需要退费项目的数量!");
            }
            //整理处方,除去0数量和没有明细的处方
            List <Prescription> lstPrescription = new List <Prescription>( );

            for (int i = 0; i < remanentPrescriptions.Length; i++)
            {
                remanentPrescriptions[i].PrescriptionID = 0;
                List <PrescriptionDetail> lstDetail = new List <PrescriptionDetail>( );
                for (int j = 0; j < remanentPrescriptions[i].PresDetails.Length; j++)
                {
                    remanentPrescriptions[i].PresDetails[j].DetailId = 0;
                    if (remanentPrescriptions[i].PresDetails[j].Tolal_Fee != 0)
                    {
                        lstDetail.Add(remanentPrescriptions[i].PresDetails[j]);
                    }
                }
                remanentPrescriptions[i].Modified  = true;
                remanentPrescriptions[i].DocPresId = 0;
                if (lstDetail.Count > 0)
                {
                    remanentPrescriptions[i].PresDetails = lstDetail.ToArray( );
                    lstPrescription.Add(remanentPrescriptions[i]);
                }
            }
            remanentPrescriptions = lstPrescription.ToArray( );
            if (remanentPrescriptions.Length == 0)
            {
                remanentPrescriptions = null;
            }


            ChargeControl chargeController = new ChargeControl(currentPatient, _EmployeeID);

            try
            {
                decimal newcost      = 0;
                decimal newmoneypay  = 0;
                decimal newpos       = 0;
                decimal newfoverpay  = 0;
                decimal newtally     = 0;
                decimal invoiceCount = 0;
                if (chargeController.Refundment(currentInvoice, remanentPrescriptions, returnedDocPresIdList))
                {
                    if (remanentPrescriptions != null)
                    {
                        if (chargeController.SavePrescription(remanentPrescriptions))
                        {
                            if (MessageBox.Show("部分退费需要重新补打发票收据,请确认发票是否已经准备就绪!", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            {
                                MessageBox.Show("用户已取消操作,需要重新收费的处方还未收费,请转到收费窗口继续收费!", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
                                ReturnPatient      = currentPatient;
                                HasPresNeedBalance = true;
                                return;
                            }

                            ChargeInfo[] chargeInfos = chargeController.Budget(remanentPrescriptions);
                            #region 合计结算信息并显示给用户
                            //累计结算信息
                            HIS.MZ_BLL.ChargeInfo totalChargeInfo = new HIS.MZ_BLL.ChargeInfo( );
                            for (int i = 0; i < chargeInfos.Length; i++)
                            {
                                totalChargeInfo.TotalFee   += chargeInfos[i].TotalFee;
                                totalChargeInfo.FavorFee   += chargeInfos[i].FavorFee;
                                totalChargeInfo.SelfFee    += chargeInfos[i].SelfFee;
                                totalChargeInfo.VillageFee += chargeInfos[i].VillageFee;
                            }

                            //向用户展示结算信息
                            FrmChargeInfo frmChargeInfo = new FrmChargeInfo(totalChargeInfo, true);
                            frmChargeInfo.ShowDialog( );

                            chargeController.SetChargeInfoPay(ref chargeInfos, frmChargeInfo.ReturnChargeInfo.VillageFee,
                                                              frmChargeInfo.ReturnChargeInfo.PosFee,
                                                              frmChargeInfo.ReturnChargeInfo.CashFee, frmChargeInfo.ReturnChargeInfo.SelfTally);

                            #endregion
                            Invoice[] invoices;
                            chargeController.Charge(chargeInfos, remanentPrescriptions, out invoices);

                            PrintController.PrintChargeInvoice(invoices);
                            invoiceCount = invoices.Length;
                            for (int i = 0; i < invoices.Length; i++)
                            {
                                newcost     += invoices[i].TotalPay;
                                newmoneypay += invoices[i].CashPay;
                                newpos      += invoices[i].PosPay;
                                newfoverpay += invoices[i].FavorPay;
                                newtally    += invoices[i].VillagePay;
                            }
                        }
                    }

                    decimal returncost     = currentInvoice.TotalPay - newcost;
                    decimal returnmoneypay = currentInvoice.CashPay - newmoneypay;
                    decimal returnpos      = currentInvoice.PosPay - newpos;
                    decimal returnfoverpay = currentInvoice.FavorPay - newfoverpay;
                    decimal returntally    = currentInvoice.VillagePay - newtally;
                    GWMHIS.BussinessLogicLayer.Forms.GwmMessageBox.Show("本次操作完成!\r\n需要退病人金额:" + returncost + "元,其中:" +
                                                                        "\r\n退 现 金:" + returnmoneypay + "元" +
                                                                        "\r\n退 POS  :" + returnpos + "元" +
                                                                        "\r\n退 优 惠:" + returnfoverpay + "元" +
                                                                        "\r\n退 记 账:" + returntally + "元" +
                                                                        "\r\n\r\n新打发票:" + invoiceCount + "张" +
                                                                        "\r\n总 金 额:" + newcost + "元",
                                                                        (new Font("宋体", 15F)), Color.Red, "退费成功", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show("退费失败!\r\n可能的原因;+\r\n" + err.Message, "", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
        /// <summary>
        /// 预算
        /// </summary>
        /// <param name="prescriptions">要进行计算的处方,数组对象</param>
        /// <returns></returns>
        private ChargeInfo[] _budget(Prescription[] prescriptions)
        {
            //MZClinicInterface clinicInterface = new MZClinicInterface();

            ChargeInfo[] chargeInfos = new ChargeInfo[prescriptions.Length];
            try
            {
                for (int prescCount = 0; prescCount < prescriptions.Length; prescCount++)
                {
                    List <Item> lstStatItems = MergePrescriptionByStatItemCode(ref prescriptions[prescCount]);

                    Prescription prescription = prescriptions[prescCount];
                    chargeInfos[prescCount] = new ChargeInfo( );
                    //保存结算头
                    HIS.Model.MZ_CostMaster chargeBill = new HIS.Model.MZ_CostMaster( );
                    #region ....
                    chargeBill.PatID        = Patient.PatID;
                    chargeBill.PatListID    = Patient.PatListID;
                    chargeBill.PresMasterID = prescription.PrescriptionID;
                    chargeBill.TicketNum    = "";
                    chargeBill.TicketCode   = "";
                    chargeBill.ChargeCode   = OperatorId.ToString( );
                    //chargeBill.ChargeName = PublicDataReader.GetEmployeeNameById( OperatorId ); //BindEntity<HIS.Model.BASE_EMPLOYEE_PROPERTY>.CreateInstanceDAL(oleDb).GetModel(OperatorId).NAME ;
                    chargeBill.ChargeName  = BaseDataController.GetName(BaseDataCatalog.人员列表, OperatorId);
                    chargeBill.Total_Fee   = prescription.Total_Fee;
                    chargeBill.Self_Fee    = 0;
                    chargeBill.Village_Fee = 0;
                    chargeBill.Favor_Fee   = 0;
                    chargeBill.Pos_Fee     = 0;
                    chargeBill.Money_Fee   = 0;
                    chargeBill.Ticket_Flag = 0;
                    //chargeBill.CostDate;//预结算不写结算时间
                    chargeBill.Record_Flag  = 9;//预结算记录状态置为9
                    chargeBill.OldID        = 0;
                    chargeBill.AccountID    = 0;
                    chargeBill.Hang_Flag    = (int)OPDOperationType.门诊收费;
                    chargeBill.Hurried_Flag = Patient.IsEmergency ? 1 : 0;
                    #endregion
                    int ret1 = BindEntity <Model.MZ_CostMaster> .CreateInstanceDAL(oleDb).Add(chargeBill);

                    chargeBill.CostMasterID            = ret1;
                    prescriptions[prescCount].ChargeID = ret1;
                    //累加每张处方结算信息
                    chargeInfos[prescCount].ChargeID       = chargeBill.CostMasterID;
                    chargeInfos[prescCount].PrescriptionID = chargeBill.PresMasterID;
                    chargeInfos[prescCount].TotalFee       = chargeBill.Total_Fee;
                    chargeInfos[prescCount].SelfFee        = chargeBill.Self_Fee;
                    chargeInfos[prescCount].VillageFee     = chargeBill.Village_Fee;
                    chargeInfos[prescCount].FavorFee       = chargeBill.Favor_Fee;
                    if (ret1 > 0)
                    {
                        List <InvoiceItem> chargeItems = new List <InvoiceItem>( );
                        #region  大项目保存结算明细
                        foreach (object obj in lstStatItems)
                        {
                            Item item = (Item)obj;
                            HIS.Model.MZ_CostOrder chargeDetail = new HIS.Model.MZ_CostOrder( );
                            chargeDetail.CostID    = chargeBill.CostMasterID;
                            chargeDetail.ItemType  = item.Text;
                            chargeDetail.Total_Fee = Convert.ToDecimal(item.Value);

                            int ret2 = BindEntity <Model.MZ_CostOrder> .CreateInstanceDAL(oleDb).Add(chargeDetail);

                            if (ret2 > 0)
                            {
                                InvoiceItem invoice = GetInvoiceByStatCode(chargeDetail.ItemType);
                                invoice.Cost = chargeDetail.Total_Fee;
                                chargeItems.Add(invoice);
                            }
                        }
                        #endregion
                        chargeInfos[prescCount].Items = chargeItems.ToArray( );
                    }
                }

                //for (int i = 0; i < prescriptions.Length; i++)//预算就修改门诊处方状态
                //    clinicInterface.ChangePresStatus(prescriptions[i].DocPresId, 1);
            }
            catch (Exception err)
            {
                throw err;
            }
            //计算每张处方的打折金额
            for (int i = 0; i < chargeInfos.Length; i++)
            {
                chargeInfos[i].FavorFee = GetFavorCost(Patient.MediType, chargeInfos[i], prescriptions[i]);
            }
            return(chargeInfos);
        }