<?xml version="1.0" encoding="UTF-8"?>
<bm:model xmlns:bm="http://www.leaf-framework.org/schema/bm" alias="t1" baseTable="ACR_INVOICE_HD_LV">
    <bm:fields>
        <bm:field name="invoice_hd_id"/>
        <bm:field name="bp_name"/>
        <bm:field name="bp_tax_registry_num"/>
        <bm:field name="bp_address_phone_num"/>
        <bm:field name="bp_bank_account"/>
        <bm:field name="created_by_name"/>
        <bm:field name="confirmed_by_name"/>
        <bm:field name="description"/>
        <bm:field name="invoice_kind"/>
        <bm:field name="bp_class"/>
        <bm:field name="selleraddrtel"/>
        <bm:field name="sellerbankacct"/>
        <bm:field name="skr"/>
        <bm:field name="exists_flag"/>
        <bm:field name="vat_interface_status"/>
        <bm:field name="cf_item"/>
        <bm:field name="contract_number"/>

    </bm:fields>
    <bm:features>
        <f:standard-who xmlns:f="leaf.database.features"/>
    </bm:features>
    <bm:operations>
        <bm:operation name="query">
            <bm:query-sql><![CDATA[
            Select th.invoice_hd_id,
                   th.bp_name,
                   trim(th.bp_tax_registry_num) as bp_tax_registry_num,
                   th.bp_address_phone_num,
                   th.bp_bank_account,
                   th.invoice_kind,
                   (Select u.user_name || '-' || u.description
                      From sys_user u
                     Where u.user_id = th.created_by) As created_by_name,
                   (Select u.user_name || '-' || u.description
                      From sys_user u
                     Where u.user_id = th.confirmed_by) As confirmed_by_name,
                   th.description,
                   th.bp_class,
                   '北京市朝阳区东三环北路霞光里18号佳程广场B座20层CD单元010-84547167' As selleraddrtel,
                   '友利银行（中国）有限公司北京分行1171908069449' As sellerbankacct,
                   sys_parameter_pkg.value('ACR_INVOICE_SKR') As skr,
                   nvl(th.invoice_number, 'N') exists_flag,
                   th.vat_interface_status,
                   th.cf_item as cf_item,
                   th.contract_number
              From acr_invoice_hd_lv th
              Where th.invoice_hd_id = ${@invoice_hd_id}

            ]]></bm:query-sql>


        </bm:operation>
        <bm:operation name="update">
            <bm:update-sql><![CDATA[
            begin
                update  acr_invoice_hd hd
                  set hd.invoice_number = lpad(${@invoice_number},8,'0'),
                      hd.vat_invoice_code = ${@vat_invoice_code},
                      hd.invoice_date = to_date(${@invoice_date},'yyyy-mm-dd HH24:mi:ss') ,
                      hd.vat_invoice_status = ${@vat_invoice_status},
                      hd.vat_interface_status = ${@vat_interface_status},
                      hd.tax_code = ${@tax_code},
                      hd.tax_msg = ${@tax_msg}
                   where hd.invoice_hd_id = ${@invoice_hd_id};
             end;
            ]]></bm:update-sql>
        </bm:operation>
    </bm:operations>
</bm:model>
