Index: ssts-packing/src/main/java/com/forgon/disinfectsystem/packing/service/PackingManagerImpl.java =================================================================== diff -u -r14310 -r14341 --- ssts-packing/src/main/java/com/forgon/disinfectsystem/packing/service/PackingManagerImpl.java (.../PackingManagerImpl.java) (revision 14310) +++ ssts-packing/src/main/java/com/forgon/disinfectsystem/packing/service/PackingManagerImpl.java (.../PackingManagerImpl.java) (revision 14341) @@ -53,6 +53,9 @@ import com.forgon.disinfectsystem.basedatamanager.toussedefinition.service.TousseInstanceUtils; import com.forgon.disinfectsystem.basedatamanager.warehouse.service.WareHouseManager; import com.forgon.disinfectsystem.common.CssdUtils; +import com.forgon.disinfectsystem.entity.assestmanagement.DiposableGoodsInstance; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsIdentification; import com.forgon.disinfectsystem.entity.basedatamanager.container.Container; import com.forgon.disinfectsystem.entity.basedatamanager.materialdefinition.MaterialDefinition; import com.forgon.disinfectsystem.entity.basedatamanager.materialinstance.MaterialInstance; @@ -67,11 +70,13 @@ import com.forgon.disinfectsystem.entity.goodsstock.GoodsStock; import com.forgon.disinfectsystem.entity.idcarddefinition.IDCardDefinition; import com.forgon.disinfectsystem.entity.idcardinstance.IDCardInstance; +import com.forgon.disinfectsystem.entity.invoicemanager.DiposableGoodsItem; import com.forgon.disinfectsystem.entity.invoicemanager.Invoice; import com.forgon.disinfectsystem.entity.invoicemanager.InvoiceItem; import com.forgon.disinfectsystem.entity.invoicemanager.InvoicePlan; import com.forgon.disinfectsystem.entity.packing.IDCardInfoForPackingTask; import com.forgon.disinfectsystem.entity.packing.PackingRecord; +import com.forgon.disinfectsystem.entity.packing.PackingRecordOutItem; import com.forgon.disinfectsystem.entity.packing.PackingTask; import com.forgon.disinfectsystem.entity.packing.ReviewedBasket; import com.forgon.disinfectsystem.entity.recyclingdamagerecord.RecyclingDamageItem; @@ -104,6 +109,7 @@ import com.forgon.tools.MathTools; import com.forgon.tools.Path; import com.forgon.tools.db.DatabaseUtil; +import com.forgon.tools.db.InitDbConnection; import com.forgon.tools.hibernate.ObjectDao; import com.forgon.tools.json.JSONUtil; import com.forgon.tools.util.SqlUtils; @@ -163,6 +169,12 @@ private TimeoutManager timeoutManager; + private InitDbConnection dbConnection; + + public void setDbConnection(InitDbConnection dbConnection) { + this.dbConnection = dbConnection; + } + public void setTimeoutManager(TimeoutManager timeoutManager) { this.timeoutManager = timeoutManager; } @@ -2334,6 +2346,26 @@ return packingRecord; } + /** + * 创建装配扣减库存明细 + * @param packingRecord + * @param packingRecordOutItemList + * @param diposableGoodsItemList + */ + private void createPackingRecordOutItemList(PackingRecord packingRecord , + List packingRecordOutItemList , List diposableGoodsItemList){ + if(CollectionUtils.isNotEmpty(packingRecordOutItemList) && CollectionUtils.isNotEmpty(diposableGoodsItemList)){ + for(PackingRecordOutItem packingRecordOutItem : packingRecordOutItemList){ + packingRecordOutItem.setPackingRecordId(packingRecord.getId()); + objectDao.saveOrUpdate(packingRecordOutItem); + } + for(DiposableGoodsItem diposableGoodsItem : diposableGoodsItemList){ + diposableGoodsItem.setPackingRecordId(packingRecord.getId()); + objectDao.saveOrUpdate(diposableGoodsItem); + } + } + } + private void updateTousseWorkloadStaticsAmount(TousseDefinition tousseDefinition) { int workloadAmount = tousseDefinitionManager.getWorkloadAmount(tousseDefinition); @@ -2368,6 +2400,128 @@ return idToWashRecordMap; } /** + * 装配时扣减材料(一次性物品)库存 + * @param td 器械包定义 + * @param disposableGoods 一次性物品定义 + * @param amount 待扣减数量 + * @param config 科室供应室配置 + * @param packingRecordOutItemList 装配器械包后扣减一次性物品明细 + * @param diposableGoodsItemList 装配器械包后扣减一次性物品详细明细 + * @return + */ + private JSONObject outDisposableGoodsStock(TousseDefinition td , DisposableGoods disposableGoods , Integer amount,SupplyRoomConfig config, + List packingRecordOutItemList ,List diposableGoodsItemList) throws SQLException{ + JSONObject jsonObject = new JSONObject(); + jsonObject.put("success", true); + + Long disposableGoodsId = disposableGoods.getId(); + String disposableGoodsName = CssdUtils.getDiposableGoodsName(disposableGoods); + //先算出该一次性物品的标识表库存总和 + String sumAmountSql = "select sum(amount) amount " + + "from DisposableGoodsIdentification di join DisposableGoodsBatch db on di.disposableGoodsBatchID=db.id " + + "where di.disposableGoodsID = " + disposableGoodsId + " and di.warehouseID in (select id from WareHouse where orgUnitCode='" + + AcegiHelper.getCurrentOrgUnitCode()+ "') and amount > 0 "; + + + String sql = "select di.id,di.disposableGoodsBatchID ,di.batch_id,di.disposableGoodsStockID,amount,price,batchNumber " + + "from DisposableGoodsIdentification di join DisposableGoodsBatch db on di.disposableGoodsBatchID=db.id " + + "where di.disposableGoodsID = " + disposableGoodsId + " and di.warehouseID in (select id from WareHouse where orgUnitCode='" + + AcegiHelper.getCurrentOrgUnitCode()+ "') and amount > 0 "; + if(DatabaseUtil.isSqlServer(dbConnection.getDatabase())){ + sql += " and db.expDate > GETDATE() "; + sumAmountSql += " and db.expDate > GETDATE() "; + } else if(DatabaseUtil.isOracle(dbConnection.getDatabase())){ + sql += " and db.expDate > SYSDATE "; + sumAmountSql += " and db.expDate > SYSDATE "; + } else { + jsonObject.put("success", false); + jsonObject.put("message", ""); + } + sql += " order by db.expDate"; + + int needOutAmount = amount.intValue(); + int sumAmount = objectDao.countBySql(sumAmountSql); + if(sumAmount < needOutAmount){ + jsonObject.put("success", false); + jsonObject.put("message", disposableGoodsName + "库存不足,不能装配!"); + }else{ + //扣减库存,成功后加入到扣减明细集合中 + PackingRecordOutItem outItem = new PackingRecordOutItem(); + outItem.setTousseDefinitionId(td.getId()); + outItem.setTousseName(td.getName()); + outItem.setAmount(amount); + outItem.setDisposableGoodsId(disposableGoodsId); + outItem.setDisposableGoodsName(disposableGoodsName); + objectDao.saveOrUpdate(outItem); + double settlementPrice = 0.0; + ResultSet rs = objectDao.executeSql(sql); + while (rs.next()) { + Number nb = (Number)rs.getObject("amount"); + if(nb != null){ + long stockAmount = nb.longValue(); + long disposableGoodsStockID = rs.getLong("disposableGoodsStockID"); + long disposableGoodsBatchID = rs.getLong("disposableGoodsBatchID"); + long disposableGoodsBatchStockID = rs.getLong("batch_id"); + long identificationID = rs.getLong("id"); + double price = rs.getDouble("price"); + String batchNumber = rs.getString("batchNumber"); + if(stockAmount >= needOutAmount){ + //扣减库存(三个库存表数量都减),减少数量为needOutAmount + objectDao.executeUpdate("update DisposableGoodsIdentification set amount=amount-" + needOutAmount + " where id=" + identificationID); + objectDao.executeUpdate("update DisposableGoodsBatchStock set storage=storage-" + needOutAmount + " where id=" + disposableGoodsBatchStockID); + objectDao.executeUpdate("update DisposableGoodsStock set amount=amount-" + needOutAmount + " where id=" + disposableGoodsStockID); + + DiposableGoodsItem diposableGoodsItem = new DiposableGoodsItem(); + diposableGoodsItem.setAmount(needOutAmount); + diposableGoodsItem.setPrice(price); + diposableGoodsItem.setDisposableGoodsID(disposableGoodsId); + diposableGoodsItem.setBatch(batchNumber); + diposableGoodsItem.setDisposableGoodsStockID(disposableGoodsStockID); + diposableGoodsItem.setDisposableGoodsBatchID(disposableGoodsBatchID); + diposableGoodsItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStockID); + diposableGoodsItem.setFluctuationPrice(config.getDiposablePriceFluctuation() * price); + diposableGoodsItem.setIdentificationID(identificationID); + diposableGoodsItem.setName(disposableGoodsName); + diposableGoodsItem.setPackingRecordOutItemId(outItem.getId()); + diposableGoodsItemList.add(diposableGoodsItem); + + settlementPrice += needOutAmount * diposableGoodsItem.getFluctuationPrice(); + break; + } + //扣减库存(三个库存表数量都减),减少数量为stockAmount + objectDao.executeUpdate("update DisposableGoodsIdentification set amount=amount-" + stockAmount + " where id=" + identificationID); + objectDao.executeUpdate("update DisposableGoodsBatchStock set storage=storage-" + stockAmount + " where id=" + disposableGoodsBatchStockID); + objectDao.executeUpdate("update DisposableGoodsStock set amount=amount-" + stockAmount + " where id=" + disposableGoodsStockID); + + DiposableGoodsItem diposableGoodsItem = new DiposableGoodsItem(); + diposableGoodsItem.setAmount((int)stockAmount); + diposableGoodsItem.setPrice(price); + diposableGoodsItem.setDisposableGoodsID(disposableGoodsId); + diposableGoodsItem.setBatch(batchNumber); + diposableGoodsItem.setDisposableGoodsStockID(disposableGoodsStockID); + diposableGoodsItem.setDisposableGoodsBatchID(disposableGoodsBatchID); + diposableGoodsItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStockID); + diposableGoodsItem.setFluctuationPrice(config.getDiposablePriceFluctuation() * price); + diposableGoodsItem.setIdentificationID(identificationID); + diposableGoodsItem.setName(disposableGoodsName); + diposableGoodsItem.setPackingRecordOutItemId(outItem.getId()); + diposableGoodsItemList.add(diposableGoodsItem); + + settlementPrice += stockAmount * diposableGoodsItem.getFluctuationPrice(); + needOutAmount -= stockAmount; + } + + //如果待扣减的数量小于等于0时,跳出循环 + if(needOutAmount <= 0){ + break; + } + } + outItem.setSettlementPrice(settlementPrice); + packingRecordOutItemList.add(outItem); + } + return jsonObject; + } + /** * 装配器械包(外来器械、消毒物品、器械包等装配改造实现兼容) * 增加一个确认继续的操作,参数名:confirm,为"true"时表示继续 * @return @@ -2550,6 +2704,41 @@ TousseDefinition td = currentPackingTask.getTousseDefinition(); String tousseType = td.getTousseType(); String tousseName = tdName; + + List packingRecordOutItemList = null; + List diposableGoodsItemList = null; + /* + * 先判断装配任务对应的器械包定义是否需要扣一次性物品库存 + */ + if(CollectionUtils.isNotEmpty(packingTasks)){ + //如果该包定义需要扣减一次性物品库存的话 + if(TousseDefinition.STR_YES.equals(td.getAutoOutStockForPacking())){ + //判断对应的各一次性是否库存数量是否够扣,如果够扣的话 + List diposableGoodsItems = td.getDiposableGoodsItems(); + if(CollectionUtils.isNotEmpty(diposableGoodsItems)){ + packingRecordOutItemList = new ArrayList(); + diposableGoodsItemList = new ArrayList(); + for(DiposableGoodsInstance diposableGoodsInstance : diposableGoodsItems){ + //扣减库存 + DisposableGoods disposableGoods = diposableGoodsInstance.getDiposableGoods(); + Integer amount = diposableGoodsInstance.getAmount(); + if(disposableGoods != null && amount != null && amount > 0){ + try { + json = outDisposableGoodsStock(td, disposableGoods , amount , supplyRoomConfigParams, + packingRecordOutItemList , diposableGoodsItemList); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + if(!json.optBoolean("success")){ + return json.toString(); + } + } + } + } + } + } + // 外来器械包(未拆分成多个包) if (TousseDefinition.PACKAGE_TYPE_FOREIGN .equals(tousseType)) { @@ -2604,6 +2793,9 @@ PackingRecord packingRecord = createPackingRecord( inspector, operator, wrapper, orgUnitCoding, taskGroup, sterilizerName, sterileFrequency, td, packingDate, currentPackAmount, currentPackingTask); + + //创建装配扣减库存明细 + createPackingRecordOutItemList( packingRecord , packingRecordOutItemList , diposableGoodsItemList); packingSplitPackages(operator, operatorCode, reviewer, reviewerCode, sterilingType, sterilizerName, sterileFrequency, @@ -2668,6 +2860,8 @@ sterilizerName, sterileFrequency, td, packingDate, packingAmountForThisTask, currentPackingTask); + //创建装配扣减库存明细 + createPackingRecordOutItemList( packingRecord , packingRecordOutItemList , diposableGoodsItemList); JSONObject result = batchCreateTousseInstance( operator, operatorCode, reviewer,reviewerCode, packageType, Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/toussedefinition/TousseDefinition.java =================================================================== diff -u -r14270 -r14341 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/toussedefinition/TousseDefinition.java (.../TousseDefinition.java) (revision 14270) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/basedatamanager/toussedefinition/TousseDefinition.java (.../TousseDefinition.java) (revision 14341) @@ -222,6 +222,12 @@ private Long parentID;// 父包定义ID private Long ancestorID;// 祖先包定义ID private String materialsMD5; + + /** + * 装配时是否扣减库存(针对一次性材料),如果扣的话默认扣失效期距离当前时间最近的,默认不自动扣 + */ + private String autoOutStockForPacking = STR_NO; + @Id @GeneratedValue(strategy = GenerationType.AUTO) public Long getId() { @@ -989,6 +995,14 @@ } } + public String getAutoOutStockForPacking() { + return autoOutStockForPacking; + } + + public void setAutoOutStockForPacking(String autoOutStockForPacking) { + this.autoOutStockForPacking = autoOutStockForPacking; + } + @Transient public boolean isRestrictAmountGoods(){ if(this.intoBasketMaxAmount != null && this.intoBasketMaxAmount > 0){ Index: ssts-web/src/main/webapp/disinfectsystem/basedatamanager/tousse/tousseForm.js =================================================================== diff -u -r14050 -r14341 --- ssts-web/src/main/webapp/disinfectsystem/basedatamanager/tousse/tousseForm.js (.../tousseForm.js) (revision 14050) +++ ssts-web/src/main/webapp/disinfectsystem/basedatamanager/tousse/tousseForm.js (.../tousseForm.js) (revision 14341) @@ -642,6 +642,8 @@ //是否回收设为是 top.Ext.getCmp('isRecycling').enable(); top.Ext.getCmp('isRecycling').setValue('是'); + + top.Ext.getCmp('autoOutStockForPacking').enable(); }else if(record.data.value == '敷料包'){ //是否回收设为否 top.Ext.getCmp('isRecycling').disable(); @@ -650,6 +652,8 @@ top.Ext.getCmp('isSterile').disable(); top.Ext.getCmp('isSterile').setValue('是'); top.Ext.getCmp('isApplyEntireTousse').disable(); + + top.Ext.getCmp('autoOutStockForPacking').enable(); }else{ //是否回收设为是 top.Ext.getCmp('isRecycling').enable(); @@ -658,6 +662,14 @@ top.Ext.getCmp('isSterile').disable(); top.Ext.getCmp('isSterile').setValue('是'); top.Ext.getCmp('isApplyEntireTousse').disable(); + + top.Ext.getCmp('autoOutStockForPacking').enable(); + + if(record.data.value == '外部代理灭菌'){ + //材料扣库存设值为否,并禁用 + top.Ext.getCmp('autoOutStockForPacking').setValue('否'); + top.Ext.getCmp('autoOutStockForPacking').disable(); + } } } }, @@ -1512,6 +1524,28 @@ anchor : '100%' }] },{ + columnWidth : .25, + layout : 'form', + items:[{ + xtype : 'combo', + fieldLabel : '装配扣材料库存', + id : 'autoOutStockForPacking', + name : 'autoOutStockForPacking', + valueField : 'value', + displayField : 'value', + store : new Ext.data.SimpleStore( { + fields : [ 'value'], + data : [['是'],['否']] + }), + editable : false, + forceSelection : true, + //allowBlank : false, + value : '否', + mode : 'local', + triggerAction : 'all', + anchor : '100%' + }] + },{ columnWidth : .7, layout : 'form', id : 'videoPanel', @@ -1761,6 +1795,12 @@ top.Ext.getCmp('isSterile').disable(); top.Ext.getCmp('isSterile').setValue('是'); top.Ext.getCmp('isApplyEntireTousse').disable(); + + if(record.data.value == '外部代理灭菌'){ + //材料扣库存设值为否,并禁用 + top.Ext.getCmp('autoOutStockForPacking').setValue('否'); + top.Ext.getCmp('autoOutStockForPacking').disable(); + } } if (sstsConfig.disableIdCard){