<?php if ($this->form->hasElements()) { ?>
<?php $nbColumns = count($this->columns); ?>

<form method="<?php echo $this->form->getMethod(); ?>" action="<?php echo $this->form->getAction(); ?>" class="form-horizontal">
    <?php echo $this->form->hiddenElements; ?>
    <table class="table table-striped table-hover">
        <thead>
            <tr>
                <?php foreach ($this->columns as $column) { ?>
                <th<?php echo (isset($column['class'])) ? ' class="' . $column['class'] . '"' : ''; ?>><?php echo $this->_($column['label']); ?></th>
                <?php } ?>
            </tr>
        </thead>
        <tbody>
            <!-- list table data -->
            <?php
            $checkboxCounter = 0;
            $shippingModelInput = array();
            foreach ((array) $this->form->getData() as $data) {
                if (is_array($data)) { ?>
            <tr>
                <?php foreach ($this->columns as $column) { ?>
                <td<?php echo (isset($column['class'])) ? ' class="' . $column['class'] . '"' : ''; ?>>
                    <?php foreach ((array) $column['element_id'] as $elementId) {
                        $element = $this->form->getElement($elementId);

                        if ($elementId == 'price') {
                            $element->setPrefix($data['currency']);
                        }

                        if ($elementId == 'id' && $element->getType() == 'checkbox') {
                            $element->setMultiOptions(array($data['id'] => null));
                        }
                        if (isset($data[$elementId])) {
                            $element->setData($data[$elementId]);
                        }

                        $element->setBrackets('[' . $checkboxCounter . ']');

                        echo $element;
                    } ?>
                </td>
                <?php } ?>
            </tr>
            <?php  $checkboxCounter ++;
                }
            } ?>

            <?php if ($this->settings['enable_shipping']) { ?>
            <?php $shippingAddress = $this->form->getElement('shipping_address_id'); ?>

            <tr>
                <td colspan="<?php echo ($nbColumns - 2); ?>">
                    <div class="text-right">
                        <strong><?php echo $shippingAddress->getLabel(); ?></strong>
                    </div>
                </td>
                <!-- select shipping address dropdown -->
                <td colspan="2">
                    <div>
                        <?php echo $shippingAddress->render(); ?>
                    </div>
                </td>
            </tr>

            <?php $postageMethod = $this->form->getElement('postage_id'); ?>

            <tr>
                <td colspan="<?php echo ($nbColumns - 2); ?>">
                    <div class="text-right">
                        <strong><?php echo $postageMethod->getLabel(); ?></strong>
                    </div>
                </td>
                <!-- select postage method dropdown -->
                <!-- postage amount field (text box or description field) -->
                <td colspan="2">
                    <div>
                        <?php echo $postageMethod->render(); ?>
                    </div>
                    <div>
                        <?php echo $this->form->getElement('postage_amount')->render(); ?>
                    </div>
                </td>
            </tr>

            <?php if ($this->form->hasElement('tax_rate')) { ?>
            <?php $taxRate = $this->form->getElement('tax_rate'); ?>
            <tr>
                <td colspan="<?php echo ($nbColumns - 2); ?>">
                    <div class="text-right">
                        <strong><?php echo $taxRate->getLabel(); ?></strong>
                    </div>
                </td>
                <!-- tax rate field (text box or description field) -->
                <td colspan="2">
                    <div>
                        <?php echo $taxRate->render(); ?>
                    </div>
                </td>
            </tr>
            <?php } ?>

            <?php $insuranceCheckbox = $this->form->getElement('apply_insurance'); ?>
            <tr>
                <td colspan="<?php echo ($nbColumns - 2); ?>">
                    <div class="text-right">
                        <strong><?php echo $insuranceCheckbox->getLabel(); ?></strong>
                    </div>
                </td>
                <!-- apply insurance checkbox -->
                <!-- insurance amount field (text box or description field) -->
                <td colspan="2">
                    <div>
                        <?php echo $insuranceCheckbox->render(); ?>
                    </div>
                    <div>
                        <?php echo $this->form->getElement('insurance_amount')->render(); ?>
                    </div>
                </td>
            </tr>
            <?php } ?>

            <tr>
                <td colspan="<?php echo ($nbColumns - 2); ?>">
                    <p class="text-right">
                        <strong><?php echo $this->_('Total'); ?></strong>
                    </p>
                </td>
                <td colspan="2"><?php echo $this->amount($sale->calculateTotal(), $sale['currency']); ?></td>
            </tr>


            <tr>
                <td colspan="<?php echo $nbColumns; ?>">
                    <?php echo $this->form->getElement('update_values')->render(); ?>
                    <?php echo $this->form->getElement(\App\Form\Tables::BTN_SUBMIT)->render(); ?>
                </td>
            </tr>
        </tbody>
    </table>
</form>
<?php } ?>