{include file='r/hidden.tpl' name="invoice_format" default=$invoice_format}
{include file='r/hidden.tpl' name="xRechnung_payment_type" default=$payment_type}

<fieldset class="borderbottom">
    {include file='r/select.tpl' name="xRechnung_invoice_version"
        title="fees_invoice_version" collapse='formcoll'
        list=$invoice_versions id="id" text="title" default=$invoice_version
        class="required t-mid on_change_update ocu-p:feeadmin ocu-m:update_xrechnung_fields ocu-f:{$invoice_format}"
        noempty=TRUE}
    {include file='r/select.tpl' name="xRechnung_document_type"
        title="fees_invoice_document_type" collapse='formcoll'
        list=$document_types id="id" text="title" default=$document_type
        class="required t-mid on_change_update ocu-p:feeadmin ocu-m:update_corrected_invoice_fields ocu-f:xRechnung"
        noempty=TRUE add_icons_file='warning' past_span_text='<small>(BT-3)</small>'}
</fieldset>
<fieldset id="corrected_invoice_fields" class="borderbottom" style="{if $document_type != "corrected_invoice"}display: none;{/if}">
    <h3>{$i.fees_fee_preceding_invoice} <small>(BG-3)</small></h3>
        {include file='r/input.tpl' name="preceding_fee_no"
            title="fees_fee_no"
            default=$fee_no text="name" class="t-mid {if $document_type == "corrected_invoice"}required{/if}"
            add_icons_file='warning' past_span_text='<small>(BT-25)</small>'}
        {include file='r/date.tpl' name="preceding_issue_date"
            title="fees_fee_date" collapse='formcoll' class="dateUS"
            add_icons_file='warning' past_span_text='<small>(BT-26)</small>'}
</fieldset>

<fieldset class="borderbottom">
    <h3>{$i.fees_fee_biller} <small>(BG-4)</small></h3>
    {include file='r/ajaxselect.tpl' name='seller_address'
        title="fees_fee_address" id="id" text="name" collapse='formcoll'
        default_id=$seller_address_id
        default=$seller_address class="required addressselect fulltext_search t-mid"
        add_icons_file='warning' past_span_text='<small>(BG-5)</small>'
        filter_extra_hidden="onchange='feeadmin.e_invoice.update_fields_according_to_address(this);'"}

    {include file='r/select.tpl' name="fee_account_id"
        title="fees_fee_account" collapse='formcoll'
        list=$fee_accounts id="id" text="name" default=$fee_account_id
        class="required t-mid" noempty=TRUE
        add_icons_file='warning' past_span_text='<small>(BG-16)</small>'}
        
    {include file='r/input-endpoint.tpl' name="seller_address_endpoint"
        title="fees_fee_address_endpoint_id"
        default=$seller_address_endpoint_id text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-34)</small>'
        no_newline=true pre_default=$seller_address_endpoint_type}
</fieldset>
<fieldset class="borderbottom">
    <h3>{$i.fees_fee_recipient} <small>(BG-7)</small></h3>
    {include file='r/ajaxselect.tpl' name='buyer_address'
        title="fees_fee_address" id="id" text="name"
        default_id=$buyer_address_id
        default=$buyer_address class="required addressselect fulltext_search t-mid"
        add_icons_file='warning' past_span_text='<small>(BG-8)</small>'
        filter_extra_hidden="onchange='feeadmin.e_invoice.update_fields_according_to_address(this);'"}
        
    {include file='r/input-endpoint.tpl' name="buyer_address_endpoint"
        title="fees_fee_address_endpoint_id"
        default=$buyer_address_endpoint_id text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-49)</small>'
        no_newline=true pre_default=$buyer_address_endpoint_type}
