Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManager.java =================================================================== diff -u -r13141 -r13158 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManager.java (.../JasperReportManager.java) (revision 13141) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManager.java (.../JasperReportManager.java) (revision 13158) @@ -278,5 +278,5 @@ */ public List getGodownSummaryReport(String startTime,String endTime,String suplier,String warehouseId,String type,String hasInvoice,String goodsType); - public List getStockTakeList(String id,String type); + public List getStockTakeList(String id,String type,String summaryType); } Index: ssts-web/src/main/webapp/jasperRtp/stocktakeSummaryReport.jrxml =================================================================== diff -u --- ssts-web/src/main/webapp/jasperRtp/stocktakeSummaryReport.jrxml (revision 0) +++ ssts-web/src/main/webapp/jasperRtp/stocktakeSummaryReport.jrxml (revision 13158) @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + <band height="39" splitType="Stretch"> + <textField> + <reportElement uuid="689fc869-a193-40c9-a4d0-a20389948eaf" x="0" y="0" width="1015" height="39"/> + <textElement textAlignment="Center" verticalAlignment="Middle"> + <font size="16" isBold="true"/> + </textElement> + <textFieldExpression><![CDATA[$P{title}]]></textFieldExpression> + </textField> + </band> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Index: ssts-web/src/main/webapp/jasperRtp/stocktakeSummaryReport.jasper =================================================================== diff -u Binary files differ Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java =================================================================== diff -u -r13156 -r13158 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java (.../JasperReportManagerImpl.java) (revision 13156) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java (.../JasperReportManagerImpl.java) (revision 13158) @@ -51,6 +51,7 @@ import com.forgon.disinfectsystem.diposablegoods.service.GodownEntryItemManager; import com.forgon.disinfectsystem.diposablegoods.util.GodownEntryUtil; import com.forgon.disinfectsystem.diposablegoods.util.MaterialEntryUtil; +import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoods; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsBatchStock; import com.forgon.disinfectsystem.entity.assestmanagement.DisposableGoodsStock; import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry; @@ -7588,20 +7589,123 @@ /** * 导出物品收发明细月报 */ - public List getStockTakeList(String id,String type){ + public List getStockTakeList(String id,String type,String summaryType){ if(StringUtils.isNotBlank(id)){ StockTakeRecord record = (StockTakeRecord)objectDao.getByProperty(StockTakeRecord.class.getSimpleName(), "inventoryRecordId", Long.valueOf(id)); StockTakeRecord lastRecord = null; if(record != null){ String sql = "where po.warehouseId = " + record.getWarehouseId() + " and id < " + record.getId() + " order by id desc"; lastRecord = (StockTakeRecord)objectDao.getBySql(StockTakeRecord.class.getSimpleName(), sql); } - return createGoodsDetail(record,lastRecord,type); + if("summary".equals(summaryType)){ + return createGoodsSummary(record, lastRecord, type); + }else{ + return createGoodsDetail(record,lastRecord,type); + } } return null; } - - + private double getTotalPrice(String sql){ + double totalPrice = 0.0; + System.out.println("sql:" + sql); + ResultSet rs = objectDao.executeSql(sql); + try { + if(rs.next()){ + totalPrice = rs.getDouble("totalPrice"); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally{ + DatabaseUtil.closeResultSetAndStatement(rs); + } + return totalPrice; + } + public List createGoodsSummary(StockTakeRecord currentRecord,StockTakeRecord lastMonthRecord,String type){ + List list = createGoodsDetail(currentRecord,lastMonthRecord,type); + MonthGoodsDetailVo vo = new MonthGoodsDetailVo(); + for(MonthGoodsDetailVo item : list){ + vo.setStartStockPrice(MathTools.add(vo.getStartStockPrice(), item.getStartStockPrice()).doubleValue()); + vo.setEndStockPrice(MathTools.add(vo.getEndStockPrice(), item.getEndStockPrice()).doubleValue()); + vo.setInStoragePrice(MathTools.add(vo.getInStoragePrice(), item.getInStoragePrice()).doubleValue()); + vo.setOutStoragePrice(MathTools.add(vo.getOutStoragePrice(), item.getOutStoragePrice()).doubleValue()); + } + List retList = new ArrayList(); + retList.add(vo); + return retList; + /*if(currentRecord != null){ + //查找入库单中入库项的id和对应的名称全称 + String idNameSql = "select gei.id,"; + String strLink = " + "; + if(dbConnection.isOracle()){ + strLink = " | "; + } + idNameSql += " case when dg.specification is null or LEN(dg.specification) = 0 then dg.name else dg.name" + + strLink + "'['" + strLink + "dg.specification" + strLink + "']' end as name "; + idNameSql += " from " + GodownEntryItem.class.getSimpleName() + " gei inner join " + + DisposableGoods.class.getSimpleName() + " dg on gei.disposableGoodsID = dg.id"; + + String lastTotalPriceSql = "select 0.00 as totalPrice"; + if(lastMonthRecord != null){ + lastTotalPriceSql = "select sum(totalPrice) as totalPrice from StockDiposableGoods where takeRecord_id=" + lastMonthRecord.getId(); + } + String thisTotalPriceSql = "select sum(totalPrice) as totalPrice from StockDiposableGoods where takeRecord_id=" + currentRecord.getId(); + + String typesql = ""; + if(StringUtils.isNotBlank(type)){ + typesql = " and po.type = '" + type + "' "; + } + //按物品类型、外部编码排序 + String orderBySql = " where po.stockTakeRecord.id = " + + currentRecord.getId() + typesql + " order by po.typeSequence,po.externalCode asc"; + @SuppressWarnings("unchecked") + List goodsList = objectDao.findBySql(StockDiposableGoods.class.getSimpleName(), orderBySql); + + //本期入库 + String startDate = ""; + if(lastMonthRecord != null){ + startDate = dateQueryAdapter.dateAdapter(lastMonthRecord.getStockTakeDate()); + } + String endDate = dateQueryAdapter.dateAdapter(currentRecord.getStockTakeDate()); + + String basesql = "select sum(i.amount*i.cost) as totalPrice from GodownEntry r inner join GodownEntryItem i " + + "on r.id = i.godownEntry_id inner join ( " + idNameSql + " ) idName on i.id = idName.id inner join " + + StockDiposableGoods.class.getSimpleName() + " po on " + + "po.name=idName.name " + typesql; + //入库sql + String insql = basesql + " where r.type ='"+GodownEntry.TYPE_IN+"' and r.warehouseID = " + + currentRecord.getWarehouseId(); + if(StringUtils.isBlank(startDate)){ + insql += " and r.time < " + endDate + ""; + }else{ + insql += " and r.time between " + startDate + " and " + endDate + " "; + } + + //退库sql + String outsql = basesql + " and r.type ='"+GodownEntry.TYPE_OUT+"' and r.warehouseID = " + + currentRecord.getWarehouseId(); + if(StringUtils.isBlank(startDate)){ + outsql += " and r.time < " + endDate + ""; + }else{ + outsql += " and r.time between " + startDate + " and " + endDate + " "; + } + + double thisTotal = getTotalPrice(thisTotalPriceSql); + double lastTotal = getTotalPrice(lastTotalPriceSql); + double thisIn = getTotalPrice(insql); + double thisout = getTotalPrice(outsql); + + MonthGoodsDetailVo vo = new MonthGoodsDetailVo(); + vo.setEndStockPrice(thisTotal); + vo.setStartStockPrice(lastTotal); + vo.setInStoragePrice(thisIn-thisout); + vo.setOutStoragePrice(vo.getStartStockPrice() + vo.getInStoragePrice() - vo.getEndStockPrice()); + + List voList = new ArrayList(); + voList.add(vo); + return voList; + } + return null;*/ + } /** * @param currentRecord * @param lastMonthRecord @@ -7667,8 +7771,8 @@ List batchList = goods.getGoodsBatchs(); for (StockDiposableGoodBatch stockDiposableGoodBatch : batchList) { for (StockIdentificationOfGoods stockIdentification : stockDiposableGoodBatch.getStockIdentifications()) { - double tempPrice = new BigDecimal(stockIdentification.getAmount()).multiply(new BigDecimal(stockIdentification.getPrice())).doubleValue(); - startPrice = new BigDecimal(startPrice).add(new BigDecimal(tempPrice)).doubleValue(); + double tempPrice = MathTools.mul(stockIdentification.getAmount(), stockIdentification.getPrice()).doubleValue(); + startPrice = MathTools.add(startPrice, tempPrice).doubleValue(); } } vo.setEndStockAmount(startAmount); @@ -7692,7 +7796,7 @@ List startBatchList = diposableGoods.getGoodsBatchs(); for (StockDiposableGoodBatch stockDiposableGoodBatch : startBatchList) { for (StockIdentificationOfGoods stockIdentification : stockDiposableGoodBatch.getStockIdentifications()) { - double tempPrice = new BigDecimal(stockIdentification.getAmount()).multiply(new BigDecimal(stockIdentification.getPrice())).doubleValue(); + double tempPrice = MathTools.mul(stockIdentification.getAmount(), stockIdentification.getPrice()).doubleValue(); tempPrice2 = new BigDecimal(tempPrice2).add(new BigDecimal(tempPrice)).doubleValue(); } } @@ -7713,10 +7817,9 @@ if(entryItems != null){ for (GodownEntryItem godownEntryItem : entryItems) { Long tempAmount = godownEntryItem.getAmount(); - double cost = godownEntryItem.getCost(); - double itemTotalPrice = new BigDecimal(tempAmount).multiply(new BigDecimal(cost)).doubleValue(); + double itemTotalPrice = MathTools.mul(tempAmount, godownEntryItem.getCost()).doubleValue(); totalPrice += itemTotalPrice; - amount += tempAmount; + amount = MathTools.add(amount, tempAmount).longValue(); } } @@ -7726,9 +7829,9 @@ for (GodownEntryItem godownEntryItem : entryOutItems) { Long tempAmount = godownEntryItem.getAmount(); double cost = godownEntryItem.getCost(); - double itemTotalPrice = new BigDecimal(tempAmount).multiply(new BigDecimal(cost)).doubleValue(); - totalPrice -= itemTotalPrice; - amount -= tempAmount; + double itemTotalPrice = MathTools.mul(tempAmount, cost).doubleValue(); + totalPrice = MathTools.sub(totalPrice, itemTotalPrice).doubleValue(); + amount = MathTools.sub(amount, tempAmount).longValue(); } } vo.setInStorageAmount(amount); Index: forgon-tools/src/main/java/com/forgon/tools/MathTools.java =================================================================== diff -u -r13154 -r13158 --- forgon-tools/src/main/java/com/forgon/tools/MathTools.java (.../MathTools.java) (revision 13154) +++ forgon-tools/src/main/java/com/forgon/tools/MathTools.java (.../MathTools.java) (revision 13158) @@ -69,21 +69,34 @@ } /** * 计算两个数之和.如果有一个数为null,返回值为另一个数的值,如果两个数都为null,则返回0.0 - * @param a 加数,可以为null - * @param b 加数,可以为null - * @return + * @param a 加数,可以为null,此时认为值为0.0 + * @param b 加数,可以为null,此时认为值为0.0 + * @return a + b */ public static BigDecimal add(Number a,Number b){ - BigDecimal ret = null; if(a == null){ a = new BigDecimal(0.0); } if(b == null){ b = new BigDecimal(0.0); } - ret = new BigDecimal(a.doubleValue()).add(new BigDecimal(b.doubleValue())); - return ret; + return new BigDecimal(a.doubleValue()).add(new BigDecimal(b.doubleValue())); } + /** + * 计算两个数的差 + * @param a 被减数,可以为null,此时认为值为0.0 + * @param b 减数,可以为null,此时认为值为0.0 + * @return a - b + */ + public static BigDecimal sub(Number a,Number b){ + if(a == null){ + a = new BigDecimal(0.0); + } + if(b == null){ + b = new BigDecimal(0.0); + } + return new BigDecimal(a.doubleValue()).subtract(new BigDecimal(b.doubleValue())); + } // 将对象转为Integer,如果对象为空或者不为数字,则转为0 public static Integer object2Integer(Object object){ Integer result = 0; Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/action/JasperreportsAction.java =================================================================== diff -u -r13141 -r13158 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/action/JasperreportsAction.java (.../JasperreportsAction.java) (revision 13141) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/action/JasperreportsAction.java (.../JasperreportsAction.java) (revision 13158) @@ -254,7 +254,11 @@ if (reportName.equals("stocktakereport")) {// 结算 String id = StrutsParamUtils.getPraramValue("id", ""); String type = StrutsParamUtils.getPraramValue("type", ""); - return jasperReportManager.getStockTakeList(id,type); + return jasperReportManager.getStockTakeList(id,type,null); + }else if(reportName.equals("stocktakeSummaryReport")){ + String id = StrutsParamUtils.getPraramValue("id", ""); + String type = StrutsParamUtils.getPraramValue("type", ""); + return jasperReportManager.getStockTakeList(id,type,"summary"); }else if (reportName.equals("QualityMonitoring")) {// 质量监测 return getQualityMonitoringDataSource(); } else if (reportName.equals("departSatisfyReport")) {// 满意度调查报表 @@ -915,6 +919,23 @@ } map.put("title", "物资收发存明细表(" + startDate + " & " + endDate + ")"); } + }else if(reportName.equals("stocktakeSummaryReport")){ + String id = StrutsParamUtils.getPraramValue("id", ""); + if(StringUtils.isNotBlank(id)){ + StockTakeRecord record = (StockTakeRecord)objectDao.getByProperty(StockTakeRecord.class.getSimpleName(), "inventoryRecordId", Long.valueOf(id)); + StockTakeRecord lastRecord = null; + if(record != null){ + String sql = "where po.warehouseId = " + record.getWarehouseId() + " and id < " + record.getId() + " order by id desc"; + lastRecord = (StockTakeRecord)objectDao.getBySql(StockTakeRecord.class.getSimpleName(), sql); + } + SimpleDateFormat sfd = new SimpleDateFormat("yyyy-MM-dd HH:mm"); + String endDate = sfd.format(record.getStockTakeDate()); + String startDate = ""; + if(lastRecord != null){ + startDate = sfd.format(lastRecord.getStockTakeDate()); + } + map.put("title", "物资收发存汇总表(" + startDate + " & " + endDate + ")"); + } } else if (reportName.equals("monthReport")){ String startTime = StrutsParamUtils.getPraramValue("startTime", ""); String endTime = StrutsParamUtils.getPraramValue("endTime", ""); Index: ssts-web/src/main/webapp/disinfectsystem/reportforms/stocktakeView.js =================================================================== diff -u -r13141 -r13158 --- ssts-web/src/main/webapp/disinfectsystem/reportforms/stocktakeView.js (.../stocktakeView.js) (revision 13141) +++ ssts-web/src/main/webapp/disinfectsystem/reportforms/stocktakeView.js (.../stocktakeView.js) (revision 13158) @@ -11,14 +11,25 @@ removeMask: true }); myMask.show(); - window.open(WWWROOT+"/jasperreports/jasperreportsAction!createReportFromJavaBeanSource.do?jasperreportName=stocktakereport.jasper&reportName=stocktakereport&id=" + inventoryRecordId + "&type=" + type,'thisIframe','_self'); + var summaryType = Ext.getCmp('summaryType').getValue(); + if(summaryType == '汇总'){ + window.open(WWWROOT+"/jasperreports/jasperreportsAction!createReportFromJavaBeanSource.do?jasperreportName=stocktakeSummaryReport.jasper&reportName=stocktakeSummaryReport&id=" + inventoryRecordId + "&type=" + type,'thisIframe','_self'); + }else{ + window.open(WWWROOT+"/jasperreports/jasperreportsAction!createReportFromJavaBeanSource.do?jasperreportName=stocktakereport.jasper&reportName=stocktakereport&id=" + inventoryRecordId + "&type=" + type,'thisIframe','_self'); + } + } var diposableGoodsTypeStore = new Ext.data.SimpleStore({ fields : [ 'typeName' ], url : WWWROOT + '/disinfectSystem/diposableGoodsAction!getDiposableGoodsType.do' }); + var summaryTypeStore = new Ext.data.SimpleStore( { + fields : ['value'], + data : [ ['明细'],['汇总']] + }); + var form = new Ext.form.FormPanel({ title : entityName, region : 'north', @@ -32,25 +43,51 @@ bodyStyle : 'padding:0px auto;margin:0px',// padding:1px;padding-top:5px; height : 105, items : [{ - layout : 'form', + layout : 'column', + height : 40, labelWidth : 60, - width : 220, items:[{ - xtype : 'combo', - fieldLabel : '材料类型', - id : 'type', - name : 'type', - minChars : 0, - valueField : 'typeName', - displayField : 'typeName', - store : diposableGoodsTypeStore, - forceSelection : true, - lazyInit : false, - triggerAction : 'all', - hideTrigger : false, - typeAhead : false, - allowBlank : true, - anchor : '95%' + width : 180, + layout : 'form', + labelWidth : 60, + items:[{ + xtype : 'combo', + fieldLabel : '材料类型', + id : 'type', + name : 'type', + minChars : 0, + valueField : 'typeName', + displayField : 'typeName', + store : diposableGoodsTypeStore, + forceSelection : true, + lazyInit : false, + triggerAction : 'all', + hideTrigger : false, + typeAhead : false, + allowBlank : true, + anchor : '95%' + }] + },{ + width : 180, + layout : 'form', + labelWidth : 60, + items:[{ + xtype : 'combo', + fieldLabel : '统计类型', + id : 'summaryType', + name : 'summaryType', + valueField : 'value', + displayField : 'value', + store : summaryTypeStore, + forceSelection : true, + hideTrigger : false, + editable : false, + allowBlank : false, + value : '明细', + mode : 'local', + triggerAction : 'all', + anchor : '95%' + }] }] }], buttons:[{