/// <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> /// <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(); }
public ServiceResponseData OPDisp() { List <DS_OPDispHead> dispHead = new List <DS_OPDispHead>(); DataTable dtFeeHead = requestData.GetData <DataTable>(0); int sendEmpID = requestData.GetData <int>(1); string sendEmpName = requestData.GetData <string>(2); int deptId = requestData.GetData <int>(3); string feeHeadIds = "("; foreach (DataRow row in dtFeeHead.Rows) { DS_OPDispHead modelHead = new DS_OPDispHead(); DrugStoreManagement model = NewObject <DrugStoreManagement>(); if (model.HasRefund(row["InvoiceNO"].ToString())) { throw new Exception("本张单据不能发药,存在退费记录,请进行退费操作"); } modelHead.BillNO = 0; modelHead.BusiType = DGConstant.OP_DS_OPDISPENSE; modelHead.RetailFee = Convert.ToDecimal(row["TotalFee"]); modelHead.PatListID = Convert.ToInt32(row["PatListID"]); modelHead.PatName = row["PatName"].ToString(); modelHead.PatSex = row["PatSex"].ToString(); modelHead.Diagnose = row["DiseaseName"].ToString(); modelHead.PatAge = row["Age"].ToString(); modelHead.PresDocID = Convert.ToInt32(row["PresEmpID"]); modelHead.PresDocName = row["PresEmpName"].ToString(); modelHead.PresDeptID = Convert.ToInt32(row["PresDeptID"]); modelHead.PresDeptName = row["PresDeptName"].ToString(); modelHead.DispenserID = sendEmpID; modelHead.DispenserName = sendEmpName; modelHead.PharmacistID = sendEmpID; modelHead.PharmacistName = sendEmpName; modelHead.RefundFlag = 0;//发药0退药1 modelHead.DispTime = System.DateTime.Now; modelHead.FeeNO = row["FeeNo"].ToString(); modelHead.InvoiceNO = row["InvoiceNO"].ToString(); modelHead.ChargeTime = Convert.ToDateTime(row["ChargeDate"]); modelHead.ChargeEmpID = Convert.ToInt32(row["ChargeEmpID"]); modelHead.ChargeEmpName = row["ChargeEmpName"].ToString(); modelHead.FeeItemHeadID = Convert.ToInt32(row["CostHeadID"]); modelHead.RecipeID = Convert.ToInt32(row["FeeItemHeadID"]); modelHead.RecipeType = row["PresType"].ToString(); modelHead.RecipeAmount = Convert.ToInt32(row["PresAmount"]); modelHead.DeptID = deptId; dispHead.Add(modelHead); feeHeadIds += row["FeeItemHeadID"].ToString() + ","; } feeHeadIds = feeHeadIds.Substring(0, feeHeadIds.Length - 1) + ")"; //获取该结算单所有明细记录 List <DS_OPDispDetail> dispDetail = ConvertFeeDetailModel(feeHeadIds, deptId); OPDispBill iProcess = NewObject <OPDispBill>(); DGBillResult rtn = new DGBillResult(); try { oleDb.BeginTransaction(); rtn = iProcess.OPDisp(dispHead, dispDetail, sendEmpID); if (rtn.Result == 0) { oleDb.CommitTransaction(); } else { oleDb.RollbackTransaction(); } responseData.AddData(rtn); } catch (Exception error) { oleDb.RollbackTransaction(); rtn.ErrMsg = error.Message; rtn.Result = 2; responseData.AddData(rtn); } return(responseData); }
/// <summary> /// 获取头表信息 /// </summary> /// <param name="opType">业务类型</param> /// <param name="deptId">科室Id</param> /// <param name="detailID">明细Id</param> /// <returns>头表信息</returns> public BillMasterShower GetBillHeadInfo(string opType, int deptId, int detailID) { BillMasterShower shower = new BillMasterShower(); switch (opType) { case "011": //采购入库 case "012": //期初入库 case "013": //流通入库 DS_InStoreDetail inStoreDetail = (DS_InStoreDetail)NewObject <DS_InStoreDetail>().getmodel(detailID); if (inStoreDetail != null) { DS_InstoreHead instoreHead = (DS_InstoreHead)NewObject <DS_InstoreHead>().getmodel(inStoreDetail.InHeadID); if (instoreHead != null) { shower.RegTime = instoreHead.RegTime; shower.AuditTime = instoreHead.AuditTime; shower.BillNo = instoreHead.BillNO.ToString(); shower.RelationPeopleNo = instoreHead.OpEmpID.ToString(); shower.RelationPeople = instoreHead.OpEmpName; shower.RelationUnit = instoreHead.SupplierName; shower.RetailFee = instoreHead.RetailFee; shower.StockFee = instoreHead.StockFee; shower.OpType = GetBusiTypeName(opType); shower.RegPeople = instoreHead.RegEmpName; shower.Remark = instoreHead.Remark; } } break; case "021": //内耗出库 case "022": //报损出库 DS_OutStoreDetail outStoreDetail = (DS_OutStoreDetail)NewObject <DS_OutStoreDetail>().getmodel(detailID); if (outStoreDetail != null) { DS_OutStoreHead outStoreHead = (DS_OutStoreHead)NewObject <DS_OutStoreHead>().getmodel(outStoreDetail.OutHeadID); if (outStoreDetail != null) { shower.RegTime = outStoreHead.RegTime; shower.AuditTime = outStoreHead.AuditTime; shower.BillNo = outStoreHead.BillNO.ToString(); shower.RelationPeopleNo = "暂无"; shower.RelationPeople = "暂无"; shower.RelationUnit = outStoreHead.ToDeptName; shower.RetailFee = outStoreHead.RetailFee; shower.StockFee = outStoreHead.StockFee; shower.OpType = GetBusiTypeName(opType); shower.RegPeople = outStoreHead.RegEmpName; shower.Remark = outStoreHead.Remark; } } break; case "031": //门诊发药 case "032": //门诊退药 DS_OPDispDetail oPDispDetail = (DS_OPDispDetail)NewObject <DS_OPDispDetail>().getmodel(detailID); if (oPDispDetail != null) { DS_OPDispHead oPDispHead = (DS_OPDispHead)NewObject <DS_OPDispHead>().getmodel(oPDispDetail.DispHeadID); if (oPDispHead != null) { shower.RegTime = oPDispHead.DispTime; shower.AuditTime = oPDispHead.DispTime; shower.BillNo = oPDispHead.BillNO.ToString(); shower.RelationPeopleNo = "暂无"; shower.RelationPeople = "暂无"; shower.RelationUnit = oPDispHead.PresDeptName; shower.RetailFee = oPDispHead.RetailFee; shower.StockFee = 0; shower.OpType = GetBusiTypeName(opType); shower.RegPeople = oPDispHead.PharmacistName; shower.Remark = string.Empty; } } break; case "033": //住院发药 DS_IPDispDetail iPDispDetail = (DS_IPDispDetail)NewObject <DS_IPDispDetail>().getmodel(detailID); if (iPDispDetail != null) { DS_IPDispHead iPDispHead = (DS_IPDispHead)NewObject <DS_IPDispHead>().getmodel(iPDispDetail.DispHeadID); if (iPDispHead != null) { shower.RegTime = iPDispHead.DispTime; shower.AuditTime = iPDispHead.DispTime; shower.BillNo = iPDispHead.BillNO.ToString(); shower.RelationPeopleNo = "暂无"; shower.RelationPeople = "暂无"; shower.RelationUnit = GetDeptName(iPDispHead.DeptID); shower.RetailFee = iPDispHead.RetailFee; shower.StockFee = 0; shower.OpType = GetBusiTypeName(opType); shower.RegPeople = GetEmpName(iPDispHead.PharmacistID); shower.Remark = string.Empty; } } break; case "042": //盘点审核 DS_AuditDetail auditDetail = (DS_AuditDetail)NewObject <DS_AuditDetail>().getmodel(detailID); if (auditDetail != null) { DS_AuditHead auditHead = (DS_AuditHead)NewObject <DS_AuditHead>().getmodel(auditDetail.AuditHeadID); if (auditHead != null) { shower.RegTime = auditHead.AuditTime; shower.AuditTime = auditHead.AuditTime; shower.BillNo = auditHead.BillNO.ToString(); shower.RelationPeopleNo = auditHead.EmpID.ToString(); shower.RelationPeople = auditHead.EmpName; shower.RelationUnit = GetDeptName(auditHead.DeptID); shower.RetailFee = auditHead.CheckRetailFee; shower.StockFee = auditHead.CheckStockFee; shower.OpType = GetBusiTypeName(opType); shower.RegPeople = auditHead.EmpName; shower.Remark = string.Empty; } } break; case "051": //药房调价 DG_AdjDetail adjDetail = (DG_AdjDetail)NewObject <DG_AdjDetail>().getmodel(detailID); if (adjDetail != null) { DG_AdjHead adjHead = (DG_AdjHead)NewObject <DG_AdjHead>().getmodel(adjDetail.AdjHeadID); if (adjHead != null) { shower.RegTime = adjHead.RegTime; shower.AuditTime = adjHead.ExecTime; shower.BillNo = adjHead.BillNO.ToString(); shower.RelationPeopleNo = adjHead.RegEmpID.ToString(); shower.RelationPeople = GetEmpName(adjHead.RegEmpID); shower.RelationUnit = GetDeptName(adjHead.DeptID); shower.RetailFee = 0; shower.StockFee = 0; shower.OpType = GetBusiTypeName(opType); shower.RegPeople = GetEmpName(adjHead.RegEmpID); shower.Remark = adjHead.Remark; } } break; } return(shower); }
public ServiceResponseData OPRefund() { List <DS_OPDispHead> dispHead = new List <DS_OPDispHead>(); DataTable dtRefund = requestData.GetData <DataTable>(0); int sendEmpID = requestData.GetData <int>(1); string sendEmpName = requestData.GetData <string>(2); int deptId = requestData.GetData <int>(3); //判断退费消息是否存在,不存在抛出异常 foreach (DataRow row in dtRefund.Rows) { int reHeadID = Convert.ToInt32(row["ReHeadID"]); DataTable dtRefundRecord = NewObject <OP_FeeRefundHead>().gettable("ReHeadID=" + reHeadID.ToString()); if (dtRefundRecord == null || dtRefundRecord.Rows.Count <= 0) { throw new Exception("该退药单已经被删除,请刷新界面重新操作!"); } int recipeId = Convert.ToInt32(row["FeeItemHeadID"]); //判断是否存在 if (dispHead.FindIndex(x => x.RecipeID == recipeId) >= 0) { continue; } DS_OPDispHead modelHead = new DS_OPDispHead(); modelHead.BillNO = 0; modelHead.BusiType = DGConstant.OP_DS_OPREFUND; //求退费总金额 modelHead.RetailFee = Convert.ToDecimal(dtRefund.Compute("sum(RefundAmount)", "FeeItemHeadID=" + recipeId.ToString())); modelHead.PatListID = Convert.ToInt32(row["PatListID"]); modelHead.PatName = row["PatName"].ToString(); modelHead.PatSex = row["PatSex"].ToString(); modelHead.Diagnose = row["DiseaseName"].ToString(); modelHead.PatAge = row["Age"].ToString(); modelHead.PresDocID = Convert.ToInt32(row["PresEmpID"]); modelHead.PresDocName = row["PresEmpName"].ToString(); modelHead.PresDeptID = Convert.ToInt32(row["PresDeptID"]); modelHead.PresDeptName = row["PresDeptName"].ToString(); modelHead.DispenserID = sendEmpID; modelHead.DispenserName = sendEmpName; modelHead.PharmacistID = sendEmpID; modelHead.PharmacistName = sendEmpName; modelHead.RefundFlag = 1;//发药0退药1 modelHead.DispTime = System.DateTime.Now; modelHead.FeeNO = row["FeeNo"].ToString(); modelHead.InvoiceNO = row["InvoiceNO"].ToString(); modelHead.ChargeTime = Convert.ToDateTime(row["ChargeDate"]); modelHead.ChargeEmpID = Convert.ToInt32(row["ChargeEmpID"]); modelHead.ChargeEmpName = row["ChargeEmpName"].ToString(); modelHead.FeeItemHeadID = Convert.ToInt32(row["CostHeadID"]); modelHead.RecipeID = Convert.ToInt32(row["FeeItemHeadID"]); modelHead.RecipeType = row["PresType"].ToString(); modelHead.RecipeAmount = Convert.ToInt32(row["PresAmount"]); modelHead.DeptID = deptId; dispHead.Add(modelHead); } //获取该结算单所有明细记录 List <DS_OPDispDetail> dispDetail = ConvertRefundDetailModel(dtRefund, deptId); OPDispBill iProcess = NewObject <OPDispBill>(); DGBillResult rtn = new DGBillResult(); try { oleDb.BeginTransaction(); rtn = iProcess.OPRefund(dispHead, dispDetail, dtRefund); if (rtn.Result == 0) { oleDb.CommitTransaction(); } else { oleDb.RollbackTransaction(); } responseData.AddData(rtn); } catch (Exception error) { oleDb.RollbackTransaction(); rtn.ErrMsg = error.Message; rtn.Result = 2; responseData.AddData(rtn); } return(responseData); }