/// <summary> /// 写入台帐 /// </summary> /// <param name="billMaster">单据头表信息</param> /// <param name="orderList">单据明细信息</param> /// <param name="storeTable">库存处理后的最新药品库存信息</param> public override void WriteAccount(BillMaster billMaster, List <BillOrder> orderList, Hashtable storeTable) { try { int actYear = 0, actMonth = 0; decimal storeNum; int smallUnit; YP_CheckMaster master = (YP_CheckMaster)billMaster; IBaseDAL <YP_Account> accountDao = BindEntity <YP_Account> .CreateInstanceDAL(oleDb, HIS.BLL.Tables.YF_ACCOUNT); AccountFactory.GetQuery(ConfigManager.YF_SYSTEM).GetAccountTime(master.AuditTime, ref actYear, ref actMonth, master.DeptID); foreach (YP_CheckOrder order in orderList) { if (order.CheckNum != order.FactNum) { storeNum = ((YP_StoreNum)(storeTable[order.MakerDicID])).storeNum; smallUnit = ((YP_StoreNum)(storeTable[order.MakerDicID])).smallUnit; YP_Account account = BuildAccount(billMaster, order, storeNum, actYear, actMonth, smallUnit); ComputeFee(account); accountDao.Add(account); } } } catch (Exception error) { throw error; } }
/// <summary> /// 获取当前未结月药品期末台帐信息 /// </summary> /// <param name="actList">台帐信息表</param> /// <param name="billNum">单据号</param> /// <param name="currentTime">当前时间</param> /// <param name="actHisID">月结历史记录ID</param> /// <returns></returns> protected List <YP_Account> GetMonthEndData(List <YP_Account> actList, int billNum, DateTime currentTime, int actHisID) { List <YP_Account> endActList = new List <YP_Account>(); Hashtable makerdicDt = new Hashtable(); foreach (YP_Account act in actList) { if (!makerdicDt.ContainsKey(act.MakerDicID)) { makerdicDt.Add(act.MakerDicID, act); } else if (act.MAccountID > ((YP_Account)(makerdicDt[act.MakerDicID])).MAccountID) { makerdicDt[act.MakerDicID] = act; } } foreach (object makerDicId in makerdicDt) { YP_Account hashValue = (YP_Account)((DictionaryEntry)makerDicId).Value; YP_Account endData = (YP_Account)(hashValue.Clone()); endData.AccountType = 1; endData.DebitFee = 0; endData.DebitNum = 0; endData.LenderNum = 0; endData.LenderFee = 0; endData.BillNum = billNum; endData.RegTime = currentTime; endData.AccountHistoryID = actHisID; endActList.Add(endData); } return(endActList); }
/// <summary> /// 根据单据信息构造台帐信息 /// </summary> /// <param name="billMaster">单据头</param> /// <param name="billOrder">单据明细信息</param> /// <param name="storeNum">库存处理后药品库存信息</param> /// <param name="accountYear">会计年份</param> /// <param name="accountMonth">会计月份</param> /// <param name="smallUnit">基本单位</param> /// <returns>台帐信息</returns> override protected YP_Account BuildAccount(BillMaster billMaster, BillOrder billOrder, decimal storeNum, int accountYear, int accountMonth, int smallUnit) { YP_Account account = new YP_Account(); YP_CheckMaster master = (YP_CheckMaster)billMaster; YP_CheckOrder order = (YP_CheckOrder)billOrder; account.AccountYear = accountYear; account.AccountMonth = accountMonth;; account.AccountType = 2; account.Balance_Flag = 0; account.BillNum = master.BillNum; account.OpType = master.OpType; account.DeptID = master.DeptID; account.LeastUnit = smallUnit; account.UnitNum = order.UnitNum; account.MakerDicID = order.MakerDicID; account.RegTime = master.AuditTime; account.RetailPrice = order.RetailPrice; account.StockPrice = order.TradePrice; account.OrderID = order.CheckOrderID; if (order.CheckNum - order.FactNum > 0) { account.LenderNum = order.CheckNum - order.FactNum; account.LenderFee = Math.Abs(order.CKRetailFee - order.FTRetailFee); } else { account.DebitNum = order.FactNum - order.CheckNum; account.DebitFee = Math.Abs(order.CKRetailFee - order.FTRetailFee); } account.OverNum = storeNum; return(account); }
/// <summary> /// 根据单据信息构造台帐信息 /// </summary> /// <param name="billMaster">单据头</param> /// <param name="billOrder">单据明细信息</param> /// <param name="storeNum">库存处理后药品库存信息</param> /// <param name="accountYear">会计年份</param> /// <param name="accountMonth">会计月份</param> /// <param name="smallUnit">基本单位</param> /// <returns>台帐信息</returns> protected override HIS.Model.YP_Account BuildAccount(HIS.Model.BillMaster billMaster, HIS.Model.BillOrder billOrder, decimal storeNum, int accountYear, int accountMonth, int smallUnit) { YP_InMaster master = (YP_InMaster)billMaster; YP_InOrder order = (YP_InOrder)billOrder; YP_Account account = new YP_Account(); account.AccountYear = accountYear; account.AccountMonth = accountMonth; account.AccountType = 2; account.Balance_Flag = 0; account.BillNum = master.BillNum; account.OpType = master.OpType; account.DeptID = master.DeptID; account.LeastUnit = smallUnit; account.UnitNum = order.UnitNum; account.MakerDicID = order.MakerDicID; account.RegTime = master.AuditTime; account.RetailPrice = order.RetailPrice; account.StockPrice = order.TradePrice; account.OrderID = order.InStorageID; account.DebitFee = order.RetailFee; account.DebitNum = order.InNum; account.OverNum = storeNum; return(account); }
/// <summary> /// 写入台帐 /// </summary> /// <param name="billMaster">单据头表信息</param> /// <param name="orderList">单据明细信息</param> /// <param name="storeTable">库存处理后的最新药品库存信息</param> public override void WriteAccount(BillMaster billMaster, List <BillOrder> orderList, System.Collections.Hashtable storeTable) { try { int actYear = 0, actMonth = 0; YP_InMaster master = (YP_InMaster)billMaster; IBaseDAL <YP_Account> accountDao = BindEntity <YP_Account> .CreateInstanceDAL(oleDb, HIS.BLL.Tables.YK_ACCOUNT); AccountFactory.GetQuery(ConfigManager.YK_SYSTEM).GetAccountTime(master.AuditTime, ref actYear, ref actMonth, master.DeptID); foreach (YP_InOrder order in orderList) { string queryKey = order.MakerDicID.ToString() + order.BatchNum.ToString(); decimal storeNum = ((YP_StoreNum)(storeTable[queryKey])).storeNum; int smallUnit = ((YP_StoreNum)(storeTable[queryKey])).smallUnit; YP_Account account = BuildAccount(billMaster, order, storeNum, actYear, actMonth, smallUnit); ComputeFee(account); accountDao.Add(account); } } catch (Exception error) { throw error; } }
/// <summary> /// 根据单据信息构造台帐信息 /// </summary> /// <param name="billMaster">单据头</param> /// <param name="billOrder">单据明细信息</param> /// <param name="storeNum">库存处理后药品库存信息</param> /// <param name="accountYear">会计年份</param> /// <param name="accountMonth">会计月份</param> /// <param name="smallUnit">基本单位</param> /// <returns>台帐信息</returns> override protected YP_Account BuildAccount(BillMaster billMaster, BillOrder billOrder, decimal storeNum, int accountYear, int accountMonth, int smallUnit) { YP_DRMaster master = (YP_DRMaster)billMaster; YP_DROrder order = (YP_DROrder)billOrder; YP_Account account = new YP_Account(); account.AccountYear = accountYear; account.AccountMonth = accountMonth;; account.AccountType = 2; account.Balance_Flag = 0; account.BillNum = (master.InvoiceNum != 0 ? master.InvoiceNum : Convert.ToInt32(master.InpatientID)); account.OpType = master.OpType; account.DeptID = master.DeptID; account.LeastUnit = smallUnit; account.UnitNum = order.UnitNum; account.MakerDicID = order.MakerDicID; account.RegTime = master.OPTime; account.RetailPrice = order.RetailPrice; account.StockPrice = order.TradePrice; account.OrderID = order.OrderDrugOCID; if (master.InvoiceNum != 0) { account.DebitFee = order.RetailFee * master.RecipeNum; account.DebitNum = order.DrugOCNum * master.RecipeNum; } else { account.DebitFee = order.RetailFee; account.DebitNum = order.DrugOCNum; } account.OverNum = storeNum; return(account); }
/// <summary> /// 月结对账算法 /// </summary> /// <param name="accountList">月末未结算的各药品最后一笔台帐记录</param> protected DataTable CheckAccount(List <YP_Account> accountList) { DataTable wrongDt = base.BuildWrongDataTable(); Hashtable makerdicDt = new Hashtable(); foreach (YP_Account act in accountList) { if (!makerdicDt.ContainsKey(act.MakerDicID)) { makerdicDt.Add(act.MakerDicID, act); } else if (act.MAccountID > ((YP_Account)(makerdicDt[act.MakerDicID])).MAccountID) { makerdicDt[act.MakerDicID] = act; } } foreach (object makerDicId in makerdicDt) { YP_Dal dal = new YP_Dal(); dal._oleDb = oleDb; YP_Account hashValue = (YP_Account)((DictionaryEntry)makerDicId).Value; _makerDicId = hashValue.MakerDicID; List <YP_Account> actList = accountList.FindAll(match); decimal balanceFee = 0; decimal storeFee = dal.YF_GetDrugFee(hashValue.DeptID, hashValue.MakerDicID); decimal storeNum = StoreFactory.GetQuery(ConfigManager.YF_SYSTEM).QueryNum(hashValue.MakerDicID, hashValue.DeptID); foreach (YP_Account act in actList) { if (act.AccountType == 0) { balanceFee = act.BalanceFee; } } foreach (YP_Account act in actList) { balanceFee += act.LenderFee; balanceFee -= act.DebitFee; } if (Convert.ToDecimal(Math.Abs(hashValue.BalanceFee - balanceFee)) > 2 || Convert.ToDecimal(Math.Abs(hashValue.BalanceFee - storeFee)) > 2 || Math.Abs(hashValue.OverNum - storeNum) > 0) { string drugName = DrugBaseDataBll.GetDurgName(hashValue.MakerDicID); DataRow errorRow = wrongDt.NewRow(); errorRow["CHEMNAME"] = drugName; errorRow["MAKERDICID"] = hashValue.MakerDicID; errorRow["WRONGFEE"] = hashValue.BalanceFee - balanceFee; errorRow["STOREWRONGFEE"] = storeFee - hashValue.BalanceFee; errorRow["WRONGNUM"] = storeNum - hashValue.OverNum; errorRow["BALANCEFEE"] = hashValue.BalanceFee; errorRow["BALANCENUM"] = hashValue.OverNum; errorRow["UNIT"] = hashValue.LeastUnit; errorRow["UNITNUM"] = hashValue.UnitNum; wrongDt.Rows.Add(errorRow); } } return(wrongDt); }
/// <summary> /// 账目调整算法 /// </summary> /// <param name="deptId">药剂科室ID</param> /// <param name="wrongAccountDt">错误账目信息表</param> /// <param name="query">账务查询器</param> /// <param name="accountDao">台帐表操作对象</param> protected static void AdjAccount(int deptId, DataTable wrongAccountDt, AccountQuery query, IBaseDAL <YP_Account> accountDao) { DateTime currentTime = XcDate.ServerDateTime; //获取当前会计年月 int currentActYear = 0, currentActMonth = 0; query.GetAccountTime(currentTime, ref currentActYear, ref currentActMonth, deptId); string opType = ""; if (query.GetType().ToString() == "HIS.YP_BLL.YK_AccountQuery") { opType = ConfigManager.OP_YK_MONTHACCOUNT; } else if (query.GetType().ToString() == "HIS.YP_BLL.YF_AccountQuery") { opType = ConfigManager.OP_YF_MONTHACCOUNT; } else { throw new Exception("账目调节系统类型错误"); } oleDb.BeginTransaction(); //按错误药品信息依次写入调整台帐,把账目调平 for (int index = 0; index < wrongAccountDt.Rows.Count; index++) { DataRow currentRow = wrongAccountDt.Rows[index]; YP_Account adjAccount = new YP_Account(); adjAccount.AccountMonth = currentActMonth; adjAccount.AccountType = 3; adjAccount.AccountYear = currentActYear; adjAccount.MakerDicID = Convert.ToInt32(currentRow["MAKERDICID"]); adjAccount.LeastUnit = Convert.ToInt32(currentRow["UNIT"]); adjAccount.UnitNum = Convert.ToInt32(currentRow["UNITNUM"]); if (currentRow["WRONGFEE"] != DBNull.Value) { adjAccount.LenderFee = Convert.ToDecimal(currentRow["WRONGFEE"]) + Convert.ToDecimal(currentRow["STOREWRONGFEE"]); } if (currentRow["WRONGNUM"] != DBNull.Value) { adjAccount.LenderNum = Convert.ToDecimal(currentRow["WRONGNUM"]); } if (currentRow["BALANCEFEE"] != DBNull.Value) { adjAccount.BalanceFee = Convert.ToDecimal(currentRow["BALANCEFEE"]) + Convert.ToDecimal(currentRow["STOREWRONGFEE"]); } if (currentRow["BALANCENUM"] != DBNull.Value) { adjAccount.OverNum = Convert.ToDecimal(currentRow["BALANCENUM"]) + adjAccount.LenderNum; } adjAccount.DeptID = deptId; adjAccount.OpType = opType; adjAccount.RegTime = currentTime; accountDao.Add(adjAccount); } oleDb.CommitTransaction(); }
/// <summary> /// 根据单据信息构造台帐信息 /// </summary> /// <param name="billMaster">单据头</param> /// <param name="billOrder">单据明细信息</param> /// <param name="storeNum">库存处理后药品库存信息</param> /// <param name="accountYear">会计年份</param> /// <param name="accountMonth">会计月份</param> /// <param name="smallUnit">基本单位</param> /// <returns>台帐信息</returns> protected override YP_Account BuildAccount(BillMaster billMaster, BillOrder billOrder, decimal storeNum, int accountYear, int accountMonth, int smallUnit) { YP_InOrder order = (YP_InOrder)billOrder; YP_Account account = base.BuildAccount(billMaster, billOrder, storeNum, accountYear, accountMonth, smallUnit); account.LenderNum = order.InNum; return(account); }
/// <summary> /// 委托函数定义:比较台帐对应药品是否相等 /// </summary> /// <param name="account">台帐信息</param> /// <returns></returns> protected bool match(YP_Account account) { if (account.MakerDicID == _makerDicId) { return(true); } else { return(false); } }
/// <summary> /// 计算余额 /// </summary> /// <param name="account">台帐信息</param> protected override void ComputeFee(YP_Account account) { if (account.OpType == ConfigManager.OP_YF_ADJPRICE) { account.BalanceFee = AccountWriter.YF_ComputeTotalFee(account.RetailPrice, account.OverNum, account.UnitNum); } else { account.BalanceFee = AccountWriter.YK_ComputeTotalFee(account.RetailPrice, account.OverNum); } }
/// <summary> /// 写药房期末台帐 /// </summary> /// <param name="accountHis"></param> /// <param name="billNum"></param> /// <param name="accountDao"></param> /// <param name="deptId"></param> protected override void WriteBeginDateAccount(YP_AccountHis accountHis, int billNum, IBaseDAL <YP_Account> accountDao, int deptId) { YP_Dal ypDal = new YP_Dal(); ypDal._oleDb = oleDb; YP_Account account = new YP_Account(); DataTable beginDataDt = ypDal.YF_Storage_GetListForAccount(deptId); for (int index = 0; index < beginDataDt.Rows.Count; index++) { DataRow dRow = beginDataDt.Rows[index]; if (accountHis.RegTime.Month != 12) { account.AccountMonth = accountHis.RegTime.Month + 1; account.AccountYear = accountHis.RegTime.Year; } else { account.AccountMonth = 1; account.AccountYear++; } account.Balance_Flag = 0; account.BillNum = billNum; account.DeptID = deptId; account.AccountHistoryID = accountHis.AccountHistoryID; account.LeastUnit = Convert.ToInt32(dRow["UNIT"]); account.MakerDicID = Convert.ToInt32(dRow["MAKERDICID"]); account.OpType = ConfigManager.OP_YF_MONTHACCOUNT; account.OrderID = 0; account.RegTime = accountHis.RegTime; account.RetailPrice = Convert.ToDecimal(dRow["RETAILPRICE"]); account.StockPrice = Convert.ToDecimal(dRow["TRADEPRICE"]); account.UnitNum = Convert.ToInt32(dRow["PUNITNUM"]); account.OverNum = Convert.ToInt32(dRow["CURRENTNUM"]); account.BalanceFee = 0; int modNum = (Convert.ToInt32(account.OverNum) % Convert.ToInt32(account.UnitNum)); if (modNum == 0) { account.BalanceFee += (account.OverNum / account.UnitNum) * account.RetailPrice; } else { account.BalanceFee += ((account.OverNum - modNum) / account.UnitNum) * account.RetailPrice; account.BalanceFee += (Convert.ToDecimal(modNum) / Convert.ToDecimal(account.UnitNum)) * account.RetailPrice; } accountDao.Add(account); } }
/// <summary> /// 根据单据信息构造台帐信息 /// </summary> /// <param name="billMaster">单据头</param> /// <param name="billOrder">单据明细信息</param> /// <param name="storeNum">库存处理后药品库存信息</param> /// <param name="accountYear">会计年份</param> /// <param name="accountMonth">会计月份</param> /// <param name="smallUnit">基本单位</param> /// <returns>台帐信息</returns> protected override YP_Account BuildAccount(BillMaster billMaster, BillOrder billOrder, decimal storeNum, int accountYear, int accountMonth, int smallUnit) { YP_InOrder order = (YP_InOrder)billOrder; YP_Account account = base.BuildAccount(billMaster, billOrder, storeNum, accountYear, accountMonth, smallUnit); if (account.OpType != ConfigManager.OP_YF_APPLYIN) { account.LenderNum = Convert.ToInt32(order.InNum); } else { account.LenderNum = Convert.ToInt32(order.InNum * order.UnitNum); } return(account); }
/// <summary> /// 写入台帐 /// </summary> /// <param name="billMaster">单据头表信息</param> /// <param name="orderList">单据明细信息</param> /// <param name="storeTable">库存处理后的最新药品库存信息</param> public override void WriteAccount(BillMaster billMaster, List <BillOrder> orderList, Hashtable storeTable) { try { int actYear = 0, actMonth = 0; int smallUnit = 0; decimal storeNum = 0; YP_DRMaster master = (YP_DRMaster)billMaster; AccountFactory.GetQuery(ConfigManager.YF_SYSTEM).GetAccountTime(master.OPTime, ref actYear, ref actMonth, master.DeptID); foreach (YP_DROrder order in orderList) { storeNum = ((YP_StoreNum)(storeTable[order.OrderRecipeID])).storeNum; smallUnit = ((YP_StoreNum)(storeTable[order.OrderRecipeID])).smallUnit; YP_Account account = BuildAccount(billMaster, order, storeNum, actYear, actMonth, smallUnit); ComputeFee(account); } } catch (Exception error) { throw error; } }
/// <summary> /// 计算余额 /// </summary> /// <param name="account">台帐信息</param> protected override void ComputeFee(YP_Account account) { account.BalanceFee = AccountWriter.YK_ComputeTotalFee(account.RetailPrice, account.OverNum); }
/// <summary> /// 计算余额 /// </summary> /// <param name="account">台帐信息</param> protected abstract void ComputeFee(YP_Account account);
/// <summary> /// 计算余额 /// </summary> /// <param name="account">台帐信息</param> protected override void ComputeFee(YP_Account account) { IBaseDAL <YP_Account> accountDao = BindEntity <YP_Account> .CreateInstanceDAL(oleDb, HIS.BLL.Tables.YF_ACCOUNT); //库存金额 decimal storeFee = 0; decimal adjLenderFee = 0; decimal adjDebitFee = 0; //判断退药期间是否有调价发生 YP_MakerDic makerDic = new YP_MakerDic(); IBaseDAL <YP_MakerDic> makerDao = BindEntity <YP_MakerDic> .CreateInstanceDAL(oleDb); makerDic = makerDao.GetModel(account.MakerDicID); //计算库存金额 storeFee = AccountWriter.YF_ComputeTotalFee(makerDic.RetailPrice, account.OverNum, account.UnitNum); //如果在发/退药期间调价 if (makerDic.RetailPrice != account.RetailPrice) { //调赢 if (makerDic.RetailPrice > account.RetailPrice) { //账务调整 adjLenderFee = (Convert.ToDecimal(account.LenderNum) / Convert.ToDecimal(account.UnitNum)) * (makerDic.RetailPrice - account.RetailPrice); account.BalanceFee = storeFee - adjLenderFee; //写发/退药台帐 accountDao.Add(account); //写调整台帐 account.AccountType = 3; account.DebitNum = 0; account.DebitFee = 0; account.LenderNum = 0; account.LenderFee = adjLenderFee; account.BalanceFee = storeFee; accountDao.Add(account); } //调亏 else { //账务调整 adjDebitFee = (Convert.ToDecimal(account.LenderNum) / Convert.ToDecimal(account.UnitNum)) * (account.RetailPrice - makerDic.RetailPrice); account.BalanceFee = storeFee + adjDebitFee; //写发/退药台帐 accountDao.Add(account); //写调整台帐 account.AccountType = 3; account.DebitNum = 0; account.DebitFee = adjDebitFee; account.LenderNum = 0; account.LenderFee = 0; account.BalanceFee = storeFee; accountDao.Add(account); } } else { account.BalanceFee = storeFee; accountDao.Add(account); } }