select ar_bill_id,
bill_no,
bill_name,
customer_id,
customer_code,
customer_name,
bill_period_start,
bill_period_end,
bill_date,
currency,
order_count,
total_amount,
written_off_amount,
unwritten_amount,
status,
generation_status,
bill_version,
bank_account_name,
bank_account_no,
bank_name,
remark,
confirmed_by,
confirmed_time,
create_by,
create_user_id,
create_time,
update_by,
update_time
from ar_bill
and (generation_status is null or generation_status = 'READY')
and bill_no like concat('%', #{query.billNo}, '%')
and bill_name like concat('%', #{query.billName}, '%')
and customer_code like concat('%', #{query.customerCode},
'%')
and customer_name like concat('%', #{query.customerName},
'%')
and customer_id = #{query.customerId}
and status in
#{statusValue}
and status = #{query.status}
and currency = #{query.currency}
and bill_date >= #{query.billDateStart}
and bill_date <= #{query.billDateEnd}
and bill_period_end = #{query.billPeriodEnd}
insert into ar_bill (bill_no, bill_name, customer_id, customer_code, customer_name, bill_period_start,
bill_period_end,
bill_date, currency, order_count, total_amount, written_off_amount, unwritten_amount,
status, generation_status, bill_version, bank_account_name, bank_account_no, bank_name,
remark,
confirmed_by, confirmed_time, create_by, create_user_id, create_time, update_by, update_time)
values (#{billNo}, #{billName}, #{customerId}, #{customerCode}, #{customerName}, #{billPeriodStart},
#{billPeriodEnd},
#{billDate}, #{currency}, #{orderCount}, #{totalAmount}, #{writtenOffAmount}, #{unwrittenAmount},
#{status}, #{generationStatus}, #{billVersion}, #{bankAccountName}, #{bankAccountNo}, #{bankName},
#{remark},
#{confirmedBy}, #{confirmedTime}, #{createBy}, #{createUserId}, sysdate(), #{updateBy}, sysdate())
update ar_bill
set status = #{status},
remark = #{remark},
update_by = #{operator},
update_time = sysdate(),
confirmed_by = case when #{status} = 'CONFIRMED' then #{operator} else confirmed_by end,
confirmed_time = case when #{status} = 'CONFIRMED' then sysdate() else confirmed_time end
where ar_bill_id = #{arBillId}
and status = #{fromStatus}
update ar_bill
set written_off_amount = #{writtenOffAmount},
unwritten_amount = #{unwrittenAmount},
status = #{status},
update_by = #{operator},
update_time = sysdate()
where ar_bill_id = #{arBillId}
and status = #{fromStatus}
update ar_bill
set order_count = #{orderCount},
total_amount = #{totalAmount},
unwritten_amount = #{unwrittenAmount},
bill_period_start = case
when #{billPeriodStart} < bill_period_start then #{billPeriodStart}
else bill_period_start end,
update_by = #{operator},
update_time = sysdate()
where ar_bill_id = #{arBillId}
update ar_bill
set generation_status = #{generationStatus},
update_by = #{operator},
update_time = sysdate(),
remark = case when #{remark} is null or #{remark} = '' then remark else #{remark} end
where ar_bill_id = #{arBillId}