修复应收应付明细单价生成不对的问题
This commit is contained in:
+23
-2
@@ -357,11 +357,13 @@ public class ReceivablePayableDetailServiceImpl
|
|||||||
try {
|
try {
|
||||||
String planId = matchedPlanId(waybill, contract);
|
String planId = matchedPlanId(waybill, contract);
|
||||||
if (Func.isEmpty(planId)) continue;
|
if (Func.isEmpty(planId)) continue;
|
||||||
|
// 自动生成只按合同计费方案计算,matchOnly=true 禁止回退读取运单自身其他费用。
|
||||||
List<ReceivablePayableCargoFee> matchedFees = calculatedFees(waybill, contract, planId, true);
|
List<ReceivablePayableCargoFee> matchedFees = calculatedFees(waybill, contract, planId, true);
|
||||||
if (matchedFees.isEmpty()) continue;
|
if (matchedFees.isEmpty()) continue;
|
||||||
|
BigDecimal contractUnitPrice = resolveContractUnitPrice(matchedFees);
|
||||||
for (String settlementType : List.of("payable", "receivable")) {
|
for (String settlementType : List.of("payable", "receivable")) {
|
||||||
if (existsByWaybill(waybill.getId(), settlementType)) continue;
|
if (existsByWaybill(waybill.getId(), settlementType)) continue;
|
||||||
ReceivablePayableDetail detail = buildDetail(waybill, contract, settlementType, matchedFees);
|
ReceivablePayableDetail detail = buildDetail(waybill, contract, settlementType, matchedFees, contractUnitPrice);
|
||||||
save(detail);
|
save(detail);
|
||||||
for (ReceivablePayableCargoFee fee : matchedFees) {
|
for (ReceivablePayableCargoFee fee : matchedFees) {
|
||||||
ReceivablePayableCargoFee copy = BeanUtil.copyProperties(fee, ReceivablePayableCargoFee.class);
|
ReceivablePayableCargoFee copy = BeanUtil.copyProperties(fee, ReceivablePayableCargoFee.class);
|
||||||
@@ -510,6 +512,11 @@ public class ReceivablePayableDetailServiceImpl
|
|||||||
}
|
}
|
||||||
|
|
||||||
private ReceivablePayableDetail buildDetail(Waybill waybill, ContractManage contract, String settlementType, List<ReceivablePayableCargoFee> fees) {
|
private ReceivablePayableDetail buildDetail(Waybill waybill, ContractManage contract, String settlementType, List<ReceivablePayableCargoFee> fees) {
|
||||||
|
return buildDetail(waybill, contract, settlementType, fees, resolveContractUnitPrice(fees));
|
||||||
|
}
|
||||||
|
|
||||||
|
private ReceivablePayableDetail buildDetail(Waybill waybill, ContractManage contract, String settlementType,
|
||||||
|
List<ReceivablePayableCargoFee> fees, BigDecimal unitPrice) {
|
||||||
BigDecimal freight = fees.stream().filter(this::isFreight).map(ReceivablePayableCargoFee::getAfterAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal freight = fees.stream().filter(this::isFreight).map(ReceivablePayableCargoFee::getAfterAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal total = fees.stream().map(ReceivablePayableCargoFee::getAfterAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
BigDecimal total = fees.stream().map(ReceivablePayableCargoFee::getAfterAmount).reduce(BigDecimal.ZERO, BigDecimal::add);
|
||||||
BigDecimal other = total.subtract(freight).setScale(2, RoundingMode.HALF_UP);
|
BigDecimal other = total.subtract(freight).setScale(2, RoundingMode.HALF_UP);
|
||||||
@@ -538,7 +545,7 @@ public class ReceivablePayableDetailServiceImpl
|
|||||||
detail.setQuantityUnit(waybill.getQuantityUnit());
|
detail.setQuantityUnit(waybill.getQuantityUnit());
|
||||||
detail.setMileage(waybill.getMileage());
|
detail.setMileage(waybill.getMileage());
|
||||||
detail.setBatchNo(waybill.getBatchNo());
|
detail.setBatchNo(waybill.getBatchNo());
|
||||||
detail.setUnitPrice(waybill.getUnitPrice());
|
detail.setUnitPrice(unitPrice);
|
||||||
detail.setCurrency("RMB");
|
detail.setCurrency("RMB");
|
||||||
detail.setFreightAmount(freight);
|
detail.setFreightAmount(freight);
|
||||||
detail.setOtherFeeAmount(other);
|
detail.setOtherFeeAmount(other);
|
||||||
@@ -549,6 +556,19 @@ public class ReceivablePayableDetailServiceImpl
|
|||||||
return detail;
|
return detail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private BigDecimal resolveContractUnitPrice(List<ReceivablePayableCargoFee> fees) {
|
||||||
|
return fees.stream()
|
||||||
|
.filter(this::isFreight)
|
||||||
|
.map(ReceivablePayableCargoFee::getUnitPrice)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.findFirst()
|
||||||
|
.orElseGet(() -> fees.stream()
|
||||||
|
.map(ReceivablePayableCargoFee::getUnitPrice)
|
||||||
|
.filter(Objects::nonNull)
|
||||||
|
.findFirst()
|
||||||
|
.orElse(BigDecimal.ZERO));
|
||||||
|
}
|
||||||
|
|
||||||
private ReceivablePayableCargoFee buildCargoFee(Long detailId, Waybill waybill) {
|
private ReceivablePayableCargoFee buildCargoFee(Long detailId, Waybill waybill) {
|
||||||
BigDecimal quantity = money(waybill.getQuantity());
|
BigDecimal quantity = money(waybill.getQuantity());
|
||||||
BigDecimal unitPrice = money(waybill.getUnitPrice());
|
BigDecimal unitPrice = money(waybill.getUnitPrice());
|
||||||
@@ -807,6 +827,7 @@ public class ReceivablePayableDetailServiceImpl
|
|||||||
detail.setFreightAmount(freight);
|
detail.setFreightAmount(freight);
|
||||||
detail.setOtherFeeAmount(total.subtract(freight));
|
detail.setOtherFeeAmount(total.subtract(freight));
|
||||||
detail.setTotalAmount(total);
|
detail.setTotalAmount(total);
|
||||||
|
detail.setUnitPrice(resolveContractUnitPrice(fees));
|
||||||
detail.setFeeItemsJson(JsonUtil.toJson(fees.stream().collect(HashMap<String, BigDecimal>::new, (map, fee) -> map.put(fee.getCargoName(), fee.getAfterAmount()), HashMap::putAll)));
|
detail.setFeeItemsJson(JsonUtil.toJson(fees.stream().collect(HashMap<String, BigDecimal>::new, (map, fee) -> map.put(fee.getCargoName(), fee.getAfterAmount()), HashMap::putAll)));
|
||||||
updateById(detail);
|
updateById(detail);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user