refactor(sales): 重构销售出库单单价计算逻辑
- 移除了未使用的代码片段- 优化了 groupMergeDetailedRows 方法的参数列表 - 新增 getRefsaleprice 方法用于获取参考售价 - 调整了单价计算逻辑,支持取参考售价和实付金额两种方式
This commit is contained in:
parent
472964e254
commit
4c0d0058f7
|
@ -856,7 +856,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
// 查询销售收发类别
|
||||
// BdRdclEntity bdRdclEntity = rdclUtil.queryRdClObject("202");
|
||||
//初始化所有存货管理档案对应的结存价+采购价
|
||||
List<Map> mapList = initAllBalancePricePurchasePrice();
|
||||
// List<Map> mapList = initAllBalancePricePurchasePrice();
|
||||
//查询「平台运费」存货基本档案
|
||||
BdInvbasdocEntity bdInvbasdocEntity1 = queryStockBasicArchives();
|
||||
//查询「平台运费」对应的税率
|
||||
|
@ -938,7 +938,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
Boolean isCheckShopChoose = balanceUnitPriceUtil.checkOfsShop(header.getStoreCode());
|
||||
|
||||
//把汇总好的出库单明细行合并成一行
|
||||
SonDetailsDto sonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose, mapList);
|
||||
SonDetailsDto sonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose);
|
||||
|
||||
//存货管理档案:取发货公司的存货管理档案
|
||||
// BdInvmandocEntity bdInvmandocEntity = queryInventoryMan(sonDetailsDto, bdCalbodyEntity.getPkCorp());
|
||||
|
@ -1666,14 +1666,15 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
* 单价计算公式:sum(实付金额/实发数量) 最后除以条数
|
||||
*
|
||||
* @param sonDetailsDtoList 销售出库单明细行集合
|
||||
* @param isCheckShopChoose true取参考售价、false取O应收
|
||||
* @author liuyang
|
||||
*/
|
||||
private SonDetailsDto groupMergeDetailedRows(List<SonDetailsDto> sonDetailsDtoList, Boolean isCheckShopChoose, List<Map> mapList) throws Exception {
|
||||
private SonDetailsDto groupMergeDetailedRows(List<SonDetailsDto> sonDetailsDtoList, Boolean isCheckShopChoose) throws Exception {
|
||||
Assert.notNull(sonDetailsDtoList, "sonDetailsDtoList不能为空");
|
||||
Assert.notNull(isCheckShopChoose, "isCheckShopChoose不能为空");
|
||||
Assert.notNull(mapList, "mapLists不能为空");
|
||||
|
||||
StringBuffer aaa = new StringBuffer();
|
||||
// Assert.notNull(mapList, "mapLists不能为空");
|
||||
// StringBuffer aaa = new StringBuffer();
|
||||
if (sonDetailsDtoList != null && sonDetailsDtoList.size() > 0) {
|
||||
BigDecimal groupTotalPayAmount = new BigDecimal("0");
|
||||
BigDecimal groupShipQty = new BigDecimal("0");
|
||||
|
@ -1682,6 +1683,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
SonDetailsDto sonDetailsDto = sonDetailsDtoList.get(i);
|
||||
HeaderDto header = sonDetailsDto.getHeader();//销售出库单表头
|
||||
BdInvmandocEntity bdInvmandocEntity = sonDetailsDto.getBdInvmandocEntity();//存货管理档案
|
||||
BdInvbasdocEntity bdInvbasdocEntity = sonDetailsDto.getBdInvbasdocEntity();//存货基本档案
|
||||
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDetailsDto headerDetailsDto = sonDetailsDto.getHeaderDetailsDto();//OFS销售订单
|
||||
com.hzya.frame.ttxofs.dto.ofssalesordersearch.HeaderDto header1 = headerDetailsDto.getHeader();
|
||||
List<com.hzya.frame.ttxofs.dto.ofssalesordersearch.DetailsDto> details = headerDetailsDto.getDetails();
|
||||
|
@ -1702,9 +1704,13 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
//OFS销售订单实付金额:totalPayAmount
|
||||
//OFS销售出库单实付金额:totalPayAmount
|
||||
//是一样的字段,目前暂时取销售出库单对应的totalPayAmount
|
||||
String totalPayAmount = null;
|
||||
StringBuffer calculationFormulaStr = new StringBuffer();
|
||||
String totalPayAmount = getFloorPrice(isCheckShopChoose, bdInvmandocEntity, header, sonDetailsDto, mapList, calculationFormulaStr);
|
||||
if (totalPayAmount == null) {
|
||||
if (isCheckShopChoose) {
|
||||
//取《U8C存货基本档案-参考售价》
|
||||
totalPayAmount = getRefsaleprice(bdInvmandocEntity, bdInvbasdocEntity, calculationFormulaStr, sonDetailsDto, header);
|
||||
} else {
|
||||
//取《O实付》
|
||||
calculationFormulaStr.append("取O应收金额:");
|
||||
//触发取实付金额的逻辑,因此需要累加:O实付金额+O达人优惠+O支付优惠+O平台优惠
|
||||
//取O实付金额
|
||||
|
@ -1724,19 +1730,47 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
BigDecimal detailedLineUnitPrice = new BigDecimal(targetDetails.getPayableAmount()).divide(new BigDecimal(targetDetails.getRequestQty()), 20, BigDecimal.ROUND_HALF_UP);
|
||||
BigDecimal totalPayAmountBigDecimal = detailedLineUnitPrice.multiply(new BigDecimal(sonDetailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
totalPayAmount = totalPayAmountBigDecimal.stripTrailingZeros().toPlainString();
|
||||
aaa.append(totalPayAmount);
|
||||
aaa.append(",");
|
||||
// aaa.append(totalPayAmount);
|
||||
// aaa.append(",");
|
||||
|
||||
String format = StrUtil.format("{}/{}*{}", targetDetails.getPayableAmount(), targetDetails.getRequestQty(), sonDetailsDto.getShipQty());
|
||||
calculationFormulaStr.append(format);
|
||||
} else {
|
||||
//取结存单价、或者采购单价
|
||||
//和李佳妮确认取采购价、结存价的情况下,不需要累加优惠金额
|
||||
BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalPayAmount);
|
||||
// totalPayAmount = totalPayAmountBigDecimal.multiply(new BigDecimal(sonDetailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();
|
||||
totalPayAmount = totalPayAmountBigDecimal.stripTrailingZeros().toPlainString();
|
||||
}
|
||||
Assert.notNull(totalPayAmount, "应收金额不能为空(应收金额=实付金额+达人优惠+支付优惠+平台优惠) 销售出库单编码:{} 出库单明细主键:{}", header.getCode(), sonDetailsDto.getId());
|
||||
|
||||
// String totalPayAmount = getFloorPrice(isCheckShopChoose, bdInvmandocEntity, header, sonDetailsDto, mapList, calculationFormulaStr);
|
||||
// if (totalPayAmount == null) {
|
||||
// calculationFormulaStr.append("取O应收金额:");
|
||||
// //触发取实付金额的逻辑,因此需要累加:O实付金额+O达人优惠+O支付优惠+O平台优惠
|
||||
// //取O实付金额
|
||||
//// totalPayAmount = sonDetailsDto.getTotalPayAmount();
|
||||
//// totalPayAmount = accumulatedDiscounts(sonDetailsDto, headerDetailsDto, targetDetails);
|
||||
// //和万万确认,O销售出库单明细行应收金额=O销售订单明细行应收金额/O销售订单明细行请求数量*O销售出库单明细行实发数量
|
||||
// //这里做好必要的参数验证抛出异常
|
||||
// Assert.notNull(targetDetails.getPayableAmount(), "O应收金额不能为空 O销售订单编码:{} O明细行主键:{}", header1.getCode(), targetDetails.getId());
|
||||
// Assert.state(!"".equals(targetDetails.getPayableAmount()), "O应收金额不能为空 O销售订单编码:{} O明细行主键:{}", header1.getCode(), targetDetails.getId());
|
||||
//
|
||||
// Assert.notNull(targetDetails.getRequestQty(), "O请求数量不能为空 O销售订单编码:{} O明细行主键:{}", header1.getCode(), targetDetails.getId());
|
||||
// Assert.state(!"".equals(targetDetails.getRequestQty()), "O请求数量不能为空 O销售订单编码:{} O明细行主键:{}", header1.getCode(), targetDetails.getId());
|
||||
//
|
||||
// Assert.notNull(sonDetailsDto.getShipQty(), "O实发数量不能为空 O销售出库单编码:{} O明细行主键:{}", header.getCode(), sonDetailsDto.getId());
|
||||
// Assert.state(!"".equals(sonDetailsDto.getShipQty()), "O实发数量不能为空 O销售出库单编码:{} O明细行主键:{}", header.getCode(), sonDetailsDto.getId());
|
||||
//
|
||||
// BigDecimal detailedLineUnitPrice = new BigDecimal(targetDetails.getPayableAmount()).divide(new BigDecimal(targetDetails.getRequestQty()), 20, BigDecimal.ROUND_HALF_UP);
|
||||
// BigDecimal totalPayAmountBigDecimal = detailedLineUnitPrice.multiply(new BigDecimal(sonDetailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP);
|
||||
// totalPayAmount = totalPayAmountBigDecimal.stripTrailingZeros().toPlainString();
|
||||
//// aaa.append(totalPayAmount);
|
||||
//// aaa.append(",");
|
||||
//
|
||||
// String format = StrUtil.format("{}/{}*{}", targetDetails.getPayableAmount(), targetDetails.getRequestQty(), sonDetailsDto.getShipQty());
|
||||
// calculationFormulaStr.append(format);
|
||||
// } else {
|
||||
// //取结存单价、或者采购单价
|
||||
// //和李佳妮确认取采购价、结存价的情况下,不需要累加优惠金额
|
||||
// BigDecimal totalPayAmountBigDecimal = new BigDecimal(totalPayAmount);
|
||||
//// totalPayAmount = totalPayAmountBigDecimal.multiply(new BigDecimal(sonDetailsDto.getShipQty())).setScale(2, BigDecimal.ROUND_HALF_UP).stripTrailingZeros().toPlainString();
|
||||
// totalPayAmount = totalPayAmountBigDecimal.stripTrailingZeros().toPlainString();
|
||||
// }
|
||||
// Assert.notNull(sonDetailsDto.getShipQty(), "实发数量不能为空 销售出库单编码:{} 出库单明细主键:{}", header.getCode(), sonDetailsDto.getId());
|
||||
|
||||
// BigDecimal totalPayAmountBigDecimal = new BigDecimal("0");
|
||||
|
@ -1780,7 +1814,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
|
||||
//累加各类优惠
|
||||
// logger.info("{}个明细行发生了合并!", sonDetailsDtoList.size());
|
||||
System.out.println(aaa.toString());
|
||||
// System.out.println(aaa.toString());
|
||||
return sonDetailsDto;
|
||||
} else {
|
||||
logger.error("sonDetailsDtoList集合是空的!");
|
||||
|
@ -1923,7 +1957,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
//查询销售收发类别
|
||||
// BdRdclEntity bdRdclEntity = rdclUtil.queryRdClObject("202");
|
||||
//初始化所有存货管理档案对应的结存价+采购价
|
||||
List<Map> mapList = initAllBalancePricePurchasePrice();
|
||||
// List<Map> mapList = initAllBalancePricePurchasePrice();
|
||||
//查询「平台运费」存货基本档案
|
||||
BdInvbasdocEntity bdInvbasdocEntity1 = queryStockBasicArchives();
|
||||
//查询「平台运费」对应的税率
|
||||
|
@ -1965,7 +1999,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
//如果这个汇总集合,已经全部推送成功,那么就不需要推送红字销售订单,把isOneSuccess标识修改为true即可
|
||||
if (!"Y".equals(newState2)) {
|
||||
//合并成一行
|
||||
SonDetailsDto sonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose, mapList);//把汇总好的出库单明细行合并成一行
|
||||
SonDetailsDto sonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose);//把汇总好的出库单明细行合并成一行
|
||||
BdInvmandocEntity bdInvmandocEntity = sonDetailsDto.getBdInvmandocEntity();//存货管理档案:取发货公司的存货管理档案
|
||||
BdInvbasdocEntity bdInvbasdocEntity = sonDetailsDto.getBdInvbasdocEntity();//存货基础档案
|
||||
BdTaxitemsEntity bdTaxitemsEntity1 = sonDetailsDto.getBdTaxitemsEntity();//根据存货基础档案编码,查询当前存货的税率
|
||||
|
@ -2186,7 +2220,7 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
logger.info("开始第二阶段:销售订单 ->(自动生成) 销售出库单 ->(自动生成) 销售发票");
|
||||
try {
|
||||
//合并成一行
|
||||
SonDetailsDto sonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose, mapList);//把汇总好的出库单明细行合并成一行
|
||||
SonDetailsDto sonDetailsDto = groupMergeDetailedRows(oldValue, isCheckShopChoose);//把汇总好的出库单明细行合并成一行
|
||||
BdInvmandocEntity bdInvmandocEntity = sonDetailsDto.getBdInvmandocEntity();//存货管理档案:取发货公司的存货管理档案
|
||||
BdInvbasdocEntity bdInvbasdocEntity = sonDetailsDto.getBdInvbasdocEntity();//存货基础档案
|
||||
BdTaxitemsEntity bdTaxitemsEntity1 = sonDetailsDto.getBdTaxitemsEntity();//根据存货基础档案编码,查询当前存货的税率
|
||||
|
@ -3518,4 +3552,37 @@ public class SoSaleOutPluginInitializerToC extends PluginBaseEntity {
|
|||
sonDetailsDtoList.get(0).setVdef7(merchantDiscountsBigDecimal.stripTrailingZeros().toPlainString());//商家
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取参考售价
|
||||
*
|
||||
* @param bdInvmandocEntity 存货管理档案
|
||||
* @param bdInvbasdocEntity 存货基本档案
|
||||
* @param calculationFormulaStr 计算公式
|
||||
* @param sonDetailsDto O销售出库单明细行
|
||||
* @param header O销售出库单表头
|
||||
* @author liuyang
|
||||
*/
|
||||
private String getRefsaleprice(BdInvmandocEntity bdInvmandocEntity, BdInvbasdocEntity bdInvbasdocEntity, StringBuffer calculationFormulaStr, SonDetailsDto sonDetailsDto, HeaderDto header) throws Exception {
|
||||
Assert.notNull(bdInvmandocEntity, "bdInvmandocEntity不能为空!");
|
||||
Assert.notNull(bdInvbasdocEntity, "bdInvbasdocEntity不能为空!");
|
||||
Assert.notNull(calculationFormulaStr, "calculationFormulaStr不能为空!");
|
||||
Assert.notNull(sonDetailsDto, "sonDetailsDto不能为空!");
|
||||
Assert.notNull(header, "header不能为空");
|
||||
|
||||
//U参考售价
|
||||
String refsaleprice = bdInvmandocEntity.getRefsaleprice();
|
||||
Assert.notNull(refsaleprice, "存货:{} 公司:{} 不存在参考售价,请维护!", bdInvbasdocEntity.getInvname(), bdInvmandocEntity.getPkCorp());
|
||||
|
||||
//O实发数量
|
||||
String shipQty = sonDetailsDto.getShipQty();
|
||||
Assert.notNull(shipQty, "O实发数量不能为空 O销售出库单编码:{} O明细行主键:{}", header.getCode(), sonDetailsDto.getId());
|
||||
Assert.state(!"".equals(shipQty), "O实发数量不能为空 O销售出库单编码:{} O明细行主键:{}", header.getCode(), sonDetailsDto.getId());
|
||||
|
||||
BigDecimal amountOfMoney = new BigDecimal(refsaleprice).multiply(new BigDecimal(shipQty));
|
||||
|
||||
String format = StrUtil.format("取U参考售价:{}*{}", refsaleprice, shipQty);
|
||||
calculationFormulaStr.append(format);
|
||||
return amountOfMoney.stripTrailingZeros().toPlainString();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue