{% extends request.ajax ? "layout_blank.phtml" : "layout_default.phtml" %}
{% import "macro_functions.phtml" as mf %}
{% set active_menu = 'invoice' %}
{% block meta_title %}Transaction {{ transaction.txn_id }}{% endblock %}

{% block breadcrumbs %}
<ul>
    <li class="firstB"><a href="{{ '/'|alink }}">{{ 'Home'|trans }}</a></li>
    <li><a href="{{ 'invoice/transactions'|alink }}">{{ 'Transactions'|trans }}</a></li>
    <li class="lastB">#{{transaction.id}}</li>
</ul>
{% endblock %}

{% block content %}

<div class="widget simpleTabs">

    <ul class="tabs">
        <li><a href="#tab-index">{{ 'Transaction'|trans }}</a></li>
        <li><a href="#tab-manage">{{ 'Manage'|trans }}</a></li>
        <li><a href="#tab-ipn">{{ 'IPN'|trans }}</a></li>
        <li><a href="#tab-note">{{ 'Notes'|trans }}</a></li>
    </ul>

    <div class="tab_container">

        <div class="tab_content nopadding" id="tab-index">
            <div class="help">
                <h3>{{ 'Transaction details'|trans }} #{{transaction.id}}</h3>
            </div>

            {% if transaction.error %}
            <div class="body">
                <strong class="red">{{ transaction.error_code }} - {{ transaction.error }}</strong>
                <p>{{ 'If you are sure that this transaction is valid you can update transaction details in &quot;Manage&quot; tab and try processing transaction again'|trans }}</p>
            </div>
            {% endif%}


            <table class="tableStatic wide">
                <tbody>
                    <tr {% if not transaction.error %}class="noborder"{% endif %}>
                        <td style="width: 35%">{{ 'ID'|trans }}</td>
                        <td>{{ transaction.id }}</td>
                    </tr>

                    <tr>
                        <td>{{ 'Invoice Id'|trans }}</td>
                        <td><a href="{{ 'invoice/manage'|alink }}/{{ transaction.invoice_id }}">{{ transaction.invoice_id|default('-') }}</a></td>
                    </tr>

                    <tr>
                        <td>{{ 'Amount'|trans }}</td>
                        <td>{{ transaction.amount }} {{ transaction.currency }}</td>
                    </tr>

                    <tr>
                        <td>{{ 'Payment gateway'|trans }}</td>
                        <td>{{ transaction.gateway|default('-') }}</td>
                    </tr>

                    <tr>
                        <td>{{ 'Transaction ID on payment gateway'|trans }}</td>
                        <td>{{ transaction.txn_id|default('-') }}</td>
                    </tr>

                    <tr>
                        <td>{{ 'Transaction status on payment gateway'|trans }}</td>
                        <td>{{ mf.status_name(transaction.txn_status) }}</td>
                    </tr>

                    <tr>
                        <td>{{ 'Status'|trans }}</td>
                        <td>{{ mf.status_name(transaction.status) }}</td>
                    </tr>

                    <tr>
                        <td>{{ 'IP'|trans }}</td>
                        <td>{{ transaction.ip }} {{ transaction.ip|ipcountryname|default('Unknown') }}</td>
                    </tr>

                    {% if transaction.note %}
                    <tr>
                        <td>{{ 'Note'|trans }}</td>
                        <td>{{ transaction.note }}</td>
                    </tr>
                    {% endif %}

                    <tr>
                        <td>{{ 'Received at'|trans }}</td>
                        <td>{{ transaction.created_at|date('l, d F Y') }}</td>
                    </tr>

                    {% if transaction.created_at != transaction.updated_at %}
                    <tr>
                        <td>{{ 'Updated at'|trans }}</td>
                        <td>{{ transaction.updated_at|date('l, d F Y') }}</td>
                    </tr>
                    {% endif %}
                 </tbody>

                 <tfoot>
                     <tr>
                         <td colspan="2">
                            <div class="aligncenter">
                                <a class="btn55 mr10 api-link" href="{{ 'api/admin/invoice/transaction_process'|link({ 'id': transaction.id }) }}" data-api-reload="1">
                                    <img src="images/icons/middlenav/refresh4.png" alt=""><span>{{ 'Process'|trans }}</span>
                                </a>
                                <a class="btn55 mr10 api-link" href="{{ 'api/admin/invoice/transaction_delete'|link({ 'id': transaction.id }) }}" data-api-confirm="Are you sure?" data-api-redirect="{{ 'invoice/transactions'|alink }}">
                                    <img src="images/icons/middlenav/trash.png" alt=""><span>{{ 'Delete'|trans }}</span>
                                </a>
                            </div>
                         </td>
                     </tr>
                 </tfoot>
            </table>

        </div>

        <div id="tab-manage" class="tab_content nopadding">
            <form method="post" action="{{ 'api/admin/invoice/transaction_update'|link }}" class="mainForm save api-form" data-api-reload="Transaction updated">
                <fieldset>
                    <legend>Transaction payment information</legend>
                    <div class="rowElem">
                        <label>{{ 'Invoice ID'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="invoice_id" value="{{ transaction.invoice_id }}" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Amount'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="amount" value="{{ transaction.amount }}" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Currency'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="currency" value="{{ transaction.currency }}" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                </fieldset>

                <fieldset>
                    <legend>{{ 'Transaction processing information'|trans }}</legend>
                    <div class="rowElem">
                        <label>{{ 'Payment Gateway'|trans }}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('gateway_id', admin.invoice_gateway_get_pairs, transaction.gateway_id, 0, 'Select payment gateway') }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Validate IPN'|trans }}:</label>
                        <div class="formRight">
                            <input type="radio" name="validate_ipn" value="1"{% if transaction.validate_ipn  %} checked="checked"{% endif %}/><label>Yes</label>
                            <input type="radio" name="validate_ipn" value="0"{% if not transaction.validate_ipn %} checked="checked"{% endif %} /><label>No</label>
                        </div>
                        <div class="fix"></div>
                    </div>
                </fieldset>

                <fieldset>
                    <legend>{{ 'Transaction information on payment gateway'|trans }}</legend>
                    <div class="rowElem">
                        <label>{{ 'Transaction type'|trans }}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('type', admin.invoice_transaction_types, transaction.type, 0, 'Select transaction type') }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Transaction status on Payment Gateway'|trans }}:</label>
                        <div class="formRight">
                            {{ mf.selectbox('txn_status', admin.invoice_transaction_gateway_statuses, transaction.txn_status, 0, 'Select status') }}
                        </div>
                        <div class="fix"></div>
                    </div>
                    <div class="rowElem">
                        <label>{{ 'Transaction ID on Payment Gateway'|trans }}:</label>
                        <div class="formRight">
                            <input type="text" name="txn_id" value="{{ transaction.txn_id }}" placeholder=""/>
                        </div>
                        <div class="fix"></div>
                    </div>
                    <input type="submit" value="{{ 'Update'|trans }}" class="greyishBtn submitForm" />
                    <input type="hidden" name="id" value="{{ transaction.id }}"/>
                </fieldset>
            </form>
        </div>

        <div id="tab-note" class="tab_content nopadding">
            <div class="help">
                <h3>{{ 'Note about this transaction'|trans }}</h3>
            </div>
            <form method="post" action="{{ 'api/admin/invoice/transaction_update'|link }}" class="mainForm save api-form" data-api-msg="Transaction note updated">
                <fieldset>
                    <div class="rowElem">
                        <div class="formBottom">
                            <textarea name="note" cols="" rows="10">{{ transaction.note }}</textarea>
                        </div>
                        <div class="fix"></div>
                    </div>
                </fieldset>

                <fieldset>
                    <input type="submit" value="{{ 'Update'|trans }}" class="greyishBtn submitForm" />
                    <input type="hidden" name="id" value="{{ transaction.id }}"/>
                </fieldset>
            </form>
        </div>

        <div id="tab-ipn" class="tab_content nopadding">


            <div class="help">
                <h3>{{ 'GET'|trans }}</h3>
            </div>
            {% if transaction.ipn.get %}
            <table class="tableStatic wide">
                <tbody>
                    {% for key,val in transaction.ipn.get %}
                    <tr {% if loop.first %}class="noborder"{% endif %}>
                        <td width="30%">{{ key }}</td>
                        <td>{{ val }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="body">
                <p>{{ 'No GET parameters received'|trans }}</p>
            </div>
            {% endif %}


            <div class="help">
                <h3>{{ 'POST'|trans }}</h3>
            </div>
            {% if transaction.ipn.post %}
            <table class="tableStatic wide">
                <tbody>
                    {% for key,val in transaction.ipn.post %}
                    <tr {% if loop.first %}class="noborder"{% endif %}>
                        <td width="30%">{{ key }}</td>
                        <td>{{ val }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="body">
                <p>{{ 'No POST parameters received'|trans }}</p>
            </div>
            {% endif %}

            <div class="help">
                <h3>{{ 'SERVER'|trans }}</h3>
            </div>
            {% if transaction.ipn.server %}
            <table class="tableStatic wide">
                <tbody>
                    {% for key,val in transaction.ipn.server %}
                    <tr {% if loop.first %}class="noborder"{% endif %}>
                        <td width="30%">{{ key }}</td>
                        <td>{{ val }}</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
            {% else %}
            <div class="body">
                <p>{{ 'No SERVER parameters logged'|trans }}</p>
            </div>
            {% endif %}

            <div class="help">
                <h3>{{ 'http_raw_post_data'|upper}}</h3>
            </div>
            {% if transaction.ipn.http_raw_post_data %}
            <div class="body">
                {{ transaction.ipn.http_raw_post_data }}
            </div>
            {% else %}
            <div class="body">
                <p>No {{ 'http_raw_post_data'|upper}} parameters received</p>
            </div>
            {% endif %}
            <div class="fix"></div>
        </div>
    </div>

    <div class="fix"></div>
</div>
{% endblock %}
