/// <summary> /// 加有效库存 /// </summary> /// <param name="storeParam">库存处理参数</param> /// <returns>处理结果</returns> public DGStoreResult AddValidStore(StoreParam storeParam) { DGStoreResult result = new DGStoreResult { Result = 1 }; //默认 if (storeParam != null) { DS_ValidStorage storage = NewDao <IDSDao>().GetValidStoreageInfo(storeParam.DeptID, storeParam.DrugID); if (storage == null) { if (storeParam.Amount >= 0) { storage = NewObject <DS_ValidStorage>(); storage.StorageID = storeParam.StorageId; storage.DeptID = storeParam.DeptID; storage.DrugID = storeParam.DrugID; storage.ValidAmount = storeParam.Amount; int iRtn = storage.save(); result.Result = 0; } else { result.Result = 1; } } else { storage.ValidAmount += storeParam.Amount;//不考虑有效库存的正负数 int iRtn = storage.save(); } } return(result); }
/// <summary> /// 审核药库入库单 /// </summary> /// <param name="headID">药库入库单表头</param> /// <param name="auditEmpID">审核人ID</param> /// <param name="auditEmpName">审核人姓名</param> /// <returns>单据处理结果</returns> public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName) { DW_InStoreHead head = (DW_InStoreHead)NewObject <DW_InStoreHead>().getmodel(headID); List <DW_InStoreDetail> lstDetails = NewObject <DW_InStoreDetail>().getlist <DW_InStoreDetail>("InHeadID=" + headID); head.AuditEmpID = auditEmpID; head.AuditEmpName = auditEmpName; head.AuditTime = System.DateTime.Now; head.AuditFlag = 1; head.save(); DGBillResult result = new DGBillResult(); foreach (DW_InStoreDetail detail in lstDetails) { StoreParam storeParam = new StoreParam(); storeParam.Amount = detail.Amount; storeParam.BatchNO = detail.BatchNo; storeParam.DeptID = head.DeptID; storeParam.DrugID = detail.DrugID; storeParam.RetailPrice = detail.RetailPrice; storeParam.StockPrice = detail.StockPrice; storeParam.UnitID = detail.UnitID; storeParam.UnitName = detail.UnitName; storeParam.ValidityTime = detail.ValidityDate; storeParam.BussConstant = head.BusiType; //storeParam.PackUnit = detail.PackUnit; DGStoreResult storeRtn = iStore.AddStore(storeParam); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = head.DeptID; notEnough.DrugID = detail.DrugID; notEnough.LackAmount = storeRtn.StoreAmount + detail.Amount; notEnough.DrugInfo = "药品编号" + detail.DrugID + "药品批次号:" + detail.BatchNo; result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { WriteAccount(head, detail, storeRtn); } } result.Result = 0; return(result); }
/// <summary> /// 减有效库存 /// </summary> /// <param name="storeParam">库存参数</param> /// <returns>处理结果</returns> public DGStoreResult ReduceValidStore(StoreParam storeParam) { DGStoreResult result = new DGStoreResult { Result = 1 }; //默认 if (storeParam != null) { DS_ValidStorage storage = NewDao <IDSDao>().GetValidStoreageInfo(storeParam.DeptID, storeParam.DrugID); if (storage == null) { result.Result = 1; } else { storage.ValidAmount -= storeParam.Amount; storage.save(); result.Result = 0; } } return(result); }
/// <summary> /// 按批次增加库存 /// </summary> /// <param name="storeParam">药品库存入参</param> /// <returns>库存处理结果</returns> public DGStoreResult AddStore(StoreParam storeParam) { DGStoreResult storeResult = new DGStoreResult(); if (storeParam != null) { DW_Storage storage = NewDao <IDWDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID); if (storage != null) { //获取批次数据 DW_Batch batch = NewDao <IDWDao>().GetBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO); if (batch != null) { //如果批次数量加退货数量大于0 if (batch.BatchAmount + storeParam.Amount >= 0) { bool addRtn = NewDao <IDWDao>().AddStoreAmount(storeParam.DeptID, storeParam.DrugID, storeParam.Amount); addRtn = NewDao <IDWDao>().AddBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO, storeParam.Amount); if (addRtn) { //添加成功 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = batch.RetailPrice; batchAllot.StockPrice = batch.StockPrice; batchAllot.StoreAmount = batch.BatchAmount + storeParam.Amount; batchAllot.StorageID = storage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1]; storeResult.BatchAllot[0] = batchAllot; storeResult.StoreAmount = storage.Amount + storeParam.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } else { //添加失败 storeResult.Result = 2; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { //批次不存在 if (storeParam.Amount < 0) { storeResult.Result = 1; return(storeResult); } //新建批次 DW_Batch dwBatch = NewObject <DW_Batch>(); dwBatch.StorageID = storage.StorageID; dwBatch.BatchAmount = storeParam.Amount; dwBatch.BatchNO = storeParam.BatchNO; dwBatch.ValidityTime = storeParam.ValidityTime; dwBatch.DelFlag = 0; dwBatch.DeptID = storeParam.DeptID; dwBatch.DrugID = storeParam.DrugID; dwBatch.DelFlag = 0; dwBatch.InstoreTime = System.DateTime.Now; dwBatch.UnitID = storeParam.UnitID; dwBatch.UnitName = storeParam.UnitName; dwBatch.RetailPrice = storeParam.RetailPrice; dwBatch.StockPrice = storeParam.StockPrice; dwBatch.save(); bool addRtn = NewDao <IDWDao>().AddStoreAmount(storeParam.DeptID, storeParam.DrugID, storeParam.Amount);//改库存 if (addRtn) { //构建返回值 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = dwBatch.RetailPrice; batchAllot.StockPrice = dwBatch.StockPrice; batchAllot.StoreAmount = dwBatch.BatchAmount; batchAllot.StorageID = storage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1]; storeResult.BatchAllot[0] = batchAllot; storeResult.StoreAmount = storage.Amount + storeParam.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; } else { //添加失败 storeResult.Result = 2; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } } else { if (storeParam.Amount < 0) { storeResult.Result = 1; return(storeResult); } //新建库存记录 DW_Storage dwStorage = NewObject <DW_Storage>(); dwStorage.DrugID = storeParam.DrugID; dwStorage.DeptID = storeParam.DeptID; dwStorage.DelFlag = 0; dwStorage.UnitID = storeParam.UnitID; dwStorage.UnitName = storeParam.UnitName; dwStorage.Amount = storeParam.Amount; dwStorage.UpperLimit = 0; dwStorage.LowerLimit = 0; dwStorage.LocationID = 0; dwStorage.Place = string.Empty; dwStorage.RegTime = System.DateTime.Now; dwStorage.LStockPrice = 0; dwStorage.save(); //新建批次记录 DW_Batch dwBatch = NewObject <DW_Batch>(); dwBatch.StorageID = dwStorage.StorageID; dwBatch.BatchAmount = storeParam.Amount; dwBatch.BatchNO = storeParam.BatchNO; dwBatch.ValidityTime = storeParam.ValidityTime; dwBatch.DelFlag = 0; dwBatch.DeptID = storeParam.DeptID; dwBatch.DrugID = storeParam.DrugID; dwBatch.DelFlag = 0; dwBatch.InstoreTime = dwStorage.RegTime; dwBatch.UnitID = storeParam.UnitID; dwBatch.UnitName = storeParam.UnitName; dwBatch.RetailPrice = storeParam.RetailPrice; dwBatch.StockPrice = storeParam.StockPrice; dwBatch.save(); //构建返回值 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = storeParam.RetailPrice; batchAllot.StockPrice = storeParam.StockPrice; batchAllot.StoreAmount = storeParam.Amount; batchAllot.StorageID = dwStorage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1] { batchAllot }; storeResult.StoreAmount = storeParam.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = dwStorage.StorageID; return(storeResult); } } return(storeResult); }
/// <summary> /// 审核药库单据 /// </summary> /// <param name="headID">药库入库单表头ID</param> /// <param name="auditEmpID">审核人ID</param> /// <param name="auditEmpName">审核人姓名</param> /// <param name="workId">机构ID</param> /// <returns>单据处理结果</returns> public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName, int workId) { DW_InStoreHead head = (DW_InStoreHead)NewObject <DW_InStoreHead>().getmodel(headID); List <DW_InStoreDetail> lstDetails = NewObject <DW_InStoreDetail>().getlist <DW_InStoreDetail>("InHeadID=" + headID); head.AuditEmpID = auditEmpID; head.AuditEmpName = auditEmpName; head.AuditTime = System.DateTime.Now; head.AuditFlag = 1; head.save(); DGBillResult result = new DGBillResult(); if (!NewObject <DrugDeptMgr>().IsDeptChecked(head.DeptID, workId)) { result.Result = 1; result.ErrMsg = "当前科室处于盘点状态或者没有设置科室的盘点状态 不能处理业务操作"; return(result); } foreach (DW_InStoreDetail detail in lstDetails) { //获取批次数据 DW_Batch batch = NewDao <IDWDao>().GetBatchAmount(head.DeptID, detail.DrugID, detail.BatchNo); if (batch != null) { if (detail.Amount < 0) { if ((batch.RetailPrice.Equals(detail.RetailPrice) == false) || (batch.StockPrice.Equals(detail.StockPrice) == false)) { result.Result = 1; result.ErrMsg = "编码【" + detail.DrugID.ToString() + "的(进货价/零售价)】与【" + batch.BatchNO + "】批次价格不一致(进货价:" + batch.StockPrice.ToString() + ",零售价:" + batch.RetailPrice.ToString() + "),请核查库存!"; return(result); } } else { if ((batch.RetailPrice.Equals(detail.RetailPrice) == false) || (batch.StockPrice.Equals(detail.StockPrice) == false)) { result.Result = 1; result.ErrMsg = "编码【" + detail.DrugID.ToString() + "的(进货价/零售价)】与【" + batch.BatchNO + "】批次价格不一致(进货价:" + batch.StockPrice.ToString() + ",零售价:" + batch.RetailPrice.ToString() + "),请核查库存!"; return(result); } } } StoreParam storeParam = new StoreParam(); storeParam.Amount = detail.Amount; storeParam.BatchNO = detail.BatchNo; storeParam.DeptID = head.DeptID; storeParam.DrugID = detail.DrugID; storeParam.RetailPrice = detail.RetailPrice; storeParam.StockPrice = detail.StockPrice; storeParam.UnitID = detail.UnitID; storeParam.UnitName = detail.UnitName; storeParam.ValidityTime = detail.ValidityDate; storeParam.BussConstant = head.BusiType; //storeParam.PackUnit = detail.PackUnit; DGStoreResult storeRtn = iStore.AddStore(storeParam); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = head.DeptID; notEnough.DrugID = detail.DrugID; notEnough.LackAmount = storeRtn.StoreAmount + detail.Amount; notEnough.DrugInfo = "药品编号" + detail.DrugID + " 药品批次号:" + detail.BatchNo; result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { WriteAccount(head, detail, storeRtn); } } result.Result = 0; return(result); }
/// <summary> /// 台账写入 /// </summary> /// <typeparam name="THead">药库入库单表头模板</typeparam> /// <typeparam name="TDetail">药库入库单明细模板</typeparam> /// <param name="billHead">药库入库单表头</param> /// <param name="billDetails">药库入库单明细</param> /// <param name="storeResult">库存处理结果</param> public override void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult) { DW_InStoreDetail detail = billDetails as DW_InStoreDetail; DW_InStoreHead head = billHead as DW_InStoreHead; int actYear; int actMonth; string errMsg; if (!GetAccountTime(head.DeptID, out errMsg, out actYear, out actMonth)) { throw new Exception(errMsg); } DW_Account account = NewObject <DW_Account>(); account.BalanceYear = actYear; account.BalanceMonth = actMonth; account.AccountType = 0; account.BalanceFlag = 0; 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.LendAmount = detail.Amount; account.BillNO = detail.BillNo; account.RegTime = DateTime.Now; if (head.BusiType == DGConstant.OP_DW_BACKSTORE) { account.StockPrice = storeResult.BatchAllot[0].StockPrice; account.RetailPrice = storeResult.BatchAllot[0].RetailPrice; account.LendAmount = detail.Amount; account.LendRetailFee = account.LendAmount * account.RetailPrice; account.LendStockFee = account.LendAmount * account.StockPrice; account.OverAmount = storeResult.BatchAllot[0].StoreAmount; account.OverRetailFee = storeResult.BatchAllot[0].StoreAmount * account.RetailPrice; account.OverStockFee = storeResult.BatchAllot[0].StoreAmount * account.StockPrice; } else { account.StockPrice = detail.StockPrice; account.RetailPrice = detail.RetailPrice; account.LendAmount = detail.Amount; account.LendRetailFee = detail.RetailFee; account.LendStockFee = detail.StockFee; account.OverAmount = storeResult.BatchAllot[0].StoreAmount; account.OverRetailFee = storeResult.BatchAllot[0].StoreAmount * account.RetailPrice; account.OverStockFee = storeResult.BatchAllot[0].StoreAmount * account.StockPrice; } account.save(); }
/// <summary> /// 住院统领发药 /// </summary> /// <param name="dispHead">发药单表头</param> /// <param name="dispDetail">发药单明细</param> /// <returns>返回结果对象</returns> public DGBillResult IPDisp(DS_IPDispHead dispHead, List <DS_IPDispDetail> dispDetail) { //药品单据处理结果 DGBillResult result = new DGBillResult(); if (dispHead != null) { //1.判断药房是否处于盘点状态中 if (NewObject <DrugStoreManagement>().IsCheckStatus(dispHead.ExecDeptID, 0)) { throw new Exception("药房当前正在盘点中,不能发药"); } //生成单据号 string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, dispHead.ExecDeptID, DGConstant.OP_DS_IPDISPENSE); dispHead.BillNO = Convert.ToInt64(serialNO); dispHead.DispTime = System.DateTime.Now; BindDb(dispHead); dispHead.save(); //发药如果跨批次的化,台账需要记录差额调整记录 foreach (DS_IPDispDetail ispDetailModel in dispDetail) { decimal dispRetailPrice = ispDetailModel.RetailPrice; //5发药明细设置发药头表ID,保存数据在库存处理方法中 ispDetailModel.DispHeadID = dispHead.DispHeadID; //6减库存处理 StoreParam storeParam = new StoreParam(); storeParam.Amount = ispDetailModel.DispAmount; storeParam.BatchNO = ispDetailModel.BatchNO; storeParam.DeptID = ispDetailModel.DeptID; storeParam.DrugID = ispDetailModel.DrugID; storeParam.RetailPrice = ispDetailModel.RetailPrice; storeParam.StockPrice = ispDetailModel.StockPrice; storeParam.UnitID = ispDetailModel.UnitID; storeParam.UnitName = ispDetailModel.UnitName; if (storeParam.Amount > 0) { DGStoreResult storeRtn = NewObject <DSStore>().ReduceStoreAuto(storeParam, true); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = ispDetailModel.DeptID; notEnough.DrugID = ispDetailModel.DrugID; notEnough.LackAmount = ispDetailModel.DispAmount - storeRtn.StoreAmount; notEnough.DrugInfo = "药品批次号:" + ispDetailModel.BatchNO.ToString(); result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { //NewObject<DSStore>().UpdateValidStore(ispDetailModel.DrugID, ispDetailModel.DeptID, - Math.Abs(ispDetailModel.DispAmount)); foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList) { //保存发药明细数据 ispDetailModel.DispDetailID = 0; ispDetailModel.DispAmount = batchAllot.DispAmount; if (batchAllot.DispAmount == 0) { continue; } ispDetailModel.RetailPrice = batchAllot.RetailPrice; ispDetailModel.StockPrice = batchAllot.StockPrice; ispDetailModel.RetailFee = batchAllot.DispRetailFee; ispDetailModel.StockFee = batchAllot.DispStockFee; ispDetailModel.BatchNO = batchAllot.BatchNO; ispDetailModel.RetFlag = 0; BindDb(ispDetailModel); ispDetailModel.save(); if (ispDetailModel.RetailPrice != dispRetailPrice) { //零售价不一致,调整金额差额台账 WriteAccount(dispHead, ispDetailModel, storeParam, batchAllot); } //写减批次库存台账 WriteAccount(dispHead, ispDetailModel, batchAllot, 0, storeParam); } } } else { //退药 DGStoreResult storeRtn = NewObject <DSStore>().AddStoreAuto(storeParam, false); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.ErrMsg = "药品更新库存出错"; } return(result); } //更新有效库存 NewObject <DSStore>().UpdateValidStore(ispDetailModel.DrugID, ispDetailModel.DeptID, Math.Abs(ispDetailModel.DispAmount)); foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList) { //保存发药明细数据 ispDetailModel.DispDetailID = 0; ispDetailModel.DispAmount = -Math.Abs(batchAllot.DispAmount); ispDetailModel.RetailPrice = batchAllot.RetailPrice; ispDetailModel.StockPrice = batchAllot.StockPrice; ispDetailModel.RetailFee = batchAllot.DispRetailFee; ispDetailModel.StockFee = batchAllot.DispStockFee; ispDetailModel.BatchNO = batchAllot.BatchNO; ispDetailModel.RetFlag = 1; BindDb(ispDetailModel); ispDetailModel.save(); ispDetailModel.DispAmount = Math.Abs(ispDetailModel.DispAmount); if (ispDetailModel.RetailPrice != dispRetailPrice) { //零售价不一致,调整金额差额台账 WriteAccountRefund(dispHead, ispDetailModel, storeParam, batchAllot); } //写减批次库存台账 WriteAccount(dispHead, ispDetailModel, batchAllot, 1, storeParam); } } //回写住院统领单状态 IP_DrugBillDetail ipDrugBillDetail = (IP_DrugBillDetail)NewObject <IP_DrugBillDetail>().getmodel(ispDetailModel.MsgDetaillID); ipDrugBillDetail.DispDrugFlag = 1; ipDrugBillDetail.DispHeadID = dispHead.DispHeadID; ipDrugBillDetail.save(); //回写住院费用明细单 IP_FeeItemRecord feeItemRecord = (IP_FeeItemRecord)NewObject <IP_FeeItemRecord>().getmodel(ipDrugBillDetail.FeeRecordID); feeItemRecord.DrugFlag = 1; feeItemRecord.save(); } } //发药成功 result.Result = 0; result.DispHeadID = dispHead.DispHeadID; return(result); }
/// <summary> /// 门诊处方发药 /// </summary> /// <param name="dispHead">发药单表头</param> /// <param name="dispDetail">发药单明细</param> /// <param name="execEmpID">执行人ID</param> /// <returns>处理结果</returns> public DGBillResult OPDisp(List <DS_OPDispHead> dispHead, List <DS_OPDispDetail> dispDetail, int execEmpID) { //药品单据处理结果 DGBillResult result = new DGBillResult(); if (dispHead.Count > 0) { //1.判断药房是否处于盘点状态中 if (NewObject <DrugStoreManagement>().IsCheckStatus(dispHead[0].DeptID, 0)) { throw new Exception("药房当前正在盘点中,不能发药"); } //2.创建发药单表头,保存数据到发药表头中,发药单是多张,所以要做循环 foreach (DS_OPDispHead dispHeadModel in dispHead) { //生成单据号 string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, dispHeadModel.DeptID, DGConstant.OP_DS_OPDISPENSE); dispHeadModel.BillNO = Convert.ToInt64(serialNO); dispHeadModel.DispTime = System.DateTime.Now; BindDb(dispHeadModel); dispHeadModel.save(); //3.发药明细列表dispDetail通过字段(FeeItemHeadID)过滤出该表头对应的发药明细 List <DS_OPDispDetail> dispDetailList = dispDetail.Where(w => w.FeeItemHeadID == dispHeadModel.RecipeID).ToList(); //4.循环该张处方明细记录,更新DispHeadID等相关字段,保存数据到发药明细中,同时判断库存量,批次库存量,调用减库存的方法并返回处理结果 //发药如果跨批次的化,台账需要记录差额调整记录 foreach (DS_OPDispDetail ispDetailModel in dispDetailList) { decimal dispRetailPrice = ispDetailModel.RetailPrice; //5发药明细设置发药头表ID,保存数据在库存处理方法中 ispDetailModel.DispHeadID = dispHeadModel.DispHeadID; //6减库存处理 StoreParam storeParam = new StoreParam(); storeParam.Amount = ispDetailModel.DispAmount; storeParam.BatchNO = ispDetailModel.BatchNO; storeParam.DeptID = ispDetailModel.DeptID; storeParam.DrugID = ispDetailModel.DrugID; storeParam.RetailPrice = ispDetailModel.RetailPrice;//收费价格 storeParam.StockPrice = ispDetailModel.StockPrice; storeParam.UnitID = ispDetailModel.UnitID; storeParam.UnitName = ispDetailModel.UnitName; DGStoreResult storeRtn = NewObject <DSStore>().ReduceStoreAuto(storeParam, true); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = ispDetailModel.DeptID; notEnough.DrugID = ispDetailModel.DrugID; notEnough.LackAmount = ispDetailModel.DispAmount - storeRtn.StoreAmount; notEnough.DrugInfo = "药品批次号:" + ispDetailModel.BatchNO.ToString(); result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList) { //保存发药明细数据 ispDetailModel.DispDetailID = 0; if (batchAllot.DispAmount == 0) { continue; } ispDetailModel.DispAmount = batchAllot.DispAmount; ispDetailModel.RetailPrice = batchAllot.RetailPrice; ispDetailModel.StockPrice = batchAllot.StockPrice; ispDetailModel.RetailFee = batchAllot.DispRetailFee; ispDetailModel.StockFee = batchAllot.DispStockFee; ispDetailModel.BatchNO = batchAllot.BatchNO; BindDb(ispDetailModel); ispDetailModel.save(); if (ispDetailModel.RetailPrice != dispRetailPrice) { //零售价不一致,调整金额差额台账 WriteAccount(dispHeadModel, ispDetailModel, storeParam, batchAllot);//按收费价格算 } //写减批次库存台账 WriteAccount(dispHeadModel, ispDetailModel, batchAllot, 0, storeParam); } } } //8.在循环发药头表末尾处,更新收费主表发药标志DistributeFlag=1 OP_FeeItemHead feeItemHead = (OP_FeeItemHead)NewObject <OP_FeeItemHead>().getmodel(dispHeadModel.RecipeID); feeItemHead.DistributeFlag = 1;//发药标识=1 feeItemHead.ExecDate = System.DateTime.Now; feeItemHead.ExecEmpID = execEmpID; feeItemHead.save(); } } //发药成功 result.Result = 0; return(result); }
/// <summary> /// 台账写入 /// </summary> /// <typeparam name="THead">药房盘点单表头模板</typeparam> /// <typeparam name="TDetail">药房盘点单明细模板</typeparam> /// <param name="billHead">药房盘点单头</param> /// <param name="billDetails">药房盘点单明细</param> /// <param name="storeResult">结果对象</param> public override void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult) { throw new NotImplementedException(); }
/// <summary> /// 按先进先出减少库存 /// </summary> /// <param name="storeParam">库存参数</param> /// <param name="retAllBatch">true返回所有批次,返回</param> /// <returns>处理结果</returns> public DGStoreResult ReduceStoreAuto(StoreParam storeParam, bool retAllBatch) { DGStoreResult storeResult = new DGStoreResult(); if (storeParam != null) { DS_Storage storage = NewDao <IDSDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID); if (storage != null) { if (storage.Amount < storeParam.Amount) { //药品库存不足 //添加失败 storeResult.Result = 2; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = storage.UnitAmount; storeResult.StorageID = storage.StorageID; return(storeResult); } //减少药品库存 storage.Amount += -storeParam.Amount; storage.BindDb(this as AbstractBusines); int addStorageRtn = storage.save(); //取得所有批次 DataTable dtBatch = NewDao <IDSDao>().GetStorageBatch(storage.StorageID); decimal tempAmount = Math.Abs(storeParam.Amount); storeResult.BatchAllotList = new List <DGBatchAllot>(); storeResult.StoreAmount = storage.Amount; storeResult.StorageID = storage.StorageID; for (int i = 0; i < dtBatch.Rows.Count; i++) { DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = dtBatch.Rows[i]["BatchNO"].ToString(); batchAllot.RetailPrice = Convert.ToDecimal(dtBatch.Rows[i]["RetailPrice"]); batchAllot.StockPrice = Convert.ToDecimal(dtBatch.Rows[i]["StockPrice"]); batchAllot.ValidityDate = Convert.ToDateTime(dtBatch.Rows[i]["ValidityTime"]); batchAllot.StorageID = storage.StorageID; batchAllot.UnitAmount = Convert.ToInt32(dtBatch.Rows[i]["UnitAmount"]); decimal batchAmount = Convert.ToDecimal(dtBatch.Rows[i]["BatchAmount"]); decimal retailPrice = storeParam.RetailPrice;//收费价格 decimal stockPrice = storeParam.StockPrice; decimal unitAmount = Convert.ToDecimal(dtBatch.Rows[i]["UnitAmount"]); decimal retailFee = 0; decimal stockFee = 0; decimal dispAmount = 0; if (tempAmount >= batchAmount) { stockFee = batchAllot.CalFee(stockPrice, batchAllot.UnitAmount, batchAmount); retailFee = batchAllot.CalFee(retailPrice, batchAllot.UnitAmount, batchAmount); batchAllot.DispRetailFee = retailFee; batchAllot.DispStockFee = stockFee; batchAllot.StoreAmount = 0; batchAllot.DispAmount = batchAmount; dispAmount = batchAmount; storeResult.BatchAllotList.Add(batchAllot); bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), -dispAmount, 0, 1); if (!addBatchRtn) { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount - storeParam.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { stockFee = batchAllot.CalFee(stockPrice, batchAllot.UnitAmount, tempAmount); retailFee = batchAllot.CalFee(retailPrice, batchAllot.UnitAmount, tempAmount); batchAllot.DispRetailFee = retailFee; batchAllot.DispStockFee = stockFee; batchAllot.StoreAmount = batchAmount - tempAmount; batchAllot.DispAmount = tempAmount; dispAmount = batchAmount; storeResult.BatchAllotList.Add(batchAllot); bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), -tempAmount, 0, 1); if (!addBatchRtn) { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } break; } tempAmount -= batchAmount; } } } return(storeResult); }
/// <summary> /// 按先进先出增加库存 /// </summary> /// <param name="storeParam">药品库存入参</param> /// <param name="retAllBatch">true返回所有批次,返回</param> /// <returns>库存处理结果</returns> public DGStoreResult AddStoreAuto(StoreParam storeParam, bool retAllBatch) { DGStoreResult storeResult = new DGStoreResult(); if (storeParam != null) { if (storeParam.Amount < 0) { storeParam.Amount = Math.Abs(storeParam.Amount); } DS_Storage storage = NewDao <IDSDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID); if (storage != null) { if (!retAllBatch) { //退药模式,返回最近入库批次 //获取该药品最近入库批次,将药品加到该批次上 DS_Batch latelyBatch = NewDao <IDSDao>().GetLatelyBatchInfo(storeParam.DeptID, storeParam.DrugID); if (latelyBatch != null) { //增加药品库存 storage.Amount += storeParam.Amount; int addStorageRtn = storage.save(); //增加药品批次库存 bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(latelyBatch.DeptID, latelyBatch.DrugID, latelyBatch.BatchNO, storeParam.Amount, 0, 1); //如果批次数量加退货数量大于0 if (addStorageRtn >= 0 && addBatchRtn == true) { //添加成功 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = latelyBatch.BatchNO; batchAllot.StoreAmount = latelyBatch.BatchAmount + storeParam.Amount; batchAllot.StorageID = storage.StorageID; batchAllot.RetailPrice = latelyBatch.RetailPrice; batchAllot.StockPrice = latelyBatch.StockPrice; batchAllot.DispAmount = storeParam.Amount; batchAllot.UnitAmount = latelyBatch.UnitAmount; batchAllot.DispRetailFee = batchAllot.CalFee(storeParam.RetailPrice, latelyBatch.UnitAmount, storeParam.Amount); batchAllot.DispStockFee = batchAllot.CalFee(storeParam.StockPrice, latelyBatch.UnitAmount, storeParam.Amount); storeResult.BatchAllotList = new List <DGBatchAllot>(); storeResult.BatchAllotList.Add(batchAllot); storeResult.StoreAmount = storage.Amount + storeParam.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } else { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } } else { //盘点模式返回所有批次 decimal profitAmount = storeParam.FactAmount - storeParam.ActAmount; //更新药品库存 storage.Amount += profitAmount; int addStorageRtn = storage.save(); //更新有效库存 if (profitAmount != 0) { UpdateValidStore(storeParam.DrugID, storeParam.DeptID, profitAmount); } //取得所有批次 DataTable dtBatch = NewDao <IDSDao>().GetStorageBatch(storage.StorageID); decimal tempAmount = storeParam.FactAmount; storeResult.BatchAllotList = new List <DGBatchAllot>(); storeResult.StoreAmount = storage.Amount; storeResult.StorageID = storage.StorageID; for (int i = dtBatch.Rows.Count - 1; i >= 0; i--) { DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = dtBatch.Rows[i]["BatchNO"].ToString(); batchAllot.RetailPrice = Convert.ToDecimal(dtBatch.Rows[i]["RetailPrice"]); batchAllot.StockPrice = Convert.ToDecimal(dtBatch.Rows[i]["StockPrice"]); batchAllot.ValidityDate = Convert.ToDateTime(dtBatch.Rows[i]["ValidityTime"]); batchAllot.StorageID = storage.StorageID; batchAllot.DispAmount = storeParam.Amount; batchAllot.UnitAmount = Convert.ToInt32(dtBatch.Rows[i]["UnitAmount"]); decimal batchAmount = Convert.ToDecimal(dtBatch.Rows[i]["BatchAmount"]); decimal retailPrice = Convert.ToDecimal(dtBatch.Rows[i]["RetailPrice"]); decimal stockPrice = Convert.ToDecimal(dtBatch.Rows[i]["StockPrice"]);//盘点按照批次库存价格调整 decimal unitAmount = Convert.ToDecimal(dtBatch.Rows[i]["UnitAmount"]); decimal factAmount = 0; decimal factStockFee = 0; decimal factRetailFee = 0; decimal actAmount = 0; decimal actStockFee = 0; decimal actRetailFee = 0; if (tempAmount >= batchAmount) { //按照批次数计算金额 if (profitAmount > 0 && i == dtBatch.Rows.Count - 1) { //盘盈加入到最近入库批次 factAmount = batchAmount + profitAmount; factStockFee = batchAllot.CalFee(stockPrice, unitAmount, factAmount); factRetailFee = batchAllot.CalFee(retailPrice, unitAmount, factAmount); actAmount = batchAmount; actStockFee = batchAllot.CalFee(stockPrice, unitAmount, actAmount); actRetailFee = batchAllot.CalFee(retailPrice, unitAmount, actAmount); batchAllot.StoreAmount = factAmount; //更改批次库存 //增加药品批次库存 bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), profitAmount, 0, 1); if (!addBatchRtn) { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { factAmount = batchAmount; factStockFee = batchAllot.CalFee(stockPrice, unitAmount, factAmount); factRetailFee = batchAllot.CalFee(retailPrice, unitAmount, factAmount); actAmount = batchAmount; actStockFee = factStockFee; actRetailFee = factRetailFee; batchAllot.StoreAmount = factAmount; } tempAmount -= batchAmount; } else { if (tempAmount > 0) { //按照剩余数算 factAmount = tempAmount; factStockFee = batchAllot.CalFee(stockPrice, unitAmount, factAmount); factRetailFee = batchAllot.CalFee(retailPrice, unitAmount, factAmount); actAmount = batchAmount; actStockFee = batchAllot.CalFee(stockPrice, unitAmount, actAmount); actRetailFee = batchAllot.CalFee(retailPrice, unitAmount, actAmount); batchAllot.StoreAmount = tempAmount; } else { factAmount = 0; factStockFee = batchAllot.CalFee(stockPrice, unitAmount, factAmount); factRetailFee = batchAllot.CalFee(retailPrice, unitAmount, factAmount); actAmount = batchAmount; actStockFee = batchAllot.CalFee(stockPrice, unitAmount, actAmount); actRetailFee = batchAllot.CalFee(retailPrice, unitAmount, actAmount); batchAllot.StoreAmount = 0; } //增加药品批次库存 bool addBatchRtn = NewDao <IDSDao>().UpdateBatchAmount(storeParam.DeptID, storeParam.DrugID, dtBatch.Rows[i]["BatchNO"].ToString(), -(batchAmount - tempAmount), 0, 1); if (!addBatchRtn) { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } tempAmount = 0; } batchAllot.FactAmount = factAmount; batchAllot.FactStockFee = factStockFee; batchAllot.FactRetailFee = factRetailFee; batchAllot.ActAmount = actAmount; batchAllot.ActStockFee = actStockFee; batchAllot.ActRetailFee = actRetailFee; storeResult.BatchAllotList.Add(batchAllot); } } } } return(storeResult); }
/// <summary> /// 按批次增加库存 /// </summary> /// <param name="storeParam">药品库存入参</param> /// <returns>库存处理结果</returns> public DGStoreResult AddStore(StoreParam storeParam) { DGStoreResult storeResult = new DGStoreResult(); if (storeParam != null) { DS_Storage storage = NewDao <IDSDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID); if (storage != null) { storeParam.StorageId = storage.StorageID; //获取批次数据 DS_Batch batch = NewDao <IDSDao>().GetBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO); if (batch != null) { //如果批次数量加退货数量大于0 if (batch.BatchAmount + storeParam.Amount >= 0 && storage.Amount + storeParam.Amount >= 0) { if ((batch.BatchAmount + storeParam.Amount) == 0) { //当库存量为零时,把批次记录标记为已删除,新增加该批次库存,然后再标记为有效 batch.DelFlag = 1; } else { batch.DelFlag = 0; } batch.BatchAmount += storeParam.Amount; batch.BindDb(this as AbstractBusines); batch.save(); storage.Amount += storeParam.Amount; storage.BindDb(this as AbstractBusines); storage.save(); //添加成功 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = batch.RetailPrice; batchAllot.StockPrice = batch.StockPrice; batchAllot.StoreAmount = batch.BatchAmount; batchAllot.StorageID = storage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1]; storeResult.BatchAllot[0] = batchAllot; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } else { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { if (storeParam.BussConstant == DGConstant.OP_DS_RETURNSOTRE) { //退库业务 storeResult.Result = 1; return(storeResult); } if (storeParam.BussConstant == DGConstant.OP_DS_FIRSTIN) { if (storeParam.Amount < 0) { storeResult.Result = 1; return(storeResult); } } //新建批次 DS_Batch dwBatch = NewObject <DS_Batch>(); dwBatch.StorageID = storage.StorageID; dwBatch.BatchAmount = storeParam.Amount; dwBatch.BatchNO = storeParam.BatchNO; dwBatch.ValidityTime = storeParam.ValidityTime; dwBatch.DelFlag = 0; dwBatch.DeptID = storeParam.DeptID; dwBatch.DrugID = storeParam.DrugID; dwBatch.DelFlag = 0; dwBatch.UnitAmount = storeParam.PackAmount;//单位系数 dwBatch.InstoreTime = System.DateTime.Now; dwBatch.PackUnit = storeParam.PackUnit; dwBatch.UnitID = storeParam.UnitID; dwBatch.UnitName = storeParam.UnitName; dwBatch.RetailPrice = storeParam.RetailPrice; dwBatch.StockPrice = storeParam.StockPrice; dwBatch.save(); bool addRtn = NewDao <IDSDao>().AddStoreAmount(storeParam.DeptID, storeParam.DrugID, storeParam.Amount);//改库存 if (addRtn) { //构建返回值 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = dwBatch.RetailPrice; batchAllot.StockPrice = dwBatch.StockPrice; batchAllot.StoreAmount = dwBatch.BatchAmount; batchAllot.StorageID = storage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1]; storeResult.BatchAllot[0] = batchAllot; storeResult.StoreAmount = storage.Amount + storeParam.Amount; storeResult.UnitAmount = storeParam.PackAmount; storeResult.StorageID = storage.StorageID; } else { //添加失败 storeResult.Result = 2; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = storeParam.PackAmount; storeResult.StorageID = storage.StorageID; return(storeResult); } } } else { if (storeParam.BussConstant == DGConstant.OP_DS_RETURNSOTRE) { //如果返库业务 storeResult.Result = 1; return(storeResult); } if (storeParam.Amount < 0) { storeResult.Result = 1; return(storeResult); } //新建库存记录 DS_Storage dwStorage = NewObject <DS_Storage>(); dwStorage.DrugID = storeParam.DrugID; dwStorage.DeptID = storeParam.DeptID; dwStorage.DelFlag = 0; dwStorage.UnitAmount = storeParam.UnitAmount; dwStorage.UnitID = storeParam.UnitID; dwStorage.UnitName = storeParam.UnitName; dwStorage.Amount = storeParam.Amount; dwStorage.PackUnit = storeParam.PackUnit; dwStorage.UpperLimit = 0; dwStorage.LowerLimit = 0; dwStorage.LocationID = 0; dwStorage.Place = string.Empty; dwStorage.RegTime = System.DateTime.Now; dwStorage.LastStockPrice = 0; dwStorage.save(); storeParam.StorageId = dwStorage.StorageID; //新建批次记录 DS_Batch dwBatch = NewObject <DS_Batch>(); dwBatch.StorageID = dwStorage.StorageID; dwBatch.BatchAmount = storeParam.Amount; dwBatch.BatchNO = storeParam.BatchNO; dwBatch.ValidityTime = storeParam.ValidityTime; dwBatch.DelFlag = 0; dwBatch.DeptID = storeParam.DeptID; dwBatch.DrugID = storeParam.DrugID; dwBatch.DelFlag = 0; dwBatch.InstoreTime = dwStorage.RegTime; dwBatch.UnitAmount = storeParam.PackAmount; dwBatch.UnitID = storeParam.UnitID; dwBatch.PackUnit = storeParam.PackUnit; dwBatch.UnitName = storeParam.UnitName; dwBatch.RetailPrice = storeParam.RetailPrice; dwBatch.StockPrice = storeParam.StockPrice; dwBatch.save(); //构建返回值 DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = storeParam.RetailPrice; batchAllot.StockPrice = storeParam.StockPrice; batchAllot.StoreAmount = storeParam.Amount; batchAllot.StorageID = dwStorage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1] { batchAllot }; storeResult.StoreAmount = storeParam.Amount; storeResult.UnitAmount = storeParam.PackAmount; storeResult.StorageID = dwStorage.StorageID; return(storeResult); } } return(storeResult); }
/// <summary> /// 台账写入 /// </summary> /// <typeparam name="THead">药库盘点单表头模板</typeparam> /// <typeparam name="TDetail">药库盘点单明细模板</typeparam> /// <param name="billHead">药库盘点单头</param> /// <param name="billDetails">药库盘点单明细</param> /// <param name="storeResult">处理结果</param> public override void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult) { DW_AuditDetail detail = billDetails as DW_AuditDetail; DW_AuditHead head = billHead as DW_AuditHead; int actYear; int actMonth; string errMsg; if (!GetAccountTime(head.DeptID, out errMsg, out actYear, out actMonth)) { throw new Exception(errMsg); } DW_Account account = NewObject <DW_Account>(); account.BalanceYear = actYear; account.BalanceMonth = actMonth; account.AccountType = 0; account.BalanceFlag = 0; 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; account.BillNO = head.BillNO; account.RegTime = DateTime.Now; //盘盈 借方 //盘亏 贷方 if (detail.FactAmount - detail.ActAmount > 0) { account.StockPrice = detail.StockPrice; account.RetailPrice = detail.RetailPrice; account.LendAmount = detail.FactAmount - detail.ActAmount; account.LendRetailFee = (detail.FactAmount - detail.ActAmount) * detail.RetailPrice; account.LendStockFee = (detail.FactAmount - detail.ActAmount) * detail.StockPrice; account.OverAmount = storeResult.StoreAmount; account.OverRetailFee = storeResult.StoreAmount * account.RetailPrice; account.OverStockFee = storeResult.StoreAmount * account.StockPrice; } else { //贷方 account.StockPrice = detail.StockPrice; account.RetailPrice = detail.RetailPrice; account.DebitAmount = detail.ActAmount - detail.FactAmount; account.DebitRetailFee = (detail.ActAmount - detail.FactAmount) * detail.RetailPrice; account.DebitStockFee = (detail.ActAmount - detail.FactAmount) * detail.StockPrice; account.OverAmount = storeResult.StoreAmount; account.OverRetailFee = storeResult.StoreAmount * account.RetailPrice; account.OverStockFee = storeResult.StoreAmount * account.StockPrice; } account.save(); }
/// <summary> /// 台账写入 /// </summary> /// <typeparam name="THead">药房入库单表头模板</typeparam> /// <typeparam name="TDetail">药房入库单明细模板</typeparam> /// <param name="billHead">药房入库单表头</param> /// <param name="billDetails">药房入库单明细</param> /// <param name="storeResult">库存处理结果</param> public override void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult) { WriteAccount(billHead, billDetails, storeResult, 0); }
/// <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(); }
/// <summary> /// 按批次减少库存 /// </summary> /// <param name="storeParam">库存处理入参</param> /// <returns>库存处理结果</returns> public DGStoreResult ReduceStore(StoreParam storeParam) { DGStoreResult storeResult = new DGStoreResult(); if (storeParam != null) { DW_Storage storage = NewDao <IDWDao>().GetStorageInfo(storeParam.DeptID, storeParam.DrugID); if (storage != null) { DW_Batch batch = NewDao <IDWDao>().GetBatchAmount(storeParam.DeptID, storeParam.DrugID, storeParam.BatchNO); if (batch != null) { //本批次存量 和库存总量都必须大于出库数量 if (batch.BatchAmount >= storeParam.Amount && storage.Amount >= storeParam.Amount) { storage.Amount = storage.Amount - storeParam.Amount; storage.BindDb(this as AbstractBusines); storage.save(); batch.BatchAmount -= storeParam.Amount; batch.BindDb(this as AbstractBusines); batch.save(); DGBatchAllot batchAllot = new DGBatchAllot(); batchAllot.BatchNO = storeParam.BatchNO; batchAllot.RetailPrice = batch.RetailPrice; batchAllot.StockPrice = batch.StockPrice; batchAllot.StoreAmount = batch.BatchAmount; batchAllot.StorageID = storage.StorageID; storeResult.BatchAllot = new DGBatchAllot[1]; storeResult.BatchAllot[0] = batchAllot; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = storeParam.UnitAmount; storeResult.StorageID = storage.StorageID; return(storeResult); } else { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { storeResult.Result = 1; storeResult.StoreAmount = storage.Amount; storeResult.UnitAmount = 1; storeResult.StorageID = storage.StorageID; return(storeResult); } } else { storeResult.Result = 1; return(storeResult); } } return(storeResult); }
/// <summary> /// 审核单据 /// </summary> /// <param name="deptId">科室Id</param> /// <param name="auditEmpID">审核人ID</param> /// <param name="auditEmpName">审核人姓名</param> /// <returns>处理结果</returns> public override DGBillResult AuditBill(int deptId, int auditEmpID, string auditEmpName) { string serialNO = string.Empty;//审核单据号 //1.检查库房状态是否处于盘点状态 int checkStatus = NewDao <SqlDSDao>().GetStoreRoomStatus(deptId); if (checkStatus == 0) { throw new Exception("药房系统没有进入盘点状态,请启用盘点状态"); } //2.提取所有未审核的单据返回DataTable; Dictionary <string, string> queryCondition = new Dictionary <string, string>(); queryCondition.Add("a.DeptID", deptId.ToString()); DataTable dtNotAuditDetail = LoadAllNotAuditDetail(queryCondition, true); //3.创建盘点审核单据头 DS_AuditHead auditHead = NewObject <DS_AuditHead>(); decimal profitRetailFee = 0, profitStockFee = 0, lossRetailFee = 0, lossStockFee = 0; decimal checkStockFee = 0, actStockFee = 0, checkRetailFee = 0, actRetailFee = 0; checkStockFee = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactStockFee)", "true")); //盘存进货金额 actStockFee = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActStockFee)", "true")); //账存进货金额 checkRetailFee = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactRetailFee)", "true")); //盘存零售金额 actRetailFee = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActRetailFee)", "true")); //账存零售金额 profitRetailFee = checkRetailFee - actRetailFee > 0 ? checkRetailFee - actRetailFee : 0; //盘盈零售金额 profitStockFee = checkStockFee - actStockFee > 0 ? checkStockFee - actStockFee : 0; //盘盈进货金额 lossRetailFee = checkRetailFee - actRetailFee < 0 ? Math.Abs(checkRetailFee - actRetailFee) : 0; //盘亏零售金额 lossStockFee = checkStockFee - actStockFee < 0 ? Math.Abs(checkStockFee - actStockFee) : 0; //盘亏进货金额 serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, deptId, DGConstant.OP_DS_AUDITCHECK); auditHead.BillNO = Convert.ToInt64(serialNO); auditHead.EmpID = auditEmpID; auditHead.EmpName = auditEmpName; auditHead.AuditTime = System.DateTime.Now; auditHead.Remark = string.Empty; auditHead.DelFlag = 0; auditHead.AuditFlag = 1; auditHead.BusiType = DGConstant.OP_DS_AUDITCHECK; auditHead.DeptID = deptId; auditHead.ProfitRetailFee = profitRetailFee; auditHead.ProfitStockFee = profitStockFee; auditHead.LossRetailFee = lossRetailFee; auditHead.LossStockFee = lossStockFee; auditHead.CheckStockFee = checkStockFee; auditHead.ActStockFee = actStockFee; auditHead.CheckRetailFee = checkRetailFee; auditHead.ActRetailFee = actRetailFee; BindDb(auditHead); auditHead.save(); //循环DataTable,根据DataTable的每一行的值去构建盘点审核单明细和盘点审核单头; //4.保存盘点审核单表头和明细 //5、按盘点审核单内容更新药库库存 DGBillResult result = new DGBillResult(); foreach (DataRow drNotAuditRow in dtNotAuditDetail.Rows) { StoreParam storeParam = new StoreParam(); storeParam.DeptID = auditHead.DeptID; storeParam.DrugID = Convert.ToInt32(drNotAuditRow["DrugID"]); storeParam.RetailPrice = Convert.ToDecimal(drNotAuditRow["RetailPrice"]); storeParam.StockPrice = Convert.ToDecimal(drNotAuditRow["StockPrice"]); storeParam.FactAmount = Convert.ToDecimal(drNotAuditRow["FactAmount"]); storeParam.ActAmount = Convert.ToDecimal(drNotAuditRow["ActAmount"]); DGStoreResult storeRtn = NewObject <DSStore>().AddStoreAuto(storeParam, true); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = Convert.ToInt32(drNotAuditRow["DeptID"]); notEnough.DrugID = Convert.ToInt32(drNotAuditRow["DrugID"]); notEnough.DrugInfo = "药品名称:" + drNotAuditRow["ChemName"].ToString(); result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】保存错误"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList) { DS_AuditDetail auditdetail = NewObject <DS_AuditDetail>(); auditdetail.StorageID = Convert.ToInt32(drNotAuditRow["StorageID"]); auditdetail.CTypeID = Convert.ToInt32(drNotAuditRow["CTypeID"]); auditdetail.DrugID = Convert.ToInt32(drNotAuditRow["DrugID"]); auditdetail.Place = drNotAuditRow["Place"].ToString(); auditdetail.DeptID = auditHead.DeptID; auditdetail.BillNO = auditHead.BillNO; auditdetail.UnitID = Convert.ToInt32(drNotAuditRow["UnitID"]); auditdetail.UnitName = drNotAuditRow["UnitName"].ToString(); auditdetail.PackUnit = drNotAuditRow["PackUnit"].ToString(); auditdetail.UnitAmount = Convert.ToInt32(drNotAuditRow["UnitAmount"].ToString()); auditdetail.AuditHeadID = auditHead.AuditHeadID; auditdetail.BatchNO = batchAllot.BatchNO; auditdetail.ValidityDate = batchAllot.ValidityDate; auditdetail.RetailPrice = batchAllot.RetailPrice; auditdetail.StockPrice = batchAllot.StockPrice; auditdetail.FactAmount = batchAllot.FactAmount; auditdetail.FactStockFee = batchAllot.FactStockFee; auditdetail.FactRetailFee = batchAllot.FactRetailFee; auditdetail.ActAmount = batchAllot.ActAmount; auditdetail.ActStockFee = batchAllot.ActStockFee; auditdetail.ActRetailFee = batchAllot.ActRetailFee; BindDb(auditdetail); auditdetail.save(); //写台账表 WriteAccount(auditHead, auditdetail, batchAllot); } } } //7、更新所有未审核的盘点录入单状态 DS_CheckHead checkHead = NewObject <DS_CheckHead>(); checkHead.AuditEmpID = auditEmpID; checkHead.AuditEmpName = auditEmpName; checkHead.AuditHeadID = auditHead.AuditHeadID; checkHead.AuditNO = (int)auditHead.BillNO; checkHead.DeptID = deptId; int ret = NewDao <IDSDao>().UpdateCheckHeadStatus(checkHead); if (ret > 0) { //8、设置库房盘点状态为运营状态 NewDao <IDGDao>().SetCheckStatus(deptId, 0, 0); result.Result = 0; } else { result.Result = 1; } return(result); }
/// <summary> /// 审核药库出库单 /// </summary> /// <param name="headID">药库出库单表头ID</param> /// <param name="auditEmpID">审核人ID</param> /// <param name="auditEmpName">审核人姓名</param> /// <returns>单据处理结果</returns> public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName) { DW_OutStoreHead outHead = (DW_OutStoreHead)NewObject <DW_OutStoreHead>().getmodel(headID); outHead.AuditEmpID = auditEmpID; outHead.AuditEmpName = auditEmpName; outHead.AuditTime = System.DateTime.Now; outHead.AuditFlag = 1; outHead.save(); List <DW_OutStoreDetail> lstDetails = NewObject <DW_OutStoreDetail>().getlist <DW_OutStoreDetail>("OutHeadID=" + headID); DGBillResult result = new DGBillResult(); foreach (var outDeatils in lstDetails) { StoreParam storeParam = new StoreParam(); storeParam.Amount = outDeatils.Amount; storeParam.BatchNO = outDeatils.BatchNO; storeParam.DeptID = outDeatils.DeptID; storeParam.DrugID = outDeatils.DrugID; storeParam.RetailPrice = outDeatils.RetailPrice; storeParam.StockPrice = outDeatils.StockPrice; storeParam.UnitID = outDeatils.UnitID; storeParam.UnitName = outDeatils.UnitName; storeParam.ValidityTime = outDeatils.ValidityDate; DGStoreResult storeRtn = iStore.ReduceStore(storeParam); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = outHead.DeptID; notEnough.DrugID = outDeatils.DrugID; notEnough.LackAmount = outDeatils.Amount - storeRtn.StoreAmount; notEnough.DrugInfo = "药品批次号:" + outDeatils.BatchNO; result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { WriteAccount(outHead, outDeatils, storeRtn); } } if (outHead.BusiType == DGConstant.OP_DW_CIRCULATEOUT || outHead.BusiType == DGConstant.OP_DW_RETURNSTORE) { //流通出库业务和退库业务 var t = outHead.BusiType == DGConstant.OP_DW_CIRCULATEOUT ? DGConstant.OP_DS_CIRCULATEIN:DGConstant.OP_DS_RETURNSOTRE; DS_InstoreHead dshead = NewObject <DGBillConverter>().ConvertInFromDWOutHead(outHead, auditEmpID, auditEmpName, t); IDGBill iProcess = NewObject <DGBillFactory>().GetBillProcess(t); List <DS_InStoreDetail> dsInStore = NewObject <DGBillConverter>().ConvertInFromDwStoreDetail(headID); iProcess.SaveBill(dshead, dsInStore);//药房入库 Basic_SystemConfig config = NewObject <IDGDao>().GetDeptParameters(dshead.DeptID, "AutoAuditInstore"); if (config != null) { //药房是否需要审核 if (config.Value == "1") { result = iProcess.AuditBill(dshead.InHeadID, auditEmpID, auditEmpName); } } } return(result); }
/// <summary> /// 写入调价单台账 /// </summary> /// <typeparam name="THead">调价单表头</typeparam> /// <typeparam name="TDetail">调价单明细</typeparam> /// <param name="billHead">单据头</param> /// <param name="billDetails">单据明细</param> /// <param name="storeResult">库存处理结果</param> public void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult) { DG_AdjHead adjHead = billHead as DG_AdjHead; DG_AdjDetail currentDetail = billDetails as DG_AdjDetail; currentDetail.AdjHeadID = adjHead.AdjHeadID; currentDetail.BillNO = adjHead.BillNO; #region 操作药库批次和明细表 List <DW_Batch> dwlist = NewDao <IDWDao>().GetBatchList(currentDetail.BatchNO, currentDetail.DrugID); foreach (DW_Batch dwbatch in dwlist) { SaveAccout(dwbatch, currentDetail); } #endregion #region 操作药房批次和明细表 List <DS_Batch> dslist = NewDao <IDSDao>().GetBatchList(currentDetail.BatchNO, currentDetail.DrugID); foreach (DS_Batch dsbatch in dslist) { SaveAccout(dsbatch, currentDetail); } #endregion }
/// <summary> /// 写入药库台账 /// </summary> /// <typeparam name="THead">药库单据头模板</typeparam> /// <typeparam name="TDetail">药库单据明细模板</typeparam> /// <param name="billHead">药库单据头</param> /// <param name="billDetails">药库单据明细</param> /// <param name="storeResult">库存处理结果</param> public abstract void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult);
/// <summary> /// 门诊处方退药 /// </summary> /// <param name="dispHead">退药单表头</param> /// <param name="dispDetail">退药单明细</param> /// <param name="dtRefund">退药单明细数据</param> /// <returns>返回处理结果</returns> public DGBillResult OPRefund(List <DS_OPDispHead> dispHead, List <DS_OPDispDetail> dispDetail, DataTable dtRefund) { //药品单据处理结果 DGBillResult result = new DGBillResult(); if (dispHead.Count > 0) { //1.判断药房是否处于盘点状态中 if (NewObject <DrugStoreManagement>().IsCheckStatus(dispHead[0].DeptID, 0)) { throw new Exception("药房当前正在盘点中,不能退药"); } //2.创建发药单表头,保存数据到发药表头中,发药单是多张,所以要做循环 foreach (DS_OPDispHead dispHeadModel in dispHead) { //生成单据号 string serialNO = NewObject <SerialNumberSource>().GetSerialNumber(SnType.药品, dispHeadModel.DeptID, DGConstant.OP_DS_OPREFUND); dispHeadModel.BillNO = Convert.ToInt64(serialNO); dispHeadModel.DispTime = System.DateTime.Now;//退药时间 BindDb(dispHeadModel); dispHeadModel.save(); //3.发药明细列表dispDetail通过字段(FeeItemHeadID)过滤出该表头对应的退药明细 List <DS_OPDispDetail> dispDetailList = dispDetail.Where(w => w.FeeItemHeadID == dispHeadModel.RecipeID).ToList(); //4.循环该张处方明细记录,更新DispHeadID等相关字段,保存数据到发药明细中,同时判断库存量,批次库存量,调用加库存的方法并返回处理结果 //退药如果跨批次的话,台账需要记录差额调整记录 foreach (DS_OPDispDetail ispDetailModel in dispDetailList) { decimal dispRetailPrice = ispDetailModel.RetailPrice; //5发药明细设置发药头表ID,保存数据在库存处理方法中 ispDetailModel.DispHeadID = dispHeadModel.DispHeadID; //6.加库存处理 StoreParam storeParam = new StoreParam(); storeParam.Amount = ispDetailModel.DispAmount; storeParam.BatchNO = ispDetailModel.BatchNO; storeParam.DeptID = ispDetailModel.DeptID; storeParam.DrugID = ispDetailModel.DrugID; storeParam.RetailPrice = ispDetailModel.RetailPrice; storeParam.StockPrice = ispDetailModel.StockPrice; storeParam.UnitID = ispDetailModel.UnitID; storeParam.UnitName = ispDetailModel.UnitName; storeParam.UnitAmount = ispDetailModel.UnitAmount; DGStoreResult storeRtn = NewObject <DSStore>().AddStoreAuto(storeParam, false); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.ErrMsg = "药品更新库存出错"; } return(result); } else { foreach (DGBatchAllot batchAllot in storeRtn.BatchAllotList) { //保存发药明细数据 ispDetailModel.DispDetailID = 0; ispDetailModel.DispAmount = batchAllot.DispAmount; ispDetailModel.RetailPrice = batchAllot.RetailPrice; ispDetailModel.StockPrice = batchAllot.StockPrice; ispDetailModel.RetailFee = batchAllot.DispRetailFee; ispDetailModel.StockFee = batchAllot.DispStockFee; ispDetailModel.BatchNO = batchAllot.BatchNO; BindDb(ispDetailModel); ispDetailModel.save(); if (ispDetailModel.RetailPrice != dispRetailPrice) { //零售价不一致,调整金额差额台账 WriteAccount(dispHeadModel, ispDetailModel, storeParam, batchAllot);//按收费价格算 } //写减批次库存台账 WriteAccount(dispHeadModel, ispDetailModel, batchAllot, 1, storeParam); } } int feeDetailID = ispDetailModel.FeeDetailID; //更新明细退药标志 NewDao <IDSDao>().UpdateFeeRefundStatus(feeDetailID); } } } //退药成功 result.Result = 0; return(result); }
/// <summary> /// 审核药房出库单 /// </summary> /// <param name="headID">药房出库单表头ID</param> /// <param name="auditEmpID">审核人ID</param> /// <param name="auditEmpName">审核人姓名</param> /// <param name="workId">机构ID</param> /// <returns>单据处理结果</returns> public override DGBillResult AuditBill(int headID, int auditEmpID, string auditEmpName, int workId) { DS_OutStoreHead outHead = (DS_OutStoreHead)NewObject <DS_OutStoreHead>().getmodel(headID); outHead.AuditEmpID = auditEmpID; outHead.AuditEmpName = auditEmpName; outHead.AuditTime = System.DateTime.Now; outHead.AuditFlag = 1; outHead.save(); List <DS_OutStoreDetail> lstDetails = NewObject <DS_OutStoreDetail>().getlist <DS_OutStoreDetail>("OutHeadID=" + headID); DGBillResult result = new DGBillResult(); if (!NewObject <DrugDeptMgr>().IsDeptChecked(outHead.DeptID, workId)) { result.Result = 1; result.ErrMsg = "当前科室处于盘点状态或者没有设置科室的盘点状态 不能处理业务操作"; return(result); } foreach (var outDeatils in lstDetails) { StoreParam storeParam = new StoreParam(); storeParam.Amount = outDeatils.Amount; decimal packAmount = GetPackAmount(outDeatils.DrugID); storeParam.PackAmount = Convert.ToInt32(packAmount); storeParam.Amount = outDeatils.Amount;//包装数*系数+基本单位数 storeParam.BatchNO = outDeatils.BatchNO; storeParam.DeptID = outDeatils.DeptID; storeParam.DrugID = outDeatils.DrugID; storeParam.RetailPrice = outDeatils.RetailPrice; storeParam.StockPrice = outDeatils.StockPrice; storeParam.UnitID = outDeatils.UnitID; storeParam.UnitName = outDeatils.UnitName; storeParam.ValidityTime = outDeatils.ValidityDate; DGStoreResult storeRtn = iStore.ReduceStore(storeParam); if (storeRtn.Result != 0) { result.Result = 1; if (storeRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = outHead.DeptID; notEnough.DrugID = outDeatils.DrugID; notEnough.LackAmount = outDeatils.Amount - storeRtn.StoreAmount; notEnough.DrugInfo = "药品编号" + outDeatils.DrugID + " 药品批次号:" + outDeatils.BatchNO; result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足"; } else { result.ErrMsg = "药品更新库存出错"; } return(result); } else { DGStoreResult vStoreRtn = NewObject <DSStore>().ReduceValidStore(storeParam); if (vStoreRtn.Result != 0) { result.Result = 1; if (vStoreRtn.Result == 1) { result.LstNotEnough = new List <DGNotEnough>(); DGNotEnough notEnough = new DGNotEnough(); notEnough.DeptID = outHead.DeptID; notEnough.DrugID = outDeatils.DrugID; notEnough.LackAmount = outDeatils.Amount - storeRtn.StoreAmount; notEnough.DrugInfo = "药品编号" + outDeatils.DrugID + " 药品批次号:" + outDeatils.BatchNO; result.LstNotEnough.Add(notEnough); result.ErrMsg = "【" + notEnough.DrugInfo + "】没有有效库存"; } else { result.ErrMsg = "药品更新有效库存出错"; } return(result); } WriteAccount(outHead, outDeatils, storeRtn, packAmount); } } return(result); }