<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: qwm  
    $Date: 2013-5-24 下午03:50:31  
    $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 c.contract_number,
               c.contract_name,
               hbm.bp_name,
               cpr.apply_pay_date,
               cpr.bp_bank_account_id,
               (select cph.payment_req_number
                  from csh_payment_req_hd cph
                 where cpr.payment_req_id = cph.payment_req_id) payment_req_number,
               cpr.ref_doc_line_id cashflow_id,
               (select times
                  from con_contract_cashflow ccc
                 where ccc.cashflow_id = cpr.ref_doc_line_id) times,
               (select ccc.due_amount
                  from con_contract_cashflow ccc
                 where ccc.cashflow_id = cpr.ref_doc_line_id) due_amount,
               (select description
                  from hls_cashflow_item hci, con_contract_cashflow ccc
                 where hci.cf_item = ccc.cf_item
                   and hci.cf_type = ccc.cf_type
                   and ccc.cashflow_id = cpr.ref_doc_line_id) CF_DESCRIPTION,
               /* (select c.transaction_num
                 from csh_transaction c
                where c.source_doc_line_id = cpr.payment_req_ln_id
                  and c.source_doc_id = cpr.payment_req_id) transaction_num,
               (select c.bank_slip_num
                 from csh_transaction c
                where c.source_doc_line_id = cpr.payment_req_ln_id
                  and c.source_doc_id = cpr.payment_req_id
                  and c.transaction_type = 'PAYMENT') bank_slip_num,*/


               (select bp_name
                  from hls_bp_master hbm
                 where hbm.bp_id = cpr.bp_id) BP_ID_AGENT_N,

               (select hbm.bank_account_num
                  from hls_bp_master_bank_account hbm
                 where hbm.bank_account_id = cpr.bp_bank_account_id) BP_BANK_ACCOUNT_NUM,

               (select hbm.bank_account_name
                  from hls_bp_master_bank_account hbm
                 where hbm.bank_account_id = cpr.bp_bank_account_id) BP_BANK_ACCOUNT_NAME,

               --应付我司金额
               cpr.amount_agent,
               cpr.amount_vender,
               --未付金额
               (cpr.amount_agent - nvl(cpr.amount_agent_paid, 0)) residual_agent_amount,
               (cpr.amount_vender - nvl(cpr.amount_vender_paid, 0)) residual_vender_amount,

               (select bp_name
                  from hls_bp_master hbm
                 where hbm.bp_id =
                       (select ccli.vender_id
                          from con_contract_lease_item ccli,
                               hls_lease_item          hli
                         where ccli.lease_item_id = hli.lease_item_id
                           and ccli.contract_id = c.contract_id)) vender_name,
               (select hbm.bank_account_name
                  from hls_bp_master_bank_account hbm
                 where hbm.bank_account_id = cpr.vender_bank_account_id) VENDER_BANK_ACCOUNT_ID,
               (select hbm.bank_account_num
                  from hls_bp_master_bank_account hbm
                 where hbm.bank_account_id = cpr.vender_bank_account_id) VENDER_BANK_ACCOUNT_number,
               cpr.amount,
               --首付款抵充金额
               (select nvl(hd.other_payment2, 0)
                  from hls_fin_calculator_hd hd
                 where hd.calc_session_id =
                       (select PQ.CALC_SESSION_ID
                          from prj_quotation pq
                         where pq.document_id =
                               (select cc.project_id
                                  from con_contract cc
                                 where cc.contract_id = c.contract_id)
                           and pq.document_category = 'PROJECT')) other_payment2,
               (SELECT gc.currency_name
                  FROM gld_currency_v gc
                 WHERE gc.currency_code = cpr.currency_code) currency_name,
               cpr.payment_req_ln_id,
               cpr.payment_req_id,
               cpr.payment_req_ln_type,
               cpr.ref_doc_id,
               cpr.ref_doc_line_id,
               cpr.ref_doc_category

          from csh_payment_req_ln cpr, con_contract c, hls_bp_master hbm
         where cpr.ref_doc_category = 'CONTRACT'
           and c.contract_id = cpr.ref_doc_id
           and hbm.bp_id = c.bp_id_tenant) v
            #WHERE_CLAUSE#
                ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
    <bm:data-filters>
        <bm:data-filter enforceOperations="query" expression="v.payment_req_id =${@payment_req_id}"/>
    </bm:data-filters>
  <!--  <bm:query-fields>
        <bm:query-field name="payment_req_id" queryOperator="="/>
    </bm:query-fields>-->

</bm:model>
