示例#1
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)
            {
                throw new Exception("合并项目发生错误!");
            }
            #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;
                            MZ_CostOrder mz_costorder = (MZ_CostOrder)htCostOrder[item.Text.Trim( )];
                            mz_costorder.Total_Fee = mz_costorder.Total_Fee + Convert.ToDecimal(item.Value);
                        }
                        else
                        {
                            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)
            {
                throw new Exception("合并明细大类发生错误!");
            }
            #endregion
            int costmasterid = MSAccessDb.GetMaxID("MZ_COSTMASTER", Tables.mz_costmaster.COSTMASTERID);
            #region 数据库操作,得到结算号
            try
            {
                MSAccessDb.BeginTrans();

                #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   = DataReader.GetEmployeeNameById(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 = costmasterid;

                MSAccessDb.InsertRecord(mz_costmaster, Tables.mz_costorder.COSTORDERID);
                #endregion

                #region 更新处方表的结算号和总金额,舍入金额
                for (int prescCount = 0; prescCount < prescriptions.Length; prescCount++)
                {
                    string        strWhere      = Tables.mz_presmaster.PRESMASTERID + " = " + prescriptions[prescCount].PrescriptionID;
                    MZ_PresMaster mz_presmaster = (MZ_PresMaster)MSAccessDb.GetModel("MZ_PRESMASTER", strWhere, typeof(MZ_PresMaster));
                    if (mz_presmaster.Charge_Flag == 1)
                    {
                        throw new Exception("处方已被别的收费员收费,请确认!");
                    }
                    //更新处方表的结算号和总金额,舍入金额
                    //BindEntity<MZ_PresMaster>.CreateInstanceDAL( oleDb ).Update( strWhere ,
                    //                      Tables.mz_presmaster.COSTMASTERID + " = " + mz_costmaster.CostMasterID ,
                    //                      Tables.mz_presmaster.TOTAL_FEE + " = " + prescriptions[prescCount].Total_Fee ,
                    //                      Tables.mz_presmaster.ROUNGINGMONEY + " = " + prescriptions[prescCount].RoundingMoney );
                    MSAccessDb.UpdateRecord(new string[] { Tables.mz_presmaster.COSTMASTERID + " = " + mz_costmaster.CostMasterID,
                                                           Tables.mz_presmaster.TOTAL_FEE + " = " + prescriptions[prescCount].Total_Fee,
                                                           Tables.mz_presmaster.ROUNGINGMONEY + " = " + prescriptions[prescCount].RoundingMoney },
                                            strWhere, typeof(MZ_PresMaster));
                }
                #endregion

                #region 保存结算明细到数据库(按大项目保存)
                int costorderid = MSAccessDb.GetMaxID("MZ_COSTORDER", Tables.mz_costorder.COSTORDERID);
                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 = costorderid;
                    //保存到数据库
                    //mz_costorder.CostOrderID = BindEntity<MZ_CostOrder>.CreateInstanceDAL( oleDb ).Add( mz_costorder );
                    MSAccessDb.InsertRecord(mz_costorder, Tables.mz_costorder.COSTORDERID);
                    costorderid++;
                }
                #endregion

                MSAccessDb.CommitTrans( );
            }

            catch (Exception err)
            {
                MSAccessDb.RollbackTrans( );
                throw new Exception("保存预算结果到数据库发生错误!");
            }
            #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)
            {
                throw new Exception("返回预算结果发生错误!");
            }
            #endregion
        }
