Commit dbc367ad9511445c437b3b17aa5a92df4b13bab8
1 parent
0694bc86
✨ ERP:基本完成销售入库模块
Showing
4 changed files
with
55 additions
and
6 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/number/MoneyUtils.java
| ... | ... | @@ -19,6 +19,11 @@ public class MoneyUtils { |
| 19 | 19 | private static final int PRICE_SCALE = 2; |
| 20 | 20 | |
| 21 | 21 | /** |
| 22 | + * 百分比对应的 BigDecimal 对象 | |
| 23 | + */ | |
| 24 | + public static final BigDecimal PERCENT_100 = BigDecimal.valueOf(100); | |
| 25 | + | |
| 26 | + /** | |
| 22 | 27 | * 计算百分比金额,四舍五入 |
| 23 | 28 | * |
| 24 | 29 | * @param price 金额 |
| ... | ... | @@ -107,4 +112,20 @@ public class MoneyUtils { |
| 107 | 112 | return price.multiply(count).setScale(PRICE_SCALE, RoundingMode.HALF_UP); |
| 108 | 113 | } |
| 109 | 114 | |
| 115 | + /** | |
| 116 | + * 金额相乘(百分比),默认进行四舍五入 | |
| 117 | + * | |
| 118 | + * 位数:{@link #PRICE_SCALE} | |
| 119 | + * | |
| 120 | + * @param price 金额 | |
| 121 | + * @param percent 百分比 | |
| 122 | + * @return 金额相乘结果 | |
| 123 | + */ | |
| 124 | + public static BigDecimal priceMultiplyPercent(BigDecimal price, BigDecimal percent) { | |
| 125 | + if (price == null || percent == null) { | |
| 126 | + return null; | |
| 127 | + } | |
| 128 | + return price.multiply(percent).divide(PERCENT_100, PRICE_SCALE, RoundingMode.HALF_UP); | |
| 129 | + } | |
| 130 | + | |
| 110 | 131 | } | ... | ... |
yudao-module-erp/yudao-module-erp-api/src/main/java/cn/iocoder/yudao/module/erp/enums/stock/ErpStockRecordBizTypeEnum.java
| ... | ... | @@ -30,6 +30,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable { |
| 30 | 30 | CHECK_MORE_IN_CANCEL(41, "盘盈入库(作废)"), |
| 31 | 31 | CHECK_LESS_OUT(42, "盘亏出库"), |
| 32 | 32 | CHECK_LESS_OUT_CANCEL(43, "盘亏出库(作废)"), |
| 33 | + | |
| 34 | + SALE_OUT(50, "销售出库"), | |
| 35 | + SALE_OUT_CANCEL(51, "销售出库(作废)"), | |
| 33 | 36 | ; |
| 34 | 37 | |
| 35 | 38 | public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray(); | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleOrderServiceImpl.java
| ... | ... | @@ -131,7 +131,7 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService { |
| 131 | 131 | if (saleOrder.getDiscountPercent() == null) { |
| 132 | 132 | saleOrder.setDiscountPercent(BigDecimal.ZERO); |
| 133 | 133 | } |
| 134 | - saleOrder.setDiscountPrice(MoneyUtils.priceMultiply(saleOrder.getTotalPrice(), saleOrder.getDiscountPercent())); | |
| 134 | + saleOrder.setDiscountPrice(MoneyUtils.priceMultiplyPercent(saleOrder.getTotalPrice(), saleOrder.getDiscountPercent())); | |
| 135 | 135 | saleOrder.setTotalPrice(saleOrder.getTotalPrice().subtract(saleOrder.getDiscountPrice())); |
| 136 | 136 | } |
| 137 | 137 | |
| ... | ... | @@ -191,8 +191,11 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService { |
| 191 | 191 | if (item.getTotalPrice() == null) { |
| 192 | 192 | return; |
| 193 | 193 | } |
| 194 | - item.setTaxPrice(MoneyUtils.priceMultiply(item.getTotalPrice(), item.getTaxPercent())); | |
| 195 | - item.setTotalPrice(item.getTotalPrice().add(item.getTaxPrice())); | |
| 194 | + if (item.getTaxPercent() == null) { | |
| 195 | + item.setTaxPercent(BigDecimal.ZERO); | |
| 196 | + } else { | |
| 197 | + item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent())); | |
| 198 | + } | |
| 196 | 199 | })); |
| 197 | 200 | } |
| 198 | 201 | ... | ... |
yudao-module-erp/yudao-module-erp-biz/src/main/java/cn/iocoder/yudao/module/erp/service/sale/ErpSaleOutServiceImpl.java
| ... | ... | @@ -15,8 +15,11 @@ import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutItemMapper; |
| 15 | 15 | import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutMapper; |
| 16 | 16 | import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO; |
| 17 | 17 | import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; |
| 18 | +import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum; | |
| 18 | 19 | import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService; |
| 19 | 20 | import cn.iocoder.yudao.module.erp.service.product.ErpProductService; |
| 21 | +import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService; | |
| 22 | +import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO; | |
| 20 | 23 | import cn.iocoder.yudao.module.system.api.user.AdminUserApi; |
| 21 | 24 | import jakarta.annotation.Resource; |
| 22 | 25 | import org.springframework.context.annotation.Lazy; |
| ... | ... | @@ -60,6 +63,8 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 60 | 63 | private ErpSaleOrderService saleOrderService; |
| 61 | 64 | @Resource |
| 62 | 65 | private ErpAccountService accountService; |
| 66 | + @Resource | |
| 67 | + private ErpStockRecordService stockRecordService; | |
| 63 | 68 | |
| 64 | 69 | @Resource |
| 65 | 70 | private AdminUserApi adminUserApi; |
| ... | ... | @@ -142,8 +147,11 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 142 | 147 | if (saleOut.getDiscountPercent() == null) { |
| 143 | 148 | saleOut.setDiscountPercent(BigDecimal.ZERO); |
| 144 | 149 | } |
| 145 | - saleOut.setDiscountPrice(MoneyUtils.priceMultiply(saleOut.getTotalPrice(), saleOut.getDiscountPercent())); | |
| 150 | + saleOut.setDiscountPrice(MoneyUtils.priceMultiplyPercent(saleOut.getTotalPrice(), saleOut.getDiscountPercent())); | |
| 146 | 151 | saleOut.setTotalPrice(saleOut.getTotalPrice().subtract(saleOut.getDiscountPrice())); |
| 152 | + // 计算应收金额 | |
| 153 | + BigDecimal allPrice = saleOut.getTotalPrice().add(saleOut.getOtherPrice()); | |
| 154 | + saleOut.setDebtPrice(allPrice.subtract(saleOut.getPayPrice())); | |
| 147 | 155 | } |
| 148 | 156 | |
| 149 | 157 | private void updateSaleOrderOutCount(Long orderId) { |
| ... | ... | @@ -173,6 +181,17 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 173 | 181 | if (updateCount == 0) { |
| 174 | 182 | throw exception(approve ? SALE_OUT_APPROVE_FAIL : SALE_OUT_PROCESS_FAIL); |
| 175 | 183 | } |
| 184 | + | |
| 185 | + // 3. 变更库存 | |
| 186 | + List<ErpSaleOutItemDO> saleOutItems = saleOutItemMapper.selectListByOutId(id); | |
| 187 | + Integer bizType = approve ? ErpStockRecordBizTypeEnum.SALE_OUT.getType() | |
| 188 | + : ErpStockRecordBizTypeEnum.SALE_OUT_CANCEL.getType(); | |
| 189 | + saleOutItems.forEach(saleOutItem -> { | |
| 190 | + BigDecimal count = approve ? saleOutItem.getCount().negate() : saleOutItem.getCount(); | |
| 191 | + stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO( | |
| 192 | + saleOutItem.getProductId(), saleOutItem.getWarehouseId(), count, | |
| 193 | + bizType, saleOutItem.getOutId(), saleOutItem.getId(), saleOut.getNo())); | |
| 194 | + }); | |
| 176 | 195 | } |
| 177 | 196 | |
| 178 | 197 | private List<ErpSaleOutItemDO> validateSaleOutItems(List<ErpSaleOutSaveReqVO.Item> list) { |
| ... | ... | @@ -187,8 +206,11 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService { |
| 187 | 206 | if (item.getTotalPrice() == null) { |
| 188 | 207 | return; |
| 189 | 208 | } |
| 190 | - item.setTaxPrice(MoneyUtils.priceMultiply(item.getTotalPrice(), item.getTaxPercent())); | |
| 191 | - item.setTotalPrice(item.getTotalPrice().add(item.getTaxPrice())); | |
| 209 | + if (item.getTaxPercent() == null) { | |
| 210 | + item.setTaxPercent(BigDecimal.ZERO); | |
| 211 | + } else { | |
| 212 | + item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent())); | |
| 213 | + } | |
| 192 | 214 | })); |
| 193 | 215 | } |
| 194 | 216 | ... | ... |