</fieldset>
<fieldset class="borderbottom">
    {include file='r/input.tpl' name="fee_no"
        title="fees_fee_no"
        default=$fee_no text="name" class="required t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-1)</small>'}
        
    {include file='r/datefromto.tpl' name="xRechnung_order_period"
        title="fees_fee_period" collapse='formcoll'
        default=$period_dates text="name" class="dateUS t-small"
        add_icons_file='warning' past_span_text='<small>(BG-26)</small>'}
        
    {include file='r/select.tpl' name="xRechnung_vat_category_code"
        class="required t-mid on_change_update ocu-p:feeadmin ocu-m:update_tax_exemption_fields ocu-f:xRechnung"
        title="fees_vat_category_code" collapse='formcoll'
        list=$vat_category_codes id="id" text="title" default=$vat_category_code
        filter_extra='title="(UNTDID 5305)"' noempty=TRUE
        add_icons_file='warning' past_span_text='<small>(BT-151)</small>'}
    
    {include file='r/textarea.tpl' name="xRechnung_tax_exemption" class="t-long" hide="{if $vat_category_code != "E"}display: none;{/if}"
        title="fees_fee_tax_exemption"
        default=$tax_exemption text='name'
        add_icons_file='warning' past_span_text='<small>(BT-120)</small>'}
</fieldset>
<fieldset class="borderbottom">
    <h3>{$i.fees_order}</h3>
    {include file='r/input.tpl' name="xRechnung_buyer_reference"
        title="fees_fee_buyer_reference"
        default=$buyer_reference text="name" class="required t-mid portlettooltip"
        add_icons_file='warning' past_span_text='<small>(BT-10)</small>'}
    <div id="xRechnung_buyer_reference_data" style="display: none">
        {$i.pages_fee_buyer_reference|markdown}
    </div>
    {if $show_item_name}
        {include file='r/input.tpl' name="xRechnung_item_name"  class="t-long"
            title="fees_fee_item_name"
            default=$item_name text='name'
            add_icons_file='warning' past_span_text='<small>(BT-153)</small>'}
    {/if}
    {include file='r/textarea.tpl' name="xRechnung_order_description"  class="t-long"
        title="fees_fee_description"
        default=$order_description text='name'
        add_icons_file='warning' past_span_text='<small>(BT-154)</small>'}
</fieldset>
<fieldset class="borderbottom">
    {include file='r/input.tpl' name="xRechnung_project_reference"
        title="fees_fee_project_reference" collapse='formcoll'
        default=$project_reference text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-11)</small>'}
    {include file='r/input.tpl' name="xRechnung_contract_reference"
        title="fees_fee_contract_reference" collapse='formcoll'
        default=$contract_reference text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-12)</small>'}
    {include file='r/input.tpl' name="xRechnung_order_reference"
        title="fees_fee_order_reference" collapse='formcoll'
        default=$order_reference text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-13)</small>'}
    {include file='r/input.tpl' name="xRechnung_order_number"
        title="fees_fee_order_number" collapse='formcoll'
        default=$order_number text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-14)</small>'}
    {include file='r/input.tpl' name="xRechnung_receipt_reference"
        title="fees_fee_receipt_reference" collapse='formcoll'
        default=$receipt_reference text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-15)</small>'}
    {include file='r/input.tpl' name="xRechnung_despatch_reference"
        title="fees_fee_despatch_reference" collapse='formcoll'
        default=$despatch_reference text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-16)</small>'}
    {include file='r/input.tpl' name="xRechnung_originator_reference"
        title="fees_fee_originator_reference" collapse='formcoll'
        default=$originator_reference text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-17)</small>'}
    {include file='r/input.tpl' name="xRechnung_invoice_note"
        title="fees_fee_invoice_note" collapse='formcoll'
        default=$invoice_note text="name" class="t-mid"
        add_icons_file='warning' past_span_text='<small>(BT-22)</small>'}
</fieldset>

<fieldset class="borderbottom">
    <h3>{$i.fees_fee_attachments} <small>(BT-125)</small></h3>
    {include file='r/file.tpl' name="e_invoice_attachment_upload_1" title="{$i.fees_fee_attachment} 1"
        allow_delete=TRUE targettype="files" targetdata="temp" labelclass="label2"
         collapse='formcoll'}
    {include file='r/file.tpl' name="e_invoice_attachment_upload_2" title="{$i.fees_fee_attachment} 2"
        allow_delete=TRUE targettype="files" targetdata="temp" labelclass="label2"
         collapse='formcoll'}
    {include file='r/file.tpl' name="e_invoice_attachment_upload_3" title="{$i.fees_fee_attachment} 3"
        allow_delete=TRUE targettype="files" targetdata="temp" labelclass="label2"
         collapse='formcoll'}
    {include file='r/file.tpl' name="e_invoice_attachment_upload_4" title="{$i.fees_fee_attachment} 4"
        allow_delete=TRUE targettype="files" targetdata="temp" labelclass="label2"
         collapse='formcoll'}

    {if !empty($order_reference) || !empty($order_date) || (isset($show_invoice_statement) && $show_invoice_statement)}
        <h4>{$order_reference} - {$order_date}</h4>
        {if !isset($invoice_statement)}{$invoice_statement=1}{/if}
        {include file='r/radio.tpl' name="e_invoice_invoice_statement" title='fees_invoice_statement'
            list=$invoice_statements_list id="id" text="title" default=$invoice_statement
            add_icons_file="openhref" openhref="https://www.bvbs.de/erechnung/" openhref_title="BVBS Implementierungsempfehlung"}
        {include file='r/hidden.tpl' name="e_invoice_show_invoice_statement" default=true}
    {/if}
</fieldset>

<fieldset class="borderbottom">
    {include file='r/select.tpl' name="save_type"
        title="fees_save_type" 
        list=$save_types id="id" text="name" default=$save_type
        collapse='formcoll' class="required on_change_update ocu-p:feeadmin ocu-m:update_e_invoice_save_types t-mid" noempty=TRUE}
    {if !$correspondence_has_right}
        {if $correspondence_has_bought}
            <span class="warningsmaller ui-corner-all">{$i.fees_save_type_corr_no_rights}</span>
        {else}
            <span class="warningsmaller ui-corner-all" style="opacity: 0.5; scale: 0.7;">{$i.fees_save_type_corr_no_bought}</span>
        {/if}
    {/if}
    <div id="e_invoice_correspondence_inputs">
        {include file='Feeadmin/e_invoice/e_invoice_correspondence.tpl'
            save_type=$save_type subject=$subject
            correspondence_type=$correspondence_type}
    </div>
</fieldset>