示例#2
0
        /// <summary>
        /// 发票号
        /// </summary>
        /// <param name="InvoiceNo">发票号</param>
        public Invoice(string PerfChar, string InvoiceNo, OPDBillKind kind)
        {
            HIS.Model.MZ_CostMaster m_mz_costmaster = new HIS.Model.MZ_CostMaster( );
            //HIS.DAL.MZ_DAL mz_dal = new HIS.DAL.MZ_DAL( );
            //mz_dal._OleDB = oleDb;
            try
            {
                string condiction = "TicketNum='" + InvoiceNo + "' and record_flag in (0,1)";
                if (PerfChar.Trim( ) != "")
                {
                    condiction += " and TicketCode ='" + PerfChar + "'";
                }

                if (kind == OPDBillKind.门诊挂号发票)
                {
                    condiction += " and hang_flag=" + (int)OPDOperationType.门诊挂号;
                }
                if (kind == OPDBillKind.门诊收费发票)
                {
                    condiction += " and hang_flag=" + (int)OPDOperationType.门诊收费;
                }

                //m_mz_costmaster = BindEntity<MZ_CostMaster>.CreateInstanceDAL(oleDb).GetModel( condiction );
                m_mz_costmaster = (MZ_CostMaster)MSAccessDb.GetModel("MZ_COSTMASTER", condiction, typeof(MZ_CostMaster));
                _chargeId       = m_mz_costmaster.CostMasterID;
                _invoiceNo      = InvoiceNo;
                MZ_CostMaster mz_costmaster = (MZ_CostMaster)MSAccessDb.GetModel("MZ_COSTMASTER", Tables.mz_costmaster.COSTMASTERID + "=" + m_mz_costmaster.CostMasterID, typeof(MZ_CostMaster));
                MZ_PatList    mz_patlist    = (MZ_PatList)MSAccessDb.GetModel("MZ_PATLIST", Tables.mz_patlist.PATLISTID + "=" + mz_costmaster.PatListID, typeof(MZ_PatList));
                _patientName  = mz_patlist == null ? "" : mz_patlist.PatName;
                _totalPay     = m_mz_costmaster.Total_Fee;
                _posPay       = m_mz_costmaster.Pos_Fee;
                _favorPay     = m_mz_costmaster.Favor_Fee;
                _villagePay   = m_mz_costmaster.Village_Fee;
                _chargeUser   = m_mz_costmaster.ChargeName;
                _chargeUserId = m_mz_costmaster.ChargeCode;
                _chargeDate   = m_mz_costmaster.CostDate;
                _record_flag  = m_mz_costmaster.Record_Flag;
                _cashPay      = _totalPay - _posPay - _villagePay - _favorPay;//m_mz_costmaster.Money_Fee;
                //发票内容
//                string sql = @"select b.ITEM_NAME,TOTAL_FEE
//                                from mz_costorder as a,base_stat_mzfp as b,base_stat_item as c
//                                where a.ITEMTYPE = c.CODE AND c.MZFP_CODE = b.CODE AND a.COSTID = " + mz_costmaster.CostMasterID;
//                System.Data.DataTable tb = mz_dal.GetInvoiceDetail( mz_costmaster.CostMasterID );
                string    sql            = @"select c.mzfp_name as ITEM_NAME,TOTAL_FEE 
                                from mz_costorder as a,base_stat_item as c  
                                where a.ITEMTYPE = c.CODE AND a.COSTID = " + mz_costmaster.CostMasterID;
                DataTable tb             = MSAccessDb.GetDataTable(sql);
                Hashtable htInvoiceItems = new Hashtable( );
                for (int i = 0; i < tb.Rows.Count; i++)
                {
                    InvoiceItem item = new InvoiceItem();
                    item.ItemName = tb.Rows[i]["Item_Name"].ToString( ).Trim( );
                    item.Cost     = Convert.ToDecimal(tb.Rows[i]["Total_fee"]);

                    if (htInvoiceItems.ContainsKey(item.ItemName))
                    {
                        InvoiceItem item1 = (InvoiceItem)htInvoiceItems[item.ItemName];
                        item1.Cost = item1.Cost + item.Cost;
                        htInvoiceItems.Remove(item.ItemName);
                        htInvoiceItems.Add(item1.ItemName, item1);
                    }
                    else
                    {
                        htInvoiceItems.Add(item.ItemName, item);
                    }
                }

                _items = new InvoiceItem[htInvoiceItems.Count];
                int invoiceCount = 0;
                foreach (object obj in htInvoiceItems)
                {
                    _items[invoiceCount].ItemName = ((InvoiceItem)((DictionaryEntry)obj).Value).ItemName;
                    _items[invoiceCount].Cost     = ((InvoiceItem)((DictionaryEntry)obj).Value).Cost;
                    invoiceCount++;
                }

                //处方信息
                #region ...
                //定义统计大类容器
                Hashtable htStatItems = new Hashtable( );
                List <HIS.Model.MZ_PresMaster> lst_mz_presmaster = new List <HIS.Model.MZ_PresMaster>( );
                //lst_mz_presmaster = BindEntity<MZ_PresMaster>.CreateInstanceDAL( oleDb ).GetListArray( Tables.mz_presmaster.COSTMASTERID + oleDb.EuqalTo() + _chargeId );
                lst_mz_presmaster = MSAccessDb.GetListArray <MZ_PresMaster>("MZ_PRESMASTER", Tables.mz_presmaster.COSTMASTERID + "=" + _chargeId);
                _prescription     = new Prescription[lst_mz_presmaster.Count];
                int index = 0;
                foreach (MZ_PresMaster model_mz_presmaster in lst_mz_presmaster)
                {
                    _prescription[index]                = new Prescription( );
                    _prescription[index].Charge_Flag    = model_mz_presmaster.Charge_Flag;
                    _prescription[index].ChargeCode     = model_mz_presmaster.ChargeCode;
                    _prescription[index].ChargeID       = model_mz_presmaster.CostMasterID;
                    _prescription[index].Drug_Flag      = model_mz_presmaster.Drug_Flag;
                    _prescription[index].ExecDeptCode   = model_mz_presmaster.ExecDeptCode;
                    _prescription[index].ExecDocCode    = model_mz_presmaster.ExecDocCode;
                    _prescription[index].OldPresID      = model_mz_presmaster.OldID;
                    _prescription[index].PresCostCode   = model_mz_presmaster.PresCostCode;
                    _prescription[index].PrescriptionID = model_mz_presmaster.PresMasterID;
                    _prescription[index].PrescType      = model_mz_presmaster.PresType;
                    _prescription[index].PresDeptCode   = model_mz_presmaster.PresDocCode;
                    _prescription[index].PresDocCode    = model_mz_presmaster.PresDocCode;
                    _prescription[index].Record_Flag    = model_mz_presmaster.Record_Flag;
                    _prescription[index].TicketCode     = model_mz_presmaster.TicketCode;
                    _prescription[index].TicketNum      = model_mz_presmaster.TicketNum;
                    _prescription[index].Total_Fee      = model_mz_presmaster.Total_Fee;
                    _prescription[index].Drug_Flag      = model_mz_presmaster.Drug_Flag;
                    //List<HIS.Model.MZ_PresOrder> orders = BindEntity<MZ_PresOrder>.CreateInstanceDAL( oleDb ).GetListArray( "PresmasterID=" + _prescription[index].PrescriptionID );
                    List <MZ_PresOrder>  orders  = MSAccessDb.GetListArray <MZ_PresOrder>("MZ_PRESORDER", "PresmasterID=" + _prescription[index].PrescriptionID);
                    PrescriptionDetail[] details = new PrescriptionDetail[orders.Count];
                    for (int j = 0; j < orders.Count; j++)
                    {
                        #region 明细
                        details[j].Amount      = orders[j].Amount;
                        details[j].BigitemCode = orders[j].BigItemCode;
                        details[j].Buy_price   = orders[j].Buy_Price;
                        details[j].ComplexId   = orders[j].CaseID;
                        details[j].DetailId    = orders[j].PresOrderID;
                        details[j].ItemId      = orders[j].ItemID;
                        details[j].Itemname    = orders[j].ItemName;
                        details[j].ItemType    = orders[j].ItemType;
                        details[j].Order_Flag  = orders[j].Order_Flag;
                        details[j].PassId      = orders[j].PassID;
                        details[j].PresAmount  = orders[j].PresAmount;
                        details[j].PresctionId = orders[j].PresMasterID;
                        details[j].RelationNum = orders[j].RelationNum;
                        details[j].Sell_price  = orders[j].Sell_Price;
                        details[j].Standard    = orders[j].Standard;
                        details[j].Tolal_Fee   = orders[j].Tolal_Fee;
                        details[j].Unit        = orders[j].Unit;
                        details[j].Comp_Money  = orders[j].Comp_Money;
                        #endregion

                        #region 生成大项目列表
                        if (htStatItems.ContainsKey(orders[j].BigItemCode.Trim()))
                        {
                            InvoiceItem item = (InvoiceItem)htStatItems[orders[j].BigItemCode.Trim( )];
                            item.Cost += orders[j].Tolal_Fee;
                            htStatItems.Remove(orders[j].BigItemCode.Trim( ));
                            htStatItems.Add(item.ItemCode, item);
                        }
                        else
                        {
                            InvoiceItem item = new InvoiceItem( );
                            item.ItemCode = orders[j].BigItemCode.Trim();
                            item.ItemName = GetStatItemNameByStatCode(item.ItemCode);
                            item.Cost     = orders[j].Tolal_Fee;
                            htStatItems.Add(item.ItemCode, item);
                        }
                        #endregion
                    }
                    _prescription[index].PresDetails = details;
                    index++;
                }
                #endregion
                _statitems = new InvoiceItem[htStatItems.Count];
                index      = 0;
                foreach (object obj in htStatItems.Values)
                {
                    _statitems[index] = (InvoiceItem)obj;
                    index++;
                }
                paytype = "";
                if (_cashPay > 0)
                {
                    paytype += " 现金 ";
                }
                if (_posPay > 0)
                {
                    paytype += " POS ";
                }
                if (_villagePay > 0)
                {
                    paytype += " 记账 ";
                }
            }
            catch (Exception err)
            {
                throw new Exception("读取发票信息错误!");
            }
        }
        /// <summary>
        /// 汇总所有人账单
        /// </summary>
        /// <param name="Books"></param>
        /// <returns></returns>
        public static CollectAccountBook CollectAllAccountBook(List <PrivyAccountBook> Books)
        {
            CollectAccountBook     totalBook        = new CollectAccountBook( );
            List <AccountBillInfo> chargeBillinfo   = new List <AccountBillInfo>( );
            List <AccountBillInfo> registerBillinfo = new List <AccountBillInfo>( );
            FundPart  cashPart      = new FundPart( );
            FundPart  favorPart     = new FundPart( );
            FundPart  tallyPart     = new FundPart( );
            Hashtable htInvoiceItem = new Hashtable( );

            foreach (PrivyAccountBook book in Books)
            {
                totalBook.InvoiceItemSumTotal += book.InvoiceItemSumTotal;

                #region 合并收费票据部分
                chargeBillinfo.Add(book.ChargeInvoiceInfo);
                //chargeBillinfo.Count += book.ChargeInvoiceInfo.Count;

                //chargeBillinfo.RefundCount += book.ChargeInvoiceInfo.RefundCount;
                //chargeBillinfo.RefundMoney += book.ChargeInvoiceInfo.RefundMoney;
                //List<Invoice> lstChargeInvoice = new List<Invoice>( );
                //if ( chargeBillinfo.InvoiceList != null )
                //    lstChargeInvoice = chargeBillinfo.InvoiceList.ToList( );
                //if ( book.ChargeInvoiceInfo.InvoiceList != null )
                //{
                //    for ( int i = 0 ; i < book.ChargeInvoiceInfo.InvoiceList.Length ; i++ )
                //        lstChargeInvoice.Add( book.ChargeInvoiceInfo.InvoiceList[i] );
                //}
                //chargeBillinfo.InvoiceList = lstChargeInvoice.ToArray( );
                #endregion

                #region 合并挂号票据部分
                //registerBillinfo.Count += book.RegisterInvoiceInfo.Count;
                ////if ( ( registerBillinfo.StartNumber == "" || registerBillinfo.StartNumber == null ) && book.RegisterInvoiceInfo.StartNumber != "" )
                ////    registerBillinfo.StartNumber = book.RegisterInvoiceInfo.StartNumber;
                ////if ( book.RegisterInvoiceInfo.EndNumber != "" )
                ////    registerBillinfo.EndNumber = book.RegisterInvoiceInfo.EndNumber;

                //registerBillinfo.RefundCount += book.RegisterInvoiceInfo.RefundCount;
                //registerBillinfo.RefundMoney += book.RegisterInvoiceInfo.RefundMoney;
                //List<Invoice> lstRegInvoice = new List<Invoice>( );
                //if ( registerBillinfo.InvoiceList != null )
                //    lstRegInvoice = registerBillinfo.InvoiceList.ToList( );
                //if ( book.RegisterInvoiceInfo.InvoiceList != null )
                //{
                //    for ( int i = 0 ; i < book.RegisterInvoiceInfo.InvoiceList.Length ; i++ )
                //        lstRegInvoice.Add( book.RegisterInvoiceInfo.InvoiceList[i] );
                //}
                //registerBillinfo.InvoiceList = lstRegInvoice.ToArray( );
                registerBillinfo.Add(book.RegisterInvoiceInfo);
                #endregion

                #region 合并发票科目部分
                for (int i = 0; i < book.InvoiceItem.Length; i++)
                {
                    if (htInvoiceItem.ContainsKey(book.InvoiceItem[i].ItemCode))
                    {
                        InvoiceItem invoiceItem = (InvoiceItem)htInvoiceItem[book.InvoiceItem[i].ItemCode];
                        invoiceItem.Cost += book.InvoiceItem[i].Cost;
                        htInvoiceItem.Remove(book.InvoiceItem[i].ItemCode);
                        htInvoiceItem.Add(invoiceItem.ItemCode, invoiceItem);
                    }
                    else
                    {
                        htInvoiceItem.Add(book.InvoiceItem[i].ItemCode, book.InvoiceItem[i]);
                    }
                }
                #endregion

                #region 合并现金部分
                cashPart.TotalMoney += book.CashPart.TotalMoney;
                if (cashPart.Details == null)
                {
                    cashPart.Details = new FundInfo[3];
                }
                for (int i = 0; i < book.CashPart.Details.Length; i++)
                {
                    cashPart.Details[i].BillCount += book.CashPart.Details[i].BillCount;
                    cashPart.Details[i].Money     += book.CashPart.Details[i].Money;
                    cashPart.Details[i].PayCode    = book.CashPart.Details[i].PayCode;
                    cashPart.Details[i].PayName    = book.CashPart.Details[i].PayName;
                }
                #endregion

                #region 合并记账部分
                tallyPart.TotalMoney += book.TallyPart.TotalMoney;
                if (tallyPart.Details == null)
                {
                    tallyPart.Details = new FundInfo[book.TallyPart.Details.Length];
                }

                for (int i = 0; i < book.TallyPart.Details.Length; i++)
                {
                    tallyPart.Details[i].BillCount += book.TallyPart.Details[i].BillCount;
                    tallyPart.Details[i].Money     += book.TallyPart.Details[i].Money;
                    tallyPart.Details[i].PayCode    = book.TallyPart.Details[i].PayCode;
                    tallyPart.Details[i].PayName    = book.TallyPart.Details[i].PayName;
                }
                #endregion

                //合并优惠部分
                favorPart.TotalMoney += book.FavorPart.TotalMoney;
            }

            totalBook.ChargeInvoiceInfo   = chargeBillinfo.ToArray();
            totalBook.RegisterInvoiceInfo = registerBillinfo.ToArray();
            totalBook.CashPart            = cashPart;
            totalBook.TallyPart           = tallyPart;
            totalBook.FavorPart           = favorPart;

            totalBook.InvoiceItem = new InvoiceItem[htInvoiceItem.Count];
            int count = 0;
            foreach (object obj in htInvoiceItem)
            {
                totalBook.InvoiceItem[count] = (InvoiceItem)((DictionaryEntry)obj).Value;
                count++;
            }

            return(totalBook);
        }
        /// <summary>
        /// 获取个人账单
        /// </summary>
        /// <param name="TollCollectorId">收费员ID</param>
        /// <param name="AccountBookId">账单ID</param>
        /// <param name="tbInvoiceList">发票清单</param>
        /// <param name="tbInvoiceDetailList">发票明细列表</param>
        /// <returns></returns>
        public static PrivyAccountBook GetPrivyAccountBook(int TollCollectorId, int AccountBookId,
                                                           DataTable tbAllInvoiceList, DataTable tbAllInvoiceDetailList, DataTable tbAccountList)
        {
            DataTable tbInvoiceList = tbAllInvoiceList.Clone();

            DataRow[] drsInvoiceList = tbAllInvoiceList.Select("AccountId=" + AccountBookId);
            foreach (DataRow dr in drsInvoiceList)
            {
                tbInvoiceList.Rows.Add(dr.ItemArray);
            }

            DataTable tbInvoiceDetailList = tbAllInvoiceDetailList.Clone( );

            DataRow[] drsInvoiceDetailList = tbAllInvoiceDetailList.Select("AccountId=" + AccountBookId);
            foreach (DataRow dr in drsInvoiceDetailList)
            {
                tbInvoiceDetailList.Rows.Add(dr.ItemArray);
            }

            DataRow[] drAccounts = tbAccountList.Select("ACCOUNTID=" + AccountBookId);
            DataRow   drAccount  = null;

            if (drAccounts.Length != 0)
            {
                drAccount = drAccounts[0];
            }

            PrivyAccountBook accountBook = new PrivyAccountBook( );

            if (drAccount != null)
            {
                accountBook.AccountBookDate   = Convert.ToDateTime(drAccount["AccountDate"]);
                accountBook.AccountId         = Convert.ToInt32(drAccount["AccountId"]);
                accountBook.TollCollectorName = DataReader.GetEmployeeNameById(TollCollectorId);
            }
            else
            {
                accountBook.AccountId = 0;
            }
            #region 发票科目明细列表
            Hashtable htInvoiceItems = new Hashtable( );
            for (int i = 0; i < tbInvoiceDetailList.Rows.Count; i++)
            {
                string      mzfp_code   = tbInvoiceDetailList.Rows[i]["mzfp_code"].ToString( ).Trim( );
                string      mzfp_name   = tbInvoiceDetailList.Rows[i]["item_name"].ToString( ).Trim( );
                decimal     item_fee    = Convert.ToDecimal(tbInvoiceDetailList.Rows[i]["total_fee"]);
                InvoiceItem invoiceItem = new InvoiceItem( );
                invoiceItem.ItemCode = mzfp_code;
                invoiceItem.ItemName = mzfp_name;
                invoiceItem.Cost     = item_fee;

                if (htInvoiceItems.ContainsKey(invoiceItem.ItemCode))
                {
                    InvoiceItem _invoiceItem = (InvoiceItem)htInvoiceItems[invoiceItem.ItemCode];
                    htInvoiceItems.Remove(invoiceItem.ItemCode);
                    _invoiceItem.Cost = _invoiceItem.Cost + invoiceItem.Cost;
                    htInvoiceItems.Add(_invoiceItem.ItemCode, _invoiceItem);
                }
                else
                {
                    htInvoiceItems.Add(invoiceItem.ItemCode, invoiceItem);
                }
                accountBook.InvoiceItemSumTotal += invoiceItem.Cost;
            }
            accountBook.InvoiceItem = new InvoiceItem[htInvoiceItems.Count];
            int invoiceItemIndex = 0;
            foreach (object obj in htInvoiceItems)
            {
                accountBook.InvoiceItem[invoiceItemIndex] = (InvoiceItem)((DictionaryEntry)obj).Value;
                invoiceItemIndex++;
            }
            #endregion
            //收费票据信息
            AccountBillInfo chargeBillInfo = GetBillInfo(OPDOperationType.门诊收费, tbInvoiceList);
            chargeBillInfo.ChargeName     = DataReader.GetEmployeeNameById(TollCollectorId);
            accountBook.ChargeInvoiceInfo = chargeBillInfo;
            //挂号票据信息
            AccountBillInfo registerBillInfo = GetBillInfo(OPDOperationType.门诊挂号, tbInvoiceList);
            registerBillInfo.ChargeName     = chargeBillInfo.ChargeName;
            accountBook.RegisterInvoiceInfo = registerBillInfo;
            //优惠部分
            accountBook.FavorPart = GetFavorPart(tbInvoiceList);
            //现金部分
            accountBook.CashPart = GetCashPart(tbInvoiceList, tbInvoiceDetailList);
            //记账部分
            accountBook.TallyPart = GetTallyPart(tbInvoiceList);

            return(accountBook);
        }
