<?xml version="1.0" encoding="UTF-8"?>
<!--
    $Author: Harry
	$Date: 2018/10/17 14:26
	$Revision: 1.0
-->
<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 t.*,
                       CASE
                         WHEN t.omonth = t.nmonth THEN
                          TO_CHAR(t.journal_date, 'YYYYMMDD')
                         ELSE
                          TO_CHAR(t.journal_date, 'YYYYMMDD')
                       END AS BUDAT
                  FROM (SELECT (SELECT l.sap_belnr
                                  FROM hls_journal_header l
                                 WHERE l.journal_header_id = h.reversed_journal_header_id) BELNR,
                               h.period_year GJAHR,
                               (SELECT TO_CHAR(l.journal_date, 'YYYYMMDD')
                                  FROM hls_journal_header l
                                 WHERE l.journal_header_id = h.reversed_journal_header_id) ZBUDAT,
                               '' STGRD,
                               (SELECT TO_CHAR(l.journal_date, 'YYYYMM')
                                  FROM hls_journal_header l
                                 WHERE l.journal_header_id = h.reversed_journal_header_id) omonth,
                               TO_CHAR(h.journal_date, 'YYYYMM') nmonth,
                               h.period_num MONAT,
                               h.journal_date,
                               h.reversed_journal_header_id
                          FROM hls_journal_header h
                         WHERE h.journal_header_id = ${@journal_header_id}) t
                ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
                BEGIN

                    UPDATE
                        hls_journal_header t
                    SET
                        t.sap_belnr = ${@stblg},
                        t.sap_gjahr = ${@gjahr},
                        t.sap_bukrs = ${@bukrs},
                        t.re_type   = ${@re_type},
                        t.re_meg    = ${@re_meg},
                        t.post_gl_status=DECODE(${@re_type},'E','N','Y')
                    WHERE
                        t.journal_header_id = ${@journal_header_id};
                END;
                ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>