/// <summary> /// 台账写入--批次发退药价格差额台账 /// </summary> /// <param name="billHead">发药单表头</param> /// <param name="billDetails">发药单明细</param> /// <param name="storeParam">库存参数</param> /// <param name="batchAllot">批次</param> public void WriteAccount(DS_OPDispHead billHead, DS_OPDispDetail billDetails, StoreParam storeParam, DGBatchAllot batchAllot) { int actYear; int actMonth; string errMsg; if (!GetAccountTime(billHead.DeptID, out errMsg, out actYear, out actMonth)) { throw new Exception(errMsg); } DS_Account account = NewObject <DS_Account>(); account.BalanceYear = actYear; account.BalanceMonth = actMonth; account.AccountType = 3;//药房 account.BalanceFlag = 0; account.BatchNO = billDetails.BatchNO; account.BusiType = billHead.BusiType; account.CTypeID = billDetails.CTypeID; account.DeptID = billDetails.DeptID; account.DetailID = billDetails.DispDetailID; account.DrugID = billDetails.DrugID; account.UnitID = billDetails.UnitID; account.UnitName = billDetails.UnitName; account.RegTime = DateTime.Now; //盘盈 借方 //盘亏 贷方 if (storeParam.RetailPrice < billDetails.RetailPrice) { //该批次大于处方零售价写入 贷方 account.StockPrice = billDetails.StockPrice; account.RetailPrice = billDetails.RetailPrice; //发生调整时,数量为0,只调价格 account.DebitAmount = 0; //Math.Abs(billDetails.DispAmount); account.DebitRetailFee = GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, billDetails.RetailPrice, billHead.RecipeAmount) - GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, storeParam.RetailPrice, billHead.RecipeAmount); account.DebitStockFee = GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, billDetails.StockPrice, billHead.RecipeAmount) - GetFee(Math.Abs(billDetails.DispAmount), billDetails.UnitAmount, storeParam.StockPrice, billHead.RecipeAmount); account.OverAmount = batchAllot.StoreAmount; account.OverRetailFee = batchAllot.StoreAmount * (account.RetailPrice / batchAllot.UnitAmount); account.OverStockFee = batchAllot.StoreAmount * (account.StockPrice / batchAllot.UnitAmount); } else { //发药 借方 account.StockPrice = billDetails.StockPrice; account.RetailPrice = billDetails.RetailPrice; //发生调整时,数量为0,只调价格 account.LendAmount = 0;//billDetails.DispAmount; account.LendRetailFee = GetFee(billDetails.DispAmount, billDetails.UnitAmount, storeParam.RetailPrice, billHead.RecipeAmount) - GetFee(billDetails.DispAmount, billDetails.UnitAmount, billDetails.RetailPrice, billHead.RecipeAmount); account.LendStockFee = GetFee(billDetails.DispAmount, billDetails.UnitAmount, storeParam.StockPrice, billHead.RecipeAmount) - GetFee(billDetails.DispAmount, billDetails.UnitAmount, billDetails.StockPrice, billHead.RecipeAmount); account.OverAmount = batchAllot.StoreAmount; account.OverRetailFee = batchAllot.StoreAmount * (account.RetailPrice / batchAllot.UnitAmount); account.OverStockFee = batchAllot.StoreAmount * (account.StockPrice / batchAllot.UnitAmount); } account.save(); }
/// <summary> /// 台账写入 /// </summary> /// <typeparam name="THead">药房盘点单表头模板</typeparam> /// <typeparam name="TDetail">药房盘点单明细模板</typeparam> /// <param name="billHead">药房盘点单头</param> /// <param name="billDetails">药房盘点单明细</param> /// <param name="batchAllot">批次分类对象</param> public void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGBatchAllot batchAllot) { DS_AuditDetail detail = billDetails as DS_AuditDetail; DS_AuditHead head = billHead as DS_AuditHead; int actYear; int actMonth; string errMsg; if (!GetAccountTime(head.DeptID, out errMsg, out actYear, out actMonth)) { throw new Exception(errMsg); } DS_Account account = NewObject <DS_Account>(); account.BalanceYear = actYear; account.BalanceMonth = actMonth; account.AccountType = 0; account.BalanceFlag = 0; account.RegTime = System.DateTime.Now; account.BillNO = head.BillNO; account.BatchNO = detail.BatchNO; account.BusiType = head.BusiType; account.CTypeID = detail.CTypeID; account.DeptID = head.DeptID; account.DetailID = detail.AuditDetailID; account.DrugID = detail.DrugID; account.UnitID = detail.UnitID; account.UnitName = detail.UnitName; //盘盈 借方 //盘亏 贷方 if (detail.FactAmount - detail.ActAmount > 0) { //借方 account.StockPrice = detail.StockPrice; account.RetailPrice = detail.RetailPrice; account.LendAmount = detail.FactAmount - detail.ActAmount; account.LendRetailFee = detail.FactRetailFee - detail.ActRetailFee; account.LendStockFee = detail.FactStockFee - detail.ActStockFee; account.OverAmount = batchAllot.StoreAmount; account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount); account.OverStockFee = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount); } else { //贷方 account.StockPrice = detail.StockPrice; account.RetailPrice = detail.RetailPrice; account.DebitAmount = detail.ActAmount - detail.FactAmount; account.DebitRetailFee = detail.ActRetailFee - detail.FactRetailFee; account.DebitStockFee = detail.ActStockFee - detail.FactStockFee; account.OverAmount = batchAllot.StoreAmount; account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount); account.OverStockFee = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount); } account.save(); }
/// <summary> /// 台账写入 /// </summary> /// <typeparam name="THead">药房入库单表头模板</typeparam> /// <typeparam name="TDetail">药房入库单明细模板</typeparam> /// <param name="billHead">药房入库单表头</param> /// <param name="billDetails">药房入库单明细</param> /// <param name="storeResult">库存处理结果</param> /// <param name="packAmount">包装系数</param> public void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult, decimal packAmount) { //1、构建台账表实体; //2、根据台账表内容填写相应的信息; //3、保存台账表 DS_InStoreDetail detail = billDetails as DS_InStoreDetail; DS_InstoreHead head = billHead as DS_InstoreHead; int actYear; int actMonth; string errMsg; if (!GetAccountTime(head.DeptID, out errMsg, out actYear, out actMonth)) { throw new Exception(errMsg); } packAmount = packAmount > 0 ? packAmount : GetPackAmount(detail.DrugID); DS_Account account = NewObject <DS_Account>(); account.BalanceYear = actYear; account.BalanceMonth = actMonth; account.AccountType = 0; account.BalanceFlag = 0; account.BillNO = head.BillNO; account.BatchNO = detail.BatchNO; account.BusiType = head.BusiType; account.CTypeID = detail.CTypeID; account.DeptID = head.DeptID; account.DetailID = detail.InDetailID; account.DrugID = detail.DrugID; account.UnitID = detail.UnitID; account.UnitName = detail.UnitName; account.RegTime = System.DateTime.Now; account.UnitAmount = Convert.ToInt32(packAmount); if (head.BusiType == DGConstant.OP_DS_RETURNSOTRE) { account.StockPrice = storeResult.BatchAllot[0].StockPrice; account.RetailPrice = storeResult.BatchAllot[0].RetailPrice; account.LendAmount = detail.Amount; account.LendRetailFee = detail.Amount * (account.RetailPrice / packAmount); account.LendStockFee = detail.Amount * (account.StockPrice / packAmount); } else { account.StockPrice = detail.StockPrice; account.RetailPrice = detail.RetailPrice; account.LendAmount = detail.Amount; account.LendRetailFee = detail.Amount * (account.RetailPrice / packAmount); account.LendStockFee = detail.Amount * (account.StockPrice / packAmount); } account.OverAmount = storeResult.BatchAllot[0].StoreAmount; account.OverStockFee = storeResult.BatchAllot[0].StoreAmount * (account.StockPrice / packAmount); account.OverRetailFee = storeResult.BatchAllot[0].StoreAmount * (account.RetailPrice / packAmount); account.save(); }
private void LoadAccountCallback(string error, DS_Account data) { if (null != error) { LogSys.Log(LOG_TYPE.INFO, "Load account : {0} failed: {1}", Account, error); Next("CreateNickName", billing_player_); } else { LogSys.Log(LOG_TYPE.INFO, "Load aoount : {0} success: {1}", Account, data.Guid); LoadUserInfo(data.Guid); } }
/// <summary> /// 台账写入--批次发退药数量台账 /// </summary> /// <param name="billHead">发药单表头</param> /// <param name="billDetails">发药单明细</param> /// <param name="batchAllot">批次</param> /// <param name="refundFlag">退药标志</param> /// <param name="storeParam">库存处理参数</param> public void WriteAccount(DS_OPDispHead billHead, DS_OPDispDetail billDetails, DGBatchAllot batchAllot, int refundFlag, StoreParam storeParam) { int actYear; int actMonth; string errMsg; if (!GetAccountTime(billHead.DeptID, out errMsg, out actYear, out actMonth)) { throw new Exception(errMsg); } DS_Account account = NewObject <DS_Account>(); account.BalanceYear = actYear; account.BalanceMonth = actMonth; account.AccountType = 0;//药房 account.BalanceFlag = 0; account.BatchNO = billDetails.BatchNO; account.BusiType = billHead.BusiType; account.CTypeID = billDetails.CTypeID; account.DeptID = billDetails.DeptID; account.DetailID = billDetails.DispDetailID; account.DrugID = billDetails.DrugID; account.UnitID = billDetails.UnitID; account.UnitName = billDetails.UnitName; account.RegTime = DateTime.Now; account.UnitAmount = batchAllot.UnitAmount; //盘盈 借方 //盘亏 贷方 if (billDetails.RetFlag == 1 || refundFlag == 1) { //退药 借方 account.StockPrice = storeParam.StockPrice; account.RetailPrice = storeParam.RetailPrice; account.LendAmount = Math.Abs(billDetails.DispAmount); account.LendRetailFee = batchAllot.DispRetailFee; account.LendStockFee = batchAllot.DispStockFee; account.OverAmount = batchAllot.StoreAmount; //当药品批次价格和实际价格不一致时,退药按实际价格退 if (storeParam.RetailPrice.Equals(batchAllot.RetailPrice) == false) { account.OverRetailFee = batchAllot.StoreAmount * (storeParam.RetailPrice / storeParam.UnitAmount); } else { account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount); } if (storeParam.StockPrice.Equals(batchAllot.StockPrice) == false) { account.OverStockFee = batchAllot.StoreAmount * (storeParam.StockPrice / storeParam.UnitAmount); } else { account.OverStockFee = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount); } } else { //发药 贷方 account.StockPrice = storeParam.StockPrice; account.RetailPrice = storeParam.RetailPrice; account.DebitAmount = billDetails.DispAmount; account.DebitRetailFee = batchAllot.DispRetailFee; account.DebitStockFee = batchAllot.DispStockFee; account.OverAmount = batchAllot.StoreAmount; //当发药时价格和实际批次价格不一致时,剩余价格等于加上要发出的数量*调价后的金额减去发出药量的总金额(发出药量是按批次表原有的价格算的) if (storeParam.RetailPrice.Equals(batchAllot.RetailPrice) == false) { account.OverRetailFee = ((batchAllot.StoreAmount + billDetails.DispAmount) * (batchAllot.RetailPrice / batchAllot.UnitAmount)) - batchAllot.DispRetailFee; } else { account.OverRetailFee = batchAllot.StoreAmount * (batchAllot.RetailPrice / batchAllot.UnitAmount); } if (storeParam.StockPrice.Equals(batchAllot.StockPrice) == false) { account.OverStockFee = ((batchAllot.StoreAmount + billDetails.DispAmount) * (batchAllot.StockPrice / batchAllot.UnitAmount)) - batchAllot.DispStockFee; } else { account.OverStockFee = batchAllot.StoreAmount * (batchAllot.StockPrice / batchAllot.UnitAmount); } } account.save(); }
/// <summary> /// 保存台账 /// </summary> /// <typeparam name="TBatch">批次类型</typeparam> /// <param name="batchs">批次对象</param> /// <param name="currentDetail">当前调价明细单对象</param> public void SaveAccout <TBatch>(TBatch batchs, DG_AdjDetail currentDetail) { string errMsg = string.Empty; int actYear = 0; int actMonth = 0; int actId = 0; if (batchs.GetType() == typeof(DW_Batch)) { DW_Batch batch = batchs as DW_Batch; currentDetail.AdjAmount = batch.BatchAmount; batch.RetailPrice = currentDetail.NewRetailPrice; this.BindDb(batch); int dwresult = batch.save(); if (dwresult > 0) { this.BindDb(currentDetail); int detailresult = currentDetail.save(); if (detailresult > 0) { if (!GetDWAccountTime(batch.DeptID, out errMsg, out actYear, out actMonth, out actId)) { throw new Exception(errMsg); } DW_Account newaccount = new DW_Account(); newaccount.AccountType = 0; newaccount.BalanceFlag = 0; newaccount.BalanceID = actId; newaccount.BalanceMonth = actMonth; newaccount.BalanceYear = actYear; newaccount.BatchNO = batch.BatchNO; newaccount.BillNO = currentDetail.BillNO; newaccount.BusiType = DGConstant.OP_DW_ADJPRICE; newaccount.CTypeID = NewDao <IDWDao>().GetTypeId(batch.BatchNO, batch.DrugID); newaccount.LendRetailFee = currentDetail.NewRetailPrice > currentDetail.OldRetailPrice ? (currentDetail.NewRetailPrice - currentDetail.OldRetailPrice) * currentDetail.AdjAmount : 0; newaccount.DebitRetailFee = currentDetail.NewRetailPrice < currentDetail.OldRetailPrice ? (currentDetail.OldRetailPrice - currentDetail.NewRetailPrice) * currentDetail.AdjAmount : 0; newaccount.OverRetailFee = currentDetail.NewRetailPrice * currentDetail.AdjAmount; newaccount.DebitAmount = 0; newaccount.LendAmount = 0; newaccount.OverAmount = currentDetail.AdjAmount; newaccount.OverStockFee = batch.StockPrice * currentDetail.AdjAmount; newaccount.DebitStockFee = 0; newaccount.LendStockFee = 0; newaccount.DeptID = batch.DeptID; newaccount.DetailID = detailresult; newaccount.DrugID = batch.DrugID; newaccount.UnitName = currentDetail.PackUnitName; newaccount.UnitID = currentDetail.UnitID; newaccount.StockPrice = batch.StockPrice; newaccount.RegTime = DateTime.Now; newaccount.RetailPrice = currentDetail.NewRetailPrice; this.BindDb(newaccount); newaccount.save(); } } } else { DS_Batch batch = batchs as DS_Batch; currentDetail.AdjAmount = batch.BatchAmount; batch.RetailPrice = currentDetail.NewRetailPrice; this.BindDb(batch); int dsresult = batch.save(); if (dsresult > 0) { this.BindDb(currentDetail); int detailresult = currentDetail.save(); if (detailresult > 0) { if (!GetDSAccountTime(batch.DeptID, out errMsg, out actYear, out actMonth, out actId)) { throw new Exception(errMsg); } DS_Account newaccount = new DS_Account(); newaccount.AccountType = 0; newaccount.BalanceFlag = 0; newaccount.BalanceID = actId; newaccount.BalanceMonth = actMonth; newaccount.BalanceYear = actYear; newaccount.BatchNO = batch.BatchNO; newaccount.BillNO = currentDetail.BillNO; newaccount.BusiType = DGConstant.OP_DS_ADJPRICE; newaccount.CTypeID = NewDao <IDSDao>().GetTypeId(batch.BatchNO, batch.DrugID); newaccount.LendRetailFee = (currentDetail.NewRetailPrice > currentDetail.OldRetailPrice) ? ((currentDetail.NewRetailPrice - currentDetail.OldRetailPrice) * (currentDetail.AdjAmount / batch.UnitAmount)) : 0; newaccount.DebitRetailFee = (currentDetail.NewRetailPrice < currentDetail.OldRetailPrice) ? ((currentDetail.OldRetailPrice - currentDetail.NewRetailPrice) * (currentDetail.AdjAmount / batch.UnitAmount)) : 0; newaccount.OverRetailFee = (currentDetail.NewRetailPrice * (currentDetail.AdjAmount / batch.UnitAmount)); newaccount.DebitAmount = 0; newaccount.LendAmount = 0; newaccount.OverAmount = currentDetail.AdjAmount; newaccount.OverStockFee = (batch.StockPrice * (currentDetail.AdjAmount / batch.UnitAmount)); newaccount.DebitStockFee = 0; newaccount.LendStockFee = 0; newaccount.DeptID = batch.DeptID; newaccount.DetailID = detailresult; newaccount.DrugID = batch.DrugID; newaccount.UnitName = currentDetail.UnitName; newaccount.UnitID = currentDetail.UnitID; newaccount.StockPrice = batch.StockPrice; newaccount.RegTime = DateTime.Now; newaccount.RetailPrice = currentDetail.NewRetailPrice; this.BindDb(newaccount); newaccount.save(); } } } }
///============================================================================================== /// 只能在本线程调用的方法。 ///============================================================================================== private void HandleLoadGMPAccount(uint msgId, string key, MyAction <DSLoadResult, string, IMessage> cb) { string error = null; IMessage data = null; Type dataType = MessageMapping.Query(msgId); try { DbThreadManager.Instance.LoadActionQueue.QueueAction(() => { GMP_Account.Builder dataAccountBuilder = GMP_Account.CreateBuilder(); DS_Account dataAccountBasic = DataLoadImpl.LoadSingleRow(typeof(DS_Account), key) as DS_Account; if (dataAccountBasic != null) { dataAccountBuilder.SetAccount(dataAccountBasic.Account); dataAccountBuilder.SetAccountBasic(dataAccountBasic); } else { error = string.Format("GMServer Load from Database MISS: key:({0}), data({1})", key, dataType.Name); cb(DSLoadResult.NotFound, error, null); LogSys.Log(LOG_TYPE.INFO, error); return; } List <DS_UserInfo> dataUserList = new List <DS_UserInfo>(); if (dataAccountBasic.UserGuid1 > 0) { DS_UserInfo dataUser = DataLoadImpl.LoadSingleRow(typeof(DS_UserInfo), dataAccountBasic.UserGuid1.ToString()) as DS_UserInfo; if (dataUser != null) { dataUserList.Add(dataUser); } } if (dataAccountBasic.UserGuid2 > 0) { DS_UserInfo dataUser = DataLoadImpl.LoadSingleRow(typeof(DS_UserInfo), dataAccountBasic.UserGuid2.ToString()) as DS_UserInfo; if (dataUser != null) { dataUserList.Add(dataUser); } } if (dataAccountBasic.UserGuid3 > 0) { DS_UserInfo dataUser = DataLoadImpl.LoadSingleRow(typeof(DS_UserInfo), dataAccountBasic.UserGuid3.ToString()) as DS_UserInfo; if (dataUser != null) { dataUserList.Add(dataUser); } } foreach (var dataUser in dataUserList) { dataAccountBuilder.UserListList.Add(dataUser as DS_UserInfo); } data = dataAccountBuilder.Build(); cb(DSLoadResult.Success, null, data); LogSys.Log(LOG_TYPE.DEBUG, "GMServer Load from Database: key:({0}), data({1})", key, dataType.Name); }); } catch (Exception e) { error = e.Message; cb(DSLoadResult.PostError, error, data); LogSys.Log(LOG_TYPE.ERROR, "GMServer Load from Database ERROR: key:({0}), data({1}), error({2})", key, dataType.Name, error); return; } }