/// <summary> /// 得到票据信息 /// </summary> /// <param name="kind">票据类型</param> /// <param name="tbAllInvoiceList">所有的发票列表</param> /// <returns>根据票据类型返回的票据信息</returns> private static AccountBillInfo GetBillInfo(OPDOperationType kind, DataTable tbAllInvoiceList) { int flag = (int)kind; DataTable tbInvoice = tbAllInvoiceList.Clone( ); DataRow[] drsInvoice = tbAllInvoiceList.Select("hang_flag=" + flag, "costdate asc"); for (int i = 0; i < drsInvoice.Length; i++) { tbInvoice.Rows.Add(drsInvoice[i].ItemArray); } AccountBillInfo billInfo = new AccountBillInfo( ); if (drsInvoice.Length > 0) { DataRow[] drs = tbInvoice.Select("record_flag in (0,1)"); billInfo.Count = drs.Length; if (drs.Length > 0) { billInfo.StartNumber = drs[0]["ticketnum"].ToString( ).Trim( ); billInfo.EndNumber = drs[drs.Length - 1]["ticketnum"].ToString( ).Trim( ); } //构造发票清单 billInfo.InvoiceList = new Invoice[drs.Length]; for (int i = 0; i < drs.Length; i++) { billInfo.InvoiceList[i] = new Invoice( ); billInfo.InvoiceList[i].InvoiceNo = drs[i]["ticketnum"].ToString( ).Trim( ); billInfo.InvoiceList[i].PatientName = DataReader.GetPatientTypeNameByCode(drs[i]["meditype"].ToString( ).Trim( )); billInfo.InvoiceList[i].TotalPay = Convert.ToDecimal(drs[i]["total_fee"]); billInfo.InvoiceList[i].CashPay = Convert.ToDecimal(drs[i]["money_fee"]); billInfo.InvoiceList[i].PosPay = Convert.ToDecimal(drs[i]["pos_fee"]); billInfo.InvoiceList[i].VillagePay = Convert.ToDecimal(drs[i]["village_fee"]); billInfo.InvoiceList[i].SelfTally = Convert.ToDecimal(drs[i]["self_tally"]); billInfo.InvoiceList[i].FavorPay = Convert.ToDecimal(drs[i]["favor_fee"]); billInfo.InvoiceList[i].ChargeDate = Convert.ToDateTime(drs[i]["costdate"]); billInfo.InvoiceList[i].RecordFlag = Convert.ToInt32(drs[i]["record_flag"]); } //退票 DataRow[] drsRefund = tbInvoice.Select("record_flag = 2 "); billInfo.RefundCount = drsRefund.Length; for (int i = 0; i < drsRefund.Length; i++) { billInfo.RefundMoney += Math.Abs(Convert.ToDecimal(drsRefund[i]["total_fee"])); } billInfo.Useless = new string[] { "" }; } else { billInfo.Count = 0; billInfo.StartNumber = ""; billInfo.EndNumber = ""; billInfo.RefundMoney = 0; billInfo.RefundCount = 0; billInfo.Useless = new string[] { "" }; } return(billInfo); }
/// <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); }
/// <summary> /// 汇总个人账单 /// </summary> /// <param name="Books"></param> /// <returns></returns> public static PrivyAccountBook CollectPrivyAccountBook(List <PrivyAccountBook> Books) { PrivyAccountBook totalBook = new PrivyAccountBook( ); AccountBillInfo chargeBillinfo = new AccountBillInfo( ); AccountBillInfo registerBillinfo = new 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.Count += book.ChargeInvoiceInfo.Count; if ((chargeBillinfo.StartNumber == "" || chargeBillinfo.StartNumber == null) && book.ChargeInvoiceInfo.StartNumber != "") { chargeBillinfo.StartNumber = book.ChargeInvoiceInfo.StartNumber; } if (book.ChargeInvoiceInfo.EndNumber != "") { chargeBillinfo.EndNumber = book.ChargeInvoiceInfo.EndNumber; } chargeBillinfo.RefundCount += book.ChargeInvoiceInfo.RefundCount; chargeBillinfo.RefundMoney += book.ChargeInvoiceInfo.RefundMoney; chargeBillinfo.ChargeName = book.ChargeInvoiceInfo.ChargeName; 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; registerBillinfo.ChargeName = book.RegisterInvoiceInfo.ChargeName; 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( ); #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; totalBook.RegisterInvoiceInfo = registerBillinfo; 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); }