新增、编辑、删除费用后,都会根据费用明细重新汇总订单状态:
- 全部未出账:UNBILLED - 部分已出账、部分未出账:PARTIAL - 全部已出账:BILLED 3. 应收账单生成 - 预览、统计、分页生成支持 UNBILLED 和 PARTIAL; - PARTIAL 订单只读取未出账费用; - 生成成功后,只将本次实际生成的费用更新为 BILLED; - 不会重复带入历史已出账费用; - 账单金额只统计本次未出账费用。 4. 作废、取消、失败清理 - 只恢复当前账单关联的费用; - 如果费用仍被其他有效账单使用,则继续保持 BILLED; - 根据费用状态重新汇总订单状态; - 大账单清理使用批量 SQL,不组装几十万条费用 ID。
This commit is contained in:
@@ -39,6 +39,18 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
order by bill_id, field(fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE'), fee_id
|
||||
</select>
|
||||
|
||||
<select id="selectUnbilledByBillIds" resultMap="PrcIncomeBillFeeResult">
|
||||
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
|
||||
ar_bill_status, manual_flag, create_time
|
||||
from prc_income_bill_fee
|
||||
where ar_bill_status = #{arBillStatus}
|
||||
and bill_id in
|
||||
<foreach collection="billIds" item="billId" open="(" separator="," close=")">
|
||||
#{billId}
|
||||
</foreach>
|
||||
order by bill_id, field(fee_type, 'BASIC_FREIGHT', 'REGISTRATION_FEE', 'SURCHARGE'), fee_id
|
||||
</select>
|
||||
|
||||
<select id="selectByFeeId" parameterType="String" resultMap="PrcIncomeBillFeeResult">
|
||||
select fee_id, bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, currency, round_mode, remark,
|
||||
ar_bill_status, manual_flag, create_time
|
||||
@@ -98,6 +110,52 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="updateArBillStatusByFeeIds">
|
||||
update prc_income_bill_fee
|
||||
set ar_bill_status = #{toStatus}
|
||||
where ar_bill_status = #{fromStatus}
|
||||
and fee_id in
|
||||
<foreach collection="feeIds" item="feeId" open="(" separator="," close=")">
|
||||
#{feeId}
|
||||
</foreach>
|
||||
</update>
|
||||
|
||||
<update id="restoreUnbilledIfNoActiveArBill">
|
||||
update prc_income_bill_fee f
|
||||
set f.ar_bill_status = 'UNBILLED'
|
||||
where f.ar_bill_status = 'BILLED'
|
||||
and f.fee_id in
|
||||
<foreach collection="feeIds" item="feeId" open="(" separator="," close=")">
|
||||
#{feeId}
|
||||
</foreach>
|
||||
and not exists (
|
||||
select 1
|
||||
from ar_bill_detail_fee df
|
||||
inner join ar_bill_detail d on d.detail_id = df.detail_id
|
||||
inner join ar_bill b on b.ar_bill_id = d.ar_bill_id
|
||||
where df.prc_income_bill_fee_id = f.fee_id
|
||||
and b.status <> 'VOID'
|
||||
)
|
||||
</update>
|
||||
|
||||
<update id="restoreUnbilledIfNoActiveArBillByArBillId">
|
||||
update prc_income_bill_fee f
|
||||
inner join ar_bill_detail_fee current_df on current_df.prc_income_bill_fee_id = f.fee_id
|
||||
inner join ar_bill_detail current_d on current_d.detail_id = current_df.detail_id
|
||||
and current_d.ar_bill_id = #{arBillId}
|
||||
set f.ar_bill_status = 'UNBILLED'
|
||||
where f.ar_bill_status = 'BILLED'
|
||||
and not exists (
|
||||
select 1
|
||||
from ar_bill_detail_fee other_df
|
||||
inner join ar_bill_detail other_d on other_d.detail_id = other_df.detail_id
|
||||
inner join ar_bill other_b on other_b.ar_bill_id = other_d.ar_bill_id
|
||||
where other_df.prc_income_bill_fee_id = f.fee_id
|
||||
and other_b.status <> 'VOID'
|
||||
and other_b.ar_bill_id <> #{arBillId}
|
||||
)
|
||||
</update>
|
||||
|
||||
<delete id="deleteByFeeId" parameterType="String">
|
||||
delete from prc_income_bill_fee where fee_id = #{feeId}
|
||||
</delete>
|
||||
|
||||
Reference in New Issue
Block a user