demand: TMS系统 - 客户账单管理 - 业务销账申请 - 新增加运单号销账逻辑调整
This commit is contained in:
parent
157cac3817
commit
b22714e749
@ -10,9 +10,11 @@
|
||||
*/
|
||||
package com.xdadan.erp.emis.mapper;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.xdadan.erp.emis.domain.EmisWriteoffApplyDetail;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
/**
|
||||
* @ClassName EmisWriteoffApplyDetailMapper
|
||||
@ -104,4 +106,14 @@ public interface EmisWriteoffApplyDetailMapper extends BaseMapper<EmisWriteoffAp
|
||||
* @return 结果
|
||||
*/
|
||||
public int deleteEmisWriteoffApplyDetailByIds(Long[] ids);
|
||||
|
||||
/**
|
||||
* 根据运单号汇总历史申请金额(仅统计财务中心未通过的数据:bl_center_confirmed != 1)
|
||||
*
|
||||
* @param billCode 运单号
|
||||
* @param excludeApplyId 排除的申请ID(用于修改时避免把当前申请算入历史)
|
||||
* @return 历史申请金额合计(无数据返回0)
|
||||
*/
|
||||
BigDecimal sumHistoryApplyMoneyByBillCode(@Param("billCode") String billCode,
|
||||
@Param("excludeApplyId") Long excludeApplyId);
|
||||
}
|
||||
|
||||
@ -121,6 +121,21 @@ public class EmisWriteoffApplyServiceImpl extends EmisBaseService implements IEm
|
||||
* 验证:申请金额+已收金额 <= 运单应收金额
|
||||
*/
|
||||
private void validateWriteoffAmount(EmisWriteoffApply emisWriteoffApply) throws EmisBizError {
|
||||
validateWriteoffAmount(emisWriteoffApply, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证销账金额
|
||||
*
|
||||
* <p>
|
||||
* - 来自 auditCenterPass:申请金额 + 已收金额 <= 账单应收金额
|
||||
* - 非 auditCenterPass:申请金额 + 该运单历史申请金额(所有 bl_center_confirmed != 1 的申请明细之和) + 已收金额 <= 账单应收金额
|
||||
* </p>
|
||||
*
|
||||
* @param fromAuditCenterPass 是否来自财务中心审核通过(auditCenterPass)
|
||||
*/
|
||||
private void validateWriteoffAmount(EmisWriteoffApply emisWriteoffApply, boolean fromAuditCenterPass)
|
||||
throws EmisBizError {
|
||||
if (CollectionUtils.isEmpty(emisWriteoffApply.getDetailList())) {
|
||||
throw new EmisBizError("销账申请明细不能为空");
|
||||
}
|
||||
@ -170,7 +185,14 @@ 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()
|
||||
+ ") + 已收金额(" + receivedAmount + ") = " + totalAmount + " 超过运单应收金额("
|
||||
@ -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);
|
||||
|
||||
@ -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'
|
||||
</sql>
|
||||
|
||||
<!-- 根据运单号汇总历史申请金额(仅统计财务中心未通过的数据:bl_center_confirmed != 1) -->
|
||||
<select id="sumHistoryApplyMoneyByBillCode" resultType="java.math.BigDecimal">
|
||||
select ifnull(sum(wad.apply_money), 0)
|
||||
from emis_writeoff_apply_detail wad
|
||||
inner join emis_writeoff_apply wa on wa.id = wad.apply_id and wa.del_flag = '0'
|
||||
where wad.del_flag = '0'
|
||||
and wad.bill_code = #{billCode}
|
||||
and wa.bl_center_confirmed = '0'
|
||||
<if test="excludeApplyId != null">
|
||||
and wa.id != #{excludeApplyId}
|
||||
</if>
|
||||
</select>
|
||||
|
||||
<select id="selectEmisWriteoffApplyDetailList" parameterType="EmisWriteoffApplyDetail" resultMap="EmisWriteoffApplyDetailResult">
|
||||
<include refid="selectEmisWriteoffApplyDetailVo"/>
|
||||
<where>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user