| | |
| | | private BigDecimal endingQty; |
| | | |
| | | /** |
| | | * 当前实际库存数量 |
| | | * 差异数量(期末库存-期初库存) |
| | | * 期末大于期初时为正数,表示库存增加 |
| | | */ |
| | | @ApiModelProperty(value = "当前实际库存数量") |
| | | @TableField("stock_qty") |
| | | private BigDecimal stockQty; |
| | | |
| | | /** |
| | | * 差异数量(实际库存-期末库存) |
| | | */ |
| | | @ApiModelProperty(value = "差异数量(实际库存-期末库存)") |
| | | @ApiModelProperty(value = "差异数量(期末库存-期初库存)") |
| | | @TableField("diff_qty") |
| | | private BigDecimal diffQty; |
| | | |
| | |
| | | currentMaterialMap.put(key, stat); |
| | | } |
| | | |
| | | // 收集所有需要查询库存的物料(本期有出入库的 + 上一期存在但本期没有出入库的) |
| | | List<String> matnrBatchList = new java.util.ArrayList<>(); |
| | | for (MaterialInOutStatDTO stat : materialStats) { |
| | | String matnr = stat.getMatnr(); |
| | | String batch = stat.getBatch() != null ? stat.getBatch() : ""; |
| | | matnrBatchList.add(matnr + "_" + batch); |
| | | } |
| | | if (previousSettle != null && !previousDetailMap.isEmpty()) { |
| | | for (Map.Entry<String, PreviousSettleEndingQtyDTO> entry : previousDetailMap.entrySet()) { |
| | | String key = entry.getKey(); |
| | | if (!currentMaterialMap.containsKey(key)) { |
| | | PreviousSettleEndingQtyDTO previousDetail = entry.getValue(); |
| | | String matnr = previousDetail.getMatnr(); |
| | | String batch = previousDetail.getBatch() != null ? previousDetail.getBatch() : ""; |
| | | String matnrBatchKey = matnr + "_" + batch; |
| | | if (!matnrBatchList.contains(matnrBatchKey)) { |
| | | matnrBatchList.add(matnrBatchKey); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | // 批量查询库存 |
| | | Map<String, BigDecimal> stockQtyMap = new HashMap<>(); |
| | | if (!matnrBatchList.isEmpty()) { |
| | | List<com.zy.asrs.entity.result.StockQtyDTO> stockQtyList = manLocDetlService.queryStockAnfmeBatch(matnrBatchList); |
| | | if (stockQtyList != null) { |
| | | for (com.zy.asrs.entity.result.StockQtyDTO stockQtyDTO : stockQtyList) { |
| | | String key = stockQtyDTO.getMatnr() + "_" + (stockQtyDTO.getBatch() != null ? stockQtyDTO.getBatch() : ""); |
| | | stockQtyMap.put(key, stockQtyDTO.getStockQty() != null ? stockQtyDTO.getStockQty() : BigDecimal.ZERO); |
| | | } |
| | | } |
| | | } |
| | | |
| | | // 收集所有明细记录,用于批量插入 |
| | | List<MonthlySettleDetail> detailList = new java.util.ArrayList<>(); |
| | | |
| | |
| | | // 3. 计算库存相关数量 |
| | | BigDecimal beginningQty = getBeginningQty(matnr, batch, brand, previousEndingQtyMap); |
| | | BigDecimal endingQty = calculateEndingQty(beginningQty, inQty, outQty); |
| | | // 从批量查询的Map中获取库存 |
| | | String stockKey = matnr + "_" + batch; |
| | | BigDecimal stockQtyDecimal = stockQtyMap.getOrDefault(stockKey, BigDecimal.ZERO); |
| | | BigDecimal diffQty = calculateDiffQty(stockQtyDecimal, endingQty); |
| | | // 差异数量 = 期末库存 - 期初库存(期末大于期初时为正数) |
| | | BigDecimal diffQty = calculateDiffQty(beginningQty, endingQty); |
| | | |
| | | // 4. 创建明细记录(暂不插入) |
| | | MonthlySettleDetail detail = buildMonthlySettleDetail( |
| | | monthlySettle.getId(), settleNo, matnr, batch, maktx, brand, |
| | | beginningQty, inQty, outQty, endingQty, stockQtyDecimal, diffQty |
| | | beginningQty, inQty, outQty, endingQty, diffQty |
| | | ); |
| | | detail.setIsDeleted(0); // 未删除 |
| | | detailList.add(detail); |
| | |
| | | BigDecimal beginningQty = previousEndingQty; |
| | | // 期末库存 = 期初 + 入库 - 出库 = 期初(因为本期没有出入库) |
| | | BigDecimal endingQty = beginningQty; |
| | | // 从批量查询的Map中获取库存 |
| | | String stockKey = matnr + "_" + batch; |
| | | BigDecimal stockQtyDecimal = stockQtyMap.getOrDefault(stockKey, BigDecimal.ZERO); |
| | | // 计算差异 |
| | | BigDecimal diffQty = calculateDiffQty(stockQtyDecimal, endingQty); |
| | | // 差异数量 = 期初库存 - 期末库存(期初大于期末时为正数) |
| | | BigDecimal diffQty = calculateDiffQty(beginningQty, endingQty); |
| | | |
| | | // 创建明细记录(暂不插入) |
| | | MonthlySettleDetail detail = buildMonthlySettleDetail( |
| | | monthlySettle.getId(), settleNo, matnr, batch, maktx, brand, |
| | | beginningQty, inQty, outQty, endingQty, stockQtyDecimal, diffQty |
| | | beginningQty, inQty, outQty, endingQty, diffQty |
| | | ); |
| | | detail.setIsDeleted(0); // 未删除 |
| | | detailList.add(detail); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 计算差异数量(实际库存-期末库存) |
| | | * 计算差异数量(期末库存-期初库存) |
| | | * 期末大于期初时为正数,表示库存增加 |
| | | */ |
| | | private BigDecimal calculateDiffQty(BigDecimal stockQty, BigDecimal endingQty) { |
| | | return stockQty.subtract(endingQty); |
| | | private BigDecimal calculateDiffQty(BigDecimal beginningQty, BigDecimal endingQty) { |
| | | return endingQty.subtract(beginningQty); |
| | | } |
| | | |
| | | /** |
| | |
| | | private MonthlySettleDetail buildMonthlySettleDetail( |
| | | Long settleId, String settleNo, String matnr, String batch, String maktx, String brand, |
| | | BigDecimal beginningQty, BigDecimal inQty, BigDecimal outQty, BigDecimal endingQty, |
| | | BigDecimal stockQty, BigDecimal diffQty) { |
| | | BigDecimal diffQty) { |
| | | MonthlySettleDetail detail = new MonthlySettleDetail(); |
| | | // 基本信息 |
| | | detail.setSettleId(settleId); |
| | |
| | | detail.setInQty(inQty); |
| | | detail.setOutQty(outQty); |
| | | detail.setEndingQty(endingQty); |
| | | detail.setStockQty(stockQty); |
| | | // stock_qty 字段已废弃,实际库存等于期末库存,不再单独存储 |
| | | // detail.setStockQty(endingQty); |
| | | detail.setDiffQty(diffQty); |
| | | // 时间信息 |
| | | detail.setCreateTime(new Date()); |
| | |
| | | <result column="in_qty" property="inQty" /> |
| | | <result column="out_qty" property="outQty" /> |
| | | <result column="ending_qty" property="endingQty" /> |
| | | <result column="stock_qty" property="stockQty" /> |
| | | <result column="diff_qty" property="diffQty" /> |
| | | <result column="create_time" property="createTime" /> |
| | | <result column="is_deleted" property="isDeleted" /> |
| | |
| | | d.in_qty, |
| | | d.out_qty, |
| | | d.ending_qty, |
| | | d.stock_qty, |
| | | d.diff_qty, |
| | | d.create_time, |
| | | m.specs, |
| | |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'本期出库数量', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'out_qty'; |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'期末库存(期初+入库-出库)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'ending_qty'; |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'当前实际库存数量', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'stock_qty'; |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'差异数量(实际库存-期末库存)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'diff_qty'; |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'差异数量(期末库存-期初库存)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'diff_qty'; |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'创建时间', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'create_time'; |
| | | EXEC sp_addextendedproperty @name = N'MS_Description', @value = N'删除标记 0:未删除 1:已删除', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'man_monthly_settle_detail', @level2type = N'COLUMN', @level2name = N'is_deleted'; |
| | | |
| | |
| | | } |
| | | }, |
| | | { |
| | | field: 'stockQty', |
| | | align: 'right', |
| | | title: '实际库存', |
| | | width: 120, |
| | | templet: function (d) { |
| | | var qty = parseFloat(d.stockQty || 0); |
| | | return qty.toFixed(2); |
| | | } |
| | | }, |
| | | { |
| | | field: 'diffQty', |
| | | align: 'right', |
| | | title: '差异数量', |