insert into prc_income_bill_fee (
bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
) values (
#{billId}, #{incomeBillId}, #{feeType}, #{feeName}, #{scId}, #{amount}, #{productAmount}, #{redlineAmount}, #{currency}, #{roundMode}, #{remark},
#{arBillStatus}, #{manualFlag}, sysdate()
)
insert into prc_income_bill_fee (
bill_id, income_bill_id, fee_type, fee_name, sc_id, amount, product_amount, redline_amount, currency, round_mode, remark,
ar_bill_status, manual_flag, create_time
) values
(#{item.billId}, #{item.incomeBillId}, #{item.feeType}, #{item.feeName}, #{item.scId}, #{item.amount},
#{item.productAmount}, #{item.redlineAmount},
#{item.currency}, #{item.roundMode}, #{item.remark},
#{item.arBillStatus}, #{item.manualFlag}, sysdate())
update prc_income_bill_fee
set fee_type = #{feeType},
fee_name = #{feeName},
sc_id = #{scId},
amount = #{amount},
product_amount = #{productAmount},
redline_amount = #{redlineAmount},
currency = #{currency},
round_mode = #{roundMode},
remark = #{remark},
income_bill_id = #{incomeBillId},
manual_flag = #{manualFlag}
where fee_id = #{feeId}
update prc_income_bill_fee
set ar_bill_status = #{toStatus}
where ar_bill_status = #{fromStatus}
and bill_id in
#{billId}
update prc_income_bill_fee
set ar_bill_status = #{toStatus}
where ar_bill_status = #{fromStatus}
and fee_id in
#{feeId}
update prc_income_bill_fee f
set f.ar_bill_status = 'UNBILLED'
where f.ar_bill_status = 'BILLED'
and f.fee_id in
#{feeId}
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 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}
)
delete from prc_income_bill_fee where fee_id = #{feeId}
delete from prc_income_bill_fee where bill_id = #{billId}
delete from prc_income_bill_fee
where bill_id = #{billId}
and (manual_flag is null or manual_flag <> '1')