<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: gaoyang 
    $Date: 2014-11-11 下午05:36:49  
    $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
                    h.company_id,
                    -- fc.company_code,
                     (select t.kingdee_compnay_code from fnd_companies t where t.company_id=h.company_id) company_code,
                    TO_CHAR(h.journal_date,'yyyy-mm-dd') journal_date,
                    TO_CHAR(h.journal_date,'yyyy-mm-dd') BizDate,
                    h.period_year,
                    h.period_num,
                    '记账' vouchertype,
                    h.journal_num,
                    h.attachment_num,
                    l.line_num,
                    h.description,
                    l.account_id,
                    --gav.account_code,
                    l.account_id_n as account_code,
                    --h.currency_code,
                    'BB01' currency_code,
                    h.exchange_rate,
                    (
                        CASE
                            WHEN l.amount_cr IS NOT NULL AND
                                l.amount_dr  IS NULL
                            THEN -1
                            WHEN l.amount_cr IS NULL AND
                                l.amount_dr  IS NOT NULL
                            THEN 1
                        END) entrydc,
                    NVL(l.amount_dr, l.amount_cr) originalamount,
                    (SELECT
                        COUNT(*)
                    FROM
                        hls_journal_detail dl
                    WHERE
                        dl.journal_header_id = l.journal_header_id
                    ) qty,
                    l.line_description,
                    l.amount_dr,
                    l.amount_cr,
                    --su.description user_desc,
                    su.description user_desc,
               
                    l.reference1,
                    l.reference1_n,
                    l.reference2,
                    l.reference2_n,
                    l.reference3,
                    l.reference3_n,
                    l.reference4,
                    l.reference5,
                    l.reference5_n,
                     r.ref_code1,
                               r.ref_code2,
                               r.ref_code3               
                FROM
                    hls_journal_header h,
                    hls_journal_detail_lv l,
                    sys_user su,
                    gld_company_accounts_ref r
                WHERE
                    h.journal_header_id = l.journal_header_id AND
                    r.account_id = l.account_id and
                    su.user_id = nvl(${/session/@user_id},361)  and
                    h.journal_header_id = ${@journal_header_id}
            ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                DECLARE
                    v_flag           VARCHAR2(1);
                    jounal_num_error EXCEPTION;
                BEGIN
                    v_flag   := hls_journal_pkg.update_external_journal_num( p_journal_header_id =>${@journal_header_id}, p_external_journal_num =>${@kingdee_journal_header_num}, p_interface_deal_message =>${@interface_deal_message}, p_itfc_exception =>${@itfc_exception}, p_interface_date =>sysdate, p_user_id =>NVL(${/session/@user_id},${@user_id}));
                    IF v_flag = 'N' THEN
                      null;
                   --   raise jounal_num_error;
                    END IF;
                EXCEPTION
                WHEN jounal_num_error THEN
                    sys_raise_app_error_pkg.raise_user_define_error(p_message_code => 'HLS_JOURNAL_PKG.KINGDEE_POST_FAILURE', p_created_by => 1, p_package_name => 'HLS_JOURNAL_PKG', p_procedure_function_name => 'update_external_journal_num');
                    raise_application_error(sys_raise_app_error_pkg.c_error_number, sys_raise_app_error_pkg.g_err_line_id);
                END;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
