diff --git a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSettleBillController.java b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSettleBillController.java
index a5d82b36a..db4abe2d1 100644
--- a/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSettleBillController.java
+++ b/emis-biz-web/src/main/java/com/xdadan/erp/web/emis/EmisSettleBillController.java
@@ -714,63 +714,104 @@ public class EmisSettleBillController extends BaseController
{
try {
- EmisSettleBill bill=emisBaseService.getSettleBillBySettleBillNo(emisSettleBill.getSettleBillNo());
+ // 参数校验
+ if (emisSettleBill == null || StringUtils.isEmpty(emisSettleBill.getSettleBillNo())) {
+ response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
+ return;
+ }
+
+ EmisSettleBill bill = emisBaseService.getSettleBillBySettleBillNo(emisSettleBill.getSettleBillNo());
+ // 账单不存在校验
+ if (bill == null) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
// 获取子账单数据
List list = emisBaseService.selectSubBillListBySettleBillNo(emisSettleBill.getSettleBillNo());
+ // 子账单列表为空校验
+ if (CollectionUtils.isEmpty(list)) {
+ response.setStatus(HttpServletResponse.SC_NOT_FOUND);
+ return;
+ }
+
// 转换子账单为 MAP
-
Map textMap = MapUtils.newHashMap();
- textMap.put("title", bill.getSettleBillName());
- textMap.put("total", bill.getRecMoney().stripTrailingZeros().toPlainString());
+ textMap.put("title", bill.getSettleBillName() != null ? bill.getSettleBillName() : "");
+ // 处理可能为null的金额
+ BigDecimal recMoney = bill.getRecMoney();
+ textMap.put("total", recMoney != null ? recMoney.stripTrailingZeros().toPlainString() : "0");
- String tplName="tpl/bill_tpl_simple.xlsx";
+ String tplName = "tpl/bill_tpl_simple.xlsx";
// 是否使用复复杂模版,如果有清关费用和其他费用都需要使用复杂模版
- boolean isNeedComplexTpl=false;
+ boolean isNeedComplexTpl = false;
+
+ List
+ *
+ * @param fromAuditCenterPass 是否来自财务中心审核通过(auditCenterPass)
+ */
+ private void validateWriteoffAmount(EmisWriteoffApply emisWriteoffApply, boolean fromAuditCenterPass)
+ throws EmisBizError {
if (CollectionUtils.isEmpty(emisWriteoffApply.getDetailList())) {
throw new EmisBizError("销账申请明细不能为空");
}
@@ -170,9 +185,16 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
}
// 验证:申请金额 + 已收金额 <= 账单应收金额
- BigDecimal totalAmount = detail.getApplyMoney().add(receivedAmount);
+ BigDecimal historyApplyAmount = BigDecimal.ZERO;
+ if (!fromAuditCenterPass) {
+ BigDecimal dbSum = emisWriteoffApplyDetailMapper.sumHistoryApplyMoneyByBillCode(detail.getBillCode(),
+ emisWriteoffApply.getId());
+ historyApplyAmount = dbSum != null ? dbSum : BigDecimal.ZERO;
+ }
+
+ BigDecimal totalAmount = detail.getApplyMoney().add(historyApplyAmount).add(receivedAmount);
if (totalAmount.compareTo(recMoney) > 0) {
- throw new EmisBizError("运单号 " + detail.getBillCode() + " 的申请金额(" + detail.getApplyMoney()
+ throw new EmisBizError("运单号 " + detail.getBillCode() + " 的累计申请金额(" + detail.getApplyMoney().add(historyApplyAmount)
+ ") + 已收金额(" + receivedAmount + ") = " + totalAmount + " 超过运单应收金额("
+ recMoney + ")");
}
@@ -431,8 +453,8 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
.selectEmisWriteoffApplyDetailListByApplyIdWithDetails(existingApply.getId());
existingApply.setDetailList(detailList);
- // 验证销账金额
- validateWriteoffAmount(existingApply);
+ // 验证销账金额(财务中心审核通过场景不纳入“历史申请金额”)
+ validateWriteoffAmount(existingApply, true);
// 先更新相关业务数据(在更新审核状态之前进行验证和更新)
detailList = updateRelatedBusinessData(existingApply, true);
diff --git a/emis-biz/src/main/resources/mapper/EmisWriteoffApplyDetailMapper.xml b/emis-biz/src/main/resources/mapper/EmisWriteoffApplyDetailMapper.xml
index c1c653a36..15d419ffb 100644
--- a/emis-biz/src/main/resources/mapper/EmisWriteoffApplyDetailMapper.xml
+++ b/emis-biz/src/main/resources/mapper/EmisWriteoffApplyDetailMapper.xml
@@ -252,6 +252,19 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
left join emis_site dest_site on w.dispatch_underling_site_code = dest_site.site_code and dest_site.del_flag = '0'
+
+
+