insert into pay_bill ( bill_no, supplier_id, supplier_name, currency, source_type, period_start, period_end, order_count, total_amount, supplier_amount, diff_amount, paid_amount, due_date, status, bill_kind, original_bill_id, tax_rate, amount_net, tax_amount, exchange_rate, base_amount, rate_date, term_days, create_by, create_time, remark ) values ( #{billNo}, #{supplierId}, #{supplierName}, #{currency}, #{sourceType}, #{periodStart}, #{periodEnd}, #{orderCount}, #{totalAmount}, #{supplierAmount}, #{diffAmount}, #{paidAmount}, #{dueDate}, 'DRAFT', ifnull(#{billKind}, 'BLUE'), #{originalBillId}, ifnull(#{taxRate}, 0), ifnull(#{amountNet}, #{totalAmount}), ifnull(#{taxAmount}, 0), ifnull(#{exchangeRate}, 1), ifnull(#{baseAmount}, #{totalAmount}), #{rateDate}, #{termDays}, #{createBy}, sysdate(), #{remark} ) update pay_bill set status = #{status}, void_reason = #{voidReason}, void_by = #{voidBy}, void_time = #{voidTime}, update_by = #{updateBy}, update_time = sysdate() where bill_id = #{billId} insert into pay_bill_line ( bill_id, fee_id, order_bill_id, order_no, lading_no, lading_fee_id, fee_name, fee_source, fee_level, amount, supplier_amount, diff_amount, diff_status, currency, price_date, version_no, remote_flag, density_level, line_source ) values (#{item.billId}, #{item.feeId}, #{item.orderBillId}, #{item.orderNo}, #{item.ladingNo}, #{item.ladingFeeId}, #{item.feeName}, #{item.feeSource}, #{item.feeLevel}, #{item.amount}, #{item.supplierAmount}, #{item.diffAmount}, ifnull(#{item.diffStatus}, 'NONE'), #{item.currency}, #{item.priceDate}, #{item.versionNo}, #{item.remoteFlag}, #{item.densityLevel}, #{item.lineSource}) insert into pay_bill_line ( bill_id, fee_id, order_bill_id, order_no, lading_no, lading_fee_id, fee_name, fee_source, fee_level, amount, supplier_amount, diff_amount, diff_status, currency, price_date, version_no, remote_flag, density_level, line_source ) values ( #{billId}, #{feeId}, #{orderBillId}, #{orderNo}, #{ladingNo}, #{ladingFeeId}, #{feeName}, #{feeSource}, #{feeLevel}, #{amount}, #{supplierAmount}, #{diffAmount}, ifnull(#{diffStatus}, 'NONE'), #{currency}, #{priceDate}, #{versionNo}, #{remoteFlag}, #{densityLevel}, #{lineSource} ) update prc_pay_bill_fee set statement_line_id = #{lineId} where fee_id = #{feeId} and statement_line_id is null and ifnull(is_deleted, '0') = '0' update prc_pay_bill_fee set statement_line_id = null where statement_line_id = #{lineId} update prc_pay_bill_fee f inner join pay_bill_line l on l.line_id = f.statement_line_id set f.statement_line_id = null where l.bill_id = #{billId} update pay_bill set total_amount = #{totalAmount}, supplier_amount = #{supplierAmount}, diff_amount = #{diffAmount}, paid_amount = #{paidAmount}, order_count = #{orderCount}, status = #{status}, confirm_by = #{confirmBy}, confirm_time = #{confirmTime}, tax_rate = ifnull(#{taxRate}, 0), amount_net = ifnull(#{amountNet}, #{totalAmount}), tax_amount = ifnull(#{taxAmount}, 0), exchange_rate = ifnull(#{exchangeRate}, 1), base_amount = ifnull(#{baseAmount}, #{totalAmount}), rate_date = #{rateDate}, term_days = #{termDays}, update_by = #{updateBy}, update_time = sysdate() where bill_id = #{billId} update pay_bill_line set supplier_amount = #{supplierAmount}, diff_amount = #{diffAmount}, diff_status = #{diffStatus} where line_id = #{lineId} and bill_id = #{billId} delete from pay_bill_diff where line_id = #{lineId} and handle_type = 'OPEN' delete from pay_bill_line where bill_id = #{billId} and line_id = #{lineId} insert into pay_bill_diff ( bill_id, line_id, fee_id, our_amount, supplier_amount, diff_amount, reason, handle_type, adjust_fee_id, create_by, create_time ) values ( #{billId}, #{lineId}, #{feeId}, #{ourAmount}, #{supplierAmount}, #{diffAmount}, #{reason}, #{handleType}, #{adjustFeeId}, #{createBy}, sysdate() ) update pay_bill_diff set our_amount = #{ourAmount}, supplier_amount = #{supplierAmount}, diff_amount = #{diffAmount}, reason = #{reason}, handle_type = #{handleType}, adjust_fee_id = #{adjustFeeId} where diff_id = #{diffId} delete from pay_bill_diff where line_id = #{lineId} insert into pay_bill_file ( bill_id, file_type, invoice_no, invoice_date, amount, tax_amount, amount_net, seller_name, matched_amount, currency, file_name, file_url, deleted, create_by, create_time ) values ( #{billId}, #{fileType}, #{invoiceNo}, #{invoiceDate}, #{amount}, #{taxAmount}, #{amountNet}, #{sellerName}, ifnull(#{matchedAmount}, 0), #{currency}, #{fileName}, #{fileUrl}, '0', #{createBy}, sysdate() ) update pay_bill_file set deleted = '1' where file_id = #{fileId} insert into pay_bill_approval (bill_id, action, opinion, operator_name, create_time) values (#{billId}, #{action}, #{opinion}, #{operatorName}, sysdate()) insert into pay_bill_log ( bill_id, biz_type, biz_id, line_id, fee_id, operation_type, from_status, to_status, operation_desc, amount_before, amount_after, operator_name, create_time ) values ( #{billId}, #{bizType}, #{bizId}, #{lineId}, #{feeId}, #{operationType}, #{fromStatus}, #{toStatus}, #{operationDesc}, #{amountBefore}, #{amountAfter}, #{operatorName}, sysdate() )