<?php
/**
 * @version 7.8
 */
/** @var bool $inAdmin */
/** @var string $type */
?>
<nav class="navbar navbar-filter">
    <?php if (!$inAdmin) { ?>
        <div class="navbar-left">
            <?php
            /** @var \Cube\Navigation $container */
            $container = $this->navigation()->getContainer();

            echo $this->navigation()
                ->setContainer($container->findOneBy('label', $this->_('Sale Invoices Filter')))
                ->setPartial('navigation/browse-filter.phtml')
                ->menu();

            // reset navigation container (workaround for the navigation on the layout page)
            $this->navigation()->setContainer($container);
            ?>
        </div>
    <?php } ?>

    <form class="navbar-form navbar-right" action="<?php echo $this->url(null, null, true,
        array('sale_id', 'listing_id', 'keywords', 'option', 'page', 'submit')); ?>" method="get">

        <div class="form-group">
            <?php echo
            $this->formElement('text', 'sale_id', $this->saleId)
                ->setAttributes(array('placeholder' => $this->_('Invoice ID'), 'class' => 'form-control input-default'))
                ->render();
            ?>
        </div>
        <?php echo
        $this->formElement('submit', 'submit', $this->_('Search'))
            ->setAttributes(array('class' => 'btn btn-default'))
            ->render();
        ?>
    </form>
</nav>

<div class="table-responsive">
    <table class="table">
        <caption>
            <strong><?php echo $this->paginator->getPages()->totalItemCount; ?></strong> <?php echo $this->_('invoices found.'); ?>

            <?php if ($this->paginator->getPages()->totalItemCount) { ?>
                <?php echo $this->_('Showing results'); ?>
                <strong><?php echo $this->paginator->getPages()->firstItemNumber; ?></strong>
                <?php echo $this->_('to'); ?>
                <strong><?php echo $this->paginator->getPages()->lastItemNumber; ?></strong>
            <?php } ?>
        </caption>
        <?php if ($this->paginator->getPages()->totalItemCount) { ?>
            <thead>
            <tr>
                <th><?php echo $this->_('Sale Details'); ?></th>
                <th class="size-tiny"></th>
            </tr>
            </thead>
        <?php } ?>
        <tbody>
        <?php
        /** @var \Ppb\Db\Table\Row\Sale $sale */
        foreach ($this->paginator as $sale) {
            ?>
            <tr>
                <td>
                    <?php echo $this->partial('partials/sale.phtml', array(
                        'sale'                => $sale,
                        'postageDesc'         => true,
                        'caption'             => true,
                        'directPaymentButton' => true,
                        'type'                => $type,
                        'displayDownloads'    => true,
                        'inAdmin'             => $inAdmin)); ?>
                </td>
                <td>
                    <?php if ($sale->isActive(false) && !$inAdmin) { ?>
                        <div class="btn-group-vertical">
                            <?php if ($sale->canEdit()) { ?>
                                <a class="btn btn-sm btn-default"
                                   href="<?php echo $this->url(array('action' => 'edit', 'sale_id' => $sale['id'])); ?>"
                                   title="<?php echo $this->_('Edit Invoice'); ?>">
                                    <i class="fa fa-folder-open"></i>
                                </a>
                                <?php if ($sale->canCombinePurchases()) { ?>
                                    <a class="btn btn-sm btn-default"
                                       href="<?php echo $this->url(array('action' => 'edit', 'option' => 'combine', 'sale_id' => $sale['id'])); ?>"
                                       title="<?php echo $this->_('Combine Invoices'); ?>">
                                        <i class="fa fa-chain"></i>
                                    </a>
                                <?php } ?>
                            <?php } ?>
                            <?php if ($sale->isSeller()) { ?>
                                <a class="btn btn-sm btn-default jq-popup-form"
                                   href="<?php echo $this->url(array('action' => 'update-status', 'sale_id' => $sale['id'])); ?>"
                                   data-close-redirect="<?php echo $this->url(array('action' => 'browse', 'type' => 'sold')); ?>"
                                   title="<?php echo $this->_('Update Shipping & Payment Details'); ?>">
                                    <i class="fa fa-truck"></i>
                                </a>
                            <?php } ?>
                            <?php if ($sale->canDelete()) { ?>
                                <a class="btn btn-sm btn-danger confirm-box"
                                   href="<?php echo $this->url(array('action' => 'delete', 'sale_id' => $sale['id']),
                                       null,
                                       true); ?>"
                                   title="<?php echo $this->_('Delete Invoice'); ?>"
                                   data-message="<?php echo $this->_('Are you sure you want to delete this invoice?'); ?>">
                                    <i class="fa fa-times"></i>
                                </a>
                            <?php } ?>
                        </div>
                    <?php } ?>
                    <?php if ($inAdmin) { ?>
                        <a class="btn btn-danger confirm-box"
                           href="<?php echo $this->url(array('option' => 'delete', 'sale_id' => $sale['id']), null,
                               true); ?>"
                           title="<?php echo $this->_('Delete Invoice'); ?>"
                           data-message="<?php echo $this->_('Are you sure you want to delete this invoice?'); ?>">
                            <i class="fa fa-times"></i>
                        </a>
                    <?php } ?>
                </td>
            </tr>
        <?php } ?>
        </tbody>
    </table>
</div>

<?php echo $this->pagination($this->paginator, 'sliding', 'partials/pagination.phtml'); ?>
