
            <?php
            // Don't show this container when only rendering the widget section
            if (!($render_section ?? null) && !($is_ajax ?? null)) {
            ?>
        <div class="col-md-12">
            <?php
            }

            $links = [
                ['name' => $this->_('ClientQuotations.index.category_pending', true) . ' <span class="badge">' . (isset($status_count['pending']) ? $this->Html->safe($status_count['pending']) : null) . '</span>', 'current' => (($status ?? null) == 'pending' ? true : false), 'attributes' => ['href' => $this->base_uri . 'quotations/index/pending/', 'class' => 'ajax']],
                ['name' => $this->_('ClientQuotations.index.category_approved', true) . ' <span class="badge">' . (isset($status_count['approved']) ? $this->Html->safe($status_count['approved']) : null) . '</span>', 'current' => (($status ?? null) == 'approved' ? true : false), 'attributes' => ['href' => $this->base_uri . 'quotations/index/approved/', 'class' => 'ajax']],
                ['name' => $this->_('ClientQuotations.index.category_expired', true) . ' <span class="badge">' . (isset($status_count['expired']) ? $this->Html->safe($status_count['expired']) : null) . '</span>', 'current' => (($status ?? null) == 'expired' ? true : false), 'attributes' => ['href' => $this->base_uri . 'quotations/index/expired/', 'class' => 'ajax']]
            ];

            $this->WidgetClient->clear();
            $this->WidgetClient->setLinks($links);
            $this->WidgetClient->setFilters(($filters ?? null), $this->Html->safe($this->base_uri . 'quotations/index/' . (isset($status) ? $this->Html->safe($status) : null)), !empty($filter_vars));
            $this->WidgetClient->setAjaxFiltering();
            $this->WidgetClient->create($this->_('ClientQuotations.index.boxtitle_quotations', true), ['id' => 'client_quotations'], ($render_section ?? null));
            $this->WidgetClient->startBody();
            $this->WidgetClient->buildFilters();
            ?>

                <?php
                if (($quotations ?? false) && ($num_quotations = count($quotations)) > 0) {
                ?>
                <div class="table-responsive">
                    <table class="table table-curved table-striped-alt table-hover" id="quotations">
                        <thead>
                            <tr>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/index/' . ($status ?? null) . '/?sort=id_code&order=' . ($sort == 'id_code' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'id_code' ? ' ' . $order : '');?>"><?php $this->_('ClientQuotations.index.heading_quotation');?></a></th>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/index/' . ($status ?? null) . '/?sort=title&order=' . ($sort == 'title' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'title' ? ' ' . $order : '');?>"><?php $this->_('ClientQuotations.index.heading_title');?></a></th>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/index/' . ($status ?? null) . '/?sort=subtotal&order=' . ($sort == 'subtotal' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'subtotal' ? ' ' . $order : '');?>"><?php $this->_('ClientQuotations.index.heading_subtotal');?></a></th>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/index/' . ($status ?? null) . '/?sort=total&order=' . ($sort == 'total' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'total' ? ' ' . $order : '');?>"><?php $this->_('ClientQuotations.index.heading_total');?></a></th>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/index/' . ($status ?? null) . '/?sort=date_created&order=' . ($sort == 'date_created' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'date_created' ? ' ' . $order : '');?>"><?php $this->_('ClientQuotations.index.heading_date_created');?></a></th>
                                <?php
                                if (($status ?? null) !== 'approved') {
                                ?>
                                <th><a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/index/' . ($status ?? null) . '/?sort=date_expires&order=' . ($sort == 'date_expires' ? $negate_order : $order));?>" class="ajax<?php echo $this->Html->safe($sort == 'date_expires' ? ' ' . $order : '');?>"><?php $this->_('ClientQuotations.index.heading_date_expires');?></a></th>
                                <?php
                                }
                                ?>
                                <th><?php $this->_('ClientQuotations.index.heading_options');?></th>
                            </tr>
                        </thead>
                        <tbody>
                            <?php
                            // Loop through all quotations
                            for ($i = 0; $i < $num_quotations; $i++) {
                                $expired = (($status ?? null) == 'expired' && $this->Date->toTime($this->Date->cast($quotations[$i]->date_expires)) < $this->Date->toTime(date('c')));
                            ?>
                            <tr class="expand quotation_applied">
                                <td><?php (print (isset($quotations[$i]->id_code) ? $this->Html->safe($quotations[$i]->id_code) : null));?></td>
                                <td><?php echo (isset($quotations[$i]->title) ? $this->Html->safe($quotations[$i]->title) : null);?></td>
                                <td><?php echo $this->CurrencyFormat->format((isset($quotations[$i]->subtotal) ? $this->Html->safe($quotations[$i]->subtotal) : null), (isset($quotations[$i]->currency) ? $this->Html->safe($quotations[$i]->currency) : null), ['html_code' => true]);?></td>
                                <td><?php echo $this->CurrencyFormat->format((isset($quotations[$i]->total) ? $this->Html->safe($quotations[$i]->total) : null), (isset($quotations[$i]->currency) ? $this->Html->safe($quotations[$i]->currency) : null), ['html_code' => true]);?></td>
                                <td><?php echo $this->Date->cast((isset($quotations[$i]->date_created) ? $this->Html->safe($quotations[$i]->date_created) : null));?></td>
                                <?php
                                if (($status ?? null) !== 'approved') {
                                ?>
                                <td<?php echo ($expired ? ' class="text-danger"' : '');?>><?php echo $this->Date->cast((isset($quotations[$i]->date_expires) ? $this->Html->safe($quotations[$i]->date_expires) : null));?></td>
                                <?php
                                }
                                ?>
                                <td>
                                    <div class="btn-group">
                                        <?php
                                        if (($status ?? null) == 'pending') {
                                        ?>
                                        <a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/approve/' . ($quotations[$i]->id ?? null) . '/');?>" class="btn btn-xs btn-light approve_quotation">
                                            <i class="fas fa-plus-circle fa-fw"></i> <?php $this->_('ClientQuotations.index.option_approve');?>
                                        </a>
                                        <button class="btn btn-xs btn-light dropdown-toggle" data-toggle="dropdown" type="button">
                                            <span class="caret"></span>
                                        </button>
                                        <ul class="dropdown-menu">
                                            <li>
                                                <a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/view/' . ($quotations[$i]->id ?? null) . '/');?>">
                                                    <i class="fas fa-file-invoice-dollar fa-fw"></i> <?php $this->_('ClientQuotations.index.option_view');?>
                                                </a>
                                            </li>
                                        </ul>
                                        <?php
                                        } else {
                                        ?>
                                        <a href="<?php echo $this->Html->safe($this->base_uri . 'quotations/view/' . ($quotations[$i]->id ?? null) . '/');?>" class="btn btn-xs btn-light">
                                            <i class="fas fa-file-invoice-dollar fa-fw"></i> <?php $this->_('ClientQuotations.index.option_view');?>
                                        </a>
                                        <?php
                                        }
                                        ?>
                                    </div>
                                </td>
                            </tr>
                            <tr class="expand_details" id="quotations_<?php (print (isset($quotations[$i]->id) ? $this->Html->safe($quotations[$i]->id) : null));?>">
                                <td colspan="<?php if (($status ?? null) !== 'approved') { echo '7'; } else { echo '6'; } ?>" class="subtable">
                                </td>
                            </tr>
                            <?php
                            }
                            ?>
                        </tbody>
                    </table>
                </div>
                <?php
                } else {
                ?>
                <div class="alert alert-info">
                    <p>
                        <?php
                        $section_language = $this->_('ClientQuotations.index.category_' . ($status ?? null), true);
                        $this->_('ClientQuotations.index.no_results', false, $section_language);
                        ?>
                    </p>
                </div>
                <?php
                }
                ?>
            <?php
            $this->WidgetClient->endBody();
            if ($this->Pagination->hasPages()) {
                $this->WidgetClient->startFooter();
                $this->Pagination->build();
                $this->WidgetClient->endFooter();
            }
            $this->WidgetClient->end();

            // Don't show this container when only rendering the widget section
            if (!($render_section ?? null) && !($is_ajax ?? null)) {
            ?>
        </div>
            <?php
            }
            ?>
<script type="text/javascript">
    $(document).ready(function() {
        // Fetch all associated invoices to the given quotations
        $(".quotation_applied").click(function() {
            $(this).blestaUpdateRow("<?php echo $this->Html->safe((isset($this->base_uri) ? $this->Html->safe($this->base_uri) : null) . 'quotations/invoices/');?>" + $(this).next("tr").attr("id").split("_")[1], ".subtable");
        });

        $('a.approve_quotation').each(function() {
            $(this).blestaModal({url: $(this).attr('href')});
        });
    });
</script>