mirror of
https://gitee.com/huangge1199_admin/vue-pro.git
synced 2024-11-23 07:41:53 +08:00
✨ ERP:基本完成销售入库模块
This commit is contained in:
parent
0694bc8684
commit
dbc367ad95
@ -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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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();
|
||||||
|
@ -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()));
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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()));
|
||||||
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user