<?php
/**
 * Maho
 *
 * @category    design
 * @package     base_default
 * @copyright   Copyright (c) 2006-2020 Magento, Inc. (https://magento.com)
 * @copyright   Copyright (c) 2021-2024 The OpenMage Contributors (https://openmage.org)
 * @copyright   Copyright (c) 2024 Maho (https://mahocommerce.com)
 * @license     https://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
 */
?>
<?php /** @var Mage_Sales_Block_Billing_Agreement_View $this */ ?>
<div class="page-title title-buttons">
    <h1><?= $this->__('Billing Agreement # %s', $this->escapeHtml($this->getReferenceId())) ?></h1>
    <?php if ($this->getCanCancel()): ?>
        <button type="button" title="<?= Mage::helper('core')->quoteEscape($this->__('Cancel')) ?>" class="button" onclick="if( confirm('<?= Mage::helper('core')->quoteEscape($this->__('Are you sure you want to do this?')) ?>') ) { window.location.href = '<?= $this->getCancelUrl() ?>'; } return false;"><?= $this->__('Cancel') ?></button>
    <?php endif ?>
</div>
<?= $this->getMessagesBlock()->toHtml() ?>
<div class="billing-agreements">
    <div class="info-box">
        <h2 class="box-title"><?= $this->__('Agreement Information') ?></h2>
        <div class="box-content">
            <table class="info-table">
                <tbody>
                    <tr>
                        <th><?= $this->__('Reference ID:') ?></th>
                        <td><?= $this->escapeHtml($this->getReferenceId()) ?></td>
                    </tr>
                    <tr>
                        <th><?= $this->__('Status:') ?></th>
                        <td><?= $this->getAgreementStatus() ?></td>
                    </tr>
                    <tr>
                        <th><?= $this->__('Created:') ?></th>
                        <td><?= $this->escapeHtml($this->getAgreementCreatedAt()) ?></td>
                    </tr>
                    <?php if($this->getAgreementUpdatedAt()): ?>
                    <tr>
                        <th><?= $this->__('Updated:') ?></th>
                        <td><?= $this->escapeHtml($this->getAgreementUpdatedAt()) ?></td>
                    </tr>
                    <?php endif ?>
                    <tr>
                        <th><?= $this->__('Payment Method:') ?></th>
                        <td><?= $this->getPaymentMethodTitle() ?></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
    <?php $relatedOrders = $this->getRelatedOrders() ?>
    <?php if(count($relatedOrders) > 0): ?>
    <?= $this->getChildHtml('pager') ?>
    <h2 class="table-caption"><?= $this->__('Related Orders') ?></h2>
    <table class="data-table" id="related-orders-table">
        <col width="1" />
        <col width="1" />
        <col />
        <col width="1" />
        <col width="1" />
        <col width="1" />
        <thead>
            <tr>
                <th><span class="nobr"><?= $this->__('Order #') ?></span></th>
                <th><?= $this->__('Date') ?></th>
                <th><?= $this->__('Ship To') ?></th>
                <th><span class="nobr"><?= $this->__('Order Total') ?></span></th>
                <th><span class="nobr"><?= $this->__('Order Status') ?></span></th>
                <th>&nbsp;</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($relatedOrders as $order): ?>
                <tr>
                    <td><?= $this->getOrderItemValue($order, 'order_increment_id') ?></td>
                    <td><span class="nobr"><?= $this->getOrderItemValue($order, 'created_at') ?></span></td>
                    <td><?= $this->getOrderItemValue($order, 'shipping_address') ?></td>
                    <td><?= $this->getOrderItemValue($order, 'order_total') ?></td>
                    <td><em><?= $this->getOrderItemValue($order, 'status_label') ?></em></td>
                    <td class="a-center">
                        <span class="nobr">
                            <a href="<?= $this->getOrderItemValue($order, 'view_url') ?>"><?= $this->__('View Order') ?></a>
                        </span>
                    </td>
                </tr>
            <?php endforeach ?>
        </tbody>
    </table>
    <?php endif ?>
    <div class="buttons-set">
        <p class="back-link"><a href="<?= $this->getBackUrl() ?>"><small>&laquo; </small><?= $this->__('Back to Billing Agreements') ?></a></p>
    </div>
</div>
