ERP:基本完成销售入库模块

This commit is contained in:
YunaiV 2024-02-11 22:12:56 +08:00
parent 0694bc8684
commit dbc367ad95
4 changed files with 55 additions and 6 deletions

View File

@ -18,6 +18,11 @@ public class MoneyUtils {
*/ */
private static final int PRICE_SCALE = 2; private static final int PRICE_SCALE = 2;
/**
* 百分比对应的 BigDecimal 对象
*/
public static final BigDecimal PERCENT_100 = BigDecimal.valueOf(100);
/** /**
* 计算百分比金额四舍五入 * 计算百分比金额四舍五入
* *
@ -107,4 +112,20 @@ public class MoneyUtils {
return price.multiply(count).setScale(PRICE_SCALE, RoundingMode.HALF_UP); return price.multiply(count).setScale(PRICE_SCALE, RoundingMode.HALF_UP);
} }
/**
* 金额相乘百分比默认进行四舍五入
*
* 位数{@link #PRICE_SCALE}
*
* @param price 金额
* @param percent 百分比
* @return 金额相乘结果
*/
public static BigDecimal priceMultiplyPercent(BigDecimal price, BigDecimal percent) {
if (price == null || percent == null) {
return null;
}
return price.multiply(percent).divide(PERCENT_100, PRICE_SCALE, RoundingMode.HALF_UP);
}
} }

View File

@ -30,6 +30,9 @@ public enum ErpStockRecordBizTypeEnum implements IntArrayValuable {
CHECK_MORE_IN_CANCEL(41, "盘盈入库(作废)"), CHECK_MORE_IN_CANCEL(41, "盘盈入库(作废)"),
CHECK_LESS_OUT(42, "盘亏出库"), CHECK_LESS_OUT(42, "盘亏出库"),
CHECK_LESS_OUT_CANCEL(43, "盘亏出库(作废)"), CHECK_LESS_OUT_CANCEL(43, "盘亏出库(作废)"),
SALE_OUT(50, "销售出库"),
SALE_OUT_CANCEL(51, "销售出库(作废)"),
; ;
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray(); public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(ErpStockRecordBizTypeEnum::getType).toArray();

View File

@ -131,7 +131,7 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService {
if (saleOrder.getDiscountPercent() == null) { if (saleOrder.getDiscountPercent() == null) {
saleOrder.setDiscountPercent(BigDecimal.ZERO); saleOrder.setDiscountPercent(BigDecimal.ZERO);
} }
saleOrder.setDiscountPrice(MoneyUtils.priceMultiply(saleOrder.getTotalPrice(), saleOrder.getDiscountPercent())); saleOrder.setDiscountPrice(MoneyUtils.priceMultiplyPercent(saleOrder.getTotalPrice(), saleOrder.getDiscountPercent()));
saleOrder.setTotalPrice(saleOrder.getTotalPrice().subtract(saleOrder.getDiscountPrice())); saleOrder.setTotalPrice(saleOrder.getTotalPrice().subtract(saleOrder.getDiscountPrice()));
} }
@ -191,8 +191,11 @@ public class ErpSaleOrderServiceImpl implements ErpSaleOrderService {
if (item.getTotalPrice() == null) { if (item.getTotalPrice() == null) {
return; return;
} }
item.setTaxPrice(MoneyUtils.priceMultiply(item.getTotalPrice(), item.getTaxPercent())); if (item.getTaxPercent() == null) {
item.setTotalPrice(item.getTotalPrice().add(item.getTaxPrice())); item.setTaxPercent(BigDecimal.ZERO);
} else {
item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent()));
}
})); }));
} }

View File

