这个部分主要是对采购入库经过审核进行库存更新与库存变动日志记录
1、通过两个表erp_goods_stock和erp_goods_stock_log生成两个模块,分别是商品库存表与库存变动表
其中的前后端代码可以直接拿过来使用,当然以后很多地方还需要修改,目前先完成基本功能。
2、对采购入库审核通过的代码如下:
@Override @Transactional public Result approvePass(String id) throws Exception { ErpInSheet erpInSheet = erpInSheetMapper.selectById(id); if (erpInSheet == null) { return Result.error("采购入库单不存在!"); } if (erpInSheet.getStatus() == 2 ) { return Result.error("采购入库单已审核通过,不能再次审核!"); } erpInSheet.setStatus(2); //审核通过标志 2代表通过 SysUser loginUser = iErpThirdService.getLoginUser(); LambdaUpdateWrapper<ErpInSheet> updateOrderWrapper = Wrappers.lambdaUpdate(ErpInSheet.class) .set(ErpInSheet::getApproveBy, loginUser.getUsername()) .set(ErpInSheet::getApproveTime, LocalDateTime.now()) .eq(ErpInSheet::getId, erpInSheet.getId()); if(erpInSheetMapper.update(erpInSheet, updateOrderWrapper) != 1) { return Result.error("采购入库单信息已过期,请刷新重试!"); } Wrapper<ErpInSheetDetail> queryDetailWrapper = Wrappers.lambdaQuery(ErpInSheetDetail.class) .eq(ErpInSheetDetail::getSheetId, erpInSheet.getId()) .orderByAsc(ErpInSheetDetail::getOrderNo); List<ErpInSheetDetail> details = erpInSheetDetailService.list(queryDetailWrapper); for (ErpInSheetDetail detail : details) { ErpGoodsStockVo erpGoodsStockVo = new ErpGoodsStockVo(); erpGoodsStockVo.setScId(erpInSheet.getScId()); erpGoodsStockVo.setGoodsId(detail.getGoodsId()); erpGoodsStockVo.setStockNum(detail.getOrderNum()); erpGoodsStockVo.setTaxAmount(NumberUtil.mul(detail.getTaxPrice(), detail.getOrderNum())); erpGoodsStockVo.setUnTaxAmount(NumberUtil.mul(NumberUtil.calcUnTaxPrice(detail.getTaxPrice(), detail.getTaxRate()), detail.getOrderNum())); erpGoodsStockVo.setTaxPrice(detail.getTaxPrice()); erpGoodsStockVo.setUnTaxPrice(NumberUtil.calcUnTaxPrice(detail.getTaxPrice(), detail.getTaxRate())); erpGoodsStockVo.setBizCode(erpInSheet.getCode()); erpGoodsStockVo.setBizDetailId(detail.getId()); erpGoodsStockVo.setBizId(erpInSheet.getId()); erpGoodsStockVo.setBizType(GoodsStockType.PURCHASE.getCode()); erpGoodsStockService.inStock(erpGoodsStockVo); } return Result.OK("审核通过完成"); }
这里用了两个枚举
public enum GoodsStockType implements BaseEnum<Integer> { PURCHASE(1, "采购入库"), PURCHASE_RETURN(2, "采购退货出库"), SALE(3, "销售出库"), SALE_RETURN(4, "销售退货入库"), RETAIL(5, "零售出库"), RETAIL_RETURN(6, "零售退货入库"), CHECK_STOCK_IN(7, "盘点入库"), CHECK_STOCK_OUT(8, "盘点出库"), STOCK_COST_ADJUST( 9, "库存成本调整"); @EnumValue private final Integer code; private final String desc; GoodsStockType(Integer code, String desc) { this.code = code; this.desc = desc; } @Override public Integer getCode() { return this.code; } @Override public String getDesc() { return this.desc; } } /** * @Description: Enum基类 * @Author: nbacheng * @Date: 2022-11-25 * @Version: V1.0 */ public interface BaseEnum<T extends Serializable> extends Serializable { /** * 获取枚举值 * * @return */ T getCode(); /** * 获取描述 * * @return */ String getDesc(); }
3、上面同时调用了inStock的方法,代码如下:
@Override @Transactional public void inStock(ErpGoodsStockVo erpGoodsStockVo) throws Exception { Wrapper<ErpGoodsStock> queryWrapper = Wrappers.lambdaQuery(ErpGoodsStock.class) .eq(ErpGoodsStock::getGoodsId, erpGoodsStockVo.getGoodsId()).eq(ErpGoodsStock::getScId, erpGoodsStockVo.getScId()); ErpGoodsStock inerpGoodsStock = erpGoodsStockMapper.selectOne(queryWrapper); ErpGoodsStockLog erpGoodsStockLog = new ErpGoodsStockLog(); if(inerpGoodsStock == null) { //第一次入库,新增记录 inerpGoodsStock = new ErpGoodsStock(); inerpGoodsStock.setScId(erpGoodsStockVo.getScId()); inerpGoodsStock.setGoodsId(erpGoodsStockVo.getGoodsId()); inerpGoodsStock.setStockNum(erpGoodsStockVo.getStockNum()); inerpGoodsStock.setTaxPrice(erpGoodsStockVo.getTaxPrice()); inerpGoodsStock.setTaxAmount(erpGoodsStockVo.getTaxAmount()); inerpGoodsStock.setUnTaxPrice(erpGoodsStockVo.getUnTaxPrice()); inerpGoodsStock.setUnTaxAmount(erpGoodsStockVo.getUnTaxAmount()); erpGoodsStockMapper.insert(inerpGoodsStock); erpGoodsStockLog.setOriStockNum(0); erpGoodsStockLog.setOriUnTaxPrice(BigDecimal.ZERO); erpGoodsStockLog.setOriTaxPrice(BigDecimal.ZERO); } else {//已有库存数量金额更新 LambdaUpdateWrapper<ErpGoodsStock> updateWrapper = Wrappers.lambdaUpdate(ErpGoodsStock.class) .eq(ErpGoodsStock::getScId, erpGoodsStockVo.getScId()) .eq(ErpGoodsStock::getGoodsId, erpGoodsStockVo.getGoodsId()); erpGoodsStockLog.setOriStockNum(inerpGoodsStock.getStockNum()); erpGoodsStockLog.setOriUnTaxPrice(inerpGoodsStock.getUnTaxPrice()); erpGoodsStockLog.setOriTaxPrice(inerpGoodsStock.getTaxPrice()); inerpGoodsStock.setScId(erpGoodsStockVo.getScId()); inerpGoodsStock.setGoodsId(erpGoodsStockVo.getGoodsId()); inerpGoodsStock.setStockNum(inerpGoodsStock.getStockNum() + erpGoodsStockVo.getStockNum()); inerpGoodsStock.setTaxAmount(NumberUtil.add(inerpGoodsStock.getTaxAmount(), erpGoodsStockVo.getTaxAmount())); inerpGoodsStock.setTaxPrice(NumberUtil.div(inerpGoodsStock.getTaxAmount(), inerpGoodsStock.getStockNum())); inerpGoodsStock.setUnTaxAmount(NumberUtil.add(inerpGoodsStock.getUnTaxAmount(), erpGoodsStockVo.getUnTaxAmount())); inerpGoodsStock.setUnTaxPrice(NumberUtil.div(inerpGoodsStock.getUnTaxAmount(), inerpGoodsStock.getStockNum())); if(erpGoodsStockMapper.update(inerpGoodsStock, updateWrapper) != 1) { throw new Exception("入库更新信息已过期,请刷新重试!"); } } erpGoodsStockLog.setGoodsId(erpGoodsStockVo.getGoodsId()); erpGoodsStockLog.setScId(erpGoodsStockVo.getScId()); erpGoodsStockLog.setStockNum(erpGoodsStockVo.getStockNum()); erpGoodsStockLog.setTaxAmount(erpGoodsStockVo.getTaxAmount()); erpGoodsStockLog.setUnTaxAmount(erpGoodsStockVo.getUnTaxAmount()); erpGoodsStockLog.setCurStockNum(inerpGoodsStock.getStockNum()); erpGoodsStockLog.setCurTaxPrice(inerpGoodsStock.getTaxPrice()); erpGoodsStockLog.setCurUnTaxPrice(inerpGoodsStock.getUnTaxPrice()); erpGoodsStockLog.setBizCode(erpGoodsStockVo.getBizCode()); erpGoodsStockLog.setBizDetailId(erpGoodsStockVo.getBizDetailId()); erpGoodsStockLog.setBizId(erpGoodsStockVo.getBizId()); erpGoodsStockLog.setBizType(erpGoodsStockVo.getBizType()); erpGoodsStockLogService.save(erpGoodsStockLog); }
4、效果图:
两条采购入库
库存表
库存变动表