[{include file="headitem.tpl" title="GENERAL_ADMIN_TITLE"|oxmultilangassign}]

[{if $readonly}]
    [{assign var="readonly" value="readonly disabled"}]
[{else}]
    [{assign var="readonly" value=""}]
[{/if}]

[{assign var="oCurr" value=$edit->getOrderCurrency()}]

<form name="transfer" id="transfer" action="[{$oViewConf->getSelfLink()}]" method="post">
    [{$oViewConf->getHiddenSid()}]
    <input type="hidden" name="cur" value="[{$oCurr->id}]">
    <input type="hidden" name="oxid" value="[{$oxid}]">
    <input type="hidden" name="cl" value="[{$oView->getClassName()}]">
</form>

[{if $oHeidelpayViewConfig->isModuleDemoVersion()}]
    <div class="extension_warning">[{oxmultilang ident="d3_d3heidelpay_is_demo"}]</div>
[{/if}]

<table cellspacing="0" cellpadding="0" border="0" width="100%">
    <tr>
        <td valign="top" class="edittext" width="100%">
            [{block name="admin_order_heidelpay_form"}]

                [{* showing all transactions for this order  *}]
                [{assign var='transactions' value=$oView->getTransactions()}]
                [{assign var='transactions' value=$transactions->reverse()}]

                [{if !empty($transactions)}]
                    <table border="0" class="d3hptransactions box">
                        <tr>
                            <th colspan="3">Ergebnis</th>
                            <th>Datum</th>
                            <th>Credit/Debit</th>
                            <th>Methode</th>
                            <th>Zahlungstyp</th>
                            <th>Txn-ID</th>
                            <th>Unique ID</th>
                            <th>Short ID</th>
                        </tr>
                        [{foreach from=$transactions item='transaction' key='index' name='transactions'}]
                            [{assign var='transactionLogReader' value=$transaction->getTransactiondata()}]
                            [{assign var='sClassName' value=' class="listitem"'}]
                            [{assign var='blTransactionSuccessfull' value=false}]
                            [{assign var='sAmount' value=$transactionLogReader->getAmount()}]
                            [{assign var="sPaymentType" value=$transactionLogReader->getPaymentcode()|substr:0:2}]
                            [{assign var="sPaymentMethod" value=$transactionLogReader->getPaymentcode()|substr:3}]
                            [{assign var='sUniqueId' value=$transactionLogReader->getUniqueid()}]
                            [{if false == empty($sUniqueId)}]
                                [{if $smarty.foreach.transactions.index is odd}]
                                    [{assign var='sClassName' value=' class="listitem2"'}]
                                [{/if}]
                                [{if $transactionLogReader->getResult() == 'ACK'}]
                                    [{assign var='blTransactionSuccessfull' value=true}]
                                [{/if}]

                                [{if !$blTransactionSuccessfull}]
                                    [{assign var='sAmount' value="<del>$sAmount</del>"}]
                                [{/if}]

                                [{if $sPaymentMethod == 'PA'}]
                                    [{assign var='sAmount' value="($sAmount)"}]
                                [{/if}]
                                <tr>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]"
                                           class="d3hpopen d3hpdisplay d3modcfg_icon action_plus_inactive"></a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]"
                                           class="d3hpopen d3modcfg_icon [{if $blTransactionSuccessfull}]status_ok[{else}]status_failed[{/if}]"
                                           title="[{$transactionLogReader->getResult()}]"></a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]" class="d3hpopen">[{$transactionLogReader->getReason()}]</a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]"
                                           class="d3hpopen">[{$transactionLogReader->getTimestamp()}]</a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]" class="d3hpopen">
                                            [{$sAmount}] [{$transactionLogReader->getCurrency()}]
                                        </a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]" class="d3hpopen">
                                            [{oxmultilang ident='d3_d3heidelpay_method_'|cat:$sPaymentMethod}]
                                            ([{$sPaymentMethod}])
                                        </a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]" class="d3hpopen">
                                            [{oxmultilang ident='d3_d3heidelpay_payment_'|cat:$sPaymentType}]
                                            ([{$sPaymentType}])
                                        </a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]"
                                           class="d3hpopen">[{$transactionLogReader->getTransactionid()}]</a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]"
                                           class="d3hpopen">[{$sUniqueId}]</a>
                                    </td>
                                    <td[{$sClassName}]>
                                        <a rel="[{$index}]" class="d3hpopen">[{$transactionLogReader->getShortid()}]</a>
                                    </td>
                                </tr>
                                <tr class="d3hphidden" id="[{$index}]">
                                    <td colspan="9" [{$sClassName}]>
                                        <form action="[{$oViewConf->getSelfLink()}]" method="post">
                                            <div>
                                                [{$oViewConf->getHiddenSid()}]
                                                <input type="hidden" name="cur" value="[{$oCurr->id}]">
                                                <input type="hidden" name="cl" value="[{$oView->getClassName()}]">
                                                <input type="hidden" name="fnc" value="runPaymentAction">
                                                <input type="hidden" name="oxid" value="[{$oxid}]">
                                                <input type="hidden" name="editval[oxorder__oxid]" value="[{$oxid}]">
                                                <input type="hidden" name="d3TransactionId" value="[{$index}]">
                                                <input type="hidden"
                                                       name="d3TransactionUniqueId"
                                                       value="[{$sUniqueId}]">
                                                <input type="hidden"
                                                       id="paymentAction[{$index}]"
                                                       name="paymentAction"
                                                       value="[{$sUniqueId}]">

                                            </div>
                                            <ul class="hpactions">
                                                [{foreach from=$oView->getActions($transactionLogReader) item='button'}]
                                                    <li>
                                                        <button name="[{$button.name}]" value="[{$button.value}]"
                                                                [{if $button.disabled || $transactionLogReader->getResult() != 'ACK'}]disabled="disabled"[{/if}]
                                                                rel="[{$index}]"
                                                                class="d3hptransaction">[{$button.title}]</button>
                                                    </li>
                                                [{/foreach}]
                                            </ul>
                                            <div class="hpfieldset" id="fieldset[{$index}]">
                                                <label class="d3hplabel">
                                                    Betrag
                                                    <input type="text"
                                                           name="data[betrag]"
                                                           value="[{$transactionLogReader->getAmount()}]">
                                                    &nbsp;[{$edit->oxorder__oxcurrency->value}]
                                                </label>
                                                <label class="d3modcfg_btn icon status_ok">
                                                    <input type="submit"
                                                           id="submit[{$index}]"
                                                           value="[{oxmultilang ident="d3_d3heidelpay_controllers_admin_order_heidelpay_submit"}]">
                                                    <span></span>
                                                </label>
                                            </div>
                                        </form>
                                    </td>
                                    <td[{$sClassName}] valign="top">
                                        <a rel="[{$index}]" class="d3modcfg_icon d3hpclose action_minus_inactive"
                                           title="[{oxmultilang ident="CATEGORY_UPDATE_CLOSE"}]"></a>
                                    </td>
                                </tr>
                            [{/if}]
                        [{/foreach}]
                    </table>
                    [{if $oView->checkDisplayBasicFunctions()}]
                        <div class="extension_warning">[{oxmultilang ident="D3_HEIDELPAY_RESTRICTIONINFO_ORDER"}]</div>
                    [{/if}]

                [{else}]
                    [{oxmultilang ident="d3_d3heidelpay_controllers_admin_order_heidelpay_is_not_heidelpay"}]
                [{/if}]
            [{/block}]
        </td>
    </tr>
</table>

[{oxscript add='
$(".d3hpopen").click(function(){
    var id = $(this).attr("rel");
    $("#" + id).toggle();
    $(".d3hpdisplay[rel=\'" + id + "\']").toggleClass("action_plus_inactive action_minus_inactive");
});

$(".d3hpclose").click(function(){
    var id = $(this).attr("rel");
    $("#" + id).toggle();
    $(".d3hpdisplay[rel=\'" + id + "\']").toggleClass("action_plus_inactive action_minus_inactive");
});
var originalValue = "";
$("button.d3hptransaction").click(function(){
    var hiddenId = "#paymentAction" + $(this).attr("rel");
    var submitId = "#submit" + $(this).attr("rel");
    var fieldsetId = "#fieldset" + $(this).attr("rel");
    $(hiddenId).attr("name", $(this).attr("name"));
    $(hiddenId).attr("value", $(this).attr("value"));

    if(originalValue == "") {
        originalValue = $(submitId).attr("value");
    }

    $(submitId).attr("value", $(this).text() + " " + originalValue);
    $(fieldsetId).show();
    return false;
});

'}]

[{include file="bottomnaviitem.tpl"}]

[{include file="bottomitem.tpl"}]
