<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: wujun  
    $Date: 2016-11-27 18:00:33  
    $Revision: 1.0  
    $Purpose: 还款审批表
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                SELECT
                    *
                FROM
                    (SELECT
                        wo.batch_id,
                        wo.times,
                        wo.loan_contract_id,
                        wo.quotation_id,
                        (SELECT
                            tlc.loan_contract_number
                        FROM
                            tre_loan_contract tlc
                        WHERE
                            tlc.loan_contract_id = wo.loan_contract_id
                        ) loan_contract_number, --借款合同号
                        (SELECT
                            tlc.original_con_num
                        FROM
                            tre_loan_contract tlc
                        WHERE
                            tlc.loan_contract_id = wo.loan_contract_id
                        ) original_con_num, --借款合同号
                        (SELECT
                            hbm.bp_name
                        FROM
                            tre_loan_contract tlc,
                            hls_bp_master hbm
                        WHERE
                            tlc.loan_contract_id = wo.loan_contract_id AND
                            hbm.bp_id            = tlc.loan_con_bp
                        ) loan_bp_name, --债权人
                        (SELECT
                            tlc.inside_or_outside
                        FROM
                            tre_loan_contract tlc
                        WHERE
                            tlc.loan_contract_id = wo.loan_contract_id
                        ) inside_or_outside, --境内境外
                        SUM(ROUND(wo.due_amount + NVL(wo.over_and_short, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => wo.loan_contract_id, p_loan_con_write_off_id => wo.loan_con_write_off_id, p_pay_amount => NVL(wo.due_amount, 0) + NVL(wo.over_and_short, 0), p_type => 1) + NVL(wo.withhold_income_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => wo.loan_contract_id, p_loan_con_write_off_id => wo.loan_con_write_off_id, p_pay_amount => NVL(wo.due_amount, 0) + NVL(wo.over_and_short, 0), p_type => 2) + NVL(wo.withhold_city_build_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => wo.loan_contract_id, p_loan_con_write_off_id => wo.loan_con_write_off_id, p_pay_amount => NVL(wo.due_amount, 0) + NVL(wo.over_and_short, 0), p_type => 3) + NVL(wo.withhold_edu_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => wo.loan_contract_id, p_loan_con_write_off_id => wo.loan_con_write_off_id, p_pay_amount => NVL(wo.due_amount, 0) + NVL(wo.over_and_short, 0), p_type => 4) + NVL(wo.withhold_edu_extra_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => wo.loan_contract_id, p_loan_con_write_off_id => wo.loan_con_write_off_id, p_pay_amount => NVL(wo.due_amount, 0) + NVL(wo.over_and_short, 0), p_type => 5) + NVL(wo.withhold_river_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => wo.loan_contract_id, p_loan_con_write_off_id => wo.loan_con_write_off_id, p_pay_amount => NVL(wo.due_amount, 0) + NVL(wo.over_and_short, 0), p_type => 6) + NVL(wo.withhold_value_added_tax_os, 0), 2)) payment_actual_amount,
                        (SELECT
                            SUM(ROUND(cwo.due_amount + NVL(cwo.over_and_short, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => cwo.loan_contract_id, p_loan_con_write_off_id => cwo.loan_con_write_off_id, p_pay_amount => NVL(cwo.due_amount, 0) + NVL(cwo.over_and_short, 0), p_type => 1) + NVL(cwo.withhold_income_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => cwo.loan_contract_id, p_loan_con_write_off_id => cwo.loan_con_write_off_id, p_pay_amount => NVL(cwo.due_amount, 0) + NVL(cwo.over_and_short, 0), p_type => 2) + NVL(cwo.withhold_city_build_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => cwo.loan_contract_id, p_loan_con_write_off_id => cwo.loan_con_write_off_id, p_pay_amount => NVL(cwo.due_amount, 0) + NVL(cwo.over_and_short, 0), p_type => 3) + NVL(cwo.withhold_edu_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => cwo.loan_contract_id, p_loan_con_write_off_id => cwo.loan_con_write_off_id, p_pay_amount => NVL(cwo.due_amount, 0) + NVL(cwo.over_and_short, 0), p_type => 4) + NVL(cwo.withhold_edu_extra_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => cwo.loan_contract_id, p_loan_con_write_off_id => cwo.loan_con_write_off_id, p_pay_amount => NVL(cwo.due_amount, 0) + NVL(cwo.over_and_short, 0), p_type => 5) + NVL(cwo.withhold_river_tax_os, 0) + sdic_report_pkg.get_repayment_tax(p_loan_contract_id => cwo.loan_contract_id, p_loan_con_write_off_id => cwo.loan_con_write_off_id, p_pay_amount => NVL(cwo.due_amount, 0) + NVL(cwo.over_and_short, 0), p_type => 6) + NVL(cwo.withhold_value_added_tax_os, 0), 2))
                        FROM
                            tre_loan_con_write_off cwo
                        WHERE
                            cwo.batch_id     = wo.batch_id AND
                            cwo.times        = wo.times AND
                            cwo.cf_item NOT IN (302, 303)
                        ) cost_amount
                    FROM
                        tre_loan_con_write_off wo
                    WHERE
                        wo.batch_id IN
                        (SELECT
                            t.batch_id
                        FROM
                            tre_loan_con_batch_interface t
                        WHERE
                            t.document_category      = 'REPAYMENT' AND
                            NVL(t.wfl_status, 'NEW') = 'APPROVED' AND
                            t.batch_id              <> 84
                        )
                    GROUP BY
                        wo.batch_id,
                        wo.times,
                        wo.loan_contract_id,
                        wo.quotation_id
                    ORDER BY
                        wo.loan_contract_id,
                        wo.quotation_id,
                        wo.batch_id
                    ) t1 #WHERE_CLAUSE#
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:query-fields>
        <bm:query-field name="loan_contract_number" queryExpression="t1.loan_contract_number like &apos;%&apos;||${@loan_contract_number}||&apos;%&apos;"/>
        <bm:query-field name="original_con_num" queryExpression="t1.original_con_num like &apos;%&apos;||${@original_con_num}||&apos;%&apos;"/>
        <bm:query-field name="loan_bp_name" queryExpression="t1.loan_bp_name like &apos;%&apos;||${@loan_bp_name}||&apos;%&apos;"/>
        <bm:query-field name="inside_or_outside_n" queryExpression="t1.inside_or_outside like &apos;%&apos;||${@inside_or_outside}||&apos;%&apos;"/>
    </bm:query-fields>
</bm:model>
