<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:f="leaf.database.features" xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1"
          baseTable="con_contract_et_temp">
    <bm:fields>
        <bm:field name="record_id"/>
        <bm:field name="batch_id"/>
        <bm:field name="contract_number"/>
        <bm:field name="invoice_number"/>
        <bm:field name="transfer_time"/>
        <bm:field name="recipient"/>
        <bm:field name="express_date"/>
        <bm:field name="express_num"/>
        <bm:field name="express_to"/>
        <bm:field name="err_message"/>
        <bm:field name="status"/>
        <bm:field name="status_n"/>
        <bm:field name="invoice_code"/>
    </bm:fields>
    <bm:features>
        <f:standard-who/>
    </bm:features>
    <bm:primary-key>
        <bm:pk-field name="record_id"/>
    </bm:primary-key>
    <bm:query-fields>
        <bm:query-field name="batch_id" queryExpression="t1.batch_id=${@batch_id}"/>
    </bm:query-fields>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
                Select record_id,
                batch_id,
                contract_number,
                invoice_number,
                invoice_code,
                to_char(transfer_time, 'yyyy-mm-dd') transfer_time,
                recipient,
                to_char(express_date, 'yyyy-mm-dd') express_date,
                express_num,
                express_to,
                err_message,
                created_by,
                creation_date,
                last_updated_by,
                last_update_date,
                status,
                (Select scv.code_value_name
                From sys_code_values_v scv
                Where scv.code = 'ACR520_EXPESS_STATUS'
                And scv.code_value = nvl(status, 'NEW')) status_n
                From acr_delivery_import_temp
                Where batch_id = ${@batch_id}
                Order By decode(err_message, Null, 2, 1)
         ]]></bm:query-sql>
        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            begin
                acr_delivery_import_pkg.save_data
                    (
                        p_batch_id=>${@batch_id},
                        p_user_id=>${/session/@user_id},
                        p_group_code=>${@group_code},
                        p_company_id =>${/session/@company_id}
                    );
             end;
         ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
