<table class="col2btn">
    <tr><!-- Required -->
        <td>{$i.externalexpenses_project}</td>
        <td>{$externalexpense->project}</td>
    </tr>
    <tr><!-- Required -->
        <td>{$i.externalexpenses_date}</td>
        <td>{$externalexpense->date->us_date()}</td>
    </tr>
    {if $externalexpense->purpose neq ''}
        <tr>
            <td>{$i.externalexpenses_purpose}</td>
            <td>{$externalexpense->purpose|truncate:120:"..."}</td>
        </tr>
    {/if}
    <tr><!-- Required -->
        <td>{$i.externalexpenses_value}</td>
        <td>{isfloat value=$externalexpense->value}</td>
    </tr>
    {if $externalexpense->turnover_rate neq 0}
        <tr>
            <td>{$i.externalexpenses_value_pre_tax}</td>
            <td>{isfloat value=$externalexpense->value_pre_tax}</td>
        </tr>
    {/if}
    <tr>
        <td>{$i.externalexpenses_turnover_rate}</td>
        <td>{isturnover_rate value=$externalexpense->turnover_rate add_percent_sign=true}</td>
    </tr>
    
    {if $project_use_currency && $externalexpense->value_otcurr!=null}
        <tr>
            <td style="background:rgba(210, 220, 255, 0.3);">{$externalexpense->currency_name} {$i.externalexpenses_value}</td>
            <td title="value_otcurr">{isfloat value=$externalexpense->value_otcurr} {$externalexpense->currency_abbreviation}</td>
        </tr>
        <tr>
            <td style="background:rgba(210, 220, 255, 0.3);">{$externalexpense->currency_name} {$i.externalexpenses_value_pre_tax}</td>
            <td title="value_otcurr_pre_tax">{isfloat value=$externalexpense->value_otcurr_pre_tax} {$externalexpense->currency_abbreviation}</td>
        </tr> 
        <tr>
            <td style="background:rgba(210, 220, 255, 0.3);">{$i.externalexpenses_exchange_rate}</td>
            <td title="value/value_otcurr">{isfloat value=$externalexpense->value/$externalexpense->value_otcurr maxf=4}</td>
        </tr> 
    {/if}

    {if $externalexpense->is_invoiced == false}{* Only planned *}
        <tr>
            <td>{$i.externalexpenses_is_transfered}</td>
            <td>{boolview value=$externalexpense->is_transfered}</td>
        </tr>
    {/if}
    {if $externalexpense->description neq ''}
        <tr>
            <td>{$i.externalexpenses_description}</td>
            <td>{$externalexpense->description|truncate:120:"..."}</td>
        </tr>
    {/if}
    <tr><!-- Required -->
        <td>{$i.externalexpenses_work_package_name}</td>
        <td>{$externalexpense->work_package_name}</td>
    </tr>
    {if $externalexpense->cost_centre_name neq ''}
        <tr>
            <td>{$i.externalexpenses_cost_centre_name}</td>
            <td>{$externalexpense->cost_centre_name}</td>
        </tr>
    {/if}
    {if $externalexpense->fee_category_name neq ''}
        <tr>
            <td>{$i.externalexpenses_fee_category_name}</td>
            <td>{$externalexpense->fee_category_name}</td>
        </tr>
    {/if}
    <tr>
        <td colspan="2"></td>
    </tr>
    {if $externalexpense->has_document or $externalexpense->has_invoice_json}
        <tr>
            <td>{$i.externalexpenses_file}</td>
            <td>
                {if empty($externalexpense->correspondence)}
                    {boolview value=true}
                {else}
                    <a href="{site_url url="start/open/correspondence/index/$xjxcookie/view/{$externalexpense->correspondence->id}/"}"
                       onclick="usComm.windowOpen(this.href); return false;"
                       class="dialog_make_btn16 correspondence smallbtns ui-corner-all frstbtn" title="{$i.basic_correspondence}"></a>

                    {additional_button type="correspondence_edit_document" value=$externalexpense->correspondence}
                    {$externalexpense->correspondence->subject|truncate:50:"..."}
                {/if}
                {if $externalexpense->has_invoice_json}
                    <br>
                    <a class="dialog_make_text_btn ui-corner-all" style="margin-left: 10px; text-align: center;"
                       onclick="fullPopup.view('externalexpenses', 'show_einvoice_preview',  {$externalexpense->db_id});">
                        E-Rechnung Vorschau
                    </a>
                {/if}
            </td>
        </tr>
    {/if}
    {if $externalexpense->is_invoiced != false}{* Not planned *}
        {if $externalexpense->charged neq 0}
            <tr>
                <td>{$i.externalexpenses_charged}</td>
                <td>{isfloat value=$externalexpense->charged}</td>
            </tr>
        {/if}
        {if !empty($externalexpense->charge_date) && !$externalexpense->charge_date->is_null()}
            <tr>
                <td>{$i.externalexpenses_charge_date}</td>
                <td>{$externalexpense->charge_date->us_date()}</td>
            </tr>
        {/if}
        {if !empty($externalexpense->invoice_due_date) && !$externalexpense->invoice_due_date->is_null()}
            <tr>
                <td>{$i.externalexpenses_invoice_due_date}</td>
                <td>{$externalexpense->invoice_due_date->us_date()}</td>
            </tr>
        {/if}
        {if !empty($externalexpense->invoice_number)}
            <tr>
                <td>{$i.externalexpenses_invoice_number}</td>
                <td>{$externalexpense->invoice_number}</td>
            </tr>
        {/if}
    {else}{* Only planned *}
        {if !empty($externalexpense->valid_from) && !$externalexpense->valid_from->is_null()}
            <tr>
                <td>{$i.externalexpenses_valid_from}</td>
                <td>{$externalexpense->valid_from->us_date()}</td>
            </tr>
        {/if}
    {/if}
    <tr>
        <td colspan="2"></td>
    </tr>
    {foreach from=$externalexpense->addi_fields item=field}
        <tr>
            {if $field->type eq US_exmodel::T_BLOCK}
                <th colspan="2" style="text-align:center; {if isset($field->color)}background:{$field->color}{/if}">{$field->name}</th>
            {else}
                <td style="{if isset($field->color)}background:{$field->color}{/if}">{$field->name}</td>
                <td>
                    {assign var='field_id' value=$field->field}
                    {addiview field=$field value=$externalexpense->$field_id item=$externalexpense}
                </td>
            {/if}
        </tr>
    {/foreach}
    
    <tr>
        <td>{$i.basic_created_by}</td>
        <td>{$externalexpense->created_by_name}</td>
    </tr>     
    <tr>
        <td>{$i.basic_created_date}</td>
        <td>{$externalexpense->created_date->us_date()}</td>
    </tr>    
    <tr>
        <td>{$i.basic_changed_by}</td>
        <td>{$externalexpense->changed_by_name}</td>
    </tr>      
    <tr>
        <td>{$i.basic_change_date}</td>
        <td>{$externalexpense->change_date->us_date()}</td>
    </tr>
</table>