@ -15,8 +15,11 @@ import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutItemMapper;
import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutMapper; import cn.iocoder.yudao.module.erp.dal.mysql.sale.ErpSaleOutMapper;
import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO; import cn.iocoder.yudao.module.erp.dal.redis.no.ErpNoRedisDAO;
import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus; import cn.iocoder.yudao.module.erp.enums.ErpAuditStatus;
import cn.iocoder.yudao.module.erp.enums.stock.ErpStockRecordBizTypeEnum;
import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService; import cn.iocoder.yudao.module.erp.service.finance.ErpAccountService;
import cn.iocoder.yudao.module.erp.service.product.ErpProductService; import cn.iocoder.yudao.module.erp.service.product.ErpProductService;
import cn.iocoder.yudao.module.erp.service.stock.ErpStockRecordService;
import cn.iocoder.yudao.module.erp.service.stock.bo.ErpStockRecordCreateReqBO;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi; import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -60,6 +63,8 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService {
private ErpSaleOrderService saleOrderService; private ErpSaleOrderService saleOrderService;
@Resource @Resource
private ErpAccountService accountService; private ErpAccountService accountService;
@Resource
private ErpStockRecordService stockRecordService;
@Resource @Resource
private AdminUserApi adminUserApi; private AdminUserApi adminUserApi;
@ -142,8 +147,11 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService {
if (saleOut.getDiscountPercent() == null) { if (saleOut.getDiscountPercent() == null) {
saleOut.setDiscountPercent(BigDecimal.ZERO); saleOut.setDiscountPercent(BigDecimal.ZERO);
} }
saleOut.setDiscountPrice(MoneyUtils.priceMultiply(saleOut.getTotalPrice(), saleOut.getDiscountPercent())); saleOut.setDiscountPrice(MoneyUtils.priceMultiplyPercent(saleOut.getTotalPrice(), saleOut.getDiscountPercent()));
saleOut.setTotalPrice(saleOut.getTotalPrice().subtract(saleOut.getDiscountPrice())); saleOut.setTotalPrice(saleOut.getTotalPrice().subtract(saleOut.getDiscountPrice()));
// 计算应收金额
BigDecimal allPrice = saleOut.getTotalPrice().add(saleOut.getOtherPrice());
saleOut.setDebtPrice(allPrice.subtract(saleOut.getPayPrice()));
} }
private void updateSaleOrderOutCount(Long orderId) { private void updateSaleOrderOutCount(Long orderId) {
@ -173,6 +181,17 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService {
if (updateCount == 0) { if (updateCount == 0) {
throw exception(approve ? SALE_OUT_APPROVE_FAIL : SALE_OUT_PROCESS_FAIL); throw exception(approve ? SALE_OUT_APPROVE_FAIL : SALE_OUT_PROCESS_FAIL);
} }
// 3. 变更库存
List<ErpSaleOutItemDO> saleOutItems = saleOutItemMapper.selectListByOutId(id);
Integer bizType = approve ? ErpStockRecordBizTypeEnum.SALE_OUT.getType()
: ErpStockRecordBizTypeEnum.SALE_OUT_CANCEL.getType();
saleOutItems.forEach(saleOutItem -> {
BigDecimal count = approve ? saleOutItem.getCount().negate() : saleOutItem.getCount();
stockRecordService.createStockRecord(new ErpStockRecordCreateReqBO(
saleOutItem.getProductId(), saleOutItem.getWarehouseId(), count,
bizType, saleOutItem.getOutId(), saleOutItem.getId(), saleOut.getNo()));
});
} }
private List<ErpSaleOutItemDO> validateSaleOutItems(List<ErpSaleOutSaveReqVO.Item> list) { private List<ErpSaleOutItemDO> validateSaleOutItems(List<ErpSaleOutSaveReqVO.Item> list) {
@ -187,8 +206,11 @@ public class ErpSaleOutServiceImpl implements ErpSaleOutService {
if (item.getTotalPrice() == null) { if (item.getTotalPrice() == null) {
return; return;
} }
item.setTaxPrice(MoneyUtils.priceMultiply(item.getTotalPrice(), item.getTaxPercent())); if (item.getTaxPercent() == null) {
item.setTotalPrice(item.getTotalPrice().add(item.getTaxPrice())); item.setTaxPercent(BigDecimal.ZERO);
} else {
item.setTaxPrice(MoneyUtils.priceMultiplyPercent(item.getTotalPrice(), item.getTaxPercent()));
}
})); }));
} }