/// <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> /// <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="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); }