<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: chenlingfeng
    $Date: 2018-09-28 15:37:55
    $Revision: 1.0  
    $Purpose: 
-->
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" accessControlMode="false"  needAccessControl="false">
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                select cwo.write_off_type,
                       (select v.code_value_name
                          from sys_code_values_v v
                         where v.code = 'CSH513_WRITE_OFF_TYPE'
                           and v.code_value = cwo.write_off_type) write_off_type_desc,
                       cwo.write_off_classification,
                       (select v.code_value_name
                          from sys_code_values_v v
                         where v.code = 'DS_CSH_WRITE_OFF_CLASSIFICATION'
                           and v.code_value = cwo.write_off_classification) write_off_classification_desc,
                       cwo.write_off_date,
                       to_char(cwo.journal_date, 'yyyy-mm-dd') as journal_date,
                       cwo.write_off_due_amount,
                       ct.transaction_num,
                       ct.transaction_date,
                       ct.bp_bank_account_name,
                       ct.bp_bank_account_num,
                       ct.transaction_amount,
                       cwo.contract_id,
                       cwo.cashflow_id,
                       cwo.times,
                       cwo.cf_item,
                       cwo.cf_type,
                       ct.transaction_id,
                       (select v.code_value_name
                          from sys_code_values_v v
                         where v.code = 'CSH511_TRANSACTION_TYPE'
                           and v.code_value = ct.transaction_type) transaction_type,
                       (select u.description
                          from sys_user u
                         where u.user_id = cwo.created_by) created_by_n,
                       (select ahd.document_number from acr_invoice_hd ahd where ahd.invoice_hd_id=${@invoice_hd_id})document_number,
                    (Select hb.bp_name
                From hls_bp_master hb,acr_invoice_hd ahd
                Where hb.bp_id = ahd.bp_id and ahd.invoice_hd_id=${@invoice_hd_id})                         bp_name,
                    (Select c.contract_number
                From con_contract c,acr_invoice_hd ahd
                Where c.contract_id = ahd.contract_id and ahd.invoice_hd_id=${@invoice_hd_id})              contract_number

                  from csh_write_off cwo, csh_transaction ct
                 where cwo.csh_transaction_id = ct.transaction_id
                 and cwo.reversed_flag = 'N'
                 and cwo.cashflow_id = ${@cashflow_id}
            ]]></bm:query-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
