Index: ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakerecordmanager/MonthGoodsDetailVo.java =================================================================== diff -u -r13224 -r13291 --- ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakerecordmanager/MonthGoodsDetailVo.java (.../MonthGoodsDetailVo.java) (revision 13224) +++ ssts-basedata/src/main/java/com/forgon/disinfectsystem/entity/stocktakerecordmanager/MonthGoodsDetailVo.java (.../MonthGoodsDetailVo.java) (revision 13291) @@ -30,11 +30,205 @@ private Long inAutoStorageAmount = 0L;//本期自动入库数量 private Double inAutoStoragePrice=0.00;//本期自动入库价格 + /** + * 购入入库数量(包括手工入库\导入入库\同步入库) + */ + private Long buyInStorageAmount = 0L; + /** + * 购入入库价格(包括手工入库\导入入库\同步入库) + */ + private Double buyInStoragePrice = 0.00; + /** + * 调拨入库数量 + */ + private Long moveInStorageAmount = 0L; + /** + * 调拨入库价格 + */ + private Double moveInStoragePrice = 0.00; + /** + * 盘盈入库数量 + */ + private Long stockTakeInStorageAmount = 0L; + /** + * 盘盈入库价格 + */ + private Double stockTakeInStoragePrice = 0.00; private Long outStorageAmount = 0L;//本期出库数量 private Double outStoragePrice=0.00;//本期出库价格 - + /** + * 退至供应商数量(手工出库/同步出库) + */ + private Long returnBackToSupplierStorageAmount = 0L; + /** + * 退至供应商价格(手工出库/同步出库) + */ + private Double returnBackToSupplierStoragePrice = 0.00; + /** + * 调拨出库数量 + */ + private Long moveOutStorageAmount = 0L; + /** + * 调拨出库价格 + */ + private Double moveOutStoragePrice = 0.00; + /** + * 盘盈出库数量 + */ + private Long stockTakeOutStorageAmount = 0L; + /** + * 盘盈出库价格 + */ + private Double stockTakeOutStoragePrice = 0.00; + /** + * 科室退货数量 + */ + private Long departmentReturnStorageAmount = 0L; + /** + * 科室退货价格 + */ + private Double departmentReturnStoragePrice = 0.00; + /** + * 供应室领用出库数量 + * @return + */ + private Long receiveRecordStorageAmount = 0L; + /** + * 供应室领用出库价格 + */ + private Double receiveRecordStoragePrice = 0.00; + public Long getReceiveRecordStorageAmount() { + return receiveRecordStorageAmount; + } + + public void setReceiveRecordStorageAmount(Long receiveRecordStorageAmount) { + this.receiveRecordStorageAmount = receiveRecordStorageAmount; + } + + public Double getReceiveRecordStoragePrice() { + return receiveRecordStoragePrice; + } + + public void setReceiveRecordStoragePrice(Double receiveRecordStoragePrice) { + this.receiveRecordStoragePrice = receiveRecordStoragePrice; + } + + public Long getDepartmentReturnStorageAmount() { + return departmentReturnStorageAmount; + } + + public void setDepartmentReturnStorageAmount(Long departmentReturnStorageAmount) { + this.departmentReturnStorageAmount = departmentReturnStorageAmount; + } + + public Double getDepartmentReturnStoragePrice() { + return departmentReturnStoragePrice; + } + + public void setDepartmentReturnStoragePrice(Double departmentReturnStoragePrice) { + this.departmentReturnStoragePrice = departmentReturnStoragePrice; + } + + public Long getBuyInStorageAmount() { + return buyInStorageAmount; + } + + public void setBuyInStorageAmount(Long buyInStorageAmount) { + this.buyInStorageAmount = buyInStorageAmount; + } + + public Double getBuyInStoragePrice() { + return buyInStoragePrice; + } + + public void setBuyInStoragePrice(Double buyInStoragePrice) { + this.buyInStoragePrice = buyInStoragePrice; + } + + public Long getMoveInStorageAmount() { + return moveInStorageAmount; + } + + public void setMoveInStorageAmount(Long moveInStorageAmount) { + this.moveInStorageAmount = moveInStorageAmount; + } + + public Double getMoveInStoragePrice() { + return moveInStoragePrice; + } + + public void setMoveInStoragePrice(Double moveInStoragePrice) { + this.moveInStoragePrice = moveInStoragePrice; + } + + public Long getStockTakeInStorageAmount() { + return stockTakeInStorageAmount; + } + + public void setStockTakeInStorageAmount(Long stockTakeInStorageAmount) { + this.stockTakeInStorageAmount = stockTakeInStorageAmount; + } + + public Double getStockTakeInStoragePrice() { + return stockTakeInStoragePrice; + } + + public void setStockTakeInStoragePrice(Double stockTakeInStoragePrice) { + this.stockTakeInStoragePrice = stockTakeInStoragePrice; + } + + public Long getReturnBackToSupplierStorageAmount() { + return returnBackToSupplierStorageAmount; + } + + public void setReturnBackToSupplierStorageAmount( + Long returnBackToSupplierStorageAmount) { + this.returnBackToSupplierStorageAmount = returnBackToSupplierStorageAmount; + } + + public Double getReturnBackToSupplierStoragePrice() { + return returnBackToSupplierStoragePrice; + } + + public void setReturnBackToSupplierStoragePrice( + Double returnBackToSupplierStoragePrice) { + this.returnBackToSupplierStoragePrice = returnBackToSupplierStoragePrice; + } + + public Long getMoveOutStorageAmount() { + return moveOutStorageAmount; + } + + public void setMoveOutStorageAmount(Long moveOutStorageAmount) { + this.moveOutStorageAmount = moveOutStorageAmount; + } + + public Double getMoveOutStoragePrice() { + return moveOutStoragePrice; + } + + public void setMoveOutStoragePrice(Double moveOutStoragePrice) { + this.moveOutStoragePrice = moveOutStoragePrice; + } + + public Long getStockTakeOutStorageAmount() { + return stockTakeOutStorageAmount; + } + + public void setStockTakeOutStorageAmount(Long stockTakeOutStorageAmount) { + this.stockTakeOutStorageAmount = stockTakeOutStorageAmount; + } + + public Double getStockTakeOutStoragePrice() { + return stockTakeOutStoragePrice; + } + + public void setStockTakeOutStoragePrice(Double stockTakeOutStoragePrice) { + this.stockTakeOutStoragePrice = stockTakeOutStoragePrice; + } + private Long endStockAmount = 0L;//期末库存数量 private Double endStockPrice=0.00;//期末库存总价 Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/MonthGoodsDetailSummaryService.java =================================================================== diff -u --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/MonthGoodsDetailSummaryService.java (revision 0) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/MonthGoodsDetailSummaryService.java (revision 13291) @@ -0,0 +1,186 @@ +package com.forgon.disinfectsystem.jasperreports.service; + +import java.util.LinkedList; +import java.util.List; + +import net.sf.json.JSONObject; + +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.collections4.Predicate; + +import com.forgon.disinfectsystem.entity.assestmanagement.GodownEntry; +import com.forgon.disinfectsystem.entity.stocktakerecordmanager.MonthGoodsDetailVo; +import com.forgon.disinfectsystem.jasperreports.javabeansource.ReturnGoodsItemVo; +import com.forgon.disinfectsystem.jasperreports.javabeansource.ReturnGoodsVo; +import com.forgon.tools.MathTools; +import com.forgon.tools.string.StringTools; + +/** + * 对结算进行汇总统计的类 + * @author kzh + * + */ +public class MonthGoodsDetailSummaryService { + private List returnGoodsVos = new LinkedList(); + + public List getList(){ + returnGoodsVos.forEach(vo->{ + //本期出库数量 + //Long outStoageAmount = vo.getStartStockAmount()+vo.getInStorageAmount()-vo.getEndStockAmount(); + //Double outStoragePrice = vo.getStartStockPrice()+vo.getInStoragePrice()-vo.getEndStockPrice(); + //vo.setOutStorageAmount(outStoageAmount); + //vo.setOutStoragePrice(outStoragePrice); + }); + return returnGoodsVos; + } + + public void addItem(JSONObject jsonObject){ + String name = jsonObject.optString("name"); + String spec = jsonObject.optString("specification"); + MonthGoodsDetailVo vo = findOrAdd(name, spec,false); + long amount = jsonObject.optLong("amount"); + double cost = jsonObject.optDouble("cost"); + String type = jsonObject.optString("type"); + String subType = jsonObject.optString("subType"); + addAmountAndPrice(vo,amount,cost,type,subType); + } + + /** + * 根据物品名称及规格查找对应物品的记录,如果没有找到,则添加对应的记录 + * @param name + * @param spec + * @param add 如果没有找到是否添加记录。如果是设置期末的数据,则应该添加,否则不添加 + * @return + */ + private MonthGoodsDetailVo findOrAdd(String name, String spec,boolean add) { + MonthGoodsDetailVo vo = CollectionUtils.find(returnGoodsVos, new Predicate(){ + @Override + public boolean evaluate(MonthGoodsDetailVo object) { + if(StringTools.equals(name, object.getName()) + && StringTools.equals(spec, object.getSpecification())){ + return true; + } + return false; + } + }); + if(vo == null && add){ + vo = new MonthGoodsDetailVo(); + vo.setName(name); + vo.setSpecification(spec); + returnGoodsVos.add(vo); + } + return vo; + } + + private void addAmountAndPrice(MonthGoodsDetailVo vo,long amount, + double cost,String type,String subType){ + if(vo == null){ + return; + } + //子类型 + if(GodownEntry.SUBTYPE_IMPORT_IN.equals(subType) + || GodownEntry.SUBTYPE_MANUAL_IN.equals(subType) + || GodownEntry.SUBTYPE_SYNC_IN.equals(subType)){ + vo.setBuyInStorageAmount( + MathTools.add(amount,vo.getBuyInStorageAmount()).longValue()); + vo.setBuyInStoragePrice( + MathTools.add(amount * cost, vo.getBuyInStoragePrice()).doubleValue()); + }else if(GodownEntry.SUBTYPE_MANUAL_OUT.equals(subType) + || GodownEntry.SUBTYPE_SYNC_OUT.equals(subType)){ + //这种情况下,记入入库合计,但数值是负数 + type=GodownEntry.TYPE_IN; + amount = - amount; + vo.setReturnBackToSupplierStorageAmount( + MathTools.add(amount,vo.getReturnBackToSupplierStorageAmount()).longValue()); + vo.setReturnBackToSupplierStoragePrice( + MathTools.add(amount * cost, vo.getReturnBackToSupplierStoragePrice()).doubleValue()); + }else if(GodownEntry.SUBTYPE_MOVE_IN.equals(subType)){ + vo.setMoveInStorageAmount( + MathTools.add(amount,vo.getMoveInStorageAmount()).longValue()); + vo.setMoveInStoragePrice( + MathTools.add(amount * cost, vo.getMoveInStoragePrice()).doubleValue()); + }else if(GodownEntry.SUBTYPE_MOVE_OUT.equals(subType)){ + vo.setMoveOutStorageAmount( + MathTools.add(amount,vo.getMoveOutStorageAmount()).longValue()); + vo.setMoveOutStoragePrice( + MathTools.add(amount * cost, vo.getMoveOutStoragePrice()).doubleValue()); + }else if(GodownEntry.SUBTYPE_STOCKTAKE_IN.equals(subType)){ + vo.setStockTakeInStorageAmount( + MathTools.add(amount,vo.getStockTakeInStorageAmount()).longValue()); + vo.setStockTakeInStoragePrice( + MathTools.add(amount * cost, vo.getStockTakeInStoragePrice()).doubleValue()); + }else if(GodownEntry.SUBTYPE_STOCKTAKE_OUT.equals(subType)){ + vo.setStockTakeOutStorageAmount( + MathTools.add(amount,vo.getStockTakeOutStorageAmount()).longValue()); + vo.setStockTakeOutStoragePrice( + MathTools.add(amount * cost, vo.getStockTakeOutStoragePrice()).doubleValue()); + }else if("科室退货".equals(subType)){ + //记入出库合计,数量为负 + type=GodownEntry.TYPE_OUT; + amount = - amount; + vo.setDepartmentReturnStorageAmount( + MathTools.add(amount,vo.getDepartmentReturnStorageAmount()).longValue()); + vo.setStockTakeOutStoragePrice( + MathTools.add(amount * cost, vo.getDepartmentReturnStoragePrice()).doubleValue()); + }else if("供应室领用".equals(subType)){ + vo.setReceiveRecordStorageAmount( + MathTools.add(amount,vo.getReceiveRecordStorageAmount()).longValue()); + vo.setReceiveRecordStoragePrice( + MathTools.add(amount * cost, vo.getReceiveRecordStoragePrice()).doubleValue()); + } + //单类型 + if(GodownEntry.TYPE_IN.equals(type)){ + vo.setInStorageAmount( + MathTools.add(amount,vo.getInStorageAmount()).longValue()); + vo.setInStoragePrice( + MathTools.add(amount * cost, vo.getInStoragePrice()).doubleValue()); + }else if(GodownEntry.TYPE_OUT.equals(type)){ + vo.setOutStorageAmount( + MathTools.add(amount,vo.getOutStorageAmount()).longValue()); + vo.setOutStoragePrice( + MathTools.add(amount * cost, vo.getOutStoragePrice()).doubleValue()); + } + } + + /** + * 添加期末的记录 + * @param item + */ + public void addEndItem(JSONObject item) { + String name = item.optString("name"); + String spec = item.optString("specification"); + MonthGoodsDetailVo vo = findOrAdd(name, spec,true); + long amout = item.optLong("amout"); + double price = item.optDouble("price"); + String externalCode = item.optString("externalCode"); + if(externalCode.equals("810026")){ + System.out.println("810026:" + price); + } + String unit = item.optString("unit"); + String type = item.optString("type"); + vo.setType(type); + vo.setExternalCode(externalCode); + vo.setUnit(unit); + vo.setEndStockAmount(amout); + vo.setEndStockPrice(price); + } + /** + * 添加期初的记录 + * @param item + */ + public void addStartItem(JSONObject item) { + String name = item.optString("name"); + String spec = item.optString("specification"); + MonthGoodsDetailVo vo = findOrAdd(name, spec,true); + long amout = item.optLong("amout"); + double price = item.optDouble("price"); + String externalCode = item.optString("externalCode"); + String unit = item.optString("unit"); + String type = item.optString("type"); + vo.setType(type); + vo.setExternalCode(externalCode); + vo.setUnit(unit); + vo.setStartStockAmount(amout); + vo.setStartStockPrice(price); + } +} Index: ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java =================================================================== diff -u -r13248 -r13291 --- ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java (.../JasperReportManagerImpl.java) (revision 13248) +++ ssts-reports/src/main/java/com/forgon/disinfectsystem/jasperreports/service/JasperReportManagerImpl.java (.../JasperReportManagerImpl.java) (revision 13291) @@ -78,6 +78,8 @@ import com.forgon.disinfectsystem.entity.materialmanager.MaterialEntry; import com.forgon.disinfectsystem.entity.materialmanager.MaterialEntryItem; import com.forgon.disinfectsystem.entity.packing.PackingRecord; +import com.forgon.disinfectsystem.entity.receiverecord.ReceiveRecord; +import com.forgon.disinfectsystem.entity.receiverecord.ReceiveRecordItem; import com.forgon.disinfectsystem.entity.recyclingapplication.RecyclingApplication; import com.forgon.disinfectsystem.entity.recyclingdamagerecord.RecyclingDamageItem; import com.forgon.disinfectsystem.entity.recyclingdamagerecord.RecyclingDamageRecord; @@ -7618,7 +7620,7 @@ if ("汇总".equals(summaryType)) { return createGoodsSummary(endRecord, startRecord, type); } else { - return createGoodsDetail(endRecord, startRecord, type); + return createGoodsSummary1(endRecord, startRecord, type); } } @@ -7638,7 +7640,7 @@ return totalPrice; } public List createGoodsSummary(StockTakeRecord currentRecord,StockTakeRecord lastMonthRecord,String type){ - List list = createGoodsDetail(currentRecord,lastMonthRecord,type); + List list = createGoodsSummary1(currentRecord,lastMonthRecord,type); MonthGoodsDetailVo vo = new MonthGoodsDetailVo(); for(MonthGoodsDetailVo item : list){ vo.setStartStockPrice(MathTools.add(vo.getStartStockPrice(), item.getStartStockPrice()).doubleValue()); @@ -7650,8 +7652,155 @@ retList.add(vo); return retList; } + public List createGoodsSummary1(StockTakeRecord currentRecord,StockTakeRecord lastMonthRecord,String type){ + //List voList = new ArrayList(); + MonthGoodsDetailSummaryService service = new MonthGoodsDetailSummaryService(); + if(currentRecord != null){ + String projectName = CssdUtils.getConfigProperty("project"); + + ResultSet rs; + //计算期末 + calcStockTakeRecord(currentRecord, type, service,false); + //计算期初 + calcStockTakeRecord(lastMonthRecord, type, service,true); + + //入库单及出库单 + String startDate = ""; + if(lastMonthRecord != null){ + startDate = dateQueryAdapter.dateAdapter(lastMonthRecord.getStockTakeDate()); + } + String endDate = dateQueryAdapter.dateAdapter(currentRecord.getStockTakeDate()); + + String sql = "select d.name,d.specification,i.amount,i.cost,r.type,r.subType from" + + " GodownEntry r inner join GodownEntryItem i on r.id = i.godownEntry_id" + + " inner join DisposableGoodsStock d on i.diposableGoods_id = d.id" + + " where r.warehouseID=" + currentRecord.getWarehouseId(); + + if(StringUtils.isBlank(startDate)){ + sql += " and r.time < " + endDate + ""; + }else{ + sql += " and r.time between " + startDate + " and " + endDate + " "; + } + + //一次性物品发货单 + String diposableSql = "select dg.name,dg.specification,bo.amount,bo.price as cost," + + "'" + GodownEntry.TYPE_OUT + "' as type,'发货出库' as subType" + + " from Invoice po,DiposableGoodsItem bo,DisposableGoods dg " + + "where po.id = bo.invoice_id and bo.disposableGoodsID = dg.id " + + " and po.sourceWarehouseId=" + currentRecord.getWarehouseId(); + + if(StringUtils.isBlank(startDate)){ + diposableSql += " and po.sendTime < " + endDate; + }else{ + diposableSql += " and po.sendTime between " + startDate + " and " + endDate; + } + + //供应室领用 + String supplyRoomDiposableGoodsSql = " select dg.name,dg.specification,rri.price as cost,rri.amount" + + "'" + GodownEntry.TYPE_OUT + "' as type,'供应室领用' as subType" + +" from " + ReceiveRecord.class.getSimpleName() + " rr left join " + + ReceiveRecordItem.class.getSimpleName() + " rri on rr.id = rri.receiveRecord_id" + + " left join " + DisposableGoodsBatchStock.class.getSimpleName() + " dbs on rri.diposableGoodBatchStock_id = dbs.id" + +" left join " + DisposableGoods.class.getSimpleName() + " dg on dg.id=dbs.disposableGoodsID" + + " where rri.type='一次性物品' and rr.warehouseId="+currentRecord.getWarehouseId(); + if(StringUtils.isBlank(startDate)){ + supplyRoomDiposableGoodsSql += " and rr.time < " + endDate; + }else{ + supplyRoomDiposableGoodsSql += " and rr.time between " + startDate + " and " + endDate; + } + //科室退货 + String returnGoodsSql = "select dg.name,dg.specification,i.amount,i.price as cost," + + "'" + GodownEntry.TYPE_IN + "' as type,'科室退货' as subType from " + + ReturnGoodsItem.class.getSimpleName() + " i inner join " + + ReturnGoodsRecord.class.getSimpleName() + " r on r.id = i.returnGoodsRecord_ID " + + " inner join " + DisposableGoods.class.getSimpleName() + " dg on dg.id=i.disposableGoodsID" + + " where r.type='一次性物品' and r.warehouseID=" + currentRecord.getWarehouseId(); + if(StringUtils.isBlank(startDate)){ + returnGoodsSql += " and r.returnTime < " + endDate; + }else{ + returnGoodsSql += " and r.returnTime between " + startDate + " and " + endDate; + } + sql += " union all " + diposableSql; + sql += " union all " + supplyRoomDiposableGoodsSql; + sql += " union all " + returnGoodsSql; + rs = objectDao.executeSql(sql); + try { + while(rs.next()){ + JSONObject item = new JSONObject(); + item.put("name", rs.getString("name")); + item.put("specification", rs.getString("specification")); + item.put("amount",rs.getLong("amount")); + item.put("cost",rs.getDouble("cost")); + item.put("type", rs.getString("type")); + item.put("subType", rs.getString("subType")); + service.addItem(item); + } + } catch (SQLException e) { + e.printStackTrace(); + }finally{ + DatabaseUtil.closeResultSetAndStatement(rs); + } + } + return service.getList(); + //return voList; + } /** + * 计算期初或者期末余数 * @param currentRecord + * @param type + * @param service + * @param isStart 计算期初或者是期末 + */ + private void calcStockTakeRecord(StockTakeRecord stockTakeRecord, + String type, MonthGoodsDetailSummaryService service,boolean isStart) { + if(stockTakeRecord == null){ + return; + } + String typesql = ""; + if(StringUtils.isNotBlank(type)){ + typesql = " and po.type = '" + type + "' "; + } + + //一次性物品盘点的id与总价的中间结果 + String idStartPrice = "select g.id,sum(i.amount*i.price) as price from " + StockDiposableGoods.class.getSimpleName() + " g" + + " left join " + StockDiposableGoodBatch.class.getSimpleName() + " b" + + " on g.id=b.diposablegoods_id" + + " left join " + StockIdentificationOfGoods.class.getSimpleName() + " i" + + " on b.id=i.batch_id group by g.id"; + //计算期末/期末余数 + String stockDiposableGoodsSql = "select po.externalCode,po.name,po.unit,po.type,po.specification,po.amount as amout," + + " m.price as price from " + StockDiposableGoods.class.getSimpleName() + " po" + + " inner join " + StockTakeRecord.class.getSimpleName() + " r on r.id=po.takeRecord_id" + + " inner join ( " + idStartPrice + " ) m" + + " on m.id=po.id" + + " where r.id=" + stockTakeRecord.getId() + typesql + + " order by po.typeSequence,po.externalCode asc"; + + ResultSet rs = objectDao.executeSql(stockDiposableGoodsSql); + try { + while(rs.next()){ + JSONObject item = new JSONObject(); + item.put("externalCode", rs.getString("externalCode")); + item.put("name", rs.getString("name")); + item.put("unit",rs.getString("unit")); + item.put("type",rs.getString("type")); + item.put("specification", rs.getString("specification")); + item.put("amout", rs.getLong("amout")); + item.put("price", rs.getDouble("price")); + if(isStart){ + service.addStartItem(item); + }else{ + service.addEndItem(item); + } + } + } catch (SQLException e) { + e.printStackTrace(); + }finally{ + DatabaseUtil.closeResultSetAndStatement(rs); + } + } + /** + * @param currentRecord * @param lastMonthRecord * @param ops * @return @@ -7730,8 +7879,12 @@ for (StockIdentificationOfGoods stockIdentification : stockDiposableGoodBatch.getStockIdentifications()) { double tempPrice = MathTools.mul(stockIdentification.getAmount(), stockIdentification.getPrice()).doubleValue(); startPrice = MathTools.add(startPrice, tempPrice).doubleValue(); + if("810026".equals(vo.getExternalCode())){ + System.out.println(stockIdentification); + } } } + vo.setEndStockAmount(startAmount); vo.setEndStockPrice(startPrice); if(lastMonthRecord == null){