示例#5
0
        private ChargeInfo[] _budget(Prescription[] prescriptions)
        {
            int temp_costmasterid = MSAccessDb.GetMaxID("MZ_COSTMASTER", Tables.mz_costmaster.COSTMASTERID);
            int temp_costorderid  = MSAccessDb.GetMaxID("MZ_COSTORDER", Tables.mz_costorder.COSTORDERID);

            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   = DataReader.GetEmployeeNameById(OperatorId); //BindEntity<HIS.Model.BASE_EMPLOYEE_PROPERTY>.CreateInstanceDAL(oleDb).GetModel(OperatorId).NAME ;
                    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<HIS.Model.MZ_CostMaster>.CreateInstanceDAL( oleDb ).Add( chargeBill );
                    chargeBill.CostMasterID = temp_costmasterid;
                    int ret1 = MSAccessDb.InsertRecord(chargeBill, Tables.mz_costmaster.COSTMASTERID);
                    temp_costmasterid++;

                    chargeBill.CostMasterID            = temp_costmasterid;
                    prescriptions[prescCount].ChargeID = temp_costmasterid;
                    //累加每张处方结算信息
                    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);
                            chargeDetail.CostOrderID = temp_costorderid;
                            int ret2 = MSAccessDb.InsertRecord(chargeDetail, Tables.mz_costorder.COSTORDERID);
                            temp_costorderid++;
                            if (ret2 > 0)
                            {
                                InvoiceItem invoice = GetInvoiceByStatCode(chargeDetail.ItemType);
                                invoice.Cost = chargeDetail.Total_Fee;
                                chargeItems.Add(invoice);
                            }
                        }
                        #endregion
                        chargeInfos[prescCount].Items = chargeItems.ToArray( );
                    }
                }
            }
            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);
        }