<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: trd
    $Date: 2024-3-27 下午03:50:31
    $Revision: 1.0
    $Purpose:佣金付款
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:f="leaf.database.features" alias="t1"
          baseTable="CSH_PAYMENT_REQ_LN" needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
              select t.contract_id ref_doc_id,
                     f.cashflow_id ref_doc_line_id,
                     t.document_category ref_doc_category,
                     hc.bp_id,
                     t.bp_id_agent_level1,
                     t.contract_id,
                     f.cashflow_id,
                     t.contract_number,
                     t.contract_name,
                     hc.bp_id bp_id_agent_level1,
                     (select hbm.bp_name from hls_bp_master hbm where hbm.bp_id = hc.bp_id) bp_id_agent_level1_n,
                     hc.finance_amount,
                     t.lease_start_date,
                     hc.overdue_max_days,
                     hc.comsn_amount amount_agent,
                     hc.comsn_amount amount,
                     t.currency currency_code,
                     (SELECT gc.currency_name
                        FROM gld_currency_v gc
                       WHERE gc.currency_code = t.currency) currency_name,
                     (select to_char(sysdate, 'yyyy-mm') || '-20' from dual) apply_pay_date
                FROM con_contract_cashflow f
                join con_contract t
                  on t.contract_id = f.contract_id
                join hlcm_comsn_reconcilia hc
                  on f.cashflow_id = hc.cashflow_id
               where EXISTS (SELECT 1
                        FROM CSH_PAYMENT_CASHFLOW_ID_TEMP tmp
                       WHERE tmp.session_id = ${/session/@session_id}
                         AND tmp.cashflow_id = f.cashflow_id)
                             #WHERE_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
