<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" xmlns:ns1="leaf.database.features" baseTable="gld_period_rules">
    <bm:fields>
        <bm:field name="period_set_code" databaseType="VARCHAR2" datatype="java.lang.String"/>
        <bm:field name="period_num" databaseType="NUMBER" datatype="java.lang.Long"/>
        <bm:field name="period_additional_name" databaseType="VARCHAR2" datatype="java.lang.String" prompt="GLD_PERIOD_RULES.PERIOD_ADDITIONAL_NAME"/>
        <bm:field name="month_from" databaseType="NUMBER" datatype="java.lang.Long" prompt="GLD_PERIOD_RULES.MONTH_FROM"/>
        <bm:field name="month_to" databaseType="NUMBER" datatype="java.lang.Long" prompt="GLD_PERIOD_RULES.MONTH_TO"/>
        <bm:field name="date_from" databaseType="NUMBER" datatype="java.lang.Long" prompt="GLD_PERIOD_RULES.DATE_FROM"/>
        <bm:field name="date_to" databaseType="NUMBER" datatype="java.lang.Long" prompt="GLD_PERIOD_RULES.DATE_TO"/>
        <bm:field name="quarter_num" databaseType="NUMBER" datatype="java.lang.Long" prompt="GLD_PERIOD_RULES.QUARTER_NUM"/>
        <bm:field name="adjustment_flag" databaseType="VARCHAR2" datatype="java.lang.String" prompt="GLD_PERIOD_RULES.ADJUSTMENT_FLAG"/>
    </bm:fields>
    <bm:operations>
        <bm:operation name="insert">
            <bm:update-sql><![CDATA[
		declare 
			V_ADJUSTMENT_FLAG VARCHAR2(1);
	    begin
			SELECT DECODE(${@adjustment_flag}, '0', 'N', ${@adjustment_flag}) INTO V_ADJUSTMENT_FLAG FROM DUAL;
			 GLD_PERIOD_PKG.insert_gld_period_rule 
			 (
				${@period_set_code},
				${@period_num},
				${@period_additional_name},
				${@month_from},
				${@month_to},
				${@date_from},
				${@date_to},
				${@quarter_num},
				V_ADJUSTMENT_FLAG,
				${/session/@user_id},         
				${/session/@user_id}
			 );
		 end;
		]]></bm:update-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
				declare 
					V_ADJUSTMENT_FLAG VARCHAR2(1);
				begin
					SELECT DECODE(${@adjustment_flag}, '0', 'N', ${@adjustment_flag}) INTO V_ADJUSTMENT_FLAG FROM DUAL;
					 GLD_PERIOD_PKG.update_gld_period_rule 
					 (
						${@period_set_code},
						${@period_num},
						${@period_additional_name},
						${@month_from},
						${@month_to},
						${@date_from},
						${@date_to},
						${@quarter_num},
						V_ADJUSTMENT_FLAG,
						${/session/@user_id},         
						${/session/@user_id}
					 );
				 end;
			]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
    <bm:primary-key>
        <bm:pk-field name="period_num"/>
        <bm:pk-field name="period_set_code"/>
    </bm:primary-key>
    <bm:features>
        <ns1:standard-who/>
    </bm:features>
    <bm:query-fields>
        <bm:query-field field="period_set_code" queryExpression="period_set_code=${/parameter/@period_set_code}"/>
    </bm:query-fields>
    <bm:ref-fields/>
</bm:model>