Index: ssts-web/src/main/webapp/disinfectsystem/invoice/customInvoiceForm.jsp =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/invoice/customInvoiceForm.jsp (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/invoice/customInvoiceForm.jsp (revision 15445) @@ -0,0 +1,96 @@ +<%@page import="java.text.SimpleDateFormat"%> +<%@page import="com.forgon.disinfectsystem.entity.tousseitem.TousseItem"%> +<%@page import="java.util.Calendar"%> +<%@page import="com.forgon.disinfectsystem.entity.invoicemanager.InvoicePlan"%> +<%@ page contentType="text/html; charset=UTF-8"%> +<%@ include file="/common/taglibs.jsp"%> +<%@ include file="/common/includeExtJsAndCss.jsp"%> + + + +发货计划单管理 + + + +<% + request.setAttribute("userName",AcegiHelper.getLoginUser().getUserFullName()); + + //设置日期定义 + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); + Calendar cal = Calendar.getInstance(); + String today = sdf.format(cal.getTime());//今天 + pageContext.setAttribute("today", today + ";" + today); + + cal.add(Calendar.DATE, -1); + String yesterday = sdf.format(cal.getTime());//昨天 + pageContext.setAttribute("yesterday", yesterday + ";" + yesterday); + + cal.add(Calendar.DATE, -1); + String threeDaysAgo = sdf.format(cal.getTime());//前天(近三天的起始日) + pageContext.setAttribute("lastThreeDays", threeDaysAgo + ";" + today); + + cal.add(Calendar.DATE, -4); + String sixDaysAgo = sdf.format(cal.getTime());//6天前(近一周的起始日) + pageContext.setAttribute("lastSixDays", sixDaysAgo + ";" + today); + +%> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+ + + + \ No newline at end of file Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/invoice/service/SubmitInvoiceContext.java =================================================================== diff -u -r15436 -r15445 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/invoice/service/SubmitInvoiceContext.java (.../SubmitInvoiceContext.java) (revision 15436) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/invoice/service/SubmitInvoiceContext.java (.../SubmitInvoiceContext.java) (revision 15445) @@ -35,6 +35,7 @@ private String invoiceType; private String invoiceMode = ""; private String departCode = ""; + private String depart = ""; private String sourceWarehouseId = ""; private String sourceWarehouseName = ""; private String sender = ""; @@ -102,6 +103,13 @@ return false; } + public boolean isInvoiceForCustom() { + if (StringUtils.equals(invoiceType, Invoice.TYPE_CUSTOM)) { + return true; + } + return false; + } + public String getInvoiceMode() { return invoiceMode; } @@ -118,6 +126,14 @@ this.departCode = departCode; } + public String getDepart() { + return depart; + } + + public void setDepart(String depart) { + this.depart = depart; + } + public String getSourceWarehouseId() { return sourceWarehouseId; } Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/dwr/table/InvoiceTableManager.java =================================================================== diff -u -r15403 -r15445 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/dwr/table/InvoiceTableManager.java (.../InvoiceTableManager.java) (revision 15403) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/dwr/table/InvoiceTableManager.java (.../InvoiceTableManager.java) (revision 15445) @@ -110,7 +110,8 @@ String recyclingApplicantID = sqlWhereParamMap .get("recyclingApplicantID"); String invoiceType = sqlWhereParamMap.get("invoiceType"); - String sql = "where po.invoicePlan is not null"; +// String sql = "where po.invoicePlan is not null"; + String sql = "where 1=1 "; if (StringUtils.isNotBlank(recyclingApplicantID)) { sql += " and po.invoicePlan.id = " + recyclingApplicantID + " and po.status != '" + Invoice.STATUS_UNDELIVERED + "'"; Index: ssts-web/src/main/webapp/disinfectsystem/invoice/customInvoiceForm.js =================================================================== diff -u --- ssts-web/src/main/webapp/disinfectsystem/invoice/customInvoiceForm.js (revision 0) +++ ssts-web/src/main/webapp/disinfectsystem/invoice/customInvoiceForm.js (revision 15445) @@ -0,0 +1,1072 @@ +var sendOutGoodsStore; +//定义首篮筐的label变量 +var beginBarcodeLabel = '扫描条码:'; +var hiddenEndBarcode = true;//隐藏尾篮筐 +var defaultFocusedFieldOnInvoiceForm = 'scanText'; +var lastLoadWarehouseId = null; +var TYPE_CUSTOM = '自定义发货'; +var INVOICE_MODE_DEPART = 'invoicePlan'; + +//申请科室Store +var appDepartJsonStore = new Ext.data.Store({ + proxy : new Ext.data.HttpProxy({ + url : WWWROOT + '/disinfectSystem/baseData/supplyRoomConfigAction!getApplicationDepartJson.do', + method : 'POST' + }), + reader : new Ext.data.JsonReader({ + root : 'data' + },[ + {name : 'id',mapping : 'id'}, + {name : 'departCode',mapping : 'departCode'}, + {name : 'name',mapping : 'name'} + ] + ) +}); + +var wareHouseStore = new Ext.data.Store({ + proxy : new Ext.data.HttpProxy({ + url : WWWROOT + '/disinfectSystem/baseData/wareHouseAction!getWareHouseData.do', + method : 'POST' + }), + reader : new Ext.data.JsonReader({ + totalProperty : 'totalCount', + root : 'data' + }, [ + {name : 'id',mapping : 'id'}, + {name : 'name',mapping : 'name'}, + {name : 'orgUnitCode',mapping : 'orgUnitCode'}, + ]), + listeners : { + load : function(store,records) { + var id = top.Ext.getCmp('sourceWarehouseId').getValue(); + //var name = top.Ext.getCmp('sourceWarehouseName').getValue(); + if(records.length > 0 && (id == null || id == '')){ + //id=records[0].data.id; + //name = records[0].data.name; + var combo = top.Ext.getCmp("warehouse"); + // 触发选中事件 + combo.fireEvent('select', combo,records[0],0); + } + //top.Ext.getCmp('warehouse').setValue(id); + //top.Ext.getCmp('sourceWarehouseId').setValue(id); + //top.Ext.getCmp('sourceWarehouseName').setValue(name); + } + } +}); + +if(sstsConfig.disableLoadToVirtualBasket == false){ + beginBarcodeLabel = '条码/篮筐(首):'; + hiddenEndBarcode = false;//显示尾篮筐 +} + +//条码扫描模式(单个条码逐个扫描或首尾条码段扫描两种模式) +var currentScanMode = "single"; +if(sstsConfig.invoicePageScanMode && sstsConfig.invoicePageScanMode != null){ + currentScanMode = sstsConfig.invoicePageScanMode; +} + +function getDefaultAmount(v,p,record){ + if (v==null || v.length <= 0){ + return 0; + }else{ + return v; + } +} +function formatStorage(v,p,record){ + if (v==null || v.length <= 0){ + return ''; + }else{ + return v; + } +} +function sayGoods(record){ + if(record && record.data){ + speaker.speak(record.data.showTousseName + ",数量为" + record.data.count); + } +} + +//删除发货扫描的物品 +function removeSendOutGoods(id){ + var rows = top.Ext.getCmp('sendOutGoods').getSelectionModel().getSelections();// 返回值为 + if (rows) { + for ( var i = 0; i < rows.length; i++) { + var name = rows[i].data['name']; + var amount = rows[i].data['count']; + sendOutGoodsStore.remove(rows[i]); + updateAmount1(name,amount); + } + } +} + + +//删除发货明细项 +function removeSendOutTousseByBarcode(barcode){ + var record = findRecordByNameAndValueFromStore(sendOutGoodsStore,'barcode',barcode); + if(record != null){ + var name = record.data['name']; + sendOutGoodsStore.remove(record); + updateAmount1(name,1); + } +} + +//验证条码是否重复扫描 +function isBarcodeRepeat(barcode){ + if(barcode != null && barcode.length > 0){ + for ( var i = 0; i < sendOutGoodsStore.getCount(); i++) { + var record = sendOutGoodsStore.getAt(i); + var tempBarcode =record.get('barcode'); + if(barcode == tempBarcode){ + return true; + break; + } + } + } + return false; +} + + + +//校验物品数量是否为数字 +function validGridAmount() { + //申请的物品 + var b = true; + for ( var i = 0; i < sendOutGoodsStore.getCount(); i++) { + var record = sendOutGoodsStore.getAt(i); + var count =record.get('count'); + if(/[^0-9]/g.test(count)){ + showResult('['+record.get('name')+'] 申请数量必须是数字,保存失败!'); + top.Ext.getCmp('sendOutGoods').getView().getRow(i).style.backgroundColor = '#FFB5B5'; + b = false; + break; + } + } + return b; +} + + + +var addGridItem = Ext.data.Record.create([ + {name : 'id'}, + {name : 'barcode'}, + {name : 'name'}, + {name : 'showTousseName'}, + {name : 'count'}, + {name : 'diposable'}, + {name : 'price'}, + {name : 'fluctuationPrice'}, + {name : 'storage'}, + {name : 'batchNumber'}, + {name : 'tousseType'}, + {name : 'typeInfoOnScanned'}, + {name : 'sterilizerName'}, + {name : 'frequency'}, + {name : 'isTracable'}, + {name : 'tousseDefinitionId'} + ]); + +// 根据条码获取发送项 +function getSendOutGoodsByBarcode(barcode){ + if(isUndefinedOrNullOrEmpty(barcode)){ + return null; + } + for ( var i = 0; i < sendOutGoodsStore.getCount(); i++) { + var record = sendOutGoodsStore.getAt(i); + var tempBarcode =record.get('barcode'); + if(barcode == tempBarcode){ + return record.data; + } + } + return null; +} +// 名字到数量的map +function getTousseNameToAmountMap(scannedResult){ + var map = {}; + for(var i=0;i 0){ +// showResult(msg); +// } +// } + speakBasket.speakContent(); +// if(result.data.length > 0 && alreadyAddAmount == 0){ +// showResult("器械包已扫描或不在发货单中"); +// } + }, + failure : function(response, options) { + top.Ext.getCmp("sendOutGoods").getEl().unmask(); + showResult('获取条码信息失败'); + } + + }); +} + + + +//function getTypeName(diposable){ +// if(diposable == '是'){ +// return '一次性物品'; +// } +//} +// + +function getDepartCoding(store,deptName){ + var deptCoding = ""; + for(var i = 0;i"; +// return str; +// }, +// dataIndex:'button' +// } + ]); + + var recyclingErrorCm = new Ext.grid.ColumnModel([ + {header : "材料名称",dataIndex : 'goodsName',width : 170,menuDisabled: true}, + {header : "缺失数量",dataIndex : 'count',width : 60, menuDisabled: true}, + {header : '单价',id : 'price',dataIndex : 'price',width : 60,value : 0,menuDisabled: true} + ]); + + var cm = new Ext.grid.ColumnModel([ + {header : "条码",dataIndex : 'barcode',width : 65,menuDisabled: true}, + {header : "物品名称",dataIndex : 'showTousseName',width : 190,menuDisabled: true}, + {header : "name",dataIndex : 'name',hidden : true,menuDisabled: true}, + {header : "批次/灭菌日期",dataIndex : 'batchNumber',width : 125,menuDisabled: true}, + {header : "灭菌炉名称",dataIndex : 'sterilizerName',width : 200,menuDisabled: true,hidden :true}, + {header : "炉次",dataIndex : 'frequency',width : 50,menuDisabled: true,hidden :true}, + {id : 'diposable',header : "是否一次性材料",dataIndex : 'diposable',hidden :true,width : 150}, + {header : "单价",dataIndex : 'fluctuationPrice',width : 50, align:'right', menuDisabled: true}, + {header : "数量",dataIndex : 'count',width : 50, align:'right', menuDisabled: true, + editor : new Ext.form.TextField( { + allowBlank : false, + listeners : { + focus : function(thiz){ + thiz.selectText(); + } + } + })}, + {id : 'deleteItem',header:'删除',width : 25, align:'center', menuDisabled: true, + renderer: function(v,p,record){ + var str = ""; + return str; + }, + dataIndex:'button' + }]); + + var form = new top.Ext.FormPanel({ + id : 'recyclingApplicationForm', + frame : true, + labelSeparator : ':', + bodyStyle : 'padding:5px 5px 0px 5px', + width : 1020, + autoHeight : true, + autoScroll : true, + labelAlign:'right', + layout : 'form', + items : [{ + xtype : "fieldset", + title : "基础数据", + layout : 'column', + style: 'padding:0px', + autoHeight : true, + items : [{ + layout : 'column', + columnWidth :1, + items:[{ + xtype : 'hidden', + name : 'id', + id : 'id' + },{ + xtype : 'hidden', + name : 'sendOutGoodsStoreData', + id : 'sendOutGoodsStoreData' + },{ + xtype :'hidden', + name : 'recyclingappStoreData', + id : 'recyclingappStoreData' + },{ + xtype :'hidden', + name : 'status', + id : 'status' + },{ + xtype :'hidden', + name : 'orgUnitCoding', + id : 'orgUnitCoding', + value:orgUnitCoding + },{ + xtype :'hidden', + name : 'applyDate', + id : 'applyDateHidden', + value:selectedApplyDate + },{ + xtype :'hidden', + name : 'tousseType', + id : 'tousseTypeHidden', + value:selectedTousseType + },{ + xtype :'hidden', + name : 'invoicePlanId', + id : 'invoicePlanIdHidden', + value:selectedInvoicePlanId + },{ + xtype : 'hidden', + name : 'invoiceType', + id : 'invoiceType', + value:TYPE_CUSTOM + },{ + xtype :'hidden', + name : 'personInChargeCode', + id : 'personInChargeCode' + },{ + xtype : 'hidden', + name : 'sourceWarehouseId', + id : 'sourceWarehouseId' + },{ + xtype : 'hidden', + name : 'sourceWarehouseName', + id : 'sourceWarehouseName' + },{ + xtype : 'hidden', + name : 'warehouseID', + id : 'warehouseID' + },{ + xtype : 'hidden', + name : 'warehouseName', + id : 'warehouseName' + },{ + layout : 'form', + labelWidth :70, + columnWidth :.33, + items : [{ + xtype : 'combo', + fieldLabel : '科室', + id : 'depart', + name : 'depart', + queryParam : 'spell', + minChars : 0, + valueField : 'name', + displayField : 'name', + store : appDepartJsonStore, + forceSelection : true, + lazyInit : true, + triggerAction : 'all', + hideTrigger : true, + typeAhead : false, + allowBlank : false, + anchor : '99%', + listeners:{ + select:function(combo, record, index){ + var deptName = top.Ext.getCmp("depart").getValue(); + var deptCoding = getDepartCoding(appDepartJsonStore,deptName); + top.Ext.getCmp("orgUnitCoding").setValue(deptCoding); + }, + focus : function(thiz){ + thiz.selectText(); + } + } + }] + },{ + layout : 'form', + labelWidth :70, + columnWidth :.67, + items : [{ + xtype : 'textfield', + fieldLabel : '发货员', + maxLength : '41', + id : 'deliveryPerson', + name : 'deliveryPerson', + readOnly:true, + allowBlank : false, + anchor : '99%', + value:$Id('userName').value, + cls:'fieldReadOnlyNoRemove' + }] + },{ + layout : 'form', + labelWidth :70, + columnWidth :.33, + items : [{ + xtype : 'textfield', + fieldLabel : '核对员条码', + maxLength : '16', + id : 'senderBarcode', + name : 'senderBarcode', + anchor : '99%', + listeners : { + render : function(p) { + p.getEl().on('keypress',function(e) { + if (e.getKey() == 13) {//回车键 + InvoiceTableManager.getUserNameOfCurrentLoginUserOrgsByBarcode( + top.Ext.getCmp('senderBarcode').getValue(),function(userName) { + if (userName != null) { + var resultArray = userName.split(":"); + if(resultArray[0] == "success"){ + top.Ext.getCmp('sender').setValue(resultArray[1]); + Ext.state.Manager.getProvider().set('cookieSender',resultArray[1]); + }else{ + showResult(resultArray[1]); + top.Ext.getCmp('sender').setValue(""); + } + } + top.Ext.getCmp('senderBarcode').setValue(""); + top.Ext.getCmp('personInChargeBarcode').focus(); + }); + } + }); + } + } + }] + },{ + layout : 'form', + labelWidth :70, + columnWidth :.33, + items : [{ + xtype : 'textfield', + fieldLabel : '核对员', + maxLength : '41', + id : 'sender', + name : 'sender', + readOnly:true, + allowBlank : false, + anchor : '99%', + cls:'x-item-disabled' + }] + },{ + layout : 'form', + labelWidth :90, + columnWidth :.33, + items : [{ + xtype : 'textfield', + fieldLabel : '下送责任人条码', + maxLength : '16', + id : 'personInChargeBarcode', + name : 'personInChargeBarcode', + anchor : '99%', + listeners : { + render : function(p) { + p.getEl().on('keypress',function(e) { + if (e.getKey() == 13) {//回车键 + var barcode = top.Ext.getCmp('personInChargeBarcode').getValue(); + top.Ext.getCmp('personInChargeBarcode').setValue(""); + UserTableManager.getUserByBarcode(barcode,function(responseText){ + if(!isUndefinedOrNullOrEmpty(responseText)){ + var result = top.Ext.decode(responseText); + if(!result.success){ + showResult("输入的条码有误!"); + return; + } + top.Ext.getCmp('personInCharge').setValue(result.fullName); + top.Ext.getCmp('personInChargeCode').setValue(result.name); + }else{ + showResult('找不到该条码所对应的人员信息'); + } + }); + } + }); + } + } + }] + },{ + layout : 'form', + labelWidth :70, + columnWidth :.33, + items : [{ + xtype : 'textfield', + fieldLabel : '下送责任人', + maxLength : '41', + id : 'personInCharge', + name : 'personInCharge', + readOnly:true, + anchor : '99%', + cls:'x-item-disabled' + }] + },{ + layout : 'form', + labelWidth :70, + columnWidth :.33, + items : [{ + xtype : 'datefieldWithMin', + fieldLabel : '发货时间', + id : 'sendTime', + name : 'sendTime', + allowBlank : false, + altFormats:'Y-m-d|Y-n-j|y-n-j|y-m-j|y-m-d|y-n-d|Y-n-d|Y-m-j|Ymd|Ynj|ynj|ymj|ymd|ynd|Ynd|Ymj|Y/m/d|Y/n/j|y/n/j|y/m/j|y/m/d|y/n/d|Y/n/d|Y/m/j', + format:'Y-m-d H:i', + value:new Date(), + anchor : '99%' + }] + },{ + columnWidth : .5, + layout : 'form', + labelWidth : 90, + columnWidth :.33, + items:[{ + xtype : 'combo', + fieldLabel : '仓库', + id : 'warehouse', + name : 'warehouse', + minChars : 0, + valueField : 'id', + displayField : 'name', + store : wareHouseStore, + forceSelection : true, + lazyInit : false, + triggerAction : 'all', + hideTrigger : true, + typeAhead : false, + allowBlank : false, + anchor : '99%', + listeners : { + select : function(combo, record, index) { + top.Ext.getCmp('warehouse').setValue(record.data.name); + top.Ext.getCmp('sourceWarehouseId').setValue(record.data.id); + top.Ext.getCmp('sourceWarehouseName').setValue(record.data.name); +// top.Ext.getCmp('remark2').focus(); + }, + specialkey : function(field, ee) { + if (ee.getKey() == Ext.EventObject.ENTER) { +// top.Ext.getCmp('remark2').focus(); + } + } + } + }] + },{ + layout : 'form', + columnWidth : 1, + labelWidth :70, + items : [{ + xtype : 'textarea', + fieldLabel : '备注', + id : 'remark2', + name : 'remark', + anchor : '98.5%', + height : 40, + readOnly:true + }] + }] + }] + },{ + layout:'column', + items:[{ + layout : 'form', + columnWidth : 0.57, + items:[ + new top.Ext.grid.EditorGridPanel({ + id : 'sendOutGoods', + store : sendOutGoodsStore, + columnWidth : 0.5, + cm : cm, + width : 560, + height : 425, + autoExpandColumn : 'deleteItem', + enableHdMenu : false, + frame : false, + bodyStyle : 'border:1px solid #afd7af', + viewConfig: { + autoFit:true + }, + clicksToEdit : 1,// 设置点击几次才可编辑 + selModel : new top.Ext.grid.RowSelectionModel({ + singleSelect : false + }), + tbar : [{ + text : '扫描模式:', + hidden : hiddenEndBarcode + },{ + xtype:'combo', + id : 'scanMode', + name : 'scanMode', + hidden : hiddenEndBarcode, + fieldLabel : '扫描模式', + valueField : 'scanModeCode', + displayField : 'scanModeName', + triggerAction : 'all', + width : 80, + allowBlank : true, + editable : false, + value:currentScanMode, + store : new Ext.data.SimpleStore({ + fields : ['scanModeCode', 'scanModeName' ], + data : [['single','单个条码'],['area','首尾条码']] + }), + mode:'local', + forceSelection : true, + triggerAction : 'all', + listeners : { + select : function(combo, record, index){ + //alert(record.get("scanModeCode")); + currentScanMode = record.get("scanModeCode"); + } + }, + anchor : '100%' + },{ + text : beginBarcodeLabel + },{ + xtype : 'textfield', + id : 'scanText', + name : 'scanText', + width : 90, + enableKeyEvents : true, + listeners : { + render : function(c) { + c.getEl().on('keypress',function(e) { + if (e.getKey() == 13) {// 输入;号键,grid重新加载 + if(top.Ext.getCmp("scanText").getValue() != ''){ + loadGoodsByBarcode(orgUnitCoding); + }else{ + showResult("请扫描输入器械包/篮筐(首)条码!"); + } + } + }); + c.getEl().on('focus',function(e) { + top.Ext.getCmp('scanText').setValue(''); + }); + } + } + },{ + text : '条码/篮筐(尾):', + hidden : hiddenEndBarcode + },{ + xtype : 'textfield', + id : 'scanTextEnd', + name : 'scanTextEnd', + hidden : hiddenEndBarcode, + width : 90, + enableKeyEvents : true, + listeners : { + render : function(c) { + c.getEl().on('keypress',function(e) { + if (e.getKey() == 13) {// 输入;号键,grid重新加载 + if(top.Ext.getCmp("scanTextEnd").getValue() != ''){ + loadGoodsByBarcode(orgUnitCoding); + }else{ + showResult("请扫描输入器械包/篮筐(尾)条码!"); + } + } + }); + c.getEl().on('focus',function(e) { + top.Ext.getCmp('scanTextEnd').setValue(''); + }); + } + } + }], + listeners : { + beforeedit : function(grid){//只有一次性物品才能编辑数量 + var record = grid.record; + if(record.data.diposable == '否') { + return false; + } + }, + afteredit :function(grid){ + var id = grid.record.data['id']; + var name = grid.record.data['name']; + var count = grid.record.data['count']; + var storage = grid.record.data['storage']; + var storageInt = parseInt(storage); + if(id==0){ + if(parseInt(count) <= storageInt){ + updateAmount2(name,count); + } else { + showResult('库存量为:' + storage + ',已超过库存量!'); + var index = recyclingapplicationStore.find("name",name); + var tempAmount = recyclingapplicationStore.getAt(index).data['tempAmount']; + grid.record.set('count',storageInt); + } + } else { + var record = getRecord(recyclingapplicationStore, "name", name, 0); + if(record != null) { + var tempAmount = record.data['tempAmount']; + if(parseInt(count) <= (storageInt + parseInt(tempAmount))){ + updateAmount2(name,count); + } else { + showResult('库存量为:' + storage + ',已超过库存量!'); + grid.record.set('count',tempAmount); + } + } + } + } + } + } + )] + } + ] + }], + buttons : [{ + text : '保存', + id:'saveButton', + handler : function() { + if (!form.getForm().isValid()) { + showResult('请正确填写表单各值'); + return false; + } + //验证发货物品表格 + if(!sendOutGoodsStore || sendOutGoodsStore.getCount() == 0){ + showResult('发货物品不能为空!'); + return false; + } + + var bool = validGridAmount(); + if(!bool){ + return false; + } + + getTousseGridData(); + form.form.submit( { + //url : WWWROOT + '/disinfectSystem/invoiceAction!saveDepartInvoice.do', + url : WWWROOT + '/disinfectSystem/invoiceAction!saveInvoiceByDepartOrInvoicePlanId.do', + method : 'POST', + waitMsg : '正在保存数据,请稍候', + waitTitle : '提交表单', + success : function(form, action) { + // 一定要事务提交成功才返回发货计划列表界面 + showResult(action.result.message); + if(action.result.success){ + window.close(); + } + }, + failure : function(form, action) { + if(!isUndefinedOrNullOrEmpty(action.result) && !isUndefinedOrNullOrEmpty(action.result.message)){ + showResult(action.result.message); + }else{ + showResult("发货超时,请稍后查看发货单以确定发货是否成功,避免重复发货!"); + window.close(); + } + } + }); + } + }, { + text : '取消', + handler : function() { + //切记注意:按取消关闭window后,一定要把已选择的申请单号变量清空 + selectedInvoicePlanId = ""; + window.close(); + } + }] + }); + + var cookieSender = Ext.state.Manager.getProvider().get('cookieSender'); + if(cookieSender){ + top.Ext.getCmp('sender').setValue(cookieSender); + } + + var window = new top.Ext.Window( { + id : 'recyclingApplicationWin', + layout : 'fit', + title : '发货单', + width : 1020, + height : 660, + border : false, + modal : true, + plain : true, + items : [form] + }); + + window.on('close',function(w){ + //切记注意:按取消关闭window后,一定要把已选择的申请单号变量清空 + selectedInvoicePlanId = ""; + }); + + window.show(); + top.Ext.getCmp(defaultFocusedFieldOnInvoiceForm).focus(false, 100); +// top.Ext.getCmp('senderBarcode').focus(false, 100); + + wareHouseStore.load(); +} + +//展示器械包信息 +function showDisinfectMaterial(tousseName) { + var materialStore = new Ext.data.Store({ + proxy : new Ext.data.HttpProxy({ + url : WWWROOT + '/disinfectSystem/baseData/tousseDefinitionAction!getMaterialDefinitionByTousseName.do', + method : 'POST' + }), + baseParams : {tousseName : tousseName}, + reader : new Ext.data.JsonReader({ + fields : [ + {name : 'materialDefinitionId'}, + {name : 'name'}, + {name : 'count'} + ] + }) + }); + materialStore.load(); + var materialGrid = new top.Ext.grid.GridPanel({ + id :'materialGrid', + store: materialStore, + columns: [ + {hidden : true, dataIndex : 'materialDefinitionId'}, + {header : "材料名称",width : 80, menuDisabled: true,dataIndex : 'name'}, + {header : "数量",width : 27, menuDisabled: true,dataIndex : 'count'} + ], + viewConfig: { + forceFit: true + }, + autoExpandColumn : 'materialAmount', + frame:false + }); + + var window = new top.Ext.Window({ + title : tousseName + '信息', + width : 400, + height :200, + border : false, + autoScroll: true, + layout : 'fit', + modal : true, + items : [materialGrid] + }); + window.show(); +} + +//获取扫描的物品 +function getTousseGridData() { + var submitItems = []; + for ( var i = 0; i < sendOutGoodsStore.getCount(); i++) { + var record = sendOutGoodsStore.getAt(i); + record.data.sendAmount = record.data.count; + submitItems.push(record.data); + } + top.Ext.getCmp('sendOutGoodsStoreData').setValue(JSON.stringify(submitItems)); +} + + +Ext.onReady(function() { + Ext.QuickTips.init(); + + addAndEditInvoicePlan('',''); +}); \ No newline at end of file Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/action/InvoiceAction.java =================================================================== diff -u -r15436 -r15445 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/action/InvoiceAction.java (.../InvoiceAction.java) (revision 15436) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/action/InvoiceAction.java (.../InvoiceAction.java) (revision 15445) @@ -1541,6 +1541,7 @@ JSONObject params = new JSONObject(); String orgUnitCoding = StrutsParamUtils.getPraramValue("orgUnitCoding", ""); + String depart = StrutsParamUtils.getPraramValue("depart", ""); String invoiceType = StrutsParamUtils.getPraramValue("invoiceType", Invoice.TYPE_APPLICATION); String mode = StrutsParamUtils.getPraramValue("mode", Invoice.INVOICE_MODE_DEPART); String sender = StrutsParamUtils.getPraramValue("sender", ""); @@ -1553,6 +1554,7 @@ params.put("invoiceType", invoiceType); params.put("mode", mode); params.put("departCode", orgUnitCoding); + params.put("depart", depart); params.put("assistantSender", sender); params.put("sender", loginUser); params.put("personInCharge", personInCharge); @@ -1591,6 +1593,7 @@ invoiceManager.submitInvoice(params); StrutsResponseUtils.output(true, "保存成功!"); } catch (Exception ex){ + ex.printStackTrace(); StrutsResponseUtils.output(false, ex.getMessage()); } } Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/invoicemanager/Invoice.java =================================================================== diff -u -r15436 -r15445 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/invoicemanager/Invoice.java (.../Invoice.java) (revision 15436) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/invoicemanager/Invoice.java (.../Invoice.java) (revision 15445) @@ -42,6 +42,7 @@ private String serialNumber; // 流水号 + private String departCoding;// 申请科室部门编码 private String depart; // 申请科室 private String settleAccountsDepart;//结算科室 @@ -217,6 +218,14 @@ this.serialNumber = serialNumber; } + public String getDepartCoding() { + return departCoding; + } + + public void setDepartCoding(String departCoding) { + this.departCoding = departCoding; + } + public String getDepart() { return depart; } Index: ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java =================================================================== diff -u -r15436 -r15445 --- ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 15436) +++ ssts-invoice/src/main/java/com/forgon/disinfectsystem/invoicemanager/service/InvoiceManagerImpl.java (.../InvoiceManagerImpl.java) (revision 15445) @@ -1432,19 +1432,25 @@ submitInvoiceContext.getTousseInstancesToUpdate().clear(); Map> updateStockInfo = submitInvoiceContext.getUpdateStockInfo(); List invoiceList = submitInvoiceContext.getInvoiceList(); - if (invoicePlan.delivered() || invoicePlan.deliverEnd()) { - return; + if(!submitInvoiceContext.isInvoiceForCustom()){ + if (invoicePlan.delivered() || invoicePlan.deliverEnd()) { + return; + } } - // 获取最终发货明细 - Set avaliableInvoiceItems = getAvaliableInvoiceItem( - invoicePlan, submitInvoiceContext); + Set avaliableInvoiceItems = new HashSet(); + if(!submitInvoiceContext.isInvoiceForCustom()){ + avaliableInvoiceItems = getAvaliableInvoiceItem( + invoicePlan, submitInvoiceContext); + }else{ + avaliableInvoiceItems = getAvaliableInvoiceItemForCustomInvoice(avaliableInvoiceItems, submitInvoiceContext); + } //找出发货项中的一次性物品,判断是否超支 - judgeOverspend(invoicePlan, avaliableInvoiceItems); + if(!submitInvoiceContext.isInvoiceForCustom()){ + judgeOverspend(invoicePlan, avaliableInvoiceItems); + } - - Invoice invoice = createInvoice(invoicePlan, avaliableInvoiceItems, submitInvoiceContext); @@ -1455,15 +1461,15 @@ // 设置仓库信息 invoice.setSourceWarehouseId(Long.valueOf(submitInvoiceContext.getSourceWarehouseId())); invoice.setSourceWarehouseName(submitInvoiceContext.getSourceWarehouseName()); - setDefaultWarehouse(invoice,invoice.getInvoicePlan().getDepartCoding()); + setDefaultWarehouse(invoice,invoice.getDepartCoding()); invoiceList.add(invoice); // 修改库存数量 // updateGoodsStock(invoice,tousseInstancesToUpdate); updateStockInfo.put(invoice, new HashSet(tousseInstancesToUpdate)); saveInvoice(invoice); updateTousseInstanceStatus(tousseInstancesToUpdate,submitInvoiceContext.getSubmitInvoiceItems()); //修改器械包是否常规发货的方法(cjr) // 设置发货单和器械包实例的关联以及修改器械包状态等属性 - updateTousseInstanceStatus(invoice,tousseInstancesToUpdate); + updateTousseInstanceStatus(submitInvoiceContext,invoice,tousseInstancesToUpdate); // 设置invoiceItem和invoice的关联 for (InvoiceItem invoiceItem : invoice.getInvoiceItem()) { @@ -1482,12 +1488,13 @@ } // 更新代理灭菌外来器械包申请的状态 - invoicePlanManager.updateProxyDisinfectionForeignTousseApplicationStataus( - tousseInstancesToUpdate, invoicePlan); - - // 更新发货计划单状态 - updateInvoicePlanStatus(invoicePlan); - + if(invoicePlan != null){ + invoicePlanManager.updateProxyDisinfectionForeignTousseApplicationStataus( + tousseInstancesToUpdate, invoicePlan); + + // 更新发货计划单状态 + updateInvoicePlanStatus(invoicePlan); + } } } @@ -1717,7 +1724,7 @@ writebackForZSLY(invoiceList); //省医回写接口调用 -// writebackForGDSY(invoiceList); + writebackForGDSY(invoiceList); // throw new RuntimeException("发货速度测试!"); } @@ -1815,45 +1822,45 @@ } private void writebackForGDSY(List invoiceList) { - if(StringUtils.equalsIgnoreCase(CssdUtils.getConfigProperty("project"), "gdsy") && writeBackInventoryDao != null){ - if(CollectionUtils.isNotEmpty(invoiceList)){ - try{ - for (Invoice invoice : invoiceList) { - - /*4 - */ - //发货单的发货科室-供应室 - OrgUnit invoiceCssdOrgUnit = (OrgUnit)objectDao.getByProperty(OrgUnit.class.getSimpleName(), "orgUnitCoding", invoice.getOrgUnitCoding()); - //发货单接收科室-申请单的临床科室 - OrgUnit invoiceClinicOrgUnit = (OrgUnit)objectDao.getByProperty(OrgUnit.class.getSimpleName(), "orgUnitCoding", invoice.getInvoicePlan().getDepartCoding()); - String xmlParam = "4" + invoiceCssdOrgUnit.getIdFromHisSync() + "" - + "" + invoiceClinicOrgUnit.getIdFromHisSync() + "" - + "INVOICE_" + invoice.getSerialNumber() + ""; - - if(CollectionUtils.isNotEmpty(invoice.getInvoiceItem())){ - for(InvoiceItem invoiceItem : invoice.getInvoiceItem()){ - if(Constants.STR_YES.equals(invoiceItem.getDiposable()) && DatabaseUtil.isPoIdValid(invoiceItem.getDisposableGoodsId())){ - DisposableGoods disposableGoods = diposableGoodsManager.getDisposableGoodsById(String.valueOf(invoiceItem.getDisposableGoodsId())); - DisposableGoodsBatch disposableGoodsBatch = diposableGoodsManager.getDisposableGoodsBatchById(invoiceItem.getDisposableGoodsBatchId()); - xmlParam += "" + disposableGoods.getIdFromHisSync() + "" - + "" + disposableGoodsBatch.getBatchIdFromHisSync() + "" - + "" + invoiceItem.getAmount() + ""; - } - } - xmlParam += ""; - String result = writeBackInventoryDao.insertWriteBackForCommon(xmlParam); - JSONObject jsonReturn = JSONObject.fromObject(result); - if(!jsonReturn.optBoolean("success")){ - throw new RuntimeException(jsonReturn.optString("message")); - } - } - } - }catch(Exception e){ - e.printStackTrace(); - throw new RuntimeException(e); - } - } - } +// if(StringUtils.equalsIgnoreCase(CssdUtils.getConfigProperty("project"), "gdsy") && writeBackInventoryDao != null){ +// if(CollectionUtils.isNotEmpty(invoiceList)){ +// try{ +// for (Invoice invoice : invoiceList) { +// +// /*4 +// */ +// //发货单的发货科室-供应室 +// OrgUnit invoiceCssdOrgUnit = (OrgUnit)objectDao.getByProperty(OrgUnit.class.getSimpleName(), "orgUnitCoding", invoice.getOrgUnitCoding()); +// //发货单接收科室-申请单的临床科室 +// OrgUnit invoiceClinicOrgUnit = (OrgUnit)objectDao.getByProperty(OrgUnit.class.getSimpleName(), "orgUnitCoding", invoice.getInvoicePlan().getDepartCoding()); +// String xmlParam = "4" + invoiceCssdOrgUnit.getIdFromHisSync() + "" +// + "" + invoiceClinicOrgUnit.getIdFromHisSync() + "" +// + "INVOICE_" + invoice.getSerialNumber() + ""; +// +// if(CollectionUtils.isNotEmpty(invoice.getInvoiceItem())){ +// for(InvoiceItem invoiceItem : invoice.getInvoiceItem()){ +// if(Constants.STR_YES.equals(invoiceItem.getDiposable()) && DatabaseUtil.isPoIdValid(invoiceItem.getDisposableGoodsId())){ +// DisposableGoods disposableGoods = diposableGoodsManager.getDisposableGoodsById(String.valueOf(invoiceItem.getDisposableGoodsId())); +// DisposableGoodsBatch disposableGoodsBatch = diposableGoodsManager.getDisposableGoodsBatchById(invoiceItem.getDisposableGoodsBatchId()); +// xmlParam += "" + disposableGoods.getIdFromHisSync() + "" +// + "" + disposableGoodsBatch.getBatchIdFromHisSync() + "" +// + "" + invoiceItem.getAmount() + ""; +// } +// } +// xmlParam += ""; +// String result = writeBackInventoryDao.insertWriteBackForCommon(xmlParam); +// JSONObject jsonReturn = JSONObject.fromObject(result); +// if(!jsonReturn.optBoolean("success")){ +// throw new RuntimeException(jsonReturn.optString("message")); +// } +// } +// } +// }catch(Exception e){ +// e.printStackTrace(); +// throw new RuntimeException(e); +// } +// } +// } } public void submitInvoiceForCustom(JSONObject params) { @@ -1925,8 +1932,10 @@ if (StringUtils.isBlank(sourceWarehouseId)) { throw new RuntimeException("未指定发货仓库!"); } + submitInvoiceContext.setInvoiceType(invoiceType); String mode = JSONUtil.optString(params, "mode", ""); String departCode = JSONUtil.optString(params, "departCode", ""); + String depart = JSONUtil.optString(params, "depart", ""); if(Invoice.TYPE_APPLICATION.equals(invoiceType)){ if(Invoice.INVOICE_MODE_DEPART.equals(mode)){ if (StringUtils.isBlank(departCode)) { @@ -1936,6 +1945,7 @@ } submitInvoiceContext.setInvoiceMode(mode); submitInvoiceContext.setDepartCode(departCode); + submitInvoiceContext.setDepart(depart); submitInvoiceContext.setAssistantSender(assistantSender); submitInvoiceContext.setSender(sender); submitInvoiceContext.setSourceWarehouseId(sourceWarehouseId); @@ -1948,93 +1958,90 @@ } public void submitInvoice(JSONObject params) { - try { - String invoiceType = JSONUtil.optString(params, "invoiceType", Invoice.TYPE_APPLICATION); - switch (invoiceType) { - case Invoice.TYPE_OPERATION_RESERVATION: - submitInvoiceForOperationReservation(params); - return; - case Invoice.TYPE_CUSTOM: - submitInvoiceForCustom(params); - return; - } - - SubmitInvoiceContext submitInvoiceContext = new SubmitInvoiceContext(); - setAndValidateParams(params, submitInvoiceContext); - - List submitInvoiceItems = submitInvoiceContext.getSubmitInvoiceItems(); - List invoicePlanList = getAndLockInvoicePlans(params, - submitInvoiceContext); - - List filteredList = filterInvoicePlans(invoicePlanList); - getApplicationItemsTousseDefinitionIds(submitInvoiceContext, - filteredList); - SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); - submitInvoiceContext.setSupplyRoomConfig(supplyRoomConfig); - submitInvoiceContext.setInvoicePlanList(filteredList); - // 已扫描的条码集合 - getBarcodes(submitInvoiceItems,submitInvoiceContext); - // 锁定器械包 - lockTousseInstances2(submitInvoiceContext); - // 锁定一次性物品 - lockDiposableGoods2(submitInvoiceContext); - // 自动扣减的一次性物品id - Set disposableGoodsIds = TousseInstanceUtils.getDisposableGoodsIds(objectDao, submitInvoiceContext.getScannedTousseInstances()); - DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext.getAutoDeductionDisposableGoodsServiceContext(); - autoDeductionDisposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE_AUTO_DEDUCTION); - autoDeductionDisposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); - autoDeductionDisposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIds); - diposableGoodsManager.lockAndGetDisposableGoodsResources(autoDeductionDisposableGoodsServiceContext); - // 统计发货数据 - summarySendOutInfo(submitInvoiceItems, submitInvoiceContext); - // 第一次循环发货紧急物品 - submitInvoiceContext.setSendOnlyUrgentGoods(true); - for (InvoicePlan invoicePlan : filteredList) { - // 判断如果扫描的物品已经发完货,那么剩下的单就不需要再遍历处理了 - if(isSendOutCompletely(submitInvoiceContext)){ - break; - } - invoice( invoicePlan, submitInvoiceContext); + String invoiceType = JSONUtil.optString(params, "invoiceType", Invoice.TYPE_APPLICATION); + switch (invoiceType) { + case Invoice.TYPE_OPERATION_RESERVATION: + submitInvoiceForOperationReservation(params); + return; + case Invoice.TYPE_CUSTOM: + submitInvoiceForCustom(params); + return; + } + + SubmitInvoiceContext submitInvoiceContext = new SubmitInvoiceContext(); + setAndValidateParams(params, submitInvoiceContext); + + List submitInvoiceItems = submitInvoiceContext.getSubmitInvoiceItems(); + List invoicePlanList = getAndLockInvoicePlans(params, + submitInvoiceContext); + + List filteredList = filterInvoicePlans(invoicePlanList); + getApplicationItemsTousseDefinitionIds(submitInvoiceContext, + filteredList); + SupplyRoomConfig supplyRoomConfig = supplyRoomConfigManager.getSystemParamsObj(); + submitInvoiceContext.setSupplyRoomConfig(supplyRoomConfig); + submitInvoiceContext.setInvoicePlanList(filteredList); + // 已扫描的条码集合 + getBarcodes(submitInvoiceItems,submitInvoiceContext); + // 锁定器械包 + lockTousseInstances2(submitInvoiceContext); + // 锁定一次性物品 + lockDiposableGoods2(submitInvoiceContext); + // 自动扣减的一次性物品id + Set disposableGoodsIds = TousseInstanceUtils.getDisposableGoodsIds(objectDao, submitInvoiceContext.getScannedTousseInstances()); + DisposableGoodsServiceContext autoDeductionDisposableGoodsServiceContext = submitInvoiceContext.getAutoDeductionDisposableGoodsServiceContext(); + autoDeductionDisposableGoodsServiceContext.setScene(DisposableGoodsServiceContext.SCENE_INVOICE_AUTO_DEDUCTION); + autoDeductionDisposableGoodsServiceContext.setWarehouseId(submitInvoiceContext.getSourceWarehouseId()); + autoDeductionDisposableGoodsServiceContext.getDisposableGoodsIdsSet().addAll(disposableGoodsIds); + diposableGoodsManager.lockAndGetDisposableGoodsResources(autoDeductionDisposableGoodsServiceContext); + // 统计发货数据 + summarySendOutInfo(submitInvoiceItems, submitInvoiceContext); + + // 第一次循环发货紧急物品 + submitInvoiceContext.setSendOnlyUrgentGoods(true); + for (InvoicePlan invoicePlan : filteredList) { + // 判断如果扫描的物品已经发完货,那么剩下的单就不需要再遍历处理了 + if(isSendOutCompletely(submitInvoiceContext)){ + break; } - // 开始发货非紧急物品 - submitInvoiceContext.setSendOnlyUrgentGoods(false); - for (InvoicePlan invoicePlan : filteredList) { - if(invoicePlan.delivered() || invoicePlan.deliverEnd()){ - continue; - } - // 判断如果扫描的物品已经发完货,那么剩下的单就不需要再遍历处理了 - if(isSendOutCompletely(submitInvoiceContext)){ - break; - } - invoice( invoicePlan, submitInvoiceContext); + invoice( invoicePlan, submitInvoiceContext); + } + // 开始发货非紧急物品 + submitInvoiceContext.setSendOnlyUrgentGoods(false); + for (InvoicePlan invoicePlan : filteredList) { + if(invoicePlan.delivered() || invoicePlan.deliverEnd()){ + continue; } - List invoiceList = submitInvoiceContext.getInvoiceList(); - Map> updateStockInfo = submitInvoiceContext.getUpdateStockInfo();// 用于更新库存的信息 - // 更新器械包库存 -// updateGoodsStock(updateStockInfo); - // 更新其他单的状态 - updateOtherInvoicePlanStatus(submitInvoiceContext); - // 更新仓库的库存 - updateTousseInstanceStockInwareHouse(updateStockInfo, submitInvoiceContext.getSourceWarehouseId()); - - // 检查是否已完全发货 -// for (Map.Entry entry : sendOutAmountMap.entrySet()) { -// if(entry.getValue().intValue() > 0){ -// throw new RuntimeException(String.format("物品%s库存不足,发货失败!", entry.getKey())); -// } -// } - if (CollectionUtils.isEmpty(invoiceList)) - throw new RuntimeException("未能发货!"); - - refreshReviewedBasketStatus(submitInvoiceItems); - writebackForZSLY(invoiceList); - - writebackForGDSY(invoiceList); - } catch (RuntimeException ex) { - ex.printStackTrace(); - throw ex; + // 判断如果扫描的物品已经发完货,那么剩下的单就不需要再遍历处理了 + if(isSendOutCompletely(submitInvoiceContext)){ + break; + } + invoice( invoicePlan, submitInvoiceContext); } + List invoiceList = submitInvoiceContext.getInvoiceList(); + Map> updateStockInfo = submitInvoiceContext.getUpdateStockInfo();// 用于更新库存的信息 + // 更新器械包库存 +// updateGoodsStock(updateStockInfo); + // 更新其他单的状态 + updateOtherInvoicePlanStatus(submitInvoiceContext); + // 更新仓库的库存 + updateTousseInstanceStockInwareHouse(updateStockInfo, submitInvoiceContext.getSourceWarehouseId()); + + // 检查是否已完全发货 +// for (Map.Entry entry : sendOutAmountMap.entrySet()) { +// if(entry.getValue().intValue() > 0){ +// throw new RuntimeException(String.format("物品%s库存不足,发货失败!", entry.getKey())); +// } +// } + if (CollectionUtils.isEmpty(invoiceList)) + throw new RuntimeException("未能发货!"); + + refreshReviewedBasketStatus(submitInvoiceItems); + writebackForZSLY(invoiceList); + + writebackForGDSY(invoiceList); + } /** @@ -2204,7 +2211,10 @@ invoiceItem .setDisposableGoodsType(DisposableGoods.TYPE_DIPOSABLEGOODS); // invoiceItem.setInvoiceID(invoice.getId()); - invoiceItem.setInvoicePlanID(invoicePlan.getId()); + if(invoicePlan != null){ + invoiceItem.setInvoicePlanID(invoicePlan.getId()); + } + invoiceItem.setTousseName(diposableGoods .getShowName()); invoiceItem @@ -2309,357 +2319,509 @@ InvoicePlan invoicePlan, Set invoiceItems, SubmitInvoiceContext submitInvoiceContext) { - String sourceWarehouseName = submitInvoiceContext.getSourceWarehouseName(); + String sourceWarehouseName = submitInvoiceContext + .getSourceWarehouseName(); if (CollectionUtils.isEmpty(invoiceItems)) { return null; } - Map sendOutBarcodeAmount = submitInvoiceContext.getSendOutBarcodeToAmountMap(); - Map barcodeObjMap = submitInvoiceContext.getBarcodeToBarcodeDeviceMap(); - Map barcodeToDisposableGoodsBatchStockMap = submitInvoiceContext.getDisposableGoodsServiceContext().getBarcodeToDisposableGoodsBatchStockMap(); + Map sendOutBarcodeAmount = submitInvoiceContext + .getSendOutBarcodeToAmountMap(); + Map barcodeObjMap = submitInvoiceContext + .getBarcodeToBarcodeDeviceMap(); + Map barcodeToDisposableGoodsBatchStockMap = submitInvoiceContext + .getDisposableGoodsServiceContext() + .getBarcodeToDisposableGoodsBatchStockMap(); Invoice invoice = new Invoice(); List diposableGoodsItems = new ArrayList(); // 获得浮动价格系数 - double floatPercent = supplyRoomConfigManager.getDisposableGoodsFluctuationPercent(); + double floatPercent = supplyRoomConfigManager + .getDisposableGoodsFluctuationPercent(); BigDecimal totalPrice = new BigDecimal(0.00); - String invoicePlanType = invoicePlan.getType(); - { - for (InvoiceItem invoiceItem : invoiceItems) { - // 先保存invoiceItem,以后需要invoiceItemID - objectDao.save(invoiceItem); - int amountAwaitingSent = invoiceItem.getAmount(); - // 一次性物品 - if (InvoiceItem.DIPOSABLE_YES.equals(invoiceItem.getDiposable())) { - if(invoiceItem.expensiveDisposablegoods()){// 高值耗材 - List expensiveDisposablegoodsList = invoiceItem.getExpensiveDisposablegoods(); - for (ExpensiveDisposablegoods expensiveDisposablegoods : expensiveDisposablegoodsList) { - if(!expensiveDisposablegoods.inWarehouse()){ - throw new RuntimeException(String.format("条码为[%s]的高值耗材状态为%s,不能发货", expensiveDisposablegoods.getBarcode(),expensiveDisposablegoods.getStatus())); - } - DisposableGoodsBatchStock disposableGoodsBatchStock = expensiveDisposablegoods.getDisposableGoodsBatchStock(); - expensiveDisposablegoods.setStatus(ExpensiveDisposablegoods.STATUS_DELIVERED); - expensiveDisposablegoods.adjustAmount(-1); - --amountAwaitingSent; - expensiveDisposablegoods.setInvoiceItemId(invoiceItem.getId());// 明细汇总关联 - - //记录高值耗材位置 - expensiveDisposablegoods.setLocation(invoicePlan.getDepartCoding()); - expensiveDisposablegoods.setLocationForDisplay(invoicePlan.getDepart()); - - invoiceItem.setDisposableGoodsId(expensiveDisposablegoods.getDisposableGoodsID()); - invoiceItem.setDisposableGoodsStockId(expensiveDisposablegoods.getDisposableGoodsStockID()); - invoiceItem.setDisposableGoodsBatchId(expensiveDisposablegoods.getDisposableGoodsBatchID()); - invoiceItem.setDisposableGoodsBatchStockId(disposableGoodsBatchStock.getId()); - Double price = expensiveDisposablegoods.getPrice(); - BigDecimal fluctuationPrice = MathTools.mul( - price, floatPercent).setScale( - 4, BigDecimal.ROUND_HALF_UP); - DiposableGoodsItem diposableGoodsItem = new DiposableGoodsItem(); - diposableGoodsItem.setAmount(1); - diposableGoodsItem.setFluctuationPrice(fluctuationPrice - .doubleValue()); - diposableGoodsItem.setPrice(price); - diposableGoodsItem.setName(invoiceItem.getTousseName()); - diposableGoodsItem.setBarcode(invoiceItem.getBarcode()); - diposableGoodsItem.setExpensiveDGBarcode(invoiceItem.getExpensiveDGBarcode()); - diposableGoodsItem.setBatch(invoiceItem.getBatchNumber()); - diposableGoodsItem.setDisposableGoodsID(expensiveDisposablegoods.getDisposableGoodsID()); - diposableGoodsItem.setDisposableGoodsStockID(expensiveDisposablegoods.getDisposableGoodsStockID()); - diposableGoodsItem.setDisposableGoodsBatchID(expensiveDisposablegoods.getDisposableGoodsBatchID()); - diposableGoodsItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStock.getId()); - diposableGoodsItem.setExpensiveDisposablegoodsId(expensiveDisposablegoods.getId()); - diposableGoodsItem.setInvoice(invoice);// 和发货单关联 - diposableGoodsItem.setInvoiceItemID(invoiceItem.getId());// 明细汇总关联 - if(!diposableGoodsItem.isAssociatedInfoValidForExpensiveDisposablegoodsInvoice()){ - throw new RuntimeException("关联信息不正确!"); - } - diposableGoodsItems.add(diposableGoodsItem); - // 发货物品单项总价 - BigDecimal itemPrice = fluctuationPrice.multiply( - new BigDecimal(diposableGoodsItem.getAmount())) - .setScale(4, BigDecimal.ROUND_HALF_UP); + String invoicePlanType = ""; + if (invoicePlan != null) { + invoicePlanType = invoicePlan.getType(); + } + String departCoding = submitInvoiceContext.getDepartCode(); + String depart = submitInvoiceContext.getDepart(); + String settleAccountsDepart = submitInvoiceContext.getDepart(); - // 发货物品统计总价 - totalPrice = totalPrice.add(itemPrice).setScale(4, - BigDecimal.ROUND_HALF_UP); - double tmpSettlementPrice = invoiceItem - .getSettlementPrice() + itemPrice.doubleValue(); - invoiceItem.setSettlementPrice(tmpSettlementPrice); - + Date date = new Date(); + String applicant = null; + Date applicationTime = null; + Date recyclingTime = null; + if (invoicePlan != null) { + departCoding = invoicePlan.getDepartCoding(); + depart = invoicePlan.getDepart(); + applicant = invoicePlan.getApplicant(); + applicationTime = invoicePlan.getApplicationTime(); + recyclingTime = invoicePlan.getRecyclingTime(); + settleAccountsDepart = invoicePlan.getSettleAccountsDepart(); + } else { + applicationTime = date; + recyclingTime = date; + } + invoice.setDepartCoding(departCoding); + for (InvoiceItem invoiceItem : invoiceItems) { + // 先保存invoiceItem,以后需要invoiceItemID + objectDao.save(invoiceItem); + int amountAwaitingSent = invoiceItem.getAmount(); + // 一次性物品 + if (InvoiceItem.DIPOSABLE_YES.equals(invoiceItem.getDiposable())) { + if (invoiceItem.expensiveDisposablegoods()) {// 高值耗材 + List expensiveDisposablegoodsList = invoiceItem + .getExpensiveDisposablegoods(); + for (ExpensiveDisposablegoods expensiveDisposablegoods : expensiveDisposablegoodsList) { + if (!expensiveDisposablegoods.inWarehouse()) { + throw new RuntimeException(String.format( + "条码为[%s]的高值耗材状态为%s,不能发货", + expensiveDisposablegoods.getBarcode(), + expensiveDisposablegoods.getStatus())); } - }else{ - String barcode = invoiceItem.getBarcode(); - BarcodeDevice barcodeDevice = barcodeObjMap.get(invoiceItem - .getBarcode()); - if (!(barcodeDevice instanceof DisposableGoodsBatch)) { - throw new RuntimeException(String.format("申请单[%s]上物品[%s]的类型与条码[%s]不匹配!",invoicePlan.getSerialNumber(), invoiceItem.getTousseName(),barcode)); + DisposableGoodsBatchStock disposableGoodsBatchStock = expensiveDisposablegoods + .getDisposableGoodsBatchStock(); + expensiveDisposablegoods + .setStatus(ExpensiveDisposablegoods.STATUS_DELIVERED); + expensiveDisposablegoods.adjustAmount(-1); + --amountAwaitingSent; + expensiveDisposablegoods.setInvoiceItemId(invoiceItem + .getId());// 明细汇总关联 + + // 记录高值耗材位置 + expensiveDisposablegoods.setLocation(departCoding); + expensiveDisposablegoods.setLocationForDisplay(depart); + + invoiceItem + .setDisposableGoodsId(expensiveDisposablegoods + .getDisposableGoodsID()); + invoiceItem + .setDisposableGoodsStockId(expensiveDisposablegoods + .getDisposableGoodsStockID()); + invoiceItem + .setDisposableGoodsBatchId(expensiveDisposablegoods + .getDisposableGoodsBatchID()); + invoiceItem + .setDisposableGoodsBatchStockId(disposableGoodsBatchStock + .getId()); + Double price = expensiveDisposablegoods.getPrice(); + BigDecimal fluctuationPrice = MathTools.mul(price, + floatPercent).setScale(4, + BigDecimal.ROUND_HALF_UP); + DiposableGoodsItem diposableGoodsItem = new DiposableGoodsItem(); + diposableGoodsItem.setAmount(1); + diposableGoodsItem.setFluctuationPrice(fluctuationPrice + .doubleValue()); + diposableGoodsItem.setPrice(price); + diposableGoodsItem.setName(invoiceItem.getTousseName()); + diposableGoodsItem.setBarcode(invoiceItem.getBarcode()); + diposableGoodsItem.setExpensiveDGBarcode(invoiceItem + .getExpensiveDGBarcode()); + diposableGoodsItem.setBatch(invoiceItem + .getBatchNumber()); + diposableGoodsItem + .setDisposableGoodsID(expensiveDisposablegoods + .getDisposableGoodsID()); + diposableGoodsItem + .setDisposableGoodsStockID(expensiveDisposablegoods + .getDisposableGoodsStockID()); + diposableGoodsItem + .setDisposableGoodsBatchID(expensiveDisposablegoods + .getDisposableGoodsBatchID()); + diposableGoodsItem + .setDisposableGoodsBatchStockID(disposableGoodsBatchStock + .getId()); + diposableGoodsItem + .setExpensiveDisposablegoodsId(expensiveDisposablegoods + .getId()); + diposableGoodsItem.setInvoice(invoice);// 和发货单关联 + diposableGoodsItem + .setInvoiceItemID(invoiceItem.getId());// 明细汇总关联 + if (!diposableGoodsItem + .isAssociatedInfoValidForExpensiveDisposablegoodsInvoice()) { + throw new RuntimeException("关联信息不正确!"); } - DisposableGoodsBatch diposableGoodBatch = (DisposableGoodsBatch) barcodeDevice; - DisposableGoodsBatchStock disposableGoodsBatchStock = barcodeToDisposableGoodsBatchStockMap.get(barcode); - if(disposableGoodsBatchStock == null){ - throw new RuntimeException(String.format("数据异常,物品[%s]在仓库[%s]中的批次库存[条码为 %s]不存在!", invoiceItem.getTousseName(),sourceWarehouseName,barcode)); + diposableGoodsItems.add(diposableGoodsItem); + // 发货物品单项总价 + BigDecimal itemPrice = fluctuationPrice.multiply( + new BigDecimal(diposableGoodsItem.getAmount())) + .setScale(4, BigDecimal.ROUND_HALF_UP); + + // 发货物品统计总价 + totalPrice = totalPrice.add(itemPrice).setScale(4, + BigDecimal.ROUND_HALF_UP); + double tmpSettlementPrice = invoiceItem + .getSettlementPrice() + itemPrice.doubleValue(); + invoiceItem.setSettlementPrice(tmpSettlementPrice); + + } + } else { + String barcode = invoiceItem.getBarcode(); + BarcodeDevice barcodeDevice = barcodeObjMap.get(invoiceItem + .getBarcode()); + if (!(barcodeDevice instanceof DisposableGoodsBatch)) { + throw new RuntimeException(String.format( + "申请单[%s]上物品[%s]的类型与条码[%s]不匹配!", + invoicePlan.getSerialNumber(), + invoiceItem.getTousseName(), barcode)); + } + DisposableGoodsBatch diposableGoodBatch = (DisposableGoodsBatch) barcodeDevice; + DisposableGoodsBatchStock disposableGoodsBatchStock = barcodeToDisposableGoodsBatchStockMap + .get(barcode); + if (disposableGoodsBatchStock == null) { + throw new RuntimeException(String.format( + "数据异常,物品[%s]在仓库[%s]中的批次库存[条码为 %s]不存在!", + invoiceItem.getTousseName(), + sourceWarehouseName, barcode)); + } + + // 获得价格 + List identifications = disposableGoodsBatchStock + .getIdentifications(); + // TODO:排序问题 + Collections.sort(identifications); + + DiposableGoodsItem diposableGoodsItem = null; + // 处理同一批次多个标识号是否够减 + for (DisposableGoodsIdentification identification : identifications) { + if (identification.getAmount() <= 0) { + continue; } + if (amountAwaitingSent <= 0) { + break; + } + if (identification.getAmount() < amountAwaitingSent) { + diposableGoodsItem = new DiposableGoodsItem(); + diposableGoodsItem.setAmount(Integer + .valueOf(identification.getAmount() + .intValue())); + } else { + diposableGoodsItem = new DiposableGoodsItem(); + diposableGoodsItem.setAmount(amountAwaitingSent); + } + amountAwaitingSent -= diposableGoodsItem.getAmount(); + BigDecimal fluctuationPrice = MathTools.mul( + identification.getPrice(), floatPercent) + .setScale(4, BigDecimal.ROUND_HALF_UP); + diposableGoodsItem.setFluctuationPrice(fluctuationPrice + .doubleValue()); + diposableGoodsItem.setPrice(identification.getPrice()); + diposableGoodsItem.setName(invoiceItem.getTousseName()); + diposableGoodsItem.setBarcode(barcode); + diposableGoodsItem.setBatch(diposableGoodBatch + .getBatchNumber()); + diposableGoodsItem + .setDisposableGoodsID(disposableGoodsBatchStock + .getDisposableGoodsId()); + diposableGoodsItem + .setDisposableGoodsStockID(disposableGoodsBatchStock + .getDisposableGoodsStockId()); + diposableGoodsItem + .setDisposableGoodsBatchID(disposableGoodsBatchStock + .getDisposableGoodsBatchId()); + diposableGoodsItem + .setDisposableGoodsBatchStockID(disposableGoodsBatchStock + .getId()); + diposableGoodsItem.setIdentificationID(identification + .getId());// 标识id关联,这样可以在修改库存价格时做联动修改,jeff li + diposableGoodsItem.setInvoice(invoice);// 和发货单关联 + diposableGoodsItem + .setInvoiceItemID(invoiceItem.getId());// 明细汇总关联 + if (!diposableGoodsItem + .isAssociatedInfoValidForInvoice()) { + throw new RuntimeException("关联信息不正确!"); + } + diposableGoodsItems.add(diposableGoodsItem); - // 获得价格 - List identifications = disposableGoodsBatchStock - .getIdentifications(); - // TODO:排序问题 - Collections.sort(identifications); + // 库存调整 + long amountChange = diposableGoodsItem.getAmount(); + identification.adjustAmount(-amountChange); + // 待更新库存 + objectDao.update(identification); + objectDao.update(disposableGoodsBatchStock); + objectDao.update(disposableGoodsBatchStock + .getDiposableGoods()); + // 发货物品单项总价 + BigDecimal itemPrice = fluctuationPrice.multiply( + new BigDecimal(diposableGoodsItem.getAmount())) + .setScale(4, BigDecimal.ROUND_HALF_UP); - DiposableGoodsItem diposableGoodsItem = null; - // 处理同一批次多个标识号是否够减 - for (DisposableGoodsIdentification identification : identifications) { - if (identification.getAmount() <= 0) { - continue; + // 发货物品统计总价 + totalPrice = totalPrice.add(itemPrice).setScale(4, + BigDecimal.ROUND_HALF_UP); + double tmpSettlementPrice = invoiceItem + .getSettlementPrice() + itemPrice.doubleValue(); + invoiceItem.setSettlementPrice(tmpSettlementPrice); + } + invoiceItem.setDisposableGoodsId(disposableGoodsBatchStock + .getDisposableGoodsId()); + invoiceItem + .setDisposableGoodsStockId(disposableGoodsBatchStock + .getDisposableGoodsStockId()); + invoiceItem + .setDisposableGoodsBatchId(disposableGoodsBatchStock + .getDisposableGoodsBatchId()); + invoiceItem + .setDisposableGoodsBatchStockId(disposableGoodsBatchStock + .getId()); + } + + // 器械包 + } else { + Set tousseInstancesToUpdate = submitInvoiceContext + .getTousseInstancesToUpdate(); + int sentAmount = amountAwaitingSent; + if (InvoicePlan.TYPE_FOREIGNPROXYDISINFECTION + .equals(invoicePlanType)) { + // 外部代理灭菌 + BigDecimal itemPrice = new BigDecimal(0.00); + Collection tousseInstanceList = invoiceItem + .getTousseInstances(); + for (TousseInstance tousseInstance : tousseInstanceList) { + itemPrice = addItemPriceToTotal( + tousseInstance.getPrice(), 1, itemPrice); + totalPrice = addItemPriceToTotal( + tousseInstance.getPrice(), 1, totalPrice); + tousseInstancesToUpdate.add(tousseInstance); + --amountAwaitingSent; + } + invoiceItem.setSettlementPrice(invoiceItem + .getSettlementPrice() + itemPrice.doubleValue()); + } else if (InvoicePlan.TYPE_FOREIGNTOUSSEAPPLIACTION + .equals(invoicePlanType)) { + // 外来器械申请单 + BigDecimal itemPrice = new BigDecimal(0.00); + Collection tousseInstanceList = invoiceItem + .getTousseInstances(); + for (TousseInstance tousseInstance : tousseInstanceList) { + itemPrice = addItemPriceToTotal( + tousseInstance.getPrice(), 1, itemPrice); + totalPrice = addItemPriceToTotal( + tousseInstance.getPrice(), 1, totalPrice); + tousseInstancesToUpdate.add(tousseInstance); + --amountAwaitingSent; + } + invoiceItem.setSettlementPrice(invoiceItem + .getSettlementPrice() + itemPrice.doubleValue()); + } else { + TousseInstance invoiceTousseInstance = invoiceItem + .getTousseInstance(); + if (invoiceTousseInstance != null) { + BigDecimal itemPrice = new BigDecimal(0.00); + Set tousseInstancesSet = new HashSet(); + if (invoiceTousseInstance.getTousseFixedBarcode()) { + List tousseInstanceList = invoiceItem + .getTousseInstances(); + if (tousseInstanceList != null) { + tousseInstancesSet.addAll(tousseInstanceList); + for (TousseInstance tousseInstance : tousseInstancesSet) { + if (amountAwaitingSent <= 0) { + break; + } + if (!tousseInstance.canInvoice()) { + continue; + } + itemPrice = addItemPriceToTotal( + tousseInstance.getPrice(), 1, + itemPrice); + totalPrice = addItemPriceToTotal( + tousseInstance.getPrice(), 1, + totalPrice); + tousseInstancesToUpdate.add(tousseInstance); + amountAwaitingSent--; + } } + if (amountAwaitingSent > 0) { + throw new RuntimeException(String.format( + "固定条码物品%s库存不足!", + invoiceItem.getTousseName())); + } + } else { + String barcode = invoiceTousseInstance.getBarcode(); + int amount = invoiceItem.getAmount(); + // 数量必须为1 + if (amount != 1) { + throw new RuntimeException(String.format( + "器械包[%s]条码[%s]发货数量必须为1,实际为%s!", + invoiceItem.getTousseName(), + invoiceTousseInstance.getBarcode(), + amount)); + } + + itemPrice = addItemPriceToTotal( + invoiceTousseInstance.getPrice(), amount, + itemPrice); + totalPrice = addItemPriceToTotal( + invoiceTousseInstance.getPrice(), amount, + totalPrice); + sendOutBarcodeAmount.put(barcode, 0); + tousseInstancesToUpdate.add(invoiceTousseInstance); + amountAwaitingSent--; + } + } else { + for (Entry sendOutBarcodeAmountEntry : sendOutBarcodeAmount + .entrySet()) { if (amountAwaitingSent <= 0) { break; } - if (identification.getAmount() < amountAwaitingSent) { - diposableGoodsItem = new DiposableGoodsItem(); - diposableGoodsItem.setAmount(Integer.valueOf(identification.getAmount().intValue())); - } else { - diposableGoodsItem = new DiposableGoodsItem(); - diposableGoodsItem.setAmount(amountAwaitingSent); + String barcode = sendOutBarcodeAmountEntry.getKey(); + BarcodeDevice barcodeDevice = barcodeObjMap + .get(barcode); + if (!(barcodeDevice instanceof TousseInstance)) { + continue; } - amountAwaitingSent -= diposableGoodsItem.getAmount(); - BigDecimal fluctuationPrice = MathTools.mul( - identification.getPrice(), floatPercent).setScale( - 4, BigDecimal.ROUND_HALF_UP); - diposableGoodsItem.setFluctuationPrice(fluctuationPrice - .doubleValue()); - diposableGoodsItem.setPrice(identification.getPrice()); - diposableGoodsItem.setName(invoiceItem.getTousseName()); - diposableGoodsItem.setBarcode(barcode); - diposableGoodsItem.setBatch(diposableGoodBatch - .getBatchNumber()); - diposableGoodsItem.setDisposableGoodsID(disposableGoodsBatchStock.getDisposableGoodsId()); - diposableGoodsItem.setDisposableGoodsStockID(disposableGoodsBatchStock.getDisposableGoodsStockId()); - diposableGoodsItem.setDisposableGoodsBatchID(disposableGoodsBatchStock.getDisposableGoodsBatchId()); - diposableGoodsItem.setDisposableGoodsBatchStockID(disposableGoodsBatchStock.getId()); - diposableGoodsItem.setIdentificationID(identification.getId());// 标识id关联,这样可以在修改库存价格时做联动修改,jeff li - diposableGoodsItem.setInvoice(invoice);// 和发货单关联 - diposableGoodsItem.setInvoiceItemID(invoiceItem.getId());// 明细汇总关联 - if(!diposableGoodsItem.isAssociatedInfoValidForInvoice()){ - throw new RuntimeException("关联信息不正确!"); + TousseInstance tousseInstance = (TousseInstance) barcodeDevice; + int amountAwaitSend = sendOutBarcodeAmountEntry + .getValue(); + String instanceName = tousseInstance + .getTousseName(); + if (!instanceName.equals(invoiceItem + .getTousseName()) || amountAwaitSend <= 0) { + continue; } - diposableGoodsItems.add(diposableGoodsItem); - - // 库存调整 - long amountChange = diposableGoodsItem.getAmount(); - identification.adjustAmount(-amountChange); - // 待更新库存 - objectDao.update(identification); - objectDao.update(disposableGoodsBatchStock); - objectDao.update(disposableGoodsBatchStock.getDiposableGoods()); - // 发货物品单项总价 - BigDecimal itemPrice = fluctuationPrice.multiply( - new BigDecimal(diposableGoodsItem.getAmount())) - .setScale(4, BigDecimal.ROUND_HALF_UP); - // 发货物品统计总价 - totalPrice = totalPrice.add(itemPrice).setScale(4, - BigDecimal.ROUND_HALF_UP); - double tmpSettlementPrice = invoiceItem - .getSettlementPrice() + itemPrice.doubleValue(); - invoiceItem.setSettlementPrice(tmpSettlementPrice); - } - invoiceItem.setDisposableGoodsId(disposableGoodsBatchStock.getDisposableGoodsId()); - invoiceItem.setDisposableGoodsStockId(disposableGoodsBatchStock.getDisposableGoodsStockId()); - invoiceItem.setDisposableGoodsBatchId(disposableGoodsBatchStock.getDisposableGoodsBatchId()); - invoiceItem.setDisposableGoodsBatchStockId(disposableGoodsBatchStock.getId()); - } - - // 器械包 - } else { - Set tousseInstancesToUpdate = submitInvoiceContext.getTousseInstancesToUpdate(); - int sentAmount = amountAwaitingSent; - if (InvoicePlan.TYPE_FOREIGNPROXYDISINFECTION.equals(invoicePlanType)) { - // 外部代理灭菌 - BigDecimal itemPrice = new BigDecimal(0.00); - Collection tousseInstanceList = invoiceItem.getTousseInstances(); - for (TousseInstance tousseInstance : tousseInstanceList) { - itemPrice = addItemPriceToTotal(tousseInstance.getPrice(), 1, itemPrice); - totalPrice = addItemPriceToTotal(tousseInstance.getPrice(), 1, totalPrice); - tousseInstancesToUpdate.add(tousseInstance); - --amountAwaitingSent; - } - invoiceItem.setSettlementPrice(invoiceItem - .getSettlementPrice() + itemPrice.doubleValue()); - }else if (InvoicePlan.TYPE_FOREIGNTOUSSEAPPLIACTION.equals(invoicePlanType)) { - // 外来器械申请单 - BigDecimal itemPrice = new BigDecimal(0.00); - Collection tousseInstanceList = invoiceItem.getTousseInstances(); - for (TousseInstance tousseInstance : tousseInstanceList) { - itemPrice = addItemPriceToTotal(tousseInstance.getPrice(), 1, itemPrice); - totalPrice = addItemPriceToTotal(tousseInstance.getPrice(), 1, totalPrice); - tousseInstancesToUpdate.add(tousseInstance); - --amountAwaitingSent; - } - invoiceItem.setSettlementPrice(invoiceItem - .getSettlementPrice() + itemPrice.doubleValue()); - }else{ - TousseInstance invoiceTousseInstance = invoiceItem.getTousseInstance(); - if(invoiceTousseInstance != null){ + // 代理灭菌单发货单要与条码关联 + if (InvoicePlan.TYPE_PROXYDISINFECTION + .equals(invoicePlanType)) { + if (!String.valueOf( + tousseInstance + .getProxyDisinfection_id()) + .equals(String.valueOf(invoicePlan + .getId()))) { + continue; + } + } + BigDecimal itemPrice = new BigDecimal(0.00); - Set tousseInstancesSet = new HashSet(); - if(invoiceTousseInstance.getTousseFixedBarcode()){ - List tousseInstanceList = invoiceItem.getTousseInstances(); - if(tousseInstanceList != null){ - tousseInstancesSet.addAll(tousseInstanceList); - for (TousseInstance tousseInstance : tousseInstancesSet) { + // 不追溯的固定条码的发货处理 + if (tousseInstance.getTousseFixedBarcode()) { + Collection tousseInstanceList; + Set tousseInstancesSet = new HashSet(); + if (tousseInstance.getTousseDefinition() + .isDisinfection()) { + // 消毒物品,要获取本发货计划的包实例 + // tousseInstanceList = + // getCanInvoiceTousseInstancesByFixedDisinfectionTousseInstance(invoicePlan,tousseInstance,invoiceItem.getAmount()); + tousseInstanceList = invoiceItem + .getTousseInstances(); + } else { + // 普通的器械包 + tousseInstanceList = getCanInvoiceTousseInstancesByFixedTousseInstance( + tousseInstance, amountAwaitingSent); + } + if (tousseInstanceList != null) { + tousseInstancesSet + .addAll(tousseInstanceList); + for (TousseInstance disinfectionTousseInstance : tousseInstancesSet) { if (amountAwaitingSent <= 0) { break; } - if(!tousseInstance.canInvoice()){ + if (!disinfectionTousseInstance + .canInvoice()) { continue; } - itemPrice = addItemPriceToTotal(tousseInstance.getPrice(), 1, itemPrice); - totalPrice = addItemPriceToTotal(tousseInstance.getPrice(), 1, totalPrice); - tousseInstancesToUpdate.add(tousseInstance); + itemPrice = addItemPriceToTotal( + disinfectionTousseInstance + .getPrice(), + 1, itemPrice); + totalPrice = addItemPriceToTotal( + disinfectionTousseInstance + .getPrice(), + 1, totalPrice); + tousseInstancesToUpdate + .add(disinfectionTousseInstance); amountAwaitingSent--; } } - if(amountAwaitingSent > 0 ){ - throw new RuntimeException(String.format("固定条码物品%s库存不足!", invoiceItem.getTousseName())); + if (amountAwaitingSent > 0) { + throw new RuntimeException(String.format( + "固定条码物品%s库存不足!", + invoiceItem.getTousseName())); } - }else{ - String barcode = invoiceTousseInstance.getBarcode(); - int amount = invoiceItem.getAmount(); + sendOutBarcodeAmount.put(barcode, + amountAwaitSend - sentAmount); + } else { + int amount = sendOutBarcodeAmountEntry + .getValue(); // 数量必须为1 - if(amount != 1){ - throw new RuntimeException(String.format("器械包[%s]条码[%s]发货数量必须为1,实际为%s!", invoiceItem.getTousseName(),invoiceTousseInstance.getBarcode(),amount)); + if (amount != 1) { + throw new RuntimeException(String.format( + "器械包[%s]条码[%s]发货数量必须为1,实际为%s!", + invoiceItem.getTousseName(), + barcode, amount)); } - - itemPrice = addItemPriceToTotal(invoiceTousseInstance.getPrice(), amount, itemPrice); - totalPrice = addItemPriceToTotal(invoiceTousseInstance.getPrice(), amount, totalPrice); + itemPrice = addItemPriceToTotal( + tousseInstance.getPrice(), amount, + itemPrice); + totalPrice = addItemPriceToTotal( + tousseInstance.getPrice(), amount, + totalPrice); sendOutBarcodeAmount.put(barcode, 0); - tousseInstancesToUpdate.add(invoiceTousseInstance); + tousseInstancesToUpdate.add(tousseInstance); amountAwaitingSent--; } - }else{ - for (Entry sendOutBarcodeAmountEntry : sendOutBarcodeAmount - .entrySet()) { - if (amountAwaitingSent <= 0) { - break; - } - String barcode = sendOutBarcodeAmountEntry.getKey(); - BarcodeDevice barcodeDevice = barcodeObjMap.get(barcode); - if (!(barcodeDevice instanceof TousseInstance)) { - continue; - } - TousseInstance tousseInstance = (TousseInstance) barcodeDevice; - int amountAwaitSend = sendOutBarcodeAmountEntry.getValue(); - String instanceName = tousseInstance.getTousseName(); - if (!instanceName.equals(invoiceItem.getTousseName()) - || amountAwaitSend <= 0) { - continue; - } - - // 代理灭菌单发货单要与条码关联 - if (InvoicePlan.TYPE_PROXYDISINFECTION - .equals(invoicePlanType)) { - if (!String.valueOf(tousseInstance.getProxyDisinfection_id()) - .equals(String.valueOf(invoicePlan.getId()))) { - continue; - } - } - - BigDecimal itemPrice = new BigDecimal(0.00); - // 不追溯的固定条码的发货处理 - if(tousseInstance.getTousseFixedBarcode()){ - Collection tousseInstanceList; - Set tousseInstancesSet = new HashSet(); - if(tousseInstance.getTousseDefinition().isDisinfection()){ - // 消毒物品,要获取本发货计划的包实例 -// tousseInstanceList = getCanInvoiceTousseInstancesByFixedDisinfectionTousseInstance(invoicePlan,tousseInstance,invoiceItem.getAmount()); - tousseInstanceList = invoiceItem.getTousseInstances(); - }else{ - // 普通的器械包 - tousseInstanceList = getCanInvoiceTousseInstancesByFixedTousseInstance(tousseInstance,amountAwaitingSent); - } - if(tousseInstanceList != null){ - tousseInstancesSet.addAll(tousseInstanceList); - for (TousseInstance disinfectionTousseInstance : tousseInstancesSet) { - if (amountAwaitingSent <= 0) { - break; - } - if(!disinfectionTousseInstance.canInvoice()){ - continue; - } - itemPrice = addItemPriceToTotal(disinfectionTousseInstance.getPrice(), 1, itemPrice); - totalPrice = addItemPriceToTotal(disinfectionTousseInstance.getPrice(), 1, totalPrice); - tousseInstancesToUpdate.add(disinfectionTousseInstance); - amountAwaitingSent--; - } - } - if(amountAwaitingSent > 0 ){ - throw new RuntimeException(String.format("固定条码物品%s库存不足!", invoiceItem.getTousseName())); - } - sendOutBarcodeAmount.put(barcode, amountAwaitSend - sentAmount); - }else{ - int amount = sendOutBarcodeAmountEntry.getValue(); - // 数量必须为1 - if(amount != 1){ - throw new RuntimeException(String.format("器械包[%s]条码[%s]发货数量必须为1,实际为%s!", invoiceItem.getTousseName(),barcode,amount)); - } - itemPrice = addItemPriceToTotal(tousseInstance.getPrice(), amount, itemPrice); - totalPrice = addItemPriceToTotal(tousseInstance.getPrice(), amount, totalPrice); - sendOutBarcodeAmount.put(barcode, 0); - tousseInstancesToUpdate.add(tousseInstance); - amountAwaitingSent--; - } - - invoiceItem.setSettlementPrice(invoiceItem - .getSettlementPrice() + itemPrice.doubleValue()); - } + + invoiceItem.setSettlementPrice(invoiceItem + .getSettlementPrice() + + itemPrice.doubleValue()); } - } - + } - // 如果appAmount大于0,证明未完全发货,属于异常情况 - if(amountAwaitingSent > 0){ - throw new RuntimeException(String.format("%s的库存不足,不能发货,请检查!", invoiceItem.getTousseName())); - } + } + // 如果appAmount大于0,证明未完全发货,属于异常情况 + if (amountAwaitingSent > 0) { + throw new RuntimeException(String.format("%s的库存不足,不能发货,请检查!", + invoiceItem.getTousseName())); + } } - + JSONObject params = submitInvoiceContext.getParams(); - String personInCharge = JSONUtil.optString(params, "personInCharge", ""); - String personInChargeCode = JSONUtil.optString(params, "personInChargeCode", ""); - invoice.setApplicant(invoicePlan.getApplicant()); - invoice.setApplicationTime(invoicePlan.getApplicationTime()); - invoice.setRecyclingTime(invoicePlan.getRecyclingTime()); - invoice.setDepart(invoicePlan.getDepart()); + String personInCharge = JSONUtil + .optString(params, "personInCharge", ""); + String personInChargeCode = JSONUtil.optString(params, + "personInChargeCode", ""); + invoice.setApplicant(applicant); + invoice.setApplicationTime(applicationTime); + invoice.setRecyclingTime(recyclingTime); + invoice.setDepart(depart); invoice.setDiposableGoodsItems(diposableGoodsItems); invoice.setInvoiceItem(invoiceItems); // 关联发货单ID - for (InvoiceItem invoiceItem : invoiceItems) { - invoiceItem.setInvoicePlanID(invoicePlan.getId()); + if (invoicePlan != null) { + for (InvoiceItem invoiceItem : invoiceItems) { + invoiceItem.setInvoicePlanID(invoicePlan.getId()); + } + invoice.setInvoicePlan(invoicePlan); } - invoice.setInvoicePlan(invoicePlan); + invoice.setAssistantSender(submitInvoiceContext.getAssistantSender()); - if (invoicePlan instanceof RecyclingApplication) { - RecyclingApplication application = (RecyclingApplication) invoicePlan; - invoice.setRemark(application.getRemark()); + if (invoicePlan != null) { + if (invoicePlan instanceof RecyclingApplication) { + RecyclingApplication application = (RecyclingApplication) invoicePlan; + invoice.setRemark(application.getRemark()); + } } + invoice.setSender(submitInvoiceContext.getSender()); invoice.setPersonInCharge(personInCharge); invoice.setPersonInChargeCode(personInChargeCode); invoice.setSendTime(new Date()); invoice.setSerialNumber(serialNumManager .getSerialNumberStr(SerialNum.TYPE_INVOICE)); - invoice.setSettleAccountsDepart(invoicePlan.getSettleAccountsDepart()); + invoice.setSettleAccountsDepart(settleAccountsDepart); invoice.setStatus(Invoice.STATUS_DELIVERED); invoice.setOrgUnitCoding(AcegiHelper.getLoginUser() .getCurrentOrgUnitCode()); // 发货物品总价 invoice.setTotalPrice(totalPrice.doubleValue()); // 工作量统计 -// invoice.setTousseInstances(tousseInstances); - invoice.setHospitalNumber(invoicePlan.getHospitalNumber()); - updateInvoiceStatistics(invoice,submitInvoiceContext.getTousseInstancesToUpdate()); + // invoice.setTousseInstances(tousseInstances); + if (invoicePlan != null) { + invoice.setHospitalNumber(invoicePlan.getHospitalNumber()); + } + updateInvoiceStatistics(invoice, + submitInvoiceContext.getTousseInstancesToUpdate()); return invoice; } @@ -2710,17 +2872,17 @@ //获取发货单中所有临床科室对应的默认仓库 Map targetWareHouseMap = wareHouseManager.getDefaultWareHouse( updateStockInfo.keySet().stream().map( - invoice->invoice.getInvoicePlan().getDepartCoding()).collect(Collectors.toList())); + invoice->invoice.getDepartCoding()).collect(Collectors.toList())); for (Map.Entry> entry : updateStockInfo.entrySet()) { - WareHouse targetWareHouse = targetWareHouseMap.get(entry.getKey().getInvoicePlan().getDepartCoding()); + WareHouse targetWareHouse = targetWareHouseMap.get(entry.getKey().getDepartCoding()); List sourcestocks = TousseInstanceUtils.newGoodsStockList(entry.getValue(), wareHouse); List targetstocks = TousseInstanceUtils.newGoodsStockList(entry.getValue(), targetWareHouse); allSourceStocks.addAll(sourcestocks); allTargetStocks.addAll(targetstocks); //将器械包的仓库设置为目标仓库 - tousseInstanceManager.setToDefaultWareHouse(entry.getValue(), entry.getKey().getInvoicePlan().getDepartCoding()); + tousseInstanceManager.setToDefaultWareHouse(entry.getValue(), entry.getKey().getDepartCoding()); } try { if(CollectionUtils.isNotEmpty(allSourceStocks)){ @@ -3086,14 +3248,43 @@ } } + private String getInvoiceDepartCoding(InvoicePlan invoicePlan,SubmitInvoiceContext submitInvoiceContext){ + String departCoding = submitInvoiceContext.getDepartCode(); + if (invoicePlan != null) { + departCoding = invoicePlan.getDepartCoding(); + } + return departCoding; + } + private String getInvoiceDepart(InvoicePlan invoicePlan,SubmitInvoiceContext submitInvoiceContext){ + String depart = submitInvoiceContext.getDepart(); + if (invoicePlan != null) { + depart = invoicePlan.getDepart(); + } + return depart; + } + private String getInvoiceSettleAccountsDepartCoding(InvoicePlan invoicePlan,SubmitInvoiceContext submitInvoiceContext){ + String settleAccountsDepartCoding = submitInvoiceContext.getDepartCode(); + if (invoicePlan != null) { + settleAccountsDepartCoding = invoicePlan.getSettleAccountsDepartCoding(); + } + return settleAccountsDepartCoding; + } + private String getInvoiceSettleAccountsDepart(InvoicePlan invoicePlan,SubmitInvoiceContext submitInvoiceContext){ + String settleAccountsDepart = submitInvoiceContext.getDepart(); + if (invoicePlan != null) { + settleAccountsDepart = invoicePlan.getSettleAccountsDepart(); + } + return settleAccountsDepart; + } + /** * 修改器械包状态 * * @param tousseInstances * 警告,此方法并没有修改内存中器械包实例的属性,为了避免hibernate自动更新。所以此方法调用完成之后,不应该再使用这些器械包实例 */ - private void updateTousseInstanceStatus(Invoice invoice,Collection tousseInstancesToUpdate) { + private void updateTousseInstanceStatus(SubmitInvoiceContext submitInvoiceContext,Invoice invoice,Collection tousseInstancesToUpdate) { if(invoice == null || invoice.getId() == null){ throw new RuntimeException(String.format("发货单不能为空!")); } @@ -3105,16 +3296,19 @@ } InvoicePlan invoicePlan = invoice.getInvoicePlan(); - String departCoding = invoicePlan.getDepartCoding(); + String departCoding = getInvoiceDepartCoding(invoicePlan, submitInvoiceContext); String sender = invoice.getSender(); Date sendDate = invoice.getSendTime(); - String depart = invoicePlan.getDepart(); + String depart = getInvoiceDepart(invoicePlan, submitInvoiceContext); ProxyDisinfection proxyDisinfection = null; - if(invoicePlan instanceof ProxyDisinfection){ - proxyDisinfection = (ProxyDisinfection)invoicePlan; + if(invoicePlan != null){ + if(invoicePlan instanceof ProxyDisinfection){ + proxyDisinfection = (ProxyDisinfection)invoicePlan; + } } + Set tousseInstanceIDs = new HashSet(); for (TousseInstance tousseInstance : tousseInstancesToUpdate) { tousseInstanceIDs.add(tousseInstance.getId()); @@ -3124,8 +3318,8 @@ } tousseInstance.setLocation(departCoding); tousseInstance.setLocationForDisplay(depart); - tousseInstance.setSettleAccountsDepart(invoicePlan.getSettleAccountsDepart()); - tousseInstance.setSettleAccountsDepartCode(invoicePlan.getSettleAccountsDepartCoding()); + tousseInstance.setSettleAccountsDepart(getInvoiceSettleAccountsDepart(invoicePlan, submitInvoiceContext)); + tousseInstance.setSettleAccountsDepartCode(getInvoiceSettleAccountsDepartCoding(invoicePlan, submitInvoiceContext)); tousseInstance.setInvoiceSender(sender); tousseInstance.setInvoiceSendTime(sendDate); objectDao.update(tousseInstance);