/// <summary> /// 按药房库存上下限构建入库申请单 /// </summary> /// <param name="newMaster">申请单表头</param> /// <param name="orderDt">申请单明细列表</param> /// <param name="_currentDeptId">申请科室</param> /// <param name="_currentUserId">申请人员ID</param> /// <param name="applyDept">出库科室</param> /// <param name="lowerStoreDrug">低于库存下限药品</param> public void BuildApplyInByStoreLimit(out YP_InMaster newMaster, out DataTable orderDt, int _currentDeptId, int _currentUserId, int applyDept, DataTable lowerStoreDrug) { try { if (lowerStoreDrug == null) { newMaster = null; orderDt = null; return; } decimal drugStoreNum; //药品库存数量 decimal lessNum; //还需申请数量 decimal batchStoreNum; //批次库存量 decimal applyNum; //总共需申请数量 int currentMakerDicId; //当前药品编码 StoreQuery _storeQuery = StoreFactory.GetQuery(ConfigManager.YF_SYSTEM); BillQuery _billQuery = BillFactory.GetQuery(ConfigManager.OP_YF_APPLYIN); StoreQuery _applyDeptStoreQuery = StoreFactory.GetQuery(ConfigManager.YK_SYSTEM); //构建一个新的入库申请单表头 newMaster = (YP_InMaster)(this.BuildNewMaster(_currentDeptId, _currentUserId)); orderDt = _billQuery.LoadOrder(newMaster); #region 循环低于下限的药品 for (int index = 0; index < lowerStoreDrug.Rows.Count; index++) { DataRow limitRow = lowerStoreDrug.Rows[index]; //获取当前药品编码 currentMakerDicId = Convert.ToInt32(limitRow["MAKERDICID"]); //计算需要申请入库药品数量 applyNum = (Convert.ToDecimal(limitRow["UPPERLIMIT"]) - Convert.ToDecimal(limitRow["CURRENTNUM"])) / Convert.ToDecimal(limitRow["PUNITNUM"]); applyNum = Math.Ceiling(applyNum); //按药品编码加载批次 DataTable batchDt = _applyDeptStoreQuery.LoadBatch(currentMakerDicId, applyDept); if (batchDt == null) { break; } drugStoreNum = 0; //判断批次总量是否满足申请要求 for (int temp = 0; temp < batchDt.Rows.Count; temp++) { drugStoreNum += Convert.ToDecimal(batchDt.Rows[temp]["CURRENTNUM"]); } if (drugStoreNum > applyNum) { #region 如果满足,循环批次生成入库单明细 for (int temp = 0; temp < batchDt.Rows.Count; temp++) { lessNum = applyNum; batchStoreNum = Convert.ToDecimal(batchDt.Rows[temp]["CURRENTNUM"]); if (batchStoreNum != 0) { DataRow newRow = orderDt.NewRow(); newRow["MAKERDICID"] = limitRow["MAKERDICID"]; //厂家ID newRow["CHEMNAME"] = limitRow["CHEMNAME"]; //化学名 newRow["SPEC"] = limitRow["SPEC"]; //规格 newRow["PRODUCTNAME"] = limitRow["PRODUCTNAME"]; //生产厂家名 newRow["RETAILPRICE"] = limitRow["RETAILPRICE"]; //零售价 newRow["TRADEPRICE"] = limitRow["TRADEPRICE"]; //批发价 newRow["STOCKPRICE"] = limitRow["TRADEPRICE"]; //进价 newRow["LEASTUNIT"] = limitRow["PACKUNIT"]; //包装单位编码 newRow["UNITNAME"] = limitRow["PACKUNITNAME"]; //包装单位 newRow["BATCHNUM"] = batchDt.Rows[temp]["BATCHNUM"]; //批次号 newRow["DEPTID"] = limitRow["DEPTID"]; //部门ID newRow["UNITNUM"] = limitRow["PUNITNUM"]; //单位数量 newRow["VALIDITYDATE"] = Convert.ToDateTime(batchDt.Rows[temp]["VALIDITYDATE"]); newRow["AUDIT_FLAG"] = 0; newRow["BILLNUM"] = 0; newRow["DELIVERNUM"] = ""; newRow["InStorageID"] = 0; newRow["MasterInStorageID"] = 0; newRow["REMARK"] = ""; newRow["DEFSTOCKPRICE"] = limitRow["TRADEPRICE"]; newRow["RecScale"] = 0.0; //批次数量大于还需申请数量 if (batchStoreNum >= lessNum) { if (lessNum < 1) { break; } else { //lessNum = Math.Ceiling(lessNum); newRow["INNUM"] = lessNum; //入库数量 newRow["TRADEFEE"] = lessNum * Convert.ToDecimal(newRow["TRADEPRICE"]); //批发金额 newRow["RETAILFEE"] = lessNum * Convert.ToDecimal(newRow["RETAILPRICE"]); //零售金额 newRow["STOCKFEE"] = newRow["TRADEFEE"]; //进货金额 orderDt.Rows.Add(newRow); break; } } //批次数量小于还需申请数量 else { newRow["INNUM"] = batchStoreNum; newRow["TRADEFEE"] = lessNum * Convert.ToDecimal(newRow["TRADEPRICE"]); //批发金额 newRow["RETAILFEE"] = lessNum * Convert.ToDecimal(newRow["RETAILPRICE"]); //零售金额 newRow["STOCKFEE"] = newRow["TRADEFEE"]; lessNum = applyNum - batchStoreNum; //进货金额 orderDt.Rows.Add(newRow); } } } #endregion 如果满足,循环批次生成入库单明细 } } #endregion 循环低于下限的药品 } catch (Exception error) { throw error; } }